Search in sources :

Example 1 with SwapFlowResponse

use of org.openkilda.messaging.info.flow.SwapFlowResponse in project open-kilda by telstra.

the class FlowServiceTest method swapFlowEndpoint.

@Test
public void swapFlowEndpoint() throws Exception {
    String correlationId = "bulk-flow-update";
    RequestCorrelationId.create(correlationId);
    String firstFlowId = "bulk-flow-1";
    String secondFlowId = "bulk-flow-2";
    FlowEndpointV2 firstEndpoint = new FlowEndpointV2(new SwitchId("ff:00"), 1, 1, new DetectConnectedDevicesV2(false, false));
    FlowEndpointV2 secondEndpoint = new FlowEndpointV2(new SwitchId("ff:01"), 2, 2, new DetectConnectedDevicesV2(false, false));
    SwapFlowPayload firstFlowPayload = SwapFlowPayload.builder().flowId(firstFlowId).source(firstEndpoint).destination(firstEndpoint).build();
    SwapFlowPayload secondFlowPayload = SwapFlowPayload.builder().flowId(secondFlowId).source(secondEndpoint).destination(secondEndpoint).build();
    SwapFlowEndpointPayload input = new SwapFlowEndpointPayload(firstFlowPayload, secondFlowPayload);
    FlowDto firstResponse = FlowDto.builder().flowId(firstFlowId).bandwidth(10000).description(firstFlowId).state(FlowState.UP).sourceSwitch(new SwitchId("ff:00")).sourcePort(1).sourceVlan(1).destinationSwitch(new SwitchId("ff:01")).destinationPort(2).destinationVlan(2).build();
    FlowDto secondResponse = FlowDto.builder().flowId(secondFlowId).bandwidth(20000).description(secondFlowId).state(FlowState.UP).sourceSwitch(new SwitchId("ff:01")).sourcePort(2).sourceVlan(2).destinationSwitch(new SwitchId("ff:00")).destinationPort(1).destinationVlan(1).build();
    SwapFlowResponse response = new SwapFlowResponse(new FlowResponse(firstResponse), new FlowResponse(secondResponse));
    messageExchanger.mockResponse(correlationId, response);
    SwapFlowEndpointPayload result = flowService.swapFlowEndpoint(input).get();
    assertEquals(secondEndpoint, result.getFirstFlow().getDestination());
    assertEquals(firstEndpoint, result.getSecondFlow().getDestination());
}
Also used : FlowDto(org.openkilda.messaging.model.FlowDto) SwapFlowEndpointPayload(org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload) FlowEndpointV2(org.openkilda.northbound.dto.v2.flows.FlowEndpointV2) SwapFlowPayload(org.openkilda.northbound.dto.v2.flows.SwapFlowPayload) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) DetectConnectedDevicesV2(org.openkilda.northbound.dto.v2.flows.DetectConnectedDevicesV2) SwitchId(org.openkilda.model.SwitchId) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) Test(org.junit.Test)

Example 2 with SwapFlowResponse

use of org.openkilda.messaging.info.flow.SwapFlowResponse in project open-kilda by telstra.

the class OnFinishedAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowSwapEndpointsContext context, FlowSwapEndpointsFsm stateMachine) {
    log.info("Swap endpoints operation completed successfully.");
    updateFlowsStatuses(stateMachine);
    stateMachine.saveFlowActionToHistory(stateMachine.getFirstFlowId(), format("Swap endpoints with flow %s was successful", stateMachine.getSecondFlowId()));
    stateMachine.saveFlowActionToHistory(stateMachine.getSecondFlowId(), format("Swap endpoints with flow %s was successful", stateMachine.getFirstFlowId()));
    List<FlowResponse> flowResponses = stateMachine.getFlowResponses();
    SwapFlowResponse response = stateMachine.getFirstFlowId().equals(flowResponses.get(0).getPayload().getFlowId()) ? new SwapFlowResponse(flowResponses.get(0), flowResponses.get(1)) : new SwapFlowResponse(flowResponses.get(1), flowResponses.get(0));
    CommandContext commandContext = stateMachine.getCommandContext();
    return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse)

Aggregations

FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)2 SwapFlowResponse (org.openkilda.messaging.info.flow.SwapFlowResponse)2 Test (org.junit.Test)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 FlowDto (org.openkilda.messaging.model.FlowDto)1 SwitchId (org.openkilda.model.SwitchId)1 DetectConnectedDevicesV2 (org.openkilda.northbound.dto.v2.flows.DetectConnectedDevicesV2)1 FlowEndpointV2 (org.openkilda.northbound.dto.v2.flows.FlowEndpointV2)1 SwapFlowEndpointPayload (org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload)1 SwapFlowPayload (org.openkilda.northbound.dto.v2.flows.SwapFlowPayload)1 CommandContext (org.openkilda.wfm.CommandContext)1