use of org.openkilda.floodlight.error.UnsupportedSwitchOperationException in project open-kilda by telstra.
the class RecordHandler method dumpMeters.
private void dumpMeters(SwitchId switchId, java.util.function.Consumer<MessageData> sender) {
try {
logger.debug("Get all meters for switch {}", switchId);
ISwitchManager switchManager = context.getSwitchManager();
List<OFMeterConfig> meterEntries = switchManager.dumpMeters(DatapathId.of(switchId.toLong()));
List<MeterEntry> meters = meterEntries.stream().map(OfMeterConverter::toMeterEntry).collect(Collectors.toList());
SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(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.floodlight.error.UnsupportedSwitchOperationException 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.floodlight.error.UnsupportedSwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doModifyMeterRequest.
private void doModifyMeterRequest(CommandMessage message) {
MeterModifyCommandRequest request = (MeterModifyCommandRequest) message.getData();
final IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaNbWorkerTopic();
SwitchId switchId = request.getSwitchId();
DatapathId datapathId = DatapathId.of(switchId.toLong());
long meterId = request.getMeterId();
ISwitchManager switchManager = context.getSwitchManager();
try {
switchManager.modifyMeterForFlow(datapathId, meterId, request.getBandwidth());
MeterEntry meterEntry = OfMeterConverter.toMeterEntry(switchManager.dumpMeterById(datapathId, meterId));
SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(ImmutableList.of(meterEntry)).build();
InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
} catch (UnsupportedSwitchOperationException e) {
String messageString = String.format("Not supported: %s", new SwitchId(e.getDpId().getLong()));
logger.error(messageString, e);
anError(ErrorType.PARAMETERS_INVALID).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
} catch (SwitchNotFoundException e) {
logger.error("Update switch meters is unsuccessful. Switch {} not found", new SwitchId(e.getDpId().getLong()));
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(new SwitchId(e.getDpId().getLong()).toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
} catch (SwitchOperationException e) {
String messageString = "Unable to update meter";
logger.error(messageString, e);
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.floodlight.error.UnsupportedSwitchOperationException in project open-kilda by telstra.
the class RecordHandler method doModifyDefaultMeterForSwitchManager.
private void doModifyDefaultMeterForSwitchManager(CommandMessage message) {
ModifyDefaultMeterForSwitchManagerRequest request = (ModifyDefaultMeterForSwitchManagerRequest) message.getData();
IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaSwitchManagerTopic();
long meterId = request.getMeterId();
SwitchId switchId = request.getSwitchId();
DatapathId dpid = DatapathId.of(switchId.toLong());
try {
context.getSwitchManager().modifyDefaultMeter(dpid, request.getMeterId());
InfoMessage response = new InfoMessage(new ModifyMeterResponse(switchId, request.getMeterId()), System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
} catch (UnsupportedSwitchOperationException e) {
logger.warn(format("Skip meter %d modification on switch %s because switch doesn't support meters", meterId, switchId), e);
} catch (InvalidMeterIdException | OfInstallException | SwitchNotFoundException e) {
logger.error("Failed to modify meter {} for switch: '{}'", request.getSwitchId(), meterId, e);
ErrorType errorType;
if (e instanceof InvalidMeterIdException) {
errorType = ErrorType.DATA_INVALID;
} else if (e instanceof SwitchNotFoundException) {
errorType = ErrorType.NOT_FOUND;
} else {
errorType = ErrorType.INTERNAL_ERROR;
}
anError(errorType).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.floodlight.error.UnsupportedSwitchOperationException in project open-kilda by telstra.
the class MetersResource method getMeters.
// FIXME(surabujin): is it used anywhere?
/**
* Gets meters.
* @return the map of meters.
*/
@Get("json")
@SuppressWarnings("unchecked")
public Map<Long, Object> getMeters() {
Map<Long, Object> response = new HashMap<>();
String switchId = (String) this.getRequestAttributes().get("switch_id");
logger.debug("Get meters for switch: {}", switchId);
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
try {
List<OFMeterConfig> meters = switchManager.dumpMeters(DatapathId.of(switchId));
if (meters != null) {
logger.debug("Meters from switch {} received: {}", switchId, meters.size());
for (OFMeterConfig entry : meters) {
response.put(entry.getMeterId(), entry);
}
}
} catch (UnsupportedSwitchOperationException ex) {
String messageString = "Not supported";
logger.error("{}: {}", messageString, switchId, ex);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, ex.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
getResponse().setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED);
} catch (IllegalArgumentException | SwitchOperationException exception) {
String messageString = "No such switch";
logger.error("{}: {}", messageString, switchId, exception);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
}
return response;
}
Aggregations