Search in sources :

Example 1 with IllegalSwitchStateException

use of org.openkilda.wfm.error.IllegalSwitchStateException 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);
}
Also used : DeleteSwitchResponse(org.openkilda.messaging.nbtopology.response.DeleteSwitchResponse) IllegalSwitchStateException(org.openkilda.wfm.error.IllegalSwitchStateException) MessageException(org.openkilda.messaging.error.MessageException) Values(org.apache.storm.tuple.Values) SwitchId(org.openkilda.model.SwitchId) DeactivateSwitchInfoData(org.openkilda.messaging.info.event.DeactivateSwitchInfoData) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Aggregations

Values (org.apache.storm.tuple.Values)1 MessageException (org.openkilda.messaging.error.MessageException)1 DeactivateSwitchInfoData (org.openkilda.messaging.info.event.DeactivateSwitchInfoData)1 DeleteSwitchResponse (org.openkilda.messaging.nbtopology.response.DeleteSwitchResponse)1 SwitchId (org.openkilda.model.SwitchId)1 IllegalSwitchStateException (org.openkilda.wfm.error.IllegalSwitchStateException)1 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)1