Merge "In case of an error event, cleanup the config too"
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / InventoryServiceShim.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.protocol_plugin.openflow.internal;
10
11 import java.util.ArrayList;
12 import java.util.Date;
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.Set;
17 import java.util.concurrent.ConcurrentHashMap;
18 import java.util.concurrent.ConcurrentMap;
19 import java.util.concurrent.CopyOnWriteArrayList;
20 import java.util.concurrent.CopyOnWriteArraySet;
21
22 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimExternalListener;
23 import org.opendaylight.controller.protocol_plugin.openflow.IInventoryShimInternalListener;
24 import org.opendaylight.controller.protocol_plugin.openflow.IOFStatisticsListener;
25 import org.opendaylight.controller.protocol_plugin.openflow.core.IController;
26 import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener;
27 import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch;
28 import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitchStateListener;
29 import org.opendaylight.controller.sal.connection.ConnectionLocality;
30 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
31 import org.opendaylight.controller.sal.core.Actions;
32 import org.opendaylight.controller.sal.core.Buffers;
33 import org.opendaylight.controller.sal.core.Capabilities;
34 import org.opendaylight.controller.sal.core.ContainerFlow;
35 import org.opendaylight.controller.sal.core.Description;
36 import org.opendaylight.controller.sal.core.IContainerAware;
37 import org.opendaylight.controller.sal.core.IContainerListener;
38 import org.opendaylight.controller.sal.core.MacAddress;
39 import org.opendaylight.controller.sal.core.Node;
40 import org.opendaylight.controller.sal.core.NodeConnector;
41 import org.opendaylight.controller.sal.core.Property;
42 import org.opendaylight.controller.sal.core.Tables;
43 import org.opendaylight.controller.sal.core.TimeStamp;
44 import org.opendaylight.controller.sal.core.UpdateType;
45 import org.opendaylight.controller.sal.utils.GlobalConstants;
46 import org.opendaylight.controller.sal.utils.NodeCreator;
47 import org.openflow.protocol.OFMessage;
48 import org.openflow.protocol.OFPortStatus;
49 import org.openflow.protocol.OFPortStatus.OFPortReason;
50 import org.openflow.protocol.OFType;
51 import org.openflow.protocol.statistics.OFDescriptionStatistics;
52 import org.openflow.protocol.statistics.OFStatistics;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55
56 /**
57  * The class describes a shim layer that bridges inventory events from Openflow
58  * core to various listeners. The notifications are filtered based on container
59  * configurations.
60  *
61  *
62  */
63 public class InventoryServiceShim implements IContainerListener,
64         IMessageListener, ISwitchStateListener, IOFStatisticsListener, IContainerAware {
65     protected static final Logger logger = LoggerFactory
66             .getLogger(InventoryServiceShim.class);
67     private IController controller = null;
68     private final ConcurrentMap<String, IInventoryShimInternalListener> inventoryShimInternalListeners = new ConcurrentHashMap<String, IInventoryShimInternalListener>();
69     private final Set<IInventoryShimInternalListener> globalInventoryShimInternalListeners = new HashSet<IInventoryShimInternalListener>();
70     private final List<IInventoryShimExternalListener> inventoryShimExternalListeners = new CopyOnWriteArrayList<IInventoryShimExternalListener>();
71     private final ConcurrentMap<NodeConnector, Set<String>> nodeConnectorContainerMap = new ConcurrentHashMap<NodeConnector, Set<String>>();
72     private final ConcurrentMap<Node, Set<String>> nodeContainerMap = new ConcurrentHashMap<Node, Set<String>>();
73     private final ConcurrentMap<NodeConnector, Set<Property>> nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Set<Property>>();
74     private final ConcurrentMap<Node, Set<Property>> nodeProps = new ConcurrentHashMap<Node, Set<Property>>();
75     private IPluginOutConnectionService connectionOutService;
76
77     void setController(IController s) {
78         this.controller = s;
79     }
80
81     void unsetController(IController s) {
82         if (this.controller == s) {
83             this.controller = null;
84         }
85     }
86
87     void setInventoryShimGlobalInternalListener(Map<?, ?> props,
88             IInventoryShimInternalListener s) {
89         if ((this.globalInventoryShimInternalListeners != null)) {
90             this.globalInventoryShimInternalListeners.add(s);
91         }
92     }
93
94     void unsetInventoryShimGlobalInternalListener(Map<?, ?> props,
95             IInventoryShimInternalListener s) {
96         if ((this.globalInventoryShimInternalListeners != null)) {
97             this.globalInventoryShimInternalListeners.remove(s);
98         }
99     }
100
101     void setInventoryShimInternalListener(Map<?, ?> props,
102             IInventoryShimInternalListener s) {
103         if (props == null) {
104             logger.error("setInventoryShimInternalListener property is null");
105             return;
106         }
107         String containerName = (String) props.get("containerName");
108         if (containerName == null) {
109             logger.error("setInventoryShimInternalListener containerName not supplied");
110             return;
111         }
112         if ((this.inventoryShimInternalListeners != null)
113                 && !this.inventoryShimInternalListeners.containsValue(s)) {
114             this.inventoryShimInternalListeners.put(containerName, s);
115             logger.trace(
116                     "Added inventoryShimInternalListener for container {}",
117                     containerName);
118         }
119     }
120
121     void unsetInventoryShimInternalListener(Map<?, ?> props,
122             IInventoryShimInternalListener s) {
123         if (props == null) {
124             logger.error("unsetInventoryShimInternalListener property is null");
125             return;
126         }
127         String containerName = (String) props.get("containerName");
128         if (containerName == null) {
129             logger.error("setInventoryShimInternalListener containerName not supplied");
130             return;
131         }
132         if ((this.inventoryShimInternalListeners != null)
133                 && this.inventoryShimInternalListeners.get(containerName) != null
134                 && this.inventoryShimInternalListeners.get(containerName)
135                         .equals(s)) {
136             this.inventoryShimInternalListeners.remove(containerName);
137             logger.trace(
138                     "Removed inventoryShimInternalListener for container {}",
139                     containerName);
140         }
141     }
142
143     void setInventoryShimExternalListener(IInventoryShimExternalListener s) {
144         logger.trace("Set inventoryShimExternalListener {}", s);
145         if ((this.inventoryShimExternalListeners != null)
146                 && !this.inventoryShimExternalListeners.contains(s)) {
147             this.inventoryShimExternalListeners.add(s);
148         }
149     }
150
151     void unsetInventoryShimExternalListener(IInventoryShimExternalListener s) {
152         logger.trace("Unset inventoryShimExternalListener {}", s);
153         if ((this.inventoryShimExternalListeners != null)
154                 && this.inventoryShimExternalListeners.contains(s)) {
155             this.inventoryShimExternalListeners.remove(s);
156         }
157     }
158
159     void setIPluginOutConnectionService(IPluginOutConnectionService s) {
160         connectionOutService = s;
161     }
162
163     void unsetIPluginOutConnectionService(IPluginOutConnectionService s) {
164         if (connectionOutService == s) {
165             connectionOutService = null;
166         }
167     }
168
169     /**
170      * Function called by the dependency manager when all the required
171      * dependencies are satisfied
172      *
173      */
174     void init() {
175         this.controller.addMessageListener(OFType.PORT_STATUS, this);
176         this.controller.addSwitchStateListener(this);
177     }
178
179     /**
180      * Function called after registering the service in OSGi service registry.
181      */
182     void started() {
183         /* Start with existing switches */
184         startService();
185     }
186
187     /**
188      * Function called by the dependency manager when at least one dependency
189      * become unsatisfied or when the component is shutting down because for
190      * example bundle is being stopped.
191      *
192      */
193     void destroy() {
194         this.controller.removeMessageListener(OFType.PACKET_IN, this);
195         this.controller.removeSwitchStateListener(this);
196
197         this.inventoryShimInternalListeners.clear();
198         this.nodeConnectorContainerMap.clear();
199         this.nodeContainerMap.clear();
200         this.globalInventoryShimInternalListeners.clear();
201         this.controller = null;
202     }
203
204     @Override
205     public void receive(ISwitch sw, OFMessage msg) {
206         if (msg instanceof OFPortStatus) {
207             handlePortStatusMessage(sw, (OFPortStatus) msg);
208         }
209         return;
210     }
211
212     protected void handlePortStatusMessage(ISwitch sw, OFPortStatus m) {
213         Node node = NodeCreator.createOFNode(sw.getId());
214         NodeConnector nodeConnector = PortConverter.toNodeConnector(
215             m.getDesc().getPortNumber(), node);
216         // get node connector properties
217         Set<Property> props = InventoryServiceHelper.OFPortToProps(m.getDesc());
218
219         UpdateType type = null;
220         if (m.getReason() == (byte) OFPortReason.OFPPR_ADD.ordinal()) {
221             type = UpdateType.ADDED;
222             nodeConnectorProps.put(nodeConnector, props);
223         } else if (m.getReason() == (byte) OFPortReason.OFPPR_DELETE.ordinal()) {
224             type = UpdateType.REMOVED;
225             nodeConnectorProps.remove(nodeConnector);
226         } else if (m.getReason() == (byte) OFPortReason.OFPPR_MODIFY.ordinal()) {
227             type = UpdateType.CHANGED;
228             nodeConnectorProps.put(nodeConnector, props);
229         }
230
231         logger.trace("handlePortStatusMessage {} type {}", nodeConnector, type);
232
233         if (type != null) {
234             notifyInventoryShimListener(nodeConnector, type, props);
235         }
236     }
237
238     @Override
239     public void switchAdded(ISwitch sw) {
240         if (sw == null) {
241             return;
242         }
243         Node node = NodeCreator.createOFNode(sw.getId());
244         if ((nodeProps.get(node) != null)  && (connectionOutService.isLocal(node))) {
245             logger.debug("Ignore switchAdded {}", sw);
246             return;
247         }
248
249         // Add all the nodeConnectors of this switch
250         Map<NodeConnector, Set<Property>> ncProps = InventoryServiceHelper
251                 .OFSwitchToProps(sw);
252         for (Map.Entry<NodeConnector, Set<Property>> entry : ncProps.entrySet()) {
253             Set<Property> props = new HashSet<Property>();
254             Set<Property> prop = entry.getValue();
255             if (prop != null) {
256                 props.addAll(prop);
257             }
258             nodeConnectorProps.put(entry.getKey(), props);
259             notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, entry.getValue());
260         }
261
262         // Add this node
263         if (connectionOutService.getLocalityStatus(node) != ConnectionLocality.NOT_CONNECTED) {
264             addNode(sw);
265         } else {
266             logger.debug("Skipping node addition due to Connectivity Status : {}", connectionOutService.getLocalityStatus(node).name());
267         }
268     }
269
270     @Override
271     public void switchDeleted(ISwitch sw) {
272         if (sw == null) {
273             return;
274         }
275
276         removeNode(sw);
277     }
278
279     @Override
280     public void containerModeUpdated(UpdateType t) {
281         // do nothing
282     }
283
284     @Override
285     public void tagUpdated(String containerName, Node n, short oldTag,
286             short newTag, UpdateType t) {
287         logger.debug("tagUpdated: {} type {} for container {}", new Object[] {
288                 n, t, containerName });
289     }
290
291     @Override
292     public void containerFlowUpdated(String containerName,
293             ContainerFlow previousFlow, ContainerFlow currentFlow, UpdateType t) {
294     }
295
296     @Override
297     public void nodeConnectorUpdated(String containerName, NodeConnector nc, UpdateType t) {
298         logger.debug("nodeConnectorUpdated: {} type {} for container {}", new Object[] { nc, t, containerName });
299         Node node = nc.getNode();
300         Set<String> ncContainers = this.nodeConnectorContainerMap.get(nc);
301         Set<String> nodeContainers = this.nodeContainerMap.get(node);
302         if (ncContainers == null) {
303             ncContainers = new CopyOnWriteArraySet<String>();
304         }
305         if (nodeContainers == null) {
306             nodeContainers = new CopyOnWriteArraySet<String>();
307         }
308         boolean notifyNodeUpdate = false;
309
310         switch (t) {
311         case ADDED:
312             if (ncContainers.add(containerName)) {
313                 this.nodeConnectorContainerMap.put(nc, ncContainers);
314             }
315             if (nodeContainers.add(containerName)) {
316                 this.nodeContainerMap.put(node, nodeContainers);
317                 notifyNodeUpdate = true;
318             }
319             break;
320         case REMOVED:
321             if (ncContainers.remove(containerName)) {
322                 if (ncContainers.isEmpty()) {
323                     // Do cleanup to reduce memory footprint if no
324                     // elements to be tracked
325                     this.nodeConnectorContainerMap.remove(nc);
326                 } else {
327                     this.nodeConnectorContainerMap.put(nc, ncContainers);
328                 }
329             }
330             boolean nodeContainerUpdate = true;
331             for (NodeConnector ncContainer : nodeConnectorContainerMap.keySet()) {
332                 if ((ncContainer.getNode().equals(node)) && (nodeConnectorContainerMap.get(ncContainer).contains(containerName))) {
333                     nodeContainerUpdate = false;
334                     break;
335                 }
336             }
337             if (nodeContainerUpdate) {
338                 nodeContainers.remove(containerName);
339                 notifyNodeUpdate = true;
340                 if (nodeContainers.isEmpty()) {
341                     this.nodeContainerMap.remove(node);
342                 } else {
343                     this.nodeContainerMap.put(node, nodeContainers);
344                 }
345             }
346             break;
347         case CHANGED:
348             break;
349         }
350
351         Set<Property> nodeProp = nodeProps.get(node);
352         if (nodeProp == null) {
353             return;
354         }
355         Set<Property> ncProp = nodeConnectorProps.get(nc);
356         // notify InventoryService
357         notifyInventoryShimInternalListener(containerName, nc, t, ncProp);
358
359         if (notifyNodeUpdate) {
360             notifyInventoryShimInternalListener(containerName, node, t, nodeProp);
361         }
362     }
363
364     private void notifyInventoryShimExternalListener(Node node, UpdateType type, Set<Property> props) {
365         for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) {
366             s.updateNode(node, type, props);
367         }
368     }
369
370     private void notifyInventoryShimExternalListener(NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
371         for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) {
372             s.updateNodeConnector(nodeConnector, type, props);
373         }
374     }
375
376     private void notifyInventoryShimInternalListener(String container,
377             NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
378         IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners.get(container);
379         if (inventoryShimInternalListener != null) {
380             inventoryShimInternalListener.updateNodeConnector(nodeConnector, type, props);
381             logger.trace("notifyInventoryShimInternalListener {} type {} for container {}", new Object[] {
382                     nodeConnector, type, container });
383         }
384     }
385
386     /*
387      * Notify all internal and external listeners
388      */
389     private void notifyInventoryShimListener(NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
390
391         //establish locality before notifying
392         boolean isNodeLocal;
393         if (type == UpdateType.REMOVED){
394             //if removing get the locality first
395             isNodeLocal = connectionOutService.isLocal(nodeConnector.getNode());
396             notifyGlobalInventoryShimInternalListener(nodeConnector, type, props);
397         } else {
398             notifyGlobalInventoryShimInternalListener(nodeConnector, type, props);
399             isNodeLocal = connectionOutService.isLocal(nodeConnector.getNode());
400         }
401
402         if (isNodeLocal) {
403             // notify other containers
404             Set<String> containers = (nodeConnectorContainerMap.get(nodeConnector) == null) ? new HashSet<String>()
405                     : new HashSet<String>(nodeConnectorContainerMap.get(nodeConnector));
406             containers.add(GlobalConstants.DEFAULT.toString());
407             for (String container : containers) {
408                 notifyInventoryShimInternalListener(container, nodeConnector, type, props);
409             }
410
411             // Notify plugin listeners (Discovery, DataPacket, OFstats etc.)
412             notifyInventoryShimExternalListener(nodeConnector, type, props);
413
414             logger.debug("Connection service accepted the inventory notification for {} {}", nodeConnector, type);
415         } else {
416             logger.debug("Connection service dropped the inventory notification for {} {}", nodeConnector, type);
417         }
418     }
419
420     /*
421      * Notify all internal and external listeners
422      */
423     private void notifyInventoryShimListener(Node node, UpdateType type, Set<Property> props) {
424
425         //establish locality before notifying
426         boolean isNodeLocal;
427         if (type == UpdateType.REMOVED){
428             //if removing get the locality first
429             isNodeLocal = connectionOutService.isLocal(node);
430             notifyGlobalInventoryShimInternalListener(node, type, props);
431         } else {
432             notifyGlobalInventoryShimInternalListener(node, type, props);
433             isNodeLocal = connectionOutService.isLocal(node);
434         }
435
436         if (isNodeLocal) {
437             // Now notify other containers
438             Set<String> containers = (nodeContainerMap.get(node) == null) ? new HashSet<String>()
439                     : new HashSet<String>(nodeContainerMap.get(node));
440             containers.add(GlobalConstants.DEFAULT.toString());
441             for (String container : containers) {
442                 notifyInventoryShimInternalListener(container, node, type, props);
443             }
444
445             // Notify plugin listeners (Discovery, DataPacket, OFstats etc.)
446             notifyInventoryShimExternalListener(node, type, props);
447
448             logger.debug("Connection service accepted the inventory notification for {} {}", node, type);
449         } else {
450             logger.debug("Connection service dropped the inventory notification for {} {}", node, type);
451         }
452     }
453
454     private void notifyGlobalInventoryShimInternalListener(Node node, UpdateType type, Set<Property> props) {
455         for (IInventoryShimInternalListener globalListener : globalInventoryShimInternalListeners) {
456             globalListener.updateNode(node, type, props);
457             logger.trace("notifyGlobalInventoryShimInternalListener {} type {}", new Object[] { node, type });
458         }
459     }
460
461     private void notifyGlobalInventoryShimInternalListener(NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
462         for (IInventoryShimInternalListener globalListener : globalInventoryShimInternalListeners) {
463             globalListener.updateNodeConnector(nodeConnector, type, props);
464             logger.trace(
465                     "notifyGlobalInventoryShimInternalListener {} type {}",
466                     new Object[] { nodeConnector, type });
467         }
468     }
469
470     private void notifyInventoryShimInternalListener(String container,
471             Node node, UpdateType type, Set<Property> props) {
472         IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners
473                 .get(container);
474         if (inventoryShimInternalListener != null) {
475             inventoryShimInternalListener.updateNode(node, type, props);
476             logger.trace(
477                     "notifyInventoryShimInternalListener {} type {} for container {}",
478                     new Object[] { node, type, container });
479         }
480     }
481
482     private void addNode(ISwitch sw) {
483         Node node = NodeCreator.createOFNode(sw.getId());
484         UpdateType type = UpdateType.ADDED;
485
486         Set<Property> props = new HashSet<Property>();
487         Long sid = (Long) node.getID();
488
489         Date connectedSince = sw.getConnectedDate();
490         Long connectedSinceTime = (connectedSince == null) ? 0 : connectedSince
491                 .getTime();
492         props.add(new TimeStamp(connectedSinceTime, "connectedSince"));
493         props.add(new MacAddress(deriveMacAddress(sid)));
494
495         byte tables = sw.getTables();
496         Tables t = new Tables(tables);
497         if (t != null) {
498             props.add(t);
499         }
500         int cap = sw.getCapabilities();
501         Capabilities c = new Capabilities(cap);
502         if (c != null) {
503             props.add(c);
504         }
505         int act = sw.getActions();
506         Actions a = new Actions(act);
507         if (a != null) {
508             props.add(a);
509         }
510         int buffers = sw.getBuffers();
511         Buffers b = new Buffers(buffers);
512         if (b != null) {
513             props.add(b);
514         }
515
516         if ((nodeProps.get(node) == null) &&  (connectionOutService.isLocal(node)))  {
517             // The switch is connected for the first time, flush all flows
518             // that may exist on this switch
519             sw.deleteAllFlows();
520        }
521         nodeProps.put(node, props);
522         // Notify all internal and external listeners
523         notifyInventoryShimListener(node, type, props);
524     }
525
526     private void removeNode(ISwitch sw) {
527         Node node = NodeCreator.createOFNode(sw.getId());
528         if(node == null) {
529             return;
530         }
531         removeNodeConnectorProps(node);
532         nodeProps.remove(node);
533         UpdateType type = UpdateType.REMOVED;
534         // Notify all internal and external listeners
535         notifyInventoryShimListener(node, type, null);
536     }
537
538     private void startService() {
539         // Get a snapshot of all the existing switches
540         Map<Long, ISwitch> switches = this.controller.getSwitches();
541         for (ISwitch sw : switches.values()) {
542             switchAdded(sw);
543         }
544     }
545
546     private void removeNodeConnectorProps(Node node) {
547         List<NodeConnector> ncList = new ArrayList<NodeConnector>();
548         for (NodeConnector nc : nodeConnectorProps.keySet()) {
549             if (nc.getNode().equals(node)) {
550                 ncList.add(nc);
551             }
552         }
553         for (NodeConnector nc : ncList) {
554             nodeConnectorProps.remove(nc);
555         }
556     }
557
558     @Override
559     public void descriptionStatisticsRefreshed(Long switchId, List<OFStatistics> descriptionStats) {
560         Node node = NodeCreator.createOFNode(switchId);
561         Set<Property> properties = new HashSet<Property>(1);
562         OFDescriptionStatistics ofDesc = (OFDescriptionStatistics) descriptionStats.get(0);
563         Description desc = new Description(ofDesc.getDatapathDescription());
564         properties.add(desc);
565
566         // Notify all internal and external listeners
567         notifyInventoryShimListener(node, UpdateType.CHANGED, properties);
568     }
569
570     private byte[] deriveMacAddress(long dpid) {
571         byte[] mac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
572
573         for (short i = 0; i < 6; i++) {
574             mac[5 - i] = (byte) dpid;
575             dpid >>= 8;
576         }
577
578         return mac;
579     }
580
581     @Override
582     public void flowStatisticsRefreshed(Long switchId, List<OFStatistics> flows) {
583         // Nothing to do
584     }
585
586     @Override
587     public void portStatisticsRefreshed(Long switchId, List<OFStatistics> ports) {
588         // Nothing to do
589     }
590
591     @Override
592     public void tableStatisticsRefreshed(Long switchId, List<OFStatistics> tables) {
593         // Nothing to do
594     }
595
596     @Override
597     public void containerCreate(String containerName) {
598         // Nothing to do
599     }
600
601     @Override
602     public void containerDestroy(String containerName) {
603         Set<NodeConnector> removeNodeConnectorSet = new HashSet<NodeConnector>();
604         Set<Node> removeNodeSet = new HashSet<Node>();
605         for (Map.Entry<NodeConnector, Set<String>> entry : nodeConnectorContainerMap.entrySet()) {
606             Set<String> ncContainers = entry.getValue();
607             if (ncContainers.contains(containerName)) {
608                 NodeConnector nodeConnector = entry.getKey();
609                 removeNodeConnectorSet.add(nodeConnector);
610             }
611         }
612         for (Map.Entry<Node, Set<String>> entry : nodeContainerMap.entrySet()) {
613             Set<String> nodeContainers = entry.getValue();
614             if (nodeContainers.contains(containerName)) {
615                 Node node = entry.getKey();
616                 removeNodeSet.add(node);
617             }
618         }
619         for (NodeConnector nodeConnector : removeNodeConnectorSet) {
620             Set<String> ncContainers = nodeConnectorContainerMap.get(nodeConnector);
621             ncContainers.remove(containerName);
622             if (ncContainers.isEmpty()) {
623                 nodeConnectorContainerMap.remove(nodeConnector);
624             }
625         }
626         for (Node node : removeNodeSet) {
627             Set<String> nodeContainers = nodeContainerMap.get(node);
628             nodeContainers.remove(containerName);
629             if (nodeContainers.isEmpty()) {
630                 nodeContainerMap.remove(node);
631             }
632         }
633     }
634 }