Search in sources :

Example 71 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class RyaQueryEngineFactory method getQueryEngine.

@SuppressWarnings("unchecked")
public static <C extends RdfCloudTripleStoreConfiguration> RyaQueryEngine<C> getQueryEngine(RdfCloudTripleStoreConfiguration conf) {
    if (conf instanceof AccumuloRdfConfiguration) {
        AccumuloRdfConfiguration aConf = (AccumuloRdfConfiguration) conf;
        Instance instance;
        String instanceName = aConf.get("sc.cloudbase.instancename");
        String user = aConf.get("sc.cloudbase.username");
        String password = aConf.get("sc.cloudbase.password");
        if (aConf.getBoolean(".useMockInstance", false)) {
            instance = new MockInstance(instanceName);
        } else {
            String zookeepers = aConf.get("sc.cloudbase.zookeepers");
            instance = new ZooKeeperInstance(instanceName, zookeepers);
        }
        Connector conn;
        try {
            conn = instance.getConnector(user, new PasswordToken(password));
        } catch (AccumuloException | AccumuloSecurityException e) {
            throw new RuntimeException(e);
        }
        return (RyaQueryEngine<C>) new AccumuloRyaQueryEngine(conn, aConf);
    } else if (conf instanceof StatefulMongoDBRdfConfiguration && ConfigUtils.getUseMongo(conf)) {
        StatefulMongoDBRdfConfiguration mongoConf = (StatefulMongoDBRdfConfiguration) conf;
        MongoDBQueryEngine mongoQueryEngine = new MongoDBQueryEngine();
        mongoQueryEngine.setConf(mongoConf);
        return (RyaQueryEngine<C>) mongoQueryEngine;
    } else {
        throw new IllegalArgumentException("Invalid configuration type.");
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) RyaQueryEngine(org.apache.rya.api.persist.query.RyaQueryEngine) MongoDBQueryEngine(org.apache.rya.mongodb.MongoDBQueryEngine)

Example 72 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class RyaAccumuloSailFactory method getSail.

@Override
public Sail getSail(final SailImplConfig config) throws SailConfigException {
    try {
        final RdfCloudTripleStore store = new RdfCloudTripleStore();
        final RyaAccumuloSailConfig cbconfig = (RyaAccumuloSailConfig) config;
        final String instanceName = cbconfig.getInstance();
        final String zooKeepers = cbconfig.getZookeepers();
        Instance i;
        if (cbconfig.isMock()) {
            i = new MockInstance(instanceName);
        } else {
            i = new ZooKeeperInstance(instanceName, zooKeepers);
        }
        final String user = cbconfig.getUser();
        final String pass = cbconfig.getPassword();
        final Connector connector = i.getConnector(user, new PasswordToken(pass));
        final AccumuloRyaDAO crdfdao = new AccumuloRyaDAO();
        crdfdao.setConnector(connector);
        final AccumuloRdfConfiguration conf = cbconfig.toRdfConfiguation();
        ConfigUtils.setIndexers(conf);
        conf.setDisplayQueryPlan(true);
        crdfdao.setConf(conf);
        crdfdao.init();
        store.setRyaDAO(crdfdao);
        return store;
    } catch (RyaDAOException | AccumuloException | AccumuloSecurityException e) {
        throw new SailConfigException(e);
    }
}
Also used : RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) Connector(org.apache.accumulo.core.client.Connector) AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) AccumuloException(org.apache.accumulo.core.client.AccumuloException) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) SailConfigException(org.openrdf.sail.config.SailConfigException)

Example 73 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class AccumuloLoadStatementsFile method loadStatements.

@Override
public void loadStatements(final String ryaInstanceName, final Path statementsFile, final RDFFormat format) throws InstanceDoesNotExistException, RyaClientException {
    requireNonNull(ryaInstanceName);
    requireNonNull(statementsFile);
    requireNonNull(format);
    // Ensure the Rya Instance exists.
    if (!instanceExists.exists(ryaInstanceName)) {
        throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
    }
    Sail sail = null;
    SailRepository sailRepo = null;
    SailRepositoryConnection sailRepoConn = null;
    try {
        // Get a Sail object that is connected to the Rya instance.
        final AccumuloRdfConfiguration ryaConf = getAccumuloConnectionDetails().buildAccumuloRdfConfiguration(ryaInstanceName);
        // RYA-327 should address this hardcoded value.
        ryaConf.setFlush(false);
        sail = RyaSailFactory.getInstance(ryaConf);
        // Load the file.
        sailRepo = new SailRepository(sail);
        sailRepoConn = sailRepo.getConnection();
        sailRepoConn.add(statementsFile.toFile(), null, format);
    } catch (final SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) {
        log.warn("Exception while loading:", e);
        throw new RyaClientException("A problem connecting to the Rya instance named '" + ryaInstanceName + "' has caused the load to fail.", e);
    } catch (final RepositoryException | RDFParseException | UnsupportedRDFormatException | IOException e) {
        log.warn("Exception while loading:", e);
        throw new RyaClientException("A problem processing the RDF file has caused the load into Rya instance named " + ryaInstanceName + "to fail.", e);
    } finally {
        // Shut it all down.
        if (sailRepoConn != null) {
            try {
                sailRepoConn.close();
            } catch (final RepositoryException e) {
                log.warn("Couldn't close the SailRepoConnection that is attached to the Rya instance.", e);
            }
        }
        if (sailRepo != null) {
            try {
                sailRepo.shutDown();
            } catch (final RepositoryException e) {
                log.warn("Couldn't shut down the SailRepository that is attached to the Rya instance.", e);
            }
        }
        if (sail != null) {
            try {
                sail.shutDown();
            } catch (final SailException e) {
                log.warn("Couldn't shut down the Sail that is attached to the Rya instance.", e);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) UnsupportedRDFormatException(org.openrdf.rio.UnsupportedRDFormatException) RyaClientException(org.apache.rya.api.client.RyaClientException) SailRepository(org.openrdf.repository.sail.SailRepository) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RepositoryException(org.openrdf.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.openrdf.sail.SailException) IOException(java.io.IOException) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Sail(org.openrdf.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) RDFParseException(org.openrdf.rio.RDFParseException)

Example 74 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class EntityCentricIndex method setConf.

// initialization occurs in setConf because index is created using reflection
@Override
public void setConf(final Configuration conf) {
    if (conf instanceof AccumuloRdfConfiguration) {
        this.conf = (AccumuloRdfConfiguration) conf;
    } else {
        this.conf = new AccumuloRdfConfiguration(conf);
    }
    if (!isInit) {
        try {
            initInternal();
            isInit = true;
        } catch (final AccumuloException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        } catch (final AccumuloSecurityException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        } catch (final TableNotFoundException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        } catch (final TableExistsException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        } catch (final IOException e) {
            logger.warn("Unable to initialize index.  Throwing Runtime Exception. ", e);
            throw new RuntimeException(e);
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 75 with AccumuloRdfConfiguration

use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.

the class ConfigUtils method getInstance.

/**
 * Create an {@link Instance} that may be used to create {@link Connector}s
 * to Accumulo. If the configuration has the {@link #USE_MOCK_INSTANCE} flag
 * set, then the instance will be be a {@link MockInstance} instead of a
 * Zookeeper backed instance.
 *
 * @param conf - The configuration object that will be interrogated. (not null)
 * @return The {@link Instance} that may be used to connect to Accumulo.
 */
public static Instance getInstance(final Configuration conf) {
    // Pull out the Accumulo specific configuration values.
    final AccumuloRdfConfiguration accConf = new AccumuloRdfConfiguration(conf);
    final String instanceName = accConf.getInstanceName();
    final String zoookeepers = accConf.getZookeepers();
    // Create an Instance a mock if the mock flag is set.
    if (useMockInstance(conf)) {
        return new MockInstance(instanceName);
    }
    // Otherwise create an Instance to a Zookeeper managed instance of Accumulo.
    return new ZooKeeperInstance(instanceName, zoookeepers);
}
Also used : MockInstance(org.apache.accumulo.core.client.mock.MockInstance) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Aggregations

AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)108 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)26 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)25 Test (org.junit.Test)24 RyaURI (org.apache.rya.api.domain.RyaURI)22 Connector (org.apache.accumulo.core.client.Connector)21 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)20 RyaStatement (org.apache.rya.api.domain.RyaStatement)20 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)15 Sail (org.openrdf.sail.Sail)15 RyaType (org.apache.rya.api.domain.RyaType)14 StatementPattern (org.openrdf.query.algebra.StatementPattern)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)13 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)12 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)12 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)11 LiteralImpl (org.openrdf.model.impl.LiteralImpl)10 BindingSet (org.openrdf.query.BindingSet)10 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10