use of org.onosproject.net.region.Region in project onos by opennetworkinglab.
the class RegionsWebResource method removeDevices.
/**
* Removes the specified collection of devices from the region.
*
* @param regionId region identifier
* @param stream deviceIds JSON stream
* @return 204 NO CONTENT
* @onos.rsModel RegionDeviceIds
*/
@DELETE
@Path("{regionId}/devices")
@Consumes(MediaType.APPLICATION_JSON)
public Response removeDevices(@PathParam("regionId") String regionId, InputStream stream) {
RegionId rid = RegionId.regionId(regionId);
Region region = nullIsNotFound(regionService.getRegion(rid), REGION_NOT_FOUND + rid);
try {
regionAdminService.removeDevices(rid, extractDeviceIds(stream));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return Response.noContent().build();
}
use of org.onosproject.net.region.Region in project onos by opennetworkinglab.
the class RegionsWebResource method getRegionById.
/**
* Returns the region with the specified identifier.
*
* @param regionId region identifier
* @return 200 OK with a region, 404 not found
* @onos.rsModel Region
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{regionId}")
public Response getRegionById(@PathParam("regionId") String regionId) {
final RegionId rid = RegionId.regionId(regionId);
final Region region = nullIsNotFound(regionService.getRegion(rid), REGION_NOT_FOUND + rid.toString());
return ok(codec(Region.class).encode(region, this)).build();
}
use of org.onosproject.net.region.Region in project onos by opennetworkinglab.
the class DistributedRegionStoreTest method basics.
@Test
public void basics() {
Region r1 = store.createRegion(RID1, "R1", METRO, NO_ANNOTS, MASTERS);
assertEquals("incorrect id", RID1, r1.id());
assertEquals("incorrect event", REGION_ADDED, event.type());
Region r2 = store.createRegion(RID2, "R2", CAMPUS, NO_ANNOTS, MASTERS);
assertEquals("incorrect id", RID2, r2.id());
assertEquals("incorrect type", CAMPUS, r2.type());
assertEquals("incorrect event", REGION_ADDED, event.type());
r2 = store.updateRegion(RID2, "R2", COUNTRY, NO_ANNOTS, MASTERS);
assertEquals("incorrect type", COUNTRY, r2.type());
assertEquals("incorrect event", REGION_UPDATED, event.type());
Set<Region> regions = store.getRegions();
assertEquals("incorrect size", 2, regions.size());
assertTrue("missing r1", regions.contains(r1));
assertTrue("missing r2", regions.contains(r2));
r1 = store.getRegion(RID1);
assertEquals("incorrect id", RID1, r1.id());
store.removeRegion(RID1);
regions = store.getRegions();
assertEquals("incorrect size", 1, regions.size());
assertTrue("missing r2", regions.contains(r2));
assertEquals("incorrect event", REGION_REMOVED, event.type());
}
use of org.onosproject.net.region.Region in project onos by opennetworkinglab.
the class DistributedRegionStore method addDevices.
@Override
public void addDevices(RegionId regionId, Collection<DeviceId> deviceIds) {
// attempting to add it.
for (DeviceId deviceId : deviceIds) {
Region region = getRegionForDevice(deviceId);
if ((region != null) && (!regionId.id().equals(region.id().id()))) {
Set<DeviceId> deviceIdSet1 = ImmutableSet.of(deviceId);
removeDevices(region.id(), deviceIdSet1);
}
}
membershipRepo.compute(regionId, (id, existingDevices) -> {
if (existingDevices == null) {
return ImmutableSet.copyOf(deviceIds);
} else if (!existingDevices.containsAll(deviceIds)) {
return ImmutableSet.<DeviceId>builder().addAll(existingDevices).addAll(deviceIds).build();
} else {
return existingDevices;
}
});
Region region = regionsById.get(regionId);
deviceIds.forEach(deviceId -> regionsByDevice.put(deviceId, region));
}
use of org.onosproject.net.region.Region in project onos by opennetworkinglab.
the class Topo2Jsonifier method jsonClosedRegion.
private ObjectNode jsonClosedRegion(String ridStr, UiRegion region) {
ObjectNode node = objectNode().put("id", region.idAsString()).put("name", region.name()).put("nodeType", REGION).put("nDevs", region.deviceCount()).put("nHosts", region.hostCount());
// TODO: device and host counts should take into account any nested
// subregions. i.e. should be the sum of all devices/hosts in
// all descendant subregions.
Region r = region.backingRegion();
if (r != null) {
// add data injected via network configuration script
addGeoGridLocation(node, r);
addProps(node, r);
}
// this may contain location data, as dragged by user
// (which should take precedence, over configured data)
addMetaUi(node, ridStr, region.idAsString());
return node;
}
Aggregations