Search in sources :

Example 11 with MiniAccumuloCluster

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

the class DemoDriver method startMiniAccumulo.

/**
 * Setup a Mini Accumulo cluster that uses a temporary directory to store its data.
 *
 * @return A Mini Accumulo cluster.
 */
private static MiniAccumuloCluster startMiniAccumulo() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException {
    final File miniDataDir = Files.createTempDir();
    // Setup and start the Mini Accumulo.
    final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(miniDataDir, "password");
    accumulo.start();
    // Store a connector to the Mini Accumulo.
    final Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
    accumuloConn = instance.getConnector("root", new PasswordToken("password"));
    return accumulo;
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) File(java.io.File) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 12 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} or
 * distribution instance
 * @throws Exception
 */
public void setUpInstance() throws Exception {
    switch(instanceType) {
        case DISTRIBUTION:
            log.info("Setting up " + driverName + " distribution instance...");
            if (instanceName == null) {
                throw new IllegalArgumentException("Must specify instance name for distributed mode");
            } else if (zooKeepers == null) {
                throw new IllegalArgumentException("Must specify ZooKeeper hosts for distributed mode");
            }
            instance = new ZooKeeperInstance(instanceName, zooKeepers);
            connector = instance.getConnector(user, new PasswordToken(userpwd));
            log.info("Created connector to " + driverName + " distribution instance");
            break;
        case MINI:
            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");
            break;
        case MOCK:
            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");
            break;
        default:
            throw new AccumuloException("Unexpected instance type: " + instanceType);
    }
    zooKeepers = instance.getZooKeepers();
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) 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 13 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project hive by apache.

the class AccumuloTestSetup method setupWithHiveConf.

private void setupWithHiveConf(HiveConf conf) throws Exception {
    if (null == miniCluster) {
        String testTmpDir = System.getProperty("test.tmp.dir");
        File tmpDir = new File(testTmpDir, "accumulo");
        if (tmpDir.exists()) {
            FileUtils.deleteDirectory(tmpDir);
        }
        MiniAccumuloConfig cfg = new MiniAccumuloConfig(tmpDir, PASSWORD);
        cfg.setNumTservers(1);
        miniCluster = new MiniAccumuloCluster(cfg);
        appendZooKeeperConf(EXTRA_ZOOKEEPER_CONFIG, tmpDir);
        miniCluster.start();
        createAccumuloTable(miniCluster.getConnector("root", PASSWORD));
    }
    updateConf(conf);
}
Also used : MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig) File(java.io.File)

Example 14 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project Gaffer by gchq.

the class RFileReaderRddIT method throwRTX_whenRDDHasUserWithoutPermission.

@Test
public void throwRTX_whenRDDHasUserWithoutPermission() throws IOException, InterruptedException, AccumuloSecurityException, AccumuloException, TableNotFoundException, TableExistsException {
    // Given
    final MiniAccumuloCluster cluster = createAccumuloCluster(tableName, config, Arrays.asList("Bananas"));
    final RFileReaderRDD rdd = new RFileReaderRDD(sparkSession.sparkContext(), cluster.getInstanceName(), cluster.getZooKeepers(), MiniAccumuloClusterProvider.USER_NO_GRANTED_PERMISSION, MiniAccumuloClusterProvider.PASSWORD, tableName, new HashSet<>(), serialiseConfiguration(config));
    // When / Then
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(rdd::getPartitions).withMessage("User user2 does not have access to table " + tableName);
}
Also used : RFileReaderRDD(uk.gov.gchq.gaffer.sparkaccumulo.operation.rfilereaderrdd.RFileReaderRDD) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Test(org.junit.jupiter.api.Test)

Example 15 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project Gaffer by gchq.

the class RFileReaderRddIT method testRFileReaderRDDAppliesIteratorCorrectly.

@Test
public void testRFileReaderRDDAppliesIteratorCorrectly() throws IOException, InterruptedException, AccumuloSecurityException, AccumuloException, TableNotFoundException, TableExistsException {
    // Given
    final List<String> data = Arrays.asList("no", "not", "value");
    final Job job = Job.getInstance(config);
    final MiniAccumuloCluster cluster = createAccumuloCluster(tableName, job.getConfiguration(), data);
    // Create an iterator and an option to grep for "val"
    final Map<String, String> options = new HashMap<>();
    options.put("term", "val");
    AccumuloInputFormat.addIterator(job, new IteratorSetting(2, "NAME", GrepIterator.class.getName(), options));
    // When
    final RFileReaderRDD rdd = new RFileReaderRDD(sparkSession.sparkContext(), cluster.getInstanceName(), cluster.getZooKeepers(), MiniAccumuloClusterProvider.USER, MiniAccumuloClusterProvider.PASSWORD, tableName, new HashSet<>(), serialiseConfiguration(job.getConfiguration()));
    // Then
    assertThat(rdd.count()).isEqualTo(1L);
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) HashMap(java.util.HashMap) RFileReaderRDD(uk.gov.gchq.gaffer.sparkaccumulo.operation.rfilereaderrdd.RFileReaderRDD) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Job(org.apache.hadoop.mapreduce.Job) Test(org.junit.jupiter.api.Test)

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