Search in sources :

Example 6 with RyaClient

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);
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) DeletePeriodicPCJ(org.apache.rya.api.client.DeletePeriodicPCJ) RyaClient(org.apache.rya.api.client.RyaClient) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Example 7 with RyaClient

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);
}
Also used : ExportStrategy(org.apache.rya.api.client.CreatePCJ.ExportStrategy) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) CreatePCJ(org.apache.rya.api.client.CreatePCJ) RyaClient(org.apache.rya.api.client.RyaClient) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Example 8 with RyaClient

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);
    }
}
Also used : RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 9 with RyaClient

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.";
    }
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) RyaClientException(org.apache.rya.api.client.RyaClientException) RyaClient(org.apache.rya.api.client.RyaClient) RyaClientException(org.apache.rya.api.client.RyaClientException) MalformedQueryException(org.openrdf.query.MalformedQueryException) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 10 with RyaClient

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);
}
Also used : ListInstances(org.apache.rya.api.client.ListInstances) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Aggregations

RyaClient (org.apache.rya.api.client.RyaClient)105 Test (org.junit.Test)76 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)41 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)29 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)26 CliCommand (org.springframework.shell.core.annotation.CliCommand)20 RyaClientException (org.apache.rya.api.client.RyaClientException)18 Install (org.apache.rya.api.client.Install)17 ShellState (org.apache.rya.shell.SharedShellState.ShellState)16 InstallPrompt (org.apache.rya.shell.util.InstallPrompt)16 UninstallPrompt (org.apache.rya.shell.util.UninstallPrompt)16 RyaDetails (org.apache.rya.api.instance.RyaDetails)14 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)13 IOException (java.io.IOException)11 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)9 Sail (org.openrdf.sail.Sail)9 ValueFactory (org.openrdf.model.ValueFactory)8 HashSet (java.util.HashSet)7 Connector (org.apache.accumulo.core.client.Connector)7 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)7