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);
}
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);
}
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));
}
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();
}
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();
}
Aggregations