use of org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest in project open-kilda by telstra.
the class UpdateYFlowRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
String yFlowId = flow.getYFlowId();
if (yFlowId == null) {
stateMachine.saveActionToHistory("No need to update y-flow rules - it's not a sub-flow");
stateMachine.fire(Event.SKIP_YFLOW_RULES_UPDATE);
return;
}
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found in persistent storage", yFlowId)));
stateMachine.clearPendingAndRetriedAndFailedCommands();
SwitchId sharedEndpoint = yFlow.getSharedEndpoint().getSwitchId();
InstallSpeakerCommandsRequest installRequest = buildYFlowInstallRequest(sharedEndpoint, stateMachine.getNewPrimaryForwardPath(), stateMachine.getCommandContext());
stateMachine.addInstallSpeakerCommand(installRequest.getCommandId(), installRequest);
DeleteSpeakerCommandsRequest deleteRequest = buildYFlowDeleteRequest(sharedEndpoint, stateMachine.getOldPrimaryForwardPath(), stateMachine.getCommandContext());
stateMachine.addDeleteSpeakerCommand(deleteRequest.getCommandId(), deleteRequest);
// emitting
Stream.of(installRequest, deleteRequest).forEach(command -> {
stateMachine.getCarrier().sendSpeakerRequest(command);
stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
});
stateMachine.saveActionToHistory("Commands for updating y-flow rules have been sent");
}
use of org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest in project open-kilda by telstra.
the class RevertYFlowRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
String yFlowId = flow.getYFlowId();
if (yFlowId == null) {
stateMachine.saveActionToHistory("No need to revert y-flow rules - it's not a sub-flow");
stateMachine.fire(Event.SKIP_YFLOW_RULES_REVERT);
return;
}
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found in persistent storage", yFlowId)));
stateMachine.clearPendingAndRetriedAndFailedCommands();
SwitchId sharedEndpoint = yFlow.getSharedEndpoint().getSwitchId();
InstallSpeakerCommandsRequest installRequest = buildYFlowInstallRequest(sharedEndpoint, stateMachine.getOldPrimaryForwardPath(), stateMachine.getCommandContext());
stateMachine.addInstallSpeakerCommand(installRequest.getCommandId(), installRequest);
DeleteSpeakerCommandsRequest deleteRequest = buildYFlowDeleteRequest(sharedEndpoint, stateMachine.getNewPrimaryForwardPath(), stateMachine.getCommandContext());
stateMachine.addDeleteSpeakerCommand(deleteRequest.getCommandId(), deleteRequest);
// emitting
Stream.of(installRequest, deleteRequest).forEach(command -> {
stateMachine.getCarrier().sendSpeakerRequest(command);
stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
});
stateMachine.saveActionToHistory("Commands for reverting 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, 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);
}
}
}
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, 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);
}
}
}
use of org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest in project open-kilda by telstra.
the class YFlowDeleteServiceTest method handleSpeakerCommandsAndTimeoutRemove.
private void handleSpeakerCommandsAndTimeoutRemove(YFlowDeleteService yFlowDeleteService, String yFlowFsmKey) {
handleSpeakerRequests(request -> {
SpeakerResponse commandResponse;
if (request instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) request;
commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
handleAsyncResponse(yFlowDeleteService, yFlowFsmKey, commandResponse);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) request;
if (speakerCommandsRequest instanceof DeleteSpeakerCommandsRequest) {
try {
yFlowDeleteService.handleTimeout(yFlowFsmKey);
} catch (UnknownKeyException ex) {
// skip
}
} else {
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
handleAsyncResponse(yFlowDeleteService, yFlowFsmKey, commandResponse);
}
}
});
}
Aggregations