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%2FNeutronNetworkInterface.java;h=eda4d21d5dcd20a772791bfea85ac6a081281fb4;hb=a84d1bd3fba5d6fb7d9777e1508221e2f773e94f;hp=b1e382107adcb5e52b58da3e41a5f4b91e9881bf;hpb=caee336f062eba4909ba53cbaccdde0714236134;p=controller.git 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 b1e382107a..eda4d21d5d 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 @@ -8,14 +8,18 @@ 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; import java.util.EnumSet; import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.apache.felix.dm.Component; @@ -23,13 +27,23 @@ 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.IConfigurationContainerAware; import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkCRUD; import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork; +import org.opendaylight.controller.sal.utils.GlobalConstants; +import org.opendaylight.controller.sal.utils.IObjectReader; +import org.opendaylight.controller.sal.utils.ObjectReader; +import org.opendaylight.controller.sal.utils.ObjectWriter; +import org.opendaylight.controller.sal.utils.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NeutronNetworkInterface implements INeutronNetworkCRUD { +public class NeutronNetworkInterface implements INeutronNetworkCRUD, IConfigurationContainerAware, + IObjectReader { private static final Logger logger = LoggerFactory.getLogger(NeutronNetworkInterface.class); + private static String ROOT = GlobalConstants.STARTUPHOME.toString(); + private static final String FILENAME ="neutron.network"; + private static String fileName; private String containerName = null; private ConcurrentMap networkDB; @@ -85,6 +99,9 @@ public class NeutronNetworkInterface implements INeutronNetworkCRUD { private void startUp() { allocateCache(); retrieveCache(); + if ((clusterContainerService != null) && (clusterContainerService.amICoordinator())) { + loadConfiguration(); + } } /** @@ -101,6 +118,7 @@ public class NeutronNetworkInterface implements INeutronNetworkCRUD { // In the Global instance case the containerName is empty this.containerName = ""; } + fileName = ROOT + FILENAME + "_" + containerName + ".conf"; startUp(); } @@ -170,16 +188,19 @@ public class NeutronNetworkInterface implements INeutronNetworkCRUD { // IfNBNetworkCRUD methods + @Override public boolean networkExists(String uuid) { return networkDB.containsKey(uuid); } + @Override public NeutronNetwork getNetwork(String uuid) { if (!networkExists(uuid)) return null; return networkDB.get(uuid); } + @Override public List getAllNetworks() { Set allNetworks = new HashSet(); for (Entry entry : networkDB.entrySet()) { @@ -192,6 +213,7 @@ public class NeutronNetworkInterface implements INeutronNetworkCRUD { return ans; } + @Override public boolean addNetwork(NeutronNetwork input) { if (networkExists(input.getID())) return false; @@ -200,6 +222,7 @@ public class NeutronNetworkInterface implements INeutronNetworkCRUD { return true; } + @Override public boolean removeNetwork(String uuid) { if (!networkExists(uuid)) return false; @@ -208,6 +231,7 @@ public class NeutronNetworkInterface implements INeutronNetworkCRUD { return true; } + @Override public boolean updateNetwork(String uuid, NeutronNetwork delta) { if (!networkExists(uuid)) return false; @@ -215,6 +239,7 @@ public class NeutronNetworkInterface implements INeutronNetworkCRUD { return overwrite(target, delta); } + @Override public boolean networkInUse(String netUUID) { if (!networkExists(netUUID)) return true; @@ -223,4 +248,31 @@ public class NeutronNetworkInterface implements INeutronNetworkCRUD { return true; return false; } + + @SuppressWarnings("unchecked") + private void loadConfiguration() { + ObjectReader objReader = new ObjectReader(); + ConcurrentMap confList = (ConcurrentMap) + objReader.read(this, fileName); + + if (confList == null) { + return; + } + + for (String key : confList.keySet()) { + networkDB.put(key, confList.get(key)); + } + } + + @Override + public Status saveConfiguration() { + ObjectWriter objWriter = new ObjectWriter(); + return objWriter.write(new ConcurrentHashMap(networkDB), fileName); + } + + @Override + public Object readObject(ObjectInputStream ois) throws FileNotFoundException, IOException, ClassNotFoundException { + return ois.readObject(); + } + }