Search in sources :

Example 1 with MeterConfigReply

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);
    }
}
Also used : StatsComponentType(org.openkilda.wfm.topology.stats.StatsComponentType) MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) InfoMessage(org.openkilda.messaging.info.InfoMessage) MeterConfigReply(org.openkilda.messaging.info.stats.MeterConfigReply)

Example 2 with MeterConfigReply

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"));
        });
    });
}
Also used : MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) MeterConfigReply(org.openkilda.messaging.info.stats.MeterConfigReply) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) InfoMessage(org.openkilda.messaging.info.InfoMessage) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Aggregations

InfoMessage (org.openkilda.messaging.info.InfoMessage)2 MeterConfigReply (org.openkilda.messaging.info.stats.MeterConfigReply)2 MeterConfigStatsData (org.openkilda.messaging.info.stats.MeterConfigStatsData)2 StormTopology (org.apache.storm.generated.StormTopology)1 FixedTuple (org.apache.storm.testing.FixedTuple)1 MockedSources (org.apache.storm.testing.MockedSources)1 Values (org.apache.storm.tuple.Values)1 Test (org.junit.Test)1 StableAbstractStormTest (org.openkilda.wfm.StableAbstractStormTest)1 TestingKafkaBolt (org.openkilda.wfm.topology.TestingKafkaBolt)1 StatsComponentType (org.openkilda.wfm.topology.stats.StatsComponentType)1