use of org.openkilda.floodlight.api.request.rulemanager.OfCommand in project open-kilda by telstra.
the class OnReceivedInstallResponseAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm 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 the y-flow {}", stateMachine.getYFlowId());
stateMachine.fire(Event.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.OfCommand in project open-kilda by telstra.
the class OnReceivedRemoveResponseAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm 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 deleted", format("The rule was removed: switch %s", response.getSwitchId()));
} else {
Optional<DeleteSpeakerCommandsRequest> request = stateMachine.getDeleteSpeakerCommand(commandId);
int attempt = stateMachine.doRetryForCommand(commandId);
if (attempt <= speakerCommandRetriesLimit && request.isPresent()) {
response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_RULE_ACTION, format("Failed to remove 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();
DeleteSpeakerCommandsRequest deleteRequest = request.get();
List<OfCommand> commands = deleteRequest.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(deleteRequest.toBuilder().commands(commands).build());
} else {
stateMachine.addFailedCommand(commandId, response);
stateMachine.removePendingCommand(commandId);
response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_RULE_ACTION, format("Failed to remove 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 remove commands of the y-flow {}", stateMachine.getYFlowId());
stateMachine.fire(Event.YPOINT_METER_REMOVED);
} else {
String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
stateMachine.saveErrorToHistory(errorMessage);
stateMachine.fireError(errorMessage);
}
}
}
use of org.openkilda.floodlight.api.request.rulemanager.OfCommand in project open-kilda by telstra.
the class OnReceivedRemoveResponseAction 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 deleted", format("The rule was removed: switch %s", response.getSwitchId()));
} else {
Optional<DeleteSpeakerCommandsRequest> request = stateMachine.getDeleteSpeakerCommand(commandId);
int attempt = stateMachine.doRetryForCommand(commandId);
if (attempt <= speakerCommandRetriesLimit && request.isPresent()) {
response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_RULE_ACTION, format("Failed to remove 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();
DeleteSpeakerCommandsRequest deleteRequest = request.get();
List<OfCommand> commands = deleteRequest.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(deleteRequest.toBuilder().commands(commands).build());
} else {
stateMachine.addFailedCommand(commandId, response);
stateMachine.removePendingCommand(commandId);
response.getFailedCommandIds().forEach((uuid, message) -> stateMachine.saveErrorToHistory(FAILED_TO_REMOVE_RULE_ACTION, format("Failed to remove 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 remove commands of y-flow {}", stateMachine.getYFlowId());
stateMachine.fire(Event.ALL_YFLOW_METERS_REMOVED);
} else {
String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
stateMachine.saveErrorToHistory(errorMessage);
stateMachine.fireError(errorMessage);
}
}
}
use of org.openkilda.floodlight.api.request.rulemanager.OfCommand in project open-kilda by telstra.
the class OfSpeakerService method processBatchDelete.
@Override
public void processBatchDelete(DeleteSpeakerCommandsRequest request, String key) {
SwitchId switchId = request.getSwitchId();
DatapathId dpId = DatapathId.of(switchId.toLong());
IOFSwitch sw = iofSwitchService.getSwitch(dpId);
OfBatchHolder holder = new OfBatchHolder(iofSwitchService, request.getMessageContext(), request.getCommandId(), request.getSwitchId());
for (OfCommand data : request.getCommands()) {
data.buildDelete(holder, switchId);
}
OfBatchExecutor executor = OfBatchExecutor.builder().iofSwitch(sw).kafkaUtilityService(kafkaUtilityService).kafkaProducerService(kafkaProducerService).sessionService(sessionService).messageContext(request.getMessageContext()).holder(holder).switchFeatures(featureDetectorService.detectSwitch(sw)).kafkaKey(key).build();
executor.executeBatch();
}
use of org.openkilda.floodlight.api.request.rulemanager.OfCommand in project open-kilda by telstra.
the class OfSpeakerService method processBatchInstall.
@Override
public void processBatchInstall(InstallSpeakerCommandsRequest request, String key) {
SwitchId switchId = request.getSwitchId();
DatapathId dpId = DatapathId.of(switchId.toLong());
IOFSwitch sw = iofSwitchService.getSwitch(dpId);
OfBatchHolder holder = new OfBatchHolder(iofSwitchService, request.getMessageContext(), request.getCommandId(), request.getSwitchId());
for (OfCommand data : request.getCommands()) {
data.buildInstall(holder, switchId);
}
OfBatchExecutor executor = OfBatchExecutor.builder().iofSwitch(sw).kafkaUtilityService(kafkaUtilityService).kafkaProducerService(kafkaProducerService).sessionService(sessionService).messageContext(request.getMessageContext()).holder(holder).switchFeatures(featureDetectorService.detectSwitch(sw)).kafkaKey(key).build();
executor.executeBatch();
}
Aggregations