Search in sources :

Example 31 with RyaClientException

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

Example 32 with RyaClientException

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

the class RyaAdminCommands method installWithMongoParameters.

@CliCommand(value = INSTALL_MONGO_PARAMETERS_CMD, help = "Create a new MongoDB instance of Rya with command line parameters.")
public String installWithMongoParameters(@CliOption(key = { "instanceName" }, mandatory = true, help = "The name of the Rya instance to create.") final String instanceName, @CliOption(key = { "enableFreeTextIndex" }, mandatory = false, help = "Use Free Text Indexing.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") final boolean enableFreeTextIndex, @CliOption(key = { "enableTemporalIndex" }, mandatory = false, help = "Use Temporal Indexing.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") final boolean enableTemporalIndex, @CliOption(key = { "enablePcjIndex" }, mandatory = false, help = "Use Precomputed Join (PCJ) Indexing.", unspecifiedDefaultValue = "false", specifiedDefaultValue = "true") final boolean enablePcjIndex) {
    // Fetch the commands that are connected to the store.
    final RyaClient commands = state.getShellState().getConnectedCommands().get();
    try {
        final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableFreeTextIndex(enableFreeTextIndex).setEnableTemporalIndex(enableTemporalIndex).setEnablePcjIndex(enablePcjIndex).build();
        // Verify the configuration is what the user actually wants to do.
        if (!installPrompt.promptVerified(instanceName, installConfig)) {
            return "Skipping Installation.";
        }
        // 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 33 with RyaClientException

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

the class RyaAdminCommands method printInstanceDetails.

@CliCommand(value = PRINT_INSTANCE_DETAILS_CMD, help = "Print information about how the Rya instance is configured.")
public String printInstanceDetails() {
    // 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 Optional<RyaDetails> details = commands.getGetInstanceDetails().getDetails(ryaInstance);
        if (details.isPresent()) {
            return new RyaDetailsFormatter().format(shellState.getStorageType().get(), details.get());
        } else {
            return "This instance of Rya does not have a Rya Details table. Consider migrating to a newer version of Rya.";
        }
    } 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("Could not get the instance details. Reason: " + e.getMessage(), e);
    }
}
Also used : RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) RyaDetailsFormatter(org.apache.rya.shell.util.RyaDetailsFormatter) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 34 with RyaClientException

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

the class RyaAdminCommands method addUser.

@CliCommand(value = ADD_USER_CMD, help = "Adds an authorized user to the Rya instance.")
public void addUser(@CliOption(key = { "username" }, mandatory = true, help = "The username of the user that will be granted access.") 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.getAddUser().get().addUser(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 granted. 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 35 with RyaClientException

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

the class RyaCommands method loadData.

@CliCommand(value = LOAD_DATA_CMD, help = "Loads RDF Statement data from a local file to the connected Rya instance.")
public String loadData(@CliOption(key = { "file" }, mandatory = true, help = "A local file containing RDF Statements that is to be loaded.") final String file, @CliOption(key = { "format" }, mandatory = false, help = "The format of the supplied RDF Statements file. [RDF/XML, N-Triples, Turtle, N3, TriX, TriG, BinaryRDF, N-Quads, JSON-LD, RDF/JSON, RDFa]") final String format) {
    // Fetch the command that is connected to the store.
    final ShellState shellState = state.getShellState();
    final RyaClient commands = shellState.getConnectedCommands().get();
    final Optional<String> ryaInstanceName = shellState.getRyaInstanceName();
    try {
        final long start = System.currentTimeMillis();
        // If the provided path is relative, then make it rooted in the user's home.
        // Make sure the path is formatted with Unix style file
        // separators('/') before using it as a regex replacement string.
        // Windows file separators('\') will not work unless escaped.
        final String userHome = FilenameUtils.separatorsToUnix(System.getProperty("user.home"));
        final Path rootedFile = Paths.get(file.replaceFirst("^~", userHome));
        RDFFormat rdfFormat = null;
        // If a format was provided, then go with that.
        if (format != null) {
            rdfFormat = RDFFormat.valueOf(format);
            if (rdfFormat == null) {
                throw new RuntimeException("Unsupported RDF Statement data input format: " + format);
            }
        } else // Otherwise try to figure it out using the filename.
        if (rdfFormat == null) {
            rdfFormat = RDFFormat.forFileName(rootedFile.getFileName().toString());
            if (rdfFormat == null) {
                throw new RuntimeException("Unable to detect RDF Statement data input format for file: " + rootedFile);
            } else {
                consolePrinter.println("Detected RDF Format: " + rdfFormat);
                consolePrinter.flush();
            }
        }
        commands.getLoadStatementsFile().loadStatements(ryaInstanceName.get(), rootedFile, rdfFormat);
        final String seconds = new DecimalFormat("0.0##").format((System.currentTimeMillis() - start) / 1000.0);
        return "Loaded the file: '" + file + "' successfully in " + seconds + " seconds.";
    } catch (final RyaClientException | IOException e) {
        log.error("Error", e);
        throw new RuntimeException("Can not load the RDF Statement data. Reason: " + e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) RyaClientException(org.apache.rya.api.client.RyaClientException) ShellState(org.apache.rya.shell.SharedShellState.ShellState) DecimalFormat(java.text.DecimalFormat) RyaClient(org.apache.rya.api.client.RyaClient) IOException(java.io.IOException) RDFFormat(org.openrdf.rio.RDFFormat) 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