Mohammad Shahid | 0cf9c0e | 2017-08-09 15:58:19 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.gluon.manager; |
| 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.osgi.service.component.annotations.Activate; |
| 19 | import org.osgi.service.component.annotations.Component; |
| 20 | import org.osgi.service.component.annotations.Deactivate; |
| 21 | import org.osgi.service.component.annotations.Reference; |
| 22 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Mohammad Shahid | 0cf9c0e | 2017-08-09 15:58:19 +0530 | [diff] [blame] | 23 | import org.onosproject.core.CoreService; |
| 24 | import org.onosproject.gluon.rsc.GluonConfig; |
| 25 | import org.onosproject.gluon.rsc.GluonServer; |
| 26 | import org.onosproject.net.config.ConfigFactory; |
| 27 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 28 | import org.onosproject.net.config.basics.SubjectFactories; |
| 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
| 31 | |
| 32 | import java.util.LinkedHashMap; |
| 33 | import java.util.Map; |
| 34 | |
| 35 | /** |
| 36 | * Gluon Shim Application. |
| 37 | */ |
| 38 | @Component(immediate = true) |
| 39 | public class GluonManager { |
| 40 | |
| 41 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 42 | private static final String APP_ID = "org.onosproject.gluon"; |
| 43 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 44 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Mohammad Shahid | 0cf9c0e | 2017-08-09 15:58:19 +0530 | [diff] [blame] | 45 | protected CoreService coreService; |
| 46 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Mohammad Shahid | 0cf9c0e | 2017-08-09 15:58:19 +0530 | [diff] [blame] | 48 | 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 Milkey | 10f35dc | 2018-02-01 09:26:51 -0800 | [diff] [blame] | 60 | private static Map<String, GluonServer> serverMap = new LinkedHashMap<>(); |
Mohammad Shahid | 0cf9c0e | 2017-08-09 15:58:19 +0530 | [diff] [blame] | 61 | |
| 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 | } |