Search in sources :

Example 1 with YFlowRerouteResponse

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

the class OnSubFlowAllocatedAction method buildRerouteResponseMessage.

private Message buildRerouteResponseMessage(YFlowRerouteFsm stateMachine) {
    String yFlowId = stateMachine.getYFlowId();
    List<Long> oldFlowPathCookies = stateMachine.getOldYFlowPathCookies();
    List<FlowPath> flowPaths = transactionManager.doInTransaction(() -> {
        YFlow yflow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
        SwitchId sharedSwitchId = yflow.getSharedEndpoint().getSwitchId();
        List<FlowPath> paths = new ArrayList<>();
        for (YSubFlow subFlow : yflow.getSubFlows()) {
            Flow flow = subFlow.getFlow();
            FlowPath flowPath = flow.getPaths().stream().filter(path -> sharedSwitchId.equals(path.getSrcSwitchId()) && !path.isProtected() && !oldFlowPathCookies.contains(path.getCookie().getValue())).findFirst().orElse(sharedSwitchId.equals(flow.getForwardPath().getSrcSwitchId()) ? flow.getForwardPath() : flow.getReversePath());
            paths.add(flowPath);
        }
        return paths;
    });
    List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(flowPaths);
    PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
    List<SubFlowPathDto> subFlowPathDtos = flowPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).sorted(Comparator.comparing(SubFlowPathDto::getFlowId)).collect(Collectors.toList());
    PathInfoData oldSharedPath = stateMachine.getOldSharedPath();
    List<SubFlowPathDto> oldSubFlowPathDtos = stateMachine.getOldSubFlowPathDtos();
    YFlowRerouteResponse response = new YFlowRerouteResponse(sharedPath, subFlowPathDtos, !(sharedPath.equals(oldSharedPath) && subFlowPathDtos.equals(oldSubFlowPathDtos)));
    CommandContext commandContext = stateMachine.getCommandContext();
    return new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId());
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) 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) YFlowRerouteResponse(org.openkilda.messaging.command.yflow.YFlowRerouteResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowPath(org.openkilda.model.FlowPath) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto)

Aggregations

ArrayList (java.util.ArrayList)1 SubFlowPathDto (org.openkilda.messaging.command.yflow.SubFlowPathDto)1 YFlowRerouteResponse (org.openkilda.messaging.command.yflow.YFlowRerouteResponse)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)1 Flow (org.openkilda.model.Flow)1 FlowPath (org.openkilda.model.FlowPath)1 PathSegment (org.openkilda.model.PathSegment)1 SwitchId (org.openkilda.model.SwitchId)1 YFlow (org.openkilda.model.YFlow)1 YSubFlow (org.openkilda.model.YSubFlow)1 CommandContext (org.openkilda.wfm.CommandContext)1 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)1