use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class CoordinationManager method eventuallyConsistentMapBuilder.
@Override
public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() {
checkPermission(STORAGE_WRITE);
final NodeId localNodeId = clusterService.getLocalNode().id();
Supplier<List<NodeId>> peersSupplier = () -> clusterService.getNodes().stream().map(ControllerNode::id).filter(nodeId -> !nodeId.equals(localNodeId)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
Supplier<List<NodeId>> bootstrapPeersSupplier = () -> clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> !localNodeId.equals(id)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
return new EventuallyConsistentMapBuilderImpl<>(localNodeId, clusterCommunicator, persistenceService, peersSupplier, bootstrapPeersSupplier);
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class AtomixClusterStore method changeMembership.
private void changeMembership(ClusterMembershipEvent event) {
ControllerNode node = nodes.get(NodeId.nodeId(event.subject().id().id()));
log.debug("Received a membership event {}", event);
switch(event.type()) {
case MEMBER_ADDED:
case METADATA_CHANGED:
if (node == null) {
node = toControllerNode(event.subject());
nodes.put(node.id(), node);
notifyDelegate(clusterEvent(ClusterEvent.Type.INSTANCE_ADDED, event.subject(), node));
}
updateVersion(node, event.subject());
updateState(node, event.subject());
break;
case MEMBER_REMOVED:
if (node != null && states.put(node.id(), ControllerNode.State.INACTIVE) != ControllerNode.State.INACTIVE) {
notifyDelegate(clusterEvent(ClusterEvent.Type.INSTANCE_DEACTIVATED, event.subject(), node));
notifyDelegate(clusterEvent(ClusterEvent.Type.INSTANCE_REMOVED, event.subject(), node));
}
break;
default:
break;
}
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class AtomixClusterStore method addNode.
@Override
public ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort) {
checkNotNull(nodeId, INSTANCE_ID_NULL);
ControllerNode node = new DefaultControllerNode(nodeId, ip, tcpPort);
nodes.put(node.id(), node);
ControllerNode.State state = node.equals(localNode) ? ControllerNode.State.ACTIVE : ControllerNode.State.INACTIVE;
Member member = membershipService.getMember(node.id().id());
member.properties().setProperty(STATE_KEY, state.name());
notifyDelegate(clusterEvent(ClusterEvent.Type.INSTANCE_ADDED, member, node));
return node;
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class MastershipProxyManagerTest method testProxyManager.
@Test
public void testProxyManager() throws Exception {
TestClusterCommunicationServiceFactory clusterCommunicatorFactory = new TestClusterCommunicationServiceFactory();
NodeId a = NodeId.nodeId("a");
NodeId b = NodeId.nodeId("b");
DeviceId deviceId = DeviceId.deviceId("a");
Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
ProxyInterfaceImpl proxyInterface1 = new ProxyInterfaceImpl();
MastershipProxyManager proxyManager1 = new MastershipProxyManager();
proxyManager1.clusterService = new ClusterServiceAdapter() {
@Override
public ControllerNode getLocalNode() {
return new DefaultControllerNode(a, IpAddress.valueOf(0));
}
};
proxyManager1.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(a);
proxyManager1.mastershipService = new MastershipServiceAdapter() {
@Override
public NodeId getMasterFor(DeviceId deviceId) {
return b;
}
};
proxyManager1.activate();
proxyManager1.registerProxyService(ProxyInterface.class, proxyInterface1, serializer);
ProxyInterfaceImpl proxyInterface2 = new ProxyInterfaceImpl();
MastershipProxyManager proxyManager2 = new MastershipProxyManager();
proxyManager2.clusterService = new ClusterServiceAdapter() {
@Override
public ControllerNode getLocalNode() {
return new DefaultControllerNode(b, IpAddress.valueOf(0));
}
};
proxyManager2.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(b);
proxyManager2.mastershipService = new MastershipServiceAdapter() {
@Override
public NodeId getMasterFor(DeviceId deviceId) {
return b;
}
};
proxyManager2.activate();
proxyManager2.registerProxyService(ProxyInterface.class, proxyInterface2, serializer);
MastershipProxyFactory<ProxyInterface> proxyFactory1 = proxyManager1.getProxyFactory(ProxyInterface.class, serializer);
assertEquals("Hello world!", proxyFactory1.getProxyFor(deviceId).sync("Hello world!"));
assertEquals(1, proxyInterface2.syncCalls.get());
assertEquals("Hello world!", proxyFactory1.getProxyFor(deviceId).async("Hello world!").join());
assertEquals(1, proxyInterface2.asyncCalls.get());
MastershipProxyFactory<ProxyInterface> proxyFactory2 = proxyManager2.getProxyFactory(ProxyInterface.class, serializer);
assertEquals("Hello world!", proxyFactory2.getProxyFor(deviceId).sync("Hello world!"));
assertEquals(2, proxyInterface2.syncCalls.get());
assertEquals("Hello world!", proxyFactory2.getProxyFor(deviceId).async("Hello world!").join());
assertEquals(2, proxyInterface2.asyncCalls.get());
proxyManager1.deactivate();
proxyManager2.deactivate();
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class DefaultClusterMetadataProvider method activate.
@Activate
public void activate() {
String localIp = getSiteLocalAddress();
ControllerNode localNode = new DefaultControllerNode(new NodeId(localIp), IpAddress.valueOf(localIp), DEFAULT_ONOS_PORT);
ClusterMetadata metadata = new ClusterMetadata(PROVIDER_ID, "default", localNode, ImmutableSet.of(), ImmutableSet.of(), UUID.randomUUID().toString());
long version = System.currentTimeMillis();
cachedMetadata.set(new Versioned<>(metadata, version));
providerRegistry.register(this);
log.info("Started");
}
Aggregations