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