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