use of org.openkilda.messaging.command.yflow.YFlowResponse 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.YFlowResponse 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.YFlowResponse in project open-kilda by telstra.
the class YFlowServiceImpl method updateYFlow.
@Override
public CompletableFuture<YFlow> updateYFlow(String yFlowId, YFlowUpdatePayload updatePayload) {
log.debug("Processing y-flow update: {}", updatePayload);
String correlationId = RequestCorrelationId.getId();
YFlowRequest flowRequest;
try {
flowRequest = flowMapper.toYFlowUpdateRequest(yFlowId, updatePayload);
} catch (IllegalArgumentException e) {
throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.DATA_INVALID, e.getMessage(), "Can not parse arguments of the create y-flow request");
}
CommandMessage command = new CommandMessage(flowRequest, System.currentTimeMillis(), correlationId);
return messagingChannel.sendAndGet(flowHsTopic, command).thenApply(YFlowResponse.class::cast).thenApply(YFlowResponse::getYFlow).thenApply(flowMapper::toYFlow);
}
use of org.openkilda.messaging.command.yflow.YFlowResponse in project open-kilda by telstra.
the class YFlowServiceImpl method createYFlow.
@Override
public CompletableFuture<YFlow> createYFlow(YFlowCreatePayload createPayload) {
log.debug("Processing y-flow creation: {}", createPayload);
String correlationId = RequestCorrelationId.getId();
YFlowRequest flowRequest;
try {
flowRequest = flowMapper.toYFlowCreateRequest(createPayload);
} catch (IllegalArgumentException e) {
throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.DATA_INVALID, e.getMessage(), "Can not parse arguments of the create y-flow request");
}
CommandMessage command = new CommandMessage(flowRequest, System.currentTimeMillis(), correlationId);
return messagingChannel.sendAndGet(flowHsTopic, command).thenApply(YFlowResponse.class::cast).thenApply(YFlowResponse::getYFlow).thenApply(flowMapper::toYFlow);
}
use of org.openkilda.messaging.command.yflow.YFlowResponse in project open-kilda by telstra.
the class YFlowServiceImpl method dumpYFlows.
@Override
public CompletableFuture<YFlowDump> dumpYFlows() {
log.debug("Processing getting all y-flows");
YFlowsDumpRequest dumpRequest = new YFlowsDumpRequest();
CommandMessage request = new CommandMessage(dumpRequest, System.currentTimeMillis(), RequestCorrelationId.getId());
return messagingChannel.sendAndGetChunked(flowHsTopic, request).thenApply(result -> result.stream().map(YFlowResponse.class::cast).map(YFlowResponse::getYFlow).map(flowMapper::toYFlow).collect(Collectors.toList())).thenApply(YFlowDump::new);
}
Aggregations