Search in sources :

Example 6 with DeleteSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest in project open-kilda by telstra.

the class RemoveMetersAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    String yFlowId = stateMachine.getYFlowId();
    YFlow yFlow = getYFlow(yFlowId);
    Collection<DeleteSpeakerCommandsRequest> commands = buildYFlowDeleteCommands(yFlow, stateMachine.getCommandContext());
    commands.addAll(stateMachine.getDeleteOldYFlowCommands());
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove y-flow meters");
        stateMachine.fire(Event.YPOINT_METERS_REMOVED);
    } else {
        // emitting
        commands.forEach(command -> {
            stateMachine.getCarrier().sendSpeakerRequest(command);
            stateMachine.addDeleteSpeakerCommand(command.getCommandId(), command);
            stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
        });
        stateMachine.saveActionToHistory("Commands for removing y-flow rules have been sent");
    }
}
Also used : YFlow(org.openkilda.model.YFlow) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Example 7 with DeleteSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest in project open-kilda by telstra.

the class OnReceivedRemoveResponseAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm 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) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteFsm.Event) 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) YFlowDeleteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteContext) OfCommand(org.openkilda.floodlight.api.request.rulemanager.OfCommand) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteFsm.State) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) HistoryRecordingAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction) YFlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteFsm) Optional(java.util.Optional) 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 8 with DeleteSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest in project open-kilda by telstra.

the class OnReceivedRemoveResponseAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm 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_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) 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) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) HistoryRecordingAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction) YFlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm.Event) Optional(java.util.Optional) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm.State) GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) YFlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateContext) 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 9 with DeleteSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest in project open-kilda by telstra.

the class RemoveYFlowResourcesAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    String yFlowId = stateMachine.getYFlowId();
    YFlow yFlow = getYFlow(yFlowId);
    Collection<DeleteSpeakerCommandsRequest> commands = buildYFlowDeleteCommands(yFlow, stateMachine.getCommandContext());
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove y-flow meters");
        stateMachine.fire(Event.ALL_YFLOW_METERS_REMOVED);
    } else {
        // emitting
        commands.forEach(command -> {
            stateMachine.getCarrier().sendSpeakerRequest(command);
            stateMachine.addDeleteSpeakerCommand(command.getCommandId(), command);
            stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
        });
        stateMachine.saveActionToHistory("Commands for removing y-flow rules have been sent");
    }
}
Also used : YFlow(org.openkilda.model.YFlow) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Example 10 with DeleteSpeakerCommandsRequest

use of org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest in project open-kilda by telstra.

the class RemoveYFlowResourcesAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
    String yFlowId = stateMachine.getYFlowId();
    YFlow yFlow = getYFlow(yFlowId);
    YFlowResources oldResources;
    // This could be a retry.
    if (stateMachine.getOldResources() != null) {
        oldResources = stateMachine.getOldResources();
    } else {
        oldResources = new YFlowResources();
        stateMachine.setOldResources(oldResources);
    }
    if (oldResources.getSharedEndpointResources() == null) {
        oldResources.setSharedEndpointResources(EndpointResources.builder().endpoint(yFlow.getSharedEndpoint().getSwitchId()).meterId(yFlow.getSharedEndpointMeterId()).build());
    }
    if (oldResources.getMainPathYPointResources() == null) {
        oldResources.setMainPathYPointResources(EndpointResources.builder().endpoint(yFlow.getYPoint()).meterId(yFlow.getMeterId()).build());
    }
    if (yFlow.isAllocateProtectedPath() && oldResources.getProtectedPathYPointResources() == null) {
        oldResources.setProtectedPathYPointResources(EndpointResources.builder().endpoint(yFlow.getProtectedPathYPoint()).meterId(yFlow.getProtectedPathMeterId()).build());
    }
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    Collection<DeleteSpeakerCommandsRequest> commands = stateMachine.getDeleteOldYFlowCommands();
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove y-flow meters");
        stateMachine.fire(Event.ALL_YFLOW_METERS_REMOVED);
    } else {
        // emitting
        commands.forEach(command -> {
            stateMachine.getCarrier().sendSpeakerRequest(command);
            stateMachine.addDeleteSpeakerCommand(command.getCommandId(), command);
            stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
        });
        stateMachine.saveActionToHistory("Commands for removing y-flow rules have been sent");
    }
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowResources(org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Aggregations

DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)12 UUID (java.util.UUID)5 OfCommand (org.openkilda.floodlight.api.request.rulemanager.OfCommand)5 YFlow (org.openkilda.model.YFlow)5 String.format (java.lang.String.format)4 List (java.util.List)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Slf4j (lombok.extern.slf4j.Slf4j)4 FlowCommand (org.openkilda.floodlight.api.request.rulemanager.FlowCommand)4 GroupCommand (org.openkilda.floodlight.api.request.rulemanager.GroupCommand)4 MeterCommand (org.openkilda.floodlight.api.request.rulemanager.MeterCommand)4 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)4 HistoryRecordingAction (org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction)4 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)2 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)2 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)2 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)2 Flow (org.openkilda.model.Flow)2