Search in sources :

Example 11 with Region

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();
}
Also used : Region(org.onosproject.net.region.Region) RegionId(org.onosproject.net.region.RegionId) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 12 with Region

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();
}
Also used : Region(org.onosproject.net.region.Region) RegionId(org.onosproject.net.region.RegionId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 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 14 with Region

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

Example 15 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)

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