Search in sources :

Example 11 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class FlowDeleteService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerFlowSegmentResponse flowResponse) throws UnknownKeyException {
    log.debug("Received flow command response {}", flowResponse);
    FlowDeleteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    FlowDeleteContext context = FlowDeleteContext.builder().speakerFlowResponse(flowResponse).build();
    if (flowResponse instanceof FlowErrorResponse) {
        fsmExecutor.fire(fsm, Event.ERROR_RECEIVED, context);
    } else {
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    }
    removeIfFinished(fsm, key);
}
Also used : FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) FlowDeleteContext(org.openkilda.wfm.topology.flowhs.fsm.delete.FlowDeleteContext)

Example 12 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class FlowSegmentReport method assembleResponse.

private SpeakerResponse assembleResponse() {
    FlowErrorResponseBuilder errorResponse = makeErrorTemplate();
    try {
        raiseError();
        return makeSuccessReply();
    } catch (SwitchNotFoundException e) {
        errorResponse.errorCode(ErrorCode.SWITCH_UNAVAILABLE);
    } catch (SessionErrorResponseException e) {
        decodeError(errorResponse, e.getErrorResponse());
    } catch (SwitchMissingFlowsException e) {
        errorResponse.errorCode(ErrorCode.MISSING_OF_FLOWS);
        errorResponse.description(e.getMessage());
    } catch (SwitchOperationException e) {
        errorResponse.errorCode(ErrorCode.UNKNOWN);
        errorResponse.description(e.getMessage());
    } catch (Exception e) {
        log.error(String.format("Unhandled exception while processing command %s", command), e);
        errorResponse.errorCode(ErrorCode.UNKNOWN);
    }
    FlowErrorResponse response = errorResponse.build();
    log.error("Command {} have failed - {} {}", command, response.getErrorCode(), response.getDescription());
    return response;
}
Also used : SwitchMissingFlowsException(org.openkilda.floodlight.error.SwitchMissingFlowsException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowErrorResponseBuilder(org.openkilda.floodlight.flow.response.FlowErrorResponse.FlowErrorResponseBuilder) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) SwitchMissingFlowsException(org.openkilda.floodlight.error.SwitchMissingFlowsException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException)

Example 13 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class FlowMirrorPointCreateService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(String key, SpeakerFlowSegmentResponse flowResponse) {
    log.debug("Received flow command response {}", flowResponse);
    FlowMirrorPointCreateFsm fsm = fsmRegister.getFsmByKey(key).orElse(null);
    if (fsm == null) {
        log.warn("Failed to find a FSM: received response with key {} for non pending FSM", key);
        return;
    }
    FlowMirrorPointCreateContext context = FlowMirrorPointCreateContext.builder().speakerFlowResponse(flowResponse).build();
    if (flowResponse instanceof FlowErrorResponse) {
        fsmExecutor.fire(fsm, Event.ERROR_RECEIVED, context);
    } else {
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    }
    removeIfFinished(fsm, key);
}
Also used : FlowMirrorPointCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.mirrorpoint.create.FlowMirrorPointCreateFsm) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) FlowMirrorPointCreateContext(org.openkilda.wfm.topology.flowhs.fsm.mirrorpoint.create.FlowMirrorPointCreateContext)

Example 14 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class SpeakerCommandFsm method processResponse.

protected void processResponse(State from, State to, Event event, SpeakerFlowSegmentResponse response) {
    if (response.isSuccess()) {
        log.debug("Successfully executed the command {}", response);
        fire(Event.NEXT);
    } else {
        FlowErrorResponse errorResponse = (FlowErrorResponse) response;
        final ErrorCode errorCode = errorResponse.getErrorCode();
        String giveUpReason = null;
        if (remainingRetries <= 0) {
            giveUpReason = String.format("all %s retry attempts have been used", allowedRetriesCount);
        } else if (giveUpErrors.contains(errorCode)) {
            giveUpReason = String.format("Error %s is in \"give up\" list, no more retry attempts allowed", errorCode);
        }
        if (giveUpReason == null) {
            remainingRetries--;
            log.debug("About to retry execution of the command {}", response);
            fire(Event.RETRY);
        } else {
            fireError(giveUpReason);
        }
    }
}
Also used : FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) ErrorCode(org.openkilda.floodlight.flow.response.FlowErrorResponse.ErrorCode)

Example 15 with FlowErrorResponse

use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.

the class OnReceivedResponseAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
    SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
    if (!response.isSuccess() || response instanceof FlowErrorResponse) {
        throw new IllegalArgumentException(format("Invoked %s for an error response: %s", this.getClass(), response));
    }
    UUID commandId = response.getCommandId();
    if (!stateMachine.removePendingCommand(commandId)) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    Cookie cookie = response.getCookie();
    stateMachine.saveActionToHistory("Rule was deleted", format("The rule was deleted: switch %s, cookie %s", response.getSwitchId(), cookie));
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedCommands().isEmpty()) {
            log.debug("Received responses for all pending remove commands of the flow {}", stateMachine.getFlowId());
        } else {
            String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
            stateMachine.saveErrorToHistory(errorMessage);
        }
        stateMachine.fire(Event.RULES_REMOVED);
    }
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) UUID(java.util.UUID)

Aggregations

FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)25 UUID (java.util.UUID)16 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)15 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)15 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)3 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)3 String.format (java.lang.String.format)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)2 FlowPathSwapContext (org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapContext)2 FlowPathSwapFsm (org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm)2 Event (org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm.Event)2 State (org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm.State)2 SessionErrorResponseException (org.openkilda.floodlight.error.SessionErrorResponseException)1 SwitchMissingFlowsException (org.openkilda.floodlight.error.SwitchMissingFlowsException)1 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)1 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)1 ErrorCode (org.openkilda.floodlight.flow.response.FlowErrorResponse.ErrorCode)1 FlowErrorResponseBuilder (org.openkilda.floodlight.flow.response.FlowErrorResponse.FlowErrorResponseBuilder)1