Search in sources :

Example 1 with BaseSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest in project open-kilda by telstra.

the class SpeakerWorkerService method handleTimeout.

/**
 * Handles operation timeout.
 * @param key operation identifier.
 */
public void handleTimeout(@NonNull String key) throws PipelineException {
    SpeakerRequest failedRequest = keyToRequest.remove(key);
    if (failedRequest instanceof FlowSegmentRequest) {
        FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) failedRequest;
        SpeakerFlowSegmentResponse response = FlowErrorResponse.errorBuilder().commandId(flowSegmentRequest.getCommandId()).switchId(flowSegmentRequest.getSwitchId()).metadata(flowSegmentRequest.getMetadata()).errorCode(ErrorCode.OPERATION_TIMED_OUT).messageContext(flowSegmentRequest.getMessageContext()).build();
        carrier.sendResponse(key, response);
    } else if (failedRequest instanceof BaseSpeakerCommandsRequest) {
        BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) failedRequest;
        SpeakerCommandResponse response = SpeakerCommandResponse.builder().commandId(speakerCommandsRequest.getCommandId()).switchId(speakerCommandsRequest.getSwitchId()).messageContext(speakerCommandsRequest.getMessageContext()).success(false).failedCommandIds(speakerCommandsRequest.getCommands().stream().map(command -> {
            if (command instanceof FlowCommand) {
                return ((FlowCommand) command).getData();
            }
            if (command instanceof MeterCommand) {
                return ((MeterCommand) command).getData();
            }
            return ((GroupCommand) command).getData();
        }).collect(Collectors.toMap(SpeakerData::getUuid, error -> "Operation is timed out"))).build();
        carrier.sendResponse(key, response);
    }
}
Also used : GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) SpeakerRequest(org.openkilda.floodlight.api.request.SpeakerRequest) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) SpeakerData(org.openkilda.rulemanager.SpeakerData)

Example 2 with BaseSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest in project open-kilda by telstra.

the class FlowPathSwapServiceTest method produceAsyncResponse.

private void produceAsyncResponse(FlowPathSwapService service, String fsmKey, SpeakerRequest speakerRequest) {
    SpeakerResponse commandResponse;
    if (speakerRequest instanceof FlowSegmentRequest) {
        commandResponse = buildSpeakerResponse((FlowSegmentRequest) speakerRequest);
    } else {
        BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
        commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
    }
    service.handleAsyncResponse(fsmKey, commandResponse);
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)

Example 3 with BaseSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest 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 4 with BaseSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest 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)

Example 5 with BaseSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest in project open-kilda by telstra.

the class YFlowDeleteServiceTest method handleSpeakerCommandsAndTimeoutRemove.

private void handleSpeakerCommandsAndTimeoutRemove(YFlowDeleteService yFlowDeleteService, String yFlowFsmKey) {
    handleSpeakerRequests(request -> {
        SpeakerResponse commandResponse;
        if (request instanceof FlowSegmentRequest) {
            FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) request;
            commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
            handleAsyncResponse(yFlowDeleteService, yFlowFsmKey, commandResponse);
        } else {
            BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) request;
            if (speakerCommandsRequest instanceof DeleteSpeakerCommandsRequest) {
                try {
                    yFlowDeleteService.handleTimeout(yFlowFsmKey);
                } catch (UnknownKeyException ex) {
                // skip
                }
            } else {
                commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
                handleAsyncResponse(yFlowDeleteService, yFlowFsmKey, commandResponse);
            }
        }
    });
}
Also used : FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Aggregations

BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)24 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)23 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)21 CommandContext (org.openkilda.wfm.CommandContext)9 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)6 SpeakerRequest (org.openkilda.floodlight.api.request.SpeakerRequest)3 Test (org.junit.Test)2 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)2 FlowPathSwapRequest (org.openkilda.messaging.command.flow.FlowPathSwapRequest)2 Flow (org.openkilda.model.Flow)2 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)2 FlowRerouteService (org.openkilda.wfm.topology.flowhs.service.FlowRerouteService)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 FlowCommand (org.openkilda.floodlight.api.request.rulemanager.FlowCommand)1 GroupCommand (org.openkilda.floodlight.api.request.rulemanager.GroupCommand)1 MeterCommand (org.openkilda.floodlight.api.request.rulemanager.MeterCommand)1 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)1 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)1 YFlowDeleteRequest (org.openkilda.messaging.command.yflow.YFlowDeleteRequest)1