Search in sources :

Example 1 with InvalidDataException

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

the class LagPortOperationService method validatePhysicalPort.

private void validatePhysicalPort(SwitchId switchId, Set<SwitchFeature> features, Integer portNumber) throws InvalidDataException {
    if (portNumber == null || portNumber <= 0) {
        throw new InvalidDataException(format("Invalid physical port number %s. It can't be null or negative.", portNumber));
    }
    int bfdPortOffset = config.getBfdPortOffset();
    int bfdPortMaxNumber = config.getBfdPortMaxNumber();
    if (features.contains(BFD) && portNumber >= bfdPortOffset && portNumber <= bfdPortMaxNumber) {
        throw new InvalidDataException(format("Physical port number %d intersects with BFD port range [%d, %d]", portNumber, bfdPortOffset, bfdPortMaxNumber));
    }
    long lagPortOffset = config.getPoolConfig().getIdMinimum();
    if (portNumber >= lagPortOffset) {
        throw new InvalidDataException(format("Physical port number %d can't be greater than LAG port offset %d.", portNumber, lagPortOffset));
    }
    Collection<Isl> isls = islRepository.findByEndpoint(switchId, portNumber);
    if (!isls.isEmpty()) {
        throw new InvalidDataException(format("Physical port number %d intersects with existing ISLs %s.", portNumber, isls));
    }
    Optional<SwitchProperties> properties = switchPropertiesRepository.findBySwitchId(switchId);
    if (properties.isPresent() && Objects.equals(properties.get().getServer42Port(), portNumber)) {
        throw new InvalidDataException(format("Physical port number %d on switch %s is server42 port.", portNumber, switchId));
    }
    Set<String> flowIds = flowRepository.findByEndpoint(switchId, portNumber).stream().map(Flow::getFlowId).collect(Collectors.toSet());
    if (!flowIds.isEmpty()) {
        throw new InvalidDataException(format("Physical port %d already used by following flows: %s. You must " + "remove these flows to be able to use the port in LAG.", portNumber, flowIds));
    }
    Collection<FlowMirrorPath> mirrorPaths = flowMirrorPathRepository.findByEgressSwitchIdAndPort(switchId, portNumber);
    if (!mirrorPaths.isEmpty()) {
        Map<String, List<PathId>> mirrorPathByFLowIdMap = new HashMap<>();
        for (FlowMirrorPath path : mirrorPaths) {
            String flowId = path.getFlowMirrorPoints().getFlowPath().getFlowId();
            mirrorPathByFLowIdMap.computeIfAbsent(flowId, ignore -> new ArrayList<>());
            mirrorPathByFLowIdMap.get(flowId).add(path.getPathId());
        }
        String message = mirrorPathByFLowIdMap.entrySet().stream().map(entry -> format("flow '%s': %s", entry.getKey(), entry.getValue())).collect(Collectors.joining(", "));
        throw new InvalidDataException(format("Physical port %d already used as sink by following mirror points %s", portNumber, message));
    }
}
Also used : TransactionManager(org.openkilda.persistence.tx.TransactionManager) SwitchFeature(org.openkilda.model.SwitchFeature) LRUMap(org.apache.commons.collections4.map.LRUMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) Flow(org.openkilda.model.Flow) PoolManager(org.openkilda.wfm.share.utils.PoolManager) IslRepository(org.openkilda.persistence.repositories.IslRepository) Map(java.util.Map) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) LagLogicalPort(org.openkilda.model.LagLogicalPort) LagPortNotFoundException(org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException) PathId(org.openkilda.model.PathId) SwitchProperties(org.openkilda.model.SwitchProperties) IpSocketAddress(org.openkilda.model.IpSocketAddress) Switch(org.openkilda.model.Switch) PhysicalPortRepository(org.openkilda.persistence.repositories.PhysicalPortRepository) InconsistentDataException(org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException) NonNull(lombok.NonNull) Collection(java.util.Collection) SetView(com.google.common.collect.Sets.SetView) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) BFD(org.openkilda.model.SwitchFeature.BFD) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) Optional(java.util.Optional) ConstraintViolationException(org.openkilda.persistence.exceptions.ConstraintViolationException) Isl(org.openkilda.model.Isl) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) Isl(org.openkilda.model.Isl) HashMap(java.util.HashMap) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) ArrayList(java.util.ArrayList) List(java.util.List) SwitchProperties(org.openkilda.model.SwitchProperties) FlowMirrorPath(org.openkilda.model.FlowMirrorPath)

Example 2 with InvalidDataException

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

the class LagPortOperationService method createTransaction.

private LagLogicalPort createTransaction(SwitchId switchId, Set<Integer> targetPorts) {
    // locate switch first to produce correct error if switch is missing
    Switch sw = querySwitch(switchId);
    if (!isSwitchLagCapable(sw)) {
        throw new InvalidDataException(format("Switch %s doesn't support LAG.", sw.getSwitchId()));
    }
    Set<SwitchFeature> features = sw.getFeatures();
    for (Integer portNumber : targetPorts) {
        validatePhysicalPort(switchId, features, portNumber);
    }
    ensureNoLagCollisions(switchId, targetPorts);
    LagLogicalPort port = queryPoolManager(switchId).allocate();
    port.setPhysicalPorts(targetPorts.stream().map(portNumber -> new PhysicalPort(switchId, portNumber, port)).collect(Collectors.toList()));
    log.info("Adding new LAG logical port entry into DB: {}", port);
    lagLogicalPortRepository.add(port);
    return port;
}
Also used : Switch(org.openkilda.model.Switch) LagLogicalPort(org.openkilda.model.LagLogicalPort) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchFeature(org.openkilda.model.SwitchFeature)

Example 3 with InvalidDataException

use of org.openkilda.wfm.topology.switchmanager.error.InvalidDataException 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 4 with InvalidDataException

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

the class CreateLagPortFsm method createLagInDb.

void createLagInDb(CreateLagState from, CreateLagState to, CreateLagEvent event, CreateLagContext context) {
    log.info("Creating LAG {} on switch {}. Key={}", request, switchId, key);
    try {
        HashSet<Integer> targetPorts = new HashSet<>(request.getPortNumbers());
        lagLogicalPortNumber = lagPortOperationService.createLagPort(switchId, targetPorts);
        String ipAddress = lagPortOperationService.getSwitchIpAddress(switchId);
        grpcRequest = new CreateLogicalPortRequest(ipAddress, request.getPortNumbers(), lagLogicalPortNumber, LAG);
    } catch (InvalidDataException | InconsistentDataException | SwitchNotFoundException e) {
        log.error(format("Unable to handle %s. Error: %s", request, e.getMessage()), e);
        fire(ERROR, CreateLagContext.builder().error(e).build());
    }
}
Also used : InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) InconsistentDataException(org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) HashSet(java.util.HashSet) CreateLogicalPortRequest(org.openkilda.messaging.command.grpc.CreateLogicalPortRequest)

Example 5 with InvalidDataException

use of org.openkilda.wfm.topology.switchmanager.error.InvalidDataException 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)4 LagLogicalPort (org.openkilda.model.LagLogicalPort)3 Switch (org.openkilda.model.Switch)3 HashSet (java.util.HashSet)2 PhysicalPort (org.openkilda.model.PhysicalPort)2 SwitchFeature (org.openkilda.model.SwitchFeature)2 InconsistentDataException (org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException)2 LagPortNotFoundException (org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException)2 SwitchNotFoundException (org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException)2 Sets (com.google.common.collect.Sets)1 SetView (com.google.common.collect.Sets.SetView)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1