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