Search in sources :

Example 1 with YFlowPathsResponse

use of org.openkilda.messaging.command.yflow.YFlowPathsResponse in project open-kilda by telstra.

the class YFlowReadService method getYFlowPaths.

/**
 * Gets y-flow paths.
 */
public YFlowPathsResponse getYFlowPaths(@NonNull String yFlowId) throws FlowNotFoundException {
    return transactionManager.doInTransaction(getReadOperationRetryPolicy(), () -> {
        Set<YSubFlow> subFlows = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId)).getSubFlows();
        Set<FlowPath> mainPaths = new HashSet<>();
        Set<FlowPath> protectedPaths = new HashSet<>();
        for (YSubFlow subFlow : subFlows) {
            Flow flow = subFlow.getFlow();
            mainPaths.add(flow.getForwardPath());
            if (flow.isAllocateProtectedPath() && flow.getProtectedForwardPath() != null) {
                protectedPaths.add(flow.getProtectedForwardPath());
            }
        }
        List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(mainPaths);
        PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
        PathInfoData sharedProtectedPath;
        // At least 2 paths required to calculate Y-point.
        if (protectedPaths.size() < 2) {
            sharedProtectedPath = new PathInfoData();
        } else {
            List<PathSegment> pathSegments = IntersectionComputer.calculatePathIntersectionFromSource(protectedPaths);
            sharedProtectedPath = FlowPathMapper.INSTANCE.map(pathSegments);
        }
        List<SubFlowPathDto> subFlowPathDtos = mainPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
        List<SubFlowPathDto> subFlowProtectedPathDtos = protectedPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
        return new YFlowPathsResponse(sharedPath, subFlowPathDtos, sharedProtectedPath, subFlowProtectedPathDtos);
    });
}
Also used : TransactionManager(org.openkilda.persistence.tx.TransactionManager) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) YFlowDto(org.openkilda.messaging.command.yflow.YFlowDto) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) HashSet(java.util.HashSet) Flow(org.openkilda.model.Flow) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) Duration(java.time.Duration) SubFlowsResponse(org.openkilda.messaging.command.yflow.SubFlowsResponse) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YSubFlow(org.openkilda.model.YSubFlow) ErrorType(org.openkilda.messaging.error.ErrorType) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Collectors(java.util.stream.Collectors) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) YFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.YFlowMapper) Objects(java.util.Objects) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) Collections(java.util.Collections) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) PathSegment(org.openkilda.model.PathSegment) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse)

Example 2 with YFlowPathsResponse

use of org.openkilda.messaging.command.yflow.YFlowPathsResponse in project open-kilda by telstra.

the class YFlowReadBolt method handleInput.

protected void handleInput(Tuple input) throws Exception {
    String requestId = getCommandContext().getCorrelationId();
    CommandData request = pullValue(input, FIELD_ID_PAYLOAD, CommandData.class);
    try {
        if (request instanceof YFlowsDumpRequest) {
            List<YFlowResponse> result = processYFlowDumpRequest();
            emitMessages(input, requestId, result);
        } else if (request instanceof YFlowReadRequest) {
            YFlowResponse result = processYFlowReadRequest((YFlowReadRequest) request);
            emitMessage(input, requestId, result);
        } else if (request instanceof YFlowPathsReadRequest) {
            YFlowPathsResponse result = processYFlowPathsReadRequest((YFlowPathsReadRequest) request);
            emitMessage(input, requestId, result);
        } else if (request instanceof SubFlowsReadRequest) {
            SubFlowsResponse result = processSubFlowsReadRequest((SubFlowsReadRequest) request);
            emitMessage(input, requestId, result);
        } else {
            unhandledInput(input);
        }
    } catch (MessageException e) {
        ErrorData errorData = new ErrorData(e.getErrorType(), e.getMessage(), e.getErrorDescription());
        Message message = new ErrorMessage(errorData, System.currentTimeMillis(), requestId);
        emit(input, new Values(requestId, message));
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) Values(org.apache.storm.tuple.Values) YFlowsDumpRequest(org.openkilda.messaging.command.yflow.YFlowsDumpRequest) MessageException(org.openkilda.messaging.error.MessageException) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) YFlowReadRequest(org.openkilda.messaging.command.yflow.YFlowReadRequest) SubFlowsResponse(org.openkilda.messaging.command.yflow.SubFlowsResponse) ErrorData(org.openkilda.messaging.error.ErrorData) YFlowPathsReadRequest(org.openkilda.messaging.command.yflow.YFlowPathsReadRequest) SubFlowsReadRequest(org.openkilda.messaging.command.yflow.SubFlowsReadRequest) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse)

Example 3 with YFlowPathsResponse

use of org.openkilda.messaging.command.yflow.YFlowPathsResponse in project open-kilda by telstra.

the class YFlowReadServiceTest method shouldFetchYFlowWithProtectedPaths.

@Test
public void shouldFetchYFlowWithProtectedPaths() throws FlowNotFoundException {
    // given
    String yFlowId = "test_y_flow_1";
    createYFlowWithProtected(yFlowId);
    // when
    YFlowResponse yFlowResponse = yFlowReadService.getYFlow(yFlowId);
    // then
    YFlowDto yFlow = yFlowResponse.getYFlow();
    assertNotNull(yFlow);
    assertEquals(2, yFlow.getSubFlows().size());
    // and when
    YFlowPathsResponse yFlowPathsResponse = yFlowReadService.getYFlowPaths(yFlowId);
    // then
    // Only 1 shared segment
    assertEquals(2, yFlowPathsResponse.getSharedPath().getPath().size());
    assertEquals(SWITCH_SHARED, yFlowPathsResponse.getSharedPath().getPath().get(0).getSwitchId());
    assertEquals(SWITCH_TRANSIT, yFlowPathsResponse.getSharedPath().getPath().get(1).getSwitchId());
    assertEquals(2, yFlowPathsResponse.getSubFlowPaths().size());
    // The protected paths
    assertEquals(2, yFlowPathsResponse.getSharedProtectedPath().getPath().size());
    assertEquals(SWITCH_SHARED, yFlowPathsResponse.getSharedProtectedPath().getPath().get(0).getSwitchId());
    assertEquals(SWITCH_ALT_TRANSIT, yFlowPathsResponse.getSharedProtectedPath().getPath().get(1).getSwitchId());
    assertEquals(2, yFlowPathsResponse.getSubFlowProtectedPaths().size());
}
Also used : YFlowDto(org.openkilda.messaging.command.yflow.YFlowDto) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 4 with YFlowPathsResponse

use of org.openkilda.messaging.command.yflow.YFlowPathsResponse in project open-kilda by telstra.

the class YFlowReadServiceTest method shouldFetchYFlowPaths.

@Test
public void shouldFetchYFlowPaths() throws FlowNotFoundException {
    // given
    String yFlowId = "test_y_flow_1";
    createYFlowViaTransit(yFlowId);
    // when
    YFlowPathsResponse yFlowResponse = yFlowReadService.getYFlowPaths(yFlowId);
    // then
    // Only 1 shared segment
    assertEquals(2, yFlowResponse.getSharedPath().getPath().size());
    assertEquals(SWITCH_SHARED, yFlowResponse.getSharedPath().getPath().get(0).getSwitchId());
    assertEquals(SWITCH_TRANSIT, yFlowResponse.getSharedPath().getPath().get(1).getSwitchId());
    assertEquals(2, yFlowResponse.getSubFlowPaths().size());
    // No protected paths
    assertNull(yFlowResponse.getSharedProtectedPath().getPath());
    assertEquals(0, yFlowResponse.getSubFlowProtectedPaths().size());
}
Also used : YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Aggregations

YFlowPathsResponse (org.openkilda.messaging.command.yflow.YFlowPathsResponse)4 YFlowResponse (org.openkilda.messaging.command.yflow.YFlowResponse)3 Test (org.junit.Test)2 SubFlowsResponse (org.openkilda.messaging.command.yflow.SubFlowsResponse)2 YFlowDto (org.openkilda.messaging.command.yflow.YFlowDto)2 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)2 Duration (java.time.Duration)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 NonNull (lombok.NonNull)1 Slf4j (lombok.extern.slf4j.Slf4j)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1 Values (org.apache.storm.tuple.Values)1 Message (org.openkilda.messaging.Message)1 CommandData (org.openkilda.messaging.command.CommandData)1