Search in sources :

Example 6 with AccumuloConnectionDetails

use of org.apache.rya.api.client.accumulo.AccumuloConnectionDetails in project incubator-rya by apache.

the class GeoFunctionsIT method runTest.

public void runTest(final String sparql, final Collection<Statement> statements, final Collection<BindingSet> expectedResults) throws Exception {
    requireNonNull(sparql);
    requireNonNull(statements);
    requireNonNull(expectedResults);
    // Register the PCJ with Rya.
    final Instance accInstance = super.getAccumuloConnector().getInstance();
    final Connector accumuloConn = super.getAccumuloConnector();
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(getUsername(), getPassword().toCharArray(), accInstance.getInstanceName(), accInstance.getZooKeepers()), accumuloConn);
    ryaClient.getCreatePCJ().createPCJ(getRyaInstanceName(), sparql);
    // Write the data to Rya.
    final SailRepositoryConnection ryaConn = super.getRyaSailRepository().getConnection();
    ryaConn.begin();
    ryaConn.add(statements);
    ryaConn.commit();
    ryaConn.close();
    // Wait for the Fluo application to finish computing the end result.
    super.getMiniFluo().waitForObservers();
    // Fetch the value that is stored within the PCJ table.
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName())) {
        final String pcjId = pcjStorage.listPcjs().get(0);
        final Set<BindingSet> results = Sets.newHashSet(pcjStorage.listResults(pcjId));
        // Ensure the result of the query matches the expected result.
        assertEquals(expectedResults, results);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) Instance(org.apache.accumulo.core.client.Instance) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) RyaClient(org.apache.rya.api.client.RyaClient) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection)

Example 7 with AccumuloConnectionDetails

use of org.apache.rya.api.client.accumulo.AccumuloConnectionDetails 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;
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Instance(org.apache.accumulo.core.client.Instance) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) RyaClient(org.apache.rya.api.client.RyaClient)

Example 8 with AccumuloConnectionDetails

use of org.apache.rya.api.client.accumulo.AccumuloConnectionDetails 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);
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) Sail(org.openrdf.sail.Sail) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) RyaClient(org.apache.rya.api.client.RyaClient) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration)

Example 9 with AccumuloConnectionDetails

use of org.apache.rya.api.client.accumulo.AccumuloConnectionDetails in project incubator-rya by apache.

the class RyaConnectionCommands method printConnectionDetails.

@CliCommand(value = PRINT_CONNECTION_DETAILS_CMD, help = "Print information about the Shell's Rya storage connection.")
public String printConnectionDetails() {
    // Check to see if the shell is connected to any storages.
    final com.google.common.base.Optional<StorageType> storageType = sharedState.getShellState().getStorageType();
    if (!storageType.isPresent()) {
        return "The shell is not connected to anything.";
    }
    // Create a print out based on what it is connected to.
    switch(storageType.get()) {
        case ACCUMULO:
            final AccumuloConnectionDetails accDetails = sharedState.getShellState().getAccumuloDetails().get();
            return "The shell is connected to an instance of Accumulo using the following parameters:\n" + "    Username: " + accDetails.getUsername() + "\n" + "    Instance Name: " + accDetails.getInstanceName() + "\n" + "    Zookeepers: " + accDetails.getZookeepers();
        case MONGO:
            final MongoConnectionDetails mongoDetails = sharedState.getShellState().getMongoDetails().get();
            final StringBuilder message = new StringBuilder().append("The shell is connected to an instance of MongoDB using the following parameters:\n").append("    Hostname: " + mongoDetails.getHostname() + "\n").append("    Port: " + mongoDetails.getPort() + "\n");
            if (mongoDetails.getUsername().isPresent()) {
                message.append("    Username: " + mongoDetails.getUsername().get() + "\n");
            }
            return message.toString();
        default:
            throw new RuntimeException("Unrecognized StorageType: " + storageType.get());
    }
}
Also used : MongoConnectionDetails(org.apache.rya.api.client.mongo.MongoConnectionDetails) StorageType(org.apache.rya.shell.SharedShellState.StorageType) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 10 with AccumuloConnectionDetails

use of org.apache.rya.api.client.accumulo.AccumuloConnectionDetails in project incubator-rya by apache.

the class RyaConnectionCommands method connectToAccumulo.

@CliCommand(value = CONNECT_ACCUMULO_CMD, help = "Connect the shell to an instance of Accumulo.")
public String connectToAccumulo(@CliOption(key = { "username" }, mandatory = true, help = "The username that will be used to connect to Accummulo.") final String username, @CliOption(key = { "instanceName" }, mandatory = true, help = "The name of the Accumulo instance that will be connected to.") final String instanceName, @CliOption(key = { "zookeepers" }, mandatory = true, help = "A comma delimited list of zookeeper server hostnames.") final String zookeepers) {
    try {
        // Prompt the user for their password.
        final char[] password = passwordPrompt.getPassword();
        final Connector connector = new ConnectorFactory().connect(username, CharBuffer.wrap(password), instanceName, zookeepers);
        // Initialize the connected to Accumulo shared state.
        final AccumuloConnectionDetails accumuloDetails = new AccumuloConnectionDetails(username, password, instanceName, zookeepers);
        final RyaClient commands = AccumuloRyaClientFactory.build(accumuloDetails, connector);
        sharedState.connectedToAccumulo(accumuloDetails, commands);
    } catch (IOException | AccumuloException | AccumuloSecurityException e) {
        throw new RuntimeException("Could not connect to Accumulo. Reason: " + e.getMessage(), e);
    }
    return "Connected. You must select a Rya instance to interact with next.";
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ConnectorFactory(org.apache.rya.shell.util.ConnectorFactory) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) RyaClient(org.apache.rya.api.client.RyaClient) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Aggregations

AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)17 RyaClient (org.apache.rya.api.client.RyaClient)15 Test (org.junit.Test)8 Connector (org.apache.accumulo.core.client.Connector)5 MiniAccumuloCluster (org.apache.accumulo.minicluster.MiniAccumuloCluster)4 ShellState (org.apache.rya.shell.SharedShellState.ShellState)4 Instance (org.apache.accumulo.core.client.Instance)3 File (java.io.File)2 MiniAccumuloConfig (org.apache.accumulo.minicluster.MiniAccumuloConfig)2 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)2 Sail (org.openrdf.sail.Sail)2 CliCommand (org.springframework.shell.core.annotation.CliCommand)2 IOException (java.io.IOException)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 AlreadyInitializedException (org.apache.fluo.api.client.FluoAdmin.AlreadyInitializedException)1 TableExistsException (org.apache.fluo.api.client.FluoAdmin.TableExistsException)1