Search in sources :

Example 6 with InfoData

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;
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 7 with InfoData

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;
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 8 with InfoData

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);
}
Also used : SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InfoData(org.openkilda.messaging.info.InfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 9 with InfoData

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);
}
Also used : IslInfoData(org.openkilda.messaging.info.event.IslInfoData) InfoData(org.openkilda.messaging.info.InfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 10 with InfoData

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);
        }
    }
}
Also used : HeartBeat(org.openkilda.messaging.HeartBeat) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) BaseMessage(org.openkilda.messaging.BaseMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) NetworkInfoData(org.openkilda.messaging.info.discovery.NetworkInfoData) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) InfoData(org.openkilda.messaging.info.InfoData) PortInfoData(org.openkilda.messaging.info.event.PortInfoData) IslInfoData(org.openkilda.messaging.info.event.IslInfoData) IOException(java.io.IOException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Aggregations

InfoData (org.openkilda.messaging.info.InfoData)12 InfoMessage (org.openkilda.messaging.info.InfoMessage)8 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)5 IOException (java.io.IOException)4 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)4 Message (org.openkilda.messaging.Message)3 CommandMessage (org.openkilda.messaging.command.CommandMessage)3 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)3 FlowInfoData (org.openkilda.messaging.info.flow.FlowInfoData)3 Values (org.apache.storm.tuple.Values)2 BaseMessage (org.openkilda.messaging.BaseMessage)2 CommandData (org.openkilda.messaging.command.CommandData)2 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)2 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)2 FlowGetRequest (org.openkilda.messaging.command.flow.FlowGetRequest)2 FlowPathRequest (org.openkilda.messaging.command.flow.FlowPathRequest)2 FlowUpdateRequest (org.openkilda.messaging.command.flow.FlowUpdateRequest)2 FlowsGetRequest (org.openkilda.messaging.command.flow.FlowsGetRequest)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2