Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 16 | package org.onlab.onos.core.impl; |
| 17 | |
| 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Reference; |
| 21 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 22 | import org.apache.felix.scr.annotations.Service; |
| 23 | import org.onlab.onos.core.ApplicationId; |
| 24 | import org.onlab.onos.core.ApplicationIdStore; |
| 25 | import org.onlab.onos.core.CoreService; |
| 26 | import org.onlab.onos.core.Version; |
| 27 | import org.onlab.util.Tools; |
| 28 | |
| 29 | import java.io.File; |
| 30 | import java.util.List; |
| 31 | import java.util.Set; |
| 32 | |
| 33 | import static com.google.common.base.Preconditions.checkNotNull; |
| 34 | |
| 35 | /** |
| 36 | * Core service implementation. |
| 37 | */ |
| 38 | @Component |
| 39 | @Service |
| 40 | public class CoreManager implements CoreService { |
| 41 | |
| 42 | private static final File VERSION_FILE = new File("../VERSION"); |
| 43 | private static Version version = Version.version("1.0.0-SNAPSHOT"); |
| 44 | |
| 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 46 | protected ApplicationIdStore applicationIdStore; |
| 47 | |
| 48 | @Activate |
| 49 | public void activate() { |
| 50 | List<String> versionLines = Tools.slurp(VERSION_FILE); |
| 51 | if (versionLines != null && !versionLines.isEmpty()) { |
| 52 | version = Version.version(versionLines.get(0)); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public Version version() { |
| 58 | return version; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public Set<ApplicationId> getAppIds() { |
| 63 | return applicationIdStore.getAppIds(); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public ApplicationId getAppId(Short id) { |
| 68 | return applicationIdStore.getAppId(id); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public ApplicationId registerApplication(String name) { |
| 73 | checkNotNull(name, "Application ID cannot be null"); |
| 74 | return applicationIdStore.registerApplication(name); |
| 75 | } |
| 76 | |
| 77 | } |