use of org.apache.rya.shell.SharedShellState.ShellState 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;
}
use of org.apache.rya.shell.SharedShellState.ShellState 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.shell.SharedShellState.ShellState 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.shell.SharedShellState.ShellState 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.shell.SharedShellState.ShellState 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