blob: 26d85285cf543f6528b707cbad7f84e98060c11e [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.core.impl;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070017
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Reference;
21import org.apache.felix.scr.annotations.ReferenceCardinality;
22import org.apache.felix.scr.annotations.Service;
Simon Hunt9fec43f2015-03-25 11:36:30 -070023import org.onlab.util.Tools;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.core.ApplicationId;
25import org.onosproject.core.ApplicationIdStore;
26import org.onosproject.core.CoreService;
27import org.onosproject.core.IdBlockStore;
28import org.onosproject.core.IdGenerator;
29import org.onosproject.core.Version;
Thomas Vachuska8dc1a692015-03-31 01:01:37 -070030import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070032
33import java.io.File;
34import java.util.List;
35import java.util.Set;
36
37import static com.google.common.base.Preconditions.checkNotNull;
38
39/**
40 * Core service implementation.
41 */
Brian O'Connor520c0522014-11-23 23:50:47 -080042@Component(immediate = true)
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070043@Service
44public class CoreManager implements CoreService {
45
Thomas Vachuska8dc1a692015-03-31 01:01:37 -070046 private final Logger log = LoggerFactory.getLogger(getClass());
47
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070048 private static final File VERSION_FILE = new File("../VERSION");
Simon Hunt9fec43f2015-03-25 11:36:30 -070049 private static Version version = Version.version("1.2.0-SNAPSHOT");
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070050
51 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
52 protected ApplicationIdStore applicationIdStore;
53
Brian O'Connor520c0522014-11-23 23:50:47 -080054 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
55 protected IdBlockStore idBlockStore;
56
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070057 @Activate
58 public void activate() {
59 List<String> versionLines = Tools.slurp(VERSION_FILE);
60 if (versionLines != null && !versionLines.isEmpty()) {
61 version = Version.version(versionLines.get(0));
62 }
63 }
64
65 @Override
66 public Version version() {
67 return version;
68 }
69
70 @Override
71 public Set<ApplicationId> getAppIds() {
72 return applicationIdStore.getAppIds();
73 }
74
75 @Override
76 public ApplicationId getAppId(Short id) {
77 return applicationIdStore.getAppId(id);
78 }
79
80 @Override
Ray Milkey02479862015-02-17 17:02:19 -080081 public ApplicationId getAppId(String name) {
82 return applicationIdStore.getAppId(name);
83 }
84
85
86 @Override
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070087 public ApplicationId registerApplication(String name) {
88 checkNotNull(name, "Application ID cannot be null");
89 return applicationIdStore.registerApplication(name);
90 }
91
Brian O'Connor520c0522014-11-23 23:50:47 -080092 @Override
93 public IdGenerator getIdGenerator(String topic) {
Brian O'Connor520c0522014-11-23 23:50:47 -080094 IdBlockAllocator allocator = new StoreBasedIdBlockAllocator(topic, idBlockStore);
95 return new BlockAllocatorBasedIdGenerator(allocator);
96 }
97
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070098}