use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class RecordHandler method dispatch.
private boolean dispatch(CommandContext commandContext, CommandMessage message) {
CommandData payload = message.getData();
for (CommandDispatcher<?> entry : dispatchers) {
Optional<Command> command = entry.dispatch(commandContext, payload);
if (!command.isPresent()) {
continue;
}
commandProcessor.process(command.get());
return true;
}
return false;
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class FlowResource method installFlow.
/**
* Installing flow.
*
* @param json the json from request.
* @return json response.
* @throws JsonProcessingException if response can't be wrote to string.
*/
@Post("json")
@Put("json")
public String installFlow(String json) throws JsonProcessingException {
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
Message message;
try {
message = MAPPER.readValue(json, Message.class);
} catch (IOException exception) {
String messageString = "Received JSON is not valid for TPN";
logger.error("{}: {}", messageString, json, exception);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, exception.getMessage());
return MAPPER.writeValueAsString(responseMessage);
}
if (!(message instanceof CommandMessage)) {
String messageString = "Json payload message is not an instance of CommandMessage";
logger.error("{}: class={}, data={}", messageString, message.getClass().getCanonicalName(), json);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, message.getClass().getCanonicalName());
return MAPPER.writeValueAsString(responseMessage);
}
CommandMessage cmdMessage = (CommandMessage) message;
CommandData data = cmdMessage.getData();
if (!(data instanceof BaseInstallFlow)) {
String messageString = "Json payload data is not an instance of CommandData";
logger.error("{}: class={}, data={}", messageString, data.getClass().getCanonicalName(), json);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), now(), ErrorType.DATA_INVALID.toString(), messageString, data.getClass().getCanonicalName());
return MAPPER.writeValueAsString(responseMessage);
}
return MAPPER.writeValueAsString("ok");
}
use of org.openkilda.messaging.command.CommandData 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.CommandData in project open-kilda by telstra.
the class CacheWarmingService method getFlowCommands.
public List<CommandData> getFlowCommands(String switchId) {
List<CommandData> result = new ArrayList<>();
predefinedFlows.stream().filter(flow -> switchId.equals(flow.getLeft().getSourceSwitch())).forEach(pair -> {
CommandData command = getFlowCommandIfNeeded(pair.getLeft());
if (Objects.nonNull(command)) {
result.add(command);
}
});
return result;
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class CacheWarmingService method getFlowCommandIfNeeded.
private CommandData getFlowCommandIfNeeded(Flow flow) {
CommandData request = null;
if (flow.getState() == FlowState.CACHED && isFlowSwitchesUp(flow)) {
request = new FlowCreateRequest(flow);
LOGGER.info("Created flow create request for flowId {}", flow.getFlowId());
predefinedFlows.stream().filter(item -> item.getLeft().equals(flow)).findFirst().ifPresent(pair -> pair.setRight(CachedFlowState.CREATED));
}
return request;
}
Aggregations