Search in sources :

Example 21 with SpeakerFlowSegmentResponse

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

the class FlowCreateHubBolt method onWorkerResponse.

@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
    String operationKey = pullKey(input);
    currentKey = KeyProvider.getParentKey(operationKey);
    SpeakerFlowSegmentResponse flowResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerFlowSegmentResponse.class);
    try {
        service.handleAsyncResponse(currentKey, flowResponse);
    } catch (UnknownKeyException e) {
        log.warn("Received a response with unknown key {}.", currentKey);
    }
}
Also used : SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 22 with SpeakerFlowSegmentResponse

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

the class FlowMirrorPointCreateHubBolt method onWorkerResponse.

@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
    String operationKey = pullKey(input);
    currentKey = KeyProvider.getParentKey(operationKey);
    SpeakerFlowSegmentResponse flowResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerFlowSegmentResponse.class);
    service.handleAsyncResponse(currentKey, flowResponse);
}
Also used : SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)

Example 23 with SpeakerFlowSegmentResponse

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

the class OnReceivedRemoveOrRevertResponseAction 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 ? "re-installed (reverted)" : "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) {
            if (response instanceof FlowErrorResponse) {
                FlowErrorResponse errorResponse = (FlowErrorResponse) response;
                if (isInstallCommand) {
                    FlowSegmentRequestFactory installCommand = stateMachine.getInstallCommand(commandId);
                    stateMachine.saveErrorToHistory("Failed to re-install (revert) rule", format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), installCommand.getCookie(), errorResponse, attempt));
                    stateMachine.getCarrier().sendSpeakerRequest(installCommand.makeInstallRequest(commandId));
                } else {
                    FlowSegmentRequestFactory removeCommand = stateMachine.getRemoveCommand(commandId);
                    stateMachine.saveErrorToHistory("Failed to delete rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), removeCommand.getCookie(), errorResponse, attempt));
                    stateMachine.getCarrier().sendSpeakerRequest(removeCommand.makeRemoveRequest(commandId));
                }
            } else if (response instanceof SpeakerCommandResponse) {
                String commandName = isInstallCommand ? "re-install (revert)" : "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 ? "re-install (revert)" : "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_REMOVED);
        } 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 24 with SpeakerFlowSegmentResponse

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

the class OnReceivedValidateResponseAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
    UUID commandId = response.getCommandId();
    FlowSegmentRequestFactory command = stateMachine.getCommands().get(commandId);
    if (!stateMachine.getPendingCommands().containsKey(commandId) || command == null) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.getPendingCommands().remove(commandId);
        stateMachine.saveActionToHistory("Rule was validated", format("The installed rule has been validated successfully: switch %s, cookie %s", command.getSwitchId(), command.getCookie()));
    } else {
        FlowErrorResponse errorResponse = (FlowErrorResponse) response;
        int retries = stateMachine.getRetriedCommands().getOrDefault(commandId, 0);
        if (retries < speakerCommandRetriesLimit && errorResponse.getErrorCode() != FlowErrorResponse.ErrorCode.MISSING_OF_FLOWS) {
            stateMachine.getRetriedCommands().put(commandId, ++retries);
            stateMachine.saveErrorToHistory(RULE_VALIDATION_FAILED_ACTION, format("Failed to validate non ingress rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse, retries));
            stateMachine.getCarrier().sendSpeakerRequest(command.makeVerifyRequest(commandId));
        } else {
            stateMachine.getPendingCommands().remove(commandId);
            stateMachine.saveErrorToHistory(RULE_VALIDATION_FAILED_ACTION, format("Failed to validate non ingress rule: commandId %s, switch %s, cookie %s. Error %s", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse));
            stateMachine.getFailedValidationResponses().put(commandId, response);
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedValidationResponses().isEmpty()) {
            log.debug("Installed rules have been validated for flow {}", stateMachine.getFlowId());
            stateMachine.fire(Event.RULES_VALIDATED);
        } else {
            stateMachine.saveErrorToHistory(format("Found missing rules or received error response(s) on %d validation commands", stateMachine.getFailedValidationResponses().size()));
            stateMachine.fire(Event.MISSING_RULE_FOUND);
        }
    }
}
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 25 with SpeakerFlowSegmentResponse

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

the class OnReceivedRemoveOrRevertResponseAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
    UUID commandId = response.getCommandId();
    FlowSegmentRequestFactory removeCommand = stateMachine.getRemoveCommands().get(commandId);
    FlowSegmentRequestFactory installCommand = stateMachine.getInstallCommand(commandId);
    if (!stateMachine.getPendingCommands().containsKey(commandId) || (removeCommand == null && installCommand == null)) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    MeterRegistryHolder.getRegistry().ifPresent(registry -> {
        if (response.getRequestCreateTime() > 0) {
            long roundtrip = Duration.between(Instant.ofEpochMilli(response.getRequestCreateTime()), Instant.now()).toNanos();
            if (roundtrip > 0) {
                registry.timer("fsm.remove_command.roundtrip").record(roundtrip, TimeUnit.NANOSECONDS);
            }
        }
        if (response.getExecutionTime() > 0) {
            registry.timer("fsm.remove_command.floodlight_execution").record(response.getExecutionTime(), TimeUnit.NANOSECONDS);
        }
    });
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        if (removeCommand != null) {
            stateMachine.saveActionToHistory("Rule was deleted", format("The rule was removed: switch %s, cookie %s", response.getSwitchId(), removeCommand.getCookie()));
        } else {
            stateMachine.saveActionToHistory("Rule was re-installed (reverted)", format("The rule was installed: switch %s, cookie %s", response.getSwitchId(), installCommand.getCookie()));
        }
    } else {
        FlowErrorResponse errorResponse = (FlowErrorResponse) response;
        int attempt = stateMachine.doRetryForCommand(commandId);
        if (attempt <= speakerCommandRetriesLimit) {
            if (removeCommand != null) {
                stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), removeCommand.getCookie(), errorResponse, attempt));
                stateMachine.getCarrier().sendSpeakerRequest(removeCommand.makeRemoveRequest(commandId));
            } else {
                stateMachine.saveErrorToHistory("Failed to re-install (revert) rule", format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), installCommand.getCookie(), errorResponse, attempt));
                stateMachine.getCarrier().sendSpeakerRequest(installCommand.makeInstallRequest(commandId));
            }
        } else {
            stateMachine.removePendingCommand(commandId);
            if (removeCommand != null) {
                stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error: %s", commandId, errorResponse.getSwitchId(), removeCommand.getCookie(), errorResponse));
            } else {
                stateMachine.saveErrorToHistory("Failed to re-install rule", format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error: %s", commandId, errorResponse.getSwitchId(), installCommand.getCookie(), errorResponse));
            }
            stateMachine.addFailedCommand(commandId, errorResponse);
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedCommands().isEmpty()) {
            log.debug("Received responses for all pending remove / re-install commands of the flow {}", stateMachine.getFlowId());
            stateMachine.fire(Event.RULES_REMOVED);
        } else {
            String errorMessage = format("Received error response(s) for %d remove / re-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)

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