Search in sources :

Example 1 with UiRegion

use of org.onosproject.ui.model.topo.UiRegion in project onos by opennetworkinglab.

the class ModelCache method loadRegions.

private void loadRegions() {
    for (Region r : services.region().getRegions()) {
        UiRegion region = addNewRegion(r);
        updateRegion(region);
    }
}
Also used : UiRegion(org.onosproject.ui.model.topo.UiRegion) Region(org.onosproject.net.region.Region) UiRegion(org.onosproject.ui.model.topo.UiRegion)

Example 2 with UiRegion

use of org.onosproject.ui.model.topo.UiRegion in project onos by opennetworkinglab.

the class ModelCache method addOrUpdateRegion.

// invoked from UiSharedTopologyModel region listener
void addOrUpdateRegion(Region region) {
    RegionId id = region.id();
    String memo = MEMO_UPDATED;
    UiRegion uiRegion = uiTopology.findRegion(id);
    if (uiRegion == null) {
        uiRegion = addNewRegion(region);
        memo = MEMO_ADDED;
    }
    updateRegion(uiRegion);
    postEvent(REGION_ADDED_OR_UPDATED, uiRegion, memo);
}
Also used : UiRegion(org.onosproject.ui.model.topo.UiRegion) RegionId(org.onosproject.net.region.RegionId)

Example 3 with UiRegion

use of org.onosproject.ui.model.topo.UiRegion in project onos by opennetworkinglab.

the class ModelCache method refresh.

/**
 * Refreshes the internal state.
 */
public void refresh() {
    // fix up internal linkages to ensure they are correct
    // make sure regions reflect layout containment hierarchy
    fixupContainmentHierarchy(uiTopology.nullRegion());
    uiTopology.allRegions().forEach(this::fixupContainmentHierarchy);
    // make sure devices and hosts are in the correct region
    Set<UiDevice> allDevices = uiTopology.allDevices();
    Set<UiHost> allHosts = uiTopology.allHosts();
    services.region().getRegions().forEach(r -> {
        RegionId rid = r.id();
        UiRegion region = uiTopology.findRegion(rid);
        if (region != null) {
            reconcileDevicesAndHostsWithRegion(allDevices, allHosts, rid, region);
        } else {
            log.warn("No UiRegion in topology for ID {}", rid);
        }
    });
    // what is left over, must belong to the null-region
    Set<DeviceId> leftOver = new HashSet<>(allDevices.size());
    allDevices.forEach(d -> leftOver.add(d.id()));
    uiTopology.nullRegion().reconcileDevices(leftOver);
    Set<HostId> leftOverHosts = new HashSet<>(allHosts.size());
    allHosts.forEach(h -> leftOverHosts.add(h.id()));
    uiTopology.nullRegion().reconcileHosts(leftOverHosts);
    // now that we have correct region hierarchy, and devices are in their
    // respective regions, we can compute synthetic links for each region.
    uiTopology.computeSynthLinks();
}
Also used : DeviceId(org.onosproject.net.DeviceId) UiRegion(org.onosproject.ui.model.topo.UiRegion) 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) HashSet(java.util.HashSet)

Example 4 with UiRegion

use of org.onosproject.ui.model.topo.UiRegion 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 5 with UiRegion

use of org.onosproject.ui.model.topo.UiRegion in project onos by opennetworkinglab.

the class UiTopoSession method event.

@Override
public void event(UiModelEvent event) {
    // they are created
    if (event.type() == UiModelEvent.Type.DEVICE_ADDED_OR_UPDATED && event.memo().equals("added")) {
        UiRegion uiRegion = sharedModel.getRegion(currentLayout.regionId());
        uiRegion.newDeviceAdded(DeviceId.deviceId(event.subject().idAsString()));
    } else if (event.type() == UiModelEvent.Type.DEVICE_REMOVED) {
        UiRegion uiRegion = sharedModel.getRegion(currentLayout.regionId());
        uiRegion.deviceRemoved(DeviceId.deviceId(event.subject().idAsString()));
    }
    webSocket.sendMessage(TOPO2_UI_MODEL_EVENT, t2json.jsonEvent(event));
}
Also used : UiRegion(org.onosproject.ui.model.topo.UiRegion)

Aggregations

UiRegion (org.onosproject.ui.model.topo.UiRegion)9 RegionId (org.onosproject.net.region.RegionId)3 Region (org.onosproject.net.region.Region)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 DeviceId (org.onosproject.net.DeviceId)1 HostId (org.onosproject.net.HostId)1 UiDevice (org.onosproject.ui.model.topo.UiDevice)1 UiHost (org.onosproject.ui.model.topo.UiHost)1 UiSynthLink (org.onosproject.ui.model.topo.UiSynthLink)1