Search in sources :

Example 11 with FlowNotFoundException

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

the class FlowOperationsService method getFlowPath.

/**
 * Returns flow path. If flow has group, returns also path for each flow in group.
 *
 * @param flowId the flow to get a path.
 */
public List<FlowPathDto> getFlowPath(String flowId) throws FlowNotFoundException {
    flowDashboardLogger.onFlowPathsRead(flowId);
    Flow flow = flowRepository.findById(flowId).orElseThrow(() -> new FlowNotFoundException(flowId));
    String groupId = flow.getDiverseGroupId();
    if (groupId == null) {
        return Collections.singletonList(toFlowPathDtoBuilder(flow).build());
    } else {
        Collection<Flow> flowsInGroup = flowRepository.findByDiverseGroupId(groupId);
        Collection<FlowPath> flowPathsInGroup = flowPathRepository.findByFlowGroupId(groupId);
        IntersectionComputer primaryIntersectionComputer = new IntersectionComputer(flow.getFlowId(), flow.getForwardPathId(), flow.getReversePathId(), flowPathsInGroup);
        // target flow primary path
        FlowPathDtoBuilder targetFlowDtoBuilder = this.toFlowPathDtoBuilder(flow).segmentsStats(primaryIntersectionComputer.getOverlappingStats());
        // other flows in the the group
        List<FlowPathDto> payloads = flowsInGroup.stream().filter(e -> !e.getFlowId().equals(flowId)).map(e -> this.mapGroupPathFlowDto(e, true, primaryIntersectionComputer)).collect(Collectors.toList());
        if (flow.isAllocateProtectedPath()) {
            IntersectionComputer protectedIntersectionComputer = new IntersectionComputer(flow.getFlowId(), flow.getProtectedForwardPathId(), flow.getProtectedReversePathId(), flowPathsInGroup);
            // target flow protected path
            targetFlowDtoBuilder.protectedPath(FlowProtectedPathDto.builder().forwardPath(buildPathFromFlow(flow, flow.getProtectedForwardPath())).reversePath(buildPathFromFlow(flow, flow.getProtectedReversePath())).segmentsStats(protectedIntersectionComputer.getOverlappingStats()).build());
            // other flows in the the group
            List<FlowPathDto> protectedPathPayloads = flowsInGroup.stream().filter(e -> !e.getFlowId().equals(flowId)).map(e -> this.mapGroupPathFlowDto(e, false, protectedIntersectionComputer)).collect(Collectors.toList());
            payloads = union(payloads, protectedPathPayloads);
        }
        payloads.add(targetFlowDtoBuilder.build());
        return payloads;
    }
}
Also used : MAX_LATENCY(org.openkilda.model.PathComputationStrategy.MAX_LATENCY) FlowStats(org.openkilda.model.FlowStats) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) FlowPath(org.openkilda.model.FlowPath) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowMirrorPoint(org.openkilda.messaging.nbtopology.response.FlowMirrorPointsDumpResponse.FlowMirrorPoint) Flow(org.openkilda.model.Flow) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) Duration(java.time.Duration) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) SwitchConnectedDeviceRepository(org.openkilda.persistence.repositories.SwitchConnectedDeviceRepository) IslEndpoint(org.openkilda.model.IslEndpoint) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) YSubFlow(org.openkilda.model.YSubFlow) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) Objects(java.util.Objects) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) FlowPatch(org.openkilda.messaging.model.FlowPatch) Builder(lombok.Builder) FlowsDumpRequest(org.openkilda.messaging.nbtopology.request.FlowsDumpRequest) DetectConnectedDevicesDto(org.openkilda.messaging.model.DetectConnectedDevicesDto) Optional(java.util.Optional) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) ListUtils.union(org.apache.commons.collections4.ListUtils.union) TransactionManager(org.openkilda.persistence.tx.TransactionManager) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) PatchEndpoint(org.openkilda.messaging.model.PatchEndpoint) FlowPathDtoBuilder(org.openkilda.messaging.model.FlowPathDto.FlowPathDtoBuilder) IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) YFlow(org.openkilda.model.YFlow) FlowProtectedPathDto(org.openkilda.messaging.model.FlowPathDto.FlowProtectedPathDto) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) RequestedFlowMapper(org.openkilda.wfm.share.mappers.RequestedFlowMapper) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) ErrorType(org.openkilda.messaging.error.ErrorType) LATENCY(org.openkilda.model.PathComputationStrategy.LATENCY) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowMapper(org.openkilda.wfm.share.mappers.FlowMapper) FlowFilter(org.openkilda.model.FlowFilter) SwitchId(org.openkilda.model.SwitchId) FlowOperationsCarrier(org.openkilda.wfm.topology.nbworker.bolts.FlowOperationsCarrier) Data(lombok.Data) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) FlowPathDtoBuilder(org.openkilda.messaging.model.FlowPathDto.FlowPathDtoBuilder) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow)

Example 12 with FlowNotFoundException

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

the class FlowOperationsBolt method processFlowReadRequest.

@TimedExecution("flow_read")
private List<FlowResponse> processFlowReadRequest(FlowReadRequest readRequest) {
    try {
        String flowId = readRequest.getFlowId();
        Flow flow = flowOperationsService.getFlow(flowId);
        FlowStats flowStats = flowOperationsService.getFlowStats(flowId);
        FlowResponse response = flowOperationsService.buildFlowResponse(flow, flowStats);
        return Collections.singletonList(response);
    } catch (FlowNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, "Can not get flow: " + e.getMessage(), "Flow not found");
    } catch (Exception e) {
        log.error("Can not get flow", e);
        throw new MessageException(ErrorType.INTERNAL_ERROR, "Can not get flow", "Internal Error");
    }
}
Also used : FlowStats(org.openkilda.model.FlowStats) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Example 13 with FlowNotFoundException

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

the class FlowOperationsBolt method processFlowConnectedDeviceRequest.

private List<FlowConnectedDevicesResponse> processFlowConnectedDeviceRequest(FlowConnectedDeviceRequest request) {
    Collection<SwitchConnectedDevice> devices;
    try {
        devices = flowOperationsService.getFlowConnectedDevice(request.getFlowId()).stream().filter(device -> request.getSince().isBefore(device.getTimeLastSeen()) || request.getSince().equals(device.getTimeLastSeen())).collect(Collectors.toList());
    } catch (FlowNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Could not get connected devices for non existent flow");
    }
    FlowConnectedDevicesResponse response = new FlowConnectedDevicesResponse(new TypedConnectedDevicesDto(new ArrayList<>(), new ArrayList<>()), new TypedConnectedDevicesDto(new ArrayList<>(), new ArrayList<>()));
    for (SwitchConnectedDevice device : devices) {
        ConnectedDeviceDto deviceDto = ConnectedDeviceMapper.INSTANCE.mapSwitchDeviceToFlowDeviceDto(device);
        if (device.getSource() == null) {
            log.warn("Switch Connected Device {} has Flow ID {} but has no 'source' property.", device, device.getFlowId());
        } else if (device.getSource()) {
            if (device.getType() == LLDP) {
                response.getSource().getLldp().add(deviceDto);
            } else if (device.getType() == ARP) {
                response.getSource().getArp().add(deviceDto);
            }
        } else {
            if (device.getType() == LLDP) {
                response.getDestination().getLldp().add(deviceDto);
            } else if (device.getType() == ARP) {
                response.getDestination().getArp().add(deviceDto);
            }
        }
    }
    return Collections.singletonList(response);
}
Also used : FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) ConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.ConnectedDeviceDto) MessageException(org.openkilda.messaging.error.MessageException) ArrayList(java.util.ArrayList) TypedConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.TypedConnectedDevicesDto) FlowConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.FlowConnectedDevicesResponse) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice)

Aggregations

FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)13 Flow (org.openkilda.model.Flow)9 List (java.util.List)6 SwitchId (org.openkilda.model.SwitchId)6 YFlow (org.openkilda.model.YFlow)6 YSubFlow (org.openkilda.model.YSubFlow)6 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)6 ArrayList (java.util.ArrayList)5 Slf4j (lombok.extern.slf4j.Slf4j)4 MessageException (org.openkilda.messaging.error.MessageException)4 Duration (java.time.Duration)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 RetryPolicy (net.jodah.failsafe.RetryPolicy)3 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)3