Search in sources :

Example 26 with MiniAccumuloCluster

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

the class ZooLockTest method setupMiniCluster.

@BeforeClass
public static void setupMiniCluster() throws Exception {
    folder.create();
    accumulo = new MiniAccumuloCluster(folder.getRoot(), "superSecret");
    accumulo.start();
}
Also used : MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) BeforeClass(org.junit.BeforeClass)

Example 27 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project presto by prestodb.

the class AccumuloQueryRunner method getAccumuloConnector.

/**
 * Gets the AccumuloConnector singleton, starting the MiniAccumuloCluster on initialization.
 * This singleton instance is required so all test cases access the same MiniAccumuloCluster.
 *
 * @return Accumulo connector
 */
public static Connector getAccumuloConnector() {
    if (connector != null) {
        return connector;
    }
    try {
        MiniAccumuloCluster accumulo = createMiniAccumuloCluster();
        Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
        connector = instance.getConnector(MAC_USER, new PasswordToken(MAC_PASSWORD));
        LOG.info("Connection to MAC instance %s at %s established, user %s password %s", accumulo.getInstanceName(), accumulo.getZooKeepers(), MAC_USER, MAC_PASSWORD);
        return connector;
    } catch (AccumuloException | AccumuloSecurityException | InterruptedException | IOException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to get connector to Accumulo", e);
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) 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) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance)

Example 28 with MiniAccumuloCluster

use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project presto by prestodb.

the class AccumuloQueryRunner method createMiniAccumuloCluster.

/**
 * Creates and starts an instance of MiniAccumuloCluster, returning the new instance.
 *
 * @return New MiniAccumuloCluster
 */
private static MiniAccumuloCluster createMiniAccumuloCluster() throws IOException, InterruptedException {
    // Create MAC directory
    File macDir = Files.createTempDirectory("mac-").toFile();
    LOG.info("MAC is enabled, starting MiniAccumuloCluster at %s", macDir);
    // Start MAC and connect to it
    MiniAccumuloCluster accumulo = new MiniAccumuloCluster(macDir, MAC_PASSWORD);
    accumulo.getConfig().setDefaultMemory(512, MEGABYTE);
    setConfigClassPath(accumulo.getConfig());
    accumulo.start();
    // Add shutdown hook to stop MAC and cleanup temporary files
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        try {
            LOG.info("Shutting down MAC");
            accumulo.stop();
        } catch (IOException | InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new PrestoException(MINI_ACCUMULO, "Failed to shut down MAC instance", e);
        }
        try {
            LOG.info("Cleaning up MAC directory");
            FileUtils.forceDelete(macDir);
        } catch (IOException e) {
            throw new PrestoException(MINI_ACCUMULO, "Failed to clean up MAC directory", e);
        }
    }));
    return accumulo;
}
Also used : MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) File(java.io.File)

Example 29 with MiniAccumuloCluster

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

the class RFileReaderRddIT method throwRTX_whenGetPartitionsForFileReaderWithInvalidTableName.

public void throwRTX_whenGetPartitionsForFileReaderWithInvalidTableName() 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, MiniAccumuloClusterProvider.PASSWORD, "Invalid Table Name", new HashSet<>(), serialiseConfiguration(config));
    // When / Then
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(rdd::getPartitions).withMessage("User user does not have access to table Invalid Table Name");
}
Also used : RFileReaderRDD(uk.gov.gchq.gaffer.sparkaccumulo.operation.rfilereaderrdd.RFileReaderRDD) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster)

Example 30 with MiniAccumuloCluster

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

the class RFileReaderRddIT method throwRTX_whenRDDHasIncorrectUser.

@Test
public void throwRTX_whenRDDHasIncorrectUser() 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(), "Incorrect Username", "", tableName, new HashSet<>(), serialiseConfiguration(config));
    // When / Then
    assertThatExceptionOfType(RuntimeException.class).isThrownBy(rdd::getPartitions).withMessage("Exception connecting to Accumulo");
}
Also used : RFileReaderRDD(uk.gov.gchq.gaffer.sparkaccumulo.operation.rfilereaderrdd.RFileReaderRDD) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) 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