Search in sources :

Example 31 with SpeakerResponse

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

the class HandleNotCompletedCommandsAction method perform.

@Override
public void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    FlowSegmentRequestFactory requestFactory;
    for (UUID commandId : stateMachine.getPendingCommands().keySet()) {
        requestFactory = stateMachine.getRemoveCommands().get(commandId);
        if (requestFactory != null) {
            stateMachine.saveErrorToHistory("Command is not finished yet", format("Completing the reroute operation although the remove command may not be " + "finished yet: commandId %s, switch %s, cookie %s", commandId, requestFactory.getSwitchId(), requestFactory.getCookie()));
        } else {
            requestFactory = stateMachine.getIngressCommands().get(commandId);
            stateMachine.saveErrorToHistory("Command is not finished yet", format("Completing the reroute operation although the install command may not be " + "finished yet: commandId %s, switch %s, cookie %s", commandId, requestFactory.getSwitchId(), requestFactory.getCookie()));
        }
    }
    for (SpeakerResponse errorResponse : stateMachine.getFailedCommands().values()) {
        log.warn("Receive error response from {} for command {}: {}", errorResponse.getSwitchId(), errorResponse.getCommandId(), errorResponse);
    }
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingCommands();
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) UUID(java.util.UUID)

Example 32 with SpeakerResponse

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

the class OnReceivedInstallResponseAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
    SpeakerResponse response = context.getSpeakerResponse();
    UUID commandId = response.getCommandId();
    if (!stateMachine.hasPendingCommand(commandId)) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    boolean isInstallCommand = stateMachine.getInstallCommand(commandId) != null || stateMachine.getInstallSpeakerCommand(commandId).isPresent();
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        String commandName = isInstallCommand ? "installed" : "deleted";
        if (response instanceof SpeakerFlowSegmentResponse) {
            stateMachine.saveActionToHistory("Rule was " + commandName, format("The rule was %s: switch %s, cookie %s", commandName, response.getSwitchId(), ((SpeakerFlowSegmentResponse) response).getCookie()));
        } else {
            stateMachine.saveActionToHistory("Rule was " + commandName, format("The rule was %s: switch %s", commandName, response.getSwitchId()));
        }
    } else {
        int attempt = stateMachine.doRetryForCommand(commandId);
        if (attempt <= speakerCommandRetriesLimit) {
            FlowSegmentRequestFactory flowSegmentRequest = stateMachine.getInstallCommand(commandId);
            if (flowSegmentRequest != null && response instanceof FlowErrorResponse) {
                FlowErrorResponse errorResponse = (FlowErrorResponse) response;
                stateMachine.saveErrorToHistory("Failed to install rule", format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), flowSegmentRequest.getCookie(), errorResponse, attempt));
                stateMachine.getCarrier().sendSpeakerRequest(flowSegmentRequest.makeInstallRequest(commandId));
            } else if (response instanceof SpeakerCommandResponse) {
                String commandName = isInstallCommand ? "install" : "delete";
                SpeakerCommandResponse speakerCommandResponse = (SpeakerCommandResponse) response;
                speakerCommandResponse.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory("Failed to " + commandName + " rule", format("Failed to %s the rule: commandId %s, ruleId %s, switch %s. " + "Error %s. Retrying (attempt %d)", commandName, commandId, uuid, response.getSwitchId(), message, attempt)));
                Set<UUID> failedUuids = speakerCommandResponse.getFailedCommandIds().keySet();
                stateMachine.getInstallSpeakerCommand(commandId).ifPresent(command -> stateMachine.getCarrier().sendSpeakerRequest(command.toBuilder().commands(filterOfCommands(command.getCommands(), failedUuids)).build()));
                stateMachine.getDeleteSpeakerCommand(commandId).ifPresent(command -> stateMachine.getCarrier().sendSpeakerRequest(command.toBuilder().commands(filterOfCommands(command.getCommands(), failedUuids)).build()));
            } else {
                log.warn("Received a unknown response: {}", response);
                return;
            }
        } else {
            stateMachine.addFailedCommand(commandId, response);
            stateMachine.removePendingCommand(commandId);
            String commandName = isInstallCommand ? "install" : "delete";
            if (response instanceof FlowErrorResponse) {
                stateMachine.saveErrorToHistory("Failed to " + commandName + " rule", format("Failed to %s the rule: commandId %s, switch %s, cookie %s. Error %s.", commandName, commandId, response.getSwitchId(), ((FlowErrorResponse) response).getCookie(), response));
            } else if (response instanceof SpeakerCommandResponse) {
                ((SpeakerCommandResponse) response).getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory("Failed to " + commandName + " rule", format("Failed to %s the rule: commandId %s, ruleId %s, switch %s. Error %s.", commandName, commandId, uuid, response.getSwitchId(), message)));
            } else {
                log.warn("Received a unknown response: {}", response);
                return;
            }
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedCommands().isEmpty()) {
            log.debug("Received responses for all pending install / delete commands of the flow {}", stateMachine.getFlowId());
            stateMachine.fire(Event.RULES_INSTALLED);
        } else {
            String errorMessage = format("Received error response(s) for %d install / delete commands", stateMachine.getFailedCommands().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : FlowPathSwapFsm(org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) State(org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm.State) Set(java.util.Set) Event(org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapFsm.Event) UUID(java.util.UUID) String.format(java.lang.String.format) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) Slf4j(lombok.extern.slf4j.Slf4j) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowPathSwapContext(org.openkilda.wfm.topology.flowhs.fsm.pathswap.FlowPathSwapContext) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) Set(java.util.Set) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) UUID(java.util.UUID)

Example 33 with SpeakerResponse

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

the class SetInstallRuleErrorAction method execute.

@Override
public void execute(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    Set<SwitchId> switches = Stream.concat(stateMachine.getPendingCommands().values().stream(), stateMachine.getFailedCommands().values().stream().map(SpeakerResponse::getSwitchId)).collect(Collectors.toSet());
    stateMachine.setRerouteError(new SpeakerRequestError("Failed to install rules", switches));
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingCommands();
}
Also used : SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) SwitchId(org.openkilda.model.SwitchId) SpeakerRequestError(org.openkilda.messaging.info.reroute.error.SpeakerRequestError)

Aggregations

SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)33 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)21 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)21 CommandContext (org.openkilda.wfm.CommandContext)9 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)6 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)6 UUID (java.util.UUID)4 FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)4 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)3 String.format (java.lang.String.format)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)2 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)2 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)2 SpeakerRequestError (org.openkilda.messaging.info.reroute.error.SpeakerRequestError)2 SwitchId (org.openkilda.model.SwitchId)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