Search in sources :

Example 46 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project incubator-rya by apache.

the class CopyTool method setupAccumuloInput.

@Override
protected void setupAccumuloInput(final Job job) throws AccumuloSecurityException {
    if (useCopyFileImport) {
        try {
            FileInputFormat.setInputPaths(job, localCopyFileImportDir);
        } catch (final IOException e) {
            log.error("Failed to set copy file import directory", e);
        }
    } else {
        // set up accumulo input
        if (!hdfsInput) {
            job.setInputFormatClass(AccumuloInputFormat.class);
        } else {
            job.setInputFormatClass(AccumuloHDFSFileInputFormat.class);
        }
        AbstractInputFormat.setConnectorInfo(job, userName, new PasswordToken(pwd));
        InputFormatBase.setInputTableName(job, RdfCloudTripleStoreUtils.layoutPrefixToTable(rdfTableLayout, tablePrefix));
        AbstractInputFormat.setScanAuthorizations(job, authorizations);
        if (!mock) {
            AbstractInputFormat.setZooKeeperInstance(job, new ClientConfiguration().withInstance(instance).withZkHosts(zk));
        } else {
            AbstractInputFormat.setMockInstance(job, instance);
        }
        if (ttl != null) {
            final IteratorSetting setting = new IteratorSetting(1, "fi", AgeOffFilter.class);
            AgeOffFilter.setTTL(setting, Long.valueOf(ttl));
            InputFormatBase.addIterator(job, setting);
        }
        if (startTime != null) {
            final IteratorSetting setting = getStartTimeSetting(startTime);
            InputFormatBase.addIterator(job, setting);
        }
        for (final IteratorSetting iteratorSetting : AccumuloRyaUtils.COMMON_REG_EX_FILTER_SETTINGS) {
            InputFormatBase.addIterator(job, iteratorSetting);
        }
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) IOException(java.io.IOException) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration)

Example 47 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class Shell method config.

/**
 * Configures the shell using the provided options. Not for client use.
 *
 * @return true if the shell was successfully configured, false otherwise.
 * @throws IOException
 *           if problems occur creating the ConsoleReader
 */
public boolean config(String... args) throws IOException {
    if (this.reader == null)
        this.reader = new ConsoleReader();
    ShellOptionsJC options = new ShellOptionsJC();
    JCommander jc = new JCommander();
    jc.setProgramName("accumulo shell");
    jc.addObject(options);
    try {
        jc.parse(args);
    } catch (ParameterException e) {
        jc.usage();
        exitCode = 1;
        return false;
    }
    if (options.isHelpEnabled()) {
        jc.usage();
        // Not an error
        exitCode = 0;
        return false;
    }
    if (options.getUnrecognizedOptions() != null) {
        logError("Unrecognized Options: " + options.getUnrecognizedOptions().toString());
        jc.usage();
        exitCode = 1;
        return false;
    }
    setDebugging(options.isDebugEnabled());
    authTimeout = TimeUnit.MINUTES.toNanos(options.getAuthTimeout());
    disableAuthTimeout = options.isAuthTimeoutDisabled();
    ClientConfiguration clientConf;
    try {
        clientConf = options.getClientConfiguration();
    } catch (Exception e) {
        printException(e);
        return true;
    }
    if (Boolean.parseBoolean(clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED))) {
        log.debug("SASL is enabled, disabling authorization timeout");
        disableAuthTimeout = true;
    }
    // get the options that were parsed
    final String user;
    try {
        user = options.getUsername();
    } catch (Exception e) {
        printException(e);
        return true;
    }
    String password = options.getPassword();
    tabCompletion = !options.isTabCompletionDisabled();
    // Use a ZK, or HdfsZK Accumulo instance
    setInstance(options);
    // AuthenticationToken options
    try {
        token = options.getAuthenticationToken();
    } catch (Exception e) {
        printException(e);
        return true;
    }
    Map<String, String> loginOptions = options.getTokenProperties();
    // process default parameters if unspecified
    try {
        final boolean hasToken = (token != null);
        if (hasToken && password != null) {
            throw new ParameterException("Can not supply '--pass' option with '--tokenClass' option");
        }
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                reader.getTerminal().setEchoEnabled(true);
            }
        });
        if (hasToken) {
            // implied hasTokenOptions
            // Fully qualified name so we don't shadow java.util.Properties
            org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties props;
            // and line wrap it because the package name is so long
            props = new org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties();
            if (!loginOptions.isEmpty()) {
                props.putAllStrings(loginOptions);
            }
            token.init(props);
        } else {
            // Read password if the user explicitly asked for it, or didn't specify anything at all
            if ("stdin".equals(password) || password == null) {
                password = reader.readLine("Password: ", '*');
            }
            if (password == null) {
                // User cancel, e.g. Ctrl-D pressed
                throw new ParameterException("No password or token option supplied");
            } else {
                this.token = new PasswordToken(password);
            }
        }
        if (!options.isFake()) {
            DistributedTrace.enable(InetAddress.getLocalHost().getHostName(), "shell", clientConf);
        }
        this.setTableName("");
        connector = instance.getConnector(user, token);
    } catch (Exception e) {
        printException(e);
        exitCode = 1;
        return false;
    }
    // decide whether to execute commands from a file and quit
    if (options.getExecFile() != null) {
        execFile = options.getExecFile();
        verbose = false;
    } else if (options.getExecFileVerbose() != null) {
        execFile = options.getExecFileVerbose();
        verbose = true;
    }
    execCommand = options.getExecCommand();
    if (execCommand != null) {
        verbose = false;
    }
    rootToken = new Token();
    Command[] dataCommands = { new DeleteCommand(), new DeleteManyCommand(), new DeleteRowsCommand(), new EGrepCommand(), new FormatterCommand(), new InterpreterCommand(), new GrepCommand(), new ImportDirectoryCommand(), new InsertCommand(), new MaxRowCommand(), new ScanCommand() };
    Command[] debuggingCommands = { new ClasspathCommand(), new DebugCommand(), new ListScansCommand(), new ListCompactionsCommand(), new TraceCommand(), new PingCommand(), new ListBulkCommand() };
    Command[] execCommands = { new ExecfileCommand(), new HistoryCommand(), new ExtensionCommand(), new ScriptCommand() };
    Command[] exitCommands = { new ByeCommand(), new ExitCommand(), new QuitCommand() };
    Command[] helpCommands = { new AboutCommand(), new HelpCommand(), new InfoCommand(), new QuestionCommand() };
    Command[] iteratorCommands = { new DeleteIterCommand(), new DeleteScanIterCommand(), new ListIterCommand(), new SetIterCommand(), new SetScanIterCommand(), new SetShellIterCommand(), new ListShellIterCommand(), new DeleteShellIterCommand() };
    Command[] otherCommands = { new HiddenCommand() };
    Command[] permissionsCommands = { new GrantCommand(), new RevokeCommand(), new SystemPermissionsCommand(), new TablePermissionsCommand(), new UserPermissionsCommand(), new NamespacePermissionsCommand() };
    Command[] stateCommands = { new AuthenticateCommand(), new ClsCommand(), new ClearCommand(), new FateCommand(), new NoTableCommand(), new SleepCommand(), new TableCommand(), new UserCommand(), new WhoAmICommand() };
    Command[] tableCommands = { new CloneTableCommand(), new ConfigCommand(), new CreateTableCommand(), new DeleteTableCommand(), new DropTableCommand(), new DUCommand(), new ExportTableCommand(), new ImportTableCommand(), new OfflineCommand(), new OnlineCommand(), new RenameTableCommand(), new TablesCommand(), new NamespacesCommand(), new CreateNamespaceCommand(), new DeleteNamespaceCommand(), new RenameNamespaceCommand(), new SummariesCommand() };
    Command[] tableControlCommands = { new AddSplitsCommand(), new CompactCommand(), new ConstraintCommand(), new FlushCommand(), new GetGroupsCommand(), new GetSplitsCommand(), new MergeCommand(), new SetGroupsCommand() };
    Command[] userCommands = { new AddAuthsCommand(), new CreateUserCommand(), new DeleteUserCommand(), new DropUserCommand(), new GetAuthsCommand(), new PasswdCommand(), new SetAuthsCommand(), new UsersCommand(), new DeleteAuthsCommand() };
    commandGrouping.put("-- Writing, Reading, and Removing Data --", dataCommands);
    commandGrouping.put("-- Debugging Commands -------------------", debuggingCommands);
    commandGrouping.put("-- Shell Execution Commands -------------", execCommands);
    commandGrouping.put("-- Exiting Commands ---------------------", exitCommands);
    commandGrouping.put("-- Help Commands ------------------------", helpCommands);
    commandGrouping.put("-- Iterator Configuration ---------------", iteratorCommands);
    commandGrouping.put("-- Permissions Administration Commands --", permissionsCommands);
    commandGrouping.put("-- Shell State Commands -----------------", stateCommands);
    commandGrouping.put("-- Table Administration Commands --------", tableCommands);
    commandGrouping.put("-- Table Control Commands ---------------", tableControlCommands);
    commandGrouping.put("-- User Administration Commands ---------", userCommands);
    for (Command[] cmds : commandGrouping.values()) {
        for (Command cmd : cmds) commandFactory.put(cmd.getName(), cmd);
    }
    for (Command cmd : otherCommands) {
        commandFactory.put(cmd.getName(), cmd);
    }
    return true;
}
Also used : AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) ImportDirectoryCommand(org.apache.accumulo.shell.commands.ImportDirectoryCommand) NamespacesCommand(org.apache.accumulo.shell.commands.NamespacesCommand) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) FateCommand(org.apache.accumulo.shell.commands.FateCommand) DeleteCommand(org.apache.accumulo.shell.commands.DeleteCommand) SummariesCommand(org.apache.accumulo.shell.commands.SummariesCommand) RenameNamespaceCommand(org.apache.accumulo.shell.commands.RenameNamespaceCommand) InfoCommand(org.apache.accumulo.shell.commands.InfoCommand) NoTableCommand(org.apache.accumulo.shell.commands.NoTableCommand) ScriptCommand(org.apache.accumulo.shell.commands.ScriptCommand) HistoryCommand(org.apache.accumulo.shell.commands.HistoryCommand) CloneTableCommand(org.apache.accumulo.shell.commands.CloneTableCommand) DropTableCommand(org.apache.accumulo.shell.commands.DropTableCommand) CreateTableCommand(org.apache.accumulo.shell.commands.CreateTableCommand) DeleteTableCommand(org.apache.accumulo.shell.commands.DeleteTableCommand) ImportTableCommand(org.apache.accumulo.shell.commands.ImportTableCommand) NoTableCommand(org.apache.accumulo.shell.commands.NoTableCommand) RenameTableCommand(org.apache.accumulo.shell.commands.RenameTableCommand) TableCommand(org.apache.accumulo.shell.commands.TableCommand) ExportTableCommand(org.apache.accumulo.shell.commands.ExportTableCommand) GetAuthsCommand(org.apache.accumulo.shell.commands.GetAuthsCommand) OnlineCommand(org.apache.accumulo.shell.commands.OnlineCommand) ListScansCommand(org.apache.accumulo.shell.commands.ListScansCommand) ExitCommand(org.apache.accumulo.shell.commands.ExitCommand) HelpCommand(org.apache.accumulo.shell.commands.HelpCommand) OfflineCommand(org.apache.accumulo.shell.commands.OfflineCommand) PingCommand(org.apache.accumulo.shell.commands.PingCommand) QuestionCommand(org.apache.accumulo.shell.commands.QuestionCommand) PasswdCommand(org.apache.accumulo.shell.commands.PasswdCommand) ListCompactionsCommand(org.apache.accumulo.shell.commands.ListCompactionsCommand) QuitCommand(org.apache.accumulo.shell.commands.QuitCommand) ExportTableCommand(org.apache.accumulo.shell.commands.ExportTableCommand) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) AddSplitsCommand(org.apache.accumulo.shell.commands.AddSplitsCommand) DeleteRowsCommand(org.apache.accumulo.shell.commands.DeleteRowsCommand) TraceCommand(org.apache.accumulo.shell.commands.TraceCommand) RenameTableCommand(org.apache.accumulo.shell.commands.RenameTableCommand) JCommander(com.beust.jcommander.JCommander) DeleteNamespaceCommand(org.apache.accumulo.shell.commands.DeleteNamespaceCommand) SetScanIterCommand(org.apache.accumulo.shell.commands.SetScanIterCommand) ClearCommand(org.apache.accumulo.shell.commands.ClearCommand) AddAuthsCommand(org.apache.accumulo.shell.commands.AddAuthsCommand) ByeCommand(org.apache.accumulo.shell.commands.ByeCommand) ConsoleReader(jline.console.ConsoleReader) RevokeCommand(org.apache.accumulo.shell.commands.RevokeCommand) ListIterCommand(org.apache.accumulo.shell.commands.ListIterCommand) FlushCommand(org.apache.accumulo.shell.commands.FlushCommand) UsersCommand(org.apache.accumulo.shell.commands.UsersCommand) EGrepCommand(org.apache.accumulo.shell.commands.EGrepCommand) CompactCommand(org.apache.accumulo.shell.commands.CompactCommand) DeleteUserCommand(org.apache.accumulo.shell.commands.DeleteUserCommand) HiddenCommand(org.apache.accumulo.shell.commands.HiddenCommand) GetSplitsCommand(org.apache.accumulo.shell.commands.GetSplitsCommand) MergeCommand(org.apache.accumulo.shell.commands.MergeCommand) InterpreterCommand(org.apache.accumulo.shell.commands.InterpreterCommand) CreateTableCommand(org.apache.accumulo.shell.commands.CreateTableCommand) ExecfileCommand(org.apache.accumulo.shell.commands.ExecfileCommand) GrantCommand(org.apache.accumulo.shell.commands.GrantCommand) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) WhoAmICommand(org.apache.accumulo.shell.commands.WhoAmICommand) ListShellIterCommand(org.apache.accumulo.shell.commands.ListShellIterCommand) CreateNamespaceCommand(org.apache.accumulo.shell.commands.CreateNamespaceCommand) ParameterException(com.beust.jcommander.ParameterException) DeleteIterCommand(org.apache.accumulo.shell.commands.DeleteIterCommand) DeleteAuthsCommand(org.apache.accumulo.shell.commands.DeleteAuthsCommand) ClasspathCommand(org.apache.accumulo.shell.commands.ClasspathCommand) ConstraintCommand(org.apache.accumulo.shell.commands.ConstraintCommand) DeleteManyCommand(org.apache.accumulo.shell.commands.DeleteManyCommand) ImportTableCommand(org.apache.accumulo.shell.commands.ImportTableCommand) AuthenticateCommand(org.apache.accumulo.shell.commands.AuthenticateCommand) SetShellIterCommand(org.apache.accumulo.shell.commands.SetShellIterCommand) FormatterCommand(org.apache.accumulo.shell.commands.FormatterCommand) AboutCommand(org.apache.accumulo.shell.commands.AboutCommand) NamespacePermissionsCommand(org.apache.accumulo.shell.commands.NamespacePermissionsCommand) DUCommand(org.apache.accumulo.shell.commands.DUCommand) CloneTableCommand(org.apache.accumulo.shell.commands.CloneTableCommand) DeleteTableCommand(org.apache.accumulo.shell.commands.DeleteTableCommand) SystemPermissionsCommand(org.apache.accumulo.shell.commands.SystemPermissionsCommand) SetIterCommand(org.apache.accumulo.shell.commands.SetIterCommand) SetGroupsCommand(org.apache.accumulo.shell.commands.SetGroupsCommand) CreateUserCommand(org.apache.accumulo.shell.commands.CreateUserCommand) DropUserCommand(org.apache.accumulo.shell.commands.DropUserCommand) DropTableCommand(org.apache.accumulo.shell.commands.DropTableCommand) TablePermissionsCommand(org.apache.accumulo.shell.commands.TablePermissionsCommand) MaxRowCommand(org.apache.accumulo.shell.commands.MaxRowCommand) TablesCommand(org.apache.accumulo.shell.commands.TablesCommand) DebugCommand(org.apache.accumulo.shell.commands.DebugCommand) SetAuthsCommand(org.apache.accumulo.shell.commands.SetAuthsCommand) GetGroupsCommand(org.apache.accumulo.shell.commands.GetGroupsCommand) DeleteShellIterCommand(org.apache.accumulo.shell.commands.DeleteShellIterCommand) ConfigCommand(org.apache.accumulo.shell.commands.ConfigCommand) ListBulkCommand(org.apache.accumulo.shell.commands.ListBulkCommand) UserInterruptException(jline.console.UserInterruptException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) FileSystemException(org.apache.commons.vfs2.FileSystemException) BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) IOException(java.io.IOException) MissingOptionException(org.apache.commons.cli.MissingOptionException) ParameterException(com.beust.jcommander.ParameterException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) CreateUserCommand(org.apache.accumulo.shell.commands.CreateUserCommand) UserCommand(org.apache.accumulo.shell.commands.UserCommand) DeleteUserCommand(org.apache.accumulo.shell.commands.DeleteUserCommand) DropUserCommand(org.apache.accumulo.shell.commands.DropUserCommand) ScanCommand(org.apache.accumulo.shell.commands.ScanCommand) ExtensionCommand(org.apache.accumulo.shell.commands.ExtensionCommand) UserPermissionsCommand(org.apache.accumulo.shell.commands.UserPermissionsCommand) WhoAmICommand(org.apache.accumulo.shell.commands.WhoAmICommand) SetAuthsCommand(org.apache.accumulo.shell.commands.SetAuthsCommand) InsertCommand(org.apache.accumulo.shell.commands.InsertCommand) SystemPermissionsCommand(org.apache.accumulo.shell.commands.SystemPermissionsCommand) CreateNamespaceCommand(org.apache.accumulo.shell.commands.CreateNamespaceCommand) CloneTableCommand(org.apache.accumulo.shell.commands.CloneTableCommand) DropTableCommand(org.apache.accumulo.shell.commands.DropTableCommand) CreateTableCommand(org.apache.accumulo.shell.commands.CreateTableCommand) DUCommand(org.apache.accumulo.shell.commands.DUCommand) DeleteAuthsCommand(org.apache.accumulo.shell.commands.DeleteAuthsCommand) CreateUserCommand(org.apache.accumulo.shell.commands.CreateUserCommand) InterpreterCommand(org.apache.accumulo.shell.commands.InterpreterCommand) SetIterCommand(org.apache.accumulo.shell.commands.SetIterCommand) OfflineCommand(org.apache.accumulo.shell.commands.OfflineCommand) ScanCommand(org.apache.accumulo.shell.commands.ScanCommand) TablePermissionsCommand(org.apache.accumulo.shell.commands.TablePermissionsCommand) UserCommand(org.apache.accumulo.shell.commands.UserCommand) GetGroupsCommand(org.apache.accumulo.shell.commands.GetGroupsCommand) DeleteTableCommand(org.apache.accumulo.shell.commands.DeleteTableCommand) DeleteUserCommand(org.apache.accumulo.shell.commands.DeleteUserCommand) AddAuthsCommand(org.apache.accumulo.shell.commands.AddAuthsCommand) ListBulkCommand(org.apache.accumulo.shell.commands.ListBulkCommand) TablesCommand(org.apache.accumulo.shell.commands.TablesCommand) AuthenticateCommand(org.apache.accumulo.shell.commands.AuthenticateCommand) HistoryCommand(org.apache.accumulo.shell.commands.HistoryCommand) SummariesCommand(org.apache.accumulo.shell.commands.SummariesCommand) SetScanIterCommand(org.apache.accumulo.shell.commands.SetScanIterCommand) SleepCommand(org.apache.accumulo.shell.commands.SleepCommand) ImportTableCommand(org.apache.accumulo.shell.commands.ImportTableCommand) DropUserCommand(org.apache.accumulo.shell.commands.DropUserCommand) FormatterCommand(org.apache.accumulo.shell.commands.FormatterCommand) ExecfileCommand(org.apache.accumulo.shell.commands.ExecfileCommand) InfoCommand(org.apache.accumulo.shell.commands.InfoCommand) ConstraintCommand(org.apache.accumulo.shell.commands.ConstraintCommand) DebugCommand(org.apache.accumulo.shell.commands.DebugCommand) DeleteManyCommand(org.apache.accumulo.shell.commands.DeleteManyCommand) DeleteShellIterCommand(org.apache.accumulo.shell.commands.DeleteShellIterCommand) CompactCommand(org.apache.accumulo.shell.commands.CompactCommand) GetSplitsCommand(org.apache.accumulo.shell.commands.GetSplitsCommand) DeleteScanIterCommand(org.apache.accumulo.shell.commands.DeleteScanIterCommand) FateCommand(org.apache.accumulo.shell.commands.FateCommand) HelpCommand(org.apache.accumulo.shell.commands.HelpCommand) GrantCommand(org.apache.accumulo.shell.commands.GrantCommand) ConfigCommand(org.apache.accumulo.shell.commands.ConfigCommand) ExitCommand(org.apache.accumulo.shell.commands.ExitCommand) RenameNamespaceCommand(org.apache.accumulo.shell.commands.RenameNamespaceCommand) AboutCommand(org.apache.accumulo.shell.commands.AboutCommand) DeleteCommand(org.apache.accumulo.shell.commands.DeleteCommand) SetGroupsCommand(org.apache.accumulo.shell.commands.SetGroupsCommand) UserPermissionsCommand(org.apache.accumulo.shell.commands.UserPermissionsCommand) SetShellIterCommand(org.apache.accumulo.shell.commands.SetShellIterCommand) ScriptCommand(org.apache.accumulo.shell.commands.ScriptCommand) ImportDirectoryCommand(org.apache.accumulo.shell.commands.ImportDirectoryCommand) OnlineCommand(org.apache.accumulo.shell.commands.OnlineCommand) ListScansCommand(org.apache.accumulo.shell.commands.ListScansCommand) DeleteRowsCommand(org.apache.accumulo.shell.commands.DeleteRowsCommand) PasswdCommand(org.apache.accumulo.shell.commands.PasswdCommand) ExtensionCommand(org.apache.accumulo.shell.commands.ExtensionCommand) MaxRowCommand(org.apache.accumulo.shell.commands.MaxRowCommand) ByeCommand(org.apache.accumulo.shell.commands.ByeCommand) GrepCommand(org.apache.accumulo.shell.commands.GrepCommand) MergeCommand(org.apache.accumulo.shell.commands.MergeCommand) NoTableCommand(org.apache.accumulo.shell.commands.NoTableCommand) ListCompactionsCommand(org.apache.accumulo.shell.commands.ListCompactionsCommand) PingCommand(org.apache.accumulo.shell.commands.PingCommand) ClsCommand(org.apache.accumulo.shell.commands.ClsCommand) ListIterCommand(org.apache.accumulo.shell.commands.ListIterCommand) DeleteIterCommand(org.apache.accumulo.shell.commands.DeleteIterCommand) GetAuthsCommand(org.apache.accumulo.shell.commands.GetAuthsCommand) TraceCommand(org.apache.accumulo.shell.commands.TraceCommand) RenameTableCommand(org.apache.accumulo.shell.commands.RenameTableCommand) NamespacePermissionsCommand(org.apache.accumulo.shell.commands.NamespacePermissionsCommand) UsersCommand(org.apache.accumulo.shell.commands.UsersCommand) DeleteNamespaceCommand(org.apache.accumulo.shell.commands.DeleteNamespaceCommand) TableCommand(org.apache.accumulo.shell.commands.TableCommand) ClearCommand(org.apache.accumulo.shell.commands.ClearCommand) HiddenCommand(org.apache.accumulo.shell.commands.HiddenCommand) FlushCommand(org.apache.accumulo.shell.commands.FlushCommand) ExportTableCommand(org.apache.accumulo.shell.commands.ExportTableCommand) ClasspathCommand(org.apache.accumulo.shell.commands.ClasspathCommand) RevokeCommand(org.apache.accumulo.shell.commands.RevokeCommand) ListShellIterCommand(org.apache.accumulo.shell.commands.ListShellIterCommand) QuitCommand(org.apache.accumulo.shell.commands.QuitCommand) EGrepCommand(org.apache.accumulo.shell.commands.EGrepCommand) AddSplitsCommand(org.apache.accumulo.shell.commands.AddSplitsCommand) NamespacesCommand(org.apache.accumulo.shell.commands.NamespacesCommand) QuestionCommand(org.apache.accumulo.shell.commands.QuestionCommand) GrepCommand(org.apache.accumulo.shell.commands.GrepCommand) EGrepCommand(org.apache.accumulo.shell.commands.EGrepCommand) InsertCommand(org.apache.accumulo.shell.commands.InsertCommand) SleepCommand(org.apache.accumulo.shell.commands.SleepCommand) ClsCommand(org.apache.accumulo.shell.commands.ClsCommand) DeleteScanIterCommand(org.apache.accumulo.shell.commands.DeleteScanIterCommand)

Example 48 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class DynamicThreadPoolsIT method test.

@Test
public void test() throws Exception {
    final String[] tables = getUniqueNames(15);
    String firstTable = tables[0];
    Connector c = getConnector();
    c.instanceOperations().setProperty(Property.TSERV_MAJC_MAXCONCURRENT.getKey(), "5");
    TestIngest.Opts opts = new TestIngest.Opts();
    opts.rows = 500 * 1000;
    opts.createTable = true;
    opts.setTableName(firstTable);
    ClientConfiguration clientConf = cluster.getClientConfig();
    if (clientConf.hasSasl()) {
        opts.updateKerberosCredentials(clientConf);
    } else {
        opts.setPrincipal(getAdminPrincipal());
    }
    TestIngest.ingest(c, opts, new BatchWriterOpts());
    c.tableOperations().flush(firstTable, null, null, true);
    for (int i = 1; i < tables.length; i++) c.tableOperations().clone(firstTable, tables[i], true, null, null);
    // time between checks of the thread pool sizes
    sleepUninterruptibly(11, TimeUnit.SECONDS);
    Credentials creds = new Credentials(getAdminPrincipal(), getAdminToken());
    for (int i = 1; i < tables.length; i++) c.tableOperations().compact(tables[i], null, null, true, false);
    for (int i = 0; i < 30; i++) {
        int count = 0;
        MasterClientService.Iface client = null;
        MasterMonitorInfo stats = null;
        while (true) {
            try {
                client = MasterClient.getConnectionWithRetry(new ClientContext(c.getInstance(), creds, clientConf));
                stats = client.getMasterStats(Tracer.traceInfo(), creds.toThrift(c.getInstance()));
                break;
            } catch (ThriftNotActiveServiceException e) {
                // Let it loop, fetching a new location
                sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            } finally {
                if (client != null)
                    MasterClient.close(client);
            }
        }
        for (TabletServerStatus server : stats.tServerInfo) {
            for (TableInfo table : server.tableMap.values()) {
                count += table.majors.running;
            }
        }
        System.out.println("count " + count);
        if (count > 3)
            return;
        sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
    }
    fail("Could not observe higher number of threads after changing the config");
}
Also used : Connector(org.apache.accumulo.core.client.Connector) MasterMonitorInfo(org.apache.accumulo.core.master.thrift.MasterMonitorInfo) ThriftNotActiveServiceException(org.apache.accumulo.core.client.impl.thrift.ThriftNotActiveServiceException) BatchWriterOpts(org.apache.accumulo.core.cli.BatchWriterOpts) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) TestIngest(org.apache.accumulo.test.TestIngest) MasterClientService(org.apache.accumulo.core.master.thrift.MasterClientService) BatchWriterOpts(org.apache.accumulo.core.cli.BatchWriterOpts) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) Credentials(org.apache.accumulo.core.client.impl.Credentials) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Test(org.junit.Test)

Example 49 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class BulkSplitOptimizationIT method testBulkSplitOptimization.

@Test
public void testBulkSplitOptimization() throws Exception {
    final Connector c = getConnector();
    final String tableName = getUniqueNames(1)[0];
    c.tableOperations().create(tableName);
    c.tableOperations().setProperty(tableName, Property.TABLE_MAJC_RATIO.getKey(), "1000");
    c.tableOperations().setProperty(tableName, Property.TABLE_FILE_MAX.getKey(), "1000");
    c.tableOperations().setProperty(tableName, Property.TABLE_SPLIT_THRESHOLD.getKey(), "1G");
    FileSystem fs = cluster.getFileSystem();
    Path testDir = new Path(getUsableDir(), "testmf");
    FunctionalTestUtils.createRFiles(c, fs, testDir.toString(), ROWS, SPLITS, 8);
    FileStatus[] stats = fs.listStatus(testDir);
    System.out.println("Number of generated files: " + stats.length);
    FunctionalTestUtils.bulkImport(c, fs, tableName, testDir.toString());
    FunctionalTestUtils.checkSplits(c, tableName, 0, 0);
    FunctionalTestUtils.checkRFiles(c, tableName, 1, 1, 100, 100);
    // initiate splits
    getConnector().tableOperations().setProperty(tableName, Property.TABLE_SPLIT_THRESHOLD.getKey(), "100K");
    sleepUninterruptibly(2, TimeUnit.SECONDS);
    // wait until over split threshold -- should be 78 splits
    while (getConnector().tableOperations().listSplits(tableName).size() < 75) {
        sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
    }
    FunctionalTestUtils.checkSplits(c, tableName, 50, 100);
    VerifyIngest.Opts opts = new VerifyIngest.Opts();
    opts.timestamp = 1;
    opts.dataSize = 50;
    opts.random = 56;
    opts.rows = 100000;
    opts.startRow = 0;
    opts.cols = 1;
    opts.setTableName(tableName);
    AuthenticationToken adminToken = getAdminToken();
    if (adminToken instanceof PasswordToken) {
        PasswordToken token = (PasswordToken) getAdminToken();
        opts.setPassword(new Password(new String(token.getPassword(), UTF_8)));
        opts.setPrincipal(getAdminPrincipal());
    } else if (adminToken instanceof KerberosToken) {
        ClientConfiguration clientConf = cluster.getClientConfig();
        opts.updateKerberosCredentials(clientConf);
    } else {
        Assert.fail("Unknown token type");
    }
    VerifyIngest.verifyIngest(c, opts, new ScannerOpts());
    // ensure each tablet does not have all map files, should be ~2.5 files per tablet
    FunctionalTestUtils.checkRFiles(c, tableName, 50, 100, 1, 4);
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) FileStatus(org.apache.hadoop.fs.FileStatus) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) ScannerOpts(org.apache.accumulo.core.cli.ScannerOpts) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) ScannerOpts(org.apache.accumulo.core.cli.ScannerOpts) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) VerifyIngest(org.apache.accumulo.test.VerifyIngest) FileSystem(org.apache.hadoop.fs.FileSystem) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) Password(org.apache.accumulo.core.cli.ClientOpts.Password) Test(org.junit.Test)

Example 50 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class TransportCachingIT method testCachedTransport.

@Test
public void testCachedTransport() {
    Connector conn = getConnector();
    Instance instance = conn.getInstance();
    ClientConfiguration clientConf = cluster.getClientConfig();
    ClientContext context = new ClientContext(instance, new Credentials(getAdminPrincipal(), getAdminToken()), clientConf);
    long rpcTimeout = ConfigurationTypeHelper.getTimeInMillis(Property.GENERAL_RPC_TIMEOUT.getDefaultValue());
    // create list of servers
    ArrayList<ThriftTransportKey> servers = new ArrayList<>();
    // add tservers
    ZooCache zc = new ZooCacheFactory().getZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
    for (String tserver : zc.getChildren(ZooUtil.getRoot(instance) + Constants.ZTSERVERS)) {
        String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS + "/" + tserver;
        byte[] data = ZooUtil.getLockData(zc, path);
        if (data != null) {
            String strData = new String(data, UTF_8);
            if (!strData.equals("master"))
                servers.add(new ThriftTransportKey(new ServerServices(strData).getAddress(Service.TSERV_CLIENT), rpcTimeout, context));
        }
    }
    ThriftTransportPool pool = ThriftTransportPool.getInstance();
    TTransport first = null;
    while (null == first) {
        try {
            // Get a transport (cached or not)
            first = pool.getAnyTransport(servers, true).getSecond();
        } catch (TTransportException e) {
            log.warn("Failed to obtain transport to {}", servers);
        }
    }
    assertNotNull(first);
    // Return it to unreserve it
    pool.returnTransport(first);
    TTransport second = null;
    while (null == second) {
        try {
            // Get a cached transport (should be the first)
            second = pool.getAnyTransport(servers, true).getSecond();
        } catch (TTransportException e) {
            log.warn("Failed obtain 2nd transport to {}", servers);
        }
    }
    // We should get the same transport
    assertTrue("Expected the first and second to be the same instance", first == second);
    // Return the 2nd
    pool.returnTransport(second);
    TTransport third = null;
    while (null == third) {
        try {
            // Get a non-cached transport
            third = pool.getAnyTransport(servers, false).getSecond();
        } catch (TTransportException e) {
            log.warn("Failed obtain 2nd transport to {}", servers);
        }
    }
    assertFalse("Expected second and third transport to be different instances", second == third);
    pool.returnTransport(third);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ServerServices(org.apache.accumulo.core.util.ServerServices) Instance(org.apache.accumulo.core.client.Instance) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) ArrayList(java.util.ArrayList) TTransportException(org.apache.thrift.transport.TTransportException) ThriftTransportPool(org.apache.accumulo.core.client.impl.ThriftTransportPool) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) ZooCacheFactory(org.apache.accumulo.fate.zookeeper.ZooCacheFactory) ThriftTransportKey(org.apache.accumulo.core.client.impl.ThriftTransportKey) TTransport(org.apache.thrift.transport.TTransport) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) Credentials(org.apache.accumulo.core.client.impl.Credentials) Test(org.junit.Test)

Aggregations

ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)79 Test (org.junit.Test)40 Connector (org.apache.accumulo.core.client.Connector)28 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)28 IOException (java.io.IOException)16 TestIngest (org.apache.accumulo.test.TestIngest)15 BatchWriterOpts (org.apache.accumulo.core.cli.BatchWriterOpts)13 ScannerOpts (org.apache.accumulo.core.cli.ScannerOpts)12 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)12 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)11 VerifyIngest (org.apache.accumulo.test.VerifyIngest)11 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)10 ClusterUser (org.apache.accumulo.cluster.ClusterUser)9 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)9 Map (java.util.Map)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)7 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)7 Instance (org.apache.accumulo.core.client.Instance)6 Authorizations (org.apache.accumulo.core.security.Authorizations)6 Path (org.apache.hadoop.fs.Path)6