Search in sources :

Example 6 with PathComputationStrategy

use of org.openkilda.model.PathComputationStrategy in project open-kilda by telstra.

the class NetworkServiceImpl method getPaths.

@Override
public CompletableFuture<PathsDto> getPaths(SwitchId srcSwitch, SwitchId dstSwitch, FlowEncapsulationType encapsulationType, PathComputationStrategy pathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) {
    String correlationId = RequestCorrelationId.getId();
    if (PathComputationStrategy.MAX_LATENCY.equals(pathComputationStrategy) && maxLatency == null) {
        throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID, "Missed max_latency parameter.", "MAX_LATENCY path computation strategy requires non null " + "max_latency parameter. If max_latency will be equal to 0 LATENCY strategy will be used instead " + "of MAX_LATENCY.");
    }
    GetPathsRequest request = new GetPathsRequest(srcSwitch, dstSwitch, encapsulationType, pathComputationStrategy, maxLatency, maxLatencyTier2);
    CommandMessage message = new CommandMessage(request, System.currentTimeMillis(), correlationId);
    return messagingChannel.sendAndGetChunked(nbworkerTopic, message).thenApply(paths -> {
        List<PathDto> pathsDtoList = paths.stream().map(PathsInfoData.class::cast).map(p -> pathMapper.mapToPath(p.getPath())).collect(Collectors.toList());
        return new PathsDto(pathsDtoList);
    });
}
Also used : FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) ErrorType(org.openkilda.messaging.error.ErrorType) Autowired(org.springframework.beans.factory.annotation.Autowired) NetworkService(org.openkilda.northbound.service.NetworkService) CompletableFuture(java.util.concurrent.CompletableFuture) RequestCorrelationId(org.openkilda.northbound.utils.RequestCorrelationId) Collectors(java.util.stream.Collectors) PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) PathMapper(org.openkilda.northbound.converter.PathMapper) MessageException(org.openkilda.messaging.error.MessageException) Value(org.springframework.beans.factory.annotation.Value) CommandMessage(org.openkilda.messaging.command.CommandMessage) List(java.util.List) PathDto(org.openkilda.messaging.payload.network.PathDto) SwitchId(org.openkilda.model.SwitchId) Service(org.springframework.stereotype.Service) MessagingChannel(org.openkilda.northbound.messaging.MessagingChannel) Duration(java.time.Duration) GetPathsRequest(org.openkilda.messaging.nbtopology.request.GetPathsRequest) PathsDto(org.openkilda.messaging.payload.network.PathsDto) PathDto(org.openkilda.messaging.payload.network.PathDto) PathsInfoData(org.openkilda.messaging.info.network.PathsInfoData) MessageException(org.openkilda.messaging.error.MessageException) PathsDto(org.openkilda.messaging.payload.network.PathsDto) GetPathsRequest(org.openkilda.messaging.nbtopology.request.GetPathsRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

PathComputationStrategy (org.openkilda.model.PathComputationStrategy)6 List (java.util.List)4 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)4 SwitchId (org.openkilda.model.SwitchId)4 Duration (java.time.Duration)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Flow (org.openkilda.model.Flow)3 Objects (java.util.Objects)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 PathsInfoData (org.openkilda.messaging.info.network.PathsInfoData)2 FlowPath (org.openkilda.model.FlowPath)2 KildaConfiguration (org.openkilda.model.KildaConfiguration)2 PathId (org.openkilda.model.PathId)2 Switch (org.openkilda.model.Switch)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 String.format (java.lang.String.format)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1