use of org.openkilda.messaging.info.InfoMessage in project open-kilda by telstra.
the class StatsTopologyTest method portStatsTest.
@Ignore
@Test
public void portStatsTest() throws Exception {
final String switchId = "00:00:00:00:00:00:00:01";
final List<PortStatsEntry> entries = IntStream.range(1, 53).boxed().map(port -> {
int baseCount = port * 20;
return new PortStatsEntry(port, baseCount, baseCount + 1, baseCount + 2, baseCount + 3, baseCount + 4, baseCount + 5, baseCount + 6, baseCount + 7, baseCount + 8, baseCount + 9, baseCount + 10, baseCount + 11);
}).collect(toList());
final List<PortStatsReply> replies = Collections.singletonList(new PortStatsReply(1, entries));
InfoMessage message = new InfoMessage(new PortStatsData(switchId, replies), timestamp, CORRELATION_ID, Destination.WFM_STATS);
// mock kafka spout
MockedSources sources = new MockedSources();
sources.addMockData(StatsComponentType.STATS_OFS_KAFKA_SPOUT.toString(), new Values(MAPPER.writeValueAsString(message)));
completeTopologyParam.setMockedSources(sources);
// execute topology
Testing.withTrackedCluster(clusterParam, (cluster) -> {
StatsTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
StormTopology stormTopology = topology.createTopology();
// verify results
Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
ArrayList<FixedTuple> tuples = (ArrayList<FixedTuple>) result.get(StatsComponentType.PORT_STATS_METRIC_GEN.name());
assertThat(tuples.size(), is(728));
tuples.stream().map(this::readFromJson).forEach(datapoint -> {
assertThat(datapoint.getTags().get("switchId"), is(switchId.replaceAll(":", "")));
assertThat(datapoint.getTime(), is(timestamp));
assertThat(datapoint.getMetric(), startsWith("pen.switch"));
});
});
}
use of org.openkilda.messaging.info.InfoMessage in project open-kilda by telstra.
the class TopologyController method flows.
/**
* Dumps flows.
*
* @param correlationId correlation ID header value
* @return flows
*/
@RequestMapping(value = "/flows", method = RequestMethod.GET, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<FlowsPayload> flows(@RequestHeader(value = CORRELATION_ID, defaultValue = DEFAULT_CORRELATION_ID) String correlationId) {
logger.debug("Dump flows: {}={}", CORRELATION_ID, correlationId);
InfoMessage message = flowService.getFlows(null, correlationId);
FlowsResponse response = (FlowsResponse) message.getData();
return new ResponseEntity<>(response.getPayload(), new HttpHeaders(), HttpStatus.OK);
}
use of org.openkilda.messaging.info.InfoMessage in project open-kilda by telstra.
the class FlowServiceImpl method getFlows.
/**
* {@inheritDoc}
*/
@Override
public InfoMessage getFlows(final FlowIdStatusPayload payload, final String correlationId) {
Set<Flow> flows = flowRepository.findAll();
List<FlowPayload> flowsPayload = new ArrayList<>(flows.size() / 2);
for (Flow flow : flows) {
if ((flow.getCookie() & DIRECT_FLOW_COOKIE) == DIRECT_FLOW_COOKIE) {
flowsPayload.add(getFlowPayloadByFlow(flow));
}
}
logger.debug("Flows get: {}", flowsPayload);
return new InfoMessage(new FlowsResponse(new FlowsPayload(flowsPayload)), System.currentTimeMillis(), correlationId, Destination.WFM);
}
use of org.openkilda.messaging.info.InfoMessage in project open-kilda by telstra.
the class AbstractSerializerTest method eventIslInfoTest.
@Test
public void eventIslInfoTest() throws IOException, ClassNotFoundException {
PathNode payload = new PathNode(SWITCH_ID, INPUT_PORT, 0);
IslInfoData data = new IslInfoData(0L, Collections.singletonList(payload), 1000000L, IslChangeType.DISCOVERED, 900000L);
assertEquals(SWITCH_ID + "_" + String.valueOf(INPUT_PORT), data.getId());
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 IslInfoData);
IslInfoData resultData = (IslInfoData) resultInfo.getData();
System.out.println(resultData);
assertEquals(data, resultData);
assertEquals(data.hashCode(), resultData.hashCode());
assertEquals(payload.hashCode(), resultData.getPath().get(0).hashCode());
}
use of org.openkilda.messaging.info.InfoMessage in project open-kilda by telstra.
the class AbstractSerializerTest method eventSwitchInfoTest.
@Test
public void eventSwitchInfoTest() throws IOException, ClassNotFoundException {
SwitchInfoData data = new SwitchInfoData(SWITCH_ID, SWITCH_EVENT, "127.0.0.1", "localhost", "sw", "controller");
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 SwitchInfoData);
SwitchInfoData resultData = (SwitchInfoData) resultInfo.getData();
System.out.println(resultData);
assertEquals(data, resultData);
assertEquals(data.hashCode(), resultData.hashCode());
}
Aggregations