Search in sources :

Example 91 with RyaClient

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

the class MongoLoadStatementsFileIT method loadTurtleFile.

@Test
public void loadTurtleFile() throws Exception {
    // Install an instance of Rya.
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(false).setEnableEntityCentricIndex(false).setEnableFreeTextIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(false).setEnableGeoIndex(false).build();
    final MongoConnectionDetails connectionDetails = getConnectionDetails();
    final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
    final Install install = ryaClient.getInstall();
    install.install(conf.getRyaInstanceName(), installConfig);
    // Load the test statement file.
    ryaClient.getLoadStatementsFile().loadStatements(conf.getRyaInstanceName(), Paths.get("src/test/resources/example.ttl"), RDFFormat.TURTLE);
    // Verify that the statements were loaded.
    final ValueFactory vf = new ValueFactoryImpl();
    final Set<Statement> expected = new HashSet<>();
    expected.add(vf.createStatement(vf.createURI("http://example#alice"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#bob")));
    expected.add(vf.createStatement(vf.createURI("http://example#bob"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#charlie")));
    expected.add(vf.createStatement(vf.createURI("http://example#charlie"), vf.createURI("http://example#likes"), vf.createURI("http://example#icecream")));
    final Set<Statement> statements = new HashSet<>();
    final MongoCursor<Document> triplesIterator = getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection(conf.getTriplesCollectionName()).find().iterator();
    while (triplesIterator.hasNext()) {
        final Document triple = triplesIterator.next();
        statements.add(vf.createStatement(vf.createURI(triple.getString("subject")), vf.createURI(triple.getString("predicate")), vf.createURI(triple.getString("object"))));
    }
    assertEquals(expected, statements);
}
Also used : Statement(org.openrdf.model.Statement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) Document(org.bson.Document) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Install(org.apache.rya.api.client.Install) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 92 with RyaClient

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

the class MongoSetRyaStreamsConfigurationIT method updatesRyaDetails.

@Test
public void updatesRyaDetails() throws Exception {
    final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
    // Install an instance of Rya.
    final String ryaInstance = conf.getRyaInstanceName();
    final Install installRya = ryaClient.getInstall();
    final InstallConfiguration installConf = InstallConfiguration.builder().build();
    installRya.install(ryaInstance, installConf);
    // Fetch its details and show they do not have any RyaStreamsDetails.
    com.google.common.base.Optional<RyaStreamsDetails> streamsDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance).get().getRyaStreamsDetails();
    assertFalse(streamsDetails.isPresent());
    // Set the details.
    final RyaStreamsDetails details = new RyaStreamsDetails("localhost", 6);
    ryaClient.getSetRyaStreamsConfiguration().setRyaStreamsConfiguration(ryaInstance, details);
    // Fetch its details again and show that they are now filled in.
    streamsDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance).get().getRyaStreamsDetails();
    assertEquals(details, streamsDetails.get());
}
Also used : RyaStreamsDetails(org.apache.rya.api.instance.RyaDetails.RyaStreamsDetails) RyaClient(org.apache.rya.api.client.RyaClient) Install(org.apache.rya.api.client.Install) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) Test(org.junit.Test)

Example 93 with RyaClient

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

the class AccumuloRyaClientFactory method build.

/**
 * Initialize a set of {@link RyaClient} that will interact with an instance of
 * Rya that is hosted by an Accumulo cluster.
 *
 * @param connectionDetails - Details about the values that were used to create the connector to the cluster. (not null)
 * @param connector - The Accumulo connector the commands will use. (not null)
 * @return The initialized commands.
 */
public static RyaClient build(final AccumuloConnectionDetails connectionDetails, final Connector connector) {
    requireNonNull(connectionDetails);
    requireNonNull(connector);
    // Build the RyaCommands option with the initialized commands.
    final InstanceExists instanceExists = new AccumuloInstanceExists(connectionDetails, connector);
    return new RyaClient(new AccumuloInstall(connectionDetails, connector), new AccumuloCreatePCJ(connectionDetails, connector), new AccumuloDeletePCJ(connectionDetails, connector), Optional.of(new AccumuloCreatePeriodicPCJ(connectionDetails, connector)), Optional.of(new AccumuloDeletePeriodicPCJ(connectionDetails, connector)), Optional.of(new AccumuloListIncrementalQueries(connectionDetails, connector)), new AccumuloBatchUpdatePCJ(connectionDetails, connector), new AccumuloGetInstanceDetails(connectionDetails, connector), instanceExists, new AccumuloListInstances(connectionDetails, connector), Optional.of(new AccumuloAddUser(connectionDetails, connector)), Optional.of(new AccumuloRemoveUser(connectionDetails, connector)), new AccumuloSetRyaStreamsConfiguration(instanceExists, connector), new AccumuloUninstall(connectionDetails, connector), new AccumuloLoadStatements(connectionDetails, connector), new AccumuloLoadStatementsFile(connectionDetails, connector), new AccumuloExecuteSparqlQuery(connectionDetails, connector));
}
Also used : RyaClient(org.apache.rya.api.client.RyaClient) InstanceExists(org.apache.rya.api.client.InstanceExists)

Example 94 with RyaClient

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

the class AccumuloAddUserIT method ryaDetailsIncludesOriginalUser.

/**
 * Ensure that the user who installs the instance of Rya is reported as being a user who can access it.
 */
@Test
public void ryaDetailsIncludesOriginalUser() throws Exception {
    // Create a Rya Client for that user.
    final RyaClient userAClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ADMIN_USER, ADMIN_USER.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(ADMIN_USER, ADMIN_USER));
    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
    // Ensure the Rya instance's details only contain the username of the user who installed the instance.
    final ImmutableList<String> expectedUsers = ImmutableList.<String>builder().add(ADMIN_USER).build();
    final RyaDetails details = userAClient.getGetInstanceDetails().getDetails(getRyaInstanceName()).get();
    assertEquals(expectedUsers, details.getUsers());
}
Also used : RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 95 with RyaClient

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

the class AccumuloAddUserIT method userAddedAlsoAddedToRyaDetails.

/**
 * Ensure that when a user is added to a Rya instance that its details are updated to include the new user.
 */
@Test
public void userAddedAlsoAddedToRyaDetails() throws Exception {
    final String user = testInstance.createUniqueUser();
    final SecurityOperations secOps = super.getConnector().securityOperations();
    final RyaClient userAClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ADMIN_USER, ADMIN_USER.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(ADMIN_USER, ADMIN_USER));
    // Create the user that will be added to the instance of Rya.
    secOps.createLocalUser(user, new PasswordToken(user));
    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
    // Add the user.
    userAClient.getAddUser().get().addUser(getRyaInstanceName(), user);
    // Ensure the Rya instance's details have been updated to include the added user.
    final ImmutableList<String> expectedUsers = ImmutableList.<String>builder().add(ADMIN_USER).add(user).build();
    final RyaDetails details = userAClient.getGetInstanceDetails().getDetails(getRyaInstanceName()).get();
    assertEquals(expectedUsers, details.getUsers());
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) 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