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());
}
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;
});
}
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;
}
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;
});
}
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());
}
Aggregations