use of org.openkilda.messaging.info.flow.FlowStatusResponse in project open-kilda by telstra.
the class FlowTopologyTest method errorMessageStatusBoltSpeakerBoltTest.
@Test
public void errorMessageStatusBoltSpeakerBoltTest() throws Exception {
String flowId = UUID.randomUUID().toString();
ConsumerRecord<String, String> record;
createFlow(flowId);
record = cacheConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
statusFlow(flowId);
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
InfoMessage infoMessageUp = objectMapper.readValue(record.value(), InfoMessage.class);
assertNotNull(infoMessageUp);
FlowStatusResponse infoDataUp = (FlowStatusResponse) infoMessageUp.getData();
assertNotNull(infoDataUp);
FlowIdStatusPayload flowNbPayloadUp = infoDataUp.getPayload();
assertNotNull(flowNbPayloadUp);
assertEquals(flowId, flowNbPayloadUp.getId());
assertEquals(FlowState.ALLOCATED, flowNbPayloadUp.getStatus());
errorFlowSpeakerCommand(flowId);
statusFlow(flowId);
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
InfoMessage infoMessageDown = objectMapper.readValue(record.value(), InfoMessage.class);
assertNotNull(infoMessageDown);
FlowStatusResponse infoDataDown = (FlowStatusResponse) infoMessageDown.getData();
assertNotNull(infoDataDown);
FlowIdStatusPayload flowNbPayloadDown = infoDataDown.getPayload();
assertNotNull(flowNbPayloadDown);
assertEquals(flowId, flowNbPayloadDown.getId());
assertEquals(FlowState.DOWN, flowNbPayloadDown.getStatus());
}
use of org.openkilda.messaging.info.flow.FlowStatusResponse in project open-kilda by telstra.
the class FlowTopologyTest method installFlowTopologyEngineSpeakerBoltTest.
@Test
public void installFlowTopologyEngineSpeakerBoltTest() throws Exception {
/*
* This test will verify the state transitions of a flow, through the status mechanism.
* It achieves this by doing the following:
* - CreateFlow .. clear both cache and northbound consumers
* - GetStatus .. confirm STATE = FlowState.ALLOCATED
* - baseInstallFlowCommand .. read speaker .. validate data/responsedata
* - GetStatus .. confirm STATE = FlowState.IN_PROGRESS
* - baseInstallRuleCommand ..
* - GetStatus .. confirm STATE = FlowState.UP
*/
String flowId = UUID.randomUUID().toString();
ConsumerRecord<String, String> record;
createFlow(flowId);
record = cacheConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
statusFlow(flowId);
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
assertNotNull(infoMessage);
FlowStatusResponse infoData = (FlowStatusResponse) infoMessage.getData();
assertNotNull(infoData);
FlowIdStatusPayload flowNbPayload = infoData.getPayload();
assertNotNull(flowNbPayload);
assertEquals(flowId, flowNbPayload.getId());
assertEquals(FlowState.ALLOCATED, flowNbPayload.getStatus());
InstallOneSwitchFlow data = baseInstallFlowCommand(flowId);
record = ofsConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
CommandMessage response = objectMapper.readValue(record.value(), CommandMessage.class);
assertNotNull(response);
InstallOneSwitchFlow responseData = (InstallOneSwitchFlow) response.getData();
Long transactionId = responseData.getTransactionId();
responseData.setTransactionId(0L);
assertEquals(data, responseData);
responseData.setTransactionId(transactionId);
statusFlow(flowId);
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
assertNotNull(infoMessage);
infoData = (FlowStatusResponse) infoMessage.getData();
assertNotNull(infoData);
flowNbPayload = infoData.getPayload();
assertNotNull(flowNbPayload);
assertEquals(flowId, flowNbPayload.getId());
assertEquals(FlowState.IN_PROGRESS, flowNbPayload.getStatus());
response.setDestination(Destination.WFM_TRANSACTION);
baseInstallRuleCommand(response);
statusFlow(flowId);
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
assertNotNull(infoMessage);
infoData = (FlowStatusResponse) infoMessage.getData();
assertNotNull(infoData);
flowNbPayload = infoData.getPayload();
assertNotNull(flowNbPayload);
assertEquals(flowId, flowNbPayload.getId());
assertEquals(FlowState.UP, flowNbPayload.getStatus());
}
use of org.openkilda.messaging.info.flow.FlowStatusResponse in project open-kilda by telstra.
the class AbstractSerializerTest method flowStatusResponseTest.
@Test
public void flowStatusResponseTest() throws IOException, ClassNotFoundException {
FlowStatusResponse data = new FlowStatusResponse(flowIdStatusResponse);
System.out.println(data);
InfoMessage info = new InfoMessage(data, System.currentTimeMillis(), CORRELATION_ID, DESTINATION);
serialize(info);
Message message = (Message) deserialize();
assertTrue(message instanceof InfoMessage);
InfoMessage resultInfo = (InfoMessage) message;
assertTrue(resultInfo.getData() instanceof FlowStatusResponse);
FlowStatusResponse resultData = (FlowStatusResponse) resultInfo.getData();
System.out.println(resultData);
assertEquals(data, resultData);
assertEquals(data.hashCode(), resultData.hashCode());
assertEquals(flowIdStatusResponse.hashCode(), resultData.getPayload().hashCode());
}
use of org.openkilda.messaging.info.flow.FlowStatusResponse 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;
}
Aggregations