Search in sources :

Example 11 with ShellState

use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.

the class MongoRyaShellIT method connectToInstance_noAuths.

@Test
public void connectToInstance_noAuths() throws IOException {
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();
    // Connect to the Mongo instance.
    String cmd = RyaConnectionCommands.CONNECT_MONGO_CMD + " " + "--hostname " + super.conf.getMongoHostname() + " " + "--port " + super.conf.getMongoPort();
    shell.executeCommand(cmd);
    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();
    final ApplicationContext context = bootstrap.getApplicationContext();
    final InstallPrompt installPrompt = context.getBean(InstallPrompt.class);
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn(installConf);
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);
    CommandResult result = shell.executeCommand(RyaAdminCommands.INSTALL_CMD);
    assertTrue(result.isSuccess());
    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue(result.isSuccess());
    // Verify the shell state indicates it is connected to an instance.
    final SharedShellState sharedState = context.getBean(SharedShellState.class);
    final ShellState state = sharedState.getShellState();
    assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}
Also used : JLineShellComponent(org.springframework.shell.core.JLineShellComponent) ApplicationContext(org.springframework.context.ApplicationContext) ShellState(org.apache.rya.shell.SharedShellState.ShellState) Bootstrap(org.springframework.shell.Bootstrap) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.Test)

Example 12 with ShellState

use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.

the class RyaConnectionCommands method disconnect.

@CliCommand(value = DISCONNECT_COMMAND_NAME_CMD, help = "Disconnect the shell's Rya storage connection (Accumulo).")
public void disconnect() {
    final ShellState shellState = sharedState.getShellState();
    // If connected to Mongo, there is a client that needs to be closed.
    final com.google.common.base.Optional<MongoClient> mongoAdminClient = shellState.getMongoAdminClient();
    if (mongoAdminClient.isPresent()) {
        mongoAdminClient.get().close();
    }
    // If connected to Rya Streams, then close the associated resources.
    final com.google.common.base.Optional<RyaStreamsClient> streamsClient = shellState.getRyaStreamsCommands();
    if (streamsClient.isPresent()) {
        try {
            streamsClient.get().close();
        } catch (final Exception e) {
            System.err.print("Could not close the RyaStreamsClient.");
            e.printStackTrace();
        }
    }
    // Update the shared state to disconnected.
    sharedState.disconnected();
}
Also used : MongoClient(com.mongodb.MongoClient) RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClientException(org.apache.rya.api.client.RyaClientException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MongoException(com.mongodb.MongoException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 13 with ShellState

use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.

the class RyaAdminCommands method removeUser.

@CliCommand(value = REMOVE_USER_CMD, help = "Removes an authorized user from the Rya instance.")
public void removeUser(@CliOption(key = { "username" }, mandatory = true, help = "The username of the user whose access will be revoked.") final String username) {
    // Fetch the Rya client that is connected to the store.
    final ShellState shellState = state.getShellState();
    final RyaClient ryaClient = shellState.getConnectedCommands().get();
    final String ryaInstance = shellState.getRyaInstanceName().get();
    try {
        ryaClient.getRemoveUser().get().removeUser(ryaInstance, username);
    } catch (final InstanceDoesNotExistException e) {
        throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e);
    } catch (final RyaClientException e) {
        throw new RuntimeException("The user's access could not be revoked. Provided reason: " + e.getMessage(), e);
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 14 with ShellState

use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.

the class RyaAdminCommands method createPeriodicPcj.

@CliCommand(value = CREATE_PERIODIC_PCJ_CMD, help = "Creates and starts the maintenance of a new Periodic PCJ and registers the associated Periodic Notification with Kafka.")
public String createPeriodicPcj(@CliOption(key = { "topic" }, mandatory = true, help = "Kafka topic for registering new PeriodicNotifications.  This topic is monitored by the Periodic Notification Service.") final String topic, @CliOption(key = { "brokers" }, mandatory = true, help = "Comma delimited list of host/port pairs to establish the initial connection to the Kafka cluster.") final String brokers) {
    // Fetch the command that is connected to the store.
    final ShellState shellState = state.getShellState();
    final RyaClient commands = shellState.getConnectedCommands().get();
    final String ryaInstance = shellState.getRyaInstanceName().get();
    try {
        // Prompt the user for the SPARQL.
        final Optional<String> sparql = sparqlPrompt.getSparql();
        if (sparql.isPresent()) {
            // Execute the command.
            final String pcjId = commands.getCreatePeriodicPCJ().get().createPeriodicPCJ(ryaInstance, sparql.get(), topic, brokers);
            // Return a message that indicates the ID of the newly created ID.
            return String.format("The Periodic PCJ has been created. Its ID is '%s'.", pcjId);
        } else {
            // user aborted the SPARQL prompt.
            return "";
        }
    } catch (final InstanceDoesNotExistException e) {
        throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e);
    } catch (final IOException | RyaClientException e) {
        throw new RuntimeException("Could not create the Periodic PCJ. Provided reasons: " + e.getMessage(), e);
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 15 with ShellState

use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.

the class RyaAdminCommands method uninstall.

@CliCommand(value = UNINSTALL_CMD, help = "Uninstall an instance of Rya.")
public String uninstall() {
    // Fetch the command that is connected to the store.
    final ShellState shellState = state.getShellState();
    final RyaClient commands = shellState.getConnectedCommands().get();
    final String ryaInstanceName = shellState.getRyaInstanceName().get();
    try {
        // Make sure the user meant to uninstall the Rya instance.
        if (!uninstallPrompt.promptAreYouSure(ryaInstanceName)) {
            return "Cancelled.";
        }
        // Perform the uninstall.
        commands.getUninstall().uninstall(ryaInstanceName);
    } catch (final InstanceDoesNotExistException e) {
        throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e);
    } catch (final IOException | RyaClientException e) {
        throw new RuntimeException("The Rya instance could not be uninstalled. Provided reason: " + e.getMessage(), e);
    }
    return "The Rya instance named '" + ryaInstanceName + "' has been uninstalled.";
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Aggregations

ShellState (org.apache.rya.shell.SharedShellState.ShellState)24 RyaClient (org.apache.rya.api.client.RyaClient)16 RyaClientException (org.apache.rya.api.client.RyaClientException)15 CliCommand (org.springframework.shell.core.annotation.CliCommand)13 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)9 Test (org.junit.Test)8 IOException (java.io.IOException)6 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)4 RyaDetails (org.apache.rya.api.instance.RyaDetails)3 GetInstanceDetails (org.apache.rya.api.client.GetInstanceDetails)2 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)2 InstallPrompt (org.apache.rya.shell.util.InstallPrompt)2 ApplicationContext (org.springframework.context.ApplicationContext)2 Bootstrap (org.springframework.shell.Bootstrap)2 CommandResult (org.springframework.shell.core.CommandResult)2 JLineShellComponent (org.springframework.shell.core.JLineShellComponent)2 CliAvailabilityIndicator (org.springframework.shell.core.annotation.CliAvailabilityIndicator)2 MongoClient (com.mongodb.MongoClient)1 MongoException (com.mongodb.MongoException)1 File (java.io.File)1