Search in sources :

Example 1 with InstanceNamesFormatter

use of org.apache.rya.shell.util.InstanceNamesFormatter in project incubator-rya by apache.

the class RyaAdminCommands method listInstances.

@CliCommand(value = LIST_INSTANCES_CMD, help = "List the names of the installed Rya instances.")
public String listInstances() {
    // Fetch the command that is connected to the store.
    final ShellState shellState = state.getShellState();
    final RyaClient commands = shellState.getConnectedCommands().get();
    final Optional<String> ryaInstance = shellState.getRyaInstanceName();
    try {
        final List<String> instanceNames = commands.getListInstances().listInstances();
        // Return a special message when there are no instances installed.
        if (instanceNames.isEmpty()) {
            return "There are no Rya instances installed on this storage.";
        }
        // Sort the names alphabetically.
        Collections.sort(instanceNames);
        // Return a pretty print of the instances that have been installed.
        final String report;
        final InstanceNamesFormatter formatter = new InstanceNamesFormatter();
        if (ryaInstance.isPresent()) {
            report = formatter.format(instanceNames, ryaInstance.get());
        } else {
            report = formatter.format(instanceNames);
        }
        return report;
    } catch (final RyaClientException e) {
        throw new RuntimeException("Can not list the Rya instances. Reason: " + e.getMessage(), e);
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) InstanceNamesFormatter(org.apache.rya.shell.util.InstanceNamesFormatter) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Aggregations

RyaClient (org.apache.rya.api.client.RyaClient)1 RyaClientException (org.apache.rya.api.client.RyaClientException)1 ShellState (org.apache.rya.shell.SharedShellState.ShellState)1 InstanceNamesFormatter (org.apache.rya.shell.util.InstanceNamesFormatter)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1