Search in sources :

Example 1 with LagPortNotFoundException

use of org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException in project open-kilda by telstra.

the class LagPortOperationService method ensureDeleteIsPossible.

/**
 * Verify that LAG logical port can be removed (it exists and do not in use by any flow).
 */
public LagLogicalPort ensureDeleteIsPossible(SwitchId switchId, int logicalPortNumber) {
    // locate switch first to produce correct error if switch is missing
    Switch sw = querySwitch(switchId);
    Optional<LagLogicalPort> port = lagLogicalPortRepository.findBySwitchIdAndPortNumber(switchId, logicalPortNumber);
    if (!port.isPresent()) {
        throw new LagPortNotFoundException(switchId, logicalPortNumber);
    }
    List<String> occupiedBy = flowRepository.findByEndpoint(switchId, logicalPortNumber).stream().map(Flow::getFlowId).collect(Collectors.toList());
    if (!occupiedBy.isEmpty()) {
        throw new InvalidDataException(format("Couldn't delete LAG port '%d' from switch %s because flows '%s' " + "use it as endpoint", logicalPortNumber, switchId, occupiedBy));
    }
    if (!isSwitchLagCapable(sw)) {
        log.error("Processing request for remove existing LAG logical port #{} on switch {} without LAG support", logicalPortNumber, switchId);
    }
    return port.get();
}
Also used : Switch(org.openkilda.model.Switch) LagLogicalPort(org.openkilda.model.LagLogicalPort) LagPortNotFoundException(org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException)

Example 2 with LagPortNotFoundException

use of org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException in project open-kilda by telstra.

the class DeleteLagPortFsm method createGrpcRequest.

void createGrpcRequest(DeleteLagState from, DeleteLagState to, DeleteLagEvent event, DeleteLagContext context) {
    log.info("Removing LAG {} on switch {}. Key={}", request, switchId, key);
    try {
        lagPortOperationService.ensureDeleteIsPossible(switchId, request.getLogicalPortNumber());
        String ipAddress = lagPortOperationService.getSwitchIpAddress(switchId);
        grpcRequest = new DeleteLogicalPortRequest(ipAddress, request.getLogicalPortNumber());
    } catch (LagPortNotFoundException | InvalidDataException | SwitchNotFoundException | InconsistentDataException e) {
        log.error(format("Unable to delete LAG logical port %d on switch %s. Error: %s", request.getLogicalPortNumber(), switchId, e.getMessage()), e);
        fire(ERROR, DeleteLagContext.builder().error(e).build());
    }
}
Also used : LagPortNotFoundException(org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException) DeleteLogicalPortRequest(org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) InconsistentDataException(org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException)

Aggregations

InvalidDataException (org.openkilda.wfm.topology.switchmanager.error.InvalidDataException)2 LagPortNotFoundException (org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException)2 DeleteLogicalPortRequest (org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest)1 LagLogicalPort (org.openkilda.model.LagLogicalPort)1 Switch (org.openkilda.model.Switch)1 InconsistentDataException (org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException)1 SwitchNotFoundException (org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException)1