Fixed bug in OpenstackNode
- OVSDB client has changed to update br-int even if there's br-int already in device - So OpenstackNode modified only the leader node to performs node bootstrap Change-Id: Ie01843ca8ab36ec61b58e80ce20c0c8c31ff8273
Showing
1 changed file
with
29 additions
and
5 deletions
... | @@ -26,6 +26,8 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -26,6 +26,8 @@ import org.apache.felix.scr.annotations.Service; |
26 | import org.onlab.util.ItemNotFoundException; | 26 | import org.onlab.util.ItemNotFoundException; |
27 | import org.onlab.util.KryoNamespace; | 27 | import org.onlab.util.KryoNamespace; |
28 | import org.onosproject.cluster.ClusterService; | 28 | import org.onosproject.cluster.ClusterService; |
29 | +import org.onosproject.cluster.LeadershipService; | ||
30 | +import org.onosproject.cluster.NodeId; | ||
29 | import org.onosproject.core.ApplicationId; | 31 | import org.onosproject.core.ApplicationId; |
30 | import org.onosproject.core.CoreService; | 32 | import org.onosproject.core.CoreService; |
31 | import org.onosproject.net.DefaultAnnotations; | 33 | import org.onosproject.net.DefaultAnnotations; |
... | @@ -60,6 +62,7 @@ import org.onosproject.store.service.Serializer; | ... | @@ -60,6 +62,7 @@ import org.onosproject.store.service.Serializer; |
60 | import org.onosproject.store.service.StorageService; | 62 | import org.onosproject.store.service.StorageService; |
61 | import org.slf4j.Logger; | 63 | import org.slf4j.Logger; |
62 | 64 | ||
65 | +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
63 | import static org.onlab.util.Tools.groupedThreads; | 66 | import static org.onlab.util.Tools.groupedThreads; |
64 | import static org.onosproject.net.Device.Type.SWITCH; | 67 | import static org.onosproject.net.Device.Type.SWITCH; |
65 | import static org.onosproject.net.behaviour.TunnelDescription.Type.VXLAN; | 68 | import static org.onosproject.net.behaviour.TunnelDescription.Type.VXLAN; |
... | @@ -69,7 +72,6 @@ import java.util.ArrayList; | ... | @@ -69,7 +72,6 @@ import java.util.ArrayList; |
69 | import java.util.List; | 72 | import java.util.List; |
70 | import java.util.Map; | 73 | import java.util.Map; |
71 | import java.util.concurrent.ExecutorService; | 74 | import java.util.concurrent.ExecutorService; |
72 | -import java.util.concurrent.Executors; | ||
73 | import java.util.stream.Collectors; | 75 | import java.util.stream.Collectors; |
74 | 76 | ||
75 | import static com.google.common.base.Preconditions.checkNotNull; | 77 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -82,7 +84,6 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -82,7 +84,6 @@ import static com.google.common.base.Preconditions.checkNotNull; |
82 | @Service | 84 | @Service |
83 | public class OpenstackNodeManager implements OpenstackNodeService { | 85 | public class OpenstackNodeManager implements OpenstackNodeService { |
84 | protected final Logger log = getLogger(getClass()); | 86 | protected final Logger log = getLogger(getClass()); |
85 | - private static final int NUM_THREADS = 1; | ||
86 | private static final KryoNamespace.Builder NODE_SERIALIZER = KryoNamespace.newBuilder() | 87 | private static final KryoNamespace.Builder NODE_SERIALIZER = KryoNamespace.newBuilder() |
87 | .register(KryoNamespaces.API) | 88 | .register(KryoNamespaces.API) |
88 | .register(OpenstackNode.class) | 89 | .register(OpenstackNode.class) |
... | @@ -127,6 +128,9 @@ public class OpenstackNodeManager implements OpenstackNodeService { | ... | @@ -127,6 +128,9 @@ public class OpenstackNodeManager implements OpenstackNodeService { |
127 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
128 | protected NetworkConfigRegistry configRegistry; | 129 | protected NetworkConfigRegistry configRegistry; |
129 | 130 | ||
131 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
132 | + protected LeadershipService leadershipService; | ||
133 | + | ||
130 | private final OvsdbHandler ovsdbHandler = new OvsdbHandler(); | 134 | private final OvsdbHandler ovsdbHandler = new OvsdbHandler(); |
131 | private final BridgeHandler bridgeHandler = new BridgeHandler(); | 135 | private final BridgeHandler bridgeHandler = new BridgeHandler(); |
132 | private final NetworkConfigListener configListener = new InternalConfigListener(); | 136 | private final NetworkConfigListener configListener = new InternalConfigListener(); |
... | @@ -138,13 +142,15 @@ public class OpenstackNodeManager implements OpenstackNodeService { | ... | @@ -138,13 +142,15 @@ public class OpenstackNodeManager implements OpenstackNodeService { |
138 | } | 142 | } |
139 | }; | 143 | }; |
140 | 144 | ||
141 | - private final ExecutorService eventExecutor = Executors | 145 | + private final ExecutorService eventExecutor = |
142 | - .newFixedThreadPool(NUM_THREADS, groupedThreads("onos/openstacknode", "event-handler")); | 146 | + newSingleThreadScheduledExecutor(groupedThreads("onos/openstacknode", "event-handler")); |
147 | + | ||
143 | 148 | ||
144 | private final DeviceListener deviceListener = new InternalDeviceListener(); | 149 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
145 | 150 | ||
146 | private ApplicationId appId; | 151 | private ApplicationId appId; |
147 | private ConsistentMap<OpenstackNode, NodeState> nodeStore; | 152 | private ConsistentMap<OpenstackNode, NodeState> nodeStore; |
153 | + private NodeId localNodeId; | ||
148 | 154 | ||
149 | private enum NodeState { | 155 | private enum NodeState { |
150 | 156 | ||
... | @@ -192,6 +198,9 @@ public class OpenstackNodeManager implements OpenstackNodeService { | ... | @@ -192,6 +198,9 @@ public class OpenstackNodeManager implements OpenstackNodeService { |
192 | @Activate | 198 | @Activate |
193 | protected void activate() { | 199 | protected void activate() { |
194 | appId = coreService.registerApplication(OPENSTACK_NODEMANAGER_ID); | 200 | appId = coreService.registerApplication(OPENSTACK_NODEMANAGER_ID); |
201 | + localNodeId = clusterService.getLocalNode().id(); | ||
202 | + leadershipService.runForLeadership(appId.name()); | ||
203 | + | ||
195 | nodeStore = storageService.<OpenstackNode, NodeState>consistentMapBuilder() | 204 | nodeStore = storageService.<OpenstackNode, NodeState>consistentMapBuilder() |
196 | .withSerializer(Serializer.using(NODE_SERIALIZER.build())) | 205 | .withSerializer(Serializer.using(NODE_SERIALIZER.build())) |
197 | .withName(OPENSTACK_NODESTORE) | 206 | .withName(OPENSTACK_NODESTORE) |
... | @@ -214,6 +223,7 @@ public class OpenstackNodeManager implements OpenstackNodeService { | ... | @@ -214,6 +223,7 @@ public class OpenstackNodeManager implements OpenstackNodeService { |
214 | 223 | ||
215 | configRegistry.unregisterConfigFactory(configFactory); | 224 | configRegistry.unregisterConfigFactory(configFactory); |
216 | configService.removeListener(configListener); | 225 | configService.removeListener(configListener); |
226 | + leadershipService.withdraw(appId.name()); | ||
217 | 227 | ||
218 | log.info("Stopped"); | 228 | log.info("Stopped"); |
219 | } | 229 | } |
... | @@ -223,8 +233,15 @@ public class OpenstackNodeManager implements OpenstackNodeService { | ... | @@ -223,8 +233,15 @@ public class OpenstackNodeManager implements OpenstackNodeService { |
223 | public void addNode(OpenstackNode node) { | 233 | public void addNode(OpenstackNode node) { |
224 | checkNotNull(node, "Node cannot be null"); | 234 | checkNotNull(node, "Node cannot be null"); |
225 | 235 | ||
226 | - nodeStore.putIfAbsent(node, checkNodeState(node)); | 236 | + NodeId leaderNodeId = leadershipService.getLeader(appId.name()); |
237 | + log.debug("Node init requested, localNodeId: {}, leaderNodeId: {}", localNodeId, leaderNodeId); | ||
227 | 238 | ||
239 | + //TODO: Fix any node can engage this operation. | ||
240 | + if (!localNodeId.equals(leaderNodeId)) { | ||
241 | + log.debug("Only the leaderNode can perform addNode operation"); | ||
242 | + return; | ||
243 | + } | ||
244 | + nodeStore.putIfAbsent(node, checkNodeState(node)); | ||
228 | NodeState state = checkNodeState(node); | 245 | NodeState state = checkNodeState(node); |
229 | state.process(this, node); | 246 | state.process(this, node); |
230 | } | 247 | } |
... | @@ -488,6 +505,13 @@ public class OpenstackNodeManager implements OpenstackNodeService { | ... | @@ -488,6 +505,13 @@ public class OpenstackNodeManager implements OpenstackNodeService { |
488 | 505 | ||
489 | @Override | 506 | @Override |
490 | public void event(DeviceEvent event) { | 507 | public void event(DeviceEvent event) { |
508 | + NodeId leaderNodeId = leadershipService.getLeader(appId.name()); | ||
509 | + | ||
510 | + //TODO: Fix any node can engage this operation. | ||
511 | + if (!localNodeId.equals(leaderNodeId)) { | ||
512 | + log.debug("Only the leaderNode can process events"); | ||
513 | + return; | ||
514 | + } | ||
491 | 515 | ||
492 | Device device = event.subject(); | 516 | Device device = event.subject(); |
493 | ConnectionHandler<Device> handler = | 517 | ConnectionHandler<Device> handler = | ... | ... |
-
Please register or login to post a comment