use of org.openkilda.messaging.error.CacheException in project open-kilda by telstra.
the class CacheBolt method doWork.
/**
* {@inheritDoc}
*/
@Override
public void doWork(Tuple tuple) {
if (CtrlAction.boltHandlerEntrance(this, tuple))
return;
logger.trace("State before: {}", state);
String json = tuple.getString(0);
String source = tuple.getSourceComponent();
// TODO: Eliminate the inefficiency introduced through the hack
try {
logger.info("Received cache data={}", tuple);
BaseMessage bm = MAPPER.readValue(json, BaseMessage.class);
if (bm instanceof InfoMessage) {
InfoMessage message = (InfoMessage) bm;
InfoData data = message.getData();
if (data instanceof NetworkInfoData) {
logger.debug("Storage content message {}", json);
handleNetworkDump(data, tuple);
isReceivedCacheInfo = true;
} else if (!isReceivedCacheInfo) {
logger.debug("Cache message fail due bolt not initialized: " + "component={}, stream={}, tuple={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple);
} else if (data instanceof SwitchInfoData) {
logger.info("Cache update switch info data: {}", data);
handleSwitchEvent((SwitchInfoData) data, tuple);
} else if (data instanceof IslInfoData) {
logger.info("Cache update isl info data: {}", data);
handleIslEvent((IslInfoData) data, tuple);
} else if (data instanceof PortInfoData) {
logger.info("Cache update port info data: {}", data);
handlePortEvent((PortInfoData) data, tuple);
} else if (data instanceof FlowInfoData) {
logger.info("Cache update flow data: {}", data);
FlowInfoData flowData = (FlowInfoData) data;
handleFlowEvent(flowData, tuple);
} else if (data instanceof NetworkTopologyChange) {
logger.info("Switch flows reroute request");
NetworkTopologyChange topologyChange = (NetworkTopologyChange) data;
handleNetworkTopologyChangeEvent(topologyChange, tuple);
} else {
logger.error("Skip undefined info data type {}", json);
}
} else {
logger.error("Skip undefined message type {}", json);
}
} catch (CacheException exception) {
logger.error("Could not process message {}", tuple, exception);
} catch (IOException exception) {
logger.error("Could not deserialize message {}", tuple, exception);
} finally {
if (isReceivedCacheInfo) {
outputCollector.ack(tuple);
} else {
outputCollector.fail(tuple);
}
}
logger.trace("State after: {}", state);
}
use of org.openkilda.messaging.error.CacheException in project open-kilda by telstra.
the class CrudBolt method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(Tuple tuple) {
if (CtrlAction.boltHandlerEntrance(this, tuple))
return;
logger.trace("Flow Cache before: {}", flowCache);
ComponentType componentId = ComponentType.valueOf(tuple.getSourceComponent());
StreamType streamId = StreamType.valueOf(tuple.getSourceStreamId());
String flowId = tuple.getStringByField(Utils.FLOW_ID);
String correlationId = Utils.DEFAULT_CORRELATION_ID;
try {
logger.debug("Request tuple={}", tuple);
switch(componentId) {
case SPLITTER_BOLT:
Message msg = (Message) tuple.getValueByField(AbstractTopology.MESSAGE_FIELD);
correlationId = msg.getCorrelationId();
CommandMessage cmsg = (msg instanceof CommandMessage) ? (CommandMessage) msg : null;
InfoMessage imsg = (msg instanceof InfoMessage) ? (InfoMessage) msg : null;
logger.info("Flow request: {}={}, {}={}, component={}, stream={}", Utils.CORRELATION_ID, correlationId, Utils.FLOW_ID, flowId, componentId, streamId);
switch(streamId) {
case CREATE:
handleCreateRequest(cmsg, tuple);
break;
case UPDATE:
handleUpdateRequest(cmsg, tuple);
break;
case DELETE:
handleDeleteRequest(flowId, cmsg, tuple);
break;
case PUSH:
handlePushRequest(flowId, imsg, tuple);
break;
case UNPUSH:
handleUnpushRequest(flowId, imsg, tuple);
break;
case PATH:
handlePathRequest(flowId, cmsg, tuple);
break;
case RESTORE:
handleRestoreRequest(cmsg, tuple);
break;
case REROUTE:
handleRerouteRequest(cmsg, tuple);
break;
case STATUS:
handleStatusRequest(flowId, cmsg, tuple);
break;
case CACHE_SYNC:
handleCacheSyncRequest(cmsg, tuple);
break;
case READ:
if (flowId != null) {
handleReadRequest(flowId, cmsg, tuple);
} else {
handleDumpRequest(cmsg, tuple);
}
break;
default:
logger.debug("Unexpected stream: component={}, stream={}", componentId, streamId);
break;
}
break;
case SPEAKER_BOLT:
case TRANSACTION_BOLT:
FlowState newStatus = (FlowState) tuple.getValueByField(FlowTopology.STATUS_FIELD);
logger.info("Flow {} status {}: component={}, stream={}", flowId, newStatus, componentId, streamId);
switch(streamId) {
case STATUS:
handleStateRequest(flowId, newStatus, tuple);
break;
default:
logger.debug("Unexpected stream: component={}, stream={}", componentId, streamId);
break;
}
break;
case TOPOLOGY_ENGINE_BOLT:
ErrorMessage errorMessage = (ErrorMessage) tuple.getValueByField(AbstractTopology.MESSAGE_FIELD);
logger.info("Flow {} error: component={}, stream={}", flowId, componentId, streamId);
switch(streamId) {
case STATUS:
handleErrorRequest(flowId, errorMessage, tuple);
break;
default:
logger.debug("Unexpected stream: component={}, stream={}", componentId, streamId);
break;
}
break;
default:
logger.debug("Unexpected component: {}", componentId);
break;
}
} catch (CacheException exception) {
String logMessage = format("%s: %s", exception.getErrorMessage(), exception.getErrorDescription());
logger.error("{}, {}={}, {}={}, component={}, stream={}", logMessage, Utils.CORRELATION_ID, correlationId, Utils.FLOW_ID, flowId, componentId, streamId, exception);
ErrorMessage errorMessage = buildErrorMessage(correlationId, exception.getErrorType(), logMessage, componentId.toString().toLowerCase());
Values error = new Values(errorMessage, exception.getErrorType());
outputCollector.emit(StreamType.ERROR.toString(), tuple, error);
} catch (IOException exception) {
logger.error("Could not deserialize message {}", tuple, exception);
} finally {
logger.debug("Command message ack: component={}, stream={}, tuple={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple);
outputCollector.ack(tuple);
}
logger.trace("Flow Cache after: {}", flowCache);
}
use of org.openkilda.messaging.error.CacheException in project open-kilda by telstra.
the class NetworkCache method getIsl.
/**
* Get {@link IslInfoData} instance.
*
* @param islId {@link IslInfoData} instance id
* @return {@link IslInfoData} instance with specified {@link IslInfoData} instance id
* @throws CacheException if {@link IslInfoData} instance with specified id does not exist
*/
public IslInfoData getIsl(String islId) throws CacheException {
logger.debug("Get {} isl", islId);
IslInfoData isl = islPool.get(islId);
if (isl == null) {
throw new CacheException(ErrorType.NOT_FOUND, "Can not get isl", String.format("Isl %s not found", islId));
}
return islPool.get(islId);
}
use of org.openkilda.messaging.error.CacheException in project open-kilda by telstra.
the class NetworkCache method getIslSwitches.
/**
* Gets {@link SwitchInfoData} instances which are incident nodes for specified {@link IslInfoData} instance.
*
* @param isl {@link IslInfoData} instance
* @return {@link EndpointPair} of {@link SwitchInfoData} instances
* @throws CacheException if {@link SwitchInfoData} instances for {@link IslInfoData} instance do not exist
*/
private EndpointPair<SwitchInfoData> getIslSwitches(IslInfoData isl) throws CacheException {
String srcSwitch = isl.getPath().get(0).getSwitchId();
if (srcSwitch == null) {
throw new CacheException(ErrorType.PARAMETERS_INVALID, "Can not get isl nodes", "Source switch not specified");
}
SwitchInfoData startNode = getSwitch(srcSwitch);
String dstSwitch = isl.getPath().get(1).getSwitchId();
if (dstSwitch == null) {
throw new CacheException(ErrorType.PARAMETERS_INVALID, "Can not get isl nodes", "Destination switch not specified");
}
SwitchInfoData endNode = getSwitch(dstSwitch);
return EndpointPair.ordered(startNode, endNode);
}
use of org.openkilda.messaging.error.CacheException in project open-kilda by telstra.
the class NetworkCache method deleteIsl.
/**
* Deletes {@link IslInfoData} instance.
*
* @param islId {@link IslInfoData} instance id
* @return removed {@link IslInfoData} instance
* @throws CacheException if {@link IslInfoData} instance with specified id does not exist
*/
public IslInfoData deleteIsl(String islId) throws CacheException {
logger.debug("Delete {} isl", islId);
IslInfoData isl = islPool.remove(islId);
if (isl == null) {
throw new CacheException(ErrorType.NOT_FOUND, "Can not delete isl", String.format("Isl %s not found", islId));
}
network.removeEdge(isl);
return isl;
}
Aggregations