Search in sources :

Example 1 with SpeakerRequest

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

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

the class SpeakerWorkerService method handleResponse.

/**
 * Processes received response and forwards it to the hub component.
 * @param key operation's key.
 * @param response response payload.
 */
public void handleResponse(@NonNull String key, @NonNull SpeakerResponse response) throws PipelineException {
    log.debug("Got a response from speaker {}", response);
    SpeakerRequest pendingRequest = keyToRequest.remove(key);
    if (pendingRequest != null) {
        if (pendingRequest.getCommandId().equals(response.getCommandId())) {
            carrier.sendResponse(key, response);
        } else {
            log.warn("Pending request's command id and received response's command id mismatch");
        }
    }
}
Also used : SpeakerRequest(org.openkilda.floodlight.api.request.SpeakerRequest)

Example 3 with SpeakerRequest

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

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

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

the class FlowPathSwapServiceTest method shouldFailSwapOnUnsuccessfulInstallation.

@Test
public void shouldFailSwapOnUnsuccessfulInstallation() {
    // given
    Flow origin = dummyFactory.makeFlowWithProtectedPath(flowSource, flowDestination, singletonList(islSourceDest), singletonList(islSourceDestAlt));
    // when
    FlowPathSwapService service = makeService();
    FlowPathSwapRequest request = new FlowPathSwapRequest(origin.getFlowId(), true);
    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) {
            FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) speakerRequest;
            if (flowSegmentRequest.isInstallRequest() && failCounter > 0) {
                service.handleAsyncResponse(dummyRequestKey, FlowErrorResponse.errorBuilder().messageContext(flowSegmentRequest.getMessageContext()).errorCode(ErrorCode.UNKNOWN).description(injectedErrorMessage).commandId(flowSegmentRequest.getCommandId()).metadata(flowSegmentRequest.getMetadata()).switchId(flowSegmentRequest.getSwitchId()).build());
                failCounter--;
            } else {
                service.handleAsyncResponse(dummyRequestKey, buildSpeakerResponse(flowSegmentRequest));
            }
        } else {
            fail();
        }
    }
    // 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) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Aggregations

SpeakerRequest (org.openkilda.floodlight.api.request.SpeakerRequest)9 Test (org.junit.Test)6 FlowPathSwapRequest (org.openkilda.messaging.command.flow.FlowPathSwapRequest)6 Flow (org.openkilda.model.Flow)6 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)4 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)3 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 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)1 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)1 SpeakerData (org.openkilda.rulemanager.SpeakerData)1