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);
}
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);
}
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));
}
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();
}
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();
}
Aggregations