use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class FermaIslRepository method updateAvailableBandwidth.
private long updateAvailableBandwidth(FramedGraph framedGraph, String srcSwitchId, int srcPort, String dstSwitchId, int dstPort, long usedBandwidth) {
log.debug("Updating ISL {}_{} - {}_{} with used bandwidth {}", srcSwitchId, srcPort, dstSwitchId, dstPort, usedBandwidth);
IslFrame isl = findIsl(framedGraph, srcSwitchId, srcPort, dstSwitchId, dstPort).orElseThrow(() -> new PersistenceException(format("ISL %s_%d - %s_%d not found to be updated", srcSwitchId, srcPort, dstSwitchId, dstPort)));
long updatedAvailableBandwidth = isl.getMaxBandwidth() - usedBandwidth;
isl.setAvailableBandwidth(updatedAvailableBandwidth);
return updatedAvailableBandwidth;
}
use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class FermaPathSegmentRepository method updateFailedStatus.
@Override
@TransactionRequired
public void updateFailedStatus(FlowPath path, PathSegment segment, boolean failed) {
PathSegment segmentToUpdate;
if (segment.getData() instanceof PathSegmentFrame) {
segmentToUpdate = segment;
} else {
segmentToUpdate = path.getSegments().stream().filter(pathSegment -> pathSegment.getSrcSwitchId().equals(segment.getSrcSwitchId()) && pathSegment.getSrcPort() == segment.getSrcPort() && pathSegment.getDestSwitchId().equals(segment.getDestSwitchId()) && pathSegment.getDestPort() == segment.getDestPort()).findAny().orElse(null);
}
if (segmentToUpdate == null) {
throw new PersistenceException(format("PathSegment not found to be updated: %s_%d - %s_%d. Path id: %s.", segment.getSrcSwitchId(), segment.getSrcPort(), segment.getDestSwitchId(), segment.getDestPort(), path.getPathId()));
}
segmentToUpdate.setFailed(failed);
}
use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class FermaFlowMeterRepository method findFirstUnassignedMeter.
@Override
public Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId, MeterId highestMeterId) {
String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
Long lowestMeterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(lowestMeterId);
Long highestMeterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(highestMeterId);
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, P.gte(lowestMeterIdAsLong)).has(FlowMeterFrame.METER_ID_PROPERTY, P.lt(highestMeterIdAsLong)).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr).values(FlowMeterFrame.METER_ID_PROPERTY).order().math("_ + 1").as("a").where(__.not(__.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr).values(FlowMeterFrame.METER_ID_PROPERTY).where(P.eq("a")))).select("a").limit(1)).getRawTraversal()) {
if (traversal.hasNext()) {
return traversal.tryNext().map(l -> ((Double) l).longValue()).map(MeterIdConverter.INSTANCE::toEntityAttribute);
}
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, lowestMeterIdAsLong).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr)).getRawTraversal()) {
if (!traversal.hasNext()) {
return Optional.of(lowestMeterId);
}
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
return Optional.empty();
}
use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class FermaFlowMeterRepository method exists.
@Override
public boolean exists(SwitchId switchId, MeterId meterId) {
String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
Long meterIdAsLong = MeterIdConverter.INSTANCE.toGraphProperty(meterId);
try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(FlowMeterFrame.METER_ID_PROPERTY, meterIdAsLong).has(FlowMeterFrame.SWITCH_PROPERTY, switchIdAsStr)).getRawTraversal()) {
return traversal.hasNext();
} catch (Exception e) {
throw new PersistenceException("Failed to traverse", e);
}
}
use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.
the class NetworkPortService method updatePortProperties.
/**
* Update port properties.
*/
public void updatePortProperties(Endpoint endpoint, boolean discoveryEnabled) {
try {
transactionManager.doInTransaction(() -> {
PortProperties portProperties = savePortProperties(endpoint, discoveryEnabled);
PortFsm portFsm = locateController(endpoint);
PortFsmContext context = PortFsmContext.builder(carrier).build();
PortFsmEvent event = discoveryEnabled ? PortFsmEvent.ENABLE_DISCOVERY : PortFsmEvent.DISABLE_DISCOVERY;
controllerExecutor.fire(portFsm, event, context);
carrier.notifyPortPropertiesChanged(portProperties);
});
} catch (PersistenceException e) {
String message = format("Could not update port properties for '%s': %s", endpoint, e.getMessage());
throw new MessageException(NOT_FOUND, message, "Persistence exception");
} catch (IllegalStateException e) {
// Rollback if port is not found. It's allowed to change port properties for already existing ports only.
String message = format("Port not found: '%s'", e.getMessage());
throw new MessageException(NOT_FOUND, message, "Port not found exception");
}
}
Aggregations