Search in sources :

Example 36 with RyaClient

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

the class MongoListInstancesIT method listInstances_hasRyaDetailsTable.

@Test
public void listInstances_hasRyaDetailsTable() throws MongoException, DuplicateInstanceNameException, RyaClientException {
    // Install a few instances of Rya using the install command.
    final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
    final Install install = ryaClient.getInstall();
    install.install("instance1_", InstallConfiguration.builder().build());
    install.install("instance2_", InstallConfiguration.builder().build());
    install.install("instance3_", InstallConfiguration.builder().build());
    // Fetch the list and verify it matches what is expected.
    final ListInstances listInstances = new MongoListInstances(getMongoClient());
    final List<String> instances = listInstances.listInstances();
    Collections.sort(instances);
    final List<String> expected = Lists.newArrayList("instance1_", "instance2_", "instance3_");
    assertEquals(expected, instances);
}
Also used : ListInstances(org.apache.rya.api.client.ListInstances) RyaClient(org.apache.rya.api.client.RyaClient) Install(org.apache.rya.api.client.Install) Test(org.junit.Test)

Example 37 with RyaClient

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

the class MongoLoadStatementsIT method loadStatements.

/**
 * Pass a list of statements to our loadStatement class.
 */
@Test
public void loadStatements() throws Exception {
    // Install an instance of Rya.
    final MongoConnectionDetails connectionDetails = getConnectionDetails();
    final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(false).setEnableEntityCentricIndex(false).setEnableFreeTextIndex(false).setEnableTemporalIndex(false).setEnablePcjIndex(false).setEnableGeoIndex(false).build();
    ryaClient.getInstall().install(conf.getRyaInstanceName(), installConfig);
    // Create the statements that will be loaded.
    final Set<Statement> statements = makeTestStatements();
    // Load them.
    ryaClient.getLoadStatements().loadStatements(conf.getRyaInstanceName(), statements);
    // Fetch the statements that have been stored in Mongo DB.
    final Set<Statement> stmtResults = new HashSet<>();
    final MongoCursor<Document> triplesIterator = getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection(conf.getTriplesCollectionName()).find().iterator();
    while (triplesIterator.hasNext()) {
        final Document triple = triplesIterator.next();
        stmtResults.add(VF.createStatement(VF.createURI(triple.getString("subject")), VF.createURI(triple.getString("predicate")), VF.createURI(triple.getString("object"))));
    }
    // Show the discovered statements match the original statements.
    assertEquals(statements, stmtResults);
}
Also used : Statement(org.openrdf.model.Statement) RyaClient(org.apache.rya.api.client.RyaClient) Document(org.bson.Document) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with RyaClient

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

the class MongoUninstallIT method uninstall_instanceDoesNotExists.

@Test(expected = InstanceDoesNotExistException.class)
public void uninstall_instanceDoesNotExists() throws MongoException, RyaClientException {
    // Install an instance of Rya.
    final String instanceName = "testInstance_";
    // Uninstall the instance
    final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), getMongoClient());
    final Uninstall uninstall = ryaClient.getUninstall();
    uninstall.uninstall(instanceName);
}
Also used : Uninstall(org.apache.rya.api.client.Uninstall) RyaClient(org.apache.rya.api.client.RyaClient) Test(org.junit.Test)

Example 39 with RyaClient

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

the class AccumuloAddUserIT method userAddedCanInsert.

/**
 * Ensure a user that has been added to the Rya instance can interact with it.
 */
@Test
public void userAddedCanInsert() 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 not be added to the instance of Rya, but will try to scan it.
    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);
    // Try to add a statement to the Rya instance. This should succeed.
    Sail sail = null;
    SailConnection sailConn = null;
    try {
        final AccumuloRdfConfiguration userDConf = makeRyaConfig(getRyaInstanceName(), user, user, getInstanceName(), getZookeepers());
        sail = RyaSailFactory.getInstance(userDConf);
        sailConn = sail.getConnection();
        final ValueFactory vf = sail.getValueFactory();
        sailConn.begin();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));
        sailConn.close();
    } finally {
        if (sailConn != null) {
            sailConn.close();
        }
        if (sail != null) {
            sail.shutDown();
        }
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) SailConnection(org.openrdf.sail.SailConnection) Sail(org.openrdf.sail.Sail) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Test(org.junit.Test)

Example 40 with RyaClient

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

the class AccumuloAddUserIT method userNotAddedCanNotInsert.

/**
 * Ensure a user that has not been added to the Rya instance can not interact with it.
 */
@Test
public void userNotAddedCanNotInsert() 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));
    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
    // Create the user that will not be added to the instance of Rya, but will try to scan it.
    secOps.createLocalUser(user, new PasswordToken(user));
    // Try to add a statement the Rya instance with the unauthorized user. This should fail.
    boolean securityExceptionThrown = false;
    Sail sail = null;
    SailConnection sailConn = null;
    try {
        final AccumuloRdfConfiguration userCConf = makeRyaConfig(getRyaInstanceName(), user, user, getInstanceName(), getZookeepers());
        sail = RyaSailFactory.getInstance(userCConf);
        sailConn = sail.getConnection();
        final ValueFactory vf = sail.getValueFactory();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));
    } catch (final RuntimeException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof AccumuloSecurityException) {
            securityExceptionThrown = true;
        }
    } finally {
        if (sailConn != null) {
            sailConn.close();
        }
        if (sail != null) {
            sail.shutDown();
        }
    }
    assertTrue(securityExceptionThrown);
}
Also used : SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) SailConnection(org.openrdf.sail.SailConnection) Sail(org.openrdf.sail.Sail) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) 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