Search in sources :

Example 6 with SpeakerFlowSegmentResponse

use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.

the class OnReceivedInstallResponseAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
    UUID commandId = response.getCommandId();
    FlowSegmentRequestFactory command = stateMachine.getInstallCommand(commandId);
    if (!stateMachine.getPendingCommands().containsKey(commandId) || command == null) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        stateMachine.saveActionToHistory("Rule was installed", format("The rule was installed: switch %s, cookie %s", response.getSwitchId(), command.getCookie()));
    } else {
        FlowErrorResponse errorResponse = (FlowErrorResponse) response;
        int attempt = stateMachine.doRetryForCommand(commandId);
        if (attempt <= speakerCommandRetriesLimit) {
            stateMachine.saveErrorToHistory(FAILED_TO_INSTALL_RULE_ACTION, format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse, attempt));
            stateMachine.getCarrier().sendSpeakerRequest(command.makeInstallRequest(commandId));
        } else if (stateMachine.isDoNotRevert()) {
            stateMachine.removePendingCommand(commandId);
            stateMachine.saveErrorToHistory(FAILED_TO_INSTALL_RULE_ACTION, format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Skipping installing attempts", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse));
            stateMachine.setNewFlowStatus(FlowStatus.DOWN);
            stateMachine.setErrorReason(FAILED_TO_INSTALL_RULE_ACTION);
        } else {
            stateMachine.removePendingCommand(commandId);
            stateMachine.saveErrorToHistory(FAILED_TO_INSTALL_RULE_ACTION, format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error: %s", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse));
            stateMachine.addFailedCommand(commandId, errorResponse);
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedCommands().isEmpty()) {
            log.debug("Received responses for all pending install commands of the flow {}", stateMachine.getFlowId());
            stateMachine.fire(Event.RULES_INSTALLED);
        } else {
            String errorMessage = format("Received error response(s) for %d install commands", stateMachine.getFailedCommands().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) UUID(java.util.UUID)

Example 7 with SpeakerFlowSegmentResponse

use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.

the class YFlowDeleteService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerResponse speakerResponse) throws UnknownKeyException {
    log.debug("Received flow command response: {}", speakerResponse);
    YFlowDeleteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (speakerResponse instanceof SpeakerFlowSegmentResponse) {
        SpeakerFlowSegmentResponse response = (SpeakerFlowSegmentResponse) speakerResponse;
        String flowId = response.getMetadata().getFlowId();
        if (fsm.getDeletingSubFlows().contains(flowId)) {
            flowDeleteService.handleAsyncResponseByFlowId(flowId, response);
        }
    } else if (speakerResponse instanceof SpeakerCommandResponse) {
        SpeakerCommandResponse response = (SpeakerCommandResponse) speakerResponse;
        YFlowDeleteContext context = YFlowDeleteContext.builder().speakerResponse(response).build();
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    } else {
        log.debug("Received unexpected speaker response: {}", speakerResponse);
    }
    // After handling an event by FlowDelete services, we should propagate execution to the FSM.
    if (!fsm.isTerminated()) {
        fsmExecutor.fire(fsm, Event.NEXT);
    }
    removeIfFinished(fsm, key);
}
Also used : YFlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteFsm) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) YFlowDeleteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteContext) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 8 with SpeakerFlowSegmentResponse

use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.

the class YFlowRerouteService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerResponse speakerResponse) throws UnknownKeyException {
    log.debug("Received flow command response {}", speakerResponse);
    YFlowRerouteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (speakerResponse instanceof SpeakerFlowSegmentResponse) {
        SpeakerFlowSegmentResponse response = (SpeakerFlowSegmentResponse) speakerResponse;
        String flowId = response.getMetadata().getFlowId();
        if (fsm.getReroutingSubFlows().contains(flowId)) {
            flowRerouteService.handleAsyncResponseByFlowId(flowId, response);
        }
    } else if (speakerResponse instanceof SpeakerCommandResponse) {
        SpeakerCommandResponse response = (SpeakerCommandResponse) speakerResponse;
        YFlowRerouteContext context = YFlowRerouteContext.builder().speakerResponse(response).build();
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    } else {
        log.debug("Received unexpected speaker response: {}", speakerResponse);
    }
    // After handling an event by FlowReroute service, we should propagate execution to the FSM.
    if (!fsm.isTerminated()) {
        fsmExecutor.fire(fsm, Event.NEXT);
    }
    removeIfFinished(fsm, key);
}
Also used : YFlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm) YFlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteContext) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 9 with SpeakerFlowSegmentResponse

use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.

the class YFlowUpdateService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerResponse speakerResponse) throws UnknownKeyException {
    log.debug("Received flow command response {}", speakerResponse);
    YFlowUpdateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (speakerResponse instanceof SpeakerFlowSegmentResponse) {
        SpeakerFlowSegmentResponse response = (SpeakerFlowSegmentResponse) speakerResponse;
        String flowId = response.getMetadata().getFlowId();
        if (fsm.getUpdatingSubFlows().contains(flowId)) {
            flowUpdateService.handleAsyncResponseByFlowId(flowId, response);
        }
    } else if (speakerResponse instanceof SpeakerCommandResponse) {
        SpeakerCommandResponse response = (SpeakerCommandResponse) speakerResponse;
        YFlowUpdateContext context = YFlowUpdateContext.builder().speakerResponse(response).build();
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    } else {
        log.debug("Received unexpected speaker response: {}", speakerResponse);
    }
    // After handling an event by FlowUpdate service, we should propagate execution to the FSM.
    if (!fsm.isTerminated()) {
        fsmExecutor.fire(fsm, Event.NEXT);
    }
    removeIfFinished(fsm, key);
}
Also used : YFlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm) YFlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateContext) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 10 with SpeakerFlowSegmentResponse

use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse 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)

Aggregations

SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)27 UUID (java.util.UUID)15 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)15 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)14 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)8 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)7 String.format (java.lang.String.format)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)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 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)1 SpeakerRequest (org.openkilda.floodlight.api.request.SpeakerRequest)1 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)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