use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class YFlowDeleteServiceTest method processRequestAndSpeakerCommands.
private void processRequestAndSpeakerCommands(String yFlowId) throws DuplicateKeyException {
YFlowDeleteRequest yFlowRequest = new YFlowDeleteRequest(yFlowId);
YFlowDeleteService service = makeYFlowDeleteService(0);
service.handleRequest(yFlowRequest.getYFlowId(), new CommandContext(), yFlowRequest);
verifyYFlowStatus(yFlowRequest.getYFlowId(), FlowStatus.IN_PROGRESS);
handleSpeakerRequests(speakerRequest -> {
SpeakerResponse commandResponse;
if (speakerRequest instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) speakerRequest;
commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
}
handleAsyncResponse(service, yFlowRequest.getYFlowId(), commandResponse);
});
}
use of org.openkilda.floodlight.api.response.SpeakerResponse 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);
});
}
use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class YFlowUpdateServiceTest method processUpdateRequestAndSpeakerCommands.
private void processUpdateRequestAndSpeakerCommands(YFlowRequest yFlowRequest) throws DuplicateKeyException {
YFlowUpdateService service = makeYFlowUpdateService(0);
service.handleRequest(yFlowRequest.getYFlowId(), new CommandContext(), yFlowRequest);
verifyYFlowStatus(yFlowRequest.getYFlowId(), FlowStatus.IN_PROGRESS);
handleSpeakerRequests(speakerRequest -> {
SpeakerResponse commandResponse;
if (speakerRequest instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) speakerRequest;
commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
}
handleAsyncResponse(service, yFlowRequest.getYFlowId(), commandResponse);
});
}
use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class YFlowUpdateServiceTest method processUpdateRequestAndSpeakerCommands.
private void processUpdateRequestAndSpeakerCommands(YFlowRequest request, FlowStatus expectedStatus, FlowStatus expectedFirstSubFlowStatus, FlowStatus expectedSecondSubFlowStatus) throws DuplicateKeyException {
FlowUpdateService flowUpdateService = makeFlowUpdateService(0);
YFlowUpdateService service = makeYFlowUpdateService(flowUpdateService, 0);
service.handleRequest(request.getYFlowId(), new CommandContext(), request);
verifyYFlowStatus(request.getYFlowId(), expectedStatus, expectedFirstSubFlowStatus, expectedSecondSubFlowStatus);
handleSpeakerRequests(speakerRequest -> {
SpeakerResponse commandResponse;
if (speakerRequest instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) speakerRequest;
commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
}
handleAsyncResponse(service, request.getYFlowId(), commandResponse);
});
}
use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class OnReceivedRemoveOrRevertResponseAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
SpeakerResponse response = context.getSpeakerResponse();
UUID commandId = response.getCommandId();
if (!stateMachine.hasPendingCommand(commandId)) {
log.info("Received a response for unexpected command: {}", response);
return;
}
boolean isInstallCommand = stateMachine.getInstallCommand(commandId) != null || stateMachine.getInstallSpeakerCommand(commandId).isPresent();
if (response.isSuccess()) {
stateMachine.removePendingCommand(commandId);
String commandName = isInstallCommand ? "re-installed (reverted)" : "deleted";
if (response instanceof SpeakerFlowSegmentResponse) {
stateMachine.saveActionToHistory("Rule was " + commandName, format("The rule was %s: switch %s, cookie %s", commandName, response.getSwitchId(), ((SpeakerFlowSegmentResponse) response).getCookie()));
} else {
stateMachine.saveActionToHistory("Rule was " + commandName, format("The rule was %s: switch %s", commandName, response.getSwitchId()));
}
} else {
int attempt = stateMachine.doRetryForCommand(commandId);
if (attempt <= speakerCommandRetriesLimit) {
if (response instanceof FlowErrorResponse) {
FlowErrorResponse errorResponse = (FlowErrorResponse) response;
if (isInstallCommand) {
FlowSegmentRequestFactory installCommand = stateMachine.getInstallCommand(commandId);
stateMachine.saveErrorToHistory("Failed to re-install (revert) rule", format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), installCommand.getCookie(), errorResponse, attempt));
stateMachine.getCarrier().sendSpeakerRequest(installCommand.makeInstallRequest(commandId));
} else {
FlowSegmentRequestFactory removeCommand = stateMachine.getRemoveCommand(commandId);
stateMachine.saveErrorToHistory("Failed to delete rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), removeCommand.getCookie(), errorResponse, attempt));
stateMachine.getCarrier().sendSpeakerRequest(removeCommand.makeRemoveRequest(commandId));
}
} else if (response instanceof SpeakerCommandResponse) {
String commandName = isInstallCommand ? "re-install (revert)" : "delete";
SpeakerCommandResponse speakerCommandResponse = (SpeakerCommandResponse) response;
speakerCommandResponse.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory("Failed to " + commandName + " rule", format("Failed to %s the rule: commandId %s, ruleId %s, switch %s. " + "Error %s. Retrying (attempt %d)", commandName, commandId, uuid, response.getSwitchId(), message, attempt)));
Set<UUID> failedUuids = speakerCommandResponse.getFailedCommandIds().keySet();
stateMachine.getInstallSpeakerCommand(commandId).ifPresent(command -> stateMachine.getCarrier().sendSpeakerRequest(command.toBuilder().commands(filterOfCommands(command.getCommands(), failedUuids)).build()));
stateMachine.getDeleteSpeakerCommand(commandId).ifPresent(command -> stateMachine.getCarrier().sendSpeakerRequest(command.toBuilder().commands(filterOfCommands(command.getCommands(), failedUuids)).build()));
} else {
log.warn("Received a unknown response: {}", response);
return;
}
} else {
stateMachine.addFailedCommand(commandId, response);
stateMachine.removePendingCommand(commandId);
String commandName = isInstallCommand ? "re-install (revert)" : "delete";
if (response instanceof FlowErrorResponse) {
stateMachine.saveErrorToHistory("Failed to " + commandName + " rule", format("Failed to %s the rule: commandId %s, switch %s, cookie %s. Error %s.", commandName, commandId, response.getSwitchId(), ((FlowErrorResponse) response).getCookie(), response));
} else if (response instanceof SpeakerCommandResponse) {
((SpeakerCommandResponse) response).getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory("Failed to " + commandName + " rule", format("Failed to %s the rule: commandId %s, ruleId %s, switch %s. Error %s.", commandName, commandId, uuid, response.getSwitchId(), message)));
} else {
log.warn("Received a unknown response: {}", response);
return;
}
}
}
if (stateMachine.getPendingCommands().isEmpty()) {
if (stateMachine.getFailedCommands().isEmpty()) {
log.debug("Received responses for all pending install / delete commands of the flow {}", stateMachine.getFlowId());
stateMachine.fire(Event.RULES_REMOVED);
} else {
String errorMessage = format("Received error response(s) for %d install / delete commands", stateMachine.getFailedCommands().size());
stateMachine.saveErrorToHistory(errorMessage);
stateMachine.fireError(errorMessage);
}
}
}
Aggregations