use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.
the class RecordHandler method doDeleteSwitchRules.
private void doDeleteSwitchRules(final CommandMessage message, String replyToTopic, Destination replyDestination) {
SwitchRulesDeleteRequest request = (SwitchRulesDeleteRequest) message.getData();
logger.debug("Deleting rules from '{}' switch: action={}", request.getSwitchId(), request.getDeleteRulesAction());
DatapathId dpid = DatapathId.of(request.getSwitchId());
ISwitchManager switchManager = context.getSwitchManager();
DeleteRulesAction deleteAction = request.getDeleteRulesAction();
List<Long> removedRules = new ArrayList<>();
try {
/*
* This first part .. we are either deleting one rule, or all non-default rules (the else)
*/
List<Long> toRemove = new ArrayList<>();
if (deleteAction == DeleteRulesAction.ONE) {
toRemove.add(request.getOneCookie());
} else if (deleteAction == DeleteRulesAction.REMOVE_DROP) {
toRemove.add(ISwitchManager.DROP_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_BROADCAST) {
toRemove.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_UNICAST) {
toRemove.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
} else if (deleteAction == DeleteRulesAction.REMOVE_DEFAULTS || deleteAction == DeleteRulesAction.REMOVE_ADD) {
toRemove.add(ISwitchManager.DROP_RULE_COOKIE);
toRemove.add(ISwitchManager.VERIFICATION_BROADCAST_RULE_COOKIE);
toRemove.add(ISwitchManager.VERIFICATION_UNICAST_RULE_COOKIE);
}
// toRemove is > 0 only if we are trying to delete base rule(s).
if (toRemove.size() > 0) {
removedRules.addAll(switchManager.deleteRuleWithCookie(dpid, toRemove));
if (deleteAction == DeleteRulesAction.REMOVE_ADD) {
switchManager.installDefaultRules(dpid);
}
} else {
removedRules.addAll(switchManager.deleteAllNonDefaultRules(dpid));
/*
* The Second part - only for a subset of actions.
*/
if (deleteAction == DeleteRulesAction.DROP) {
List<Long> removedDefaultRules = switchManager.deleteDefaultRules(dpid);
// Return removedDefaultRules as a part of the result list.
removedRules.addAll(removedDefaultRules);
} else if (deleteAction == DeleteRulesAction.DROP_ADD) {
switchManager.deleteDefaultRules(dpid);
switchManager.installDefaultRules(dpid);
} else if (deleteAction == DeleteRulesAction.OVERWRITE) {
switchManager.installDefaultRules(dpid);
}
}
SwitchRulesResponse response = new SwitchRulesResponse(removedRules);
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
context.getKafkaProducer().postMessage(replyToTopic, infoMessage);
} catch (SwitchOperationException e) {
ErrorData errorData = new ErrorData(ErrorType.DELETION_FAILURE, e.getMessage(), request.getSwitchId());
ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId(), replyDestination);
context.getKafkaProducer().postMessage(replyToTopic, error);
}
}
use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.
the class SwitchManager method receive.
/**
* {@inheritDoc}
*/
@Override
public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
logger.debug("OF_ERROR: {}", msg);
// TODO: track xid for flow id
if (OFType.ERROR.equals(msg.getType())) {
ErrorMessage error = new ErrorMessage(new ErrorData(ErrorType.INTERNAL_ERROR, ((OFErrorMsg) msg).getErrType().toString(), null), System.currentTimeMillis(), DEFAULT_CORRELATION_ID, Destination.WFM_TRANSACTION);
// TODO: Most/all commands are flow related, but not all. 'kilda.flow' might
// not be the best place to send a generic error.
kafkaProducer.postMessage("kilda.flow", error);
}
return Command.CONTINUE;
}
use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.
the class FlowTopologyTest method shouldFailOnCreatingConflictingFlow.
@Test
public void shouldFailOnCreatingConflictingFlow() throws Exception {
String flowId = UUID.randomUUID().toString();
ConsumerRecord<String, String> record;
createFlow(flowId);
record = cacheConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
createFlow(flowId + "_alt");
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
ErrorMessage errorMessage = objectMapper.readValue(record.value(), ErrorMessage.class);
assertNotNull(errorMessage);
ErrorData errorData = errorMessage.getData();
assertEquals(ErrorType.CREATION_FAILURE, errorData.getErrorType());
}
use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.
the class FlowTopologyTest method errorFlowCreateMessageStatusBoltTopologyEngineBoltTest.
@Test
public void errorFlowCreateMessageStatusBoltTopologyEngineBoltTest() throws Exception {
String flowId = UUID.randomUUID().toString();
ConsumerRecord<String, String> record;
createFlow(flowId);
record = cacheConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
statusFlow(flowId);
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
InfoMessage infoMessageUp = objectMapper.readValue(record.value(), InfoMessage.class);
assertNotNull(infoMessageUp);
FlowStatusResponse infoDataUp = (FlowStatusResponse) infoMessageUp.getData();
assertNotNull(infoDataUp);
FlowIdStatusPayload flowNbPayloadUp = infoDataUp.getPayload();
assertNotNull(flowNbPayloadUp);
assertEquals(flowId, flowNbPayloadUp.getId());
assertEquals(FlowState.ALLOCATED, flowNbPayloadUp.getStatus());
errorFlowTopologyEngineCommand(flowId, ErrorType.CREATION_FAILURE);
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
ErrorMessage errorMessage = objectMapper.readValue(record.value(), ErrorMessage.class);
assertNotNull(errorMessage);
ErrorData errorData = errorMessage.getData();
assertEquals(ErrorType.CREATION_FAILURE, errorData.getErrorType());
statusFlow(flowId);
record = nbConsumer.pollMessage();
assertNotNull(record);
assertNotNull(record.value());
errorMessage = objectMapper.readValue(record.value(), ErrorMessage.class);
assertNotNull(errorMessage);
errorData = errorMessage.getData();
assertEquals(ErrorType.NOT_FOUND, errorData.getErrorType());
}
use of org.openkilda.messaging.error.ErrorData in project open-kilda by telstra.
the class FlowTopologyTest method errorFlowTopologyEngineCommand.
private ErrorMessage errorFlowTopologyEngineCommand(final String flowId, final ErrorType type) throws IOException {
System.out.println("TOPOLOGY: Error flow");
ErrorData errorData = new ErrorData(type, "Could not operate with flow", flowId);
ErrorMessage errorMessage = new ErrorMessage(errorData, 0, "error-flow", Destination.WFM);
// sendTopologyEngineMessage(errorMessage);
sendMessage(errorMessage, topologyConfig.getKafkaFlowTopic());
return errorMessage;
}
Aggregations