Search in sources :

Example 26 with FlowIdStatusPayload

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

the class FlowStatusResponseTest method testJsonSerialization.

@Test
public void testJsonSerialization() throws IOException {
    /*
         * Start with serializing to JSON.
         * Then re-populate from JSON.
         */
    InfoMessage msg = new InfoMessage(new FlowStatusResponse(new FlowIdStatusPayload("FLOW", FlowState.UP)), 10L, "CORRELATION", Destination.NORTHBOUND);
    InfoMessage fromJson = MAPPER.readValue(json, InfoMessage.class);
    FlowStatusResponse fsrJson = (FlowStatusResponse) fromJson.getData();
    FlowStatusResponse fsrObj = (FlowStatusResponse) msg.getData();
    Assert.assertEquals(fsrJson.getPayload().getId(), fsrObj.getPayload().getId());
    Assert.assertEquals(fsrJson.getPayload().getStatus(), fsrObj.getPayload().getStatus());
    Assert.assertEquals(fsrJson.getPayload().getStatus(), FlowState.UP);
    Assert.assertEquals(fromJson.getCorrelationId(), msg.getCorrelationId());
    System.out.println("JSON: " + MAPPER.writeValueAsString(msg));
}
Also used : FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) InfoMessage(org.openkilda.messaging.info.InfoMessage) Test(org.junit.Test)

Example 27 with FlowIdStatusPayload

use of org.openkilda.messaging.payload.flow.FlowIdStatusPayload 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 28 with FlowIdStatusPayload

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

the class FlowServiceImpl method flowPushUnpush.

/**
 * There are only minor differences between push and unpush .. this utility function helps
 */
private BatchResults flowPushUnpush(List<FlowInfoData> externalFlows, String correlationId, FlowOperation op) {
    LOGGER.debug("Flow {}: {}={}", op, CORRELATION_ID, correlationId);
    LOGGER.debug("Size of list: {}", externalFlows.size());
    // First, send them all, then wait for all the responses.
    // Send the command to both Flow Topology and to TE
    messageConsumer.clear();
    // used for error reporting, if needed
    ArrayList<InfoMessage> flowRequests = new ArrayList<>();
    // used for error reporting, if needed
    ArrayList<InfoMessage> teRequests = new ArrayList<>();
    for (int i = 0; i < externalFlows.size(); i++) {
        FlowInfoData data = externalFlows.get(i);
        // <-- this is what determines PUSH / UNPUSH
        data.setOperation(op);
        String flowCorrelation = correlationId + "-FLOW-" + i;
        InfoMessage flowRequest = new InfoMessage(data, System.currentTimeMillis(), flowCorrelation, Destination.WFM);
        flowRequests.add(flowRequest);
        messageProducer.send(topic, flowRequest);
        String teCorrelation = correlationId + "-TE-" + i;
        InfoMessage teRequest = new InfoMessage(data, System.currentTimeMillis(), teCorrelation, Destination.TOPOLOGY_ENGINE);
        teRequests.add(teRequest);
        messageProducer.send(topoEngTopic, teRequest);
    }
    int flow_success = 0;
    int flow_failure = 0;
    int te_success = 0;
    int te_failure = 0;
    List<String> msgs = new ArrayList<>();
    msgs.add("Total Flows Received: " + externalFlows.size());
    for (int i = 0; i < externalFlows.size(); i++) {
        String flowCorrelation = correlationId + "-FLOW-" + i;
        String teCorrelation = correlationId + "-TE-" + i;
        FlowState expectedState = (op == FlowOperation.PUSH) ? FlowState.UP : FlowState.DOWN;
        try {
            Message flowMessage = (Message) messageConsumer.poll(flowCorrelation);
            FlowStatusResponse response = (FlowStatusResponse) validateInfoMessage(flowRequests.get(i), flowMessage, correlationId);
            FlowIdStatusPayload status = response.getPayload();
            if (status.getStatus() == expectedState) {
                flow_success++;
            } else {
                msgs.add("FAILURE (FlowTopo): Flow " + status.getId() + " NOT in " + expectedState + " state: state = " + status.getStatus());
                flow_failure++;
            }
        } catch (Exception e) {
            msgs.add("EXCEPTION in Flow Topology Response: " + e.getMessage());
            flow_failure++;
        }
        try {
            // TODO: this code block is mostly the same as the previous: consolidate.
            Message teMessage = (Message) messageConsumer.poll(teCorrelation);
            FlowStatusResponse response = (FlowStatusResponse) validateInfoMessage(flowRequests.get(i), teMessage, correlationId);
            FlowIdStatusPayload status = response.getPayload();
            if (status.getStatus() == expectedState) {
                te_success++;
            } else {
                msgs.add("FAILURE (TE): Flow " + status.getId() + " NOT in " + expectedState + " state: state = " + status.getStatus());
                te_failure++;
            }
        } catch (Exception e) {
            msgs.add("EXCEPTION in Topology Engine Response: " + e.getMessage());
            te_failure++;
        }
    }
    BatchResults result = new BatchResults(flow_failure + te_failure, flow_success + te_success, msgs.stream().toArray(String[]::new));
    LOGGER.debug("Returned: ", result);
    return result;
}
Also used : FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) FlowState(org.openkilda.messaging.payload.flow.FlowState) FlowStatusResponse(org.openkilda.messaging.info.flow.FlowStatusResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) ArrayList(java.util.ArrayList) BatchResults(org.openkilda.northbound.service.BatchResults) InfoMessage(org.openkilda.messaging.info.InfoMessage)

Example 29 with FlowIdStatusPayload

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

the class NorthboundRunTest method flowState.

@Then("^flow (\\w+) in (\\w+) state$")
public void flowState(String flowId, String state) throws Throwable {
    String flowName = FlowUtils.getFlowName(flowId);
    FlowState flowState = FlowState.valueOf(state);
    FlowIdStatusPayload payload = FlowUtils.waitFlowStatus(flowName, flowState);
    assertNotNull(payload);
    assertEquals(flowName, payload.getId());
    assertEquals(flowState, payload.getStatus());
}
Also used : FlowState(org.openkilda.messaging.payload.flow.FlowState) FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) Then(cucumber.api.java.en.Then)

Aggregations

FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)29 InfoMessage (org.openkilda.messaging.info.InfoMessage)16 CommandMessage (org.openkilda.messaging.command.CommandMessage)12 Test (org.junit.Test)9 FlowStatusResponse (org.openkilda.messaging.info.flow.FlowStatusResponse)8 Message (org.openkilda.messaging.Message)6 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)6 FlowPayload (org.openkilda.messaging.payload.flow.FlowPayload)5 Then (cucumber.api.java.en.Then)3 Values (org.apache.storm.tuple.Values)3 FlowGetRequest (org.openkilda.messaging.command.flow.FlowGetRequest)3 FlowPathRequest (org.openkilda.messaging.command.flow.FlowPathRequest)3 FlowsGetRequest (org.openkilda.messaging.command.flow.FlowsGetRequest)3 Flow (org.openkilda.messaging.model.Flow)3 FlowState (org.openkilda.messaging.payload.flow.FlowState)3 FlowStatusRequest (org.openkilda.messaging.command.flow.FlowStatusRequest)2 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)2 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2