Search in sources :

Example 6 with FlowInfoData

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

the class CacheTopologyTest method sendFlowUpdate.

private static void sendFlowUpdate(ImmutablePair<Flow, Flow> flow) throws IOException {
    System.out.println("Flow Topology: Send Flow Creation Request");
    String correlationId = UUID.randomUUID().toString();
    FlowInfoData data = new FlowInfoData(flow.getLeft().getFlowId(), flow, FlowOperation.CREATE, correlationId);
    // TODO: as part of getting rid of OutputTopic, used TopoDiscoTopic. This feels wrong for
    // Flows.
    InfoMessage message = new InfoMessage(data, System.currentTimeMillis(), correlationId);
    sendMessage(message, topology.getConfig().getKafkaTopoCacheTopic());
}
Also used : FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage)

Example 7 with FlowInfoData

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

the class CacheTopologyTest method cacheReceivesFlowTopologyUpdatesAndSendsToTopologyEngine.

@Test
public void cacheReceivesFlowTopologyUpdatesAndSendsToTopologyEngine() throws Exception {
    System.out.println("Flow Update Test");
    teConsumer.clear();
    sendFlowUpdate(thirdFlow);
    ConsumerRecord<String, String> flow = teConsumer.pollMessage();
    assertNotNull(flow);
    assertNotNull(flow.value());
    InfoMessage infoMessage = objectMapper.readValue(flow.value(), InfoMessage.class);
    FlowInfoData infoData = (FlowInfoData) infoMessage.getData();
    assertNotNull(infoData);
    assertEquals(thirdFlow, infoData.getPayload());
}
Also used : FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest)

Example 8 with FlowInfoData

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

the class FlowInfoDataTest method toStringTest.

@Test
public void toStringTest() throws Exception {
    FlowInfoData data = new FlowInfoData("", new ImmutablePair<>(new Flow(), new Flow()), FlowOperation.CREATE, Utils.DEFAULT_CORRELATION_ID);
    String dataString = data.toString();
    assertNotNull(dataString);
    assertFalse(dataString.isEmpty());
    System.out.println(MAPPER.writeValueAsString(data));
}
Also used : FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) Flow(org.openkilda.messaging.model.Flow) Test(org.junit.Test)

Example 9 with FlowInfoData

use of org.openkilda.messaging.info.flow.FlowInfoData 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)

Aggregations

FlowInfoData (org.openkilda.messaging.info.flow.FlowInfoData)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)5 CommandMessage (org.openkilda.messaging.command.CommandMessage)3 InfoData (org.openkilda.messaging.info.InfoData)3 Message (org.openkilda.messaging.Message)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)2 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)2 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)2 Flow (org.openkilda.messaging.model.Flow)2 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Values (org.apache.storm.tuple.Values)1 Test (org.junit.Test)1 BaseMessage (org.openkilda.messaging.BaseMessage)1 CommandData (org.openkilda.messaging.command.CommandData)1 FlowCacheSyncRequest (org.openkilda.messaging.command.flow.FlowCacheSyncRequest)1 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)1 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)1