use of org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest in project open-kilda by telstra.
the class InstallYFlowResourcesAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
stateMachine.clearPendingAndRetriedAndFailedCommands();
String yFlowId = stateMachine.getYFlowId();
YFlow yFlow = getYFlow(yFlowId);
Collection<InstallSpeakerCommandsRequest> commands = buildYFlowInstallCommands(yFlow, stateMachine.getCommandContext());
if (commands.isEmpty()) {
stateMachine.saveActionToHistory("No need to install y-flow meters");
stateMachine.fire(Event.ALL_YFLOW_METERS_INSTALLED);
} else {
// emitting
commands.forEach(command -> {
stateMachine.getCarrier().sendSpeakerRequest(command);
stateMachine.addInstallSpeakerCommand(command.getCommandId(), command);
stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
});
stateMachine.saveActionToHistory("Commands for installing y-flow rules have been sent");
}
}
use of org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest in project open-kilda by telstra.
the class OnReceivedInstallResponseAction 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 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 y-flow {}", stateMachine.getYFlowId());
stateMachine.fire(Event.ALL_YFLOW_METERS_INSTALLED);
} else {
String errorMessage = format("Received error response(s) for %d install commands", stateMachine.getFailedCommands().size());
stateMachine.saveErrorToHistory(errorMessage);
stateMachine.fireError(errorMessage);
}
}
}
use of org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest in project open-kilda by telstra.
the class YFlowRerouteServiceTest method handleSpeakerCommandsAndTimeoutInstall.
private void handleSpeakerCommandsAndTimeoutInstall(YFlowRerouteService service, String yFlowFsmKey) {
handleSpeakerRequests(request -> {
SpeakerResponse commandResponse;
if (request instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) request;
commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
handleAsyncResponse(service, yFlowFsmKey, commandResponse);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) request;
if (speakerCommandsRequest instanceof InstallSpeakerCommandsRequest) {
try {
service.handleTimeout(yFlowFsmKey);
} catch (UnknownKeyException ex) {
// skip
}
} else {
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
handleAsyncResponse(service, yFlowFsmKey, commandResponse);
}
}
});
}
use of org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest in project open-kilda by telstra.
the class YFlowRerouteServiceTest method handleSpeakerCommandsAndFailInstall.
private void handleSpeakerCommandsAndFailInstall(YFlowRerouteService yFlowRerouteService, String yFlowFsmKey, String commandFlowIdToFail) {
handleSpeakerRequests(request -> {
SpeakerResponse commandResponse;
if (request instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) request;
commandResponse = flowSegmentRequest.isInstallRequest() && flowSegmentRequest.getMetadata().getFlowId().equals(commandFlowIdToFail) ? buildErrorSpeakerResponse(flowSegmentRequest) : buildSuccessfulSpeakerResponse(flowSegmentRequest);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) request;
commandResponse = request instanceof InstallSpeakerCommandsRequest ? buildErrorYFlowSpeakerResponse(speakerCommandsRequest) : buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
}
handleAsyncResponse(yFlowRerouteService, yFlowFsmKey, commandResponse);
});
}
use of org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest in project open-kilda by telstra.
the class YFlowCreateServiceTest method handleSpeakerCommandsAndTimeoutInstall.
private void handleSpeakerCommandsAndTimeoutInstall(YFlowCreateService yFlowCreateService, String yFlowFsmKey) {
handleSpeakerRequests(request -> {
SpeakerResponse commandResponse;
if (request instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) request;
commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) request;
if (speakerCommandsRequest instanceof InstallSpeakerCommandsRequest) {
handleTimeout(yFlowCreateService, yFlowFsmKey);
}
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
}
yFlowCreateService.handleAsyncResponse(yFlowFsmKey, commandResponse);
});
}
Aggregations