use of org.openkilda.messaging.info.InfoData in project open-kilda by telstra.
the class BasicService method validateInfoMessage.
/**
* Validates info message.
*
* @param correlationId request correlation id
* @param commandMessage request command message
* @param message response info message
* @return parsed response InfoData
*/
default InfoData validateInfoMessage(final CommandMessage commandMessage, final Message message, final String correlationId) {
InfoData data;
if (message != null) {
if (message instanceof ErrorMessage) {
ErrorData error = ((ErrorMessage) message).getData();
logger.error("Response message is error: {}={}, command={}, error={}", CORRELATION_ID, correlationId, commandMessage, error);
throw new MessageException(error.getErrorType(), message.getTimestamp());
} else if (message instanceof InfoMessage) {
InfoMessage info = (InfoMessage) message;
data = info.getData();
if (data == null) {
logger.error("Response message data is empty: {}={}, command={}, info={}", CORRELATION_ID, correlationId, commandMessage, info);
throw new MessageException(INTERNAL_ERROR, message.getTimestamp());
}
} else {
logger.error("Response message type is unexpected: {}:{}, command={}, message={}", CORRELATION_ID, correlationId, commandMessage, message);
throw new MessageException(INTERNAL_ERROR, message.getTimestamp());
}
} else {
logger.error("Response message is empty: {}={}, command={}", CORRELATION_ID, correlationId, commandMessage);
throw new MessageException(INTERNAL_ERROR, System.currentTimeMillis());
}
return data;
}
use of org.openkilda.messaging.info.InfoData in project open-kilda by telstra.
the class BasicService method validateInfoMessage.
/**
* Validates info message.
*
* @param correlationId request correlation id
* @param requestMessage request command message
* @param responseMessage response info message
* @return parsed response InfoData
*/
default InfoData validateInfoMessage(final Message requestMessage, final Message responseMessage, final String correlationId) {
InfoData data;
if (responseMessage != null) {
if (responseMessage instanceof ErrorMessage) {
ErrorData error = ((ErrorMessage) responseMessage).getData();
logger.error("Response message is error: {}={}, command={}, error={}", CORRELATION_ID, correlationId, requestMessage, error);
throw new MessageException((ErrorMessage) responseMessage);
} else if (responseMessage instanceof InfoMessage) {
InfoMessage info = (InfoMessage) responseMessage;
data = info.getData();
if (data == null) {
String errorMessage = "Response message data is empty";
logger.error("{}: {}={}, command={}, info={}", errorMessage, CORRELATION_ID, correlationId, requestMessage, info);
throw new MessageException(responseMessage.getCorrelationId(), responseMessage.getTimestamp(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
}
} else {
String errorMessage = "Response message type is unexpected";
logger.error("{}: {}:{}, command={}, message={}", errorMessage, CORRELATION_ID, correlationId, requestMessage, responseMessage);
throw new MessageException(responseMessage.getCorrelationId(), responseMessage.getTimestamp(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
}
} else {
String errorMessage = "Response message is empty";
logger.error("{}: {}={}, command={}", errorMessage, CORRELATION_ID, correlationId, requestMessage);
throw new MessageException(DEFAULT_CORRELATION_ID, System.currentTimeMillis(), INTERNAL_ERROR, errorMessage, requestMessage.toString());
}
return data;
}
use of org.openkilda.messaging.info.InfoData in project open-kilda by telstra.
the class SwitchEventCollector method buildSwitchMessage.
/**
* Builds a switch message type.
*
* @param switchId switch id
* @param eventType type of event
* @return Message
*/
public static Message buildSwitchMessage(final DatapathId switchId, final SwitchState eventType) {
final String unknown = "unknown";
InfoData data = new SwitchInfoData(switchId.toString(), eventType, unknown, unknown, unknown, unknown);
return buildMessage(data);
}
use of org.openkilda.messaging.info.InfoData in project open-kilda by telstra.
the class OFEMessageUtils method createIslFail.
public static String createIslFail(String switchId, String portId) throws IOException {
PathNode node = new PathNode(switchId, Integer.parseInt(portId), 0, 0L);
InfoData data = new IslInfoData(0L, Collections.singletonList(node), 0L, IslChangeType.FAILED, 0L);
InfoMessage message = new InfoMessage(data, System.currentTimeMillis(), UUID.randomUUID().toString());
return MAPPER.writeValueAsString(message);
}
use of org.openkilda.messaging.info.InfoData in project open-kilda by telstra.
the class OFELinkBolt method doWork.
@Override
protected void doWork(Tuple tuple) {
if (CtrlAction.boltHandlerEntrance(this, tuple))
return;
//
// (crimi) - commenting out the filter code until we re-evaluate the design. Also, this code
// should probably be embedded in "handleIslEvent"
// /*
// * Check whether ISL Filter needs to be engaged.
// */
// String source = tuple.getSourceComponent();
// if (source.equals(OFEventWFMTopology.SPOUT_ID_INPUT)) {
// PopulateIslFilterAction action = new PopulateIslFilterAction(this, tuple, islFilter);
// action.run();
// return;
// }
String json = tuple.getString(0);
try {
BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
watchDog.reset();
if (bm instanceof InfoMessage) {
InfoData data = ((InfoMessage) bm).getData();
if (data instanceof NetworkInfoData) {
handleNetworkDump(tuple, (NetworkInfoData) data);
isReceivedCacheInfo = true;
} else if (!isReceivedCacheInfo) {
logger.debug("Bolt is not initialized mark tuple as fail");
} else if (data instanceof SwitchInfoData) {
handleSwitchEvent(tuple, (SwitchInfoData) data);
passToTopologyEngine(tuple);
} else if (data instanceof PortInfoData) {
handlePortEvent(tuple, (PortInfoData) data);
passToTopologyEngine(tuple);
} else if (data instanceof IslInfoData) {
handleIslEvent(tuple, (IslInfoData) data);
} else {
logger.warn("Unknown InfoData type={}", data);
}
} else if (bm instanceof HeartBeat) {
logger.debug("Got speaker's heart beat");
}
} catch (IOException e) {
// All messages should be derived from BaseMessage .. so an exception here
// means that we found something that isn't. If this criteria changes, then
// change the logger level.
logger.error("Unknown Message type={}", json);
} finally {
// We mark as fail all tuples while bolt is not initialized
if (isReceivedCacheInfo) {
collector.ack(tuple);
} else {
collector.fail(tuple);
}
}
}
Aggregations