Search in sources :

Example 6 with ShellState

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

the class RyaPromptProvider method getPrompt.

@Override
public String getPrompt() {
    final ShellState state = sharedState.getShellState();
    // figure out the storage name: disconnected, mongo host, or Accumulo instance.
    String storageName = "unknown";
    if (state.getStorageType().isPresent()) {
        if (state.getStorageType().get() == StorageType.ACCUMULO) {
            storageName = state.getAccumuloDetails().get().getInstanceName();
        } else if (state.getStorageType().get() == StorageType.MONGO) {
            storageName = state.getMongoDetails().get().getHostname();
        } else {
            throw new java.lang.IllegalStateException("Missing or unknown storage type.");
        }
    }
    switch(state.getConnectionState()) {
        case DISCONNECTED:
            return "rya> ";
        case CONNECTED_TO_STORAGE:
            return String.format("rya/%s> ", storageName);
        case CONNECTED_TO_INSTANCE:
            return String.format("rya/%s:%s> ", storageName, state.getRyaInstanceName().or("unknown"));
        default:
            return "rya> ";
    }
}
Also used : ShellState(org.apache.rya.shell.SharedShellState.ShellState)

Example 7 with ShellState

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

the class AccumuloRyaConnectionCommandsIT method connectToInstance.

@Test
public void connectToInstance() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();
    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean(PasswordPrompt.class);
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());
    // Connect to the mini accumulo instance.
    String cmd = RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " + "--username root " + "--instanceName " + cluster.getInstanceName() + " " + "--zookeepers " + cluster.getZooKeepers();
    CommandResult result = shell.executeCommand(cmd);
    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();
    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);
    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) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Bootstrap(org.springframework.shell.Bootstrap) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) PasswordPrompt(org.apache.rya.shell.util.PasswordPrompt) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.Test)

Example 8 with ShellState

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

the class SharedShellStateTest method disconnectedAgain.

@Test
public void disconnectedAgain() {
    // Indicate we have diconnected while already in the disconnected state.
    final SharedShellState state = new SharedShellState();
    state.disconnected();
    // Verify the state.
    final ShellState expected = ShellState.builder().setConnectionState(ConnectionState.DISCONNECTED).build();
    assertEquals(expected, state.getShellState());
}
Also used : ShellState(org.apache.rya.shell.SharedShellState.ShellState) Test(org.junit.Test)

Example 9 with ShellState

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

the class SharedShellStateTest method ConnectedToInstanceAgain.

@Test
public void ConnectedToInstanceAgain() {
    final SharedShellState state = new SharedShellState();
    // Connect to Accumulo.
    final AccumuloConnectionDetails connectionDetails = mock(AccumuloConnectionDetails.class);
    final RyaClient connectedCommands = mock(RyaClient.class);
    state.connectedToAccumulo(connectionDetails, connectedCommands);
    // Connect to an Instance.
    state.connectedToInstance("instance");
    // Connect to another instance.
    state.connectedToInstance("secondInstance");
    // Verify the state.
    final ShellState expected = ShellState.builder().setConnectionState(ConnectionState.CONNECTED_TO_INSTANCE).setAccumuloDetails(connectionDetails).setConnectedCommands(connectedCommands).setRyaInstanceName("secondInstance").build();
    assertEquals(expected, state.getShellState());
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 10 with ShellState

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

the class SharedShellStateTest method initialStateIsDisconnected.

@Test
public void initialStateIsDisconnected() {
    final SharedShellState state = new SharedShellState();
    // Verify disconnected and no values are set.
    final ShellState expected = ShellState.builder().setConnectionState(ConnectionState.DISCONNECTED).build();
    assertEquals(expected, state.getShellState());
}
Also used : ShellState(org.apache.rya.shell.SharedShellState.ShellState) Test(org.junit.Test)

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