Search in sources :

Example 1 with SwapFlowEndpointPayload

use of org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload in project open-kilda by telstra.

the class FlowServiceImpl method swapFlowEndpoint.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<SwapFlowEndpointPayload> swapFlowEndpoint(SwapFlowEndpointPayload input) {
    final String correlationId = RequestCorrelationId.getId();
    logger.info("Swap endpoints for flow {} and {}", input.getFirstFlow().getFlowId(), input.getSecondFlow().getFlowId());
    SwapFlowEndpointRequest payload = new SwapFlowEndpointRequest(flowMapper.toSwapFlowDto(input.getFirstFlow()), flowMapper.toSwapFlowDto(input.getSecondFlow()));
    CommandMessage request = new CommandMessage(payload, System.currentTimeMillis(), correlationId, Destination.WFM);
    return messagingChannel.sendAndGet(flowHsTopic, request).thenApply(SwapFlowResponse.class::cast).thenApply(response -> new SwapFlowEndpointPayload(flowMapper.toSwapOutput(response.getFirstFlow().getPayload()), flowMapper.toSwapOutput(response.getSecondFlow().getPayload())));
}
Also used : SwapFlowEndpointPayload(org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload) SwapFlowEndpointRequest(org.openkilda.messaging.command.flow.SwapFlowEndpointRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with SwapFlowEndpointPayload

use of org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload in project open-kilda by telstra.

the class FlowControllerTest method bulkUpdateFlow.

@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void bulkUpdateFlow() throws Exception {
    MvcResult mvcResult = mockMvc.perform(post("/v2/flows/swap-endpoint").header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE).content(MAPPER.writeValueAsString(TestMessageMock.bulkFlow))).andReturn();
    MvcResult result = mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_VALUE)).andReturn();
    SwapFlowEndpointPayload response = MAPPER.readValue(result.getResponse().getContentAsString(), SwapFlowEndpointPayload.class);
    assertEquals(TestMessageMock.bulkFlow.getFirstFlow(), response.getFirstFlow());
    assertEquals(TestMessageMock.bulkFlow.getSecondFlow(), response.getSecondFlow());
}
Also used : SwapFlowEndpointPayload(org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 3 with SwapFlowEndpointPayload

use of org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload 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 4 with SwapFlowEndpointPayload

use of org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload in project open-kilda by telstra.

the class NorthboundServiceImpl method swapFlowEndpoint.

@Override
public SwapFlowEndpointPayload swapFlowEndpoint(SwapFlowPayload firstFlow, SwapFlowPayload secondFlow) {
    log.debug("Swap flow endpoints. First flow: {}. Second flow: {}", firstFlow, secondFlow);
    HttpEntity<SwapFlowEndpointPayload> httpEntity = new HttpEntity<>(new SwapFlowEndpointPayload(firstFlow, secondFlow), buildHeadersWithCorrelationId());
    return restTemplate.exchange("/api/v2/flows/swap-endpoint", HttpMethod.POST, httpEntity, SwapFlowEndpointPayload.class).getBody();
}
Also used : HttpEntity(org.springframework.http.HttpEntity) SwapFlowEndpointPayload(org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload)

Aggregations

SwapFlowEndpointPayload (org.openkilda.northbound.dto.v2.flows.SwapFlowEndpointPayload)4 Test (org.junit.Test)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 SwapFlowEndpointRequest (org.openkilda.messaging.command.flow.SwapFlowEndpointRequest)1 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)1 SwapFlowResponse (org.openkilda.messaging.info.flow.SwapFlowResponse)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 SwapFlowPayload (org.openkilda.northbound.dto.v2.flows.SwapFlowPayload)1 HttpEntity (org.springframework.http.HttpEntity)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1