Search in sources :

Example 31 with MiniAccumuloCluster

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

the class RFileReaderRddIT method testRFileReaderRDDCanBeCreatedWith5TableInputs.

@Test
public void testRFileReaderRDDCanBeCreatedWith5TableInputs() throws IOException, InterruptedException, AccumuloSecurityException, AccumuloException, TableNotFoundException, TableExistsException {
    // Given
    final List<String> dataInput = Arrays.asList("train", "plane", "automobile", "bike", "boat");
    final MiniAccumuloCluster cluster = createAccumuloCluster(tableName, config, dataInput);
    // When
    final RFileReaderRDD rdd = new RFileReaderRDD(sparkSession.sparkContext(), cluster.getInstanceName(), cluster.getZooKeepers(), MiniAccumuloClusterProvider.USER, MiniAccumuloClusterProvider.PASSWORD, tableName, new HashSet<>(), serialiseConfiguration(config));
    // Then
    assertThat(rdd.count()).isEqualTo(dataInput.size());
    assertThat(rdd.getPartitions()).hasSize(1);
}
Also used : RFileReaderRDD(uk.gov.gchq.gaffer.sparkaccumulo.operation.rfilereaderrdd.RFileReaderRDD) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Test(org.junit.jupiter.api.Test)

Example 32 with MiniAccumuloCluster

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

the class MiniAccumuloClusterProvider method createCluster.

private static void createCluster() throws IOException, InterruptedException, AccumuloSecurityException, AccumuloException {
    if (tempFolder.exists()) {
        FileUtils.cleanDirectory(tempFolder);
    }
    final MiniAccumuloConfig miniAccumuloConfig = new MiniAccumuloConfig(tempFolder, PASSWORD);
    cluster = new MiniAccumuloCluster(miniAccumuloConfig);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            try {
                cluster.stop();
                tempFolder.delete();
            } catch (final IOException | InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    });
    cluster.start();
    // Create user USER with permissions to create a table
    cluster.getConnector(ROOT, PASSWORD).securityOperations().createLocalUser(USER, new PasswordToken(PASSWORD));
    cluster.getConnector(ROOT, PASSWORD).securityOperations().createLocalUser(USER_NO_GRANTED_PERMISSION, new PasswordToken(PASSWORD));
    cluster.getConnector(ROOT, PASSWORD).securityOperations().grantSystemPermission(USER, SystemPermission.CREATE_TABLE);
    // Create properties
    accumuloProperties = new AccumuloProperties();
    accumuloProperties.setStoreClass(AccumuloStore.class);
    accumuloProperties.setInstance(cluster.getInstanceName());
    accumuloProperties.setZookeepers(cluster.getZooKeepers());
    accumuloProperties.setUser(MiniAccumuloClusterProvider.USER);
    accumuloProperties.setPassword(MiniAccumuloClusterProvider.PASSWORD);
    accumuloProperties.setOperationDeclarationPaths("sparkAccumuloOperationsDeclarations.json");
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig)

Example 33 with MiniAccumuloCluster

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

the class MiniAccumuloStore method createCluster.

private void createCluster() throws IOException, InterruptedException {
    String providedDirectory = getProperties().get(ACCUMULO_DIRECTORY_PROPERTY);
    if (providedDirectory == null) {
        ACCUMULO_DIRECTORIES.put(getProperties().getInstance(), Files.createTempDir());
    } else {
        ACCUMULO_DIRECTORIES.put(getProperties().getInstance(), new File(providedDirectory));
    }
    String rootUserPassword = getProperties().get(ROOT_PASSWORD_PROPERTY, ROOT_PASSWORD_DEFAULT);
    MiniAccumuloConfig config = new MiniAccumuloConfig(getAccumuloDirectory(), rootUserPassword);
    String[] zookeepers = getProperties().getZookeepers().split(":");
    if (zookeepers.length == 2) {
        config.setZooKeeperPort(Integer.parseInt(zookeepers[1]));
    } else {
        config.setZooKeeperPort(DEFAULT_ZOOKEEPER_PORT);
    }
    config.setInstanceName(getProperties().getInstance());
    CLUSTER_INSTANCES.put(getProperties().getInstance(), new MiniAccumuloCluster(config));
    getCluster().start();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        try {
            if (this.getCluster() != null) {
                this.getCluster().stop();
            }
        } catch (final InterruptedException | IOException e) {
            LOGGER.error("Failed to stop Accumulo", e);
        }
        getAccumuloDirectory().delete();
    }));
}
Also used : MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig) File(java.io.File)

Example 34 with MiniAccumuloCluster

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

the class AccumuloResource method start.

public void start() throws IOException, InterruptedException {
    if (accumulo != null) {
        return;
    }
    LOGGER.info("Starting accumulo");
    tempDir = File.createTempFile("accumulo-temp", Long.toString(System.nanoTime()));
    tempDir.delete();
    tempDir.mkdir();
    LOGGER.info("writing to: %s", tempDir);
    MiniAccumuloConfig miniAccumuloConfig = new MiniAccumuloConfig(tempDir, ACCUMULO_PASSWORD);
    miniAccumuloConfig.setZooKeeperStartupTime(60000);
    accumulo = new MiniAccumuloCluster(miniAccumuloConfig);
    accumulo.start();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            try {
                AccumuloResource.this.stop();
            } catch (Exception e) {
                System.out.println("Failed to stop Accumulo test cluster");
            }
        }
    });
}
Also used : MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig) VertexiumException(org.vertexium.VertexiumException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 35 with MiniAccumuloCluster

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

the class GoraAccumuloTestDriver method setUpClass.

@Override
public void setUpClass() throws IOException, InterruptedException {
    log.info("Starting Accumulo MiniAccumuloCluster...");
    try {
        tmpDir.create();
        MiniAccumuloConfig miniCfg = new MiniAccumuloConfig(tmpDir.getRoot(), PASSWORD);
        miniCfg.setInstanceName("goraTest");
        miniCfg.setZooKeeperPort(56321);
        cluster = new MiniAccumuloCluster(miniCfg);
        cluster.start();
    } catch (Exception e) {
        LOG.error("Error starting Accumulo MiniAccumuloCluster: {}", e.getMessage());
        // cleanup
        tearDownClass();
    }
}
Also used : MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) MiniAccumuloConfig(org.apache.accumulo.minicluster.MiniAccumuloConfig) IOException(java.io.IOException)

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