use of org.openkilda.wfm.error.LinkPropsException in project open-kilda by telstra.
the class LinkOperationsBolt method createOrUpdateProps.
private LinkProps createOrUpdateProps(LinkProps linkPropsToSet) throws MessageException {
return transactionManager.doInTransaction(() -> {
Collection<LinkProps> existingLinkProps = linkPropsRepository.findByEndpoints(linkPropsToSet.getSrcSwitchId(), linkPropsToSet.getSrcPort(), linkPropsToSet.getDstSwitchId(), linkPropsToSet.getDstPort());
LinkProps linkProps;
if (!existingLinkProps.isEmpty()) {
linkProps = existingLinkProps.iterator().next();
if (linkPropsToSet.getCost() != null) {
linkProps.setCost(linkPropsToSet.getCost());
}
if (linkPropsToSet.getMaxBandwidth() != null) {
linkProps.setMaxBandwidth(linkPropsToSet.getMaxBandwidth());
}
} else {
linkProps = new LinkProps(linkPropsToSet);
linkPropsRepository.add(linkProps);
}
Optional<Isl> existingIsl = islRepository.findByEndpoints(linkPropsToSet.getSrcSwitchId(), linkPropsToSet.getSrcPort(), linkPropsToSet.getDstSwitchId(), linkPropsToSet.getDstPort());
existingIsl.ifPresent(link -> {
if (linkPropsToSet.getCost() != null) {
link.setCost(linkPropsToSet.getCost());
}
if (linkPropsToSet.getMaxBandwidth() != null) {
long currentMaxBandwidth = link.getMaxBandwidth();
long currentAvailableBandwidth = link.getAvailableBandwidth();
long availableBandwidth = linkPropsToSet.getMaxBandwidth() - (currentMaxBandwidth - currentAvailableBandwidth);
link.setMaxBandwidth(linkPropsToSet.getMaxBandwidth());
if (availableBandwidth < 0) {
throw new LinkPropsException("Not enough available bandwidth for operation");
}
link.setAvailableBandwidth(availableBandwidth);
}
});
return linkProps;
});
}
use of org.openkilda.wfm.error.LinkPropsException in project open-kilda by telstra.
the class LinkOperationsBolt method putLinkProps.
private LinkPropsResponse putLinkProps(LinkPropsPut request) {
try {
LinkProps toSetForward = LinkPropsMapper.INSTANCE.map(request.getLinkProps());
LinkProps toSetBackward = swapLinkProps(toSetForward);
LinkProps result = createOrUpdateProps(toSetForward);
createOrUpdateProps(toSetBackward);
return new LinkPropsResponse(request, LinkPropsMapper.INSTANCE.map(result), null);
} catch (LinkPropsException e) {
throw new MessageException(ErrorType.DATA_INVALID, "Can't create/update link props", e.getMessage());
} catch (Exception e) {
log.error("Unhandled exception in create or update linkprops operation.", e);
return new LinkPropsResponse(request, null, e.getMessage());
}
}
Aggregations