Search in sources :

Example 1 with FlowPathPayload

use of org.openkilda.messaging.payload.flow.FlowPathPayload in project open-kilda by telstra.

the class FlowUtils method getFlowPath.

/**
 * Gets flow path through Northbound service.
 *
 * @param flowId flow id
 * @return The JSON document of the specified flow path
 */
public static FlowPathPayload getFlowPath(final String flowId) {
    System.out.println("\n==> Northbound Get Flow Path");
    long current = System.currentTimeMillis();
    Client client = clientFactory();
    Response response = client.target(northboundEndpoint).path("/api/v1/flows/path").path("{flowid}").resolveTemplate("flowid", flowId).request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, authHeaderValue).header(Utils.CORRELATION_ID, String.valueOf(System.currentTimeMillis())).get();
    System.out.println(format("===> Response = %s", response.toString()));
    System.out.println(format("===> Northbound Get Flow Path Time: %,.3f", getTimeDuration(current)));
    int responseCode = response.getStatus();
    if (responseCode == 200) {
        FlowPathPayload flowPath = response.readEntity(FlowPathPayload.class);
        System.out.println(format("====> Northbound Get Flow Path = %s", flowPath));
        return flowPath;
    } else {
        System.out.println(format("====> Error: Northbound Get Flow Path = %s", response.readEntity(MessageError.class)));
        return null;
    }
}
Also used : Response(javax.ws.rs.core.Response) FlowPathPayload(org.openkilda.messaging.payload.flow.FlowPathPayload) Client(javax.ws.rs.client.Client) DefaultParameters.topologyEndpoint(org.openkilda.DefaultParameters.topologyEndpoint) DefaultParameters.northboundEndpoint(org.openkilda.DefaultParameters.northboundEndpoint)

Example 2 with FlowPathPayload

use of org.openkilda.messaging.payload.flow.FlowPathPayload in project open-kilda by telstra.

the class FlowServiceImpl method pathFlow.

/**
 * {@inheritDoc}
 */
@Override
public InfoMessage pathFlow(final FlowIdStatusPayload payload, final String correlationId) {
    Set<Flow> flows = flowRepository.findByFlowId(payload.getId());
    FlowPathPayload flowPathPayload = null;
    for (Flow flow : flows) {
        if ((flow.getCookie() & DIRECT_FLOW_COOKIE) == DIRECT_FLOW_COOKIE) {
            flowPathPayload = new FlowPathPayload(flow.getFlowId(), flow.getFlowPath());
        }
    }
    logger.debug("Flow with id={} path: {}", payload.getId(), flowPathPayload);
    return new InfoMessage(new FlowPathResponse(flowPathPayload), System.currentTimeMillis(), correlationId, Destination.WFM);
}
Also used : FlowPathResponse(org.openkilda.messaging.info.flow.FlowPathResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowPathPayload(org.openkilda.messaging.payload.flow.FlowPathPayload) Flow(org.openkilda.topology.domain.Flow)

Example 3 with FlowPathPayload

use of org.openkilda.messaging.payload.flow.FlowPathPayload in project open-kilda by telstra.

the class FlowFFRTest method getFlowPath.

private FlowPathPayload getFlowPath(String flowName, PathInfoData expectedPath) throws Exception {
    FlowPathPayload payload = FlowUtils.getFlowPath(flowName);
    for (int i = 0; i < 10; i++) {
        payload = FlowUtils.getFlowPath(flowName);
        if (payload != null && expectedPath.equals(payload.getPath())) {
            break;
        }
        TimeUnit.SECONDS.sleep(2);
    }
    return payload;
}
Also used : FlowPathPayload(org.openkilda.messaging.payload.flow.FlowPathPayload) DefaultParameters.trafficEndpoint(org.openkilda.DefaultParameters.trafficEndpoint)

Example 4 with FlowPathPayload

use of org.openkilda.messaging.payload.flow.FlowPathPayload in project open-kilda by telstra.

the class FlowFFRTest method flowPathIsAlternate.

@When("^flow (.+) path is alternate$")
public void flowPathIsAlternate(String flowId) throws Throwable {
    String flowName = FlowUtils.getFlowName(flowId);
    FlowPathPayload payload = getFlowPath(flowName, FlowPathTest.expectedAlternatePath.getLeft());
    assertNotNull(payload);
    assertEquals(flowName, payload.getId());
    assertEquals(FlowPathTest.expectedAlternatePath.getLeft(), payload.getPath());
}
Also used : FlowPathPayload(org.openkilda.messaging.payload.flow.FlowPathPayload) When(cucumber.api.java.en.When)

Example 5 with FlowPathPayload

use of org.openkilda.messaging.payload.flow.FlowPathPayload in project open-kilda by telstra.

the class FlowReinstallTest method flowPathContainsSwitch.

@Then("^flow (.*) is(.*) built through (.*) switch")
public void flowPathContainsSwitch(final String flow, final String shouldNotContain, final String switchId) throws InterruptedException {
    await().atMost(20, TimeUnit.SECONDS).pollInterval(Duration.ONE_SECOND).until(() -> {
        FlowPathPayload payload = FlowUtils.getFlowPath(FlowUtils.getFlowName(flow));
        assertTrue("Flow path should exist", payload != null && payload.getPath() != null);
        List<PathNode> path = payload.getPath().getPath();
        boolean contains = path.stream().anyMatch(node -> switchId.equalsIgnoreCase(node.getSwitchId()));
        if (StringUtils.isBlank(shouldNotContain)) {
            return contains;
        } else {
            return !contains;
        }
    });
}
Also used : FlowPathPayload(org.openkilda.messaging.payload.flow.FlowPathPayload) PathNode(org.openkilda.messaging.info.event.PathNode) Then(cucumber.api.java.en.Then)

Aggregations

FlowPathPayload (org.openkilda.messaging.payload.flow.FlowPathPayload)13 Then (cucumber.api.java.en.Then)2 When (cucumber.api.java.en.When)2 String.format (java.lang.String.format)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 Destination (org.openkilda.messaging.Destination)2 FLOW_ID (org.openkilda.messaging.Utils.FLOW_ID)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 CreateFlowLoopRequest (org.openkilda.messaging.command.flow.CreateFlowLoopRequest)2 DeleteFlowLoopRequest (org.openkilda.messaging.command.flow.DeleteFlowLoopRequest)2 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)2