Search in sources :

Example 16 with RegionId

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

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

the class ModelCache method updateRegion.

private void updateRegion(UiRegion region) {
    RegionId rid = region.id();
    Set<DeviceId> deviceIds = services.region().getRegionDevices(rid);
    Set<HostId> hostIds = services.region().getRegionHosts(rid);
    // Make sure device objects refer to their region
    deviceIds.forEach(d -> {
        UiDevice dev = uiTopology.findDevice(d);
        if (dev != null) {
            dev.setRegionId(rid);
        } else {
            // if we don't have the UiDevice in the topology, what can we do?
            log.warn("Region device {}, but we don't have UiDevice in topology", d);
        }
    });
    hostIds.forEach(d -> {
        UiHost host = uiTopology.findHost(d);
        if (host != null) {
            host.setRegionId(rid);
        } else {
            // if we don't have the UiDevice in the topology, what can we do?
            log.warn("Region host {}, but we don't have UiHost in topology", d);
        }
    });
    // Make sure the region object refers to the devices
    region.reconcileDevices(deviceIds);
    region.reconcileHosts(hostIds);
    fixupContainmentHierarchy(region);
}
Also used : DeviceId(org.onosproject.net.DeviceId) UiDevice(org.onosproject.ui.model.topo.UiDevice) UiHost(org.onosproject.ui.model.topo.UiHost) RegionId(org.onosproject.net.region.RegionId) HostId(org.onosproject.net.HostId)

Example 18 with RegionId

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

the class RegionCodec method decode.

@Override
public Region decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    // parse masters
    List<Set<NodeId>> masters = new ArrayList<>();
    JsonNode mastersJson = json.get(MASTERS);
    checkNotNull(mastersJson);
    IntStream.range(0, mastersJson.size()).forEach(i -> {
        JsonNode setsJson = mastersJson.get(i);
        final Set<NodeId> nodeIds = Sets.newHashSet();
        if (setsJson != null && setsJson.isArray()) {
            Set<NodeId> localNodeIds = Sets.newHashSet();
            IntStream.range(0, setsJson.size()).forEach(j -> {
                JsonNode nodeIdJson = setsJson.get(j);
                localNodeIds.add(decodeNodeId(nodeIdJson));
            });
            nodeIds.addAll(localNodeIds);
        }
        masters.add(nodeIds);
    });
    RegionId regionId = RegionId.regionId(extractMember(REGION_ID, json));
    String name = extractMember(NAME, json);
    Region.Type type = REGION_TYPE_MAP.get(extractMember(TYPE, json));
    Annotations annots = extractAnnotations(json, context);
    return new DefaultRegion(regionId, name, type, annots, masters);
}
Also used : Set(java.util.Set) 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) JsonNode(com.fasterxml.jackson.databind.JsonNode) RegionId(org.onosproject.net.region.RegionId)

Example 19 with RegionId

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

the class RegionAddCommand method doExecute.

@Override
protected void doExecute() {
    RegionAdminService service = get(RegionAdminService.class);
    RegionId regionId = RegionId.regionId(id);
    NetworkConfigService cfgService = get(NetworkConfigService.class);
    BasicRegionConfig cfg = cfgService.addConfig(regionId, BasicRegionConfig.class);
    setConfigurationData(cfg);
    List<Set<NodeId>> masters = parseMasterArgs();
    service.createRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
    print("Region successfully added.");
}
Also used : RegionAdminService(org.onosproject.net.region.RegionAdminService) Set(java.util.Set) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) RegionId(org.onosproject.net.region.RegionId) BasicRegionConfig(org.onosproject.net.config.basics.BasicRegionConfig)

Example 20 with RegionId

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

the class RegionAddDevicesCommand method doExecute.

@Override
protected void doExecute() {
    RegionAdminService service = get(RegionAdminService.class);
    RegionId regionId = RegionId.regionId(id);
    List<DeviceId> dids = devIds.stream().map(s -> DeviceId.deviceId(s)).collect(Collectors.toList());
    service.addDevices(regionId, dids);
}
Also used : RegionAdminService(org.onosproject.net.region.RegionAdminService) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Argument(org.apache.karaf.shell.api.action.Argument) Completion(org.apache.karaf.shell.api.action.Completion) RegionAdminService(org.onosproject.net.region.RegionAdminService) DeviceId(org.onosproject.net.DeviceId) RegionId(org.onosproject.net.region.RegionId) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) DeviceId(org.onosproject.net.DeviceId) RegionId(org.onosproject.net.region.RegionId)

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