use of org.openkilda.messaging.info.stats.MeterConfigReply in project open-kilda by telstra.
the class MeterConfigMetricGenBolt method execute.
@Override
public void execute(Tuple input) {
StatsComponentType componentId = StatsComponentType.valueOf(input.getSourceComponent());
InfoMessage message = (InfoMessage) input.getValueByField(MESSAGE_FIELD);
if (!Destination.WFM_STATS.equals(message.getDestination())) {
collector.ack(input);
return;
}
LOGGER.debug("Meter config stats message: {}={}, component={}, stream={}", CORRELATION_ID, message.getCorrelationId(), componentId, StatsStreamType.valueOf(input.getSourceStreamId()));
MeterConfigStatsData data = (MeterConfigStatsData) message.getData();
long timestamp = message.getTimestamp();
try {
String switchId = data.getSwitchId().replaceAll(":", "");
for (MeterConfigReply reply : data.getStats()) {
for (Long meterId : reply.getMeterIds()) {
emit(timestamp, meterId, switchId);
}
}
} finally {
collector.ack(input);
}
}
use of org.openkilda.messaging.info.stats.MeterConfigReply in project open-kilda by telstra.
the class StatsTopologyTest method meterConfigStatsTest.
@Test
public void meterConfigStatsTest() throws Exception {
final String switchId = "00:00:00:00:00:00:00:01";
final List<MeterConfigReply> stats = Collections.singletonList(new MeterConfigReply(2, Arrays.asList(1L, 2L, 3L)));
InfoMessage message = new InfoMessage(new MeterConfigStatsData(switchId, stats), 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.METER_CFG_STATS_METRIC_GEN.name());
assertThat(tuples.size(), is(3));
tuples.stream().map(this::readFromJson).forEach(datapoint -> {
assertThat(datapoint.getTags().get("switchid"), is(switchId.replaceAll(":", "")));
assertThat(datapoint.getTime(), is(timestamp));
assertThat(datapoint.getMetric(), is("pen.switch.meters"));
});
});
}
Aggregations