use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.
the class OnReceivedRemoveOrRevertResponseAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
UUID commandId = response.getCommandId();
FlowSegmentRequestFactory removeCommand = stateMachine.getRemoveCommands().get(commandId);
FlowSegmentRequestFactory installCommand = stateMachine.getInstallCommand(commandId);
if (!stateMachine.getPendingCommands().containsKey(commandId) || (removeCommand == null && installCommand == null)) {
log.info("Received a response for unexpected command: {}", response);
return;
}
if (response.isSuccess()) {
stateMachine.removePendingCommand(commandId);
if (removeCommand != null) {
stateMachine.saveActionToHistory("Rule was deleted", format("The rule was removed: switch %s, cookie %s", response.getSwitchId(), removeCommand.getCookie()));
} else {
stateMachine.saveActionToHistory("Rule was re-installed (reverted)", format("The rule was installed: switch %s, cookie %s", response.getSwitchId(), installCommand.getCookie()));
}
} else {
FlowErrorResponse errorResponse = (FlowErrorResponse) response;
int attempt = stateMachine.doRetryForCommand(commandId);
if (attempt <= speakerCommandRetriesLimit) {
if (removeCommand != null) {
stateMachine.saveErrorToHistory("Failed to remove 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 {
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 {
stateMachine.removePendingCommand(commandId);
if (removeCommand != null) {
stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error: %s", commandId, errorResponse.getSwitchId(), removeCommand.getCookie(), errorResponse));
} else {
stateMachine.saveErrorToHistory("Failed to re-install rule", format("Failed to install the rule: commandId %s, switch %s, cookie %s. Error: %s", commandId, errorResponse.getSwitchId(), installCommand.getCookie(), errorResponse));
}
stateMachine.addFailedCommand(commandId, errorResponse);
}
}
if (stateMachine.getPendingCommands().isEmpty()) {
if (stateMachine.getFailedCommands().isEmpty()) {
log.debug("Received responses for all pending remove / re-install commands of the flow {}", stateMachine.getFlowId());
stateMachine.fire(Event.RULES_REMOVED);
} else {
String errorMessage = format("Received error response(s) for %d remove / re-install commands", stateMachine.getFailedCommands().size());
stateMachine.saveErrorToHistory(errorMessage);
stateMachine.fireError(errorMessage);
}
}
}
use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.
the class FlowUpdateHubBolt method onWorkerResponse.
@Override
protected void onWorkerResponse(Tuple input) {
String operationKey = input.getStringByField(MessageKafkaTranslator.FIELD_ID_KEY);
currentKey = KeyProvider.getParentKey(operationKey);
SpeakerFlowSegmentResponse flowResponse = (SpeakerFlowSegmentResponse) input.getValueByField(FIELD_ID_PAYLOAD);
try {
service.handleAsyncResponse(currentKey, flowResponse);
} catch (UnknownKeyException e) {
log.warn("Received a response with unknown key {}.", currentKey);
}
}
use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.
the class FlowDeleteHubBolt method onWorkerResponse.
@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
String operationKey = pullKey(input);
currentKey = KeyProvider.getParentKey(operationKey);
SpeakerFlowSegmentResponse flowResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerFlowSegmentResponse.class);
try {
service.handleAsyncResponse(currentKey, flowResponse);
} catch (UnknownKeyException e) {
log.warn("Received a response with unknown key {}.", currentKey);
}
}
use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.
the class FlowMirrorPointDeleteHubBolt method onWorkerResponse.
@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
String operationKey = pullKey(input);
currentKey = KeyProvider.getParentKey(operationKey);
SpeakerFlowSegmentResponse flowResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerFlowSegmentResponse.class);
service.handleAsyncResponse(currentKey, flowResponse);
}
use of org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse in project open-kilda by telstra.
the class FlowRerouteHubBolt method onWorkerResponse.
@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
String operationKey = pullKey(input);
currentKey = KeyProvider.getParentKey(operationKey);
SpeakerFlowSegmentResponse flowResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerFlowSegmentResponse.class);
try {
service.handleAsyncResponse(currentKey, flowResponse);
} catch (UnknownKeyException e) {
log.warn("Received a response with unknown key {}.", currentKey);
}
}
Aggregations