Merge "Bug 1029: Remove dead code: samples/clustersession"
[controller.git] / opendaylight / adsal / containermanager / implementation / src / main / java / org / opendaylight / controller / containermanager / internal / ContainerImpl.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 /**
11  * @file   ContainerImpl.java
12  *
13  * @brief  Class that instantiated per-container implements the
14  * interface IContainer
15  *
16  */
17 package org.opendaylight.controller.containermanager.internal;
18
19 import java.util.ArrayList;
20 import java.util.Dictionary;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.concurrent.ConcurrentMap;
26
27 import org.apache.felix.dm.Component;
28 import org.opendaylight.controller.containermanager.ContainerData;
29 import org.opendaylight.controller.sal.core.ContainerFlow;
30 import org.opendaylight.controller.sal.core.IContainer;
31 import org.opendaylight.controller.sal.core.Node;
32 import org.opendaylight.controller.sal.core.NodeConnector;
33
34 public class ContainerImpl implements IContainer {
35     private String containerName = null;
36     private IContainerInternal iContainerInternal = null;
37
38     public void setIContainerInternal(IContainerInternal s) {
39         this.iContainerInternal = s;
40     }
41
42     public void unsetIContainerInternal(IContainerInternal s) {
43         if (this.iContainerInternal == s) {
44             this.iContainerInternal = null;
45         }
46     }
47
48     /**
49      * Function called by the dependency manager when all the required
50      * dependencies are satisfied
51      *
52      */
53     void init(Component c) {
54         Dictionary<?, ?> props = c.getServiceProperties();
55         if (props != null) {
56             this.containerName = (String) props.get("containerName");
57         }
58     }
59
60     @Override
61     public String getName() {
62         return this.containerName;
63     }
64
65     @Override
66     public List<ContainerFlow> getContainerFlows() {
67         List<ContainerFlow> list = new ArrayList<ContainerFlow>();
68
69         ContainerData d = this.iContainerInternal.getContainerData(this.containerName);
70         if (d != null) {
71             list.addAll(d.getContainerFlowSpecs());
72         }
73         return list;
74     }
75
76     @Override
77     public short getTag(Node n) {
78         ContainerData d = this.iContainerInternal.getContainerData(this.containerName);
79         if (d != null) {
80             return d.getStaticVlan();
81         }
82         // Return 0 because in containerData that means an unassigned tag
83         return (short) 0;
84     }
85
86     @Override
87     public Set<NodeConnector> getNodeConnectors() {
88         Set<NodeConnector> set = new HashSet<NodeConnector>();
89
90         ContainerData d = this.iContainerInternal.getContainerData(this.containerName);
91         if (d != null) {
92             ConcurrentMap<Node, Set<NodeConnector>> m = d.getSwPorts();
93             if (m != null) {
94                 for (Map.Entry<Node, Set<NodeConnector>> entry : m.entrySet()) {
95                     set.addAll(entry.getValue());
96                 }
97             }
98         }
99         return set;
100     }
101
102     @Override
103     public Set<Node> getNodes() {
104         Set<Node> set = new HashSet<Node>();
105
106         ContainerData d = this.iContainerInternal.getContainerData(this.containerName);
107         if (d != null) {
108             ConcurrentMap<Node, Set<NodeConnector>> m = d.getSwPorts();
109             if (m != null) {
110                 set.addAll(m.keySet());
111             }
112         }
113         return set;
114     }
115
116     @Override
117     public String getContainerAdminRole() {
118         return iContainerInternal.getContainerData(containerName).getContainerAdminRole();
119     }
120
121     @Override
122     public String getContainerOperatorRole() {
123         return iContainerInternal.getContainerData(containerName).getContainerOperatorRole();
124     }
125 }