Search in sources :

Example 31 with FlowPayload

use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.

the class FlowServiceImpl method getFlows.

/**
 * {@inheritDoc}
 */
@Override
public List<FlowPayload> getFlows(final String correlationId) {
    LOGGER.debug("\n\n\nGet flows: ENTER {}={}\n", CORRELATION_ID, correlationId);
    // TODO: why does FlowsGetRequest use empty FlowIdStatusPayload? Delete if not needed.
    FlowsGetRequest data = new FlowsGetRequest(new FlowIdStatusPayload());
    CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId, Destination.WFM);
    messageConsumer.clear();
    messageProducer.send(topic, request);
    Message message = (Message) messageConsumer.poll(correlationId);
    FlowsResponse response = (FlowsResponse) validateInfoMessage(request, message, correlationId);
    List<FlowPayload> result = Converter.buildFlowsPayloadByFlows(response.getPayload());
    logger.debug("\nGet flows: EXIT {}={}, num_flows {}\n\n\n", CORRELATION_ID, correlationId, result.size());
    return result;
}
Also used : FlowsGetRequest(org.openkilda.messaging.command.flow.FlowsGetRequest) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) FlowsResponse(org.openkilda.messaging.info.flow.FlowsResponse) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 32 with FlowPayload

use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.

the class FlowServiceImpl method deleteFlows.

/**
 * {@inheritDoc}
 */
@Override
public List<FlowPayload> deleteFlows(final String correlationId) {
    LOGGER.debug("\n\nDELETE ALL FLOWS: ENTER {}={}\n", CORRELATION_ID, correlationId);
    ArrayList<FlowPayload> result = new ArrayList<>();
    // TODO: Need a getFlowIDs .. since that is all we need
    List<FlowPayload> flows = this.getFlows(correlationId + "-GET");
    messageConsumer.clear();
    // Send all the requests first
    ArrayList<CommandMessage> requests = new ArrayList<>();
    for (int i = 0; i < flows.size(); i++) {
        String cid = correlationId + "-" + i;
        FlowPayload flow = flows.get(i);
        requests.add(_sendDeleteFlow(flow.getId(), cid));
    }
    // Now wait for the responses.
    for (int i = 0; i < flows.size(); i++) {
        String cid = correlationId + "-" + i;
        result.add(_deleteFlowRespone(cid, requests.get(i)));
    }
    LOGGER.debug("\n\nDELETE ALL FLOWS: EXIT {}={}\n", CORRELATION_ID, correlationId);
    return result;
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) ArrayList(java.util.ArrayList) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 33 with FlowPayload

use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.

the class FlowControllerTest method createFlow.

@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void createFlow() throws Exception {
    MvcResult result = mockMvc.perform(put("/flows").header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE).content(MAPPER.writeValueAsString(TestMessageMock.flow))).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
    System.out.println("RESPONSE: " + result.getResponse().getContentAsString());
    FlowPayload response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowPayload.class);
    assertEquals(TestMessageMock.flow, response);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 34 with FlowPayload

use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.

the class FlowControllerTest method updateFlow.

@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void updateFlow() throws Exception {
    MvcResult result = mockMvc.perform(put("/flows/{flow-id}", TestMessageMock.FLOW_ID).header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE).content(MAPPER.writeValueAsString(TestMessageMock.flow))).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
    FlowPayload response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowPayload.class);
    assertEquals(TestMessageMock.flow, response);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 35 with FlowPayload

use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.

the class FlowCrudSteps method eachFlowCanNotBeReadFromTopologyEngine.

@And("^each flow can not be read from TopologyEngine$")
public void eachFlowCanNotBeReadFromTopologyEngine() {
    for (FlowPayload flow : flows) {
        ImmutablePair<Flow, Flow> result = Failsafe.with(retryPolicy.abortIf(Objects::isNull)).get(() -> topologyEngineService.getFlow(flow.getId()));
        assertNull(format("The flow '%s' exists.", flow.getId()), result);
    }
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Objects(java.util.Objects) Flow(org.openkilda.messaging.model.Flow) And(cucumber.api.java.en.And)

Aggregations

FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)48 Test (org.junit.Test)14 FlowEndpointPayload (org.openkilda.messaging.payload.flow.FlowEndpointPayload)9 Then (cucumber.api.java.en.Then)7 When (cucumber.api.java.en.When)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 DefaultParameters.northboundEndpoint (org.openkilda.DefaultParameters.northboundEndpoint)6 DefaultParameters.topologyEndpoint (org.openkilda.DefaultParameters.topologyEndpoint)6 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)6 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)6 HttpHeaders (org.springframework.http.HttpHeaders)6 ResponseEntity (org.springframework.http.ResponseEntity)6 WithMockUser (org.springframework.security.test.context.support.WithMockUser)6 MvcResult (org.springframework.test.web.servlet.MvcResult)6 And (cucumber.api.java.en.And)5 Client (javax.ws.rs.client.Client)5 Response (javax.ws.rs.core.Response)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3