use of org.openkilda.messaging.MessageData in project open-kilda by telstra.
the class KafkaEncoder method handleInput.
@Override
protected void handleInput(Tuple input) throws Exception {
MessageData payload = pullPayload(input);
try {
Message message = wrap(pullContext(input), payload);
getOutput().emit(input, new Values(pullKey(input), message));
} catch (IllegalArgumentException e) {
log.error(e.getMessage());
unhandledInput(input);
}
}
use of org.openkilda.messaging.MessageData in project open-kilda by telstra.
the class OnReceivedYFlowResourcesAction method perform.
@Override
public void perform(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) {
MessageData data = context.getSpeakerResponse();
if (data instanceof SwitchFlowEntries) {
SwitchFlowEntries switchFlowEntries = (SwitchFlowEntries) data;
log.info("Switch rules received for switch {}", switchFlowEntries.getSwitchId());
stateMachine.getReceivedRules().add(switchFlowEntries);
stateMachine.setAwaitingRules(stateMachine.getAwaitingRules() - 1);
checkOfCompleteDataCollection(stateMachine);
} else if (data instanceof SwitchMeterEntries) {
SwitchMeterEntries switchMeterEntries = (SwitchMeterEntries) data;
log.info("Switch meters received for switch {}", switchMeterEntries.getSwitchId());
stateMachine.getReceivedMeters().add(switchMeterEntries);
stateMachine.setAwaitingMeters(stateMachine.getAwaitingMeters() - 1);
checkOfCompleteDataCollection(stateMachine);
} else if (data instanceof SwitchMeterUnsupported) {
SwitchMeterUnsupported meterUnsupported = (SwitchMeterUnsupported) data;
log.info("Meters unsupported for switch {}", meterUnsupported.getSwitchId());
stateMachine.getReceivedMeters().add(SwitchMeterEntries.builder().switchId(meterUnsupported.getSwitchId()).meterEntries(Collections.emptyList()).build());
stateMachine.setAwaitingMeters(stateMachine.getAwaitingMeters() - 1);
checkOfCompleteDataCollection(stateMachine);
} else if (data instanceof ErrorData) {
ErrorData errorData = (ErrorData) data;
String errorMessage = format("%s : %s", errorData.getErrorMessage(), errorData.getErrorDescription());
stateMachine.fireError(errorMessage);
} else {
String errorMessage = format("Unhandled message : %s", data);
stateMachine.fireError(errorMessage);
}
}
use of org.openkilda.messaging.MessageData in project open-kilda by telstra.
the class RecordHandler method dumpRuleManagerMeters.
private void dumpRuleManagerMeters(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Get all meters for switch {}", switchId);
ISwitchManager switchManager = context.getSwitchManager();
DatapathId datapathId = DatapathId.of(switchId.toLong());
List<OFMeterConfig> meterEntries = switchManager.dumpMeters(datapathId);
IOFSwitch iofSwitch = switchManager.lookupSwitch(datapathId);
boolean inaccurate = featureDetectorService.detectSwitch(iofSwitch).contains(SwitchFeature.INACCURATE_METER);
List<MeterSpeakerData> meters = meterEntries.stream().map(entry -> org.openkilda.floodlight.converter.rulemanager.OfMeterConverter.INSTANCE.convertToMeterSpeakerData(entry, inaccurate)).collect(Collectors.toList());
MeterDumpResponse response = MeterDumpResponse.builder().switchId(switchId).meterSpeakerData(meters).build();
sender.accept(response);
} catch (UnsupportedSwitchOperationException e) {
logger.info("Meters not supported: {}", switchId);
sender.accept(new SwitchMeterUnsupported(switchId));
} catch (SwitchNotFoundException e) {
logger.info("Dumping switch meters is unsuccessful. Switch {} not found", switchId);
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(switchId.toString()).buildData();
sender.accept(errorData);
} catch (SwitchOperationException e) {
logger.error("Unable to dump meters", e);
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("Unable to dump meters").buildData();
sender.accept(errorData);
}
}
use of org.openkilda.messaging.MessageData in project open-kilda by telstra.
the class OperationQueueBolt method handleInput.
@Override
protected void handleInput(Tuple tuple) throws PipelineException {
CommandContext context = pullContext(tuple);
MessageData data = pullValue(tuple, FIELD_ID_PAYLOAD, MessageData.class);
if (data instanceof FlowPathSwapRequest) {
FlowPathSwapRequest flowPathSwapRequest = (FlowPathSwapRequest) data;
service.addFirst(flowPathSwapRequest.getFlowId(), context.getCorrelationId(), flowPathSwapRequest);
} else if (data instanceof FlowRerouteRequest) {
FlowRerouteRequest flowRerouteRequest = (FlowRerouteRequest) data;
service.addLast(flowRerouteRequest.getFlowId(), context.getCorrelationId(), flowRerouteRequest);
} else if (data instanceof YFlowRerouteRequest) {
YFlowRerouteRequest yFlowRerouteRequest = (YFlowRerouteRequest) data;
service.addLast(yFlowRerouteRequest.getYFlowId(), context.getCorrelationId(), yFlowRerouteRequest);
} else if (data instanceof RerouteResultInfoData) {
RerouteResultInfoData rerouteResultInfoData = (RerouteResultInfoData) data;
service.operationCompleted(rerouteResultInfoData.getFlowId(), rerouteResultInfoData);
emitRerouteResponse(rerouteResultInfoData);
} else if (data instanceof PathSwapResult) {
PathSwapResult pathSwapResult = (PathSwapResult) data;
service.operationCompleted(pathSwapResult.getFlowId(), pathSwapResult);
} else {
unhandledInput(tuple);
}
}
use of org.openkilda.messaging.MessageData in project open-kilda by telstra.
the class RecordHandler method processDumpRuleManagerRulesRequest.
private void processDumpRuleManagerRulesRequest(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Loading installed rules for switch {}", switchId);
List<OFFlowStatsEntry> flowEntries = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId.toLong()));
List<FlowSpeakerData> flows = flowEntries.stream().map(entry -> OfFlowConverter.INSTANCE.convertToFlowSpeakerData(entry, switchId)).collect(Collectors.toList());
FlowDumpResponse response = FlowDumpResponse.builder().switchId(switchId).flowSpeakerData(flows).build();
sender.accept(response);
} catch (SwitchNotFoundException e) {
logger.error("Dumping of rules on switch '{}' was unsuccessful: {}", switchId, e.getMessage());
ErrorData errorData = anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription("The switch was not found when requesting a rules dump.").buildData();
sender.accept(errorData);
}
}
Aggregations