Search in sources :

Example 1 with YFlowsDumpRequest

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

the class RouterBolt method handleInput.

@Override
protected void handleInput(Tuple input) {
    if (active) {
        String key = input.getStringByField(FIELD_ID_KEY);
        if (StringUtils.isBlank(key)) {
            // TODO: the key must be unique, but the correlationId comes in from outside and we can't guarantee that.
            // IMPORTANT: Storm may initiate reprocessing of the same tuple (e.g. in the case of timeout) and
            // cause creating multiple FSMs for the same tuple. This must be avoided.
            // As for now tuples are routed by the key field, and services can check FSM uniqueness.
            key = getCommandContext().getCorrelationId();
        }
        CommandMessage message = (CommandMessage) input.getValueByField(FIELD_ID_PAYLOAD);
        MessageData data = message.getData();
        if (data instanceof FlowRequest) {
            FlowRequest request = (FlowRequest) data;
            log.debug("Received request {} with key {}", request, key);
            Values values = new Values(key, request.getFlowId(), request);
            switch(request.getType()) {
                case CREATE:
                    emitWithContext(ROUTER_TO_FLOW_CREATE_HUB.name(), input, values);
                    break;
                case UPDATE:
                    emitWithContext(ROUTER_TO_FLOW_UPDATE_HUB.name(), input, values);
                    break;
                default:
                    throw new UnsupportedOperationException(format("Flow operation %s is not supported", request.getType()));
            }
        } else if (data instanceof FlowRerouteRequest) {
            FlowRerouteRequest rerouteRequest = (FlowRerouteRequest) data;
            log.debug("Received a reroute request {}/{} with key {}. MessageId {}", rerouteRequest.getFlowId(), rerouteRequest.getAffectedIsl(), key, input.getMessageId());
            Values values = new Values(key, rerouteRequest.getFlowId(), data);
            emitWithContext(ROUTER_TO_FLOW_REROUTE_HUB.name(), input, values);
        } else if (data instanceof FlowDeleteRequest) {
            FlowDeleteRequest deleteRequest = (FlowDeleteRequest) data;
            log.debug("Received a delete request {} with key {}. MessageId {}", deleteRequest.getFlowId(), key, input.getMessageId());
            Values values = new Values(key, deleteRequest.getFlowId(), data);
            emitWithContext(ROUTER_TO_FLOW_DELETE_HUB.name(), input, values);
        } else if (data instanceof FlowPathSwapRequest) {
            FlowPathSwapRequest pathSwapRequest = (FlowPathSwapRequest) data;
            log.debug("Received a path swap request {} with key {}. MessageId {}", pathSwapRequest.getFlowId(), key, input.getMessageId());
            Values values = new Values(key, pathSwapRequest.getFlowId(), data);
            emitWithContext(ROUTER_TO_FLOW_PATH_SWAP_HUB.name(), input, values);
        } else if (data instanceof SwapFlowEndpointRequest) {
            log.debug("Received a swap flow endpoints request with key {}. MessageId {}", key, input.getMessageId());
            emitWithContext(ROUTER_TO_FLOW_SWAP_ENDPOINTS_HUB.name(), input, new Values(key, data));
        } else if (data instanceof CreateFlowLoopRequest) {
            log.debug("Received a create flow loop request with key {}. MessageId {}", key, input.getMessageId());
            CreateFlowLoopRequest request = (CreateFlowLoopRequest) data;
            emitWithContext(ROUTER_TO_FLOW_UPDATE_HUB.name(), input, new Values(key, request.getFlowId(), data));
        } else if (data instanceof DeleteFlowLoopRequest) {
            log.debug("Received a delete flow loop request with key {}. MessageId {}", key, input.getMessageId());
            DeleteFlowLoopRequest request = (DeleteFlowLoopRequest) data;
            emitWithContext(ROUTER_TO_FLOW_UPDATE_HUB.name(), input, new Values(key, request.getFlowId(), data));
        } else if (data instanceof FlowMirrorPointCreateRequest) {
            log.debug("Received a flow mirror point create request with key {}. MessageId {}", key, input.getMessageId());
            FlowMirrorPointCreateRequest request = (FlowMirrorPointCreateRequest) data;
            emitWithContext(ROUTER_TO_FLOW_CREATE_MIRROR_POINT_HUB.name(), input, new Values(key, request.getFlowId(), data));
        } else if (data instanceof FlowMirrorPointDeleteRequest) {
            log.debug("Received a flow mirror point delete request with key {}. MessageId {}", key, input.getMessageId());
            FlowMirrorPointDeleteRequest request = (FlowMirrorPointDeleteRequest) data;
            emitWithContext(ROUTER_TO_FLOW_DELETE_MIRROR_POINT_HUB.name(), input, new Values(key, request.getFlowId(), data));
        } else if (data instanceof FlowValidationRequest) {
            log.debug("Received a flow validation request with key {}. MessageId {}", key, input.getMessageId());
            FlowValidationRequest request = (FlowValidationRequest) data;
            emitWithContext(ROUTER_TO_FLOW_VALIDATION_HUB.name(), input, new Values(key, request.getFlowId(), data));
        } else if (data instanceof YFlowRequest) {
            YFlowRequest request = (YFlowRequest) data;
            log.debug("Received request {} with key {}", request, key);
            Values values = new Values(key, request.getYFlowId(), request);
            switch(request.getType()) {
                case CREATE:
                    emitWithContext(ROUTER_TO_YFLOW_CREATE_HUB.name(), input, values);
                    break;
                case UPDATE:
                    emitWithContext(ROUTER_TO_YFLOW_UPDATE_HUB.name(), input, values);
                    break;
                default:
                    throw new UnsupportedOperationException(format("Y-flow operation %s is not supported", request.getType()));
            }
        } else if (data instanceof YFlowPartialUpdateRequest) {
            YFlowPartialUpdateRequest request = (YFlowPartialUpdateRequest) data;
            log.debug("Received a y-flow partial update request {} with key {}", request, key);
            emitWithContext(ROUTER_TO_YFLOW_UPDATE_HUB.name(), input, new Values(key, request.getYFlowId(), data));
        } else if (data instanceof YFlowRerouteRequest) {
            YFlowRerouteRequest request = (YFlowRerouteRequest) data;
            log.debug("Received a y-flow reroute request {} with key {}", data, key);
            emitWithContext(ROUTER_TO_YFLOW_REROUTE_HUB.name(), input, new Values(key, request.getYFlowId(), data));
        } else if (data instanceof YFlowDeleteRequest) {
            YFlowDeleteRequest request = (YFlowDeleteRequest) data;
            log.debug("Received a y-flow delete request {} with key {}", request, key);
            emitWithContext(ROUTER_TO_YFLOW_DELETE_HUB.name(), input, new Values(key, request.getYFlowId(), data));
        } else if (data instanceof YFlowsDumpRequest) {
            log.debug("Received a y-flow dump request {} with key {}", data, key);
            emitWithContext(ROUTER_TO_YFLOW_READ.name(), input, new Values(key, data));
        } else if (data instanceof YFlowReadRequest) {
            log.debug("Received a y-flow read request {} with key {}", data, key);
            emitWithContext(ROUTER_TO_YFLOW_READ.name(), input, new Values(key, data));
        } else if (data instanceof YFlowPathsReadRequest) {
            log.debug("Received a y-flow read path request {} with key {}", data, key);
            emitWithContext(ROUTER_TO_YFLOW_READ.name(), input, new Values(key, data));
        } else if (data instanceof SubFlowsReadRequest) {
            log.debug("Received a y-flow sub-flows request {} with key {}", data, key);
            emitWithContext(ROUTER_TO_YFLOW_READ.name(), input, new Values(key, data));
        } else if (data instanceof YFlowValidationRequest) {
            YFlowValidationRequest request = (YFlowValidationRequest) data;
            log.debug("Received a y-flow validation request {} with key {}", request, key);
            emitWithContext(ROUTER_TO_YFLOW_VALIDATION_HUB.name(), input, new Values(key, request.getYFlowId(), data));
        } else if (data instanceof YFlowSyncRequest) {
            YFlowSyncRequest request = (YFlowSyncRequest) data;
            log.debug("Received a y-flow synchronization request {} with key {}", request, key);
            YFlowRerouteRequest rerouteRequest = new YFlowRerouteRequest(request.getYFlowId(), emptySet(), true, "initiated via synchronization request", false);
            emitWithContext(ROUTER_TO_YFLOW_REROUTE_HUB.name(), input, new Values(key, rerouteRequest.getYFlowId(), rerouteRequest));
        } else {
            unhandledInput(input);
        }
    }
}
Also used : YFlowSyncRequest(org.openkilda.messaging.command.yflow.YFlowSyncRequest) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowDeleteRequest(org.openkilda.messaging.command.flow.FlowDeleteRequest) YFlowDeleteRequest(org.openkilda.messaging.command.yflow.YFlowDeleteRequest) CreateFlowLoopRequest(org.openkilda.messaging.command.flow.CreateFlowLoopRequest) Values(org.apache.storm.tuple.Values) SwapFlowEndpointRequest(org.openkilda.messaging.command.flow.SwapFlowEndpointRequest) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) YFlowsDumpRequest(org.openkilda.messaging.command.yflow.YFlowsDumpRequest) YFlowDeleteRequest(org.openkilda.messaging.command.yflow.YFlowDeleteRequest) FlowPathSwapRequest(org.openkilda.messaging.command.flow.FlowPathSwapRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) YFlowPartialUpdateRequest(org.openkilda.messaging.command.yflow.YFlowPartialUpdateRequest) FlowMirrorPointDeleteRequest(org.openkilda.messaging.command.flow.FlowMirrorPointDeleteRequest) DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) MessageData(org.openkilda.messaging.MessageData) FlowMirrorPointCreateRequest(org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage) YFlowValidationRequest(org.openkilda.messaging.command.yflow.YFlowValidationRequest) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) YFlowValidationRequest(org.openkilda.messaging.command.yflow.YFlowValidationRequest) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) YFlowReadRequest(org.openkilda.messaging.command.yflow.YFlowReadRequest) YFlowPathsReadRequest(org.openkilda.messaging.command.yflow.YFlowPathsReadRequest) SubFlowsReadRequest(org.openkilda.messaging.command.yflow.SubFlowsReadRequest)

Example 2 with YFlowsDumpRequest

use of org.openkilda.messaging.command.yflow.YFlowsDumpRequest 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 YFlowsDumpRequest

use of org.openkilda.messaging.command.yflow.YFlowsDumpRequest 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

SubFlowsReadRequest (org.openkilda.messaging.command.yflow.SubFlowsReadRequest)3 YFlowPathsReadRequest (org.openkilda.messaging.command.yflow.YFlowPathsReadRequest)3 YFlowReadRequest (org.openkilda.messaging.command.yflow.YFlowReadRequest)3 YFlowsDumpRequest (org.openkilda.messaging.command.yflow.YFlowsDumpRequest)3 Values (org.apache.storm.tuple.Values)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)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 YFlowPathsResponse (org.openkilda.messaging.command.yflow.YFlowPathsResponse)2 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)2 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)2 YFlowResponse (org.openkilda.messaging.command.yflow.YFlowResponse)2 YFlowSyncRequest (org.openkilda.messaging.command.yflow.YFlowSyncRequest)2 YFlowValidationRequest (org.openkilda.messaging.command.yflow.YFlowValidationRequest)2 MessageException (org.openkilda.messaging.error.MessageException)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Message (org.openkilda.messaging.Message)1