use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class FlowDeleteService method handleAsyncResponse.
/**
* Handles async response from worker.
*
* @param key command identifier.
*/
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerFlowSegmentResponse flowResponse) throws UnknownKeyException {
log.debug("Received flow command response {}", flowResponse);
FlowDeleteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
FlowDeleteContext context = FlowDeleteContext.builder().speakerFlowResponse(flowResponse).build();
if (flowResponse instanceof FlowErrorResponse) {
fsmExecutor.fire(fsm, Event.ERROR_RECEIVED, context);
} else {
fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
}
removeIfFinished(fsm, key);
}
use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class FlowSegmentReport method assembleResponse.
private SpeakerResponse assembleResponse() {
FlowErrorResponseBuilder errorResponse = makeErrorTemplate();
try {
raiseError();
return makeSuccessReply();
} catch (SwitchNotFoundException e) {
errorResponse.errorCode(ErrorCode.SWITCH_UNAVAILABLE);
} catch (SessionErrorResponseException e) {
decodeError(errorResponse, e.getErrorResponse());
} catch (SwitchMissingFlowsException e) {
errorResponse.errorCode(ErrorCode.MISSING_OF_FLOWS);
errorResponse.description(e.getMessage());
} catch (SwitchOperationException e) {
errorResponse.errorCode(ErrorCode.UNKNOWN);
errorResponse.description(e.getMessage());
} catch (Exception e) {
log.error(String.format("Unhandled exception while processing command %s", command), e);
errorResponse.errorCode(ErrorCode.UNKNOWN);
}
FlowErrorResponse response = errorResponse.build();
log.error("Command {} have failed - {} {}", command, response.getErrorCode(), response.getDescription());
return response;
}
use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class FlowMirrorPointCreateService method handleAsyncResponse.
/**
* Handles async response from worker.
*
* @param key command identifier.
*/
public void handleAsyncResponse(String key, SpeakerFlowSegmentResponse flowResponse) {
log.debug("Received flow command response {}", flowResponse);
FlowMirrorPointCreateFsm fsm = fsmRegister.getFsmByKey(key).orElse(null);
if (fsm == null) {
log.warn("Failed to find a FSM: received response with key {} for non pending FSM", key);
return;
}
FlowMirrorPointCreateContext context = FlowMirrorPointCreateContext.builder().speakerFlowResponse(flowResponse).build();
if (flowResponse instanceof FlowErrorResponse) {
fsmExecutor.fire(fsm, Event.ERROR_RECEIVED, context);
} else {
fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
}
removeIfFinished(fsm, key);
}
use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class SpeakerCommandFsm method processResponse.
protected void processResponse(State from, State to, Event event, SpeakerFlowSegmentResponse response) {
if (response.isSuccess()) {
log.debug("Successfully executed the command {}", response);
fire(Event.NEXT);
} else {
FlowErrorResponse errorResponse = (FlowErrorResponse) response;
final ErrorCode errorCode = errorResponse.getErrorCode();
String giveUpReason = null;
if (remainingRetries <= 0) {
giveUpReason = String.format("all %s retry attempts have been used", allowedRetriesCount);
} else if (giveUpErrors.contains(errorCode)) {
giveUpReason = String.format("Error %s is in \"give up\" list, no more retry attempts allowed", errorCode);
}
if (giveUpReason == null) {
remainingRetries--;
log.debug("About to retry execution of the command {}", response);
fire(Event.RETRY);
} else {
fireError(giveUpReason);
}
}
}
use of org.openkilda.floodlight.flow.response.FlowErrorResponse in project open-kilda by telstra.
the class OnReceivedResponseAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
if (!response.isSuccess() || response instanceof FlowErrorResponse) {
throw new IllegalArgumentException(format("Invoked %s for an error response: %s", this.getClass(), response));
}
UUID commandId = response.getCommandId();
if (!stateMachine.removePendingCommand(commandId)) {
log.info("Received a response for unexpected command: {}", response);
return;
}
Cookie cookie = response.getCookie();
stateMachine.saveActionToHistory("Rule was deleted", format("The rule was deleted: switch %s, cookie %s", response.getSwitchId(), cookie));
if (stateMachine.getPendingCommands().isEmpty()) {
if (stateMachine.getFailedCommands().isEmpty()) {
log.debug("Received responses for all pending remove commands of the flow {}", stateMachine.getFlowId());
} else {
String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
stateMachine.saveErrorToHistory(errorMessage);
}
stateMachine.fire(Event.RULES_REMOVED);
}
}
Aggregations