use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaAdminCommandsTest method deletePeriodicPCJ.
@Test
public void deletePeriodicPCJ() throws InstanceDoesNotExistException, RyaClientException {
// Mock the object that performs the delete operation.
final DeletePeriodicPCJ mockDeletePCJ = mock(DeletePeriodicPCJ.class);
final RyaClient mockCommands = mock(RyaClient.class);
when(mockCommands.getDeletePeriodicPCJ()).thenReturn(java.util.Optional.of(mockDeletePCJ));
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
final String instanceName = "unitTests";
state.connectedToInstance(instanceName);
// Execute the command.
final String pcjId = "123412342";
final String topic = "topic";
final String brokers = "brokers";
final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class), mock(UninstallPrompt.class));
final String message = commands.deletePeriodicPcj(pcjId, topic, brokers);
// Verify the values that were provided to the command were passed through to the DeletePCJ.
verify(mockDeletePCJ).deletePeriodicPCJ(eq(instanceName), eq(pcjId), eq(topic), eq(brokers));
// Verify a message is returned that explains what was deleted.
final String expected = "The Periodic PCJ has been deleted.";
assertEquals(expected, message);
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaAdminCommandsTest method createPCJ.
@Test
public void createPCJ() throws InstanceDoesNotExistException, RyaClientException, IOException {
// Mock the object that performs the create operation.
final String instanceName = "unitTest";
final String sparql = "SELECT * WHERE { ?person <http://isA> ?noun }";
final String pcjId = "123412342";
final CreatePCJ mockCreatePCJ = mock(CreatePCJ.class);
final Set<ExportStrategy> strategies = Sets.newHashSet(ExportStrategy.RYA);
when(mockCreatePCJ.createPCJ(eq(instanceName), eq(sparql), eq(strategies))).thenReturn(pcjId);
final RyaClient mockCommands = mock(RyaClient.class);
when(mockCommands.getCreatePCJ()).thenReturn(mockCreatePCJ);
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance(instanceName);
final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
when(mockSparqlPrompt.getSparql()).thenReturn(Optional.of(sparql));
// Execute the command.
final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mockSparqlPrompt, mock(UninstallPrompt.class));
final String message = commands.createPcj(true, false);
// Verify the values that were provided to the command were passed through to CreatePCJ.
verify(mockCreatePCJ).createPCJ(eq(instanceName), eq(sparql), eq(strategies));
// Verify a message is returned that explains what was created.
final String expected = "The PCJ has been created. Its ID is '123412342'.";
assertEquals(expected, message);
}
use of org.apache.rya.api.client.RyaClient 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.RyaClient 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.RyaClient in project incubator-rya by apache.
the class RyaAdminCommandsTest method listInstances.
@Test
public void listInstances() throws RyaClientException, IOException {
// Mock the object that performs the list operation.
final ListInstances mockListInstances = mock(ListInstances.class);
final List<String> instanceNames = Lists.newArrayList("a", "b", "c", "d");
when(mockListInstances.listInstances()).thenReturn(instanceNames);
final RyaClient mockCommands = mock(RyaClient.class);
when(mockCommands.getListInstances()).thenReturn(mockListInstances);
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance("b");
// Execute the command.
final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class), mock(UninstallPrompt.class));
final String message = commands.listInstances();
// Verify a message is returned that lists the the instances.
final String expected = "Rya instance names:\n" + " a\n" + " * b\n" + " c\n" + " d\n";
assertEquals(expected, message);
}
Aggregations