Search in sources :

Example 21 with FlowPayload

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

the class FlowControllerTest method getFlows.

@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void getFlows() throws Exception {
    MvcResult result = mockMvc.perform(get("/flows", TestMessageMock.FLOW_ID).header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
    List<FlowPayload> response = MAPPER.readValue(result.getResponse().getContentAsString(), new TypeReference<List<FlowPayload>>() {
    });
    assertEquals(Collections.singletonList(TestMessageMock.flow), response);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) List(java.util.List) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 22 with FlowPayload

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

the class FlowUtils method putFlow.

/**
 * Creates flow through Northbound service.
 *
 * @param payload flow JSON data
 * @return The JSON document of the created flow
 */
public static FlowPayload putFlow(final FlowPayload payload) {
    System.out.println("\n==> Northbound Create Flow");
    long current = System.currentTimeMillis();
    Client client = clientFactory();
    Response response = client.target(northboundEndpoint).path("/api/v1/flows").request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, authHeaderValue).header(Utils.CORRELATION_ID, String.valueOf(System.currentTimeMillis())).put(Entity.json(payload));
    System.out.println(format("===> Request Payload = %s", Entity.json(payload).getEntity()));
    System.out.println(format("===> Response = %s", response.toString()));
    System.out.println(format("===> Northbound Create Flow Time: %,.3f", getTimeDuration(current)));
    int responseCode = response.getStatus();
    if (responseCode == 200) {
        FlowPayload flow = response.readEntity(FlowPayload.class);
        System.out.println(format("====> Northbound Create Flow = %s", flow));
        return flow;
    } else {
        System.out.println(format("====> Error: Northbound Create Flow = %s", response.readEntity(MessageError.class)));
        return null;
    }
}
Also used : Response(javax.ws.rs.core.Response) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Client(javax.ws.rs.client.Client) DefaultParameters.topologyEndpoint(org.openkilda.DefaultParameters.topologyEndpoint) DefaultParameters.northboundEndpoint(org.openkilda.DefaultParameters.northboundEndpoint)

Example 23 with FlowPayload

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

the class FlowUtils method getFlowDump.

/**
 * Gets flows dump through Northbound service.
 *
 * @return The JSON document of the dump flows
 */
public static List<FlowPayload> getFlowDump() {
    System.out.println("\n==> Northbound Get Flow Dump");
    long current = System.currentTimeMillis();
    Client client = clientFactory();
    Response response = client.target(northboundEndpoint).path("/api/v1/flows").request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, authHeaderValue).header(Utils.CORRELATION_ID, String.valueOf(System.currentTimeMillis())).get();
    System.out.println(format("===> Response = %s", response.toString()));
    System.out.println(format("===> Northbound Get Flow Dump Time: %,.3f", getTimeDuration(current)));
    int responseCode = response.getStatus();
    if (responseCode == 200) {
        List<FlowPayload> flows = response.readEntity(new GenericType<List<FlowPayload>>() {
        });
        System.out.println(format("====> Northbound Get Flow Dump = %d", flows.size()));
        return flows;
    } else {
        System.out.println(format("====> Error: Northbound Get Flow Dump = %s", response.readEntity(MessageError.class)));
        return Collections.emptyList();
    }
}
Also used : Response(javax.ws.rs.core.Response) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) ArrayList(java.util.ArrayList) List(java.util.List) Client(javax.ws.rs.client.Client) DefaultParameters.topologyEndpoint(org.openkilda.DefaultParameters.topologyEndpoint) DefaultParameters.northboundEndpoint(org.openkilda.DefaultParameters.northboundEndpoint)

Example 24 with FlowPayload

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

the class FlowUtils method deleteFlow.

/**
 * Deletes flow through Northbound service.
 *
 * @param flowId flow id
 * @return The JSON document of the specified flow
 */
public static FlowPayload deleteFlow(final String flowId) {
    System.out.println("\n==> Northbound Delete Flow");
    long current = System.currentTimeMillis();
    Client client = clientFactory();
    Response response = client.target(northboundEndpoint).path("/api/v1/flows").path("{flowid}").resolveTemplate("flowid", flowId).request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, authHeaderValue).header(Utils.CORRELATION_ID, String.valueOf(System.currentTimeMillis())).delete();
    System.out.println(format("===> Response = %s", response.toString()));
    System.out.println(format("===> Northbound Delete Flow Time: %,.3f", getTimeDuration(current)));
    int responseCode = response.getStatus();
    if (responseCode == 200) {
        FlowPayload flow = response.readEntity(FlowPayload.class);
        System.out.println(format("====> Northbound Delete Flow = %s", flow));
        return flow;
    } else {
        System.out.println(format("====> Error: Northbound Delete Flow = %s", response.readEntity(MessageError.class)));
        return null;
    }
}
Also used : Response(javax.ws.rs.core.Response) FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) Client(javax.ws.rs.client.Client) DefaultParameters.topologyEndpoint(org.openkilda.DefaultParameters.topologyEndpoint) DefaultParameters.northboundEndpoint(org.openkilda.DefaultParameters.northboundEndpoint)

Example 25 with FlowPayload

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

the class FlowServiceImplTest method deleteFlow.

@Test
public void deleteFlow() throws Exception {
    FlowEndpointPayload firstEndpoint = new FlowEndpointPayload(srcSwitchId, 10, 100);
    FlowEndpointPayload secondEndpoint = new FlowEndpointPayload(dstSwitchId, 20, 100);
    FlowPayload flowPayload = new FlowPayload(flowId, 0L, secondEndpoint, firstEndpoint, 10000L, "", "", OutputVlanType.NONE);
    FlowIdStatusPayload flowIdStatusPayload = new FlowIdStatusPayload(flowId);
    flowService.createFlow(flowPayload, DEFAULT_CORRELATION_ID);
    flowService.deleteFlow(flowIdStatusPayload, DEFAULT_CORRELATION_ID);
    Set<Flow> flows = flowRepository.findByFlowId(flowId);
    assertNotNull(flows);
    assertTrue(flows.isEmpty());
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) FlowEndpointPayload(org.openkilda.messaging.payload.flow.FlowEndpointPayload) Flow(org.openkilda.topology.domain.Flow) Test(org.junit.Test)

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