Search in sources :

Example 11 with SwitchNotFoundException

use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.

the class FlowOperationsBolt method processGetFlowsForSwitchRequest.

@TimedExecution("get_flows_for_switch")
private List<FlowResponse> processGetFlowsForSwitchRequest(GetFlowsForSwitchRequest request) {
    SwitchId srcSwitch = request.getSwitchId();
    Integer srcPort = request.getPort();
    try {
        return flowOperationsService.getFlowsForEndpoint(srcSwitch, srcPort).stream().distinct().map(flowOperationsService::buildFlowResponse).collect(Collectors.toList());
    } catch (SwitchNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Switch was not found.");
    }
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 12 with SwitchNotFoundException

use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.

the class PathsService method getPaths.

/**
 * Get paths.
 */
public List<PathsInfoData> getPaths(SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException {
    if (Objects.equals(srcSwitchId, dstSwitchId)) {
        throw new IllegalArgumentException(String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId));
    }
    if (!switchRepository.exists(srcSwitchId)) {
        throw new SwitchNotFoundException(srcSwitchId);
    }
    if (!switchRepository.exists(dstSwitchId)) {
        throw new SwitchNotFoundException(dstSwitchId);
    }
    KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault();
    FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType).orElse(kildaConfiguration.getFlowEncapsulationType());
    SwitchProperties srcProperties = switchPropertiesRepository.findBySwitchId(srcSwitchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(srcSwitchId));
    if (!srcProperties.getSupportedTransitEncapsulation().contains(flowEncapsulationType)) {
        throw new IllegalArgumentException(String.format("Switch %s doesn't support %s encapslation type. Choose " + "one of the supported encapsulation types %s or update switch properties and add needed " + "encapsulation type.", srcSwitchId, flowEncapsulationType, srcProperties.getSupportedTransitEncapsulation()));
    }
    SwitchProperties dstProperties = switchPropertiesRepository.findBySwitchId(dstSwitchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(dstSwitchId));
    if (!dstProperties.getSupportedTransitEncapsulation().contains(flowEncapsulationType)) {
        throw new IllegalArgumentException(String.format("Switch %s doesn't support %s encapslation type. Choose " + "one of the supported encapsulation types %s or update switch properties and add needed " + "encapsulation type.", dstSwitchId, requestEncapsulationType, dstProperties.getSupportedTransitEncapsulation()));
    }
    PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy).orElse(kildaConfiguration.getPathComputationStrategy());
    List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy, maxLatency, maxLatencyTier2);
    return flowPaths.stream().map(PathMapper.INSTANCE::map).map(path -> PathsInfoData.builder().path(path).build()).collect(Collectors.toList());
}
Also used : Path(org.openkilda.pce.Path) KildaConfigurationRepository(org.openkilda.persistence.repositories.KildaConfigurationRepository) PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) RecoverableException(org.openkilda.pce.exception.RecoverableException) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) AvailableNetworkFactory(org.openkilda.pce.AvailableNetworkFactory) Duration(java.time.Duration) PathComputerConfig(org.openkilda.pce.PathComputerConfig) Path(org.openkilda.pce.Path) SwitchProperties(org.openkilda.model.SwitchProperties) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) KildaConfiguration(org.openkilda.model.KildaConfiguration) Collectors(java.util.stream.Collectors) PathComputerFactory(org.openkilda.pce.PathComputerFactory) 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) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) PathComputer(org.openkilda.pce.PathComputer) Optional(java.util.Optional) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) PathMapper(org.openkilda.wfm.share.mappers.PathMapper) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) SwitchProperties(org.openkilda.model.SwitchProperties) KildaConfiguration(org.openkilda.model.KildaConfiguration)

Aggregations

SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)12 Switch (org.openkilda.model.Switch)7 SwitchId (org.openkilda.model.SwitchId)6 MessageException (org.openkilda.messaging.error.MessageException)4 CommandContext (org.openkilda.wfm.CommandContext)4 List (java.util.List)3 Values (org.apache.storm.tuple.Values)3 GetSwitchResponse (org.openkilda.messaging.nbtopology.response.GetSwitchResponse)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Message (org.openkilda.messaging.Message)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 InfoData (org.openkilda.messaging.info.InfoData)2 DeactivateSwitchInfoData (org.openkilda.messaging.info.event.DeactivateSwitchInfoData)2 FlowPath (org.openkilda.model.FlowPath)2 IslEndpoint (org.openkilda.model.IslEndpoint)2 SwitchPropertiesNotFoundException (org.openkilda.wfm.error.SwitchPropertiesNotFoundException)2