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 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;
}
use of org.onosproject.net.region.Region in project onos by opennetworkinglab.
the class ModelCache method updateDevice.
// make sure the UiDevice is tagged with the region it belongs to
private void updateDevice(UiDevice device) {
Region r = services.region().getRegionForDevice(device.id());
RegionId rid = r == null ? UiRegion.NULL_ID : r.id();
device.setRegionId(rid);
}
use of org.onosproject.net.region.Region in project onos by opennetworkinglab.
the class RegionsWebResource method updateRegion.
/**
* Updates the specified region using the supplied JSON input stream.
*
* @param regionId region identifier
* @param stream region JSON stream
* @return status of the request - UPDATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel RegionPost
*/
@PUT
@Path("{regionId}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateRegion(@PathParam("regionId") String regionId, InputStream stream) {
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
JsonNode specifiedRegionId = jsonTree.get("id");
if (specifiedRegionId != null && !specifiedRegionId.asText().equals(regionId)) {
throw new IllegalArgumentException(REGION_INVALID);
}
final Region region = codec(Region.class).decode(jsonTree, this);
regionAdminService.updateRegion(region.id(), region.name(), region.type(), region.masters());
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return Response.ok().build();
}
Aggregations