Search in sources :

Example 6 with PersistenceException

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;
}
Also used : IslFrame(org.openkilda.persistence.ferma.frames.IslFrame) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException)

Example 7 with PersistenceException

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);
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) TransactionRequired(org.openkilda.persistence.tx.TransactionRequired) PathSegmentData(org.openkilda.model.PathSegment.PathSegmentData) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) List(java.util.List) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) IslRepository(org.openkilda.persistence.repositories.IslRepository) Optional(java.util.Optional) Comparator(java.util.Comparator) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) PathSegmentFrame(org.openkilda.persistence.ferma.frames.PathSegmentFrame) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PathSegment(org.openkilda.model.PathSegment) TransactionRequired(org.openkilda.persistence.tx.TransactionRequired)

Example 8 with PersistenceException

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();
}
Also used : FlowMeter(org.openkilda.model.FlowMeter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) FlowMeterData(org.openkilda.model.FlowMeter.FlowMeterData) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) MeterIdConverter(org.openkilda.persistence.ferma.frames.converters.MeterIdConverter) MeterId(org.openkilda.model.MeterId) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException)

Example 9 with PersistenceException

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);
    }
}
Also used : FlowMeter(org.openkilda.model.FlowMeter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) FlowMeterData(org.openkilda.model.FlowMeter.FlowMeterData) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) FermaPersistentImplementation(org.openkilda.persistence.ferma.FermaPersistentImplementation) SwitchIdConverter(org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Collectors(java.util.stream.Collectors) MeterIdConverter(org.openkilda.persistence.ferma.frames.converters.MeterIdConverter) MeterId(org.openkilda.model.MeterId) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) PathIdConverter(org.openkilda.persistence.ferma.frames.converters.PathIdConverter) PathId(org.openkilda.model.PathId) P(org.apache.tinkerpop.gremlin.process.traversal.P) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException)

Example 10 with PersistenceException

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");
    }
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) PortFsm(org.openkilda.wfm.topology.network.controller.port.PortFsm) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PortFsmEvent(org.openkilda.wfm.topology.network.controller.port.PortFsm.PortFsmEvent) PortProperties(org.openkilda.model.PortProperties) PortFsmContext(org.openkilda.wfm.topology.network.controller.port.PortFsm.PortFsmContext)

Aggregations

PersistenceException (org.openkilda.persistence.exceptions.PersistenceException)16 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 PathId (org.openkilda.model.PathId)6 Collection (java.util.Collection)5 Optional (java.util.Optional)5 FermaPersistentImplementation (org.openkilda.persistence.ferma.FermaPersistentImplementation)5 PathIdConverter (org.openkilda.persistence.ferma.frames.converters.PathIdConverter)5 P (org.apache.tinkerpop.gremlin.process.traversal.P)4 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)4 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)4 SwitchId (org.openkilda.model.SwitchId)4 FlowMeterFrame (org.openkilda.persistence.ferma.frames.FlowMeterFrame)4 KildaBaseVertexFrame (org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame)4 SwitchIdConverter (org.openkilda.persistence.ferma.frames.converters.SwitchIdConverter)4 OrientGraph (org.apache.tinkerpop.gremlin.orientdb.OrientGraph)2 Flow (org.openkilda.model.Flow)2 FlowMeter (org.openkilda.model.FlowMeter)2 FlowMeterData (org.openkilda.model.FlowMeter.FlowMeterData)2 FlowPath (org.openkilda.model.FlowPath)2