Search in sources :

Example 1 with CliAvailabilityIndicator

use of org.springframework.shell.core.annotation.CliAvailabilityIndicator in project incubator-rya by apache.

the class RyaAdminCommands method arePeriodicPCJCommandsAvailable.

/**
 * Enables commands that are available when the Shell is connected to a Rya Instance that supports PCJ Indexing.
 */
@CliAvailabilityIndicator({ CREATE_PERIODIC_PCJ_CMD, DELETE_PERIODIC_PCJ_CMD, LIST_INCREMENTAL_QUERIES })
public boolean arePeriodicPCJCommandsAvailable() {
    // The PCJ commands are only available if the Shell is connected to an instance of Rya
    // that is new enough to use the RyaDetailsRepository and is configured to maintain PCJs.
    final ShellState shellState = state.getShellState();
    if (shellState.getConnectionState() == ConnectionState.CONNECTED_TO_INSTANCE && shellState.getStorageType().get() == StorageType.ACCUMULO) {
        final GetInstanceDetails getInstanceDetails = shellState.getConnectedCommands().get().getGetInstanceDetails();
        final String ryaInstanceName = state.getShellState().getRyaInstanceName().get();
        try {
            final Optional<RyaDetails> instanceDetails = getInstanceDetails.getDetails(ryaInstanceName);
            if (instanceDetails.isPresent()) {
                return instanceDetails.get().getPCJIndexDetails().isEnabled();
            }
        } catch (final RyaClientException e) {
            return false;
        }
    }
    return false;
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) GetInstanceDetails(org.apache.rya.api.client.GetInstanceDetails) RyaDetails(org.apache.rya.api.instance.RyaDetails) CliAvailabilityIndicator(org.springframework.shell.core.annotation.CliAvailabilityIndicator)

Example 2 with CliAvailabilityIndicator

use of org.springframework.shell.core.annotation.CliAvailabilityIndicator in project geode by apache.

the class CommandManager method add.

/**
   * Method to add new Commands to the parser
   *
   * @param commandMarker
   */
void add(CommandMarker commandMarker) {
    if (CommandManagerAware.class.isAssignableFrom(commandMarker.getClass())) {
        ((CommandManagerAware) commandMarker).setCommandManager(this);
    }
    commandMarkers.add(commandMarker);
    for (Method method : commandMarker.getClass().getMethods()) {
        CliCommand cliCommand = method.getAnnotation(CliCommand.class);
        CliAvailabilityIndicator availability = method.getAnnotation(CliAvailabilityIndicator.class);
        if (cliCommand == null && availability == null) {
            continue;
        }
        if (cliCommand != null) {
            helper.addCommand(cliCommand, method);
        }
        if (availability != null) {
            helper.addAvailabilityIndicator(availability, new MethodTarget(method, commandMarker));
        }
    }
}
Also used : CliAvailabilityIndicator(org.springframework.shell.core.annotation.CliAvailabilityIndicator) MethodTarget(org.springframework.shell.core.MethodTarget) CliCommand(org.springframework.shell.core.annotation.CliCommand) Method(java.lang.reflect.Method)

Example 3 with CliAvailabilityIndicator

use of org.springframework.shell.core.annotation.CliAvailabilityIndicator in project incubator-rya by apache.

the class RyaAdminCommands method arePCJCommandsAvailable.

/**
 * Enables commands that are available when the Shell is connected to a Rya Instance that supports PCJ Indexing.
 */
@CliAvailabilityIndicator({ CREATE_PCJ_CMD, DELETE_PCJ_CMD })
public boolean arePCJCommandsAvailable() {
    // The PCJ commands are only available if the Shell is connected to an instance of Rya
    // that is new enough to use the RyaDetailsRepository and is configured to maintain PCJs.
    final ShellState shellState = state.getShellState();
    if (shellState.getConnectionState() == ConnectionState.CONNECTED_TO_INSTANCE) {
        final GetInstanceDetails getInstanceDetails = shellState.getConnectedCommands().get().getGetInstanceDetails();
        final String ryaInstanceName = state.getShellState().getRyaInstanceName().get();
        try {
            final Optional<RyaDetails> instanceDetails = getInstanceDetails.getDetails(ryaInstanceName);
            if (instanceDetails.isPresent()) {
                return instanceDetails.get().getPCJIndexDetails().isEnabled();
            }
        } catch (final RyaClientException e) {
            return false;
        }
    }
    return false;
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) GetInstanceDetails(org.apache.rya.api.client.GetInstanceDetails) RyaDetails(org.apache.rya.api.instance.RyaDetails) CliAvailabilityIndicator(org.springframework.shell.core.annotation.CliAvailabilityIndicator)

Aggregations

CliAvailabilityIndicator (org.springframework.shell.core.annotation.CliAvailabilityIndicator)3 GetInstanceDetails (org.apache.rya.api.client.GetInstanceDetails)2 RyaClientException (org.apache.rya.api.client.RyaClientException)2 RyaDetails (org.apache.rya.api.instance.RyaDetails)2 ShellState (org.apache.rya.shell.SharedShellState.ShellState)2 Method (java.lang.reflect.Method)1 MethodTarget (org.springframework.shell.core.MethodTarget)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1