Search in sources :

Example 21 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class RyaStreamsCommandsTest method printRyaStreamsDetails_notConfigured.

@Test
public void printRyaStreamsDetails_notConfigured() throws Exception {
    // Mock the object that performs the configure operation.
    final RyaClient mockCommands = mock(RyaClient.class);
    final GetInstanceDetails getDetails = mock(GetInstanceDetails.class);
    when(mockCommands.getGetInstanceDetails()).thenReturn(getDetails);
    // When getting the instance details, ensure they do not have RyaStreamsDetails to print.
    final RyaDetails details = mock(RyaDetails.class);
    when(details.getRyaStreamsDetails()).thenReturn(Optional.absent());
    when(getDetails.getDetails(eq("unitTest"))).thenReturn(Optional.of(details));
    // 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");
    // Execute the command.
    final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
    final String message = commands.printRyaStreamsDetails();
    final String expected = "This instance of Rya has not been configured to use a Rya Streams subsystem.";
    assertEquals(expected, message);
}
Also used : ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) GetInstanceDetails(org.apache.rya.api.client.GetInstanceDetails) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 22 with RyaClient

use of org.apache.rya.api.client.RyaClient 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 23 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class RyaStreamsCommandsTest method printRyaStreamsDetails_noRyaDetails.

@Test
public void printRyaStreamsDetails_noRyaDetails() throws Exception {
    // Mock the object that performs the configure operation.
    final RyaClient mockCommands = mock(RyaClient.class);
    final GetInstanceDetails getDetails = mock(GetInstanceDetails.class);
    when(mockCommands.getGetInstanceDetails()).thenReturn(getDetails);
    // When getting the instance details, ensure they are not found.
    when(getDetails.getDetails(eq("unitTest"))).thenReturn(Optional.absent());
    // 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");
    // Execute the command.
    final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
    final String message = commands.printRyaStreamsDetails();
    final String expected = "This instance does not have any Rya Details, so it is unable to be connected to the Rya Streams subsystem.";
    assertEquals(expected, message);
}
Also used : ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) GetInstanceDetails(org.apache.rya.api.client.GetInstanceDetails) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 24 with RyaClient

use of org.apache.rya.api.client.RyaClient 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 25 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class AccumuloBatchUpdatePCJIT method batchUpdate.

@Test
public void batchUpdate() throws Exception {
    // Setup a Rya Client.
    final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(super.getUsername(), super.getPassword().toCharArray(), super.getInstanceName(), super.getZookeepers());
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, super.getConnector());
    // Install an instance of Rya on the mini accumulo cluster.
    ryaClient.getInstall().install(RYA_INSTANCE_NAME, InstallConfiguration.builder().setEnablePcjIndex(true).build());
    Sail sail = null;
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(super.getConnector(), RYA_INSTANCE_NAME)) {
        // Get a Sail connection backed by the installed Rya instance.
        final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
        ryaConf.setTablePrefix(RYA_INSTANCE_NAME);
        ryaConf.set(ConfigUtils.CLOUDBASE_USER, super.getUsername());
        ryaConf.set(ConfigUtils.CLOUDBASE_PASSWORD, super.getPassword());
        ryaConf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, super.getZookeepers());
        ryaConf.set(ConfigUtils.CLOUDBASE_INSTANCE, super.getInstanceName());
        ryaConf.set(ConfigUtils.USE_PCJ, "true");
        ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.toString());
        ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinUpdaterType.NO_UPDATE.toString());
        sail = RyaSailFactory.getInstance(ryaConf);
        // Load some statements into the Rya instance.
        final ValueFactory vf = sail.getValueFactory();
        final SailConnection sailConn = sail.getConnection();
        sailConn.begin();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
        sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:green"));
        sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:brown"));
        sailConn.commit();
        sailConn.close();
        // Create a PCJ for a SPARQL query.
        final String sparql = "SELECT ?name WHERE { ?name <urn:likes> <urn:icecream> . ?name <urn:hasEyeColor> <urn:blue> . }";
        final String pcjId = pcjStorage.createPcj(sparql);
        // Run the test.
        ryaClient.getBatchUpdatePCJ().batchUpdate(RYA_INSTANCE_NAME, pcjId);
        // Verify the correct results were loaded into the PCJ table.
        final Set<BindingSet> expectedResults = new HashSet<>();
        MapBindingSet bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Alice"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Bob"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Charlie"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:David"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Eve"));
        expectedResults.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("name", vf.createURI("urn:Frank"));
        expectedResults.add(bs);
        final Set<BindingSet> results = new HashSet<>();
        try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
            while (resultsIt.hasNext()) {
                results.add(resultsIt.next());
            }
        }
        assertEquals(expectedResults, results);
    } finally {
        if (sail != null) {
            sail.shutDown();
        }
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) SailConnection(org.openrdf.sail.SailConnection) Sail(org.openrdf.sail.Sail) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) 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