Search in sources :

Example 1 with MiniAccumuloCluster

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

the class Proxy method execute.

@Override
public void execute(final String[] args) throws Exception {
    Opts opts = new Opts();
    opts.parseArgs(Proxy.class.getName(), args);
    Properties props = new Properties();
    if (opts.prop != null) {
        props = opts.prop;
    } else {
        try (InputStream is = this.getClass().getClassLoader().getResourceAsStream("proxy.properties")) {
            if (is != null) {
                props.load(is);
            } else {
                System.err.println("proxy.properties needs to be specified as argument (using -p) or on the classpath (by putting the file in conf/)");
                System.exit(-1);
            }
        }
    }
    boolean useMini = Boolean.parseBoolean(props.getProperty(USE_MINI_ACCUMULO_KEY, USE_MINI_ACCUMULO_DEFAULT));
    boolean useMock = Boolean.parseBoolean(props.getProperty(USE_MOCK_INSTANCE_KEY, USE_MOCK_INSTANCE_DEFAULT));
    String instance = props.getProperty(ACCUMULO_INSTANCE_NAME_KEY);
    String zookeepers = props.getProperty(ZOOKEEPERS_KEY);
    if (!useMini && !useMock && instance == null) {
        System.err.println("Properties file must contain one of : useMiniAccumulo=true, useMockInstance=true, or instance=<instance name>");
        System.exit(1);
    }
    if (instance != null && zookeepers == null) {
        System.err.println("When instance is set in properties file, zookeepers must also be set.");
        System.exit(1);
    }
    if (!props.containsKey("port")) {
        System.err.println("No port property");
        System.exit(1);
    }
    if (useMini) {
        log.info("Creating mini cluster");
        final File folder = Files.createTempDirectory(System.currentTimeMillis() + "").toFile();
        final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(folder, "secret");
        accumulo.start();
        props.setProperty("instance", accumulo.getConfig().getInstanceName());
        props.setProperty("zookeepers", accumulo.getZooKeepers());
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void start() {
                try {
                    accumulo.stop();
                } catch (Exception e) {
                    throw new RuntimeException();
                } finally {
                    if (!folder.delete())
                        log.warn("Unexpected error removing {}", folder);
                }
            }
        });
    }
    Class<? extends TProtocolFactory> protoFactoryClass = Class.forName(props.getProperty("protocolFactory", TCompactProtocol.Factory.class.getName())).asSubclass(TProtocolFactory.class);
    TProtocolFactory protoFactory = protoFactoryClass.newInstance();
    int port = Integer.parseInt(props.getProperty("port"));
    String hostname = props.getProperty(THRIFT_SERVER_HOSTNAME, THRIFT_SERVER_HOSTNAME_DEFAULT);
    HostAndPort address = HostAndPort.fromParts(hostname, port);
    ServerAddress server = createProxyServer(address, protoFactory, props);
    // Wait for the server to come up
    while (!server.server.isServing()) {
        Thread.sleep(100);
    }
    log.info("Proxy server started on {}", server.getAddress());
    while (server.server.isServing()) {
        Thread.sleep(1000);
    }
}
Also used : TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) MetricsFactory(org.apache.accumulo.server.metrics.MetricsFactory) LoggerFactory(org.slf4j.LoggerFactory) TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) Properties(java.util.Properties) IOException(java.io.IOException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) AccumuloProxy(org.apache.accumulo.proxy.thrift.AccumuloProxy) File(java.io.File)

Example 2 with MiniAccumuloCluster

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

the class StartMojo method execute.

@Override
public void execute() throws MojoExecutionException {
    if (shouldSkip()) {
        return;
    }
    File subdir = new File(new File(outputDirectory, "accumulo-maven-plugin"), instanceName);
    try {
        subdir = subdir.getCanonicalFile();
        if (subdir.exists())
            FileUtils.forceDelete(subdir);
        if (!subdir.mkdirs() && !subdir.isDirectory())
            throw new IOException(subdir + " cannot be created as a directory");
        MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(subdir, rootPassword);
        cfg.setInstanceName(instanceName);
        cfg.setZooKeeperPort(zooKeeperPort);
        configureMiniClasspath(cfg, miniClasspath);
        MiniAccumuloClusterImpl mac = new MiniAccumuloClusterImpl(cfg);
        getLog().info("Starting MiniAccumuloCluster: " + mac.getInstanceName() + " in " + mac.getConfig().getDir());
        mac.start();
        runningClusters.add(mac);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to start " + MiniAccumuloCluster.class.getSimpleName(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) IOException(java.io.IOException) MiniAccumuloClusterImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl) File(java.io.File) MiniAccumuloConfigImpl(org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 3 with MiniAccumuloCluster

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

the class AccumuloIndexSetColumnVisibilityTest method startMiniAccumulo.

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());
    accCon = 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 4 with MiniAccumuloCluster

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

the class AccumuloRyaConnectionCommandsIT method connectToInstance.

@Test
public void connectToInstance() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();
    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean(PasswordPrompt.class);
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());
    // Connect to the mini accumulo instance.
    String cmd = RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " + "--username root " + "--instanceName " + cluster.getInstanceName() + " " + "--zookeepers " + cluster.getZooKeepers();
    CommandResult result = shell.executeCommand(cmd);
    // Install an instance of rya.
    final String instanceName = "testInstance";
    final InstallConfiguration installConf = InstallConfiguration.builder().build();
    final InstallPrompt installPrompt = context.getBean(InstallPrompt.class);
    when(installPrompt.promptInstanceName()).thenReturn("testInstance");
    when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn(installConf);
    when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);
    result = shell.executeCommand(RyaAdminCommands.INSTALL_CMD);
    assertTrue(result.isSuccess());
    // Connect to the instance that was just installed.
    cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
    result = shell.executeCommand(cmd);
    assertTrue(result.isSuccess());
    // Verify the shell state indicates it is connected to an instance.
    final SharedShellState sharedState = context.getBean(SharedShellState.class);
    final ShellState state = sharedState.getShellState();
    assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}
Also used : JLineShellComponent(org.springframework.shell.core.JLineShellComponent) ApplicationContext(org.springframework.context.ApplicationContext) ShellState(org.apache.rya.shell.SharedShellState.ShellState) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Bootstrap(org.springframework.shell.Bootstrap) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) PasswordPrompt(org.apache.rya.shell.util.PasswordPrompt) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.Test)

Example 5 with MiniAccumuloCluster

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

the class AccumuloRyaConnectionCommandsIT method disconnect.

@Test
public void disconnect() throws IOException {
    final MiniAccumuloCluster cluster = getCluster();
    final Bootstrap bootstrap = getTestBootstrap();
    final JLineShellComponent shell = getTestShell();
    // Mock the user entering the correct password.
    final ApplicationContext context = bootstrap.getApplicationContext();
    final PasswordPrompt mockPrompt = context.getBean(PasswordPrompt.class);
    when(mockPrompt.getPassword()).thenReturn("password".toCharArray());
    // Connect to the mini accumulo instance.
    final String cmd = RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " + "--username root " + "--instanceName " + cluster.getInstanceName() + " " + "--zookeepers " + cluster.getZooKeepers();
    shell.executeCommand(cmd);
    // Disconnect from it.
    final CommandResult disconnectResult = shell.executeCommand(RyaConnectionCommands.DISCONNECT_COMMAND_NAME_CMD);
    assertTrue(disconnectResult.isSuccess());
}
Also used : JLineShellComponent(org.springframework.shell.core.JLineShellComponent) ApplicationContext(org.springframework.context.ApplicationContext) MiniAccumuloCluster(org.apache.accumulo.minicluster.MiniAccumuloCluster) Bootstrap(org.springframework.shell.Bootstrap) PasswordPrompt(org.apache.rya.shell.util.PasswordPrompt) CommandResult(org.springframework.shell.core.CommandResult) Test(org.junit.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