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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations