use of org.apache.accumulo.core.client.ZooKeeperInstance in project incubator-rya by apache.
the class StatementPatternStorage method addInferredRanges.
protected void addInferredRanges(String tablePrefix, Job job) throws IOException {
logger.info("Adding inferences to statement pattern[subject:" + subject_value + ", predicate:" + predicate_value + ", object:" + object_value + "]");
// inference engine
AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO();
InferenceEngine inferenceEngine = new InferenceEngine();
try {
AccumuloRdfConfiguration rdfConf = new AccumuloRdfConfiguration(job.getConfiguration());
rdfConf.setTablePrefix(tablePrefix);
ryaDAO.setConf(rdfConf);
try {
if (!mock) {
ryaDAO.setConnector(new ZooKeeperInstance(inst, zookeepers).getConnector(user, userP.getBytes(StandardCharsets.UTF_8)));
} else {
ryaDAO.setConnector(new MockInstance(inst).getConnector(user, userP.getBytes(StandardCharsets.UTF_8)));
}
} catch (Exception e) {
throw new IOException(e);
}
ryaDAO.init();
inferenceEngine.setConf(rdfConf);
inferenceEngine.setRyaDAO(ryaDAO);
inferenceEngine.setSchedule(false);
inferenceEngine.init();
// is it subclassof or subpropertyof
if (RDF.TYPE.equals(predicate_value)) {
// try subclassof
Collection<URI> parents = inferenceEngine.findParents(inferenceEngine.getSubClassOfGraph(), (URI) object_value);
if (parents != null && parents.size() > 0) {
// add all relationships
for (URI parent : parents) {
Map.Entry<TABLE_LAYOUT, Range> temp = createRange(subject_value, predicate_value, parent);
Range range = temp.getValue();
if (logger.isDebugEnabled()) {
logger.debug("Found subClassOf relationship [type:" + object_value + " is subClassOf:" + parent + "]");
}
addRange(range);
}
}
} else if (predicate_value != null) {
// subpropertyof check
Set<URI> parents = inferenceEngine.findParents(inferenceEngine.getSubPropertyOfGraph(), (URI) predicate_value);
for (URI parent : parents) {
Map.Entry<TABLE_LAYOUT, Range> temp = createRange(subject_value, parent, object_value);
Range range = temp.getValue();
if (logger.isDebugEnabled()) {
logger.debug("Found subPropertyOf relationship [type:" + predicate_value + " is subPropertyOf:" + parent + "]");
}
addRange(range);
}
}
} catch (Exception e) {
logger.error("Exception in adding inferred ranges", e);
throw new IOException(e);
} finally {
if (inferenceEngine != null) {
try {
inferenceEngine.destroy();
} catch (InferenceEngineException e) {
logger.error("Exception closing InferenceEngine", e);
}
}
if (ryaDAO != null) {
try {
ryaDAO.destroy();
} catch (RyaDAOException e) {
logger.error("Exception closing ryadao", e);
}
}
}
}
use of org.apache.accumulo.core.client.ZooKeeperInstance in project incubator-rya by apache.
the class AccumuloRyaUtils method getScanner.
/**
* Creates a {@link Scanner} of the provided table name using the specified {@link Configuration}.
* @param tablename the name of the table to scan.
* @param config the {@link Configuration}.
* @param shouldAddCommonIterators {@code true} to add the common iterators to the table scanner.
* {@code false} otherwise.
* @return the {@link Scanner} for the table.
* @throws IOException
*/
public static Scanner getScanner(final String tableName, final Configuration config, final boolean shouldAddCommonIterators) throws IOException {
try {
final String instanceName = config.get(ConfigUtils.CLOUDBASE_INSTANCE);
final String zooKeepers = config.get(ConfigUtils.CLOUDBASE_ZOOKEEPERS);
Instance instance;
if (ConfigUtils.useMockInstance(config)) {
instance = new MockInstance(instanceName);
} else {
instance = new ZooKeeperInstance(new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers));
}
final String username = ConfigUtils.getUsername(config);
final String password = ConfigUtils.getPassword(config);
final Connector connector = instance.getConnector(username, new PasswordToken(password));
final Authorizations auths = ConfigUtils.getAuthorizations(config);
final Scanner scanner = connector.createScanner(tableName, auths);
if (shouldAddCommonIterators) {
AccumuloRyaUtils.addCommonScannerIteratorsTo(scanner);
}
return scanner;
} catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
log.error("Error connecting to " + tableName);
throw new IOException(e);
}
}
use of org.apache.accumulo.core.client.ZooKeeperInstance in project incubator-rya by apache.
the class FluoITBase method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
Logger.getLogger(ClientCnxn.class).setLevel(Level.ERROR);
// Setup and start the Mini Accumulo.
cluster = clusterInstance.getCluster();
// Store a connector to the Mini Accumulo.
instanceName = cluster.getInstanceName();
zookeepers = cluster.getZooKeepers();
final Instance instance = new ZooKeeperInstance(instanceName, zookeepers);
accumuloConn = instance.getConnector(clusterInstance.getUsername(), new PasswordToken(clusterInstance.getPassword()));
}
use of org.apache.accumulo.core.client.ZooKeeperInstance 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.accumulo.core.client.ZooKeeperInstance 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);
}
}
Aggregations