Search in sources :

Example 21 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project incubator-rya by apache.

the class PcjVisibilityIT method createWithVisibilityFluo.

@Test
public void createWithVisibilityFluo() throws Exception {
    final String sparql = "SELECT ?customer ?worker ?city " + "{ " + "?customer <http://talksTo> ?worker. " + "?worker <http://livesIn> ?city. " + "?worker <http://worksAt> <http://Chipotle>. " + "}";
    // Triples that will be streamed into Fluo after the PCJ has been created.
    final Map<RyaStatement, String> streamedTriples = new HashMap<>();
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://talksTo"), new RyaURI("http://Bob")), "A&B");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://livesIn"), new RyaURI("http://London")), "A");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), "B");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://talksTo"), new RyaURI("http://Charlie")), "B&C");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Charlie"), new RyaURI("http://livesIn"), new RyaURI("http://London")), "B");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Charlie"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), "C");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://talksTo"), new RyaURI("http://David")), "C&D");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://David"), new RyaURI("http://livesIn"), new RyaURI("http://London")), "C");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://David"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), "D");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://talksTo"), new RyaURI("http://Eve")), "D&E");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Eve"), new RyaURI("http://livesIn"), new RyaURI("http://Leeds")), "D");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Eve"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), "E");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://talksTo"), new RyaURI("http://Alice")), "");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://livesIn"), new RyaURI("http://London")), "");
    addStatementVisibilityEntry(streamedTriples, new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")), "");
    final Connector accumuloConn = super.getAccumuloConnector();
    // Create the PCJ Table in Accumulo.
    final PrecomputedJoinStorage rootStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName());
    final String pcjId = rootStorage.createPcj(sparql);
    try (final FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
        // Create the PCJ in Fluo.
        new CreateFluoPcj().withRyaIntegration(pcjId, rootStorage, fluoClient, accumuloConn, getRyaInstanceName());
        // Stream the data into Fluo.
        for (final RyaStatement statement : streamedTriples.keySet()) {
            final Optional<String> visibility = Optional.of(streamedTriples.get(statement));
            new InsertTriples().insert(fluoClient, statement, visibility);
        }
    }
    // Fetch the exported results from Accumulo once the observers finish working.
    super.getMiniFluo().waitForObservers();
    setupTestUsers(accumuloConn, getRyaInstanceName(), pcjId);
    // Verify ABCDE using root.
    final Set<BindingSet> rootResults = toSet(rootStorage.listResults(pcjId));
    final Set<BindingSet> rootExpected = Sets.newHashSet();
    MapBindingSet bs = new MapBindingSet();
    bs.addBinding("customer", VF.createURI("http://Alice"));
    bs.addBinding("worker", VF.createURI("http://Bob"));
    bs.addBinding("city", VF.createURI("http://London"));
    rootExpected.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("customer", VF.createURI("http://Alice"));
    bs.addBinding("worker", VF.createURI("http://Charlie"));
    bs.addBinding("city", VF.createURI("http://London"));
    rootExpected.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("customer", VF.createURI("http://Alice"));
    bs.addBinding("worker", VF.createURI("http://Eve"));
    bs.addBinding("city", VF.createURI("http://Leeds"));
    rootExpected.add(bs);
    bs = new MapBindingSet();
    bs.addBinding("customer", VF.createURI("http://Alice"));
    bs.addBinding("worker", VF.createURI("http://David"));
    bs.addBinding("city", VF.createURI("http://London"));
    rootExpected.add(bs);
    assertEquals(rootExpected, rootResults);
    final MiniAccumuloCluster cluster = super.getMiniAccumuloCluster();
    // Verify AB
    final Connector abConn = cluster.getConnector("abUser", "password");
    try (final PrecomputedJoinStorage abStorage = new AccumuloPcjStorage(abConn, getRyaInstanceName())) {
        final Set<BindingSet> abResults = toSet(abStorage.listResults(pcjId));
        final Set<BindingSet> abExpected = Sets.newHashSet();
        bs = new MapBindingSet();
        bs.addBinding("customer", VF.createURI("http://Alice"));
        bs.addBinding("worker", VF.createURI("http://Bob"));
        bs.addBinding("city", VF.createURI("http://London"));
        abExpected.add(bs);
        assertEquals(abExpected, abResults);
    }
    // Verify ABC
    final Connector abcConn = cluster.getConnector("abcUser", "password");
    try (final PrecomputedJoinStorage abcStorage = new AccumuloPcjStorage(abcConn, getRyaInstanceName())) {
        final Set<BindingSet> abcResults = toSet(abcStorage.listResults(pcjId));
        final Set<BindingSet> abcExpected = Sets.newHashSet();
        bs = new MapBindingSet();
        bs.addBinding("customer", VF.createURI("http://Alice"));
        bs.addBinding("worker", VF.createURI("http://Bob"));
        bs.addBinding("city", VF.createURI("http://London"));
        abcExpected.add(bs);
        bs = new MapBindingSet();
        bs.addBinding("customer", VF.createURI("http://Alice"));
        bs.addBinding("worker", VF.createURI("http://Charlie"));
        bs.addBinding("city", VF.createURI("http://London"));
        abcExpected.add(bs);
        assertEquals(abcExpected, abcResults);
    }
    // Verify ADE
    final Connector adeConn = cluster.getConnector("adeUser", "password");
    try (final PrecomputedJoinStorage adeStorage = new AccumuloPcjStorage(adeConn, getRyaInstanceName())) {
        final Set<BindingSet> adeResults = toSet(adeStorage.listResults(pcjId));
        final Set<BindingSet> adeExpected = Sets.newHashSet();
        bs = new MapBindingSet();
        bs.addBinding("customer", VF.createURI("http://Alice"));
        bs.addBinding("worker", VF.createURI("http://Eve"));
        bs.addBinding("city", VF.createURI("http://Leeds"));
        adeExpected.add(bs);
        assertEquals(adeExpected, adeResults);
    }
    // Verify no auths.
    final Connector noAuthConn = cluster.getConnector("noAuth", "password");
    try (final PrecomputedJoinStorage noAuthStorage = new AccumuloPcjStorage(noAuthConn, getRyaInstanceName())) {
        final Set<BindingSet> noAuthResults = toSet(noAuthStorage.listResults(pcjId));
        assertTrue(noAuthResults.isEmpty());
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) FluoClient(org.apache.fluo.api.client.FluoClient) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) HashMap(java.util.HashMap) InsertTriples(org.apache.rya.indexing.pcj.fluo.api.InsertTriples) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) RyaStatement(org.apache.rya.api.domain.RyaStatement) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj) RyaURI(org.apache.rya.api.domain.RyaURI) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Example 22 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project incubator-rya by apache.

the class KafkaExportITBase method teardownRya.

@After
public void teardownRya() {
    final MiniAccumuloCluster cluster = getMiniAccumuloCluster();
    final String instanceName = cluster.getInstanceName();
    final String zookeepers = cluster.getZooKeepers();
    // Uninstall the instance of Rya.
    final RyaClient ryaClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ACCUMULO_USER, ACCUMULO_PASSWORD.toCharArray(), instanceName, zookeepers), super.getAccumuloConnector());
    try {
        ryaClient.getUninstall().uninstall(RYA_INSTANCE_NAME);
        // Shutdown the repo.
        if (ryaSailRepo != null) {
            ryaSailRepo.shutDown();
        }
        if (dao != null) {
            dao.destroy();
        }
    } catch (final Exception e) {
        System.out.println("Encountered the following Exception when shutting down Rya: " + e.getMessage());
    }
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) RyaClient(org.apache.rya.api.client.RyaClient) After(org.junit.After)

Example 23 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project incubator-rya by apache.

the class RyaClientExample method main.

public static void main(final String[] args) throws Exception {
    final String accumuloUsername = "root";
    final String accumuloPassword = "password";
    MiniAccumuloCluster cluster = null;
    MiniFluo fluo = null;
    Sail ryaSail = null;
    try {
        // Setup a Mini Accumulo Cluster to host the Rya instance.
        log.info("Setting up the Mini Accumulo Cluster used by this example.");
        final File miniDataDir = Files.createTempDir();
        final MiniAccumuloConfig cfg = new MiniAccumuloConfig(miniDataDir, accumuloPassword);
        cluster = new MiniAccumuloCluster(cfg);
        cluster.start();
        // Setup a Mini Fluo application that will be used to incrementally update the PCJ indicies.
        log.info("Setting up the Mini Fluo application used by this example.");
        final String fluoAppName = "demoInstance_pcjUpdater";
        fluo = makeMiniFluo(accumuloUsername, accumuloPassword, cluster.getInstanceName(), cluster.getZooKeepers(), fluoAppName);
        // Give the root user the 'U' authorizations.
        final Connector connector = cluster.getConnector(accumuloUsername, accumuloPassword);
        connector.securityOperations().changeUserAuthorizations(accumuloUsername, new Authorizations("U"));
        // Setup a Rya Client that is able to interact with the mini cluster.
        final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(accumuloUsername, accumuloPassword.toCharArray(), cluster.getInstanceName(), cluster.getZooKeepers());
        final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, connector);
        // Install an instance of Rya that has all of the secondary indexers turned on.
        final String ryaInstanceName = "demoInstance_";
        final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableEntityCentricIndex(true).setEnableGeoIndex(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).setEnablePcjIndex(true).setFluoPcjAppName(fluoAppName).build();
        ryaClient.getInstall().install(ryaInstanceName, installConfig);
        // Add a PCJ index.
        final String sparql = "SELECT ?patron ?employee " + "WHERE { " + "?patron <http://talksTo> ?employee. " + "?employee <http://worksAt> <http://CoffeeShop>. " + "}";
        // Load some statements into the Rya instance.
        final AccumuloIndexingConfiguration conf = AccumuloIndexingConfiguration.builder().setAuths("U").setAccumuloUser(accumuloUsername).setAccumuloPassword(accumuloPassword).setAccumuloInstance(cluster.getInstanceName()).setAccumuloZooKeepers(cluster.getZooKeepers()).setRyaPrefix(ryaInstanceName).setPcjUpdaterFluoAppName(fluoAppName).build();
        ryaSail = RyaSailFactory.getInstance(conf);
        final ValueFactory vf = ryaSail.getValueFactory();
        final List<Statement> statements = Lists.newArrayList(vf.createStatement(vf.createURI("http://Eve"), vf.createURI("http://talksTo"), vf.createURI("http://Charlie")), vf.createStatement(vf.createURI("http://David"), vf.createURI("http://talksTo"), vf.createURI("http://Alice")), vf.createStatement(vf.createURI("http://Alice"), vf.createURI("http://worksAt"), vf.createURI("http://CoffeeShop")), vf.createStatement(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://CoffeeShop")), vf.createStatement(vf.createURI("http://George"), vf.createURI("http://talksTo"), vf.createURI("http://Frank")), vf.createStatement(vf.createURI("http://Frank"), vf.createURI("http://worksAt"), vf.createURI("http://CoffeeShop")), vf.createStatement(vf.createURI("http://Eve"), vf.createURI("http://talksTo"), vf.createURI("http://Bob")), vf.createStatement(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://CoffeeShop")));
        SailConnection ryaConn = ryaSail.getConnection();
        log.info("");
        log.info("Loading the following statements:");
        ryaConn.begin();
        for (final Statement statement : statements) {
            log.info("    " + statement.toString());
            ryaConn.addStatement(statement.getSubject(), statement.getPredicate(), statement.getObject());
        }
        log.info("");
        ryaConn.close();
        fluo.waitForObservers();
        // Execute the SPARQL query and print the results.
        log.info("Executing the following query: ");
        prettyLogSparql(sparql);
        log.info("");
        final ParsedQuery parsedQuery = new SPARQLParser().parseQuery(sparql, null);
        ryaConn = ryaSail.getConnection();
        final CloseableIteration<? extends BindingSet, QueryEvaluationException> result = ryaConn.evaluate(parsedQuery.getTupleExpr(), null, null, false);
        log.info("Results:");
        while (result.hasNext()) {
            log.info("    " + result.next());
        }
        log.info("");
    } finally {
        if (ryaSail != null) {
            log.info("Shutting down the Rya Sail instance.");
            ryaSail.shutDown();
        }
        if (fluo != null) {
            try {
                log.info("Shutting down the Mini Fluo instance.");
                fluo.close();
            } catch (final Exception e) {
                log.error("Could not shut down the Mini Fluo instance.", e);
            }
        }
        if (cluster != null) {
            log.info("Sutting down the Mini Accumulo Cluster.");
            cluster.stop();
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Authorizations(org.apache.accumulo.core.security.Authorizations) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Statement(org.openrdf.model.Statement) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) AccumuloIndexingConfiguration(org.apache.rya.indexing.accumulo.AccumuloIndexingConfiguration) AlreadyInitializedException(org.apache.fluo.api.client.FluoAdmin.AlreadyInitializedException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) TableExistsException(org.apache.fluo.api.client.FluoAdmin.TableExistsException) MiniFluo(org.apache.fluo.api.mini.MiniFluo) SailConnection(org.openrdf.sail.SailConnection) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) Sail(org.openrdf.sail.Sail) File(java.io.File)

Example 24 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project incubator-rya by apache.

the class AccumuloInstanceDriver method setUpInstance.

/**
 * Sets up the {@link MiniAccumuloCluster} or the {@link MockInstance}.
 * @throws Exception
 */
public void setUpInstance() throws Exception {
    if (!isMock) {
        log.info("Setting up " + driverName + " MiniAccumulo cluster...");
        // Create and Run MiniAccumulo Cluster
        tempDir = Files.createTempDir();
        tempDir.deleteOnExit();
        miniAccumuloCluster = new MiniAccumuloCluster(tempDir, userpwd);
        copyHadoopHomeToTemp();
        miniAccumuloCluster.getConfig().setInstanceName(instanceName);
        log.info(driverName + " MiniAccumulo instance starting up...");
        miniAccumuloCluster.start();
        Thread.sleep(1000);
        log.info(driverName + " MiniAccumulo instance started");
        log.info("Creating connector to " + driverName + " MiniAccumulo instance...");
        zooKeeperInstance = new ZooKeeperInstance(miniAccumuloCluster.getClientConfig());
        instance = zooKeeperInstance;
        connector = zooKeeperInstance.getConnector(user, new PasswordToken(userpwd));
        log.info("Created connector to " + driverName + " MiniAccumulo instance");
    } else {
        log.info("Setting up " + driverName + " mock instance...");
        mockInstance = new MockInstance(instanceName);
        instance = mockInstance;
        connector = mockInstance.getConnector(user, new PasswordToken(userpwd));
        log.info("Created connector to " + driverName + " mock instance");
    }
    zooKeepers = instance.getZooKeepers();
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 25 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project incubator-rya by apache.

the class MiniAccumuloClusterInstance method startMiniAccumulo.

/**
 * Start the {@link MiniAccumuloCluster}.
 */
public void startMiniAccumulo() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException {
    final File miniDataDir = Files.createTempDir();
    // Setup and start the Mini Accumulo.
    final MiniAccumuloConfig cfg = new MiniAccumuloConfig(miniDataDir, PASSWORD);
    cluster = new MiniAccumuloCluster(cfg);
    cluster.start();
}
Also used : MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig) File(java.io.File)

Aggregations

MiniAccumuloCluster (org.apache.accumulo.minicluster.MiniAccumuloCluster)37 File (java.io.File)11 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)8 MiniAccumuloConfig (org.apache.accumulo.minicluster.MiniAccumuloConfig)8 Test (org.junit.Test)7 IOException (java.io.IOException)6 Connector (org.apache.accumulo.core.client.Connector)6 PasswordPrompt (org.apache.rya.shell.util.PasswordPrompt)6 RFileReaderRDD (uk.gov.gchq.gaffer.sparkaccumulo.operation.rfilereaderrdd.RFileReaderRDD)6 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)5 Test (org.junit.jupiter.api.Test)5 ApplicationContext (org.springframework.context.ApplicationContext)5 Bootstrap (org.springframework.shell.Bootstrap)5 CommandResult (org.springframework.shell.core.CommandResult)5 JLineShellComponent (org.springframework.shell.core.JLineShellComponent)5 Properties (java.util.Properties)4 BeforeClass (org.junit.BeforeClass)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 Instance (org.apache.accumulo.core.client.Instance)3 RyaClient (org.apache.rya.api.client.RyaClient)3