Search in sources :

Example 1 with SpeakerCommandResponse

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

the class OnReceivedInstallResponseAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
    SpeakerCommandResponse response = context.getSpeakerResponse();
    UUID commandId = response.getCommandId();
    if (!stateMachine.hasPendingCommand(commandId)) {
        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", response.getSwitchId()));
    } else {
        Optional<InstallSpeakerCommandsRequest> request = stateMachine.getInstallSpeakerCommand(commandId);
        int attempt = stateMachine.doRetryForCommand(commandId);
        if (attempt <= speakerCommandRetriesLimit && request.isPresent()) {
            response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_INSTALL_RULE_ACTION, format("Failed to install the rule: commandId %s, ruleId %s, switch %s. " + "Error: %s. Retrying (attempt %d)", commandId, uuid, response.getSwitchId(), message, attempt)));
            Set<UUID> failedUuids = response.getFailedCommandIds().keySet();
            InstallSpeakerCommandsRequest installRequest = request.get();
            List<OfCommand> commands = installRequest.getCommands().stream().filter(command -> command instanceof FlowCommand && failedUuids.contains(((FlowCommand) command).getData().getUuid()) || command instanceof MeterCommand && failedUuids.contains(((MeterCommand) command).getData().getUuid()) || command instanceof GroupCommand && failedUuids.contains(((GroupCommand) command).getData().getUuid())).collect(Collectors.toList());
            stateMachine.getCarrier().sendSpeakerRequest(installRequest.toBuilder().commands(commands).build());
        } else {
            stateMachine.addFailedCommand(commandId, response);
            stateMachine.removePendingCommand(commandId);
            response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_INSTALL_RULE_ACTION, format("Failed to install the rule: commandId %s, ruleId %s, switch %s. Error: %s", commandId, uuid, response.getSwitchId(), message)));
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedCommands().isEmpty()) {
            log.debug("Received responses for all pending install commands of the y-flow {}", stateMachine.getYFlowId());
            stateMachine.fire(Event.YFLOW_METERS_INSTALLED);
        } else {
            String errorMessage = format("Received error response(s) for %d install commands", stateMachine.getFailedCommands().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm.State) Set(java.util.Set) UUID(java.util.UUID) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) YFlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteContext) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) InstallSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest) HistoryRecordingAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction) Optional(java.util.Optional) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm.Event) GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) YFlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm) InstallSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) UUID(java.util.UUID)

Example 2 with SpeakerCommandResponse

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

the class OnReceivedRemoveResponseAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
    SpeakerCommandResponse response = context.getSpeakerResponse();
    UUID commandId = response.getCommandId();
    if (!stateMachine.hasPendingCommand(commandId)) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        stateMachine.saveActionToHistory("Rule was deleted", format("The rule was removed: switch %s", response.getSwitchId()));
    } else {
        Optional<DeleteSpeakerCommandsRequest> request = stateMachine.getDeleteSpeakerCommand(commandId);
        int attempt = stateMachine.doRetryForCommand(commandId);
        if (attempt <= speakerCommandRetriesLimit && request.isPresent()) {
            response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_RULE_ACTION, format("Failed to remove the rule: commandId %s, ruleId %s, switch %s. " + "Error: %s. Retrying (attempt %d)", commandId, uuid, response.getSwitchId(), message, attempt)));
            Set<UUID> failedUuids = response.getFailedCommandIds().keySet();
            DeleteSpeakerCommandsRequest deleteRequest = request.get();
            List<OfCommand> commands = deleteRequest.getCommands().stream().filter(command -> command instanceof FlowCommand && failedUuids.contains(((FlowCommand) command).getData().getUuid()) || command instanceof MeterCommand && failedUuids.contains(((MeterCommand) command).getData().getUuid()) || command instanceof GroupCommand && failedUuids.contains(((GroupCommand) command).getData().getUuid())).collect(Collectors.toList());
            stateMachine.getCarrier().sendSpeakerRequest(deleteRequest.toBuilder().commands(commands).build());
        } else {
            stateMachine.addFailedCommand(commandId, response);
            stateMachine.removePendingCommand(commandId);
            response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_RULE_ACTION, format("Failed to remove the rule: commandId %s, ruleId %s, switch %s. Error: %s", commandId, uuid, response.getSwitchId(), message)));
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedCommands().isEmpty()) {
            log.debug("Received responses for all pending remove commands of the y-flow {}", stateMachine.getYFlowId());
            stateMachine.fire(Event.YPOINT_METER_REMOVED);
        } else {
            String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm.State) Set(java.util.Set) UUID(java.util.UUID) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) YFlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteContext) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) HistoryRecordingAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction) Optional(java.util.Optional) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm.Event) GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) YFlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) UUID(java.util.UUID) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Example 3 with SpeakerCommandResponse

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

the class OnReceivedValidateResponseAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
    SpeakerCommandResponse response = context.getSpeakerResponse();
    UUID commandId = response.getCommandId();
    if (!stateMachine.hasPendingCommand(commandId)) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        stateMachine.saveActionToHistory("Rule was validated", format("The rule was validated successfully: switch %s", response.getSwitchId()));
    } else {
    // We use validation directly in floodlight after installing the rules, so it's not necessary to do it here.
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedValidationResponses().isEmpty()) {
            log.debug("Rules have been validated for y-flow {}", stateMachine.getYFlowId());
            stateMachine.fire(Event.YFLOW_METERS_VALIDATED);
        } else {
            String errorMessage = format("Received error response(s) for %d validation commands", stateMachine.getFailedValidationResponses().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UUID(java.util.UUID)

Example 4 with SpeakerCommandResponse

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

the class OnReceivedRemoveResponseAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    SpeakerCommandResponse response = context.getSpeakerResponse();
    UUID commandId = response.getCommandId();
    if (!stateMachine.hasPendingCommand(commandId)) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        stateMachine.saveActionToHistory("Rule was deleted", format("The rule was removed: switch %s", response.getSwitchId()));
    } else {
        Optional<DeleteSpeakerCommandsRequest> request = stateMachine.getDeleteSpeakerCommand(commandId);
        int attempt = stateMachine.doRetryForCommand(commandId);
        if (attempt <= speakerCommandRetriesLimit && request.isPresent()) {
            response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_RULE_ACTION, format("Failed to remove the rule: commandId %s, ruleId %s, switch %s. " + "Error: %s. Retrying (attempt %d)", commandId, uuid, response.getSwitchId(), message, attempt)));
            Set<UUID> failedUuids = response.getFailedCommandIds().keySet();
            DeleteSpeakerCommandsRequest deleteRequest = request.get();
            List<OfCommand> commands = deleteRequest.getCommands().stream().filter(command -> command instanceof FlowCommand && failedUuids.contains(((FlowCommand) command).getData().getUuid()) || command instanceof MeterCommand && failedUuids.contains(((MeterCommand) command).getData().getUuid()) || command instanceof GroupCommand && failedUuids.contains(((GroupCommand) command).getData().getUuid())).collect(Collectors.toList());
            stateMachine.getCarrier().sendSpeakerRequest(deleteRequest.toBuilder().commands(commands).build());
        } else {
            stateMachine.addFailedCommand(commandId, response);
            stateMachine.removePendingCommand(commandId);
            response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_RULE_ACTION, format("Failed to remove the rule: commandId %s, ruleId %s, switch %s. Error: %s", commandId, uuid, response.getSwitchId(), message)));
        }
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedCommands().isEmpty()) {
            log.debug("Received responses for all pending remove commands of y-flow {}", stateMachine.getYFlowId());
            stateMachine.fire(Event.ALL_YFLOW_METERS_REMOVED);
        } else {
            String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) YFlowCreateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateContext) Set(java.util.Set) UUID(java.util.UUID) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateFsm.Event) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) HistoryRecordingAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction) Optional(java.util.Optional) YFlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateFsm) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateFsm.State) GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) UUID(java.util.UUID) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Example 5 with SpeakerCommandResponse

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

the class OnReceivedValidateResponseAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    SpeakerCommandResponse response = context.getSpeakerResponse();
    UUID commandId = response.getCommandId();
    if (!stateMachine.hasPendingCommand(commandId)) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        stateMachine.saveActionToHistory("Rule was validated", format("The rule was validated successfully: switch %s", response.getSwitchId()));
    } else {
    // We use validation directly in floodlight after installing the rules, so it's not necessary to do it here.
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedValidationResponses().isEmpty()) {
            log.debug("Received responses for all pending validation commands of y-flow {}", stateMachine.getYFlowId());
            stateMachine.fire(Event.ALL_YFLOW_METERS_VALIDATED);
        } else {
            String errorMessage = format("Received error response(s) for %d validation commands", stateMachine.getFailedValidationResponses().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UUID(java.util.UUID)

Aggregations

SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)17 UUID (java.util.UUID)12 String.format (java.lang.String.format)9 Set (java.util.Set)9 Slf4j (lombok.extern.slf4j.Slf4j)9 FlowCommand (org.openkilda.floodlight.api.request.rulemanager.FlowCommand)8 GroupCommand (org.openkilda.floodlight.api.request.rulemanager.GroupCommand)8 MeterCommand (org.openkilda.floodlight.api.request.rulemanager.MeterCommand)8 List (java.util.List)7 Optional (java.util.Optional)7 Collectors (java.util.stream.Collectors)7 OfCommand (org.openkilda.floodlight.api.request.rulemanager.OfCommand)7 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)7 HistoryRecordingAction (org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction)7 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)4 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)4 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)3 YFlowCreateContext (org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateContext)3 YFlowCreateFsm (org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateFsm)3 YFlowRerouteContext (org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteContext)3