use of org.openkilda.topo.builders.TeTopologyParser.TopologyDto.NodeDto in project open-kilda by telstra.
the class TeTopologyParser method parseTopologyEngineJson.
public static Topology parseTopologyEngineJson(String json) {
TopologyDto topologyDto;
ObjectMapper mapper = new ObjectMapper();
try {
topologyDto = mapper.readValue(json, TopologyDto.class);
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to parse the topology '%s'.", json), ex);
}
Map<String, Switch> switches = new HashMap<>();
// Assemble the switches from the provided nodes.
topologyDto.getNodes().forEach(node -> {
String name = node.getName();
if (Strings.isNullOrEmpty(name)) {
throw new TopologyProcessingException("The node must have a name.");
}
Objects.requireNonNull(name, "The name must be provided");
String switchId = name.toUpperCase();
switches.put(switchId, new Switch(switchId));
});
Map<String, Link> links = new HashMap<>();
// Assemble the links from the provided outgoing_relationships.
topologyDto.getNodes().forEach(node -> {
String srcId = node.getName().toUpperCase();
List<NodeDto> relations = node.getOutgoingRelationships();
if (relations != null) {
relations.forEach(relation -> {
String dstId = relation.getName().toUpperCase();
Link link = new Link(// TODO: probably reuse the same endpoint. Why not?
new LinkEndpoint(switches.get(srcId), null, null), new LinkEndpoint(switches.get(dstId), null, null));
links.put(link.getShortSlug(), link);
});
}
});
return new Topology(switches, links);
}
Aggregations