Search in sources :

Example 1 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class FermaLinkPropsRepositoryTest method shouldDeleteLinkProps.

@Test
public void shouldDeleteLinkProps() {
    LinkProps linkProps = createLinkProps(1);
    transactionManager.doInTransaction(() -> {
        linkPropsRepository.remove(linkProps);
    });
    assertEquals(0, linkPropsRepository.findAll().size());
}
Also used : LinkProps(org.openkilda.model.LinkProps) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 2 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class LinkOperationsBolt method deleteLinkProps.

private LinkProps deleteLinkProps(LinkProps fwdLinkProps, LinkProps rvsLinkProps) {
    List<LinkProps> linkProperties = Arrays.asList(rvsLinkProps, fwdLinkProps);
    return transactionManager.doInTransaction(() -> {
        LinkProps linkProps = null;
        for (LinkProps linkPropsToDrop : linkProperties) {
            Collection<LinkProps> existingLinkProps = linkPropsRepository.findByEndpoints(linkPropsToDrop.getSrcSwitchId(), linkPropsToDrop.getSrcPort(), linkPropsToDrop.getDstSwitchId(), linkPropsToDrop.getDstPort());
            if (!existingLinkProps.isEmpty()) {
                linkProps = existingLinkProps.iterator().next();
                linkPropsRepository.remove(linkProps);
            }
            Optional<Isl> existingIsl = islRepository.findByEndpoints(linkPropsToDrop.getSrcSwitchId(), linkPropsToDrop.getSrcPort(), linkPropsToDrop.getDstSwitchId(), linkPropsToDrop.getDstPort());
            long propsMaxBandwidth = (linkProps != null ? linkProps.getMaxBandwidth() : null) != null ? linkProps.getMaxBandwidth() : 0L;
            existingIsl.ifPresent(link -> {
                link.setCost(0);
                link.setMaxBandwidth(link.getDefaultMaxBandwidth());
                if (propsMaxBandwidth > 0) {
                    long availableBandwidth = link.getDefaultMaxBandwidth() - (propsMaxBandwidth - link.getAvailableBandwidth());
                    link.setAvailableBandwidth(availableBandwidth);
                }
            });
        }
        return linkProps;
    });
}
Also used : Isl(org.openkilda.model.Isl) LinkProps(org.openkilda.model.LinkProps)

Example 3 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class LinkOperationsBolt method swapLinkProps.

private LinkProps swapLinkProps(LinkProps source) {
    LinkProps result = new LinkProps(source);
    result.setSrcSwitchId(source.getDstSwitchId());
    result.setSrcPort(source.getDstPort());
    result.setDstSwitchId(source.getSrcSwitchId());
    result.setDstPort(source.getSrcPort());
    return result;
}
Also used : LinkProps(org.openkilda.model.LinkProps)

Example 4 with LinkProps

use of org.openkilda.model.LinkProps 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 5 with LinkProps

use of org.openkilda.model.LinkProps in project open-kilda by telstra.

the class LinkOperationsBolt method getLinkProps.

private List<LinkPropsData> getLinkProps(LinkPropsGet request) {
    Integer srcPort = request.getSource().getPortNumber();
    SwitchId srcSwitch = request.getSource().getDatapath();
    Integer dstPort = request.getDestination().getPortNumber();
    SwitchId dstSwitch = request.getDestination().getDatapath();
    Collection<LinkProps> linkProps = linkPropsRepository.findByEndpoints(srcSwitch, srcPort, dstSwitch, dstPort);
    return linkProps.stream().map(LinkPropsMapper.INSTANCE::map).map(LinkPropsData::new).collect(Collectors.toList());
}
Also used : SwitchId(org.openkilda.model.SwitchId) LinkProps(org.openkilda.model.LinkProps)

Aggregations

LinkProps (org.openkilda.model.LinkProps)14 LinkPropsException (org.openkilda.wfm.error.LinkPropsException)3 InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)2 MessageException (org.openkilda.messaging.error.MessageException)2 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)2 Isl (org.openkilda.model.Isl)2 IllegalIslStateException (org.openkilda.wfm.error.IllegalIslStateException)2 IslNotFoundException (org.openkilda.wfm.error.IslNotFoundException)2 HttpResponse (org.apache.http.HttpResponse)1 Test (org.junit.Test)1 SwitchId (org.openkilda.model.SwitchId)1 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1