Search in sources :

Example 1 with FlowRequest

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

the class FlowServiceImpl method updateFlow.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<FlowResponsePayload> updateFlow(final FlowUpdatePayload request) {
    logger.info("Update flow request for flow {}", request.getId());
    final String correlationId = RequestCorrelationId.getId();
    FlowRequest updateRequest;
    try {
        updateRequest = flowMapper.toFlowUpdateRequest(request);
    } catch (IllegalArgumentException e) {
        logger.error("Can not parse arguments: {}", e.getMessage(), e);
        throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.DATA_INVALID, e.getMessage(), "Can not parse arguments of the update flow request");
    }
    CommandMessage command = new CommandMessage(updateRequest, System.currentTimeMillis(), correlationId, Destination.WFM);
    return messagingChannel.sendAndGet(flowHsTopic, command).thenApply(FlowResponse.class::cast).thenApply(FlowResponse::getPayload).thenApply(flowMapper::toFlowResponseOutput);
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) MessageException(org.openkilda.messaging.error.MessageException) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with FlowRequest

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

the class FlowMapper method toFlowCreateRequest.

/**
 * Map FlowCreatePayload.
 *
 * @param source {@link FlowCreatePayload} instance.
 * @return {@link FlowRequest} instance.
 */
public FlowRequest toFlowCreateRequest(FlowCreatePayload source) {
    FlowRequest target = toFlowRequest(source).toBuilder().diverseFlowId(source.getDiverseFlowId()).type(Type.CREATE).build();
    if (source.getSource().getDetectConnectedDevices() != null) {
        DetectConnectedDevicesPayload srcDevs = source.getSource().getDetectConnectedDevices();
        target.getDetectConnectedDevices().setSrcArp(srcDevs.isArp());
        target.getDetectConnectedDevices().setSrcLldp(srcDevs.isLldp());
    }
    if (source.getDestination().getDetectConnectedDevices() != null) {
        DetectConnectedDevicesPayload dstDevs = source.getDestination().getDetectConnectedDevices();
        target.getDetectConnectedDevices().setDstArp(dstDevs.isArp());
        target.getDetectConnectedDevices().setDstLldp(dstDevs.isLldp());
    }
    return target;
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) DetectConnectedDevicesPayload(org.openkilda.messaging.payload.flow.DetectConnectedDevicesPayload)

Example 3 with FlowRequest

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

the class FlowServiceImpl method createFlow.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<FlowResponsePayload> createFlow(FlowCreatePayload request) {
    logger.info("Create flow: {}", request);
    final String correlationId = RequestCorrelationId.getId();
    FlowRequest flowRequest;
    try {
        flowRequest = flowMapper.toFlowCreateRequest(request);
    } catch (IllegalArgumentException e) {
        logger.error("Can not parse arguments: {}", e.getMessage(), e);
        throw new MessageException(correlationId, System.currentTimeMillis(), ErrorType.DATA_INVALID, e.getMessage(), "Can not parse arguments of the create flow request");
    }
    CommandMessage command = new CommandMessage(flowRequest, System.currentTimeMillis(), correlationId, Destination.WFM);
    return messagingChannel.sendAndGet(flowHsTopic, command).thenApply(FlowResponse.class::cast).thenApply(FlowResponse::getPayload).thenApply(flowMapper::toFlowResponseOutput);
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) MessageException(org.openkilda.messaging.error.MessageException) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 4 with FlowRequest

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

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

the class FlowCreateServiceTest method shouldCreateFlowWithTransitSwitches.

@Test
public void shouldCreateFlowWithTransitSwitches() throws Exception {
    FlowRequest request = makeRequest().flowId("test_successful_flow_id").build();
    preparePathComputation(request.getFlowId(), make3SwitchesPathPair());
    testHappyPath(request, "successful_flow_create");
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) Test(org.junit.Test)

Aggregations

FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)45 Test (org.junit.Test)28 Flow (org.openkilda.model.Flow)25 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)12 FlowEndpoint (org.openkilda.model.FlowEndpoint)6 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 MessageException (org.openkilda.messaging.error.MessageException)5 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)5 SwapFlowResponse (org.openkilda.messaging.info.flow.SwapFlowResponse)4 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)4 CommandContext (org.openkilda.wfm.CommandContext)4 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)4 DetectConnectedDevicesDto (org.openkilda.messaging.model.DetectConnectedDevicesDto)3 Sets (com.google.common.collect.Sets)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Ignore (org.junit.Ignore)2