Search in sources :

Example 6 with TopologyProcessingException

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);
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) Topology(org.openkilda.topo.Topology) Switch(org.openkilda.topo.Switch) TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) LinkEndpoint(org.openkilda.topo.LinkEndpoint) NodeDto(org.openkilda.topo.builders.TeTopologyParser.TopologyDto.NodeDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Link(org.openkilda.topo.Link)

Example 7 with TopologyProcessingException

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) List(java.util.List) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with TopologyProcessingException

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();
}
Also used : TopologyProcessingException(org.openkilda.topo.exceptions.TopologyProcessingException) IOException(java.io.IOException) File(java.io.File) Given(cucumber.api.java.en.Given)

Aggregations

IOException (java.io.IOException)8 TopologyProcessingException (org.openkilda.topo.exceptions.TopologyProcessingException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Client (javax.ws.rs.client.Client)4 Response (javax.ws.rs.core.Response)4 List (java.util.List)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ClientConfig (org.glassfish.jersey.client.ClientConfig)2 Link (org.openkilda.topo.Link)2 LinkEndpoint (org.openkilda.topo.LinkEndpoint)2 Switch (org.openkilda.topo.Switch)2 Topology (org.openkilda.topo.Topology)2 Given (cucumber.api.java.en.Given)1 File (java.io.File)1 Map (java.util.Map)1 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)1 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)1 Flow (org.openkilda.messaging.model.Flow)1 NodeDto (org.openkilda.topo.builders.TeTopologyParser.TopologyDto.NodeDto)1