Search in sources :

Example 91 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class AccumuloRyaDAO method init.

@Override
public void init() throws RyaDAOException {
    if (isInitialized.get()) {
        return;
    }
    try {
        checkNotNull(conf);
        checkNotNull(connector);
        if (batchWriterConfig == null) {
            batchWriterConfig = new BatchWriterConfig();
            batchWriterConfig.setMaxMemory(MAX_MEMORY);
            batchWriterConfig.setTimeout(MAX_TIME, TimeUnit.MILLISECONDS);
            batchWriterConfig.setMaxWriteThreads(NUM_THREADS);
        }
        tableLayoutStrategy = conf.getTableLayoutStrategy();
        ryaContext = RyaTripleContext.getInstance(conf);
        ryaTableMutationsFactory = new RyaTableMutationsFactory(ryaContext);
        secondaryIndexers = conf.getAdditionalIndexers();
        flushEachUpdate.set(conf.flushEachUpdate());
        final TableOperations tableOperations = connector.tableOperations();
        AccumuloRdfUtils.createTableIfNotExist(tableOperations, tableLayoutStrategy.getSpo());
        AccumuloRdfUtils.createTableIfNotExist(tableOperations, tableLayoutStrategy.getPo());
        AccumuloRdfUtils.createTableIfNotExist(tableOperations, tableLayoutStrategy.getOsp());
        AccumuloRdfUtils.createTableIfNotExist(tableOperations, tableLayoutStrategy.getNs());
        for (final AccumuloIndexer index : secondaryIndexers) {
            index.setConf(conf);
        }
        mt_bw = connector.createMultiTableBatchWriter(batchWriterConfig);
        // get the batch writers for tables
        bw_spo = mt_bw.getBatchWriter(tableLayoutStrategy.getSpo());
        bw_po = mt_bw.getBatchWriter(tableLayoutStrategy.getPo());
        bw_osp = mt_bw.getBatchWriter(tableLayoutStrategy.getOsp());
        bw_ns = mt_bw.getBatchWriter(tableLayoutStrategy.getNs());
        for (final AccumuloIndexer index : secondaryIndexers) {
            index.setConnector(connector);
            index.setMultiTableBatchWriter(mt_bw);
            index.init();
        }
        queryEngine = new AccumuloRyaQueryEngine(connector, conf);
        checkVersion();
        isInitialized.set(true);
    } catch (final Exception e) {
        throw new RyaDAOException(e);
    }
}
Also used : TableOperations(org.apache.accumulo.core.client.admin.TableOperations) AccumuloIndexer(org.apache.rya.accumulo.experimental.AccumuloIndexer) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException)

Example 92 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class AccumuloRyaQueryEngine method query.

@Override
public CloseableIterable<RyaStatement> query(BatchRyaQuery ryaQuery) throws RyaDAOException {
    Preconditions.checkNotNull(ryaQuery);
    Iterable<RyaStatement> stmts = ryaQuery.getQueries();
    Preconditions.checkNotNull(stmts);
    // query configuration
    String[] auths = ryaQuery.getAuths();
    final Authorizations authorizations = auths != null ? new Authorizations(auths) : configuration.getAuthorizations();
    final Long ttl = ryaQuery.getTtl();
    Long currentTime = ryaQuery.getCurrentTime();
    Long maxResults = ryaQuery.getMaxResults();
    Integer batchSize = ryaQuery.getBatchSize();
    Integer numQueryThreads = ryaQuery.getNumQueryThreads();
    String regexSubject = ryaQuery.getRegexSubject();
    String regexPredicate = ryaQuery.getRegexPredicate();
    String regexObject = ryaQuery.getRegexObject();
    TableLayoutStrategy tableLayoutStrategy = configuration.getTableLayoutStrategy();
    int maxRanges = ryaQuery.getMaxRanges();
    // TODO: cannot span multiple tables here
    try {
        Collection<Range> ranges = new HashSet<Range>();
        TABLE_LAYOUT layout = null;
        RyaURI context = null;
        TriplePatternStrategy strategy = null;
        for (RyaStatement stmt : stmts) {
            // TODO: This will be overwritten
            context = stmt.getContext();
            strategy = ryaContext.retrieveStrategy(stmt);
            if (strategy == null) {
                throw new IllegalArgumentException("TriplePattern[" + stmt + "] not supported");
            }
            Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(stmt.getSubject(), stmt.getPredicate(), stmt.getObject(), stmt.getContext(), null);
            // use range to set scanner
            // populate scanner based on authorizations, ttl
            layout = entry.getKey();
            ByteRange byteRange = entry.getValue();
            Range range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd()));
            ranges.add(range);
        }
        // no ranges
        if (layout == null || strategy == null)
            throw new IllegalArgumentException("No table layout specified, or no statements.");
        final TripleRowRegex tripleRowRegex = strategy.buildRegex(regexSubject, regexPredicate, regexObject, null, null);
        final String table = layoutToTable(layout, tableLayoutStrategy);
        boolean useBatchScanner = ranges.size() > maxRanges;
        FluentCloseableIterable<RyaStatement> results = null;
        if (useBatchScanner) {
            BatchScanner scanner = connector.createBatchScanner(table, authorizations, numQueryThreads);
            scanner.setRanges(ranges);
            fillScanner(scanner, context, null, ttl, null, tripleRowRegex, ryaQuery.getConf());
            results = FluentCloseableIterable.from(new ScannerBaseCloseableIterable(scanner)).transform(keyValueToRyaStatementFunctionMap.get(layout));
        } else {
            final RyaURI fcontext = context;
            final RdfCloudTripleStoreConfiguration fconf = ryaQuery.getConf();
            FluentIterable<RyaStatement> fluent = FluentIterable.from(ranges).transformAndConcat(new Function<Range, Iterable<Map.Entry<Key, Value>>>() {

                @Override
                public Iterable<Map.Entry<Key, Value>> apply(Range range) {
                    try {
                        Scanner scanner = connector.createScanner(table, authorizations);
                        scanner.setRange(range);
                        fillScanner(scanner, fcontext, null, ttl, null, tripleRowRegex, fconf);
                        return scanner;
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }).transform(keyValueToRyaStatementFunctionMap.get(layout));
            results = FluentCloseableIterable.from(CloseableIterables.wrap(fluent));
        }
        if (maxResults != null) {
            results = results.limit(maxResults.intValue());
        }
        return results;
    } catch (Exception e) {
        throw new RyaDAOException(e);
    }
}
Also used : BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) ByteRange(org.apache.rya.api.query.strategy.ByteRange) BatchScanner(org.apache.accumulo.core.client.BatchScanner) RyaStatement(org.apache.rya.api.domain.RyaStatement) Function(com.google.common.base.Function) TripleRowRegex(org.apache.rya.api.resolver.triple.TripleRowRegex) HashSet(java.util.HashSet) TableLayoutStrategy(org.apache.rya.api.layout.TableLayoutStrategy) Authorizations(org.apache.accumulo.core.security.Authorizations) TriplePatternStrategy(org.apache.rya.api.query.strategy.TriplePatternStrategy) Text(org.apache.hadoop.io.Text) RyaRange(org.apache.rya.api.domain.RyaRange) Range(org.apache.accumulo.core.data.Range) ByteRange(org.apache.rya.api.query.strategy.ByteRange) IOException(java.io.IOException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) RyaURI(org.apache.rya.api.domain.RyaURI) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Example 93 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class MongoDBRyaDAO method init.

@Override
public void init() throws RyaDAOException {
    if (isInitialized.get()) {
        return;
    }
    secondaryIndexers = conf.getAdditionalIndexers();
    for (final MongoSecondaryIndex index : secondaryIndexers) {
        index.setConf(conf);
    }
    db = mongoClient.getDB(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
    coll = db.getCollection(conf.getTriplesCollectionName());
    nameSpaceManager = new SimpleMongoDBNamespaceManager(db.getCollection(conf.getNameSpacesCollectionName()));
    queryEngine = new MongoDBQueryEngine();
    queryEngine.setConf(conf);
    storageStrategy = new SimpleMongoDBStorageStrategy();
    storageStrategy.createIndices(coll);
    for (final MongoSecondaryIndex index : secondaryIndexers) {
        index.init();
    }
    final MongoDbBatchWriterConfig mongoDbBatchWriterConfig = MongoDbBatchWriterUtils.getMongoDbBatchWriterConfig(conf);
    mongoDbBatchWriter = new MongoDbBatchWriter<>(new DbCollectionType(coll), mongoDbBatchWriterConfig);
    try {
        mongoDbBatchWriter.start();
    } catch (final MongoDbBatchWriterException e) {
        throw new RyaDAOException("Error starting MongoDB batch writer", e);
    }
    isInitialized.set(true);
}
Also used : SimpleMongoDBNamespaceManager(org.apache.rya.mongodb.dao.SimpleMongoDBNamespaceManager) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MongoDbBatchWriterConfig(org.apache.rya.mongodb.batch.MongoDbBatchWriterConfig) DbCollectionType(org.apache.rya.mongodb.batch.collection.DbCollectionType) SimpleMongoDBStorageStrategy(org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy) MongoDbBatchWriterException(org.apache.rya.mongodb.batch.MongoDbBatchWriterException)

Example 94 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class MongoDBRyaDAO method delete.

@Override
public void delete(final RyaStatement statement, final StatefulMongoDBRdfConfiguration conf) throws RyaDAOException {
    final boolean canDelete = DocumentVisibilityUtil.doesUserHaveDocumentAccess(auths, statement.getColumnVisibility());
    if (canDelete) {
        final DBObject obj = storageStrategy.getQuery(statement);
        coll.remove(obj);
        for (final RyaSecondaryIndexer index : secondaryIndexers) {
            try {
                index.deleteStatement(statement);
            } catch (final IOException e) {
                log.error("Unable to remove statement: " + statement.toString() + " from secondary indexer: " + index.getTableName(), e);
            }
        }
    } else {
        throw new RyaDAOException("User does not have the required authorizations to delete statement");
    }
}
Also used : RyaDAOException(org.apache.rya.api.persist.RyaDAOException) IOException(java.io.IOException) DBObject(com.mongodb.DBObject) RyaSecondaryIndexer(org.apache.rya.api.persist.index.RyaSecondaryIndexer)

Example 95 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException 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)

Aggregations

RyaDAOException (org.apache.rya.api.persist.RyaDAOException)100 RyaStatement (org.apache.rya.api.domain.RyaStatement)61 RyaURI (org.apache.rya.api.domain.RyaURI)45 Test (org.junit.Test)39 RyaType (org.apache.rya.api.domain.RyaType)28 IOException (java.io.IOException)26 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)23 AccumuloException (org.apache.accumulo.core.client.AccumuloException)22 SailException (org.openrdf.sail.SailException)15 HashSet (java.util.HashSet)12 AccumuloRyaQueryEngine (org.apache.rya.accumulo.query.AccumuloRyaQueryEngine)12 RdfCloudTripleStoreUtils (org.apache.rya.api.RdfCloudTripleStoreUtils)12 Map (java.util.Map)11 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)11 RyaClientException (org.apache.rya.api.client.RyaClientException)11 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)10 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)10 ArrayList (java.util.ArrayList)9 Scanner (org.apache.accumulo.core.client.Scanner)8 Text (org.apache.hadoop.io.Text)8