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);
});
}
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));
}
}
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());
}
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());
}
Aggregations