Search in sources :

Example 61 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class DeviceRoleCommand method doExecute.

@Override
protected void doExecute() {
    MastershipAdminService service = get(MastershipAdminService.class);
    MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
    Futures.getUnchecked(service.setRole(new NodeId(node), deviceId(uri), mastershipRole));
}
Also used : MastershipAdminService(org.onosproject.mastership.MastershipAdminService) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 62 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class SimpleClusterStore method activate.

@Activate
public void activate() {
    instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
    listenerRegistry = new ListenerRegistry<>();
    eventDispatcher.addSink(WorkPartitionEvent.class, listenerRegistry);
    log.info("Started");
}
Also used : NodeId(org.onosproject.cluster.NodeId) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Activate(org.osgi.service.component.annotations.Activate)

Example 63 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class RoleInfoCodecTest method testRoleInfoEncode.

/**
 * Tests encoding of a role info object.
 */
@Test
public void testRoleInfoEncode() {
    NodeId masterNodeId = NodeId.nodeId("1");
    NodeId backupNodeId1 = NodeId.nodeId("1");
    NodeId backupNodeId2 = NodeId.nodeId("2");
    NodeId backupNodeId3 = NodeId.nodeId("3");
    List<NodeId> backupNodeIds = ImmutableList.of(backupNodeId1, backupNodeId2, backupNodeId3);
    RoleInfo roleInfo = new RoleInfo(masterNodeId, backupNodeIds);
    ObjectNode roleInfoJson = roleInfoCodec.encode(roleInfo, context);
    assertThat(roleInfoJson, RoleInfoJsonMatcher.matchesRoleInfo(roleInfo));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId) Test(org.junit.Test)

Example 64 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class RegionJsonMatcher method matchesSafely.

@Override
protected boolean matchesSafely(JsonNode jsonRegion, Description description) {
    // check id
    String jsonRegionId = jsonRegion.get("id").asText();
    String regionId = region.id().toString();
    if (!jsonRegionId.equals(regionId)) {
        description.appendText("region id was " + jsonRegionId);
        return false;
    }
    // check type
    String jsonType = jsonRegion.get("type").asText();
    String type = region.type().toString();
    if (!jsonType.equals(type)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    // check name
    String jsonName = jsonRegion.get("name").asText();
    String name = region.name();
    if (!jsonName.equals(name)) {
        description.appendText("name was " + jsonName);
        return false;
    }
    // check size of master array
    JsonNode jsonMasters = jsonRegion.get("masters");
    if (jsonMasters.size() != region.masters().size()) {
        description.appendText("masters size was " + jsonMasters.size());
        return false;
    }
    // check master
    for (Set<NodeId> set : region.masters()) {
        boolean masterFound = false;
        for (int masterIndex = 0; masterIndex < jsonMasters.size(); masterIndex++) {
            masterFound = checkEquality(jsonMasters.get(masterIndex), set);
        }
        if (!masterFound) {
            description.appendText("master not found " + set.toString());
            return false;
        }
    }
    return true;
}
Also used : NodeId(org.onosproject.cluster.NodeId) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 65 with NodeId

use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.

the class RegionCodecTest method testRegionDecode.

/**
 * Tests decoding of a json object.
 */
@Test
public void testRegionDecode() throws IOException {
    Region region = getRegion("Region.json");
    checkCommonData(region);
    assertThat(region.masters().size(), is(2));
    NodeId nodeId1 = NodeId.nodeId("1");
    NodeId nodeId2 = NodeId.nodeId("2");
    Set<NodeId> nodeIds1 = region.masters().get(0);
    Set<NodeId> nodeIds2 = region.masters().get(1);
    assertThat(nodeIds1.containsAll(ImmutableSet.of(nodeId1)), is(true));
    assertThat(nodeIds2.containsAll(ImmutableSet.of(nodeId1, nodeId2)), is(true));
}
Also used : NodeId(org.onosproject.cluster.NodeId) Region(org.onosproject.net.region.Region) RegionJsonMatcher.matchesRegion(org.onosproject.codec.impl.RegionJsonMatcher.matchesRegion) DefaultRegion(org.onosproject.net.region.DefaultRegion) Test(org.junit.Test)

Aggregations

NodeId (org.onosproject.cluster.NodeId)145 ClusterService (org.onosproject.cluster.ClusterService)36 DeviceId (org.onosproject.net.DeviceId)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