use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class MergeTool method createTempTableIfNeeded.
/**
* Creates the temp child table if it doesn't already exist in the parent.
* @param childTableName the name of the child table.
* @throws IOException
*/
public void createTempTableIfNeeded(final String childTableName) throws IOException {
try {
final AccumuloRdfConfiguration accumuloRdfConfiguration = new AccumuloRdfConfiguration(conf);
accumuloRdfConfiguration.setTablePrefix(childTablePrefix);
final Connector connector = AccumuloRyaUtils.setupConnector(accumuloRdfConfiguration);
if (!connector.tableOperations().exists(childTableName)) {
log.info("Creating table: " + childTableName);
connector.tableOperations().create(childTableName);
log.info("Created table: " + childTableName);
log.info("Granting authorizations to table: " + childTableName);
final SecurityOperations secOps = connector.securityOperations();
secOps.grantTablePermission(userName, childTableName, TablePermission.WRITE);
log.info("Granted authorizations to table: " + childTableName);
final Authorizations parentAuths = secOps.getUserAuthorizations(userName);
// Add child authorizations so the temp parent table can be accessed.
if (!parentAuths.equals(childAuthorizations)) {
final List<String> childAuthList = findUniqueAuthsFromChild(parentAuths.toString(), childAuthorizations.toString());
tempChildAuths = Joiner.on(",").join(childAuthList);
log.info("Adding the authorization, \"" + tempChildAuths + "\", to the parent user, \"" + userName + "\"");
final Authorizations newAuths = AccumuloRyaUtils.addUserAuths(userName, secOps, new Authorizations(tempChildAuths));
secOps.changeUserAuthorizations(userName, newAuths);
}
}
} catch (TableExistsException | AccumuloException | AccumuloSecurityException e) {
throw new IOException(e);
}
}
use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class MergeTool method run.
@Override
public int run(final String[] strings) throws Exception {
useMergeFileInput = conf.getBoolean(USE_MERGE_FILE_INPUT, false);
log.info("Setting up Merge Tool...");
setup();
if (useMergeFileInput) {
// When using file input mode the child instance will use a temporary table in the parent instance to
// store the child table data. The two tables will then be merged together.
copyParentPropertiesToChild(conf);
}
for (final String table : tables) {
final String childTable = table.replaceFirst(tablePrefix, childTablePrefix);
final String jobName = "Merge Tool, merging Child Table: " + childTable + ", into Parent Table: " + table + ", " + System.currentTimeMillis();
log.info("Initializing job: " + jobName);
conf.set(MRUtils.JOB_NAME_PROP, jobName);
conf.set(TABLE_NAME_PROP, table);
final Job job = Job.getInstance(conf);
job.setJarByClass(MergeTool.class);
if (useMergeFileInput) {
importChildFilesToTempParentTable(childTable);
}
setupAccumuloInput(job);
InputFormatBase.setInputTableName(job, table);
// Set input output of the particular job
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Mutation.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Mutation.class);
setupAccumuloOutput(job, table);
// Set mapper and reducer classes
job.setMapperClass(MergeToolMapper.class);
job.setReducerClass(Reducer.class);
// Submit the job
final Date beginTime = new Date();
log.info("Job for table \"" + table + "\" started: " + beginTime);
final int exitCode = job.waitForCompletion(true) ? 0 : 1;
if (useMergeFileInput && StringUtils.isNotBlank(tempChildAuths)) {
// Clear any of the temporary child auths given to the parent
final AccumuloRdfConfiguration parentAccumuloRdfConfiguration = new AccumuloRdfConfiguration(conf);
parentAccumuloRdfConfiguration.setTablePrefix(tablePrefix);
final Connector parentConnector = AccumuloRyaUtils.setupConnector(parentAccumuloRdfConfiguration);
final SecurityOperations secOps = parentConnector.securityOperations();
AccumuloRyaUtils.removeUserAuths(userName, secOps, tempChildAuths);
}
if (exitCode == 0) {
final Date endTime = new Date();
log.info("Job for table \"" + table + "\" finished: " + endTime);
log.info("The job took " + (endTime.getTime() - beginTime.getTime()) / 1000 + " seconds.");
} else {
log.error("Job for table \"" + table + "\" Failed!!!");
return exitCode;
}
}
return 0;
}
use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class AccumuloRyaUtils method getMetadata.
/**
* Gets the metadata key from the table.
* @param ryaStatement the {@link RyaStatement} for the metadata key to query.
* @param dao the {@link AccumuloRyaDAO}.
* @return the string value of the object from the metadata key.
* @throws RyaDAOException
*/
private static String getMetadata(final RyaStatement ryaStatement, final AccumuloRyaDAO dao) throws RyaDAOException {
String metadata = null;
final AccumuloRdfConfiguration config = dao.getConf();
final CloseableIteration<RyaStatement, RyaDAOException> iter = dao.getQueryEngine().query(ryaStatement, config);
if (iter.hasNext()) {
metadata = iter.next().getObject().getData();
}
iter.close();
return metadata;
}
use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class GeoWaveIndexerSfTest method before.
/**
* Run before each test method.
* @throws Exception
*/
@Before
public void before() throws Exception {
conf = new AccumuloRdfConfiguration();
conf.setTablePrefix("triplestore_");
final String tableName = GeoWaveGeoIndexer.getTableName(conf);
conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, IS_MOCK);
conf.set(ConfigUtils.CLOUDBASE_USER, ACCUMULO_USER);
conf.set(ConfigUtils.CLOUDBASE_PASSWORD, ACCUMULO_PASSWORD);
conf.set(ConfigUtils.CLOUDBASE_INSTANCE, IS_MOCK ? "INSTANCE" : accumulo.getInstanceName());
conf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, IS_MOCK ? "localhost" : accumulo.getZooKeepers());
conf.set(ConfigUtils.CLOUDBASE_AUTHS, "U");
conf.set(OptionalConfigUtils.USE_GEO, "true");
conf.set(OptionalConfigUtils.GEO_INDEXER_TYPE, GeoIndexerType.GEO_WAVE.toString());
final TableOperations tops = ConfigUtils.getConnector(conf).tableOperations();
// get all of the table names with the prefix
final Set<String> toDel = Sets.newHashSet();
for (final String t : tops.list()) {
if (t.startsWith(tableName)) {
toDel.add(t);
}
}
for (final String t : toDel) {
tops.delete(t);
}
g = new GeoWaveGeoIndexer();
g.setConf(conf);
g.purge(conf);
// Convert the statements as schema WKT or GML, then GML has two methods to encode.
g.storeStatement(createRyaStatement(A, schemaToTest, encodeMethod));
g.storeStatement(createRyaStatement(B, schemaToTest, encodeMethod));
g.storeStatement(createRyaStatement(C, schemaToTest, encodeMethod));
g.storeStatement(createRyaStatement(D, schemaToTest, encodeMethod));
g.storeStatement(createRyaStatement(F, schemaToTest, encodeMethod));
g.storeStatement(createRyaStatement(E, schemaToTest, encodeMethod));
g.storeStatement(createRyaStatement(G, schemaToTest, encodeMethod));
}
use of org.apache.rya.accumulo.AccumuloRdfConfiguration in project incubator-rya by apache.
the class TestVertexFormat method getConf.
private static AccumuloRdfConfiguration getConf() {
final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
conf.set(ConfigUtils.USE_PCJ, "false");
conf.set(ConfigUtils.USE_FREETEXT, "false");
conf.set(ConfigUtils.USE_TEMPORAL, "false");
conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");
conf.set(ConfigUtils.CLOUDBASE_USER, "root");
conf.set(ConfigUtils.CLOUDBASE_PASSWORD, "");
conf.set(ConfigUtils.CLOUDBASE_INSTANCE, "test");
conf.set(ConfigUtils.CLOUDBASE_AUTHS, "");
return conf;
}
Aggregations