use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class ControllerNodeCodec method decode.
@Override
public ControllerNode decode(ObjectNode json, CodecContext context) {
checkNotNull(json, "JSON cannot be null");
String ip = json.path("ip").asText();
return new DefaultControllerNode(new NodeId(json.path("id").asText(ip)), IpAddress.valueOf(ip), json.path("tcpPort").asInt(DEFAULT_PORT));
}
use of org.onosproject.cluster.NodeId 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.NodeId in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method setUp.
@Before
public void setUp() throws Exception {
groupStoreImpl = new DistributedGroupStore();
groupStoreImpl.storageService = new TestStorageService();
groupStoreImpl.clusterCommunicator = new ClusterCommunicationServiceAdapter();
groupStoreImpl.mastershipService = new MasterOfAll();
groupStoreImpl.cfgService = new ComponentConfigAdapter();
groupStoreImpl.deviceService = new InternalDeviceServiceImpl();
ClusterService mockClusterService = createMock(ClusterService.class);
NodeId nodeId = new NodeId(NODE_ID);
MockControllerNode mockControllerNode = new MockControllerNode(nodeId);
expect(mockClusterService.getLocalNode()).andReturn(mockControllerNode).anyTimes();
replay(mockClusterService);
groupStoreImpl.clusterService = mockClusterService;
groupStoreImpl.activate(null);
groupStore = groupStoreImpl;
auditPendingReqQueue = TestUtils.getField(groupStoreImpl, "auditPendingReqQueue");
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class PacketRequestCodec method decode.
@Override
public PacketRequest decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class);
TrafficSelector trafficSelector = trafficSelectorCodec.decode(get(json, TRAFFIC_SELECTOR), context);
NodeId nodeId = NodeId.nodeId(extractMember(NODE_ID, json));
PacketPriority priority = PacketPriority.valueOf(extractMember(PRIORITY, json));
CoreService coreService = context.getService(CoreService.class);
// TODO check appId (currently hardcoded - should it be read from json node?)
ApplicationId appId = coreService.registerApplication(REST_APP_ID);
DeviceId deviceId = null;
JsonNode node = json.get(DEVICE_ID);
if (node != null) {
deviceId = DeviceId.deviceId(node.asText());
}
return new DefaultPacketRequest(trafficSelector, priority, appId, nodeId, Optional.ofNullable(deviceId));
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class RoleInfoCodec method decode.
@Override
public RoleInfo decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
// parse node identifier of master
NodeId nodeId = json.get(MASTER) == null ? null : NodeId.nodeId(json.get(MASTER).asText());
// parse node identifier of backups
List<NodeId> backups = new ArrayList<>();
ArrayNode backupsJson = (ArrayNode) nullIsIllegal(json.get(BACKUPS), BACKUPS + MISSING_MEMBER_MESSAGE);
IntStream.range(0, backupsJson.size()).forEach(i -> {
JsonNode backupJson = nullIsIllegal(backupsJson.get(i), "Backup node id cannot be null");
backups.add(NodeId.nodeId(backupJson.asText()));
});
return new RoleInfo(nodeId, backups);
}
Aggregations