use of org.openkilda.topo.exceptions.TopologyProcessingException 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);
}
use of org.openkilda.topo.exceptions.TopologyProcessingException in project open-kilda by telstra.
the class LinksUtils method dumpLinks.
/**
* Returns links through Topology-Engine-Rest service.
*
* @return The JSON document of all flows
*/
public static List<IslInfoData> dumpLinks() {
System.out.println("\n==> Topology-Engine Dump Links");
long current = System.currentTimeMillis();
Client client = ClientBuilder.newClient(new ClientConfig());
Response response = client.target(topologyEndpoint).path("/api/v1/topology/links").request().header(HttpHeaders.AUTHORIZATION, authHeaderValue).get();
System.out.println(String.format("===> Response = %s", response.toString()));
System.out.println(String.format("===> Topology-Engine Dump Links Time: %,.3f", getTimeDuration(current)));
try {
List<IslInfoData> links = new ObjectMapper().readValue(response.readEntity(String.class), new TypeReference<List<IslInfoData>>() {
});
// LOGGER.debug(String.format("====> Data = %s", links));
return links;
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to parse the links '%s'.", response.toString()), ex);
}
}
use of org.openkilda.topo.exceptions.TopologyProcessingException in project open-kilda by telstra.
the class FlowPathTest method a_multi_path_topology.
@Given("^a multi-path topology$")
public void a_multi_path_topology() {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(fileName).getFile());
String json;
try {
json = new String(Files.readAllBytes(file.toPath()));
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to read the topology file '%s'.", fileName), ex);
}
pre_start = System.currentTimeMillis();
assertTrue(TopologyHelp.CreateMininetTopology(json));
start = System.currentTimeMillis();
}
Aggregations