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