Search in sources :

Example 1 with RyaStreamsDetails

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);
    }
}
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 2 with RyaStreamsDetails

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.";
    }
}
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 3 with RyaStreamsDetails

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();
    }
}
Also used : RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) SetRyaStreamsConfiguration(org.apache.rya.api.client.SetRyaStreamsConfiguration) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 4 with RyaStreamsDetails

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);
    }
}
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) RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) InstanceExists(org.apache.rya.api.client.InstanceExists) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 5 with RyaStreamsDetails

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);
}
Also used : RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Aggregations

RyaStreamsDetails (org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails)16 Test (org.junit.Test)11 RyaClient (org.apache.rya.api.client.RyaClient)9 Date (java.util.Date)6 RyaDetails (org.apache.rya.api.instance.RyaDetails)6 EntityCentricIndexDetails (org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails)6 FreeTextIndexDetails (org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails)6 JoinSelectivityDetails (org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails)6 ProspectorDetails (org.apache.rya.api.instance.RyaDetails.ProspectorDetails)6 TemporalIndexDetails (org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails)6 BasicDBObject (com.mongodb.BasicDBObject)4 FluoDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails)4 RyaClientException (org.apache.rya.api.client.RyaClientException)3 CliCommand (org.springframework.shell.core.annotation.CliCommand)3 DBObject (com.mongodb.DBObject)2 Install (org.apache.rya.api.client.Install)2 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)2 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)2 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)2 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)2