Search in sources :

Example 1 with PersistenceException

use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.

the class ActionService method saveFlowLatency.

@Override
public void saveFlowLatency(String flowId, String direction, long latency) {
    try {
        transactionManager.doInTransaction(() -> {
            FlowStats flowStats = flowStatsRepository.findByFlowId(flowId).orElse(null);
            if (flowStats == null) {
                Optional<Flow> flow = flowRepository.findById(flowId);
                if (flow.isPresent()) {
                    FlowStats toCreate = new FlowStats(flow.get(), null, null);
                    flowStatsRepository.add(toCreate);
                    flowStats = toCreate;
                } else {
                    log.warn("Can't save latency for flow '{}'. Flow not found.", flowId);
                    return;
                }
            }
            if (FORWARD.name().toLowerCase().equals(direction)) {
                flowStats.setForwardLatency(latency);
            } else {
                flowStats.setReverseLatency(latency);
            }
        });
    } catch (PersistenceException e) {
        log.error("Can't save latency for flow '{}'.", flowId, e);
    }
}
Also used : FlowStats(org.openkilda.model.FlowStats) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Flow(org.openkilda.model.Flow)

Example 2 with PersistenceException

use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.

the class HibernateHistoryFlowEventRepository method findEntityByTaskId.

/**
 * Fetch and return hibernate {@link HibernateFlowEvent} entity, dedicated to use by others hibernate repositories.
 */
public Optional<HibernateFlowEvent> findEntityByTaskId(String taskId) {
    CriteriaBuilder builder = getSession().getCriteriaBuilder();
    CriteriaQuery<HibernateFlowEvent> query = builder.createQuery(HibernateFlowEvent.class);
    Root<HibernateFlowEvent> root = query.from(HibernateFlowEvent.class);
    query.select(root);
    query.where(builder.equal(root.get(HibernateFlowEvent_.taskId), taskId));
    List<HibernateFlowEvent> results = getSession().createQuery(query).getResultList();
    if (1 < results.size()) {
        throw new PersistenceException(String.format("Unique constraint violation on field %s of %s", HibernateFlowEvent_.taskId, HibernateFlowEvent.class.getName()));
    }
    if (!results.isEmpty()) {
        return Optional.of(results.get(0));
    }
    return Optional.empty();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) HibernateFlowEvent(org.openkilda.persistence.hibernate.entities.history.HibernateFlowEvent)

Example 3 with PersistenceException

use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.

the class GraphSupplier method get.

@Override
public OrientGraph get() {
    PersistenceContext context = PersistenceContextManager.INSTANCE.getContextCreateIfMissing();
    OrientDbContextExtension contextExtension = implementation.getContextExtension(context);
    DelegatingFramedGraph<OrientGraph> wrapper = contextExtension.getGraphCreateIfMissing();
    if (wrapper == null) {
        throw new PersistenceException("Failed to obtain a framed graph");
    }
    return wrapper.getBaseGraph();
}
Also used : OrientGraph(org.apache.tinkerpop.gremlin.orientdb.OrientGraph) OrientDbContextExtension(org.openkilda.persistence.orientdb.OrientDbContextExtension) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceContext(org.openkilda.persistence.context.PersistenceContext)

Example 4 with PersistenceException

use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.

the class FermaGenericRepository method framedGraph.

protected FramedGraph framedGraph() {
    PersistenceContext context = PersistenceContextManager.INSTANCE.getContextCreateIfMissing();
    FermaContextExtension contextExtension = implementation.getContextExtension(context);
    DelegatingFramedGraph<?> graph = contextExtension.getGraphCreateIfMissing();
    if (graph == null) {
        throw new PersistenceException("Failed to obtain a framed graph");
    }
    return graph;
}
Also used : FermaContextExtension(org.openkilda.persistence.ferma.FermaContextExtension) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PersistenceContext(org.openkilda.persistence.context.PersistenceContext)

Example 5 with PersistenceException

use of org.openkilda.persistence.exceptions.PersistenceException in project open-kilda by telstra.

the class FermaMirrorGroupRepository method exists.

@Override
public boolean exists(SwitchId switchId, GroupId groupId) {
    String switchIdAsStr = SwitchIdConverter.INSTANCE.toGraphProperty(switchId);
    Long groupIdAsLong = GroupIdConverter.INSTANCE.toGraphProperty(groupId);
    try (GraphTraversal<?, ?> traversal = framedGraph().traverse(g -> g.V().hasLabel(FlowMeterFrame.FRAME_LABEL).has(MirrorGroupFrame.GROUP_ID_PROPERTY, groupIdAsLong).has(MirrorGroupFrame.SWITCH_ID_PROPERTY, switchIdAsStr)).getRawTraversal()) {
        return traversal.hasNext();
    } catch (Exception e) {
        throw new PersistenceException("Failed to traverse", e);
    }
}
Also used : GroupIdConverter(org.openkilda.persistence.ferma.frames.converters.GroupIdConverter) Collection(java.util.Collection) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) 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) MirrorGroupData(org.openkilda.model.MirrorGroup.MirrorGroupData) MirrorGroupRepository(org.openkilda.persistence.repositories.MirrorGroupRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) MirrorGroup(org.openkilda.model.MirrorGroup) MirrorGroupFrame(org.openkilda.persistence.ferma.frames.MirrorGroupFrame) Optional(java.util.Optional) FlowMeterFrame(org.openkilda.persistence.ferma.frames.FlowMeterFrame) KildaBaseVertexFrame(org.openkilda.persistence.ferma.frames.KildaBaseVertexFrame) GroupId(org.openkilda.model.GroupId) 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)

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