blob: 1d8b32a5bd6c6a7e70bf252e61f58344dea9c305 [file] [log] [blame]
Mohammad Shahid0cf9c0e2017-08-09 15:58:19 +05301/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.onosproject.gluon.manager;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.osgi.service.component.annotations.Activate;
19import org.osgi.service.component.annotations.Component;
20import org.osgi.service.component.annotations.Deactivate;
21import org.osgi.service.component.annotations.Reference;
22import org.osgi.service.component.annotations.ReferenceCardinality;
Mohammad Shahid0cf9c0e2017-08-09 15:58:19 +053023import org.onosproject.core.CoreService;
24import org.onosproject.gluon.rsc.GluonConfig;
25import org.onosproject.gluon.rsc.GluonServer;
26import org.onosproject.net.config.ConfigFactory;
27import org.onosproject.net.config.NetworkConfigRegistry;
28import org.onosproject.net.config.basics.SubjectFactories;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.LinkedHashMap;
33import java.util.Map;
34
35/**
36 * Gluon Shim Application.
37 */
38@Component(immediate = true)
39public class GluonManager {
40
41 private final Logger log = LoggerFactory.getLogger(getClass());
42 private static final String APP_ID = "org.onosproject.gluon";
43
Ray Milkeyd84f89b2018-08-17 14:54:17 -070044 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Mohammad Shahid0cf9c0e2017-08-09 15:58:19 +053045 protected CoreService coreService;
46
Ray Milkeyd84f89b2018-08-17 14:54:17 -070047 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Mohammad Shahid0cf9c0e2017-08-09 15:58:19 +053048 protected NetworkConfigRegistry configRegistry;
49
50
51 private final ConfigFactory configFactory =
52 new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY,
53 GluonConfig.class, "gluon") {
54 @Override
55 public GluonConfig createConfig() {
56 return new GluonConfig();
57 }
58 };
59
Ray Milkey10f35dc2018-02-01 09:26:51 -080060 private static Map<String, GluonServer> serverMap = new LinkedHashMap<>();
Mohammad Shahid0cf9c0e2017-08-09 15:58:19 +053061
62 @Activate
63 public void activate() {
64 coreService.registerApplication(APP_ID);
65 configRegistry.registerConfigFactory(configFactory);
66 log.info("Gluon app Started");
67 }
68
69 @Deactivate
70 public void deactivate() {
71 configRegistry.unregisterConfigFactory(configFactory);
72 log.info("Gluon app Stopped");
73 }
74
75 /**
76 * Creating gluon server object.
77 *
78 * @param etcduri server url
79 * @param targetProtonKey server key type, default net-l3vpn
80 * @param mode server mode start or stop
81 * @param version running server version
82 */
83 public static void createServer(String etcduri, String targetProtonKey,
84 String mode, String version) {
85 new GluonServer(etcduri, targetProtonKey, mode, version);
86 }
87
88 /**
89 * Deleting gluon server from server list.
90 *
91 * @param etcduri server url
92 */
93 public static void deleteServer(String etcduri) {
94 for (Map.Entry<String, GluonServer> server : serverMap.entrySet()) {
95 if (etcduri.equals(server.getKey())) {
96 serverMap.remove(etcduri);
97 return;
98 }
99 }
100 }
101
102 /**
103 * Add server into map.
104 *
105 * @param etcduri server url
106 * @param gluonObject store server object
107 */
108 public static void addServer(String etcduri, GluonServer gluonObject) {
109 serverMap.put(etcduri, gluonObject);
110 }
111
112 /**
113 * Returns serverMap size.
114 *
115 * @return total number of servers
116 */
117 public static int getTotalServers() {
118 return serverMap.size();
119 }
120
121 /**
122 * Returns all server IPs.
123 *
124 * @return serverMap
125 */
126 public static Map<String, GluonServer> getAllServersIP() {
127 return serverMap;
128 }
129
130
131}