Search in sources :

Example 6 with RyaClientException

use of org.apache.rya.api.client.RyaClientException 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 7 with RyaClientException

use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.

the class RyaAdminCommands method install.

@CliCommand(value = INSTALL_CMD, help = "Create a new instance of Rya interactively.")
public String install() {
    // Fetch the commands that are connected to the store.
    final RyaClient commands = state.getShellState().getConnectedCommands().get();
    String instanceName = null;
    InstallConfiguration installConfig = null;
    try {
        boolean verified = false;
        while (!verified) {
            // Use the install prompt to fetch the user's installation options.
            instanceName = installPrompt.promptInstanceName();
            installConfig = installPrompt.promptInstallConfiguration(instanceName);
            // Verify the configuration is what the user actually wants to do.
            verified = installPrompt.promptVerified(instanceName, installConfig);
        }
        // Execute the command.
        commands.getInstall().install(instanceName, installConfig);
        return String.format("The Rya instance named '%s' has been installed.", instanceName);
    } catch (final DuplicateInstanceNameException e) {
        throw new RuntimeException(String.format("A Rya instance named '%s' already exists. Try again with a different name.", instanceName), e);
    } catch (final IOException | RyaClientException e) {
        throw new RuntimeException("Could not install a new instance of Rya. Reason: " + e.getMessage(), e);
    }
}
Also used : DuplicateInstanceNameException(org.apache.rya.api.client.Install.DuplicateInstanceNameException) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaClient(org.apache.rya.api.client.RyaClient) IOException(java.io.IOException) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 8 with RyaClientException

use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.

the class RyaAdminCommands method deletePcj.

@CliCommand(value = DELETE_PCJ_CMD, help = "Deletes and halts maintenance of a PCJ.")
public String deletePcj(@CliOption(key = { "pcjId" }, mandatory = true, help = "The ID of the PCJ that will be deleted.") final String pcjId) {
    // 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 {
        // Execute the command.
        commands.getDeletePCJ().deletePCJ(ryaInstance, pcjId);
        return "The PCJ has been deleted.";
    } 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 PCJ could not be deleted. Provided reason: " + e.getMessage(), e);
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 9 with RyaClientException

use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.

the class RyaAdminCommands method createPcj.

@CliCommand(value = CREATE_PCJ_CMD, help = "Creates and starts the maintenance of a new PCJ using a Fluo application.")
public String createPcj(@CliOption(key = { "exportToRya" }, mandatory = false, help = "Indicates that results for the query should be exported to a Rya PCJ table.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") final boolean exportToRya, @CliOption(key = { "exportToKafka" }, mandatory = false, help = "Indicates that results for the query should be exported to a Kafka Topic.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") final boolean exportToKafka) {
    // 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 {
        final Set<ExportStrategy> strategies = new HashSet<>();
        if (exportToRya) {
            strategies.add(ExportStrategy.RYA);
        }
        if (exportToKafka) {
            strategies.add(ExportStrategy.KAFKA);
        }
        if (strategies.isEmpty()) {
            return "The user must specify at least one export strategy: (--exportToRya, --exportToKafka)";
        }
        // Prompt the user for the SPARQL.
        final Optional<String> sparql = sparqlPrompt.getSparql();
        if (sparql.isPresent()) {
            // Execute the command.
            final String pcjId = commands.getCreatePCJ().createPCJ(ryaInstance, sparql.get(), strategies);
            // Return a message that indicates the ID of the newly created ID.
            return String.format("The 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 PCJ. Provided reasons: " + e.getMessage(), e);
    }
}
Also used : ExportStrategy(org.apache.rya.api.client.CreatePCJ.ExportStrategy) RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) IOException(java.io.IOException) HashSet(java.util.HashSet) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 10 with RyaClientException

use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.

the class RyaAdminCommands method deletePeriodicPcj.

@CliCommand(value = DELETE_PERIODIC_PCJ_CMD, help = "Deletes and halts maintenance of a Periodic PCJ.")
public String deletePeriodicPcj(@CliOption(key = { "pcjId" }, mandatory = true, help = "The ID of the PCJ that will be deleted.") final String pcjId, @CliOption(key = { "topic" }, mandatory = true, help = "Kafka topic for registering a delete notice to remove a PeriodicNotification from 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 {
        // Execute the command.
        commands.getDeletePeriodicPCJ().get().deletePeriodicPCJ(ryaInstance, pcjId, topic, brokers);
        return "The Periodic PCJ has been deleted.";
    } 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 Periodic PCJ could not be deleted. Provided reason: " + e.getMessage(), e);
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaClient(org.apache.rya.api.client.RyaClient) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Aggregations

RyaClientException (org.apache.rya.api.client.RyaClientException)48 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)27 RyaClient (org.apache.rya.api.client.RyaClient)18 CliCommand (org.springframework.shell.core.annotation.CliCommand)18 RyaDetails (org.apache.rya.api.instance.RyaDetails)17 ShellState (org.apache.rya.shell.SharedShellState.ShellState)14 RyaDetailsRepositoryException (org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)13 SailException (org.openrdf.sail.SailException)13 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)12 IOException (java.io.IOException)11 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)11 Sail (org.openrdf.sail.Sail)10 PCJStorageException (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)9 RepositoryException (org.openrdf.repository.RepositoryException)9 InferenceEngineException (org.apache.rya.rdftriplestore.inference.InferenceEngineException)8 MalformedQueryException (org.openrdf.query.MalformedQueryException)8 RyaDetailsRepository (org.apache.rya.api.instance.RyaDetailsRepository)7 SailRepository (org.openrdf.repository.sail.SailRepository)7 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7