use of org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails 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.instance.RyaDetails.RyaStreamsDetails 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.instance.RyaDetails.RyaStreamsDetails in project incubator-rya by apache.
the class RyaStreamsCommandsTest method configureRyaStreams.
@Test
public void configureRyaStreams() throws Exception {
// Mock the object that performs the configure operation.
final RyaClient mockCommands = mock(RyaClient.class);
final SetRyaStreamsConfiguration setStreams = mock(SetRyaStreamsConfiguration.class);
when(mockCommands.getSetRyaStreamsConfiguration()).thenReturn(setStreams);
// Mock a shell state and connect it to a Rya instance.
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance("unitTest");
// Verify that no Rya Streams Client is set to the state.
assertFalse(state.getShellState().getRyaStreamsCommands().isPresent());
try {
// Execute the command.
final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
final String message = commands.configureRyaStreams("localhost", 6);
// Verify the request was forwarded to the mocked interactor.
final RyaStreamsDetails expectedDetails = new RyaStreamsDetails("localhost", 6);
verify(setStreams).setRyaStreamsConfiguration(eq("unitTest"), eq(expectedDetails));
// Verify a RyaStreamsClient was created and added to the state.
assertTrue(state.getShellState().getRyaStreamsCommands().isPresent());
// Verify the correct message is reported.
final String expected = "The Rya Instance has been updated to use the provided Rya Streams subsystem. " + "Rya Streams commands are now avaiable while connected to this instance.";
assertEquals(expected, message);
} finally {
state.getShellState().getRyaStreamsCommands().get().close();
}
}
use of org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails 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.instance.RyaDetails.RyaStreamsDetails in project incubator-rya by apache.
the class MongoSetRyaStreamsConfigurationIT method instanceDoesNotExist.
@Test(expected = InstanceDoesNotExistException.class)
public void instanceDoesNotExist() throws Exception {
final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
// Skip the install step to create error causing situation.
final String ryaInstance = conf.getRyaInstanceName();
final RyaStreamsDetails details = new RyaStreamsDetails("localhost", 6);
ryaClient.getSetRyaStreamsConfiguration().setRyaStreamsConfiguration(ryaInstance, details);
}
Aggregations