X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetworkconfiguration%2Fneutron%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetworkconfig%2Fneutron%2Fimplementation%2FNeutronPortInterface.java;h=3294474b49480ed9153bcef9bf2d753d6c505be8;hb=00da46dd8963791aa00d72d4f996ce725b4a8867;hp=fd030e178bd021cb8ec4ccfcb14c1877d89b172a;hpb=caee336f062eba4909ba53cbaccdde0714236134;p=controller.git 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 fd030e178b..3294474b49 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 @@ -8,6 +8,9 @@ package org.opendaylight.controller.networkconfig.neutron.implementation; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.ObjectInputStream; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Dictionary; @@ -15,8 +18,8 @@ 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.Set; import java.util.concurrent.ConcurrentMap; import org.apache.felix.dm.Component; @@ -24,6 +27,9 @@ 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.configuration.ConfigurationObject; +import org.opendaylight.controller.configuration.IConfigurationContainerAware; +import org.opendaylight.controller.configuration.IConfigurationContainerService; import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD; import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD; import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetCRUD; @@ -32,14 +38,19 @@ 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.opendaylight.controller.sal.utils.IObjectReader; +import org.opendaylight.controller.sal.utils.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NeutronPortInterface implements INeutronPortCRUD { +public class NeutronPortInterface implements INeutronPortCRUD, IConfigurationContainerAware, + IObjectReader { private static final Logger logger = LoggerFactory.getLogger(NeutronPortInterface.class); + private static final String FILE_NAME ="neutron.port.conf"; private String containerName = null; private IClusterContainerServices clusterContainerService = null; + private IConfigurationContainerService configurationService; private ConcurrentMap portDB; // methods needed for creating caches @@ -56,7 +67,16 @@ public class NeutronPortInterface implements INeutronPortCRUD { } } - @SuppressWarnings("deprecation") + public void setConfigurationContainerService(IConfigurationContainerService service) { + logger.trace("Configuration service set: {}", service); + configurationService = service; + } + + public void unsetConfigurationContainerService(IConfigurationContainerService service) { + logger.trace("Configuration service removed: {}", service); + configurationService = null; + } + private void allocateCache() { if (clusterContainerService == null) { logger.error("un-initialized clusterContainerService, can't create cache"); @@ -75,7 +95,7 @@ public class NeutronPortInterface implements INeutronPortCRUD { logger.debug("Cache successfully created for OpenDOVE"); } - @SuppressWarnings({ "unchecked", "deprecation" }) + @SuppressWarnings({ "unchecked" }) private void retrieveCache() { if (clusterContainerService == null) { logger.error("un-initialized clusterContainerService, can't retrieve cache"); @@ -91,7 +111,6 @@ public class NeutronPortInterface implements INeutronPortCRUD { 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"); @@ -104,6 +123,7 @@ public class NeutronPortInterface implements INeutronPortCRUD { private void startUp() { allocateCache(); retrieveCache(); + loadConfiguration(); } /** @@ -213,6 +233,9 @@ public class NeutronPortInterface implements INeutronPortCRUD { 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() == null){ + input.setFixedIPs(new ArrayList()); + } if (input.getFixedIPs().size() == 0) { List list = input.getFixedIPs(); Iterator subnetIterator = systemCRUD.getAllSubnets().iterator(); @@ -329,4 +352,22 @@ public class NeutronPortInterface implements INeutronPortCRUD { return null; } + private void loadConfiguration() { + for (ConfigurationObject conf : configurationService.retrieveConfiguration(this, FILE_NAME)) { + NeutronPort nn = (NeutronPort) conf; + portDB.put(nn.getID(), nn); + } + } + + @Override + public Status saveConfiguration() { + return configurationService.persistConfiguration(new ArrayList(portDB.values()), + FILE_NAME); + } + + @Override + public Object readObject(ObjectInputStream ois) throws FileNotFoundException, IOException, ClassNotFoundException { + return ois.readObject(); + } + }