Search in sources :

Example 6 with NodeId

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));
}
Also used : NodeId(org.onosproject.cluster.NodeId) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode)

Example 7 with NodeId

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();
}
Also used : DeviceId(org.onosproject.net.DeviceId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) MastershipServiceAdapter(org.onosproject.mastership.MastershipServiceAdapter) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Test(org.junit.Test)

Example 8 with NodeId

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");
}
Also used : ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ClusterService(org.onosproject.cluster.ClusterService) TestStorageService(org.onosproject.store.service.TestStorageService) NodeId(org.onosproject.cluster.NodeId) ClusterCommunicationServiceAdapter(org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter) Before(org.junit.Before)

Example 9 with NodeId

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));
}
Also used : PacketPriority(org.onosproject.net.packet.PacketPriority) DefaultPacketRequest(org.onosproject.net.packet.DefaultPacketRequest) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ApplicationId(org.onosproject.core.ApplicationId)

Example 10 with NodeId

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);
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

NodeId (org.onosproject.cluster.NodeId)150 DeviceId (org.onosproject.net.DeviceId)38 ClusterService (org.onosproject.cluster.ClusterService)36 Set (java.util.Set)26 MastershipRole (org.onosproject.net.MastershipRole)23 ControllerNode (org.onosproject.cluster.ControllerNode)22 Test (org.junit.Test)18 Activate (org.osgi.service.component.annotations.Activate)18 List (java.util.List)16 MastershipService (org.onosproject.mastership.MastershipService)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 Map (java.util.Map)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)10 ClusterCommunicationService (org.onosproject.store.cluster.messaging.ClusterCommunicationService)10 Component (org.osgi.service.component.annotations.Component)9 Deactivate (org.osgi.service.component.annotations.Deactivate)9