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> ";
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations