use of org.openkilda.messaging.command.discovery.NetworkCommandData in project open-kilda by telstra.
the class CacheBolt method getNetworkRequest.
private Values getNetworkRequest() {
Values values = null;
try {
CommandMessage command = new CommandMessage(new NetworkCommandData(), System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.TOPOLOGY_ENGINE);
values = new Values(Utils.MAPPER.writeValueAsString(command));
} catch (IOException exception) {
logger.error("Could not serialize network cache request", exception);
}
return values;
}
use of org.openkilda.messaging.command.discovery.NetworkCommandData in project open-kilda by telstra.
the class OFELinkBolt method sendNetworkRequest.
/**
* Send network dump request to FL
*/
private void sendNetworkRequest(Tuple tuple) {
try {
logger.debug("Send network dump request");
CommandMessage command = new CommandMessage(new NetworkCommandData(), System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.CONTROLLER);
String json = Utils.MAPPER.writeValueAsString(command);
collector.emit(islDiscoveryTopic, tuple, new Values(PAYLOAD, json));
} catch (JsonProcessingException exception) {
logger.error("Could not serialize network cache request", exception);
}
}
use of org.openkilda.messaging.command.discovery.NetworkCommandData in project open-kilda by telstra.
the class OFELinkBoltTest method cacheRequestCheck.
/**
* Part of warm mechanism checks. That test verifies doTick sends init message to FL and
* second tick does nothing.
*/
@Test
public void cacheRequestCheck() throws IOException {
// do Tick and verify that bolt send message with cache request to right topic
Tuple tuple = new TupleImpl(context, new Values(""), TASK_ID_BOLT, STREAM_ID_INPUT);
bolt.doTick(tuple);
bolt.doTick(tuple);
ArgumentCaptor<String> captorStreamId = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<List<Tuple>> captorAnchor = ArgumentCaptor.forClass((Class) List.class);
ArgumentCaptor<Values> captorTuple = ArgumentCaptor.forClass(Values.class);
Mockito.verify(outputDelegate, only()).emit(captorStreamId.capture(), captorAnchor.capture(), captorTuple.capture());
assertEquals(config.getKafkaSpeakerTopic(), captorStreamId.getValue());
Values values = captorTuple.getValue();
String payload = (String) values.get(1);
CommandMessage commandMessage = objectMapper.readValue(payload, CommandMessage.class);
assertTrue(commandMessage.getData() instanceof NetworkCommandData);
}
use of org.openkilda.messaging.command.discovery.NetworkCommandData in project open-kilda by telstra.
the class RecordHandler method doNetworkDump.
/**
* Create network dump for OFELinkBolt
*
* @param message NetworkCommandData
*/
private void doNetworkDump(final CommandMessage message) {
logger.info("Create network dump");
NetworkCommandData command = (NetworkCommandData) message.getData();
Map<DatapathId, IOFSwitch> allSwitchMap = context.getSwitchManager().getAllSwitchMap();
Set<SwitchInfoData> switchesInfoData = allSwitchMap.values().stream().map(this::buildSwitchInfoData).collect(Collectors.toSet());
Set<PortInfoData> portsInfoData = allSwitchMap.values().stream().flatMap(sw -> sw.getEnabledPorts().stream().map(port -> new PortInfoData(sw.getId().toString(), port.getPortNo().getPortNumber(), null, PortChangeType.UP)).collect(Collectors.toSet()).stream()).collect(Collectors.toSet());
NetworkInfoData dump = new NetworkInfoData(command.getRequester(), switchesInfoData, portsInfoData, Collections.emptySet(), Collections.emptySet());
InfoMessage infoMessage = new InfoMessage(dump, System.currentTimeMillis(), message.getCorrelationId());
context.getKafkaProducer().postMessage(OUTPUT_DISCO_TOPIC, infoMessage);
}
use of org.openkilda.messaging.command.discovery.NetworkCommandData in project open-kilda by telstra.
the class RecordHandlerTest method networkDumpTest.
/**
* Simple TDD test that was used to develop warming mechanism for OFELinkBolt. We create
* command and put it to KafkaMessageCollector then mock ISwitchManager::getAllSwitchMap and
* verify that output message comes to producer.
*/
@Test
public void networkDumpTest() {
// Cook mock data for ISwitchManager::getAllSwitchMap
// Two switches with two ports on each
// switches for ISwitchManager::getAllSwitchMap
OFSwitch iofSwitch1 = mock(OFSwitch.class);
OFSwitch iofSwitch2 = mock(OFSwitch.class);
Map<DatapathId, IOFSwitch> switches = ImmutableMap.of(DatapathId.of(1), iofSwitch1, DatapathId.of(2), iofSwitch2);
for (DatapathId swId : switches.keySet()) {
IOFSwitch sw = switches.get(swId);
expect(sw.isActive()).andReturn(true).anyTimes();
expect(sw.getId()).andReturn(swId).anyTimes();
}
expect(switchManager.getAllSwitchMap()).andReturn(switches);
// ports for OFSwitch::getEnabledPorts
OFPortDesc ofPortDesc1 = mock(OFPortDesc.class);
OFPortDesc ofPortDesc2 = mock(OFPortDesc.class);
OFPortDesc ofPortDesc3 = mock(OFPortDesc.class);
OFPortDesc ofPortDesc4 = mock(OFPortDesc.class);
expect(ofPortDesc1.getPortNo()).andReturn(OFPort.ofInt(1));
expect(ofPortDesc2.getPortNo()).andReturn(OFPort.ofInt(2));
expect(ofPortDesc3.getPortNo()).andReturn(OFPort.ofInt(3));
expect(ofPortDesc4.getPortNo()).andReturn(OFPort.ofInt(4));
expect(iofSwitch1.getEnabledPorts()).andReturn(ImmutableList.of(ofPortDesc1, ofPortDesc2));
expect(iofSwitch2.getEnabledPorts()).andReturn(ImmutableList.of(ofPortDesc3, ofPortDesc4));
// Logic in SwitchEventCollector.buildSwitchInfoData is too complicated and requires a lot
// of mocking code so I replaced it with mock on kafkaMessageCollector.buildSwitchInfoData
handler.overrideSwitchInfoData(DatapathId.of(1), new SwitchInfoData("sw1", SwitchState.ADDED, "127.0.0.1", "localhost", "test switch", "kilda"));
handler.overrideSwitchInfoData(DatapathId.of(2), new SwitchInfoData("sw2", SwitchState.ADDED, "127.0.0.1", "localhost", "test switch", "kilda"));
// setup hook for verify that we create new message for producer
producer.postMessage(eq(OUTPUT_DISCO_TOPIC), anyObject(InfoMessage.class));
replayAll();
// Create CommandMessage with NetworkCommandData for trigger network dump
CommandMessage command = new CommandMessage(new NetworkCommandData(), System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.CONTROLLER);
// KafkaMessageCollector contains a complicated run logic with couple nested private
// classes, threading and that is very painful for writing clear looking test code so I
// created the simple method in KafkaMessageCollector for simplifying test logic.
handler.handleMessage(command);
verify(producer);
// TODO: verify content of InfoMessage in producer.postMessage
}
Aggregations