use of org.apache.rya.shell.SharedShellState.ShellState in project incubator-rya by apache.
the class RyaAdminCommands method listFluoQueries.
@CliCommand(value = LIST_INCREMENTAL_QUERIES, help = "Lists relevant information about all SPARQL queries maintained by the Fluo application.")
public String listFluoQueries() {
// 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 {
return commands.getListIncrementalQueries().get().listIncrementalQueries(ryaInstance);
} 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 list incremental queries. Provided reasons: " + e.getMessage(), e);
}
}
use of org.apache.rya.shell.SharedShellState.ShellState 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;
}
use of org.apache.rya.shell.SharedShellState.ShellState 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);
}
}
use of org.apache.rya.shell.SharedShellState.ShellState 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);
}
}
use of org.apache.rya.shell.SharedShellState.ShellState 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);
}
}
Aggregations