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");
}
}
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);
}
}
}
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);
}
}
}
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");
}
}
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");
}
}
Aggregations