import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
import java.util.Dictionary;
import java.util.EnumSet;
import java.util.Enumeration;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.opendaylight.controller.clustering.services.CacheConfigException;
import org.opendaylight.controller.clustering.services.CacheExistException;
-import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
import org.opendaylight.controller.clustering.services.IClusterContainerServices;
import org.opendaylight.controller.clustering.services.IClusterServices;
import org.opendaylight.controller.configuration.IConfigurationContainerAware;
* instance per container of the network. All the node/nodeConnector properties
* are maintained in the default container only.
*/
-public class SwitchManager implements ISwitchManager,
-IConfigurationContainerAware, IObjectReader,
-ICacheUpdateAware<Long, String>, IListenInventoryUpdates,
-CommandProvider {
+public class SwitchManager implements ISwitchManager, IConfigurationContainerAware,
+ IObjectReader, IListenInventoryUpdates, CommandProvider {
private static Logger log = LoggerFactory.getLogger(SwitchManager.class);
private static String ROOT = GlobalConstants.STARTUPHOME.toString();
- private static final String SAVE = "Save";
private String subnetFileName, spanFileName, switchConfigFileName;
private final List<NodeConnector> spanNodeConnectors = new CopyOnWriteArrayList<NodeConnector>();
// Collection of Subnets keyed by the InetAddress
private ConcurrentMap<SpanConfig, SpanConfig> spanConfigList;
// manually configured parameters for the node such as name, tier, mode
private ConcurrentMap<String, SwitchConfig> nodeConfigList;
- private ConcurrentMap<Long, String> configSaveEvent;
private ConcurrentMap<Node, Map<String, Property>> nodeProps;
private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps;
private ConcurrentMap<Node, Map<String, NodeConnector>> nodeConnectorNames;
try {
clusterContainerService.createCache(
"switchmanager.subnetsConfigList",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache("switchmanager.spanConfigList",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache("switchmanager.nodeConfigList",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache("switchmanager.subnets",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache(
"switchmanager.configSaveEvent",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache("switchmanager.nodeProps",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache(
"switchmanager.nodeConnectorProps",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache(
"switchmanager.nodeConnectorNames",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache(
"switchmanager.controllerProps",
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
} catch (CacheConfigException cce) {
log.error("\nCache configuration invalid - check cache mode");
} catch (CacheExistException ce) {
log.error("\nFailed to get cache for subnets");
}
- configSaveEvent = (ConcurrentMap<Long, String>) clusterContainerService
- .getCache("switchmanager.configSaveEvent");
- if (configSaveEvent == null) {
- log.error("\nFailed to get cache for configSaveEvent");
- }
-
nodeProps = (ConcurrentMap<Node, Map<String, Property>>) clusterContainerService
.getCache("switchmanager.nodeProps");
if (nodeProps == null) {
spanConfigList = new ConcurrentHashMap<SpanConfig, SpanConfig>();
nodeConfigList = new ConcurrentHashMap<String, SwitchConfig>();
subnets = new ConcurrentHashMap<InetAddress, Subnet>();
- configSaveEvent = new ConcurrentHashMap<Long, String>();
nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
nodeConnectorNames = new ConcurrentHashMap<Node, Map<String, NodeConnector>>();
switchConfig = new SwitchConfig(nodeId, updateProperties);
} else {
// check if description is configured or was published by any other node
- for (Node n : nodeProps.keySet()) {
+ for (Map.Entry<Node, Map<String, Property>> entry : nodeProps.entrySet()) {
+ Node n = entry.getKey();
Description desc = (Description) getNodeProp(n, Description.propertyName);
NodeDescription nDesc = (this.statisticsManager == null) ? null : this.statisticsManager
.getNodeDescription(n);
return new Status(StatusCode.SUCCESS);
}
Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
- for (String prop : prevNodeProperties.keySet()) {
+ for (Map.Entry<String, Property> entry : prevNodeProperties.entrySet()) {
+ String prop = entry.getKey();
if (!updateProperties.containsKey(prop)) {
if (prop.equals(Description.propertyName)) {
if (!advertisedDesc.isEmpty()) {
Map<String, Property> propMapCurr = nodeProps.get(node);
if ((propMapCurr != null) && (nodeProperties != null) && (!nodeProperties.isEmpty())) {
Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
- for (String prop : nodeProperties.keySet()) {
+ for (Map.Entry<String, Property> entry : nodeProperties.entrySet()) {
+ String prop = entry.getKey();
if (prop.equals(Description.propertyName)) {
Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
if (nodeProp.get(node) != null) {
@Override
public Status saveSwitchConfig() {
- // Publish the save config event to the cluster nodes
- configSaveEvent.put(new Date().getTime(), SAVE);
return saveSwitchConfigInternal();
}
return ncList;
}
- @Override
- public void entryCreated(Long key, String cacheName, boolean local) {
- }
-
- @Override
- public void entryUpdated(Long key, String newValue, String cacheName,
- boolean originLocal) {
- saveSwitchConfigInternal();
- }
-
- @Override
- public void entryDeleted(Long key, String cacheName, boolean originLocal) {
- }
-
private void addNode(Node node, Set<Property> props) {
log.trace("{} added, props: {}", node, props);
if (nodeProps == null) {
return;
}
nodeProps.remove(node);
+ nodeConnectorNames.remove(node);
+ Set<NodeConnector> removeNodeConnectorSet = new HashSet<NodeConnector>();
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
+ if (nodeConnector.getNode().equals(node)) {
+ removeNodeConnectorSet.add(nodeConnector);
+ }
+ }
+ for (NodeConnector nc : removeNodeConnectorSet) {
+ nodeConnectorProps.remove(nc);
+ }
// check if span ports need to be cleaned up
removeSpanPorts(node);
public void updateNodeConnector(NodeConnector nodeConnector,
UpdateType type, Set<Property> props) {
Map<String, Property> propMap = new HashMap<String, Property>();
+ boolean update = true;
log.debug("updateNodeConnector: {} type {} props {} for container {}",
new Object[] { nodeConnector, type, props, containerName });
switch (type) {
case ADDED:
- case CHANGED:
if (props != null) {
for (Property prop : props) {
addNodeConnectorProp(nodeConnector, prop);
addSpanPort(nodeConnector);
break;
+ case CHANGED:
+ if (!nodeConnectorProps.containsKey(nodeConnector) || (props == null)) {
+ update = false;
+ } else {
+ for (Property prop : props) {
+ addNodeConnectorProp(nodeConnector, prop);
+ propMap.put(prop.getName(), prop);
+ }
+ }
+ break;
case REMOVED:
+ if (!nodeConnectorProps.containsKey(nodeConnector)) {
+ update = false;
+ }
removeNodeConnectorAllProps(nodeConnector);
// clean up span config
removeSpanPort(nodeConnector);
break;
default:
+ update = false;
break;
}
- notifyNodeConnector(nodeConnector, type, propMap);
+ if (update) {
+ notifyNodeConnector(nodeConnector, type, propMap);
+ }
}
@Override
}
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
if (!nodeConnector.getNode().equals(node)) {
continue;
}
}
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
if (!nodeConnector.getNode().equals(node)) {
continue;
}
}
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
if (!nodeConnector.getNode().equals(node)
|| isSpecial(nodeConnector)) {
continue;
Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
if (mapCurr != null) {
- for (String s : mapCurr.keySet()) {
+ for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+ String s = entry.getKey();
try {
- map.put(s, new NodeConnector(mapCurr.get(s)));
+ map.put(s, new NodeConnector(entry.getValue()));
} catch (ConstructionException e) {
e.printStackTrace();
}
Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
if (mapCurr != null) {
Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
- for (String s : mapCurr.keySet()) {
+ for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+ String s = entry.getKey();
try {
- map.put(s, new NodeConnector(mapCurr.get(s)));
+ map.put(s, new NodeConnector(entry.getValue()));
} catch (ConstructionException e) {
e.printStackTrace();
}
Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
if (mapCurr != null) {
Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
- for (String s : mapCurr.keySet()) {
+ for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+ String s = entry.getKey();
try {
- map.put(s, new NodeConnector(mapCurr.get(s)));
+ map.put(s, new NodeConnector(entry.getValue()));
} catch (ConstructionException e) {
e.printStackTrace();
}
service.notifyNode(node, type, propMap);
}
- for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
propMap = nodeConnectorProps.get(nodeConnector);
service.notifyNodeConnector(nodeConnector, type, propMap);
}