Search in sources :

Example 1 with LinkPropsException

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;
    });
}
Also used : Isl(org.openkilda.model.Isl) LinkPropsException(org.openkilda.wfm.error.LinkPropsException) LinkProps(org.openkilda.model.LinkProps)

Example 2 with LinkPropsException

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());
    }
}
Also used : LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) LinkPropsException(org.openkilda.wfm.error.LinkPropsException) MessageException(org.openkilda.messaging.error.MessageException) LinkProps(org.openkilda.model.LinkProps) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) LinkPropsException(org.openkilda.wfm.error.LinkPropsException) IllegalIslStateException(org.openkilda.wfm.error.IllegalIslStateException)

Aggregations

LinkProps (org.openkilda.model.LinkProps)2 LinkPropsException (org.openkilda.wfm.error.LinkPropsException)2 MessageException (org.openkilda.messaging.error.MessageException)1 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)1 Isl (org.openkilda.model.Isl)1 IllegalIslStateException (org.openkilda.wfm.error.IllegalIslStateException)1 IslNotFoundException (org.openkilda.wfm.error.IslNotFoundException)1