Search in sources :

Example 6 with MessageException

use of org.openkilda.messaging.error.MessageException 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 MessageException

use of org.openkilda.messaging.error.MessageException in project open-kilda by telstra.

the class FlowServiceImpl method getFlow.

/**
 * {@inheritDoc}
 */
@Override
public InfoMessage getFlow(final FlowIdStatusPayload payload, final String correlationId) {
    Set<Flow> flows = flowRepository.findByFlowId(payload.getId());
    if (flows == null || flows.isEmpty()) {
        logger.error("Flow with id={} not found", payload.getId());
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    FlowResponse response = null;
    for (Flow flow : flows) {
        if ((flow.getCookie() & DIRECT_FLOW_COOKIE) == DIRECT_FLOW_COOKIE) {
            response = new FlowResponse(getFlowPayloadByFlow(flow));
        }
    }
    logger.debug("Flow with id={} get: {}", payload.getId(), response);
    return new InfoMessage(response, System.currentTimeMillis(), correlationId, Destination.WFM);
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) Flow(org.openkilda.topology.domain.Flow)

Example 8 with MessageException

use of org.openkilda.messaging.error.MessageException in project open-kilda by telstra.

the class IslServiceImpl method dropLink.

/**
 * {@inheritDoc}
 */
@Override
public void dropLink(final IslInfoData data) {
    logger.debug("Isl drop: isl={}", data);
    PathNode sourceNode = data.getPath().get(0);
    PathNode destinationNode = data.getPath().get(1);
    Switch sourceSwitch = switchRepository.findByName(sourceNode.getSwitchId());
    Switch destinationSwitch = switchRepository.findByName(destinationNode.getSwitchId());
    if (sourceSwitch == null || destinationSwitch == null) {
        logger.error("Could not find switch: source={}, destination={}", sourceSwitch, destinationSwitch);
        return;
    }
    Isl isl = islRepository.findIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
    logger.debug("Isl relationship found: {}", isl);
    if (isl == null) {
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    // TODO: replace queries on Spring auto generated
    // islRepository.delete(isl);
    islRepository.deleteIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
    logger.debug("Isl delete relationship: isl={}", isl);
}
Also used : Isl(org.openkilda.topology.domain.Isl) Switch(org.openkilda.topology.domain.Switch) MessageException(org.openkilda.messaging.error.MessageException) PathNode(org.openkilda.messaging.info.event.PathNode)

Example 9 with MessageException

use of org.openkilda.messaging.error.MessageException in project open-kilda by telstra.

the class SwitchServiceImpl method add.

/**
 * {@inheritDoc}
 */
@Override
public Switch add(final SwitchInfoData data) {
    String name = data.getSwitchId();
    String state = SwitchStateType.INACTIVE.toString().toLowerCase();
    logger.debug("Switch adding: switch-id={}", name);
    Switch sw = switchRepository.findByName(name);
    if (sw != null) {
        throw new MessageException(ErrorType.ALREADY_EXISTS, System.currentTimeMillis());
    }
    sw = new Switch(name, state, data.getAddress(), data.getHostname(), data.getDescription());
    sw.setLabels(state, data.getDescription());
    switchRepository.save(sw);
    return sw;
}
Also used : Switch(org.openkilda.topology.domain.Switch) MessageException(org.openkilda.messaging.error.MessageException)

Example 10 with MessageException

use of org.openkilda.messaging.error.MessageException in project open-kilda by telstra.

the class SwitchServiceImpl method remove.

/**
 * {@inheritDoc}
 */
@Override
public Switch remove(final SwitchInfoData data) {
    String name = data.getSwitchId();
    logger.debug("Switch removing: switch-id={}", name);
    Switch sw = switchRepository.findByName(name);
    if (sw == null) {
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    switchRepository.delete(sw);
    return sw;
}
Also used : Switch(org.openkilda.topology.domain.Switch) MessageException(org.openkilda.messaging.error.MessageException)

Aggregations

MessageException (org.openkilda.messaging.error.MessageException)15 InfoMessage (org.openkilda.messaging.info.InfoMessage)6 Switch (org.openkilda.topology.domain.Switch)6 Values (org.apache.storm.tuple.Values)4 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)4 Flow (org.openkilda.messaging.model.Flow)4 UnroutablePathException (org.openkilda.pce.provider.UnroutablePathException)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 InfoData (org.openkilda.messaging.info.InfoData)2 Flow (org.openkilda.topology.domain.Flow)2 Isl (org.openkilda.topology.domain.Isl)2 FlowValidationException (org.openkilda.wfm.topology.flow.validation.FlowValidationException)2 FlowValidator (org.openkilda.wfm.topology.flow.validation.FlowValidator)2 SendResult (org.springframework.kafka.support.SendResult)2 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1