Search in sources :

Example 21 with Region

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());
}
Also used : Region(org.onosproject.net.region.Region) Test(org.junit.Test)

Example 22 with 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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Region(org.onosproject.net.region.Region) UiRegion(org.onosproject.ui.model.topo.UiRegion)

Example 23 with Region

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);
}
Also used : Region(org.onosproject.net.region.Region) UiRegion(org.onosproject.ui.model.topo.UiRegion) RegionId(org.onosproject.net.region.RegionId)

Example 24 with Region

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Region(org.onosproject.net.region.Region) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Region (org.onosproject.net.region.Region)24 Test (org.junit.Test)9 Set (java.util.Set)7 NodeId (org.onosproject.cluster.NodeId)7 RegionId (org.onosproject.net.region.RegionId)7 DeviceId (org.onosproject.net.DeviceId)6 DefaultRegion (org.onosproject.net.region.DefaultRegion)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 IOException (java.io.IOException)4 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Produces (javax.ws.rs.Produces)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2