use of org.onosproject.ui.model.topo.UiDevice in project onos by opennetworkinglab.
the class Topo2Jsonifier method json.
private ObjectNode json(String ridStr, UiDevice device) {
ObjectNode node = objectNode().put("id", device.idAsString()).put("nodeType", DEVICE).put("type", device.type()).put("online", deviceService.isAvailable(device.id())).put("master", master(device.id())).put("layer", device.layer());
Device d = device.backingDevice();
if (d != null) {
addProps(node, d);
addGeoGridLocation(node, d);
}
addMetaUi(node, ridStr, device.idAsString());
return node;
}
use of org.onosproject.ui.model.topo.UiDevice in project onos by opennetworkinglab.
the class ModelCache method addNewDevice.
// === DEVICES
private UiDevice addNewDevice(Device d) {
UiDevice device = new UiDevice(uiTopology, d);
updateDevice(device);
uiTopology.add(device);
log.debug("Device {} added to topology", device);
return device;
}
use of org.onosproject.ui.model.topo.UiDevice in project onos by opennetworkinglab.
the class ModelCache method removeDevice.
// invoked from UiSharedTopologyModel device listener
void removeDevice(Device device) {
DeviceId id = device.id();
UiDevice uiDevice = uiTopology.findDevice(id);
if (uiDevice != null) {
uiTopology.remove(uiDevice);
postEvent(DEVICE_REMOVED, uiDevice, MEMO_REMOVED);
} else {
log.warn(E_NO_ELEMENT, "device", id);
}
}
use of org.onosproject.ui.model.topo.UiDevice 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();
}
use of org.onosproject.ui.model.topo.UiDevice in project onos by opennetworkinglab.
the class ModelCache method reconcileDevicesAndHostsWithRegion.
private void reconcileDevicesAndHostsWithRegion(Set<UiDevice> allDevices, Set<UiHost> allHosts, RegionId rid, UiRegion region) {
Set<DeviceId> deviceIds = services.region().getRegionDevices(rid);
Set<HostId> hostIds = new HashSet<>();
region.reconcileDevices(deviceIds);
deviceIds.forEach(devId -> {
UiDevice dev = uiTopology.findDevice(devId);
if (dev != null) {
dev.setRegionId(rid);
allDevices.remove(dev);
} else {
log.warn("Region device ID {} but no UiDevice in topology", devId);
}
Set<Host> hosts = services.host().getConnectedHosts(devId);
for (Host h : hosts) {
HostId hid = h.id();
hostIds.add(hid);
UiHost host = uiTopology.findHost(hid);
if (host != null) {
host.setRegionId(rid);
allHosts.remove(host);
} else {
log.warn("Region host ID {} but no UiHost in topology", hid);
}
}
});
region.reconcileHosts(hostIds);
}
Aggregations