16 package org.openkilda.topo.builders;
18 import static java.lang.String.format;
20 import com.fasterxml.jackson.annotation.JsonIdentityInfo;
21 import com.fasterxml.jackson.annotation.JsonProperty;
22 import com.fasterxml.jackson.annotation.ObjectIdGenerators;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.google.common.base.Strings;
33 import java.io.IOException;
34 import java.util.HashMap;
35 import java.util.List;
45 TopologyDto topologyDto;
47 ObjectMapper mapper =
new ObjectMapper();
49 topologyDto = mapper.readValue(json, TopologyDto.class);
50 }
catch (IOException ex) {
54 Map<String, Switch> switches =
new HashMap<>();
56 topologyDto.getNodes().forEach(
node -> {
58 if (Strings.isNullOrEmpty(
name)) {
62 String switchId =
name.toUpperCase();
63 switches.put(switchId,
new Switch(switchId));
66 Map<String, Link> links =
new HashMap<>();
68 topologyDto.getNodes().forEach(
node -> {
69 String srcId =
node.getName().toUpperCase();
71 List<NodeDto> relations =
node.getOutgoingRelationships();
72 if (relations != null) {
73 relations.forEach(relation -> {
74 String dstId = relation.getName().toUpperCase();
87 return new Topology(switches, links);
91 static class TopologyDto {
96 @JsonIdentityInfo(property =
"name",
generator = ObjectIdGenerators.PropertyGenerator.class)
97 static class NodeDto {
101 @JsonProperty(
"outgoing_relationships")
102 List<NodeDto> outgoingRelationships;
static Topology parseTopologyEngineJson(String json)