use of org.openkilda.messaging.nbtopology.response.DeleteSwitchResponse in project open-kilda by telstra.
the class SwitchOperationsBolt method deleteSwitch.
private DeleteSwitchResponse deleteSwitch(DeleteSwitchRequest request) {
SwitchId switchId = request.getSwitchId();
boolean force = request.isForce();
boolean deleted = transactionManager.doInTransaction(() -> {
try {
if (!force) {
switchOperationsService.checkSwitchIsDeactivated(switchId);
switchOperationsService.checkSwitchHasNoFlows(switchId);
switchOperationsService.checkSwitchHasNoFlowSegments(switchId);
switchOperationsService.checkSwitchHasNoIsls(switchId);
}
return switchOperationsService.deleteSwitch(switchId, force);
} catch (SwitchNotFoundException e) {
String message = format("Could not delete switch '%s': '%s'", switchId, e.getMessage());
throw new MessageException(ErrorType.NOT_FOUND, message, "Switch is not found.");
} catch (IllegalSwitchStateException e) {
String message = format("Could not delete switch '%s': '%s'", switchId, e.getMessage());
throw new MessageException(ErrorType.REQUEST_INVALID, message, "Switch is in illegal state");
}
});
if (deleted) {
DeactivateSwitchInfoData data = new DeactivateSwitchInfoData(switchId);
getOutput().emit(StreamType.DISCO.toString(), getCurrentTuple(), new Values(data, getCorrelationId()));
}
log.info("{} deletion of switch '{}'", deleted ? "Successful" : "Unsuccessful", switchId);
return new DeleteSwitchResponse(deleted);
}
Aggregations