Search in sources :

Example 41 with CommandMessage

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());
    }
}
Also used : DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) Values(org.apache.storm.tuple.Values) CommandMessage(org.openkilda.messaging.command.CommandMessage) Commands(org.openkilda.simulator.classes.Commands) CommandData(org.openkilda.messaging.command.CommandData) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData)

Example 42 with CommandMessage

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);
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractTopology.fieldMessage(org.openkilda.wfm.topology.AbstractTopology.fieldMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) IOException(java.io.IOException) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 43 with CommandMessage

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()));
}
Also used : FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) HashSet(java.util.HashSet) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest)

Example 44 with CommandMessage

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;
}
Also used : FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Flow(org.openkilda.messaging.model.Flow) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 45 with CommandMessage

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;
}
Also used : InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

CommandMessage (org.openkilda.messaging.command.CommandMessage)70 Message (org.openkilda.messaging.Message)36 InfoMessage (org.openkilda.messaging.info.InfoMessage)32 Test (org.junit.Test)19 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)18 Values (org.apache.storm.tuple.Values)11 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)11 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)8 Flow (org.openkilda.messaging.model.Flow)8 IOException (java.io.IOException)7 CommandData (org.openkilda.messaging.command.CommandData)7 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)7 HashSet (java.util.HashSet)6 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)6 CommandWithReplyToMessage (org.openkilda.messaging.command.CommandWithReplyToMessage)5 NetworkCommandData (org.openkilda.messaging.command.discovery.NetworkCommandData)5 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)5 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)4 FlowPathRequest (org.openkilda.messaging.command.flow.FlowPathRequest)4 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)4