Search in sources :

Example 76 with InfoMessage

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"));
        });
    });
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) InfoMessage(org.openkilda.messaging.info.InfoMessage) IntStream(java.util.stream.IntStream) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) java.util(java.util) Testing(org.apache.storm.Testing) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) Values(org.apache.storm.tuple.Values) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) StormTopology(org.apache.storm.generated.StormTopology) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) MeterConfigReply(org.openkilda.messaging.info.stats.MeterConfigReply) MAPPER(org.openkilda.messaging.Utils.MAPPER) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Utils(org.openkilda.messaging.Utils) MockedSources(org.apache.storm.testing.MockedSources) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) KafkaBolt(org.apache.storm.kafka.bolt.KafkaBolt) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) FlowStatsReply(org.openkilda.messaging.info.stats.FlowStatsReply) TestFlowGenMetricsBolt(org.openkilda.wfm.topology.TestFlowGenMetricsBolt) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) FixedTuple(org.apache.storm.testing.FixedTuple) Test(org.junit.Test) IOException(java.io.IOException) MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) Datapoint(org.openkilda.messaging.info.Datapoint) File(java.io.File) FlowMetricGenBolt(org.openkilda.wfm.topology.stats.metrics.FlowMetricGenBolt) CORRELATION_ID(org.openkilda.messaging.Utils.CORRELATION_ID) Collectors.toList(java.util.stream.Collectors.toList) Ignore(org.junit.Ignore) Destination(org.openkilda.messaging.Destination) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) InfoMessage(org.openkilda.messaging.info.InfoMessage) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) Ignore(org.junit.Ignore) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Example 77 with InfoMessage

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowsResponse(org.openkilda.messaging.info.flow.FlowsResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 78 with InfoMessage

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);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowsResponse(org.openkilda.messaging.info.flow.FlowsResponse) ArrayList(java.util.ArrayList) FlowsPayload(org.openkilda.messaging.payload.flow.FlowsPayload) Flow(org.openkilda.topology.domain.Flow)

Example 79 with InfoMessage

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());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Example 80 with InfoMessage

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());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Aggregations

InfoMessage (org.openkilda.messaging.info.InfoMessage)87 Test (org.junit.Test)34 Values (org.apache.storm.tuple.Values)27 CommandMessage (org.openkilda.messaging.command.CommandMessage)21 Flow (org.openkilda.messaging.model.Flow)21 Message (org.openkilda.messaging.Message)20 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)19 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)19 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)13 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)12 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)12 IOException (java.io.IOException)9 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)9 ErrorData (org.openkilda.messaging.error.ErrorData)8 InfoData (org.openkilda.messaging.info.InfoData)8 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)8 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)8 FlowStatusResponse (org.openkilda.messaging.info.flow.FlowStatusResponse)8 NetworkInfoData (org.openkilda.messaging.info.discovery.NetworkInfoData)7 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)7