Search in sources :

Example 1 with InstanceExists

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

the class RyaConnectionCommands method connectToInstance.

@CliCommand(value = CONNECT_INSTANCE_CMD, help = "Connect to a specific Rya instance")
public void connectToInstance(@CliOption(key = { "instance" }, mandatory = true, help = "The name of the Rya instance the shell will interact with.") final String ryaInstance) {
    final RyaClient ryaClient = sharedState.getShellState().getConnectedCommands().get();
    try {
        final InstanceExists instanceExists = ryaClient.getInstanceExists();
        // Make sure the requested instance exists.
        if (!instanceExists.exists(ryaInstance)) {
            throw new RuntimeException(String.format("'%s' does not match an existing Rya instance.", ryaInstance));
        }
        // Store the instance name in the shared state.
        sharedState.connectedToInstance(ryaInstance);
        // If the Rya instance is configured to interact with Rya Streams, then connect the
        // Rya Streams client to the shared state.
        final com.google.common.base.Optional<RyaDetails> ryaDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance);
        if (ryaDetails.isPresent()) {
            final com.google.common.base.Optional<RyaStreamsDetails> streamsDetails = ryaDetails.get().getRyaStreamsDetails();
            if (streamsDetails.isPresent()) {
                final String kafkaHostname = streamsDetails.get().getHostname();
                final int kafkaPort = streamsDetails.get().getPort();
                final RyaStreamsClient streamsClient = KafkaRyaStreamsClientFactory.make(ryaInstance, kafkaHostname, kafkaPort);
                sharedState.connectedToRyaStreams(streamsClient);
            }
        }
    } catch (final RyaClientException e) {
        throw new RuntimeException("Could not connect to Rya instance. Reason: " + e.getMessage(), e);
    }
}
Also used : RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) InstanceExists(org.apache.rya.api.client.InstanceExists) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 2 with InstanceExists

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

the class MongoInstallIT method install_withAllIndexers.

@Test
public void install_withAllIndexers() throws DuplicateInstanceNameException, RyaClientException {
    // Install an instance of Rya.
    final String ryaInstance = conf.getMongoDBName();
    // Setup the connection details that were used for the embedded Mongo DB instance we are testing with.
    final MongoConnectionDetails connectionDetails = getConnectionDetails();
    // Check that the instance does not exist.
    final InstanceExists instanceExists = new MongoInstanceExists(getMongoClient());
    assertFalse(instanceExists.exists(ryaInstance));
    // Install an instance of Rya with all the valid options turned on.
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).setEnableEntityCentricIndex(true).setEnableGeoIndex(true).setEnablePcjIndex(true).build();
    final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
    final Install install = ryaClient.getInstall();
    install.install(ryaInstance, installConfig);
    // Check that the instance exists.
    assertTrue(instanceExists.exists(ryaInstance));
    // Show that the expected collections were created within the database.
    final List<String> expected = Arrays.asList(INSTANCE_DETAILS_COLLECTION_NAME, "rya_triples");
    int count = 0;
    final List<String> found = new ArrayList<>();
    for (final String collection : getMongoClient().getDatabase(conf.getMongoDBName()).listCollectionNames()) {
        count += expected.contains(collection) ? 1 : 0;
        found.add(collection);
    }
    assertTrue("Tables missing from:" + expected + " actual:" + found, expected.size() == count);
    assertTrue("Instance should exist.", instanceExists.exists(ryaInstance));
}
Also used : InstanceExists(org.apache.rya.api.client.InstanceExists) ArrayList(java.util.ArrayList) RyaClient(org.apache.rya.api.client.RyaClient) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Install(org.apache.rya.api.client.Install) Test(org.junit.Test)

Example 3 with InstanceExists

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

the class AccumuloRyaClientFactory method build.

/**
 * Initialize a set of {@link RyaClient} that will interact with an instance of
 * Rya that is hosted by an Accumulo cluster.
 *
 * @param connectionDetails - Details about the values that were used to create the connector to the cluster. (not null)
 * @param connector - The Accumulo connector the commands will use. (not null)
 * @return The initialized commands.
 */
public static RyaClient build(final AccumuloConnectionDetails connectionDetails, final Connector connector) {
    requireNonNull(connectionDetails);
    requireNonNull(connector);
    // Build the RyaCommands option with the initialized commands.
    final InstanceExists instanceExists = new AccumuloInstanceExists(connectionDetails, connector);
    return new RyaClient(new AccumuloInstall(connectionDetails, connector), new AccumuloCreatePCJ(connectionDetails, connector), new AccumuloDeletePCJ(connectionDetails, connector), Optional.of(new AccumuloCreatePeriodicPCJ(connectionDetails, connector)), Optional.of(new AccumuloDeletePeriodicPCJ(connectionDetails, connector)), Optional.of(new AccumuloListIncrementalQueries(connectionDetails, connector)), new AccumuloBatchUpdatePCJ(connectionDetails, connector), new AccumuloGetInstanceDetails(connectionDetails, connector), instanceExists, new AccumuloListInstances(connectionDetails, connector), Optional.of(new AccumuloAddUser(connectionDetails, connector)), Optional.of(new AccumuloRemoveUser(connectionDetails, connector)), new AccumuloSetRyaStreamsConfiguration(instanceExists, connector), new AccumuloUninstall(connectionDetails, connector), new AccumuloLoadStatements(connectionDetails, connector), new AccumuloLoadStatementsFile(connectionDetails, connector), new AccumuloExecuteSparqlQuery(connectionDetails, connector));
}
Also used : RyaClient(org.apache.rya.api.client.RyaClient) InstanceExists(org.apache.rya.api.client.InstanceExists)

Example 4 with InstanceExists

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

the class MongoUninstallIT method uninstall.

@Test
public void uninstall() throws MongoException, RyaClientException {
    // Install an instance of Rya.
    final String instanceName = "testInstance_";
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableEntityCentricIndex(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).setEnablePcjIndex(true).setEnableGeoIndex(true).setFluoPcjAppName("fluo_app_name").build();
    final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
    final Install install = ryaClient.getInstall();
    install.install(instanceName, installConfig);
    // Show that the instance exists.
    final InstanceExists instanceExists = ryaClient.getInstanceExists();
    assertTrue(instanceExists.exists(instanceName));
    // Uninstall the instance
    final Uninstall uninstall = ryaClient.getUninstall();
    uninstall.uninstall(instanceName);
    // Check that the instance no longer exists.
    assertFalse(instanceExists.exists(instanceName));
}
Also used : InstanceExists(org.apache.rya.api.client.InstanceExists) Uninstall(org.apache.rya.api.client.Uninstall) RyaClient(org.apache.rya.api.client.RyaClient) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Install(org.apache.rya.api.client.Install) Test(org.junit.Test)

Example 5 with InstanceExists

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

the class MongoInstallIT method install.

@Test
public void install() throws DuplicateInstanceNameException, RyaClientException {
    // Install an instance of Rya.
    final String ryaInstance = conf.getMongoDBName();
    // Setup the connection details that were used for the embedded Mongo DB instance we are testing with.
    final MongoConnectionDetails connectionDetails = getConnectionDetails();
    // Check that the instance does not exist.
    final InstanceExists instanceExists = new MongoInstanceExists(getMongoClient());
    assertFalse(instanceExists.exists(ryaInstance));
    // Install an instance of Rya with all the valid options turned on.
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).build();
    final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
    final Install install = ryaClient.getInstall();
    install.install(ryaInstance, installConfig);
    // Check that the instance exists.
    assertTrue(instanceExists.exists(ryaInstance));
    // Show that the expected collections were created within the database.
    final List<String> expected = Arrays.asList(INSTANCE_DETAILS_COLLECTION_NAME, "rya_triples");
    int count = 0;
    final List<String> found = new ArrayList<>();
    for (final String collection : getMongoClient().getDatabase(conf.getMongoDBName()).listCollectionNames()) {
        count += expected.contains(collection) ? 1 : 0;
        found.add(collection);
    }
    assertTrue("Tables missing from:" + expected + " actual:" + found, expected.size() == count);
    assertTrue("Instance should exist.", instanceExists.exists(ryaInstance));
}
Also used : InstanceExists(org.apache.rya.api.client.InstanceExists) ArrayList(java.util.ArrayList) RyaClient(org.apache.rya.api.client.RyaClient) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Install(org.apache.rya.api.client.Install) Test(org.junit.Test)

Aggregations

InstanceExists (org.apache.rya.api.client.InstanceExists)5 RyaClient (org.apache.rya.api.client.RyaClient)5 Install (org.apache.rya.api.client.Install)3 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 RyaClientException (org.apache.rya.api.client.RyaClientException)1 Uninstall (org.apache.rya.api.client.Uninstall)1 RyaDetails (org.apache.rya.api.instance.RyaDetails)1 RyaStreamsDetails (org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails)1 RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1