Search in sources :

Example 1 with NoSuchRecordException

use of org.neo4j.driver.v1.exceptions.NoSuchRecordException in project open-kilda by telstra.

the class NeoDriver method getPath.

/**
 * {@inheritDoc}
 */
@Override
public ImmutablePair<PathInfoData, PathInfoData> getPath(Flow flow, Strategy strategy) throws UnroutablePathException {
    long latency = 0L;
    List<PathNode> forwardNodes = new LinkedList<>();
    List<PathNode> reverseNodes = new LinkedList<>();
    if (!flow.isOneSwitchFlow()) {
        Statement statement = getPathQuery(flow, strategy);
        logger.debug("QUERY: {}", statement.toString());
        try (Session session = driver.session()) {
            StatementResult result = session.run(statement);
            try {
                Record record = result.next();
                LinkedList<Relationship> isls = new LinkedList<>();
                record.get(0).asPath().relationships().forEach(isls::add);
                int seqId = 0;
                for (Relationship isl : isls) {
                    latency += isl.get("latency").asLong();
                    forwardNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, isl.get("latency").asLong()));
                    seqId++;
                    forwardNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, 0L));
                    seqId++;
                }
                seqId = 0;
                Collections.reverse(isls);
                for (Relationship isl : isls) {
                    reverseNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, isl.get("latency").asLong()));
                    seqId++;
                    reverseNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, 0L));
                    seqId++;
                }
            } catch (NoSuchRecordException e) {
                throw new UnroutablePathException(flow);
            }
        }
    } else {
        logger.info("No path computation for one-switch flow");
    }
    return new ImmutablePair<>(new PathInfoData(latency, forwardNodes), new PathInfoData(latency, reverseNodes));
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Statement(org.neo4j.driver.v1.Statement) PathNode(org.openkilda.messaging.info.event.PathNode) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Relationship(org.neo4j.driver.v1.types.Relationship) Record(org.neo4j.driver.v1.Record) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException) Session(org.neo4j.driver.v1.Session)

Example 2 with NoSuchRecordException

use of org.neo4j.driver.v1.exceptions.NoSuchRecordException in project structr by structr.

the class SessionTransaction method getStrings.

public QueryResult<String> getStrings(final String statement, final Map<String, Object> map) {
    final long t0 = System.currentTimeMillis();
    try {
        final StatementResult result = tx.run(statement, map);
        final Record record = result.next();
        final Value value = record.get(0);
        return new QueryResult<String>() {

            @Override
            public void close() {
                result.consume();
            }

            @Override
            public Iterator<String> iterator() {
                return value.asList(Values.ofString()).iterator();
            }
        };
    } catch (TransientException tex) {
        closed = true;
        throw new RetryException(tex);
    } catch (NoSuchRecordException nex) {
        throw new NotFoundException(nex);
    } catch (ServiceUnavailableException ex) {
        throw new NetworkException(ex.getMessage(), ex);
    } finally {
        logQuery(statement, map, t0);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) QueryResult(org.structr.api.QueryResult) TransientException(org.neo4j.driver.v1.exceptions.TransientException) Value(org.neo4j.driver.v1.Value) NotFoundException(org.structr.api.NotFoundException) Record(org.neo4j.driver.v1.Record) ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) RetryException(org.structr.api.RetryException) NetworkException(org.structr.api.NetworkException) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException)

Example 3 with NoSuchRecordException

use of org.neo4j.driver.v1.exceptions.NoSuchRecordException in project structr by structr.

the class EntityWrapper method assertNotStale.

// ----- protected methods -----
protected synchronized void assertNotStale() {
    if (stale) {
        // invalidate caches
        onRemoveFromCache();
        // if a node/rel was deleted in a previous transaction but the caller keeps a
        // reference to this entity, we need to make sure that the reference is fresh.
        final SessionTransaction tx = db.getCurrentTransaction();
        final Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        try {
            // update data
            data.clear();
            update(tx.getEntity(getQueryPrefix() + " WHERE ID(n) = {id} RETURN n", map).asMap());
        } catch (NoSuchRecordException nex) {
            throw new NotFoundException(nex);
        }
        stale = false;
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SessionTransaction(org.structr.bolt.SessionTransaction) NotFoundException(org.structr.api.NotFoundException) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException)

Aggregations

NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)3 Record (org.neo4j.driver.v1.Record)2 StatementResult (org.neo4j.driver.v1.StatementResult)2 NotFoundException (org.structr.api.NotFoundException)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Session (org.neo4j.driver.v1.Session)1 Statement (org.neo4j.driver.v1.Statement)1 Value (org.neo4j.driver.v1.Value)1 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)1 TransientException (org.neo4j.driver.v1.exceptions.TransientException)1 Relationship (org.neo4j.driver.v1.types.Relationship)1 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)1 PathNode (org.openkilda.messaging.info.event.PathNode)1 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)1 NetworkException (org.structr.api.NetworkException)1 QueryResult (org.structr.api.QueryResult)1 RetryException (org.structr.api.RetryException)1 SessionTransaction (org.structr.bolt.SessionTransaction)1