use of org.onosproject.ui.model.topo.UiNode in project onos by opennetworkinglab.
the class Topo2Jsonifier method splitByLayer.
// package-private for unit testing
List<Set<UiNode>> splitByLayer(List<String> layerTags, Set<? extends UiNode> nodes) {
final int nLayers = layerTags.size();
if (!layerTags.get(nLayers - 1).equals(LAYER_DEFAULT)) {
throw new IllegalArgumentException(E_DEF_NOT_LAST);
}
List<Set<UiNode>> splitList = new ArrayList<>(layerTags.size());
Map<String, Set<UiNode>> byLayer = new HashMap<>(layerTags.size());
for (String tag : layerTags) {
Set<UiNode> set = new HashSet<>();
byLayer.put(tag, set);
splitList.add(set);
}
for (UiNode n : nodes) {
String which = n.layer();
if (!layerTags.contains(which)) {
which = LAYER_DEFAULT;
}
byLayer.get(which).add(n);
}
return splitList;
}
use of org.onosproject.ui.model.topo.UiNode in project onos by opennetworkinglab.
the class Topo2ViewMessageHandler method mkPeersMessage.
private ObjectNode mkPeersMessage(UiTopoLayout currentLayout) {
Set<UiNode> peers = topoSession.getPeerNodes(currentLayout);
ObjectNode peersPayload = objectNode();
String rid = currentLayout.regionId().toString();
peersPayload.set("peers", t2json.closedNodes(rid, peers));
return peersPayload;
}
use of org.onosproject.ui.model.topo.UiNode in project onos by opennetworkinglab.
the class UiTopoSession method getPeerNodes.
/**
* Returns the regions/devices that are "peers" to this region. That is,
* based on the layout the user is viewing, all the regions/devices that
* are associated with layouts that share the same parent layout as this
* layout, AND that are linked to an element within this region.
*
* @param layout the layout being viewed
* @return all regions/devices that are "siblings" to this layout's region
*/
public Set<UiNode> getPeerNodes(UiTopoLayout layout) {
Set<UiNode> peers = new HashSet<>();
// first, get the peer regions
Set<UiTopoLayout> peerLayouts = layoutService.getPeerLayouts(layout.id());
peerLayouts.forEach(l -> {
RegionId peerRegion = l.regionId();
peers.add(sharedModel.getRegion(peerRegion));
});
// now add the devices that reside in the parent region
if (!layout.isRoot()) {
UiTopoLayout parentLayout = layoutService.getLayout(layout.parent());
peers.addAll(getRegion(parentLayout).devices());
}
// directly to this region by an implicit link
return peers;
}
Aggregations