use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class SpeakerBolt method doCommand.
public void doCommand(Tuple tuple) throws Exception {
String command = tuple.getStringByField(TupleFields.COMMAND.name());
List<Values> values = new ArrayList<>();
if (command.equals(SimulatorCommands.DO_ADD_SWITCH)) {
values = addSwitch((SwitchMessage) tuple.getValueByField(TupleFields.DATA.name()));
if (values.size() > 0) {
for (Values value : values) {
logger.debug("emitting: {}", value);
collector.emit(SimulatorTopology.KAFKA_BOLT_STREAM, tuple, value);
}
}
return;
} else if (command.equals(Commands.DO_DISCOVER_ISL_P2_COMMAND.name())) {
discoverIslPartTwo(tuple, (IslInfoData) tuple.getValueByField(TupleFields.DATA.name()));
return;
}
CommandData data = (CommandData) tuple.getValueByField(TupleFields.DATA.name());
if (command.equals(Commands.DO_DELETE_FLOW.name())) {
} else if (command.equals(Commands.DO_DISCOVER_ISL_COMMAND.name())) {
discoverIsl(tuple, (DiscoverIslCommandData) data);
} else if (command.equals(Commands.DO_DISCOVER_PATH_COMMAND.name())) {
} else if (command.equals(Commands.DO_INSTALL_EGRESS_FLOW.name())) {
} else if (command.equals(Commands.DO_INSTALL_INGRESS_FLOW.name())) {
} else if (command.equals(Commands.DO_INSTALL_ONESWITCH_FLOW.name())) {
} else if (command.equals(Commands.DO_INSTALL_TRANSIT_FLOW.name())) {
} else {
logger.error("Unknown switch command: {}".format(command));
return;
}
if (values.size() > 0) {
for (Values value : values) {
logger.debug("emitting: {}", value);
collector.emit(SimulatorTopology.KAFKA_BOLT_STREAM, tuple, value);
}
}
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class SpeakerBolt method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(Tuple tuple) {
String request = tuple.getString(0);
Values values = null;
try {
Message message = MAPPER.readValue(request, Message.class);
if (!Destination.WFM_TRANSACTION.equals(message.getDestination())) {
return;
}
logger.debug("Request tuple={}", tuple);
if (message instanceof CommandMessage) {
CommandData data = ((CommandMessage) message).getData();
if (data instanceof BaseInstallFlow) {
Long transactionId = ((BaseInstallFlow) data).getTransactionId();
String switchId = ((BaseInstallFlow) data).getSwitchId();
String flowId = ((BaseInstallFlow) data).getId();
logger.debug("Flow install message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
message.setDestination(Destination.TOPOLOGY_ENGINE);
values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
// FIXME(surabujin): looks like TE ignore this messages
outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
} else if (data instanceof RemoveFlow) {
Long transactionId = ((RemoveFlow) data).getTransactionId();
String switchId = ((RemoveFlow) data).getSwitchId();
String flowId = ((RemoveFlow) data).getId();
logger.debug("Flow remove message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
message.setDestination(Destination.TOPOLOGY_ENGINE);
values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
} else {
logger.debug("Skip undefined command message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} else if (message instanceof ErrorMessage) {
String flowId = ((ErrorMessage) message).getData().getErrorDescription();
FlowState status = FlowState.DOWN;
// TODO: Should add debug message if receiving ErrorMessage.
if (flowId != null) {
logger.error("Flow error message: {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), Utils.FLOW_ID, flowId, request);
values = new Values(flowId, status);
outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
} else {
logger.debug("Skip error message without flow-id: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} else {
// TODO: should this be a warn or error? Probably, after refactored / specific
// topics
logger.debug("Skip undefined message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} catch (IOException exception) {
logger.error("\n\nCould not deserialize message={}", request, exception);
} finally {
logger.debug("Speaker message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
outputCollector.ack(tuple);
}
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class SplitterBolt method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(Tuple tuple) {
String request = tuple.getString(0);
Values values = new Values(request);
try {
Message message = tryMessage(request);
if (message == null || !Destination.WFM.equals(message.getDestination()) || !(message instanceof CommandMessage || message instanceof InfoMessage)) {
return;
}
logger.debug("Request tuple={}", tuple);
/*
* First, try to see if this is a PUSH / UNPUSH (smaller code base vs other).
* NB: InfoMessage was used since it has the relevant attributes/properties for
* pushing the flow.
*/
if (message instanceof InfoMessage) {
InfoData data = ((InfoMessage) message).getData();
if (data instanceof FlowInfoData) {
FlowInfoData fid = (FlowInfoData) data;
String flowId = fid.getFlowId();
values = new Values(message, flowId);
logger.info("Flow {} message: operation={} values={}", flowId, fid.getOperation(), values);
if (fid.getOperation() == FlowOperation.PUSH) {
outputCollector.emit(StreamType.PUSH.toString(), tuple, values);
} else if (fid.getOperation() == FlowOperation.UNPUSH) {
outputCollector.emit(StreamType.UNPUSH.toString(), tuple, values);
} else {
logger.warn("Skip undefined FlowInfoData Operation {}: {}={}", fid.getOperation(), Utils.CORRELATION_ID, message.getCorrelationId());
}
} else {
logger.warn("Skip undefined InfoMessage: {}={}", Utils.CORRELATION_ID, message.getCorrelationId());
}
return;
}
/*
* Second, it isn't an InfoMessage, so it must be a CommandMessage.
*/
CommandData data = ((CommandMessage) message).getData();
if (data instanceof FlowCreateRequest) {
String flowId = ((FlowCreateRequest) data).getPayload().getFlowId();
logger.info("Flow {} create message: values={}", flowId, values);
values = new Values(message, flowId);
outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
} else if (data instanceof FlowDeleteRequest) {
String flowId = ((FlowDeleteRequest) data).getPayload().getFlowId();
logger.info("Flow {} delete message: values={}", flowId, values);
values = new Values(message, flowId);
outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
} else if (data instanceof FlowUpdateRequest) {
String flowId = ((FlowUpdateRequest) data).getPayload().getFlowId();
logger.info("Flow {} update message: values={}", flowId, values);
values = new Values(message, flowId);
outputCollector.emit(StreamType.UPDATE.toString(), tuple, values);
} else if (data instanceof FlowRestoreRequest) {
String flowId = ((FlowRestoreRequest) data).getPayload().getLeft().getFlowId();
logger.info("Flow {} restore message: values={}", flowId, values);
values = new Values(message, flowId);
outputCollector.emit(StreamType.RESTORE.toString(), tuple, values);
} else if (data instanceof FlowRerouteRequest) {
String flowId = ((FlowRerouteRequest) data).getPayload().getFlowId();
logger.info("Flow {} reroute message: values={}", flowId, values);
values = new Values(message, flowId);
outputCollector.emit(StreamType.REROUTE.toString(), tuple, values);
} else if (data instanceof FlowStatusRequest) {
String flowId = ((FlowStatusRequest) data).getPayload().getId();
logger.info("Flow {} status message: values={}", flowId, values);
values = new Values(message, flowId);
outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
} else if (data instanceof FlowGetRequest) {
String flowId = ((FlowGetRequest) data).getPayload().getId();
logger.info("Flow {} get message: values={}", flowId, values);
values = new Values(message, flowId);
outputCollector.emit(StreamType.READ.toString(), tuple, values);
} else if (data instanceof FlowsGetRequest) {
logger.info("Flows get message: values={}", values);
values = new Values(message, null);
outputCollector.emit(StreamType.READ.toString(), tuple, values);
} else if (data instanceof FlowPathRequest) {
String flowId = ((FlowPathRequest) data).getPayload().getId();
logger.info("Flow {} path message: values={}", flowId, values);
values = new Values(message, flowId);
outputCollector.emit(StreamType.PATH.toString(), tuple, values);
} else if (data instanceof FlowCacheSyncRequest) {
logger.info("FlowCacheSyncRequest: values={}", values);
values = new Values(message, null);
outputCollector.emit(StreamType.CACHE_SYNC.toString(), tuple, values);
} else {
logger.debug("Skip undefined CommandMessage: {}={}", Utils.CORRELATION_ID, message.getCorrelationId());
}
/*
* (crimi) This was commented out since the parsing of the message is handled in tryMessage.
* Due to refactoring the kafka topics, it appears more messages are coming to the splitter than
* originally desinged for.
*
* TODO: Fix the cause of excess messages coming to the splitter.
*/
//
// } catch (IOException exception) {
// String message = String.format("Could not deserialize message: %s", request);
// logger.error("{}", message, exception);
//
// ErrorMessage errorMessage = new ErrorMessage(
// new ErrorData(ErrorType.REQUEST_INVALID, message, exception.getMessage()),
// System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.NORTHBOUND);
//
// values = new Values(errorMessage, ErrorType.INTERNAL_ERROR);
// outputCollector.emit(StreamType.ERROR.toString(), tuple, values);
} finally {
logger.debug("Splitter message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
outputCollector.ack(tuple);
}
}
use of org.openkilda.messaging.command.CommandData in project open-kilda by telstra.
the class TopologyEngineBolt method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(Tuple tuple) {
String request = tuple.getString(0);
Values values = null;
try {
Message message = MAPPER.readValue(request, Message.class);
if (!Destination.WFM.equals(message.getDestination())) {
return;
}
logger.debug("Request tuple={}", tuple);
if (message instanceof CommandMessage) {
CommandData data = ((CommandMessage) message).getData();
if (data instanceof BaseInstallFlow) {
BaseInstallFlow installData = (BaseInstallFlow) data;
Long transactionId = UUID.randomUUID().getLeastSignificantBits();
installData.setTransactionId(transactionId);
String switchId = installData.getSwitchId();
String flowId = installData.getId();
logger.debug("Flow install message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
// FIXME(surabujin): send here and in TE
message.setDestination(Destination.CONTROLLER);
values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
} else if (data instanceof RemoveFlow) {
RemoveFlow removeData = (RemoveFlow) data;
Long transactionId = UUID.randomUUID().getLeastSignificantBits();
removeData.setTransactionId(transactionId);
String switchId = removeData.getSwitchId();
String flowId = removeData.getId();
logger.debug("Flow remove message: {}={}, switch-id={}, {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), switchId, Utils.FLOW_ID, flowId, Utils.TRANSACTION_ID, transactionId, request);
message.setDestination(Destination.CONTROLLER);
values = new Values(MAPPER.writeValueAsString(message), switchId, flowId, transactionId);
outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
} else {
logger.debug("Skip undefined command message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} else if (message instanceof InfoMessage) {
values = new Values(message);
logger.debug("Flow response message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
outputCollector.emit(StreamType.RESPONSE.toString(), tuple, values);
} else if (message instanceof ErrorMessage) {
String flowId = ((ErrorMessage) message).getData().getErrorDescription();
logger.error("Flow error message: {}={}, {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), Utils.FLOW_ID, flowId, request);
values = new Values(message, flowId);
outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
} else {
logger.debug("Skip undefined message: {}={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), request);
}
} catch (IOException exception) {
logger.error("Could not deserialize message={}", request, exception);
} finally {
logger.debug("Topology-Engine message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
outputCollector.ack(tuple);
}
}
use of org.openkilda.messaging.command.CommandData 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);
}
}
Aggregations