Search in sources :

Example 21 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class RegionUpdateCommand method doExecute.

@Override
protected void doExecute() {
    RegionService regionService = get(RegionService.class);
    RegionAdminService regionAdminService = get(RegionAdminService.class);
    RegionId regionId = RegionId.regionId(id);
    if (regionService.getRegion(regionId) == null) {
        print("The region with id %s does not exist.", regionId);
        return;
    }
    List<Set<NodeId>> masters = Lists.newArrayList();
    Set<NodeId> nodeIds = Sets.newHashSet();
    for (String masterArg : masterArgs) {
        if ("/".equals(masterArg)) {
            masters.add(nodeIds);
            nodeIds = Sets.newHashSet();
        } else {
            nodeIds.add(NodeId.nodeId(masterArg));
        }
    }
    masters.add(nodeIds);
    regionAdminService.updateRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
    print("Region with id %s is successfully updated.", regionId);
}
Also used : RegionAdminService(org.onosproject.net.region.RegionAdminService) Set(java.util.Set) NodeId(org.onosproject.cluster.NodeId) RegionService(org.onosproject.net.region.RegionService) RegionId(org.onosproject.net.region.RegionId)

Example 22 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class UiTopology method makeSynthLink.

// package private for unit testing
UiSynthLink makeSynthLink(UiDeviceLink orig, List<RegionId> aBranch, List<RegionId> bBranch) {
    final int aSize = aBranch.size();
    final int bSize = bBranch.size();
    final int min = Math.min(aSize, bSize);
    int index = 0;
    RegionId commonRegion = aBranch.get(index);
    while (true) {
        int next = index + 1;
        if (next == min) {
            // no more pairs of regions left to test
            break;
        }
        RegionId rA = aBranch.get(next);
        RegionId rB = bBranch.get(next);
        if (rA.equals(rB)) {
            commonRegion = rA;
            index++;
        } else {
            break;
        }
    }
    int endPointIndex = index + 1;
    UiLinkId linkId;
    UiLink link;
    if (endPointIndex < aSize) {
        // the A endpoint is a subregion
        RegionId aRegion = aBranch.get(endPointIndex);
        if (endPointIndex < bSize) {
            // the B endpoint is a subregion
            RegionId bRegion = bBranch.get(endPointIndex);
            linkId = uiLinkId(aRegion, bRegion);
            link = new UiRegionLink(this, linkId);
        } else {
            // the B endpoint is the device
            DeviceId dB = orig.deviceB();
            PortNumber pB = orig.portB();
            linkId = uiLinkId(aRegion, dB, pB);
            link = new UiRegionDeviceLink(this, linkId);
        }
    } else {
        // the A endpoint is the device
        DeviceId dA = orig.deviceA();
        PortNumber pA = orig.portA();
        if (endPointIndex < bSize) {
            // the B endpoint is a subregion
            RegionId bRegion = bBranch.get(endPointIndex);
            linkId = uiLinkId(bRegion, dA, pA);
            link = new UiRegionDeviceLink(this, linkId);
        } else {
            // the B endpoint is the device
            // (so, we can just use the original device-device link...)
            link = orig;
        }
    }
    return new UiSynthLink(commonRegion, link, orig);
}
Also used : DeviceId(org.onosproject.net.DeviceId) RegionId(org.onosproject.net.region.RegionId) PortNumber(org.onosproject.net.PortNumber)

Example 23 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class RegionCodecTest method testRegionEncode.

/**
 * Tests encoding of a Region object.
 */
@Test
public void testRegionEncode() {
    NodeId nodeId1 = NodeId.nodeId("1");
    NodeId nodeId2 = NodeId.nodeId("2");
    NodeId nodeId3 = NodeId.nodeId("3");
    NodeId nodeId4 = NodeId.nodeId("4");
    Set<NodeId> set1 = ImmutableSet.of(nodeId1);
    Set<NodeId> set2 = ImmutableSet.of(nodeId1, nodeId2);
    Set<NodeId> set3 = ImmutableSet.of(nodeId1, nodeId2, nodeId3);
    Set<NodeId> set4 = ImmutableSet.of(nodeId1, nodeId2, nodeId3, nodeId4);
    List<Set<NodeId>> masters = ImmutableList.of(set1, set2, set3, set4);
    RegionId regionId = RegionId.regionId("1");
    String name = "foo";
    Region.Type type = Region.Type.ROOM;
    Annotations noAnnots = DefaultAnnotations.EMPTY;
    Region region = new DefaultRegion(regionId, name, type, noAnnots, masters);
    ObjectNode regionJson = regionCodec.encode(region, context);
    assertThat(regionJson, matchesRegion(region));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) 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) DefaultRegion(org.onosproject.net.region.DefaultRegion) RegionId(org.onosproject.net.region.RegionId) Test(org.junit.Test)

Example 24 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class RegionsWebResource method getRegionDevices.

/**
 * Returns the set of devices that belong to the specified region.
 *
 * @param regionId region identifier
 * @return 200 OK with set of devices that belong to the specified region
 * @onos.rsModel RegionDeviceIds
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{regionId}/devices")
public Response getRegionDevices(@PathParam("regionId") String regionId) {
    final RegionId rid = RegionId.regionId(regionId);
    final Iterable<DeviceId> deviceIds = regionService.getRegionDevices(rid);
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode deviceIdsNode = root.putArray("deviceIds");
    deviceIds.forEach(did -> deviceIdsNode.add(did.toString()));
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) RegionId(org.onosproject.net.region.RegionId) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 25 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class RegionsWebResource method removeRegion.

/**
 * Removes the specified region using the given region identifier.
 *
 * @param regionId region identifier
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{regionId}")
public Response removeRegion(@PathParam("regionId") String regionId) {
    final RegionId rid = RegionId.regionId(regionId);
    regionAdminService.removeRegion(rid);
    return Response.noContent().build();
}
Also used : RegionId(org.onosproject.net.region.RegionId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

RegionId (org.onosproject.net.region.RegionId)25 DeviceId (org.onosproject.net.DeviceId)7 Region (org.onosproject.net.region.Region)7 Set (java.util.Set)5 Path (javax.ws.rs.Path)5 RegionAdminService (org.onosproject.net.region.RegionAdminService)5 HashSet (java.util.HashSet)4 NodeId (org.onosproject.cluster.NodeId)4 UiRegion (org.onosproject.ui.model.topo.UiRegion)4 Produces (javax.ws.rs.Produces)3 Annotations (org.onosproject.net.Annotations)3 DefaultRegion (org.onosproject.net.region.DefaultRegion)3 UiTopoLayout (org.onosproject.ui.model.topo.UiTopoLayout)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2