From: Ryan Moats Date: Fri, 8 Nov 2013 17:40:19 +0000 (-0600) Subject: Convert neutron implementation classes to unix line delimiters X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~448 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=f0e3d363ed6549f0c24d6c0b2e2167a4d8196139 Convert neutron implementation classes to unix line delimiters Replace original windows line delimiters. Change-Id: Icbae06e51f774e788e82683f65fd1d9641102be0 Signed-off-by: Ryan Moats --- diff --git a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/Activator.java b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/Activator.java index 7e5b093c07..4202856774 100644 --- a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/Activator.java +++ b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/Activator.java @@ -1,136 +1,136 @@ -/* - * 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 props = new Hashtable(); - 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 props = new Hashtable(); - 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 props = new Hashtable(); - 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 props = new Hashtable(); - 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 props = new Hashtable(); - props.put("salListenerName", "neutron"); - c.add(createContainerServiceDependency(containerName) - .setService(IClusterContainerServices.class) - .setCallbacks("setClusterContainerService", - "unsetClusterContainerService").setRequired(true)); - } - } -} +/* + * 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 props = new Hashtable(); + 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 props = new Hashtable(); + 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 props = new Hashtable(); + 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 props = new Hashtable(); + 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 props = new Hashtable(); + props.put("salListenerName", "neutron"); + c.add(createContainerServiceDependency(containerName) + .setService(IClusterContainerServices.class) + .setCallbacks("setClusterContainerService", + "unsetClusterContainerService").setRequired(true)); + } + } +} diff --git a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronFloatingIPInterface.java b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronFloatingIPInterface.java index 7b10756d1c..7d9a2e6576 100644 --- a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronFloatingIPInterface.java +++ b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronFloatingIPInterface.java @@ -1,266 +1,266 @@ -/* - * 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 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) 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 getAllFloatingIPs() { - Set allIPs = new HashSet(); - for (Entry entry : floatingIPDB.entrySet()) { - NeutronFloatingIP floatingip = entry.getValue(); - allIPs.add(floatingip); - } - logger.debug("Exiting getAllFloatingIPs, Found {} FloatingIPs", allIPs.size()); - List ans = new ArrayList(); - 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; - } -} +/* + * 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 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) 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 getAllFloatingIPs() { + Set allIPs = new HashSet(); + for (Entry entry : floatingIPDB.entrySet()) { + NeutronFloatingIP floatingip = entry.getValue(); + allIPs.add(floatingip); + } + logger.debug("Exiting getAllFloatingIPs, Found {} FloatingIPs", allIPs.size()); + List ans = new ArrayList(); + 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; + } +} diff --git a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronNetworkInterface.java b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronNetworkInterface.java index a2454217a6..b1e382107a 100644 --- a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronNetworkInterface.java +++ b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronNetworkInterface.java @@ -1,226 +1,226 @@ -/* - * 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 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) 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 getAllNetworks() { - Set allNetworks = new HashSet(); - for (Entry entry : networkDB.entrySet()) { - NeutronNetwork network = entry.getValue(); - allNetworks.add(network); - } - logger.debug("Exiting getAllNetworks, Found {} OpenStackNetworks", allNetworks.size()); - List ans = new ArrayList(); - 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; - } -} +/* + * 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 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) 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 getAllNetworks() { + Set allNetworks = new HashSet(); + for (Entry entry : networkDB.entrySet()) { + NeutronNetwork network = entry.getValue(); + allNetworks.add(network); + } + logger.debug("Exiting getAllNetworks, Found {} OpenStackNetworks", allNetworks.size()); + List ans = new ArrayList(); + 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; + } +} diff --git a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronPortInterface.java b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronPortInterface.java index 8f1e70f052..fd030e178b 100644 --- a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronPortInterface.java +++ b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronPortInterface.java @@ -1,332 +1,332 @@ -/* - * 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 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) 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 getAllPorts() { - Set allPorts = new HashSet(); - for (Entry entry : portDB.entrySet()) { - NeutronPort port = entry.getValue(); - allPorts.add(port); - } - logger.debug("Exiting getAllPorts, Found {} OpenStackPorts", allPorts.size()); - List ans = new ArrayList(); - 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 list = input.getFixedIPs(); - Iterator 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 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 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 ports = getAllPorts(); - Iterator 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 portIterator = getAllPorts().iterator(); - while (portIterator.hasNext()) { - NeutronPort port = portIterator.next(); - List fixedIPs = port.getFixedIPs(); - if (fixedIPs.size() == 1) { - if (subnet.getGatewayIP().equals(fixedIPs.get(0).getIpAddress())) { - return port; - } - } - } - return null; - } - -} +/* + * 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 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) 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 getAllPorts() { + Set allPorts = new HashSet(); + for (Entry entry : portDB.entrySet()) { + NeutronPort port = entry.getValue(); + allPorts.add(port); + } + logger.debug("Exiting getAllPorts, Found {} OpenStackPorts", allPorts.size()); + List ans = new ArrayList(); + 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 list = input.getFixedIPs(); + Iterator 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 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 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 ports = getAllPorts(); + Iterator 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 portIterator = getAllPorts().iterator(); + while (portIterator.hasNext()) { + NeutronPort port = portIterator.next(); + List fixedIPs = port.getFixedIPs(); + if (fixedIPs.size() == 1) { + if (subnet.getGatewayIP().equals(fixedIPs.get(0).getIpAddress())) { + return port; + } + } + } + return null; + } + +} diff --git a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronRouterInterface.java b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronRouterInterface.java index 0a7afa562c..0e64dc5a09 100644 --- a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronRouterInterface.java +++ b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronRouterInterface.java @@ -1,224 +1,224 @@ -/* - * 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 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) 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 getAllRouters() { - Set allRouters = new HashSet(); - for (Entry entry : routerDB.entrySet()) { - NeutronRouter router = entry.getValue(); - allRouters.add(router); - } - logger.debug("Exiting getAllRouters, Found {} Routers", allRouters.size()); - List ans = new ArrayList(); - 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); - } -} +/* + * 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 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) 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 getAllRouters() { + Set allRouters = new HashSet(); + for (Entry entry : routerDB.entrySet()) { + NeutronRouter router = entry.getValue(); + allRouters.add(router); + } + logger.debug("Exiting getAllRouters, Found {} Routers", allRouters.size()); + List ans = new ArrayList(); + 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); + } +} diff --git a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronSubnetInterface.java b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronSubnetInterface.java index 0fc333723a..62ef64c74c 100644 --- a/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronSubnetInterface.java +++ b/opendaylight/networkconfiguration/neutron/implementation/src/main/java/org/opendaylight/controller/networkconfig/neutron/implementation/NeutronSubnetInterface.java @@ -1,238 +1,238 @@ -/* - * 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 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) 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 getAllSubnets() { - Set allSubnets = new HashSet(); - for (Entry entry : subnetDB.entrySet()) { - NeutronSubnet subnet = entry.getValue(); - allSubnets.add(subnet); - } - logger.debug("Exiting getAllSubnets, Found {} OpenStackSubnets", allSubnets.size()); - List ans = new ArrayList(); - 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); - } -} +/* + * 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 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) 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 getAllSubnets() { + Set allSubnets = new HashSet(); + for (Entry entry : subnetDB.entrySet()) { + NeutronSubnet subnet = entry.getValue(); + allSubnets.add(subnet); + } + logger.debug("Exiting getAllSubnets, Found {} OpenStackSubnets", allSubnets.size()); + List ans = new ArrayList(); + 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); + } +}