Search in sources :

Example 1 with CommandWithReplyToMessage

use of org.openkilda.messaging.command.CommandWithReplyToMessage in project open-kilda by telstra.

the class RecordHandler method doControllerMsg.

protected void doControllerMsg(CommandMessage message) {
    // Define the destination topic where the reply will be sent to.
    final String replyToTopic;
    if (message instanceof CommandWithReplyToMessage) {
        replyToTopic = ((CommandWithReplyToMessage) message).getReplyTo();
    } else {
        replyToTopic = OUTPUT_FLOW_TOPIC;
    }
    final Destination replyDestination = getDestinationForTopic(replyToTopic);
    try {
        CommandData data = message.getData();
        handleCommand(message, data, replyToTopic, replyDestination);
    } catch (FlowCommandException e) {
        ErrorMessage error = new ErrorMessage(e.makeErrorResponse(), System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
        context.getKafkaProducer().postMessage(replyToTopic, error);
    } catch (Exception e) {
        logger.error("Unhandled exception: {}", e);
    }
}
Also used : Destination(org.openkilda.messaging.Destination) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) DiscoverIslCommandData(org.openkilda.messaging.command.discovery.DiscoverIslCommandData) CommandData(org.openkilda.messaging.command.CommandData) DiscoverPathCommandData(org.openkilda.messaging.command.discovery.DiscoverPathCommandData) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) SwitchOperationException(org.openkilda.floodlight.switchmanager.SwitchOperationException)

Example 2 with CommandWithReplyToMessage

use of org.openkilda.messaging.command.CommandWithReplyToMessage in project open-kilda by telstra.

the class SwitchServiceImpl method syncRules.

@Override
public SyncRulesOutput syncRules(String switchId, String correlationId) {
    SyncRulesRequest request = new SyncRulesRequest(switchId);
    CommandWithReplyToMessage commandMessage = new CommandWithReplyToMessage(request, System.currentTimeMillis(), correlationId, Destination.TOPOLOGY_ENGINE, northboundTopic);
    messageProducer.send(topoEngTopic, commandMessage);
    Message message = messageConsumer.poll(correlationId);
    SyncRulesResponse response = (SyncRulesResponse) validateInfoMessage(commandMessage, message, correlationId);
    return switchMapper.toSuncRulesOutput(response);
}
Also used : SyncRulesResponse(org.openkilda.messaging.info.switches.SyncRulesResponse) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) SyncRulesRequest(org.openkilda.messaging.command.switches.SyncRulesRequest)

Example 3 with CommandWithReplyToMessage

use of org.openkilda.messaging.command.CommandWithReplyToMessage in project open-kilda by telstra.

the class SwitchServiceImpl method installRules.

@Override
public List<Long> installRules(String switchId, InstallRulesAction installAction, String correlationId) {
    LOGGER.debug("Install switch rules request received");
    SwitchRulesInstallRequest data = new SwitchRulesInstallRequest(switchId, installAction);
    CommandMessage request = new CommandWithReplyToMessage(data, System.currentTimeMillis(), correlationId, Destination.CONTROLLER, northboundTopic);
    messageProducer.send(floodlightTopic, request);
    Message message = messageConsumer.poll(correlationId);
    SwitchRulesResponse response = (SwitchRulesResponse) validateInfoMessage(request, message, correlationId);
    return response.getRuleIds();
}
Also used : Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 4 with CommandWithReplyToMessage

use of org.openkilda.messaging.command.CommandWithReplyToMessage in project open-kilda by telstra.

the class SwitchServiceImpl method deleteRules.

@Override
public List<Long> deleteRules(String switchId, DeleteRulesAction deleteAction, Long cookie, String correlationId) {
    LOGGER.debug("Delete switch rules request received");
    // TODO: remove  messageConsumer.clear() as a part of NB cleanup (clear isn't required)
    messageConsumer.clear();
    SwitchRulesDeleteRequest data = new SwitchRulesDeleteRequest(switchId, deleteAction, cookie);
    CommandMessage request = new CommandWithReplyToMessage(data, System.currentTimeMillis(), correlationId, Destination.CONTROLLER, northboundTopic);
    messageProducer.send(floodlightTopic, request);
    Message message = messageConsumer.poll(correlationId);
    SwitchRulesResponse response = (SwitchRulesResponse) validateInfoMessage(request, message, correlationId);
    return response.getRuleIds();
}
Also used : Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 5 with CommandWithReplyToMessage

use of org.openkilda.messaging.command.CommandWithReplyToMessage in project open-kilda by telstra.

the class SwitchServiceImpl method connectMode.

@Override
public ConnectModeRequest.Mode connectMode(ConnectModeRequest.Mode mode, String correlationId) {
    LOGGER.debug("Set/Get switch connect mode request received: mode = {}", mode);
    ConnectModeRequest data = new ConnectModeRequest(mode);
    CommandMessage request = new CommandWithReplyToMessage(data, System.currentTimeMillis(), correlationId, Destination.CONTROLLER, northboundTopic);
    messageProducer.send(floodlightTopic, request);
    Message message = messageConsumer.poll(correlationId);
    ConnectModeResponse response = (ConnectModeResponse) validateInfoMessage(request, message, correlationId);
    return response.getMode();
}
Also used : ConnectModeRequest(org.openkilda.messaging.command.switches.ConnectModeRequest) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandWithReplyToMessage(org.openkilda.messaging.command.CommandWithReplyToMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage) ConnectModeResponse(org.openkilda.messaging.info.switches.ConnectModeResponse)

Aggregations

CommandWithReplyToMessage (org.openkilda.messaging.command.CommandWithReplyToMessage)5 Message (org.openkilda.messaging.Message)4 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 SwitchRulesResponse (org.openkilda.messaging.info.switches.SwitchRulesResponse)2 SwitchOperationException (org.openkilda.floodlight.switchmanager.SwitchOperationException)1 Destination (org.openkilda.messaging.Destination)1 CommandData (org.openkilda.messaging.command.CommandData)1 DiscoverIslCommandData (org.openkilda.messaging.command.discovery.DiscoverIslCommandData)1 DiscoverPathCommandData (org.openkilda.messaging.command.discovery.DiscoverPathCommandData)1 NetworkCommandData (org.openkilda.messaging.command.discovery.NetworkCommandData)1 ConnectModeRequest (org.openkilda.messaging.command.switches.ConnectModeRequest)1 SwitchRulesDeleteRequest (org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest)1 SwitchRulesInstallRequest (org.openkilda.messaging.command.switches.SwitchRulesInstallRequest)1 SyncRulesRequest (org.openkilda.messaging.command.switches.SyncRulesRequest)1 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)1 ConnectModeResponse (org.openkilda.messaging.info.switches.ConnectModeResponse)1 SyncRulesResponse (org.openkilda.messaging.info.switches.SyncRulesResponse)1