Search in sources :

Example 1 with ConnectorFactory

use of org.apache.rya.shell.util.ConnectorFactory 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

IOException (java.io.IOException)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Connector (org.apache.accumulo.core.client.Connector)1 RyaClient (org.apache.rya.api.client.RyaClient)1 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)1 ConnectorFactory (org.apache.rya.shell.util.ConnectorFactory)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1