Search in sources :

Example 1 with FlowPathSwapRequest

use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.

the class FlowServiceImpl method swapFlowPaths.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<FlowResponsePayload> swapFlowPaths(String flowId) {
    final String correlationId = RequestCorrelationId.getId();
    logger.info("Swapping paths for flow : {}", flowId);
    FlowPathSwapRequest payload = new FlowPathSwapRequest(flowId, true);
    CommandMessage request = new CommandMessage(payload, System.currentTimeMillis(), correlationId, Destination.WFM);
    return messagingChannel.sendAndGet(flowHsTopic, request).thenApply(FlowResponse.class::cast).thenApply(FlowResponse::getPayload).thenApply(flowMapper::toFlowResponseOutput);
}
Also used : FlowPathSwapRequest(org.openkilda.messaging.command.flow.FlowPathSwapRequest) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with FlowPathSwapRequest

use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.

the class OperationQueueBolt method handleInput.

@Override
protected void handleInput(Tuple tuple) throws PipelineException {
    CommandContext context = pullContext(tuple);
    MessageData data = pullValue(tuple, FIELD_ID_PAYLOAD, MessageData.class);
    if (data instanceof FlowPathSwapRequest) {
        FlowPathSwapRequest flowPathSwapRequest = (FlowPathSwapRequest) data;
        service.addFirst(flowPathSwapRequest.getFlowId(), context.getCorrelationId(), flowPathSwapRequest);
    } else if (data instanceof FlowRerouteRequest) {
        FlowRerouteRequest flowRerouteRequest = (FlowRerouteRequest) data;
        service.addLast(flowRerouteRequest.getFlowId(), context.getCorrelationId(), flowRerouteRequest);
    } else if (data instanceof YFlowRerouteRequest) {
        YFlowRerouteRequest yFlowRerouteRequest = (YFlowRerouteRequest) data;
        service.addLast(yFlowRerouteRequest.getYFlowId(), context.getCorrelationId(), yFlowRerouteRequest);
    } else if (data instanceof RerouteResultInfoData) {
        RerouteResultInfoData rerouteResultInfoData = (RerouteResultInfoData) data;
        service.operationCompleted(rerouteResultInfoData.getFlowId(), rerouteResultInfoData);
        emitRerouteResponse(rerouteResultInfoData);
    } else if (data instanceof PathSwapResult) {
        PathSwapResult pathSwapResult = (PathSwapResult) data;
        service.operationCompleted(pathSwapResult.getFlowId(), pathSwapResult);
    } else {
        unhandledInput(tuple);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) MessageData(org.openkilda.messaging.MessageData) FlowPathSwapRequest(org.openkilda.messaging.command.flow.FlowPathSwapRequest) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) RerouteResultInfoData(org.openkilda.messaging.info.reroute.RerouteResultInfoData) PathSwapResult(org.openkilda.messaging.info.reroute.PathSwapResult)

Example 3 with FlowPathSwapRequest

use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.

the class RerouteBolt method emitPathSwapCommand.

/**
 * Emit swap command for consumer.
 *
 * @param correlationId correlation id to pass through
 * @param flowId flow
 * @param reason initial reason of path swap
 */
@Override
public void emitPathSwapCommand(String correlationId, String flowId, String reason) {
    CommandContext context = new CommandContext(correlationId).fork(UUID.randomUUID().toString());
    emit(STREAM_OPERATION_QUEUE_ID, getCurrentTuple(), new Values(flowId, new FlowPathSwapRequest(flowId, false), context));
    log.warn("Flow {} swap path command message sent with correlationId {}, reason \"{}\"", flowId, context.getCorrelationId(), reason);
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowPathSwapRequest(org.openkilda.messaging.command.flow.FlowPathSwapRequest) Values(org.apache.storm.tuple.Values)

Example 4 with FlowPathSwapRequest

use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.

the class FlowPathSwapServiceTest method shouldFailSwapOnUnsuccessfulYFlowRulesInstallation.

@Test
public void shouldFailSwapOnUnsuccessfulYFlowRulesInstallation() {
    // given
    Flow origin = dummyFactory.makeFlowWithProtectedPath(flowSource, flowDestination, singletonList(islSourceDest), singletonList(islSourceDestAlt));
    createTestYFlowForSubFlow(origin);
    // when
    FlowPathSwapService service = makeService();
    FlowPathSwapRequest request = new FlowPathSwapRequest(origin.getFlowId(), false);
    service.handleRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    int failCounter = 1;
    SpeakerRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        SpeakerResponse commandResponse;
        if (speakerRequest instanceof FlowSegmentRequest) {
            commandResponse = buildSpeakerResponse((FlowSegmentRequest) speakerRequest);
        } else {
            BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
            if (failCounter > 0) {
                commandResponse = buildErrorYFlowSpeakerResponse(speakerCommandsRequest);
                failCounter--;
            } else {
                commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
            }
        }
        service.handleAsyncResponse(dummyRequestKey, commandResponse);
    }
    // then
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyPathNotSwapped(origin, result);
    verifyNorthboundSuccessResponse(carrier);
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowPathSwapRequest(org.openkilda.messaging.command.flow.FlowPathSwapRequest) SpeakerRequest(org.openkilda.floodlight.api.request.SpeakerRequest) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 5 with FlowPathSwapRequest

use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.

the class FlowPathSwapServiceTest method shouldFailSwapOnTimeoutDuringYFlowRulesInstallation.

@Test
public void shouldFailSwapOnTimeoutDuringYFlowRulesInstallation() {
    // given
    Flow origin = dummyFactory.makeFlowWithProtectedPath(flowSource, flowDestination, singletonList(islSourceDest), singletonList(islSourceDestAlt));
    createTestYFlowForSubFlow(origin);
    // when
    FlowPathSwapService service = makeService();
    FlowPathSwapRequest request = new FlowPathSwapRequest(origin.getFlowId(), false);
    service.handleRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    int failCounter = 1;
    SpeakerRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (speakerRequest instanceof FlowSegmentRequest) {
            service.handleAsyncResponse(dummyRequestKey, buildSpeakerResponse((FlowSegmentRequest) speakerRequest));
        } else {
            if (failCounter > 0) {
                service.handleTimeout(dummyRequestKey);
                failCounter--;
            } else {
                BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
                service.handleAsyncResponse(dummyRequestKey, buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest));
            }
        }
    }
    // then
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    verifyPathNotSwapped(origin, result);
    verifyNorthboundSuccessResponse(carrier);
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowPathSwapRequest(org.openkilda.messaging.command.flow.FlowPathSwapRequest) SpeakerRequest(org.openkilda.floodlight.api.request.SpeakerRequest) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Aggregations

FlowPathSwapRequest (org.openkilda.messaging.command.flow.FlowPathSwapRequest)12 Test (org.junit.Test)7 SpeakerRequest (org.openkilda.floodlight.api.request.SpeakerRequest)6 Flow (org.openkilda.model.Flow)6 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)3 Values (org.apache.storm.tuple.Values)2 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)2 MessageData (org.openkilda.messaging.MessageData)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)2 CommandContext (org.openkilda.wfm.CommandContext)2 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)1 CreateFlowLoopRequest (org.openkilda.messaging.command.flow.CreateFlowLoopRequest)1 DeleteFlowLoopRequest (org.openkilda.messaging.command.flow.DeleteFlowLoopRequest)1 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)1 FlowMirrorPointCreateRequest (org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest)1 FlowMirrorPointDeleteRequest (org.openkilda.messaging.command.flow.FlowMirrorPointDeleteRequest)1 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)1 FlowValidationRequest (org.openkilda.messaging.command.flow.FlowValidationRequest)1