use of org.openkilda.messaging.info.event.PortInfoData in project open-kilda by telstra.
the class CacheBolt method doWork.
/**
* {@inheritDoc}
*/
@Override
public void doWork(Tuple tuple) {
if (CtrlAction.boltHandlerEntrance(this, tuple))
return;
logger.trace("State before: {}", state);
String json = tuple.getString(0);
String source = tuple.getSourceComponent();
// TODO: Eliminate the inefficiency introduced through the hack
try {
logger.info("Received cache data={}", tuple);
BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
if (bm instanceof InfoMessage) {
InfoMessage message = (InfoMessage) bm;
InfoData data = message.getData();
if (data instanceof NetworkInfoData) {
logger.debug("Storage content message {}", json);
handleNetworkDump(data, tuple);
isReceivedCacheInfo = true;
} else if (!isReceivedCacheInfo) {
logger.debug("Cache message fail due bolt not initialized: " + "component={}, stream={}, tuple={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple);
} else if (data instanceof SwitchInfoData) {
logger.info("Cache update switch info data: {}", data);
handleSwitchEvent((SwitchInfoData) data, tuple);
} else if (data instanceof IslInfoData) {
logger.info("Cache update isl info data: {}", data);
handleIslEvent((IslInfoData) data, tuple);
} else if (data instanceof PortInfoData) {
logger.info("Cache update port info data: {}", data);
handlePortEvent((PortInfoData) data, tuple);
} else if (data instanceof FlowInfoData) {
logger.info("Cache update flow data: {}", data);
FlowInfoData flowData = (FlowInfoData) data;
handleFlowEvent(flowData, tuple);
} else if (data instanceof NetworkTopologyChange) {
logger.info("Switch flows reroute request");
NetworkTopologyChange topologyChange = (NetworkTopologyChange) data;
handleNetworkTopologyChangeEvent(topologyChange, tuple);
} else {
logger.error("Skip undefined info data type {}", json);
}
} else {
logger.error("Skip undefined message type {}", json);
}
} catch (CacheException exception) {
logger.error("Could not process message {}", tuple, exception);
} catch (IOException exception) {
logger.error("Could not deserialize message {}", tuple, exception);
} finally {
if (isReceivedCacheInfo) {
outputCollector.ack(tuple);
} else {
outputCollector.fail(tuple);
}
}
logger.trace("State after: {}", state);
}
use of org.openkilda.messaging.info.event.PortInfoData in project open-kilda by telstra.
the class CacheBolt method onSwitchUp.
private void onSwitchUp(SwitchInfoData sw, Tuple tuple) throws IOException {
logger.info("Switch {} is {}", sw.getSwitchId(), sw.getState().getType());
if (networkCache.cacheContainsSwitch(sw.getSwitchId())) {
SwitchState prevState = networkCache.getSwitch(sw.getSwitchId()).getState();
networkCache.updateSwitch(sw);
if (prevState == SwitchState.CACHED) {
String switchId = sw.getSwitchId();
List<PortInfoData> ports = cacheWarmingService.getPortsForDiscovering(switchId);
logger.info("Found {} links for discovery", ports.size());
sendPortCachedEvent(ports);
List<? extends CommandData> commands = cacheWarmingService.getFlowCommands(switchId);
sendFlowCommands(commands);
}
} else {
networkCache.createSwitch(sw);
}
}
use of org.openkilda.messaging.info.event.PortInfoData in project open-kilda by telstra.
the class IslStatsBoltTest method getIslInfoData.
@Test
public void getIslInfoData() throws Exception {
Object data = statsBolt.getIslInfoData(statsBolt.getInfoData(message));
assertThat(data, instanceOf(IslInfoData.class));
assertEquals(data, islInfoData);
thrown.expect(Exception.class);
thrown.expectMessage(containsString("is not an IslInfoData"));
PortInfoData portData = new PortInfoData();
InfoMessage badMessage = new InfoMessage(portData, TIMESTAMP, CORRELATION, null);
data = statsBolt.getIslInfoData(statsBolt.getIslInfoData(badMessage.getData()));
}
use of org.openkilda.messaging.info.event.PortInfoData in project open-kilda by telstra.
the class AbstractSerializerTest method eventPortInfoTest.
@Test
public void eventPortInfoTest() throws IOException, ClassNotFoundException {
PortInfoData data = new PortInfoData(SWITCH_ID, INPUT_PORT, 0, PORT_CHANGE);
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 PortInfoData);
PortInfoData resultData = (PortInfoData) resultInfo.getData();
System.out.println(resultData);
assertEquals(data, resultData);
assertEquals(data.hashCode(), resultData.hashCode());
}
use of org.openkilda.messaging.info.event.PortInfoData 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);
}
Aggregations