use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class YFlowRerouteHubBolt method onWorkerResponse.
@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
String operationKey = pullKey(input);
currentKey = KeyProvider.getParentKey(operationKey);
SpeakerResponse speakerResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerResponse.class);
try {
yFlowRerouteService.handleAsyncResponse(currentKey, speakerResponse);
} catch (UnknownKeyException e) {
log.error("Received a response with unknown key {}.", currentKey);
}
}
use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class YFlowCreateHubBolt method onWorkerResponse.
@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
String operationKey = pullKey(input);
currentKey = KeyProvider.getParentKey(operationKey);
SpeakerResponse speakerResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerResponse.class);
try {
yFlowCreateService.handleAsyncResponse(currentKey, speakerResponse);
} catch (UnknownKeyException e) {
log.error("Received a response with unknown key {}.", currentKey);
}
}
use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class ValidateIngressRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
SpeakerResponse response = context.getSpeakerResponse();
UUID commandId = response.getCommandId();
FlowSegmentRequestFactory command = stateMachine.getIngressCommands().get(commandId);
if (!stateMachine.getPendingCommands().containsKey(commandId) || command == null) {
log.info("Received a response for unexpected command: {}", response);
return;
}
if (response.isSuccess()) {
stateMachine.removePendingCommand(commandId);
stateMachine.saveActionToHistory("Rule was validated", format("The ingress rule has been validated successfully: switch %s, cookie %s", command.getSwitchId(), command.getCookie()));
} else {
FlowErrorResponse errorResponse = (FlowErrorResponse) response;
int attempt = stateMachine.doRetryForCommand(commandId);
if (attempt <= speakerCommandRetriesLimit && errorResponse.getErrorCode() != FlowErrorResponse.ErrorCode.MISSING_OF_FLOWS) {
stateMachine.saveErrorToHistory("Rule validation failed", format("Failed to validate the ingress rule: commandId %s, switch %s, cookie %s. Error %s. " + "Retrying (attempt %d)", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse, attempt));
stateMachine.getCarrier().sendSpeakerRequest(command.makeInstallRequest(commandId));
} else {
stateMachine.removePendingCommand(commandId);
stateMachine.saveErrorToHistory("Rule validation failed", format("Failed to validate the ingress rule: commandId %s, switch %s, cookie %s. Error %s", commandId, errorResponse.getSwitchId(), command.getCookie(), errorResponse));
stateMachine.getFailedValidationResponses().put(commandId, response);
}
}
if (stateMachine.getPendingCommands().isEmpty()) {
if (stateMachine.getFailedValidationResponses().isEmpty()) {
log.debug("Ingress rules have been validated for flow {}", stateMachine.getFlowId());
stateMachine.fire(Event.RULES_VALIDATED);
} else {
stateMachine.saveErrorToHistory(format("Found missing rules or received error response(s) on %d validation commands", stateMachine.getFailedValidationResponses().size()));
stateMachine.fire(Event.MISSING_RULE_FOUND);
}
}
}
use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class SetValidateRuleErrorAction method execute.
@Override
public void execute(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
Set<SwitchId> switches = Stream.concat(stateMachine.getPendingCommands().values().stream(), stateMachine.getFailedValidationResponses().values().stream().map(SpeakerResponse::getSwitchId)).collect(Collectors.toSet());
stateMachine.setRerouteError(new SpeakerRequestError("Failed to validate rules", switches));
log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
stateMachine.clearPendingCommands();
}
use of org.openkilda.floodlight.api.response.SpeakerResponse in project open-kilda by telstra.
the class YFlowUpdateServiceTest method processUpdateRequestAndSpeakerCommands.
private void processUpdateRequestAndSpeakerCommands(YFlowPartialUpdateRequest request) throws DuplicateKeyException {
YFlowUpdateService service = makeYFlowUpdateService(0);
service.handlePartialUpdateRequest(request.getYFlowId(), new CommandContext(), request);
verifyYFlowStatus(request.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, request.getYFlowId(), commandResponse);
});
}
Aggregations