use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.
the class CommandBolt method processCommand.
protected void processCommand(Tuple tuple) throws Exception {
CommandMessage command = Utils.MAPPER.readValue(getJson(tuple), CommandMessage.class);
if (command.getDestination() == Destination.CONTROLLER) {
CommandData data = command.getData();
Commands switchCommand;
String sw;
if (data instanceof DiscoverIslCommandData) {
switchCommand = Commands.DO_DISCOVER_ISL_COMMAND;
sw = ((DiscoverIslCommandData) data).getSwitchId();
} else if (data instanceof DiscoverPathCommandData) {
switchCommand = Commands.DO_DISCOVER_PATH_COMMAND;
sw = ((DiscoverPathCommandData) data).getSrcSwitchId();
} else if (data instanceof InstallIngressFlow) {
switchCommand = Commands.DO_INSTALL_INGRESS_FLOW;
sw = ((InstallIngressFlow) data).getSwitchId();
} else if (data instanceof InstallEgressFlow) {
switchCommand = Commands.DO_INSTALL_EGRESS_FLOW;
sw = ((InstallEgressFlow) data).getSwitchId();
} else if (data instanceof InstallTransitFlow) {
switchCommand = Commands.DO_INSTALL_TRANSIT_FLOW;
sw = ((InstallTransitFlow) data).getSwitchId();
} else if (data instanceof InstallOneSwitchFlow) {
switchCommand = Commands.DO_INSTALL_ONESWITCH_FLOW;
sw = ((InstallOneSwitchFlow) data).getSwitchId();
} else if (data instanceof RemoveFlow) {
switchCommand = Commands.DO_DELETE_FLOW;
sw = ((RemoveFlow) data).getSwitchId();
} else {
logger.error("unknown data type: {}", data.toString());
throw new Exception("Unknown command {}".format(data.getClass().getSimpleName()));
}
List<Integer> taskIDs = collector.emit(SimulatorTopology.COMMAND_BOLT_STREAM, tuple, new Values(sw.toLowerCase(), switchCommand.name(), command.getData()));
// logger.info("{}: {} - {}", switchCommand.name(), sw, command.getData().toString());
}
}
use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.
the class HealthCheckBolt method execute.
@Override
public void execute(Tuple input) {
String request = input.getString(0);
try {
Message message = MAPPER.readValue(request, Message.class);
if (message instanceof CommandMessage) {
Values values = new Values(Utils.MAPPER.writeValueAsString(new InfoMessage(healthCheck, System.currentTimeMillis(), message.getCorrelationId(), Destination.NORTHBOUND)));
collector.emit(Topic.HEALTH_CHECK, input, values);
}
} catch (IOException exception) {
logger.error("Could not deserialize message: ", request, exception);
} finally {
collector.ack(input);
}
}
use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.
the class CacheTopologyTest method cacheReceivesNetworkDumpAndSendsToFlowTopology.
@Test
public void cacheReceivesNetworkDumpAndSendsToFlowTopology() throws Exception {
System.out.println("Dump Test");
ConsumerRecord<String, String> firstRecord = flowConsumer.pollMessage();
assertNotNull(firstRecord);
assertNotNull(firstRecord.value());
Set<String> flowIds = new HashSet<>(Arrays.asList(firstFlowId, secondFlowId));
CommandMessage commandMessage = objectMapper.readValue(firstRecord.value(), CommandMessage.class);
FlowRestoreRequest commandData = (FlowRestoreRequest) commandMessage.getData();
assertNotNull(commandData);
assertTrue(flowIds.contains(commandData.getPayload().getLeft().getFlowId()));
ConsumerRecord<String, String> secondRecord = flowConsumer.pollMessage();
assertNotNull(secondRecord);
assertNotNull(secondRecord.value());
commandMessage = objectMapper.readValue(secondRecord.value(), CommandMessage.class);
commandData = (FlowRestoreRequest) commandMessage.getData();
assertNotNull(commandData);
assertTrue(flowIds.contains(commandData.getPayload().getLeft().getFlowId()));
}
use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.
the class FlowTopologyTest method createFlow.
private Flow createFlow(final String flowId) throws IOException {
System.out.println("NORTHBOUND: Create flow");
Flow flowPayload = new Flow(flowId, 10000, false, "", "test-switch", 1, 2, "test-switch", 1, 2);
FlowCreateRequest commandData = new FlowCreateRequest(flowPayload);
CommandMessage message = new CommandMessage(commandData, 0, "create-flow", Destination.WFM);
// sendNorthboundMessage(message);
sendFlowMessage(message);
return flowPayload;
}
use of org.openkilda.messaging.command.CommandMessage in project open-kilda by telstra.
the class FlowTopologyTest method baseInstallFlowCommand.
private InstallOneSwitchFlow baseInstallFlowCommand(final String flowId) throws IOException {
System.out.println("TOPOLOGY: Install flow");
InstallOneSwitchFlow commandData = new InstallOneSwitchFlow(0L, flowId, COOKIE, "switch-id", 1, 2, 0, 0, OutputVlanType.NONE, 10000L, 0L);
CommandMessage commandMessage = new CommandMessage(commandData, 0, "install-flow", Destination.WFM);
// sendTopologyEngineMessage(commandMessage);
// sendSpeakerMessage(commandMessage);
sendFlowMessage(commandMessage);
return commandData;
}
Aggregations