Search in sources :

Example 31 with SailException

use of org.openrdf.sail.SailException in project incubator-rya by apache.

the class AccumuloCreatePeriodicPCJ method createPeriodicPCJ.

@Override
public String createPeriodicPCJ(String instanceName, String sparql, String periodicTopic, String bootStrapServers) throws RyaClientException {
    requireNonNull(instanceName);
    requireNonNull(sparql);
    final Optional<RyaDetails> ryaDetailsHolder = getInstanceDetails.getDetails(instanceName);
    final boolean ryaInstanceExists = ryaDetailsHolder.isPresent();
    if (!ryaInstanceExists) {
        throw new InstanceDoesNotExistException(String.format("The '%s' instance of Rya does not exist.", instanceName));
    }
    final PCJIndexDetails pcjIndexDetails = ryaDetailsHolder.get().getPCJIndexDetails();
    final boolean pcjIndexingEnabeld = pcjIndexDetails.isEnabled();
    if (!pcjIndexingEnabeld) {
        throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ Indexing enabled.", instanceName));
    }
    // If a Fluo application is being used, task it with updating the PCJ.
    final Optional<FluoDetails> fluoDetailsHolder = pcjIndexDetails.getFluoDetails();
    if (fluoDetailsHolder.isPresent()) {
        final String fluoAppName = fluoDetailsHolder.get().getUpdateAppName();
        try {
            return updateFluoAppAndRegisterWithKafka(instanceName, fluoAppName, sparql, periodicTopic, bootStrapServers);
        } catch (RepositoryException | MalformedQueryException | SailException | QueryEvaluationException | PcjException | RyaDAOException | PeriodicQueryCreationException e) {
            throw new RyaClientException("Problem while initializing the Fluo application with the new PCJ.", e);
        } catch (UnsupportedQueryException e) {
            throw new RyaClientException("The new PCJ could not be initialized because it either contains an unsupported query node " + "or an invalid ExportStrategy for the given QueryType.  Projection queries can be exported to either Rya or Kafka," + "unless they contain an aggregation, in which case they can only be exported to Kafka.  Construct queries can be exported" + "to Rya and Kafka, and Periodic queries can only be exported to Rya.");
        }
    } else {
        throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ Indexing enabled.", instanceName));
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) PcjException(org.apache.rya.indexing.pcj.storage.PcjException) UnsupportedQueryException(org.apache.rya.indexing.pcj.fluo.app.query.UnsupportedQueryException) RyaDetails(org.apache.rya.api.instance.RyaDetails) RepositoryException(org.openrdf.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.openrdf.sail.SailException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) PeriodicQueryCreationException(org.apache.rya.indexing.pcj.fluo.api.CreatePeriodicQuery.PeriodicQueryCreationException) FluoDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails) PCJIndexDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)

Example 32 with SailException

use of org.openrdf.sail.SailException in project backstage by zepheira.

the class Database method createTypeRecord.

private TypeRecord createTypeRecord(URI type, SailConnection sc) {
    String id = getTypeId(type, sc);
    String label = SailUtilities.getStringObject(sc, type, RDFS.LABEL, id);
    Properties properties = new Properties();
    CloseableIteration<? extends Statement, SailException> i = null;
    try {
        i = sc.getStatements(type, null, null, true);
    } catch (SailException e) {
        _logger.error("Failed to get all statements in order to get type record", e);
        return null;
    }
    if (i != null) {
        try {
            while (i.hasNext()) {
                Statement s = i.next();
                URI p = s.getPredicate();
                Value o = s.getObject();
                if (!p.equals(RDFS.LABEL) && !p.equals(ExhibitOntology.ID)) {
                    properties.put(p.getLocalName(), SailUtilities.valueToString(o));
                }
            }
        } catch (SailException e) {
            _logger.warn("Failed to iterate through statements", e);
        } finally {
            try {
                i.close();
            } catch (SailException e) {
                _logger.warn("Failed to close statement iterator", e);
            }
        }
    }
    return new TypeRecord(type, id, label, properties);
}
Also used : Statement(org.openrdf.model.Statement) Value(org.openrdf.model.Value) SailException(org.openrdf.sail.SailException) Properties(java.util.Properties) URI(org.openrdf.model.URI)

Example 33 with SailException

use of org.openrdf.sail.SailException in project backstage by zepheira.

the class Database method abbreviateItems.

protected synchronized void abbreviateItems() {
    if (_abbreviatedItems) {
        return;
    }
    _abbreviatedItems = true;
    getRepository();
    SailConnection sc = null;
    try {
        sc = _sail.getConnection();
    } catch (SailException e) {
        _logger.error("Failed to open sail connection in order to compute cached information", e);
    }
    if (sc != null) {
        try {
            CloseableIteration<? extends Statement, SailException> i;
            try {
                i = sc.getStatements(null, RDF.TYPE, null, true);
            } catch (SailException e) {
                _logger.error("Failed to get all statements in order to abbreviate items", e);
                return;
            }
            try {
                while (i.hasNext()) {
                    Statement s = i.next();
                    Resource r = s.getSubject();
                    if (r instanceof URI) {
                        getItemId((URI) r, sc);
                    }
                }
            } catch (SailException e) {
                _logger.warn("Failed to iterate through statements", e);
            } finally {
                try {
                    i.close();
                } catch (SailException e) {
                    _logger.warn("Failed to close statement iterator", e);
                }
            }
        } finally {
            try {
                sc.close();
            } catch (SailException e) {
                _logger.warn("Failed to close sail connection", e);
            }
        }
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI)

Example 34 with SailException

use of org.openrdf.sail.SailException in project backstage by zepheira.

the class Database method internalBuildTypeRecords.

private void internalBuildTypeRecords(SailConnection sc) {
    _typeRecords = new LinkedList<TypeRecord>();
    _typeIDToRecord = new HashMap<String, TypeRecord>();
    getRepository();
    CloseableIteration<? extends Statement, SailException> i;
    try {
        i = sc.getStatements(null, RDF.TYPE, null, true);
    } catch (SailException e) {
        _logger.error("Failed to get all statements in order to get type records", e);
        return;
    }
    Set<URI> types = new HashSet<URI>();
    try {
        while (i.hasNext()) {
            Statement s = i.next();
            types.add((URI) s.getObject());
        }
    } catch (SailException e) {
        _logger.warn("Failed to iterate through statements", e);
    } finally {
        try {
            i.close();
        } catch (SailException e) {
            _logger.warn("Failed to close statement iterator", e);
        }
    }
    for (URI type : types) {
        TypeRecord r = createTypeRecord(type, sc);
        if (r != null) {
            _typeRecords.add(r);
            _typeIDToRecord.put(r.id, r);
        }
    }
}
Also used : Statement(org.openrdf.model.Statement) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI) HashSet(java.util.HashSet)

Example 35 with SailException

use of org.openrdf.sail.SailException in project backstage by zepheira.

the class Database method computeCachedInformation.

private void computeCachedInformation() {
    if (_propertyRecords == null || _typeRecords == null) {
        getRepository();
        SailConnection sc = null;
        try {
            sc = _sail.getConnection();
        } catch (SailException e) {
            _logger.error("Failed to open sail connection in order to compute cached information", e);
        } catch (Exception e) {
        } finally {
        }
        if (sc != null) {
            try {
                internalBuildPropertyRecords(sc);
                internalBuildTypeRecords(sc);
            } finally {
                try {
                    sc.close();
                } catch (SailException e) {
                    _logger.warn("Failed to close sail connection", e);
                }
            }
        }
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) SailException(org.openrdf.sail.SailException) SailException(org.openrdf.sail.SailException) OpenRDFException(org.openrdf.OpenRDFException)

Aggregations

SailException (org.openrdf.sail.SailException)46 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)17 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)14 RyaClientException (org.apache.rya.api.client.RyaClientException)13 SailConnection (org.openrdf.sail.SailConnection)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)11 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)11 Sail (org.openrdf.sail.Sail)11 InferenceEngineException (org.apache.rya.rdftriplestore.inference.InferenceEngineException)10 URI (org.openrdf.model.URI)10 RepositoryException (org.openrdf.repository.RepositoryException)10 MalformedQueryException (org.openrdf.query.MalformedQueryException)9 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)8 Statement (org.openrdf.model.Statement)8 SailRepository (org.openrdf.repository.sail.SailRepository)7 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7 Resource (org.openrdf.model.Resource)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)4