Search in sources :

Example 1 with DeleteFlowLoopRequest

use of org.openkilda.messaging.command.flow.DeleteFlowLoopRequest in project open-kilda by telstra.

the class FlowServiceImpl method deleteFlowLoop.

@Override
public CompletableFuture<FlowLoopResponse> deleteFlowLoop(String flowId) {
    logger.info("Delete flow loop for flow {}", flowId);
    DeleteFlowLoopRequest request = new DeleteFlowLoopRequest(flowId);
    CommandMessage message = new CommandMessage(request, System.currentTimeMillis(), RequestCorrelationId.getId(), Destination.WFM);
    return messagingChannel.sendAndGet(flowHsTopic, message).thenApply(org.openkilda.messaging.info.flow.FlowResponse.class::cast).thenApply(flowMapper::toFlowLoopResponse);
}
Also used : DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with DeleteFlowLoopRequest

use of org.openkilda.messaging.command.flow.DeleteFlowLoopRequest in project open-kilda by telstra.

the class FlowUpdateHubBolt method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    currentKey = input.getStringByField(MessageKafkaTranslator.FIELD_ID_KEY);
    Object payload = input.getValueByField(FIELD_ID_PAYLOAD);
    try {
        if (payload instanceof FlowRequest) {
            FlowRequest flowRequest = (FlowRequest) payload;
            service.handleUpdateRequest(currentKey, pullContext(input), flowRequest);
        } else if (payload instanceof CreateFlowLoopRequest) {
            CreateFlowLoopRequest flowLoopRequest = (CreateFlowLoopRequest) payload;
            service.handleCreateFlowLoopRequest(currentKey, pullContext(input), flowLoopRequest);
        } else if (payload instanceof DeleteFlowLoopRequest) {
            DeleteFlowLoopRequest flowLoopRequest = (DeleteFlowLoopRequest) payload;
            service.handleDeleteFlowLoopRequest(currentKey, pullContext(input), flowLoopRequest);
        } else {
            unhandledInput(input);
        }
    } catch (DuplicateKeyException e) {
        log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
    }
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) CreateFlowLoopRequest(org.openkilda.messaging.command.flow.CreateFlowLoopRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 3 with DeleteFlowLoopRequest

use of org.openkilda.messaging.command.flow.DeleteFlowLoopRequest in project open-kilda by telstra.

the class FlowUpdateServiceTest method shouldSuccessfullyUpdateFlowDeleteFlowLoop.

@Test
public void shouldSuccessfullyUpdateFlowDeleteFlowLoop() throws DuplicateKeyException, UnknownKeyException {
    Flow origin = makeFlow();
    transactionManager.doInTransaction(() -> {
        Flow flow = repositoryFactory.createFlowRepository().findById(origin.getFlowId()).get();
        flow.setLoopSwitchId(origin.getDestSwitchId());
    });
    DeleteFlowLoopRequest request = new DeleteFlowLoopRequest(origin.getFlowId());
    FlowUpdateService service = makeService();
    service.handleDeleteFlowLoopRequest(dummyRequestKey, commandContext, request);
    verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    Set<Class> allowedRequestTypes = Sets.newHashSet(IngressFlowLoopSegmentRemoveRequest.class, TransitFlowLoopSegmentRemoveRequest.class);
    FlowSegmentRequest speakerRequest;
    while ((speakerRequest = requests.poll()) != null) {
        if (!allowedRequestTypes.contains(speakerRequest.getClass())) {
            throw new IllegalStateException(String.format("Not allowed request found %s", speakerRequest));
        }
        if (speakerRequest.isVerifyRequest()) {
            service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
        } else {
            service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
        }
    }
    Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
    assertFalse(result.isLooped());
    assertNull(result.getLoopSwitchId());
}
Also used : DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 4 with DeleteFlowLoopRequest

use of org.openkilda.messaging.command.flow.DeleteFlowLoopRequest 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 5 with DeleteFlowLoopRequest

use of org.openkilda.messaging.command.flow.DeleteFlowLoopRequest in project open-kilda by telstra.

the class FlowUpdateServiceTest method shouldFailDeleteLoopOnYSubFlow.

@Test
public void shouldFailDeleteLoopOnYSubFlow() throws DuplicateKeyException {
    Flow origin = makeFlow();
    createTestYFlowForSubFlow(origin);
    DeleteFlowLoopRequest request = new DeleteFlowLoopRequest(origin.getFlowId());
    FlowUpdateService service = makeService();
    service.handleDeleteFlowLoopRequest(dummyRequestKey, commandContext, request);
    verifyNoSpeakerInteraction(carrier);
    verifyNorthboundErrorResponse(carrier, ErrorType.REQUEST_INVALID);
}
Also used : DeleteFlowLoopRequest(org.openkilda.messaging.command.flow.DeleteFlowLoopRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Aggregations

DeleteFlowLoopRequest (org.openkilda.messaging.command.flow.DeleteFlowLoopRequest)5 Test (org.junit.Test)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 CreateFlowLoopRequest (org.openkilda.messaging.command.flow.CreateFlowLoopRequest)2 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)2 Flow (org.openkilda.model.Flow)2 Values (org.apache.storm.tuple.Values)1 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)1 MessageData (org.openkilda.messaging.MessageData)1 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)1 FlowMirrorPointCreateRequest (org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest)1 FlowMirrorPointDeleteRequest (org.openkilda.messaging.command.flow.FlowMirrorPointDeleteRequest)1 FlowPathSwapRequest (org.openkilda.messaging.command.flow.FlowPathSwapRequest)1 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)1 FlowValidationRequest (org.openkilda.messaging.command.flow.FlowValidationRequest)1 SwapFlowEndpointRequest (org.openkilda.messaging.command.flow.SwapFlowEndpointRequest)1 SubFlowsReadRequest (org.openkilda.messaging.command.yflow.SubFlowsReadRequest)1 YFlowDeleteRequest (org.openkilda.messaging.command.yflow.YFlowDeleteRequest)1 YFlowPartialUpdateRequest (org.openkilda.messaging.command.yflow.YFlowPartialUpdateRequest)1 YFlowPathsReadRequest (org.openkilda.messaging.command.yflow.YFlowPathsReadRequest)1