Search in sources :

Example 1 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class UiTopology method inferSyntheticLink.

private UiSynthLink inferSyntheticLink(UiDeviceLink link) {
    /*
          Look at the containment hierarchy of each end of the link. Find the
          common ancestor region R. A synthetic link will be added to R, based
          on the "next" node back down the branch...

                S1 --- S2       * in the same region ...
                :      :
                R      R          return S1 --- S2 (same link instance)


                S1 --- S2       * in different regions (R1, R2) at same level
                :      :
                R1     R2         return R1 --- R2
                :      :
                R      R

                S1 --- S2       * in different regions at different levels
                :      :
                R1     R2         return R1 --- R3
                :      :
                R      R3
                       :
                       R

                S1 --- S2       * in different regions at different levels
                :      :
                R      R2         return S1 --- R2
                       :
                       R

         */
    DeviceId a = link.deviceA();
    DeviceId b = link.deviceB();
    List<RegionId> aBranch = ancestors(a);
    List<RegionId> bBranch = ancestors(b);
    if (aBranch == null || bBranch == null) {
        return null;
    }
    return makeSynthLink(link, aBranch, bBranch);
}
Also used : DeviceId(org.onosproject.net.DeviceId) RegionId(org.onosproject.net.region.RegionId)

Example 2 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class RegionProtoTranslator method translate.

/**
 * Translates gRPC RegionProto message to {@link org.onosproject.net.region.Region}.
 *
 * @param region gRPC message
 * @return {@link org.onosproject.net.region.Region}
 */
public static Region translate(RegionProtoOuterClass.RegionProto region) {
    RegionId id = RegionId.regionId(region.getRegionId());
    Region.Type type = RegionEnumsProtoTranslator.translate(region.getType()).get();
    String name = Strings.nullToEmpty(region.getName());
    List<Set<NodeId>> masters = new ArrayList<>();
    region.getMastersList().forEach(s -> {
        Set<NodeId> nodeIdSet = new HashSet<NodeId>();
        s.getNodeIdList().forEach(n -> {
            nodeIdSet.add(new NodeId(n));
        });
        masters.add(nodeIdSet);
    });
    Annotations annots = AnnotationsTranslator.asAnnotations(region.getAnnotations());
    return new DefaultRegion(id, name, type, annots, masters);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Annotations(org.onosproject.net.Annotations) ArrayList(java.util.ArrayList) NodeId(org.onosproject.cluster.NodeId) Region(org.onosproject.net.region.Region) DefaultRegion(org.onosproject.net.region.DefaultRegion) DefaultRegion(org.onosproject.net.region.DefaultRegion) RegionId(org.onosproject.net.region.RegionId) HashSet(java.util.HashSet)

Example 3 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class SubjectFactoriesTest method testRegionIdFactory.

@Test
public void testRegionIdFactory() {
    SubjectFactory<RegionId> regionIdFactory = SubjectFactories.REGION_SUBJECT_FACTORY;
    assertThat(regionIdFactory, notNullValue());
    String region1 = "region1";
    RegionId id = RegionId.regionId(region1);
    RegionId createdRegionId = regionIdFactory.createSubject(region1);
    assertThat(createdRegionId.id(), equalTo(region1));
    assertThat(regionIdFactory.subjectKey(id), is(region1));
}
Also used : RegionId(org.onosproject.net.region.RegionId) Test(org.junit.Test)

Example 4 with RegionId

use of org.onosproject.net.region.RegionId in project onos by opennetworkinglab.

the class RegionsWebResource method addDevices.

/**
 * Adds the specified collection of devices to the region.
 *
 * @param regionId region identifier
 * @param stream deviceIds JSON stream
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel RegionDeviceIds
 */
@POST
@Path("{regionId}/devices")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addDevices(@PathParam("regionId") String regionId, InputStream stream) {
    RegionId rid = RegionId.regionId(regionId);
    Region region = nullIsNotFound(regionService.getRegion(rid), REGION_NOT_FOUND + rid);
    URI location;
    try {
        regionAdminService.addDevices(region.id(), extractDeviceIds(stream));
        location = new URI(rid.id());
    } catch (IOException | URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
    return Response.created(location).build();
}
Also used : Region(org.onosproject.net.region.Region) RegionId(org.onosproject.net.region.RegionId) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with RegionId

use of org.onosproject.net.region.RegionId 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)

Aggregations

RegionId (org.onosproject.net.region.RegionId)25 DeviceId (org.onosproject.net.DeviceId)7 Region (org.onosproject.net.region.Region)7 Set (java.util.Set)5 Path (javax.ws.rs.Path)5 RegionAdminService (org.onosproject.net.region.RegionAdminService)5 HashSet (java.util.HashSet)4 NodeId (org.onosproject.cluster.NodeId)4 UiRegion (org.onosproject.ui.model.topo.UiRegion)4 Produces (javax.ws.rs.Produces)3 Annotations (org.onosproject.net.Annotations)3 DefaultRegion (org.onosproject.net.region.DefaultRegion)3 UiTopoLayout (org.onosproject.ui.model.topo.UiTopoLayout)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2