Replace original windows line delimiters.
Change-Id: Icbae06e51f774e788e82683f65fd1d9641102be0
Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
-/*\r
- * Copyright IBM Corporation, 2013. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.networkconfig.neutron.implementation;\r
-\r
-import java.util.Hashtable;\r
-import java.util.Dictionary;\r
-import org.apache.felix.dm.Component;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronRouterCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;\r
-import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;\r
-\r
-public class Activator extends ComponentActivatorAbstractBase {\r
- protected static final Logger logger = LoggerFactory\r
- .getLogger(Activator.class);\r
-\r
- /**\r
- * Function called when the activator starts just after some\r
- * initializations are done by the\r
- * ComponentActivatorAbstractBase.\r
- *\r
- */\r
- public void init() {\r
-\r
- }\r
-\r
- /**\r
- * Function called when the activator stops just before the\r
- * cleanup done by ComponentActivatorAbstractBase\r
- *\r
- */\r
- public void destroy() {\r
-\r
- }\r
-\r
- /**\r
- * Function that is used to communicate to dependency manager the\r
- * list of known implementations for services inside a container\r
- *\r
- *\r
- * @return An array containing all the CLASS objects that will be\r
- * instantiated in order to get an fully working implementation\r
- * Object\r
- */\r
- public Object[] getImplementations() {\r
- Object[] res = { NeutronFloatingIPInterface.class,\r
- NeutronRouterInterface.class,\r
- NeutronPortInterface.class,\r
- NeutronSubnetInterface.class,\r
- NeutronNetworkInterface.class };\r
- return res;\r
- }\r
-\r
- /**\r
- * Function that is called when configuration of the dependencies\r
- * is required.\r
- *\r
- * @param c dependency manager Component object, used for\r
- * configuring the dependencies exported and imported\r
- * @param imp Implementation class that is being configured,\r
- * needed as long as the same routine can configure multiple\r
- * implementations\r
- * @param containerName The containerName being configured, this allow\r
- * also optional per-container different behavior if needed, usually\r
- * should not be the case though.\r
- */\r
- public void configureInstance(Component c, Object imp, String containerName) {\r
- if (imp.equals(NeutronFloatingIPInterface.class)) {\r
- // export the service\r
- c.setInterface(\r
- new String[] { INeutronFloatingIPCRUD.class.getName() }, null);\r
- Dictionary<String, String> props = new Hashtable<String, String>();\r
- props.put("salListenerName", "neutron");\r
- c.add(createContainerServiceDependency(containerName)\r
- .setService(IClusterContainerServices.class)\r
- .setCallbacks("setClusterContainerService",\r
- "unsetClusterContainerService").setRequired(true));\r
- }\r
- if (imp.equals(NeutronRouterInterface.class)) {\r
- // export the service\r
- c.setInterface(\r
- new String[] { INeutronRouterCRUD.class.getName() }, null);\r
- Dictionary<String, String> props = new Hashtable<String, String>();\r
- props.put("salListenerName", "neutron");\r
- c.add(createContainerServiceDependency(containerName)\r
- .setService(IClusterContainerServices.class)\r
- .setCallbacks("setClusterContainerService",\r
- "unsetClusterContainerService").setRequired(true));\r
- }\r
- if (imp.equals(NeutronPortInterface.class)) {\r
- // export the service\r
- c.setInterface(\r
- new String[] { INeutronPortCRUD.class.getName() }, null);\r
- Dictionary<String, String> props = new Hashtable<String, String>();\r
- props.put("salListenerName", "neutron");\r
- c.add(createContainerServiceDependency(containerName)\r
- .setService(IClusterContainerServices.class)\r
- .setCallbacks("setClusterContainerService",\r
- "unsetClusterContainerService").setRequired(true));\r
- }\r
- if (imp.equals(NeutronSubnetInterface.class)) {\r
- // export the service\r
- c.setInterface(\r
- new String[] { INeutronSubnetCRUD.class.getName() }, null);\r
- Dictionary<String, String> props = new Hashtable<String, String>();\r
- props.put("salListenerName", "neutron");\r
- c.add(createContainerServiceDependency(containerName)\r
- .setService(IClusterContainerServices.class)\r
- .setCallbacks("setClusterContainerService",\r
- "unsetClusterContainerService").setRequired(true));\r
- }\r
- if (imp.equals(NeutronNetworkInterface.class)) {\r
- // export the service\r
- c.setInterface(\r
- new String[] { INeutronNetworkCRUD.class.getName() }, null);\r
- Dictionary<String, String> props = new Hashtable<String, String>();\r
- props.put("salListenerName", "neutron");\r
- c.add(createContainerServiceDependency(containerName)\r
- .setService(IClusterContainerServices.class)\r
- .setCallbacks("setClusterContainerService",\r
- "unsetClusterContainerService").setRequired(true));\r
- }\r
- }\r
-}\r
+/*
+ * Copyright IBM Corporation, 2013. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.networkconfig.neutron.implementation;
+
+import java.util.Hashtable;
+import java.util.Dictionary;
+import org.apache.felix.dm.Component;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.opendaylight.controller.clustering.services.IClusterContainerServices;
+import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronRouterCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
+import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
+
+public class Activator extends ComponentActivatorAbstractBase {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(Activator.class);
+
+ /**
+ * Function called when the activator starts just after some
+ * initializations are done by the
+ * ComponentActivatorAbstractBase.
+ *
+ */
+ public void init() {
+
+ }
+
+ /**
+ * Function called when the activator stops just before the
+ * cleanup done by ComponentActivatorAbstractBase
+ *
+ */
+ public void destroy() {
+
+ }
+
+ /**
+ * Function that is used to communicate to dependency manager the
+ * list of known implementations for services inside a container
+ *
+ *
+ * @return An array containing all the CLASS objects that will be
+ * instantiated in order to get an fully working implementation
+ * Object
+ */
+ public Object[] getImplementations() {
+ Object[] res = { NeutronFloatingIPInterface.class,
+ NeutronRouterInterface.class,
+ NeutronPortInterface.class,
+ NeutronSubnetInterface.class,
+ NeutronNetworkInterface.class };
+ return res;
+ }
+
+ /**
+ * Function that is called when configuration of the dependencies
+ * is required.
+ *
+ * @param c dependency manager Component object, used for
+ * configuring the dependencies exported and imported
+ * @param imp Implementation class that is being configured,
+ * needed as long as the same routine can configure multiple
+ * implementations
+ * @param containerName The containerName being configured, this allow
+ * also optional per-container different behavior if needed, usually
+ * should not be the case though.
+ */
+ public void configureInstance(Component c, Object imp, String containerName) {
+ if (imp.equals(NeutronFloatingIPInterface.class)) {
+ // export the service
+ c.setInterface(
+ new String[] { INeutronFloatingIPCRUD.class.getName() }, null);
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put("salListenerName", "neutron");
+ c.add(createContainerServiceDependency(containerName)
+ .setService(IClusterContainerServices.class)
+ .setCallbacks("setClusterContainerService",
+ "unsetClusterContainerService").setRequired(true));
+ }
+ if (imp.equals(NeutronRouterInterface.class)) {
+ // export the service
+ c.setInterface(
+ new String[] { INeutronRouterCRUD.class.getName() }, null);
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put("salListenerName", "neutron");
+ c.add(createContainerServiceDependency(containerName)
+ .setService(IClusterContainerServices.class)
+ .setCallbacks("setClusterContainerService",
+ "unsetClusterContainerService").setRequired(true));
+ }
+ if (imp.equals(NeutronPortInterface.class)) {
+ // export the service
+ c.setInterface(
+ new String[] { INeutronPortCRUD.class.getName() }, null);
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put("salListenerName", "neutron");
+ c.add(createContainerServiceDependency(containerName)
+ .setService(IClusterContainerServices.class)
+ .setCallbacks("setClusterContainerService",
+ "unsetClusterContainerService").setRequired(true));
+ }
+ if (imp.equals(NeutronSubnetInterface.class)) {
+ // export the service
+ c.setInterface(
+ new String[] { INeutronSubnetCRUD.class.getName() }, null);
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put("salListenerName", "neutron");
+ c.add(createContainerServiceDependency(containerName)
+ .setService(IClusterContainerServices.class)
+ .setCallbacks("setClusterContainerService",
+ "unsetClusterContainerService").setRequired(true));
+ }
+ if (imp.equals(NeutronNetworkInterface.class)) {
+ // export the service
+ c.setInterface(
+ new String[] { INeutronNetworkCRUD.class.getName() }, null);
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put("salListenerName", "neutron");
+ c.add(createContainerServiceDependency(containerName)
+ .setService(IClusterContainerServices.class)
+ .setCallbacks("setClusterContainerService",
+ "unsetClusterContainerService").setRequired(true));
+ }
+ }
+}
-/*\r
- * Copyright IBM Corporation, 2013. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.networkconfig.neutron.implementation;\r
-\r
-import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
-import java.util.Dictionary;\r
-import java.util.EnumSet;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.Map.Entry;\r
-import java.util.concurrent.ConcurrentMap;\r
-\r
-import org.apache.felix.dm.Component;\r
-import org.opendaylight.controller.clustering.services.CacheConfigException;\r
-import org.opendaylight.controller.clustering.services.CacheExistException;\r
-import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
-import org.opendaylight.controller.clustering.services.IClusterServices;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronFloatingIP;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronPort;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NeutronFloatingIPInterface implements INeutronFloatingIPCRUD {\r
- private static final Logger logger = LoggerFactory.getLogger(NeutronFloatingIPInterface.class);\r
- private String containerName = null;\r
-\r
- private IClusterContainerServices clusterContainerService = null;\r
- private ConcurrentMap<String, NeutronFloatingIP> floatingIPDB;\r
-\r
- // methods needed for creating caches\r
-\r
- void setClusterContainerService(IClusterContainerServices s) {\r
- logger.debug("Cluster Service set");\r
- this.clusterContainerService = s;\r
- }\r
-\r
- void unsetClusterContainerService(IClusterContainerServices s) {\r
- if (this.clusterContainerService == s) {\r
- logger.debug("Cluster Service removed!");\r
- this.clusterContainerService = null;\r
- }\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void allocateCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't create cache");\r
- return;\r
- }\r
- logger.debug("Creating Cache for Neutron FloatingIPs");\r
- try {\r
- // neutron caches\r
- this.clusterContainerService.createCache("neutronFloatingIPs",\r
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
- } catch (CacheConfigException cce) {\r
- logger.error("Cache couldn't be created for Neutron - check cache mode");\r
- } catch (CacheExistException cce) {\r
- logger.error("Cache for Neutron already exists, destroy and recreate");\r
- }\r
- logger.debug("Cache successfully created for NeutronFloatingIps");\r
- }\r
-\r
- @SuppressWarnings({ "unchecked", "deprecation" })\r
- private void retrieveCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
- return;\r
- }\r
-\r
- logger.debug("Retrieving cache for Neutron FloatingIPs");\r
- floatingIPDB = (ConcurrentMap<String, NeutronFloatingIP>) this.clusterContainerService\r
- .getCache("neutronFloatingIPs");\r
- if (floatingIPDB == null) {\r
- logger.error("Cache couldn't be retrieved for Neutron FloatingIPs");\r
- }\r
- logger.debug("Cache was successfully retrieved for Neutron FloatingIPs");\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void destroyCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterMger, can't destroy cache");\r
- return;\r
- }\r
- logger.debug("Destroying Cache for HostTracker");\r
- this.clusterContainerService.destroyCache("neutronFloatingIPs");\r
- }\r
-\r
- private void startUp() {\r
- allocateCache();\r
- retrieveCache();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when all the required\r
- * dependencies are satisfied\r
- *\r
- */\r
- void init(Component c) {\r
- Dictionary<?, ?> props = c.getServiceProperties();\r
- if (props != null) {\r
- this.containerName = (String) props.get("containerName");\r
- logger.debug("Running containerName: {}", this.containerName);\r
- } else {\r
- // In the Global instance case the containerName is empty\r
- this.containerName = "";\r
- }\r
- startUp();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when at least one dependency\r
- * become unsatisfied or when the component is shutting down because for\r
- * example bundle is being stopped.\r
- *\r
- */\r
- void destroy() {\r
- destroyCache();\r
- }\r
-\r
- /**\r
- * Function called by dependency manager after "init ()" is called and after\r
- * the services provided by the class are registered in the service registry\r
- *\r
- */\r
- void start() {\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager before the services exported by\r
- * the component are unregistered, this will be followed by a "destroy ()"\r
- * calls\r
- *\r
- */\r
- void stop() {\r
- }\r
-\r
- // this method uses reflection to update an object from it's delta.\r
-\r
- private boolean overwrite(Object target, Object delta) {\r
- Method[] methods = target.getClass().getMethods();\r
-\r
- for(Method toMethod: methods){\r
- if(toMethod.getDeclaringClass().equals(target.getClass())\r
- && toMethod.getName().startsWith("set")){\r
-\r
- String toName = toMethod.getName();\r
- String fromName = toName.replace("set", "get");\r
-\r
- try {\r
- Method fromMethod = delta.getClass().getMethod(fromName);\r
- Object value = fromMethod.invoke(delta, (Object[])null);\r
- if(value != null){\r
- toMethod.invoke(target, value);\r
- }\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- return false;\r
- }\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- // IfNBFloatingIPCRUD interface methods\r
-\r
- public boolean floatingIPExists(String uuid) {\r
- return floatingIPDB.containsKey(uuid);\r
- }\r
-\r
- public NeutronFloatingIP getFloatingIP(String uuid) {\r
- if (!floatingIPExists(uuid))\r
- return null;\r
- return floatingIPDB.get(uuid);\r
- }\r
-\r
- public List<NeutronFloatingIP> getAllFloatingIPs() {\r
- Set<NeutronFloatingIP> allIPs = new HashSet<NeutronFloatingIP>();\r
- for (Entry<String, NeutronFloatingIP> entry : floatingIPDB.entrySet()) {\r
- NeutronFloatingIP floatingip = entry.getValue();\r
- allIPs.add(floatingip);\r
- }\r
- logger.debug("Exiting getAllFloatingIPs, Found {} FloatingIPs", allIPs.size());\r
- List<NeutronFloatingIP> ans = new ArrayList<NeutronFloatingIP>();\r
- ans.addAll(allIPs);\r
- return ans;\r
- }\r
-\r
- public boolean addFloatingIP(NeutronFloatingIP input) {\r
- INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
- INeutronSubnetCRUD subnetCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
- INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);\r
-\r
- if (floatingIPExists(input.getID()))\r
- return false;\r
- //if floating_ip_address isn't there, allocate from the subnet pool\r
- NeutronSubnet subnet = subnetCRUD.getSubnet(networkCRUD.getNetwork(input.getFloatingNetworkUUID()).getSubnets().get(0));\r
- if (input.getFloatingIPAddress() == null)\r
- input.setFloatingIPAddress(subnet.getLowAddr());\r
- subnet.allocateIP(input.getFloatingIPAddress());\r
-\r
- //if port_id is there, bind port to this floating ip\r
- if (input.getPortUUID() != null) {\r
- NeutronPort port = portCRUD.getPort(input.getPortUUID());\r
- port.addFloatingIP(input.getFixedIPAddress(), input);\r
- }\r
-\r
- floatingIPDB.putIfAbsent(input.getID(), input);\r
- return true;\r
- }\r
-\r
- public boolean removeFloatingIP(String uuid) {\r
- INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
- INeutronSubnetCRUD subnetCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
- INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);\r
-\r
- if (!floatingIPExists(uuid))\r
- return false;\r
- NeutronFloatingIP floatIP = getFloatingIP(uuid);\r
- //if floating_ip_address isn't there, allocate from the subnet pool\r
- NeutronSubnet subnet = subnetCRUD.getSubnet(networkCRUD.getNetwork(floatIP.getFloatingNetworkUUID()).getSubnets().get(0));\r
- subnet.releaseIP(floatIP.getFloatingIPAddress());\r
- if (floatIP.getPortUUID() != null) {\r
- NeutronPort port = portCRUD.getPort(floatIP.getPortUUID());\r
- port.removeFloatingIP(floatIP.getFixedIPAddress());\r
- }\r
- floatingIPDB.remove(uuid);\r
- return true;\r
- }\r
-\r
- public boolean updateFloatingIP(String uuid, NeutronFloatingIP delta) {\r
- INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);\r
-\r
- if (!floatingIPExists(uuid))\r
- return false;\r
- NeutronFloatingIP target = floatingIPDB.get(uuid);\r
- if (target.getPortUUID() != null) {\r
- NeutronPort port = portCRUD.getPort(target.getPortUUID());\r
- port.removeFloatingIP(target.getFixedIPAddress());\r
- }\r
-\r
- //if port_id is there, bind port to this floating ip\r
- if (delta.getPortUUID() != null) {\r
- NeutronPort port = portCRUD.getPort(delta.getPortUUID());\r
- port.addFloatingIP(delta.getFixedIPAddress(), delta);\r
- }\r
-\r
- target.setPortUUID(delta.getPortUUID());\r
- target.setFixedIPAddress(delta.getFixedIPAddress());\r
- return true;\r
- }\r
-}\r
+/*
+ * Copyright IBM Corporation, 2013. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.networkconfig.neutron.implementation;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.felix.dm.Component;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.IClusterContainerServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
+import org.opendaylight.controller.networkconfig.neutron.INeutronFloatingIPCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
+import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;
+import org.opendaylight.controller.networkconfig.neutron.NeutronFloatingIP;
+import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
+import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronFloatingIPInterface implements INeutronFloatingIPCRUD {
+ private static final Logger logger = LoggerFactory.getLogger(NeutronFloatingIPInterface.class);
+ private String containerName = null;
+
+ private IClusterContainerServices clusterContainerService = null;
+ private ConcurrentMap<String, NeutronFloatingIP> floatingIPDB;
+
+ // methods needed for creating caches
+
+ void setClusterContainerService(IClusterContainerServices s) {
+ logger.debug("Cluster Service set");
+ this.clusterContainerService = s;
+ }
+
+ void unsetClusterContainerService(IClusterContainerServices s) {
+ if (this.clusterContainerService == s) {
+ logger.debug("Cluster Service removed!");
+ this.clusterContainerService = null;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private void allocateCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't create cache");
+ return;
+ }
+ logger.debug("Creating Cache for Neutron FloatingIPs");
+ try {
+ // neutron caches
+ this.clusterContainerService.createCache("neutronFloatingIPs",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ } catch (CacheConfigException cce) {
+ logger.error("Cache couldn't be created for Neutron - check cache mode");
+ } catch (CacheExistException cce) {
+ logger.error("Cache for Neutron already exists, destroy and recreate");
+ }
+ logger.debug("Cache successfully created for NeutronFloatingIps");
+ }
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ private void retrieveCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't retrieve cache");
+ return;
+ }
+
+ logger.debug("Retrieving cache for Neutron FloatingIPs");
+ floatingIPDB = (ConcurrentMap<String, NeutronFloatingIP>) this.clusterContainerService
+ .getCache("neutronFloatingIPs");
+ if (floatingIPDB == null) {
+ logger.error("Cache couldn't be retrieved for Neutron FloatingIPs");
+ }
+ logger.debug("Cache was successfully retrieved for Neutron FloatingIPs");
+ }
+
+ @SuppressWarnings("deprecation")
+ private void destroyCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterMger, can't destroy cache");
+ return;
+ }
+ logger.debug("Destroying Cache for HostTracker");
+ this.clusterContainerService.destroyCache("neutronFloatingIPs");
+ }
+
+ private void startUp() {
+ allocateCache();
+ retrieveCache();
+ }
+
+ /**
+ * Function called by the dependency manager when all the required
+ * dependencies are satisfied
+ *
+ */
+ void init(Component c) {
+ Dictionary<?, ?> props = c.getServiceProperties();
+ if (props != null) {
+ this.containerName = (String) props.get("containerName");
+ logger.debug("Running containerName: {}", this.containerName);
+ } else {
+ // In the Global instance case the containerName is empty
+ this.containerName = "";
+ }
+ startUp();
+ }
+
+ /**
+ * Function called by the dependency manager when at least one dependency
+ * become unsatisfied or when the component is shutting down because for
+ * example bundle is being stopped.
+ *
+ */
+ void destroy() {
+ destroyCache();
+ }
+
+ /**
+ * Function called by dependency manager after "init ()" is called and after
+ * the services provided by the class are registered in the service registry
+ *
+ */
+ void start() {
+ }
+
+ /**
+ * Function called by the dependency manager before the services exported by
+ * the component are unregistered, this will be followed by a "destroy ()"
+ * calls
+ *
+ */
+ void stop() {
+ }
+
+ // this method uses reflection to update an object from it's delta.
+
+ private boolean overwrite(Object target, Object delta) {
+ Method[] methods = target.getClass().getMethods();
+
+ for(Method toMethod: methods){
+ if(toMethod.getDeclaringClass().equals(target.getClass())
+ && toMethod.getName().startsWith("set")){
+
+ String toName = toMethod.getName();
+ String fromName = toName.replace("set", "get");
+
+ try {
+ Method fromMethod = delta.getClass().getMethod(fromName);
+ Object value = fromMethod.invoke(delta, (Object[])null);
+ if(value != null){
+ toMethod.invoke(target, value);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ // IfNBFloatingIPCRUD interface methods
+
+ public boolean floatingIPExists(String uuid) {
+ return floatingIPDB.containsKey(uuid);
+ }
+
+ public NeutronFloatingIP getFloatingIP(String uuid) {
+ if (!floatingIPExists(uuid))
+ return null;
+ return floatingIPDB.get(uuid);
+ }
+
+ public List<NeutronFloatingIP> getAllFloatingIPs() {
+ Set<NeutronFloatingIP> allIPs = new HashSet<NeutronFloatingIP>();
+ for (Entry<String, NeutronFloatingIP> entry : floatingIPDB.entrySet()) {
+ NeutronFloatingIP floatingip = entry.getValue();
+ allIPs.add(floatingip);
+ }
+ logger.debug("Exiting getAllFloatingIPs, Found {} FloatingIPs", allIPs.size());
+ List<NeutronFloatingIP> ans = new ArrayList<NeutronFloatingIP>();
+ ans.addAll(allIPs);
+ return ans;
+ }
+
+ public boolean addFloatingIP(NeutronFloatingIP input) {
+ INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
+ INeutronSubnetCRUD subnetCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+ INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);
+
+ if (floatingIPExists(input.getID()))
+ return false;
+ //if floating_ip_address isn't there, allocate from the subnet pool
+ NeutronSubnet subnet = subnetCRUD.getSubnet(networkCRUD.getNetwork(input.getFloatingNetworkUUID()).getSubnets().get(0));
+ if (input.getFloatingIPAddress() == null)
+ input.setFloatingIPAddress(subnet.getLowAddr());
+ subnet.allocateIP(input.getFloatingIPAddress());
+
+ //if port_id is there, bind port to this floating ip
+ if (input.getPortUUID() != null) {
+ NeutronPort port = portCRUD.getPort(input.getPortUUID());
+ port.addFloatingIP(input.getFixedIPAddress(), input);
+ }
+
+ floatingIPDB.putIfAbsent(input.getID(), input);
+ return true;
+ }
+
+ public boolean removeFloatingIP(String uuid) {
+ INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
+ INeutronSubnetCRUD subnetCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+ INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);
+
+ if (!floatingIPExists(uuid))
+ return false;
+ NeutronFloatingIP floatIP = getFloatingIP(uuid);
+ //if floating_ip_address isn't there, allocate from the subnet pool
+ NeutronSubnet subnet = subnetCRUD.getSubnet(networkCRUD.getNetwork(floatIP.getFloatingNetworkUUID()).getSubnets().get(0));
+ subnet.releaseIP(floatIP.getFloatingIPAddress());
+ if (floatIP.getPortUUID() != null) {
+ NeutronPort port = portCRUD.getPort(floatIP.getPortUUID());
+ port.removeFloatingIP(floatIP.getFixedIPAddress());
+ }
+ floatingIPDB.remove(uuid);
+ return true;
+ }
+
+ public boolean updateFloatingIP(String uuid, NeutronFloatingIP delta) {
+ INeutronPortCRUD portCRUD = NeutronCRUDInterfaces.getINeutronPortCRUD(this);
+
+ if (!floatingIPExists(uuid))
+ return false;
+ NeutronFloatingIP target = floatingIPDB.get(uuid);
+ if (target.getPortUUID() != null) {
+ NeutronPort port = portCRUD.getPort(target.getPortUUID());
+ port.removeFloatingIP(target.getFixedIPAddress());
+ }
+
+ //if port_id is there, bind port to this floating ip
+ if (delta.getPortUUID() != null) {
+ NeutronPort port = portCRUD.getPort(delta.getPortUUID());
+ port.addFloatingIP(delta.getFixedIPAddress(), delta);
+ }
+
+ target.setPortUUID(delta.getPortUUID());
+ target.setFixedIPAddress(delta.getFixedIPAddress());
+ return true;
+ }
+}
-/*\r
- * Copyright IBM Corporation, 2013. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.networkconfig.neutron.implementation;\r
-\r
-import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
-import java.util.Dictionary;\r
-import java.util.EnumSet;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.Map.Entry;\r
-import java.util.concurrent.ConcurrentMap;\r
-\r
-import org.apache.felix.dm.Component;\r
-import org.opendaylight.controller.clustering.services.CacheConfigException;\r
-import org.opendaylight.controller.clustering.services.CacheExistException;\r
-import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
-import org.opendaylight.controller.clustering.services.IClusterServices;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NeutronNetworkInterface implements INeutronNetworkCRUD {\r
- private static final Logger logger = LoggerFactory.getLogger(NeutronNetworkInterface.class);\r
- private String containerName = null;\r
-\r
- private ConcurrentMap<String, NeutronNetwork> networkDB;\r
- private IClusterContainerServices clusterContainerService = null;\r
-\r
- // methods needed for creating caches\r
-\r
- void setClusterContainerService(IClusterContainerServices s) {\r
- logger.debug("Cluster Service set");\r
- this.clusterContainerService = s;\r
- }\r
-\r
- void unsetClusterContainerService(IClusterContainerServices s) {\r
- if (this.clusterContainerService == s) {\r
- logger.debug("Cluster Service removed!");\r
- this.clusterContainerService = null;\r
- }\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void allocateCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't create cache");\r
- return;\r
- }\r
- logger.debug("Creating Cache for Neutron Networks");\r
- try {\r
- // neutron caches\r
- this.clusterContainerService.createCache("neutronNetworks",\r
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
- } catch (CacheConfigException cce) {\r
- logger.error("Cache couldn't be created for Neutron Networks - check cache mode");\r
- } catch (CacheExistException cce) {\r
- logger.error("Cache for Neutron Networks already exists, destroy and recreate");\r
- }\r
- logger.debug("Cache successfully created for Neutron Networks");\r
- }\r
-\r
- @SuppressWarnings({ "unchecked", "deprecation" })\r
- private void retrieveCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
- return;\r
- }\r
- logger.debug("Retrieving cache for Neutron Networks");\r
- networkDB = (ConcurrentMap<String, NeutronNetwork>) this.clusterContainerService.getCache("neutronNetworks");\r
- if (networkDB == null) {\r
- logger.error("Cache couldn't be retrieved for Neutron Networks");\r
- }\r
- logger.debug("Cache was successfully retrieved for Neutron Networks");\r
- }\r
-\r
- private void startUp() {\r
- allocateCache();\r
- retrieveCache();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when all the required\r
- * dependencies are satisfied\r
- *\r
- */\r
- void init(Component c) {\r
- Dictionary<?, ?> props = c.getServiceProperties();\r
- if (props != null) {\r
- this.containerName = (String) props.get("containerName");\r
- logger.debug("Running containerName: {}", this.containerName);\r
- } else {\r
- // In the Global instance case the containerName is empty\r
- this.containerName = "";\r
- }\r
- startUp();\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void destroyCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterMger, can't destroy cache");\r
- return;\r
- }\r
- logger.debug("Destroying Cache for Neutron Networks");\r
- this.clusterContainerService.destroyCache("Neutron Networks");\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when at least one dependency\r
- * become unsatisfied or when the component is shutting down because for\r
- * example bundle is being stopped.\r
- *\r
- */\r
- void destroy() {\r
- destroyCache();\r
- }\r
-\r
- /**\r
- * Function called by dependency manager after "init ()" is called and after\r
- * the services provided by the class are registered in the service registry\r
- *\r
- */\r
- void start() {\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager before the services exported by\r
- * the component are unregistered, this will be followed by a "destroy ()"\r
- * calls\r
- *\r
- */\r
- void stop() {\r
- }\r
-\r
- // this method uses reflection to update an object from it's delta.\r
-\r
- private boolean overwrite(Object target, Object delta) {\r
- Method[] methods = target.getClass().getMethods();\r
-\r
- for(Method toMethod: methods){\r
- if(toMethod.getDeclaringClass().equals(target.getClass())\r
- && toMethod.getName().startsWith("set")){\r
-\r
- String toName = toMethod.getName();\r
- String fromName = toName.replace("set", "get");\r
-\r
- try {\r
- Method fromMethod = delta.getClass().getMethod(fromName);\r
- Object value = fromMethod.invoke(delta, (Object[])null);\r
- if(value != null){\r
- toMethod.invoke(target, value);\r
- }\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- return false;\r
- }\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- // IfNBNetworkCRUD methods\r
-\r
- public boolean networkExists(String uuid) {\r
- return networkDB.containsKey(uuid);\r
- }\r
-\r
- public NeutronNetwork getNetwork(String uuid) {\r
- if (!networkExists(uuid))\r
- return null;\r
- return networkDB.get(uuid);\r
- }\r
-\r
- public List<NeutronNetwork> getAllNetworks() {\r
- Set<NeutronNetwork> allNetworks = new HashSet<NeutronNetwork>();\r
- for (Entry<String, NeutronNetwork> entry : networkDB.entrySet()) {\r
- NeutronNetwork network = entry.getValue();\r
- allNetworks.add(network);\r
- }\r
- logger.debug("Exiting getAllNetworks, Found {} OpenStackNetworks", allNetworks.size());\r
- List<NeutronNetwork> ans = new ArrayList<NeutronNetwork>();\r
- ans.addAll(allNetworks);\r
- return ans;\r
- }\r
-\r
- public boolean addNetwork(NeutronNetwork input) {\r
- if (networkExists(input.getID()))\r
- return false;\r
- networkDB.putIfAbsent(input.getID(), input);\r
- //TODO: add code to find INeutronNetworkAware services and call newtorkCreated on them\r
- return true;\r
- }\r
-\r
- public boolean removeNetwork(String uuid) {\r
- if (!networkExists(uuid))\r
- return false;\r
- networkDB.remove(uuid);\r
- //TODO: add code to find INeutronNetworkAware services and call newtorkDeleted on them\r
- return true;\r
- }\r
-\r
- public boolean updateNetwork(String uuid, NeutronNetwork delta) {\r
- if (!networkExists(uuid))\r
- return false;\r
- NeutronNetwork target = networkDB.get(uuid);\r
- return overwrite(target, delta);\r
- }\r
-\r
- public boolean networkInUse(String netUUID) {\r
- if (!networkExists(netUUID))\r
- return true;\r
- NeutronNetwork target = networkDB.get(netUUID);\r
- if (target.getPortsOnNetwork().size() > 0)\r
- return true;\r
- return false;\r
- }\r
-}\r
+/*
+ * Copyright IBM Corporation, 2013. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.networkconfig.neutron.implementation;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.felix.dm.Component;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.IClusterContainerServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronNetworkInterface implements INeutronNetworkCRUD {
+ private static final Logger logger = LoggerFactory.getLogger(NeutronNetworkInterface.class);
+ private String containerName = null;
+
+ private ConcurrentMap<String, NeutronNetwork> networkDB;
+ private IClusterContainerServices clusterContainerService = null;
+
+ // methods needed for creating caches
+
+ void setClusterContainerService(IClusterContainerServices s) {
+ logger.debug("Cluster Service set");
+ this.clusterContainerService = s;
+ }
+
+ void unsetClusterContainerService(IClusterContainerServices s) {
+ if (this.clusterContainerService == s) {
+ logger.debug("Cluster Service removed!");
+ this.clusterContainerService = null;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private void allocateCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't create cache");
+ return;
+ }
+ logger.debug("Creating Cache for Neutron Networks");
+ try {
+ // neutron caches
+ this.clusterContainerService.createCache("neutronNetworks",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ } catch (CacheConfigException cce) {
+ logger.error("Cache couldn't be created for Neutron Networks - check cache mode");
+ } catch (CacheExistException cce) {
+ logger.error("Cache for Neutron Networks already exists, destroy and recreate");
+ }
+ logger.debug("Cache successfully created for Neutron Networks");
+ }
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ private void retrieveCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't retrieve cache");
+ return;
+ }
+ logger.debug("Retrieving cache for Neutron Networks");
+ networkDB = (ConcurrentMap<String, NeutronNetwork>) this.clusterContainerService.getCache("neutronNetworks");
+ if (networkDB == null) {
+ logger.error("Cache couldn't be retrieved for Neutron Networks");
+ }
+ logger.debug("Cache was successfully retrieved for Neutron Networks");
+ }
+
+ private void startUp() {
+ allocateCache();
+ retrieveCache();
+ }
+
+ /**
+ * Function called by the dependency manager when all the required
+ * dependencies are satisfied
+ *
+ */
+ void init(Component c) {
+ Dictionary<?, ?> props = c.getServiceProperties();
+ if (props != null) {
+ this.containerName = (String) props.get("containerName");
+ logger.debug("Running containerName: {}", this.containerName);
+ } else {
+ // In the Global instance case the containerName is empty
+ this.containerName = "";
+ }
+ startUp();
+ }
+
+ @SuppressWarnings("deprecation")
+ private void destroyCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterMger, can't destroy cache");
+ return;
+ }
+ logger.debug("Destroying Cache for Neutron Networks");
+ this.clusterContainerService.destroyCache("Neutron Networks");
+ }
+
+ /**
+ * Function called by the dependency manager when at least one dependency
+ * become unsatisfied or when the component is shutting down because for
+ * example bundle is being stopped.
+ *
+ */
+ void destroy() {
+ destroyCache();
+ }
+
+ /**
+ * Function called by dependency manager after "init ()" is called and after
+ * the services provided by the class are registered in the service registry
+ *
+ */
+ void start() {
+ }
+
+ /**
+ * Function called by the dependency manager before the services exported by
+ * the component are unregistered, this will be followed by a "destroy ()"
+ * calls
+ *
+ */
+ void stop() {
+ }
+
+ // this method uses reflection to update an object from it's delta.
+
+ private boolean overwrite(Object target, Object delta) {
+ Method[] methods = target.getClass().getMethods();
+
+ for(Method toMethod: methods){
+ if(toMethod.getDeclaringClass().equals(target.getClass())
+ && toMethod.getName().startsWith("set")){
+
+ String toName = toMethod.getName();
+ String fromName = toName.replace("set", "get");
+
+ try {
+ Method fromMethod = delta.getClass().getMethod(fromName);
+ Object value = fromMethod.invoke(delta, (Object[])null);
+ if(value != null){
+ toMethod.invoke(target, value);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ // IfNBNetworkCRUD methods
+
+ public boolean networkExists(String uuid) {
+ return networkDB.containsKey(uuid);
+ }
+
+ public NeutronNetwork getNetwork(String uuid) {
+ if (!networkExists(uuid))
+ return null;
+ return networkDB.get(uuid);
+ }
+
+ public List<NeutronNetwork> getAllNetworks() {
+ Set<NeutronNetwork> allNetworks = new HashSet<NeutronNetwork>();
+ for (Entry<String, NeutronNetwork> entry : networkDB.entrySet()) {
+ NeutronNetwork network = entry.getValue();
+ allNetworks.add(network);
+ }
+ logger.debug("Exiting getAllNetworks, Found {} OpenStackNetworks", allNetworks.size());
+ List<NeutronNetwork> ans = new ArrayList<NeutronNetwork>();
+ ans.addAll(allNetworks);
+ return ans;
+ }
+
+ public boolean addNetwork(NeutronNetwork input) {
+ if (networkExists(input.getID()))
+ return false;
+ networkDB.putIfAbsent(input.getID(), input);
+ //TODO: add code to find INeutronNetworkAware services and call newtorkCreated on them
+ return true;
+ }
+
+ public boolean removeNetwork(String uuid) {
+ if (!networkExists(uuid))
+ return false;
+ networkDB.remove(uuid);
+ //TODO: add code to find INeutronNetworkAware services and call newtorkDeleted on them
+ return true;
+ }
+
+ public boolean updateNetwork(String uuid, NeutronNetwork delta) {
+ if (!networkExists(uuid))
+ return false;
+ NeutronNetwork target = networkDB.get(uuid);
+ return overwrite(target, delta);
+ }
+
+ public boolean networkInUse(String netUUID) {
+ if (!networkExists(netUUID))
+ return true;
+ NeutronNetwork target = networkDB.get(netUUID);
+ if (target.getPortsOnNetwork().size() > 0)
+ return true;
+ return false;
+ }
+}
-/*\r
- * Copyright IBM Corporation, 2013. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.networkconfig.neutron.implementation;\r
-\r
-import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
-import java.util.Dictionary;\r
-import java.util.EnumSet;\r
-import java.util.HashSet;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.Map.Entry;\r
-import java.util.concurrent.ConcurrentMap;\r
-\r
-import org.apache.felix.dm.Component;\r
-import org.opendaylight.controller.clustering.services.CacheConfigException;\r
-import org.opendaylight.controller.clustering.services.CacheExistException;\r
-import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
-import org.opendaylight.controller.clustering.services.IClusterServices;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronPort;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;\r
-import org.opendaylight.controller.networkconfig.neutron.Neutron_IPs;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NeutronPortInterface implements INeutronPortCRUD {\r
- private static final Logger logger = LoggerFactory.getLogger(NeutronPortInterface.class);\r
- private String containerName = null;\r
-\r
- private IClusterContainerServices clusterContainerService = null;\r
- private ConcurrentMap<String, NeutronPort> portDB;\r
-\r
- // methods needed for creating caches\r
-\r
- void setClusterContainerService(IClusterContainerServices s) {\r
- logger.debug("Cluster Service set");\r
- clusterContainerService = s;\r
- }\r
-\r
- void unsetClusterContainerService(IClusterContainerServices s) {\r
- if (clusterContainerService == s) {\r
- logger.debug("Cluster Service removed!");\r
- clusterContainerService = null;\r
- }\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void allocateCache() {\r
- if (clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't create cache");\r
- return;\r
- }\r
- logger.debug("Creating Cache for OpenDOVE");\r
- try {\r
- // neutron caches\r
- clusterContainerService.createCache("neutronPorts",\r
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
- } catch (CacheConfigException cce) {\r
- logger.error("Cache couldn't be created for OpenDOVE - check cache mode");\r
- } catch (CacheExistException cce) {\r
- logger.error("Cache for OpenDOVE already exists, destroy and recreate");\r
- }\r
- logger.debug("Cache successfully created for OpenDOVE");\r
- }\r
-\r
- @SuppressWarnings({ "unchecked", "deprecation" })\r
- private void retrieveCache() {\r
- if (clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
- return;\r
- }\r
-\r
- logger.debug("Retrieving cache for Neutron Ports");\r
- portDB = (ConcurrentMap<String, NeutronPort>) clusterContainerService\r
- .getCache("neutronPorts");\r
- if (portDB == null) {\r
- logger.error("Cache couldn't be retrieved for Neutron Ports");\r
- }\r
- logger.debug("Cache was successfully retrieved for Neutron Ports");\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void destroyCache() {\r
- if (clusterContainerService == null) {\r
- logger.error("un-initialized clusterMger, can't destroy cache");\r
- return;\r
- }\r
- logger.debug("Destroying Cache for HostTracker");\r
- clusterContainerService.destroyCache("neutronPorts");\r
- }\r
-\r
- private void startUp() {\r
- allocateCache();\r
- retrieveCache();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when all the required\r
- * dependencies are satisfied\r
- *\r
- */\r
- void init(Component c) {\r
- Dictionary<?, ?> props = c.getServiceProperties();\r
- if (props != null) {\r
- containerName = (String) props.get("containerName");\r
- logger.debug("Running containerName: {}", containerName);\r
- } else {\r
- // In the Global instance case the containerName is empty\r
- containerName = "";\r
- }\r
- startUp();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when at least one dependency\r
- * become unsatisfied or when the component is shutting down because for\r
- * example bundle is being stopped.\r
- *\r
- */\r
- void destroy() {\r
- destroyCache();\r
- }\r
-\r
- /**\r
- * Function called by dependency manager after "init ()" is called and after\r
- * the services provided by the class are registered in the service registry\r
- *\r
- */\r
- void start() {\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager before the services exported by\r
- * the component are unregistered, this will be followed by a "destroy ()"\r
- * calls\r
- *\r
- */\r
- void stop() {\r
- }\r
-\r
- // this method uses reflection to update an object from it's delta.\r
-\r
- private boolean overwrite(Object target, Object delta) {\r
- Method[] methods = target.getClass().getMethods();\r
-\r
- for(Method toMethod: methods){\r
- if(toMethod.getDeclaringClass().equals(target.getClass())\r
- && toMethod.getName().startsWith("set")){\r
-\r
- String toName = toMethod.getName();\r
- String fromName = toName.replace("set", "get");\r
-\r
- try {\r
- Method fromMethod = delta.getClass().getMethod(fromName);\r
- Object value = fromMethod.invoke(delta, (Object[])null);\r
- if(value != null){\r
- toMethod.invoke(target, value);\r
- }\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- return false;\r
- }\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- // IfNBPortCRUD methods\r
-\r
- @Override\r
- public boolean portExists(String uuid) {\r
- return portDB.containsKey(uuid);\r
- }\r
-\r
- @Override\r
- public NeutronPort getPort(String uuid) {\r
- if (!portExists(uuid)) {\r
- return null;\r
- }\r
- return portDB.get(uuid);\r
- }\r
-\r
- @Override\r
- public List<NeutronPort> getAllPorts() {\r
- Set<NeutronPort> allPorts = new HashSet<NeutronPort>();\r
- for (Entry<String, NeutronPort> entry : portDB.entrySet()) {\r
- NeutronPort port = entry.getValue();\r
- allPorts.add(port);\r
- }\r
- logger.debug("Exiting getAllPorts, Found {} OpenStackPorts", allPorts.size());\r
- List<NeutronPort> ans = new ArrayList<NeutronPort>();\r
- ans.addAll(allPorts);\r
- return ans;\r
- }\r
-\r
- @Override\r
- public boolean addPort(NeutronPort input) {\r
- if (portExists(input.getID())) {\r
- return false;\r
- }\r
- portDB.putIfAbsent(input.getID(), input);\r
- // if there are no fixed IPs, allocate one for each subnet in the network\r
- INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
- if (input.getFixedIPs().size() == 0) {\r
- List<Neutron_IPs> list = input.getFixedIPs();\r
- Iterator<NeutronSubnet> subnetIterator = systemCRUD.getAllSubnets().iterator();\r
- while (subnetIterator.hasNext()) {\r
- NeutronSubnet subnet = subnetIterator.next();\r
- if (subnet.getNetworkUUID().equals(input.getNetworkUUID())) {\r
- list.add(new Neutron_IPs(subnet.getID()));\r
- }\r
- }\r
- }\r
- Iterator<Neutron_IPs> fixedIPIterator = input.getFixedIPs().iterator();\r
- while (fixedIPIterator.hasNext()) {\r
- Neutron_IPs ip = fixedIPIterator.next();\r
- NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
- if (ip.getIpAddress() == null) {\r
- ip.setIpAddress(subnet.getLowAddr());\r
- }\r
- if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {\r
- subnet.allocateIP(ip.getIpAddress());\r
- }\r
- else {\r
- subnet.setGatewayIPAllocated();\r
- }\r
- subnet.addPort(input);\r
- }\r
- INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
-\r
- NeutronNetwork network = networkIf.getNetwork(input.getNetworkUUID());\r
- network.addPort(input);\r
- return true;\r
- }\r
-\r
- @Override\r
- public boolean removePort(String uuid) {\r
- if (!portExists(uuid)) {\r
- return false;\r
- }\r
- NeutronPort port = getPort(uuid);\r
- portDB.remove(uuid);\r
- INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
- INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
-\r
- NeutronNetwork network = networkCRUD.getNetwork(port.getNetworkUUID());\r
- network.removePort(port);\r
- Iterator<Neutron_IPs> fixedIPIterator = port.getFixedIPs().iterator();\r
- while (fixedIPIterator.hasNext()) {\r
- Neutron_IPs ip = fixedIPIterator.next();\r
- NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
- if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {\r
- subnet.releaseIP(ip.getIpAddress());\r
- }\r
- else {\r
- subnet.resetGatewayIPAllocated();\r
- }\r
- subnet.removePort(port);\r
- }\r
- return true;\r
- }\r
-\r
- @Override\r
- public boolean updatePort(String uuid, NeutronPort delta) {\r
- if (!portExists(uuid)) {\r
- return false;\r
- }\r
- NeutronPort target = portDB.get(uuid);\r
- // remove old Fixed_IPs\r
- if (delta.getFixedIPs() != null) {\r
- NeutronPort port = getPort(uuid);\r
- INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
- for (Neutron_IPs ip: port.getFixedIPs()) {\r
- NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
- subnet.releaseIP(ip.getIpAddress());\r
- }\r
-\r
- // allocate new Fixed_IPs\r
- for (Neutron_IPs ip: delta.getFixedIPs()) {\r
- NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());\r
- if (ip.getIpAddress() == null) {\r
- ip.setIpAddress(subnet.getLowAddr());\r
- }\r
- subnet.allocateIP(ip.getIpAddress());\r
- }\r
- }\r
- return overwrite(target, delta);\r
- }\r
-\r
- @Override\r
- public boolean macInUse(String macAddress) {\r
- List<NeutronPort> ports = getAllPorts();\r
- Iterator<NeutronPort> portIterator = ports.iterator();\r
- while (portIterator.hasNext()) {\r
- NeutronPort port = portIterator.next();\r
- if (macAddress.equalsIgnoreCase(port.getMacAddress())) {\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- @Override\r
- public NeutronPort getGatewayPort(String subnetUUID) {\r
- INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);\r
- NeutronSubnet subnet = systemCRUD.getSubnet(subnetUUID);\r
- Iterator<NeutronPort> portIterator = getAllPorts().iterator();\r
- while (portIterator.hasNext()) {\r
- NeutronPort port = portIterator.next();\r
- List<Neutron_IPs> fixedIPs = port.getFixedIPs();\r
- if (fixedIPs.size() == 1) {\r
- if (subnet.getGatewayIP().equals(fixedIPs.get(0).getIpAddress())) {\r
- return port;\r
- }\r
- }\r
- }\r
- return null;\r
- }\r
-\r
-}\r
+/*
+ * Copyright IBM Corporation, 2013. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.networkconfig.neutron.implementation;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.felix.dm.Component;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.IClusterContainerServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
+import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
+import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
+import org.opendaylight.controller.networkconfig.neutron.Neutron_IPs;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronPortInterface implements INeutronPortCRUD {
+ private static final Logger logger = LoggerFactory.getLogger(NeutronPortInterface.class);
+ private String containerName = null;
+
+ private IClusterContainerServices clusterContainerService = null;
+ private ConcurrentMap<String, NeutronPort> portDB;
+
+ // methods needed for creating caches
+
+ void setClusterContainerService(IClusterContainerServices s) {
+ logger.debug("Cluster Service set");
+ clusterContainerService = s;
+ }
+
+ void unsetClusterContainerService(IClusterContainerServices s) {
+ if (clusterContainerService == s) {
+ logger.debug("Cluster Service removed!");
+ clusterContainerService = null;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private void allocateCache() {
+ if (clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't create cache");
+ return;
+ }
+ logger.debug("Creating Cache for OpenDOVE");
+ try {
+ // neutron caches
+ clusterContainerService.createCache("neutronPorts",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ } catch (CacheConfigException cce) {
+ logger.error("Cache couldn't be created for OpenDOVE - check cache mode");
+ } catch (CacheExistException cce) {
+ logger.error("Cache for OpenDOVE already exists, destroy and recreate");
+ }
+ logger.debug("Cache successfully created for OpenDOVE");
+ }
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ private void retrieveCache() {
+ if (clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't retrieve cache");
+ return;
+ }
+
+ logger.debug("Retrieving cache for Neutron Ports");
+ portDB = (ConcurrentMap<String, NeutronPort>) clusterContainerService
+ .getCache("neutronPorts");
+ if (portDB == null) {
+ logger.error("Cache couldn't be retrieved for Neutron Ports");
+ }
+ logger.debug("Cache was successfully retrieved for Neutron Ports");
+ }
+
+ @SuppressWarnings("deprecation")
+ private void destroyCache() {
+ if (clusterContainerService == null) {
+ logger.error("un-initialized clusterMger, can't destroy cache");
+ return;
+ }
+ logger.debug("Destroying Cache for HostTracker");
+ clusterContainerService.destroyCache("neutronPorts");
+ }
+
+ private void startUp() {
+ allocateCache();
+ retrieveCache();
+ }
+
+ /**
+ * Function called by the dependency manager when all the required
+ * dependencies are satisfied
+ *
+ */
+ void init(Component c) {
+ Dictionary<?, ?> props = c.getServiceProperties();
+ if (props != null) {
+ containerName = (String) props.get("containerName");
+ logger.debug("Running containerName: {}", containerName);
+ } else {
+ // In the Global instance case the containerName is empty
+ containerName = "";
+ }
+ startUp();
+ }
+
+ /**
+ * Function called by the dependency manager when at least one dependency
+ * become unsatisfied or when the component is shutting down because for
+ * example bundle is being stopped.
+ *
+ */
+ void destroy() {
+ destroyCache();
+ }
+
+ /**
+ * Function called by dependency manager after "init ()" is called and after
+ * the services provided by the class are registered in the service registry
+ *
+ */
+ void start() {
+ }
+
+ /**
+ * Function called by the dependency manager before the services exported by
+ * the component are unregistered, this will be followed by a "destroy ()"
+ * calls
+ *
+ */
+ void stop() {
+ }
+
+ // this method uses reflection to update an object from it's delta.
+
+ private boolean overwrite(Object target, Object delta) {
+ Method[] methods = target.getClass().getMethods();
+
+ for(Method toMethod: methods){
+ if(toMethod.getDeclaringClass().equals(target.getClass())
+ && toMethod.getName().startsWith("set")){
+
+ String toName = toMethod.getName();
+ String fromName = toName.replace("set", "get");
+
+ try {
+ Method fromMethod = delta.getClass().getMethod(fromName);
+ Object value = fromMethod.invoke(delta, (Object[])null);
+ if(value != null){
+ toMethod.invoke(target, value);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ // IfNBPortCRUD methods
+
+ @Override
+ public boolean portExists(String uuid) {
+ return portDB.containsKey(uuid);
+ }
+
+ @Override
+ public NeutronPort getPort(String uuid) {
+ if (!portExists(uuid)) {
+ return null;
+ }
+ return portDB.get(uuid);
+ }
+
+ @Override
+ public List<NeutronPort> getAllPorts() {
+ Set<NeutronPort> allPorts = new HashSet<NeutronPort>();
+ for (Entry<String, NeutronPort> entry : portDB.entrySet()) {
+ NeutronPort port = entry.getValue();
+ allPorts.add(port);
+ }
+ logger.debug("Exiting getAllPorts, Found {} OpenStackPorts", allPorts.size());
+ List<NeutronPort> ans = new ArrayList<NeutronPort>();
+ ans.addAll(allPorts);
+ return ans;
+ }
+
+ @Override
+ public boolean addPort(NeutronPort input) {
+ if (portExists(input.getID())) {
+ return false;
+ }
+ portDB.putIfAbsent(input.getID(), input);
+ // if there are no fixed IPs, allocate one for each subnet in the network
+ INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+ if (input.getFixedIPs().size() == 0) {
+ List<Neutron_IPs> list = input.getFixedIPs();
+ Iterator<NeutronSubnet> subnetIterator = systemCRUD.getAllSubnets().iterator();
+ while (subnetIterator.hasNext()) {
+ NeutronSubnet subnet = subnetIterator.next();
+ if (subnet.getNetworkUUID().equals(input.getNetworkUUID())) {
+ list.add(new Neutron_IPs(subnet.getID()));
+ }
+ }
+ }
+ Iterator<Neutron_IPs> fixedIPIterator = input.getFixedIPs().iterator();
+ while (fixedIPIterator.hasNext()) {
+ Neutron_IPs ip = fixedIPIterator.next();
+ NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
+ if (ip.getIpAddress() == null) {
+ ip.setIpAddress(subnet.getLowAddr());
+ }
+ if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {
+ subnet.allocateIP(ip.getIpAddress());
+ }
+ else {
+ subnet.setGatewayIPAllocated();
+ }
+ subnet.addPort(input);
+ }
+ INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
+
+ NeutronNetwork network = networkIf.getNetwork(input.getNetworkUUID());
+ network.addPort(input);
+ return true;
+ }
+
+ @Override
+ public boolean removePort(String uuid) {
+ if (!portExists(uuid)) {
+ return false;
+ }
+ NeutronPort port = getPort(uuid);
+ portDB.remove(uuid);
+ INeutronNetworkCRUD networkCRUD = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
+ INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+
+ NeutronNetwork network = networkCRUD.getNetwork(port.getNetworkUUID());
+ network.removePort(port);
+ Iterator<Neutron_IPs> fixedIPIterator = port.getFixedIPs().iterator();
+ while (fixedIPIterator.hasNext()) {
+ Neutron_IPs ip = fixedIPIterator.next();
+ NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
+ if (!ip.getIpAddress().equals(subnet.getGatewayIP())) {
+ subnet.releaseIP(ip.getIpAddress());
+ }
+ else {
+ subnet.resetGatewayIPAllocated();
+ }
+ subnet.removePort(port);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updatePort(String uuid, NeutronPort delta) {
+ if (!portExists(uuid)) {
+ return false;
+ }
+ NeutronPort target = portDB.get(uuid);
+ // remove old Fixed_IPs
+ if (delta.getFixedIPs() != null) {
+ NeutronPort port = getPort(uuid);
+ INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+ for (Neutron_IPs ip: port.getFixedIPs()) {
+ NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
+ subnet.releaseIP(ip.getIpAddress());
+ }
+
+ // allocate new Fixed_IPs
+ for (Neutron_IPs ip: delta.getFixedIPs()) {
+ NeutronSubnet subnet = systemCRUD.getSubnet(ip.getSubnetUUID());
+ if (ip.getIpAddress() == null) {
+ ip.setIpAddress(subnet.getLowAddr());
+ }
+ subnet.allocateIP(ip.getIpAddress());
+ }
+ }
+ return overwrite(target, delta);
+ }
+
+ @Override
+ public boolean macInUse(String macAddress) {
+ List<NeutronPort> ports = getAllPorts();
+ Iterator<NeutronPort> portIterator = ports.iterator();
+ while (portIterator.hasNext()) {
+ NeutronPort port = portIterator.next();
+ if (macAddress.equalsIgnoreCase(port.getMacAddress())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public NeutronPort getGatewayPort(String subnetUUID) {
+ INeutronSubnetCRUD systemCRUD = NeutronCRUDInterfaces.getINeutronSubnetCRUD(this);
+ NeutronSubnet subnet = systemCRUD.getSubnet(subnetUUID);
+ Iterator<NeutronPort> portIterator = getAllPorts().iterator();
+ while (portIterator.hasNext()) {
+ NeutronPort port = portIterator.next();
+ List<Neutron_IPs> fixedIPs = port.getFixedIPs();
+ if (fixedIPs.size() == 1) {
+ if (subnet.getGatewayIP().equals(fixedIPs.get(0).getIpAddress())) {
+ return port;
+ }
+ }
+ }
+ return null;
+ }
+
+}
-/*\r
- * Copyright IBM Corporation, 2013. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.networkconfig.neutron.implementation;\r
-\r
-import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
-import java.util.Dictionary;\r
-import java.util.EnumSet;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.Map.Entry;\r
-import java.util.concurrent.ConcurrentMap;\r
-\r
-import org.apache.felix.dm.Component;\r
-import org.opendaylight.controller.clustering.services.CacheConfigException;\r
-import org.opendaylight.controller.clustering.services.CacheExistException;\r
-import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
-import org.opendaylight.controller.clustering.services.IClusterServices;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronRouterCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronRouter;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NeutronRouterInterface implements INeutronRouterCRUD {\r
- private static final Logger logger = LoggerFactory.getLogger(NeutronRouterInterface.class);\r
- private String containerName = null;\r
-\r
- private IClusterContainerServices clusterContainerService = null;\r
- private ConcurrentMap<String, NeutronRouter> routerDB;\r
- // methods needed for creating caches\r
-\r
- void setClusterContainerService(IClusterContainerServices s) {\r
- logger.debug("Cluster Service set");\r
- this.clusterContainerService = s;\r
- }\r
-\r
- void unsetClusterContainerService(IClusterContainerServices s) {\r
- if (this.clusterContainerService == s) {\r
- logger.debug("Cluster Service removed!");\r
- this.clusterContainerService = null;\r
- }\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void allocateCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't create cache");\r
- return;\r
- }\r
- logger.debug("Creating Cache for Neutron Routers");\r
- try {\r
- // neutron caches\r
- this.clusterContainerService.createCache("neutronRouters",\r
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
- } catch (CacheConfigException cce) {\r
- logger.error("Cache couldn't be created for Neutron Routers - check cache mode");\r
- } catch (CacheExistException cce) {\r
- logger.error("Cache for Neutron Routers already exists, destroy and recreate");\r
- }\r
- logger.debug("Cache successfully created for Neutron Routers");\r
- }\r
-\r
- @SuppressWarnings({ "unchecked", "deprecation" })\r
- private void retrieveCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
- return;\r
- }\r
-\r
- logger.debug("Retrieving cache for Neutron Routers");\r
- routerDB = (ConcurrentMap<String, NeutronRouter>) this.clusterContainerService\r
- .getCache("neutronRouters");\r
- if (routerDB == null) {\r
- logger.error("Cache couldn't be retrieved for Neutron Routers");\r
- }\r
- logger.debug("Cache was successfully retrieved for Neutron Routers");\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void destroyCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterMger, can't destroy cache");\r
- return;\r
- }\r
- logger.debug("Destroying Cache for HostTracker");\r
- this.clusterContainerService.destroyCache("neutronRouters");\r
- }\r
-\r
- private void startUp() {\r
- allocateCache();\r
- retrieveCache();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when all the required\r
- * dependencies are satisfied\r
- *\r
- */\r
- void init(Component c) {\r
- Dictionary<?, ?> props = c.getServiceProperties();\r
- if (props != null) {\r
- this.containerName = (String) props.get("containerName");\r
- logger.debug("Running containerName: {}", this.containerName);\r
- } else {\r
- // In the Global instance case the containerName is empty\r
- this.containerName = "";\r
- }\r
- startUp();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when at least one dependency\r
- * become unsatisfied or when the component is shutting down because for\r
- * example bundle is being stopped.\r
- *\r
- */\r
- void destroy() {\r
- destroyCache();\r
- }\r
-\r
- /**\r
- * Function called by dependency manager after "init ()" is called and after\r
- * the services provided by the class are registered in the service registry\r
- *\r
- */\r
- void start() {\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager before the services exported by\r
- * the component are unregistered, this will be followed by a "destroy ()"\r
- * calls\r
- *\r
- */\r
- void stop() {\r
- }\r
-\r
- // this method uses reflection to update an object from it's delta.\r
-\r
- private boolean overwrite(Object target, Object delta) {\r
- Method[] methods = target.getClass().getMethods();\r
-\r
- for(Method toMethod: methods){\r
- if(toMethod.getDeclaringClass().equals(target.getClass())\r
- && toMethod.getName().startsWith("set")){\r
-\r
- String toName = toMethod.getName();\r
- String fromName = toName.replace("set", "get");\r
-\r
- try {\r
- Method fromMethod = delta.getClass().getMethod(fromName);\r
- Object value = fromMethod.invoke(delta, (Object[])null);\r
- if(value != null){\r
- toMethod.invoke(target, value);\r
- }\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- return false;\r
- }\r
- }\r
- }\r
- return true;\r
- }\r
-\r
-\r
- // IfNBRouterCRUD Interface methods\r
-\r
- public boolean routerExists(String uuid) {\r
- return routerDB.containsKey(uuid);\r
- }\r
-\r
- public NeutronRouter getRouter(String uuid) {\r
- if (!routerExists(uuid))\r
- return null;\r
- return routerDB.get(uuid);\r
- }\r
-\r
- public List<NeutronRouter> getAllRouters() {\r
- Set<NeutronRouter> allRouters = new HashSet<NeutronRouter>();\r
- for (Entry<String, NeutronRouter> entry : routerDB.entrySet()) {\r
- NeutronRouter router = entry.getValue();\r
- allRouters.add(router);\r
- }\r
- logger.debug("Exiting getAllRouters, Found {} Routers", allRouters.size());\r
- List<NeutronRouter> ans = new ArrayList<NeutronRouter>();\r
- ans.addAll(allRouters);\r
- return ans;\r
- }\r
-\r
- public boolean addRouter(NeutronRouter input) {\r
- if (routerExists(input.getID()))\r
- return false;\r
- routerDB.putIfAbsent(input.getID(), input);\r
- return true;\r
- }\r
-\r
- public boolean removeRouter(String uuid) {\r
- if (!routerExists(uuid))\r
- return false;\r
- routerDB.remove(uuid);\r
- return true;\r
- }\r
-\r
- public boolean updateRouter(String uuid, NeutronRouter delta) {\r
- if (!routerExists(uuid))\r
- return false;\r
- NeutronRouter target = routerDB.get(uuid);\r
- return overwrite(target, delta);\r
- }\r
-\r
- public boolean routerInUse(String routerUUID) {\r
- if (!routerExists(routerUUID))\r
- return true;\r
- NeutronRouter target = routerDB.get(routerUUID);\r
- return (target.getInterfaces().size() > 0);\r
- }\r
-}\r
+/*
+ * Copyright IBM Corporation, 2013. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.networkconfig.neutron.implementation;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.felix.dm.Component;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.IClusterContainerServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
+import org.opendaylight.controller.networkconfig.neutron.INeutronRouterCRUD;
+import org.opendaylight.controller.networkconfig.neutron.NeutronRouter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronRouterInterface implements INeutronRouterCRUD {
+ private static final Logger logger = LoggerFactory.getLogger(NeutronRouterInterface.class);
+ private String containerName = null;
+
+ private IClusterContainerServices clusterContainerService = null;
+ private ConcurrentMap<String, NeutronRouter> routerDB;
+ // methods needed for creating caches
+
+ void setClusterContainerService(IClusterContainerServices s) {
+ logger.debug("Cluster Service set");
+ this.clusterContainerService = s;
+ }
+
+ void unsetClusterContainerService(IClusterContainerServices s) {
+ if (this.clusterContainerService == s) {
+ logger.debug("Cluster Service removed!");
+ this.clusterContainerService = null;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private void allocateCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't create cache");
+ return;
+ }
+ logger.debug("Creating Cache for Neutron Routers");
+ try {
+ // neutron caches
+ this.clusterContainerService.createCache("neutronRouters",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ } catch (CacheConfigException cce) {
+ logger.error("Cache couldn't be created for Neutron Routers - check cache mode");
+ } catch (CacheExistException cce) {
+ logger.error("Cache for Neutron Routers already exists, destroy and recreate");
+ }
+ logger.debug("Cache successfully created for Neutron Routers");
+ }
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ private void retrieveCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't retrieve cache");
+ return;
+ }
+
+ logger.debug("Retrieving cache for Neutron Routers");
+ routerDB = (ConcurrentMap<String, NeutronRouter>) this.clusterContainerService
+ .getCache("neutronRouters");
+ if (routerDB == null) {
+ logger.error("Cache couldn't be retrieved for Neutron Routers");
+ }
+ logger.debug("Cache was successfully retrieved for Neutron Routers");
+ }
+
+ @SuppressWarnings("deprecation")
+ private void destroyCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterMger, can't destroy cache");
+ return;
+ }
+ logger.debug("Destroying Cache for HostTracker");
+ this.clusterContainerService.destroyCache("neutronRouters");
+ }
+
+ private void startUp() {
+ allocateCache();
+ retrieveCache();
+ }
+
+ /**
+ * Function called by the dependency manager when all the required
+ * dependencies are satisfied
+ *
+ */
+ void init(Component c) {
+ Dictionary<?, ?> props = c.getServiceProperties();
+ if (props != null) {
+ this.containerName = (String) props.get("containerName");
+ logger.debug("Running containerName: {}", this.containerName);
+ } else {
+ // In the Global instance case the containerName is empty
+ this.containerName = "";
+ }
+ startUp();
+ }
+
+ /**
+ * Function called by the dependency manager when at least one dependency
+ * become unsatisfied or when the component is shutting down because for
+ * example bundle is being stopped.
+ *
+ */
+ void destroy() {
+ destroyCache();
+ }
+
+ /**
+ * Function called by dependency manager after "init ()" is called and after
+ * the services provided by the class are registered in the service registry
+ *
+ */
+ void start() {
+ }
+
+ /**
+ * Function called by the dependency manager before the services exported by
+ * the component are unregistered, this will be followed by a "destroy ()"
+ * calls
+ *
+ */
+ void stop() {
+ }
+
+ // this method uses reflection to update an object from it's delta.
+
+ private boolean overwrite(Object target, Object delta) {
+ Method[] methods = target.getClass().getMethods();
+
+ for(Method toMethod: methods){
+ if(toMethod.getDeclaringClass().equals(target.getClass())
+ && toMethod.getName().startsWith("set")){
+
+ String toName = toMethod.getName();
+ String fromName = toName.replace("set", "get");
+
+ try {
+ Method fromMethod = delta.getClass().getMethod(fromName);
+ Object value = fromMethod.invoke(delta, (Object[])null);
+ if(value != null){
+ toMethod.invoke(target, value);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+
+ // IfNBRouterCRUD Interface methods
+
+ public boolean routerExists(String uuid) {
+ return routerDB.containsKey(uuid);
+ }
+
+ public NeutronRouter getRouter(String uuid) {
+ if (!routerExists(uuid))
+ return null;
+ return routerDB.get(uuid);
+ }
+
+ public List<NeutronRouter> getAllRouters() {
+ Set<NeutronRouter> allRouters = new HashSet<NeutronRouter>();
+ for (Entry<String, NeutronRouter> entry : routerDB.entrySet()) {
+ NeutronRouter router = entry.getValue();
+ allRouters.add(router);
+ }
+ logger.debug("Exiting getAllRouters, Found {} Routers", allRouters.size());
+ List<NeutronRouter> ans = new ArrayList<NeutronRouter>();
+ ans.addAll(allRouters);
+ return ans;
+ }
+
+ public boolean addRouter(NeutronRouter input) {
+ if (routerExists(input.getID()))
+ return false;
+ routerDB.putIfAbsent(input.getID(), input);
+ return true;
+ }
+
+ public boolean removeRouter(String uuid) {
+ if (!routerExists(uuid))
+ return false;
+ routerDB.remove(uuid);
+ return true;
+ }
+
+ public boolean updateRouter(String uuid, NeutronRouter delta) {
+ if (!routerExists(uuid))
+ return false;
+ NeutronRouter target = routerDB.get(uuid);
+ return overwrite(target, delta);
+ }
+
+ public boolean routerInUse(String routerUUID) {
+ if (!routerExists(routerUUID))
+ return true;
+ NeutronRouter target = routerDB.get(routerUUID);
+ return (target.getInterfaces().size() > 0);
+ }
+}
-/*\r
- * Copyright IBM Corporation, 2013. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.networkconfig.neutron.implementation;\r
-\r
-import java.lang.reflect.Method;\r
-import java.util.ArrayList;\r
-import java.util.Dictionary;\r
-import java.util.EnumSet;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.Map.Entry;\r
-import java.util.concurrent.ConcurrentMap;\r
-\r
-import org.apache.felix.dm.Component;\r
-import org.opendaylight.controller.clustering.services.CacheConfigException;\r
-import org.opendaylight.controller.clustering.services.CacheExistException;\r
-import org.opendaylight.controller.clustering.services.IClusterContainerServices;\r
-import org.opendaylight.controller.clustering.services.IClusterServices;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;\r
-import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-public class NeutronSubnetInterface implements INeutronSubnetCRUD {\r
- private static final Logger logger = LoggerFactory.getLogger(NeutronSubnetInterface.class);\r
- private String containerName = null;\r
-\r
- private IClusterContainerServices clusterContainerService = null;\r
- private ConcurrentMap<String, NeutronSubnet> subnetDB;\r
-\r
- // methods needed for creating caches\r
-\r
- void setClusterContainerService(IClusterContainerServices s) {\r
- logger.debug("Cluster Service set");\r
- this.clusterContainerService = s;\r
- }\r
-\r
- void unsetClusterContainerService(IClusterContainerServices s) {\r
- if (this.clusterContainerService == s) {\r
- logger.debug("Cluster Service removed!");\r
- this.clusterContainerService = null;\r
- }\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void allocateCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't create cache");\r
- return;\r
- }\r
- logger.debug("Creating Cache for Neutron Subnets");\r
- try {\r
- // neutron caches\r
- this.clusterContainerService.createCache("neutronSubnets",\r
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));\r
- } catch (CacheConfigException cce) {\r
- logger.error("Cache couldn't be created for Neutron Subnets - check cache mode");\r
- } catch (CacheExistException cce) {\r
- logger.error("Cache for Neutron Subnets already exists, destroy and recreate");\r
- }\r
- logger.debug("Cache successfully created for Neutron Subnets");\r
- }\r
-\r
- @SuppressWarnings({ "unchecked", "deprecation" })\r
- private void retrieveCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterContainerService, can't retrieve cache");\r
- return;\r
- }\r
-\r
- logger.debug("Retrieving cache for Neutron Subnets");\r
- subnetDB = (ConcurrentMap<String, NeutronSubnet>) this.clusterContainerService\r
- .getCache("neutronSubnets");\r
- if (subnetDB == null) {\r
- logger.error("Cache couldn't be retrieved for Neutron Subnets");\r
- }\r
- logger.debug("Cache was successfully retrieved for Neutron Subnets");\r
- }\r
-\r
- @SuppressWarnings("deprecation")\r
- private void destroyCache() {\r
- if (this.clusterContainerService == null) {\r
- logger.error("un-initialized clusterMger, can't destroy cache");\r
- return;\r
- }\r
- logger.debug("Destroying Cache for HostTracker");\r
- this.clusterContainerService.destroyCache("neutronSubnets");\r
- }\r
-\r
- private void startUp() {\r
- allocateCache();\r
- retrieveCache();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when all the required\r
- * dependencies are satisfied\r
- *\r
- */\r
- void init(Component c) {\r
- Dictionary<?, ?> props = c.getServiceProperties();\r
- if (props != null) {\r
- this.containerName = (String) props.get("containerName");\r
- logger.debug("Running containerName: {}", this.containerName);\r
- } else {\r
- // In the Global instance case the containerName is empty\r
- this.containerName = "";\r
- }\r
- startUp();\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager when at least one dependency\r
- * become unsatisfied or when the component is shutting down because for\r
- * example bundle is being stopped.\r
- *\r
- */\r
- void destroy() {\r
- destroyCache();\r
- }\r
-\r
- /**\r
- * Function called by dependency manager after "init ()" is called and after\r
- * the services provided by the class are registered in the service registry\r
- *\r
- */\r
- void start() {\r
- }\r
-\r
- /**\r
- * Function called by the dependency manager before the services exported by\r
- * the component are unregistered, this will be followed by a "destroy ()"\r
- * calls\r
- *\r
- */\r
- void stop() {\r
- }\r
-\r
- // this method uses reflection to update an object from it's delta.\r
-\r
- private boolean overwrite(Object target, Object delta) {\r
- Method[] methods = target.getClass().getMethods();\r
-\r
- for(Method toMethod: methods){\r
- if(toMethod.getDeclaringClass().equals(target.getClass())\r
- && toMethod.getName().startsWith("set")){\r
-\r
- String toName = toMethod.getName();\r
- String fromName = toName.replace("set", "get");\r
-\r
- try {\r
- Method fromMethod = delta.getClass().getMethod(fromName);\r
- Object value = fromMethod.invoke(delta, (Object[])null);\r
- if(value != null){\r
- toMethod.invoke(target, value);\r
- }\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- return false;\r
- }\r
- }\r
- }\r
- return true;\r
- }\r
-\r
-\r
- // IfNBSubnetCRUD methods\r
-\r
- public boolean subnetExists(String uuid) {\r
- return subnetDB.containsKey(uuid);\r
- }\r
-\r
- public NeutronSubnet getSubnet(String uuid) {\r
- if (!subnetExists(uuid))\r
- return null;\r
- return subnetDB.get(uuid);\r
- }\r
-\r
- public List<NeutronSubnet> getAllSubnets() {\r
- Set<NeutronSubnet> allSubnets = new HashSet<NeutronSubnet>();\r
- for (Entry<String, NeutronSubnet> entry : subnetDB.entrySet()) {\r
- NeutronSubnet subnet = entry.getValue();\r
- allSubnets.add(subnet);\r
- }\r
- logger.debug("Exiting getAllSubnets, Found {} OpenStackSubnets", allSubnets.size());\r
- List<NeutronSubnet> ans = new ArrayList<NeutronSubnet>();\r
- ans.addAll(allSubnets);\r
- return ans;\r
- }\r
-\r
- public boolean addSubnet(NeutronSubnet input) {\r
- String id = input.getID();\r
- if (subnetExists(id))\r
- return false;\r
- subnetDB.putIfAbsent(id, input);\r
- INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
-\r
- NeutronNetwork targetNet = networkIf.getNetwork(input.getNetworkUUID());\r
- targetNet.addSubnet(id);\r
- return true;\r
- }\r
-\r
- public boolean removeSubnet(String uuid) {\r
- if (!subnetExists(uuid))\r
- return false;\r
- NeutronSubnet target = subnetDB.get(uuid);\r
- INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);\r
-\r
- NeutronNetwork targetNet = networkIf.getNetwork(target.getNetworkUUID());\r
- targetNet.removeSubnet(uuid);\r
- subnetDB.remove(uuid);\r
- return true;\r
- }\r
-\r
- public boolean updateSubnet(String uuid, NeutronSubnet delta) {\r
- if (!subnetExists(uuid))\r
- return false;\r
- NeutronSubnet target = subnetDB.get(uuid);\r
- return overwrite(target, delta);\r
- }\r
-\r
- public boolean subnetInUse(String subnetUUID) {\r
- if (!subnetExists(subnetUUID))\r
- return true;\r
- NeutronSubnet target = subnetDB.get(subnetUUID);\r
- return (target.getPortsInSubnet().size() > 0);\r
- }\r
-}\r
+/*
+ * Copyright IBM Corporation, 2013. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.networkconfig.neutron.implementation;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.felix.dm.Component;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.IClusterContainerServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
+import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD;
+import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD;
+import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;
+import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
+import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronSubnetInterface implements INeutronSubnetCRUD {
+ private static final Logger logger = LoggerFactory.getLogger(NeutronSubnetInterface.class);
+ private String containerName = null;
+
+ private IClusterContainerServices clusterContainerService = null;
+ private ConcurrentMap<String, NeutronSubnet> subnetDB;
+
+ // methods needed for creating caches
+
+ void setClusterContainerService(IClusterContainerServices s) {
+ logger.debug("Cluster Service set");
+ this.clusterContainerService = s;
+ }
+
+ void unsetClusterContainerService(IClusterContainerServices s) {
+ if (this.clusterContainerService == s) {
+ logger.debug("Cluster Service removed!");
+ this.clusterContainerService = null;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private void allocateCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't create cache");
+ return;
+ }
+ logger.debug("Creating Cache for Neutron Subnets");
+ try {
+ // neutron caches
+ this.clusterContainerService.createCache("neutronSubnets",
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ } catch (CacheConfigException cce) {
+ logger.error("Cache couldn't be created for Neutron Subnets - check cache mode");
+ } catch (CacheExistException cce) {
+ logger.error("Cache for Neutron Subnets already exists, destroy and recreate");
+ }
+ logger.debug("Cache successfully created for Neutron Subnets");
+ }
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ private void retrieveCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterContainerService, can't retrieve cache");
+ return;
+ }
+
+ logger.debug("Retrieving cache for Neutron Subnets");
+ subnetDB = (ConcurrentMap<String, NeutronSubnet>) this.clusterContainerService
+ .getCache("neutronSubnets");
+ if (subnetDB == null) {
+ logger.error("Cache couldn't be retrieved for Neutron Subnets");
+ }
+ logger.debug("Cache was successfully retrieved for Neutron Subnets");
+ }
+
+ @SuppressWarnings("deprecation")
+ private void destroyCache() {
+ if (this.clusterContainerService == null) {
+ logger.error("un-initialized clusterMger, can't destroy cache");
+ return;
+ }
+ logger.debug("Destroying Cache for HostTracker");
+ this.clusterContainerService.destroyCache("neutronSubnets");
+ }
+
+ private void startUp() {
+ allocateCache();
+ retrieveCache();
+ }
+
+ /**
+ * Function called by the dependency manager when all the required
+ * dependencies are satisfied
+ *
+ */
+ void init(Component c) {
+ Dictionary<?, ?> props = c.getServiceProperties();
+ if (props != null) {
+ this.containerName = (String) props.get("containerName");
+ logger.debug("Running containerName: {}", this.containerName);
+ } else {
+ // In the Global instance case the containerName is empty
+ this.containerName = "";
+ }
+ startUp();
+ }
+
+ /**
+ * Function called by the dependency manager when at least one dependency
+ * become unsatisfied or when the component is shutting down because for
+ * example bundle is being stopped.
+ *
+ */
+ void destroy() {
+ destroyCache();
+ }
+
+ /**
+ * Function called by dependency manager after "init ()" is called and after
+ * the services provided by the class are registered in the service registry
+ *
+ */
+ void start() {
+ }
+
+ /**
+ * Function called by the dependency manager before the services exported by
+ * the component are unregistered, this will be followed by a "destroy ()"
+ * calls
+ *
+ */
+ void stop() {
+ }
+
+ // this method uses reflection to update an object from it's delta.
+
+ private boolean overwrite(Object target, Object delta) {
+ Method[] methods = target.getClass().getMethods();
+
+ for(Method toMethod: methods){
+ if(toMethod.getDeclaringClass().equals(target.getClass())
+ && toMethod.getName().startsWith("set")){
+
+ String toName = toMethod.getName();
+ String fromName = toName.replace("set", "get");
+
+ try {
+ Method fromMethod = delta.getClass().getMethod(fromName);
+ Object value = fromMethod.invoke(delta, (Object[])null);
+ if(value != null){
+ toMethod.invoke(target, value);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+
+ // IfNBSubnetCRUD methods
+
+ public boolean subnetExists(String uuid) {
+ return subnetDB.containsKey(uuid);
+ }
+
+ public NeutronSubnet getSubnet(String uuid) {
+ if (!subnetExists(uuid))
+ return null;
+ return subnetDB.get(uuid);
+ }
+
+ public List<NeutronSubnet> getAllSubnets() {
+ Set<NeutronSubnet> allSubnets = new HashSet<NeutronSubnet>();
+ for (Entry<String, NeutronSubnet> entry : subnetDB.entrySet()) {
+ NeutronSubnet subnet = entry.getValue();
+ allSubnets.add(subnet);
+ }
+ logger.debug("Exiting getAllSubnets, Found {} OpenStackSubnets", allSubnets.size());
+ List<NeutronSubnet> ans = new ArrayList<NeutronSubnet>();
+ ans.addAll(allSubnets);
+ return ans;
+ }
+
+ public boolean addSubnet(NeutronSubnet input) {
+ String id = input.getID();
+ if (subnetExists(id))
+ return false;
+ subnetDB.putIfAbsent(id, input);
+ INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
+
+ NeutronNetwork targetNet = networkIf.getNetwork(input.getNetworkUUID());
+ targetNet.addSubnet(id);
+ return true;
+ }
+
+ public boolean removeSubnet(String uuid) {
+ if (!subnetExists(uuid))
+ return false;
+ NeutronSubnet target = subnetDB.get(uuid);
+ INeutronNetworkCRUD networkIf = NeutronCRUDInterfaces.getINeutronNetworkCRUD(this);
+
+ NeutronNetwork targetNet = networkIf.getNetwork(target.getNetworkUUID());
+ targetNet.removeSubnet(uuid);
+ subnetDB.remove(uuid);
+ return true;
+ }
+
+ public boolean updateSubnet(String uuid, NeutronSubnet delta) {
+ if (!subnetExists(uuid))
+ return false;
+ NeutronSubnet target = subnetDB.get(uuid);
+ return overwrite(target, delta);
+ }
+
+ public boolean subnetInUse(String subnetUUID) {
+ if (!subnetExists(subnetUUID))
+ return true;
+ NeutronSubnet target = subnetDB.get(subnetUUID);
+ return (target.getPortsInSubnet().size() > 0);
+ }
+}