use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.
the class RyaStreamsCommands method printRyaStreamsDetails.
@CliCommand(value = STREAMS_DETAILS_CMD, help = "Print information about which Rya Streams subsystem the Rya instance is connected to.")
public String printRyaStreamsDetails() {
final String ryaInstance = state.getShellState().getRyaInstanceName().get();
final RyaClient client = state.getShellState().getConnectedCommands().get();
try {
// Handle the case where the instance does not have Rya Details.
final Optional<RyaDetails> details = client.getGetInstanceDetails().getDetails(ryaInstance);
if (!details.isPresent()) {
return "This instance does not have any Rya Details, so it is unable to be connected to the Rya Streams subsystem.";
}
// Print a message based on if the instance is connected to Rya Streams.
final Optional<RyaStreamsDetails> streamsDetails = details.get().getRyaStreamsDetails();
if (!streamsDetails.isPresent()) {
return "This instance of Rya has not been configured to use a Rya Streams subsystem.";
}
// Print the details about which Rya Streams subsystem is being used.
return "Kafka Hostname: " + streamsDetails.get().getHostname() + ", Kafka Port: " + streamsDetails.get().getPort();
} catch (final RyaClientException e) {
throw new RuntimeException("Could not fetch the Rya Details for this Rya instance.", e);
}
}
use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.
the class RyaStreamsCommands method configureRyaStreams.
@CliCommand(value = STREAMS_CONFIGURE_CMD, help = "Connect a Rya Streams subsystem to a Rya Instance.")
public String configureRyaStreams(@CliOption(key = { "kafkaHostname" }, mandatory = true, help = "The hostname of the Kafka Broker.") final String kafkaHostname, @CliOption(key = { "kafkaPort" }, mandatory = true, help = "The port of the Kafka Broker.") final int kafkaPort) {
// If this instance was connected to a different Rya Streams subsystem, then close that client.
final Optional<RyaStreamsClient> oldClient = state.getShellState().getRyaStreamsCommands();
if (oldClient.isPresent()) {
try {
oldClient.get().close();
} catch (final Exception e) {
System.err.print("Warning: Could not close the old Rya Streams Client.");
e.printStackTrace();
}
}
// Update the Rya Details for the connected Rya Instance.
final String ryaInstance = state.getShellState().getRyaInstanceName().get();
final RyaClient ryaClient = state.getShellState().getConnectedCommands().get();
try {
final RyaStreamsDetails streamsDetails = new RyaStreamsDetails(kafkaHostname, kafkaPort);
ryaClient.getSetRyaStreamsConfiguration().setRyaStreamsConfiguration(ryaInstance, streamsDetails);
} catch (final RyaClientException e) {
throw new RuntimeException("Could not update the Rya instance's Rya Details to include the new " + "information. This command failed to complete.", e);
}
// Connect a Rya Streams Client and set it in the shared state.
final RyaStreamsClient newClient = KafkaRyaStreamsClientFactory.make(ryaInstance, kafkaHostname, kafkaPort);
state.connectedToRyaStreams(newClient);
// Return a message that indicates the operation was successful.
if (oldClient.isPresent()) {
return "The Rya Streams subsystem that this Rya instance uses has been changed. Any queries that were " + "maintained by the previous subsystem will need to be migrated to the new one.";
} else {
return "The Rya Instance has been updated to use the provided Rya Streams subsystem. " + "Rya Streams commands are now avaiable while connected to this instance.";
}
}
use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.
the class RyaConnectionCommands method connectToInstance.
@CliCommand(value = CONNECT_INSTANCE_CMD, help = "Connect to a specific Rya instance")
public void connectToInstance(@CliOption(key = { "instance" }, mandatory = true, help = "The name of the Rya instance the shell will interact with.") final String ryaInstance) {
final RyaClient ryaClient = sharedState.getShellState().getConnectedCommands().get();
try {
final InstanceExists instanceExists = ryaClient.getInstanceExists();
// Make sure the requested instance exists.
if (!instanceExists.exists(ryaInstance)) {
throw new RuntimeException(String.format("'%s' does not match an existing Rya instance.", ryaInstance));
}
// Store the instance name in the shared state.
sharedState.connectedToInstance(ryaInstance);
// If the Rya instance is configured to interact with Rya Streams, then connect the
// Rya Streams client to the shared state.
final com.google.common.base.Optional<RyaDetails> ryaDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance);
if (ryaDetails.isPresent()) {
final com.google.common.base.Optional<RyaStreamsDetails> streamsDetails = ryaDetails.get().getRyaStreamsDetails();
if (streamsDetails.isPresent()) {
final String kafkaHostname = streamsDetails.get().getHostname();
final int kafkaPort = streamsDetails.get().getPort();
final RyaStreamsClient streamsClient = KafkaRyaStreamsClientFactory.make(ryaInstance, kafkaHostname, kafkaPort);
sharedState.connectedToRyaStreams(streamsClient);
}
}
} catch (final RyaClientException e) {
throw new RuntimeException("Could not connect to Rya instance. Reason: " + e.getMessage(), e);
}
}
use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.
the class AccumuloCreatePCJ method createPCJ.
@Override
public String createPCJ(final String instanceName, final String sparql, Set<ExportStrategy> strategies) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(instanceName);
requireNonNull(sparql);
final Optional<RyaDetails> ryaDetailsHolder = getInstanceDetails.getDetails(instanceName);
final boolean ryaInstanceExists = ryaDetailsHolder.isPresent();
if (!ryaInstanceExists) {
throw new InstanceDoesNotExistException(String.format("The '%s' instance of Rya does not exist.", instanceName));
}
final PCJIndexDetails pcjIndexDetails = ryaDetailsHolder.get().getPCJIndexDetails();
final boolean pcjIndexingEnabeld = pcjIndexDetails.isEnabled();
if (!pcjIndexingEnabeld) {
throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ Indexing enabled.", instanceName));
}
// Create the PCJ table that will receive the index results.
final String pcjId;
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(getConnector(), instanceName)) {
pcjId = pcjStorage.createPcj(sparql);
// If a Fluo application is being used, task it with updating the PCJ.
final Optional<FluoDetails> fluoDetailsHolder = pcjIndexDetails.getFluoDetails();
if (fluoDetailsHolder.isPresent()) {
final String fluoAppName = fluoDetailsHolder.get().getUpdateAppName();
try {
updateFluoApp(instanceName, fluoAppName, pcjId, sparql, strategies);
} catch (RepositoryException | MalformedQueryException | SailException | QueryEvaluationException | PcjException | RyaDAOException e) {
throw new RyaClientException("Problem while initializing the Fluo application with the new PCJ.", e);
} catch (UnsupportedQueryException e) {
throw new RyaClientException("The new PCJ could not be initialized because it either contains an unsupported query node " + "or an invalid ExportStrategy for the given QueryType. Projection queries can be exported to either Rya or Kafka," + "unless they contain an aggregation, in which case they can only be exported to Kafka. Construct queries can be exported" + "to Rya and Kafka, and Periodic queries can only be exported to Rya.");
}
// Update the Rya Details to indicate the PCJ is being updated incrementally.
final RyaDetailsRepository detailsRepo = new AccumuloRyaInstanceDetailsRepository(getConnector(), instanceName);
try {
new RyaDetailsUpdater(detailsRepo).update(new RyaDetailsMutator() {
@Override
public RyaDetails mutate(final RyaDetails originalDetails) throws CouldNotApplyMutationException {
// Update the original PCJ Details to indicate they are incrementally updated.
final PCJDetails originalPCJDetails = originalDetails.getPCJIndexDetails().getPCJDetails().get(pcjId);
final PCJDetails.Builder mutatedPCJDetails = PCJDetails.builder(originalPCJDetails).setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL);
// Replace the old PCJ Details with the updated ones.
final RyaDetails.Builder builder = RyaDetails.builder(originalDetails);
builder.getPCJIndexDetails().addPCJDetails(mutatedPCJDetails);
return builder.build();
}
});
} catch (RyaDetailsRepositoryException | CouldNotApplyMutationException e) {
throw new RyaClientException("Problem while updating the Rya instance's Details to indicate the PCJ is being incrementally updated.", e);
}
}
// Return the ID that was assigned to the PCJ.
return pcjId;
} catch (final PCJStorageException e) {
throw new RyaClientException("Problem while initializing the PCJ table.", e);
}
}
use of org.apache.rya.api.client.RyaClientException in project incubator-rya by apache.
the class AccumuloDeletePCJ method deletePCJ.
@Override
public void deletePCJ(final String instanceName, final String pcjId) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(instanceName);
requireNonNull(pcjId);
final Optional<RyaDetails> originalDetails = getInstanceDetails.getDetails(instanceName);
final boolean ryaInstanceExists = originalDetails.isPresent();
if (!ryaInstanceExists) {
throw new InstanceDoesNotExistException(String.format("The '%s' instance of Rya does not exist.", instanceName));
}
final boolean pcjIndexingEnabeld = originalDetails.get().getPCJIndexDetails().isEnabled();
if (!pcjIndexingEnabeld) {
throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ Indexing enabled.", instanceName));
}
final boolean pcjExists = originalDetails.get().getPCJIndexDetails().getPCJDetails().containsKey(pcjId);
if (!pcjExists) {
throw new RyaClientException(String.format("The '%s' instance of Rya does not have PCJ with ID '%s'.", instanceName, pcjId));
}
// If the PCJ was being maintained by a Fluo application, then stop that process.
final PCJIndexDetails pcjIndexDetails = originalDetails.get().getPCJIndexDetails();
final PCJDetails droppedPcjDetails = pcjIndexDetails.getPCJDetails().get(pcjId);
if (droppedPcjDetails.getUpdateStrategy().isPresent()) {
if (droppedPcjDetails.getUpdateStrategy().get() == PCJUpdateStrategy.INCREMENTAL) {
final Optional<FluoDetails> fluoDetailsHolder = pcjIndexDetails.getFluoDetails();
if (fluoDetailsHolder.isPresent()) {
final String fluoAppName = pcjIndexDetails.getFluoDetails().get().getUpdateAppName();
stopUpdatingPCJ(fluoAppName, pcjId);
} else {
log.error(String.format("Could not stop the Fluo application from updating the PCJ because the Fluo Details are " + "missing for the Rya instance named '%s'.", instanceName));
}
}
}
// Drop the table that holds the PCJ results from Accumulo.
try (final PrecomputedJoinStorage pcjs = new AccumuloPcjStorage(getConnector(), instanceName)) {
pcjs.dropPcj(pcjId);
} catch (final PCJStorageException e) {
throw new RyaClientException("Could not drop the PCJ's table from Accumulo.", e);
}
}
Aggregations