Search in sources :

Example 6 with YFlowResponse

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));
    }
}
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 7 with YFlowResponse

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());
}
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 8 with YFlowResponse

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);
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 9 with YFlowResponse

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);
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 10 with YFlowResponse

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);
}
Also used : YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) YFlowCreatePayload(org.openkilda.northbound.dto.v2.yflows.YFlowCreatePayload) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) YFlowSyncRequest(org.openkilda.messaging.command.yflow.YFlowSyncRequest) MessageException(org.openkilda.messaging.error.MessageException) Value(org.springframework.beans.factory.annotation.Value) CommandMessage(org.openkilda.messaging.command.CommandMessage) Service(org.springframework.stereotype.Service) YFlowsDumpRequest(org.openkilda.messaging.command.yflow.YFlowsDumpRequest) MessagingChannel(org.openkilda.northbound.messaging.MessagingChannel) SubFlowsResponse(org.openkilda.messaging.command.yflow.SubFlowsResponse) YFlow(org.openkilda.northbound.dto.v2.yflows.YFlow) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) YFlowReadRequest(org.openkilda.messaging.command.yflow.YFlowReadRequest) YFlowService(org.openkilda.northbound.service.YFlowService) ErrorType(org.openkilda.messaging.error.ErrorType) SubFlowsDump(org.openkilda.northbound.dto.v2.yflows.SubFlowsDump) YFlowDeleteRequest(org.openkilda.messaging.command.yflow.YFlowDeleteRequest) YFlowMapper(org.openkilda.northbound.converter.YFlowMapper) YFlowDump(org.openkilda.northbound.dto.v2.yflows.YFlowDump) YFlowPingResult(org.openkilda.northbound.dto.v2.yflows.YFlowPingResult) YFlowValidationRequest(org.openkilda.messaging.command.yflow.YFlowValidationRequest) RequestCorrelationId(org.openkilda.northbound.utils.RequestCorrelationId) Collectors(java.util.stream.Collectors) YFlowValidationResult(org.openkilda.northbound.dto.v2.yflows.YFlowValidationResult) YFlowPathsReadRequest(org.openkilda.messaging.command.yflow.YFlowPathsReadRequest) YFlowPatchPayload(org.openkilda.northbound.dto.v2.yflows.YFlowPatchPayload) YFlowRerouteResponse(org.openkilda.messaging.command.yflow.YFlowRerouteResponse) Slf4j(lombok.extern.slf4j.Slf4j) YFlowPingRequest(org.openkilda.messaging.command.flow.YFlowPingRequest) YFlowUpdatePayload(org.openkilda.northbound.dto.v2.yflows.YFlowUpdatePayload) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) YFlowPaths(org.openkilda.northbound.dto.v2.yflows.YFlowPaths) YFlowSyncResult(org.openkilda.northbound.dto.v2.yflows.YFlowSyncResult) YFlowRerouteResult(org.openkilda.northbound.dto.v2.yflows.YFlowRerouteResult) SubFlowsReadRequest(org.openkilda.messaging.command.yflow.SubFlowsReadRequest) YFlowPingPayload(org.openkilda.northbound.dto.v2.yflows.YFlowPingPayload) YFlowPartialUpdateRequest(org.openkilda.messaging.command.yflow.YFlowPartialUpdateRequest) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) YFlowDump(org.openkilda.northbound.dto.v2.yflows.YFlowDump) YFlowsDumpRequest(org.openkilda.messaging.command.yflow.YFlowsDumpRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

YFlowResponse (org.openkilda.messaging.command.yflow.YFlowResponse)10 CommandMessage (org.openkilda.messaging.command.CommandMessage)6 MessageException (org.openkilda.messaging.error.MessageException)5 Test (org.junit.Test)3 YFlowDto (org.openkilda.messaging.command.yflow.YFlowDto)3 YFlowPathsResponse (org.openkilda.messaging.command.yflow.YFlowPathsResponse)3 YFlowReadRequest (org.openkilda.messaging.command.yflow.YFlowReadRequest)3 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)3 SubFlowsReadRequest (org.openkilda.messaging.command.yflow.SubFlowsReadRequest)2 SubFlowsResponse (org.openkilda.messaging.command.yflow.SubFlowsResponse)2 YFlowDeleteRequest (org.openkilda.messaging.command.yflow.YFlowDeleteRequest)2 YFlowPartialUpdateRequest (org.openkilda.messaging.command.yflow.YFlowPartialUpdateRequest)2 YFlowPathsReadRequest (org.openkilda.messaging.command.yflow.YFlowPathsReadRequest)2 YFlowsDumpRequest (org.openkilda.messaging.command.yflow.YFlowsDumpRequest)2 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Values (org.apache.storm.tuple.Values)1 Message (org.openkilda.messaging.Message)1