use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class PcjVisibilityIT method visibilitySimplified.
@Test
public void visibilitySimplified() throws Exception {
// Create a PCJ index within Rya.
final String sparql = "SELECT ?customer ?worker ?city " + "{ " + "?customer <" + TALKS_TO + "> ?worker. " + "?worker <" + LIVES_IN + "> ?city. " + "?worker <" + WORKS_AT + "> <" + BURGER_JOINT + ">. " + "}";
final Connector accumuloConn = super.getAccumuloConnector();
final String instanceName = super.getMiniAccumuloCluster().getInstanceName();
final String zookeepers = super.getMiniAccumuloCluster().getZooKeepers();
final RyaClient ryaClient = AccumuloRyaClientFactory.build(createConnectionDetails(), accumuloConn);
final String pcjId = ryaClient.getCreatePCJ().createPCJ(getRyaInstanceName(), sparql);
// Grant the root user the "u" authorization.
super.getAccumuloConnector().securityOperations().changeUserAuthorizations(getUsername(), new Authorizations("u"));
// Setup a connection to the Rya instance that uses the "u" authorizations. This ensures
// any statements that are inserted will have the "u" authorization on them and that the
// PCJ updating application will have to maintain visibilities.
final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
ryaConf.setTablePrefix(getRyaInstanceName());
// Accumulo connection information.
ryaConf.setAccumuloUser(getUsername());
ryaConf.setAccumuloPassword(getPassword());
ryaConf.setAccumuloInstance(super.getAccumuloConnector().getInstance().getInstanceName());
ryaConf.setAccumuloZookeepers(super.getAccumuloConnector().getInstance().getZooKeepers());
ryaConf.set(ConfigUtils.CLOUDBASE_AUTHS, "u");
ryaConf.set(RdfCloudTripleStoreConfiguration.CONF_CV, "u");
// PCJ configuration information.
ryaConf.set(ConfigUtils.USE_PCJ, "true");
ryaConf.set(ConfigUtils.USE_PCJ_UPDATER_INDEX, "true");
ryaConf.set(ConfigUtils.FLUO_APP_NAME, super.getFluoConfiguration().getApplicationName());
ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinIndexerConfig.PrecomputedJoinStorageType.ACCUMULO.toString());
ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinIndexerConfig.PrecomputedJoinUpdaterType.FLUO.toString());
Sail sail = null;
RyaSailRepository ryaRepo = null;
RepositoryConnection ryaConn = null;
try {
sail = RyaSailFactory.getInstance(ryaConf);
ryaRepo = new RyaSailRepository(sail);
ryaConn = ryaRepo.getConnection();
// Load a few Statements into Rya.
ryaConn.add(VF.createStatement(ALICE, TALKS_TO, BOB));
ryaConn.add(VF.createStatement(BOB, LIVES_IN, HAPPYVILLE));
ryaConn.add(VF.createStatement(BOB, WORKS_AT, BURGER_JOINT));
// Wait for Fluo to finish processing.
super.getMiniFluo().waitForObservers();
// Fetch the exported result and show that its column visibility has been simplified.
final String pcjTableName = new PcjTableNameFactory().makeTableName(getRyaInstanceName(), pcjId);
final Scanner scan = accumuloConn.createScanner(pcjTableName, new Authorizations("u"));
scan.fetchColumnFamily(new Text("customer;worker;city"));
final Entry<Key, Value> result = scan.iterator().next();
final Key key = result.getKey();
assertEquals(new Text("u"), key.getColumnVisibility());
} finally {
if (ryaConn != null) {
try {
ryaConn.close();
} finally {
}
}
if (ryaRepo != null) {
try {
ryaRepo.shutDown();
} finally {
}
}
if (sail != null) {
try {
sail.shutDown();
} finally {
}
}
}
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class KafkaExportITBase method loadDataAndCreateQuery.
protected String loadDataAndCreateQuery(final String sparql, final Collection<Statement> statements) throws Exception {
requireNonNull(sparql);
requireNonNull(statements);
// Register the PCJ with Rya.
final Instance accInstance = super.getAccumuloConnector().getInstance();
final Connector accumuloConn = super.getAccumuloConnector();
final RyaClient ryaClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ACCUMULO_USER, ACCUMULO_PASSWORD.toCharArray(), accInstance.getInstanceName(), accInstance.getZooKeepers()), accumuloConn);
final String pcjId = ryaClient.getCreatePCJ().createPCJ(RYA_INSTANCE_NAME, sparql, Sets.newHashSet(ExportStrategy.KAFKA));
loadData(statements);
// The PCJ Id is the topic name the results will be written to.
return pcjId;
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class KafkaExportITBase method installRyaInstance.
private void installRyaInstance() throws Exception {
final MiniAccumuloCluster cluster = super.getMiniAccumuloCluster();
final String instanceName = cluster.getInstanceName();
final String zookeepers = cluster.getZooKeepers();
// Install the Rya instance to the mini accumulo cluster.
final RyaClient ryaClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ACCUMULO_USER, ACCUMULO_PASSWORD.toCharArray(), instanceName, zookeepers), super.getAccumuloConnector());
ryaClient.getInstall().install(RYA_INSTANCE_NAME, InstallConfiguration.builder().setEnableTableHashPrefix(false).setEnableFreeTextIndex(false).setEnableEntityCentricIndex(false).setEnableGeoIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(true).setFluoPcjAppName(super.getFluoConfiguration().getApplicationName()).build());
// Connect to the Rya instance that was just installed.
final AccumuloRdfConfiguration conf = makeConfig(instanceName, zookeepers);
final Sail sail = RyaSailFactory.getInstance(conf);
dao = RyaSailFactory.getAccumuloDAOWithUpdatedConfig(conf);
ryaSailRepo = new RyaSailRepository(sail);
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaCommandsTest method testLoadData_specifyFormat.
@Test
public void testLoadData_specifyFormat() throws InstanceDoesNotExistException, RyaClientException, IOException {
// Mock the object that performs the create operation.
final String instanceName = "unitTest";
final String statementsFile = "/path/to/statements.nt";
final String format = "N-TRIPLES";
final LoadStatementsFile mockLoadStatementsFile = mock(LoadStatementsFile.class);
final RyaClient mockCommands = mock(RyaClient.class);
when(mockCommands.getLoadStatementsFile()).thenReturn(mockLoadStatementsFile);
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance(instanceName);
final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
// Execute the command.
final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, mockConsolePrinter);
final String message = commands.loadData(statementsFile, format);
// Verify the values that were provided to the command were passed through to LoadStatementsFile.
verify(mockLoadStatementsFile).loadStatements(instanceName, Paths.get(statementsFile), RDFFormat.NTRIPLES);
// Verify a message is returned that explains what was created.
assertTrue(message.startsWith("Loaded the file: '" + statementsFile + "' successfully in "));
assertTrue(message.endsWith(" seconds."));
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaCommandsTest method testSparqlQuery_fromPrompt_cancelled.
@Test
public void testSparqlQuery_fromPrompt_cancelled() throws InstanceDoesNotExistException, RyaClientException, IOException {
// Mock the object that performs the create operation.
final String instanceName = "unitTest";
final String queryFile = null;
final String expectedMessage = "";
final RyaClient mockCommands = mock(RyaClient.class);
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance(instanceName);
final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
when(mockSparqlPrompt.getSparql()).thenReturn(Optional.absent());
final ConsolePrinter mockConsolePrinter = mock(ConsolePrinter.class);
// Execute the command.
final RyaCommands commands = new RyaCommands(state, mockSparqlPrompt, mockConsolePrinter);
final String message = commands.sparqlQuery(queryFile);
assertEquals(expectedMessage, message);
// Verify a message is returned that explains what was created.
}
Aggregations