Search in sources :

Example 1 with CommandContext

use of org.openkilda.floodlight.command.CommandContext in project open-kilda by telstra.

the class RecordHandler method parseRecord.

private void parseRecord(ConsumerRecord<String, String> record) {
    if (handleSpeakerCommand()) {
        return;
    }
    if (handleRuleManagerCommand()) {
        return;
    }
    CommandMessage message;
    try {
        String value = record.value();
        // TODO: Prior to Message changes, this MAPPER would read Message ..
        // but, changed to BaseMessage and got an error wrt "timestamp" ..
        // so, need to experiment with why CommandMessage can't be read as
        // a BaseMessage
        message = MAPPER.readValue(value, CommandMessage.class);
    } catch (Exception exception) {
        logger.error("error parsing record '{}'", record.value(), exception);
        return;
    }
    // Process the message within the message correlation context.
    try (CorrelationContextClosable closable = CorrelationContext.create(message.getCorrelationId())) {
        if (logger.isDebugEnabled()) {
            logger.debug("Receive command: key={}, payload={}", record.key(), message.getData());
        }
        CommandContext commandContext = new CommandContext(context.getModuleContext(), message.getCorrelationId(), record.key());
        if (!dispatch(commandContext, message)) {
            handleCommand(message);
        }
    } catch (Exception exception) {
        logger.error("error processing message '{}'", message, exception);
    }
}
Also used : CommandContext(org.openkilda.floodlight.command.CommandContext) CorrelationContextClosable(org.openkilda.floodlight.utils.CorrelationContext.CorrelationContextClosable) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) IOException(java.io.IOException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) OfInstallException(org.openkilda.floodlight.error.OfInstallException) FlowCommandException(org.openkilda.floodlight.error.FlowCommandException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with CommandContext

use of org.openkilda.floodlight.command.CommandContext in project open-kilda by telstra.

the class PingRequestCommandWriteFailTest method expectFail.

private void expectFail(Ping ping, Ping.Errors errorCode) throws Exception {
    final CommandContext context = commandContextFactory.produce();
    final PingRequestCommand command = new PingRequestCommand(context, ping);
    command.call();
    verifySentErrorResponse(ping, errorCode);
}
Also used : CommandContext(org.openkilda.floodlight.command.CommandContext)

Example 3 with CommandContext

use of org.openkilda.floodlight.command.CommandContext in project open-kilda by telstra.

the class CommandProcessorService method verifyPendingStatus.

private void verifyPendingStatus() {
    LinkedList<ProcessorTask> checkList = rotatePendingCommands();
    if (checkList.size() == 0) {
        return;
    }
    try {
        CommandContext context = commandContextFactory.produce();
        VerifyBatch verifyBatch = new VerifyBatch(this, checkList);
        PendingCommandSubmitter checkCommands = new PendingCommandSubmitter(context, verifyBatch);
        processLazy(checkCommands);
    } catch (Throwable e) {
        synchronized (this) {
            tasks.addAll(checkList);
        }
        throw e;
    }
}
Also used : PendingCommandSubmitter(org.openkilda.floodlight.command.PendingCommandSubmitter) CommandContext(org.openkilda.floodlight.command.CommandContext)

Example 4 with CommandContext

use of org.openkilda.floodlight.command.CommandContext in project open-kilda by telstra.

the class InputService method handle.

private void handle(OfInput input) {
    final CommandContext commandContext = commandContextFactory.produce();
    List<IInputTranslator> queue = translators.get(input.getType());
    commandProcessor.processLazy(new InputDispatchCommand(commandContext, commandProcessor, queue, input));
}
Also used : CommandContext(org.openkilda.floodlight.command.CommandContext) InputDispatchCommand(org.openkilda.floodlight.command.InputDispatchCommand)

Example 5 with CommandContext

use of org.openkilda.floodlight.command.CommandContext in project open-kilda by telstra.

the class BfdCommand method sendResponse.

protected void sendResponse() {
    CommandContext context = getContext();
    InfoMessage response = context.makeInfoMessage(assembleResponse());
    kafkaProducer.sendMessageAndTrack(kafkaUtility.getKafkaChannel().getTopoDiscoTopic(), context.getRequestKey(), response);
}
Also used : CommandContext(org.openkilda.floodlight.command.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage)

Aggregations

CommandContext (org.openkilda.floodlight.command.CommandContext)5 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 InputDispatchCommand (org.openkilda.floodlight.command.InputDispatchCommand)1 PendingCommandSubmitter (org.openkilda.floodlight.command.PendingCommandSubmitter)1 FlowCommandException (org.openkilda.floodlight.error.FlowCommandException)1 InvalidMeterIdException (org.openkilda.floodlight.error.InvalidMeterIdException)1 OfInstallException (org.openkilda.floodlight.error.OfInstallException)1 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)1 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)1 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)1 CorrelationContextClosable (org.openkilda.floodlight.utils.CorrelationContext.CorrelationContextClosable)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1