/*
(non-Javadoc)

@see
org.duracloud.mill.util.DriverSupport#executeImpl(org.apache.commons.
cli.CommandLine)
436750
@Override
    protected void executeImpl(CommandLine cmd) {
        try {

            boolean dryRun = Boolean.valueOf( cmd.hasOption( "d" ) );
            String host = cmd.getOptionValue( "host" );
            String port = cmd.getOptionValue( "port", "443" );
            String username = cmd.getOptionValue( "u" );
            String password = cmd.getOptionValue( "p" );
            String spaceId = cmd.getOptionValue( "s" );
            String storeId = cmd.getOptionValue( "t" );
            String auditQueueName = cmd.getOptionValue( "q" );

            String account = host.split( "[.]" )[0];
            ContentStoreManager storeManager = new ContentStoreManagerImpl( host, port );
            storeManager.login( new Credential( username, password ) );
            Map<String, ContentStore> contentStoreMap = storeManager.getContentStores();

            final ContentStore store;

            if (storeId != null) {
                store = storeManager.getContentStore( storeId );
            } else {
                store = storeManager.getPrimaryContentStore();
            }

            AuditTaskGenerator generator =
                new AuditTaskGenerator( store, spaceId, dryRun, account, auditQueueName, username );
            generator.execute();
        } catch (Exception e) {
            log.error( e.getMessage(), e );
        } finally {
            log.info( "exiting..." );
        }
    }
434380
public static void main(final String[] args) {

    try {

      final Configuration commandLineConf = parseCommandLine(args);
      final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);

      final boolean isLocal = injector.getNamedInstance(Local.class);
      final int numEvaluators = injector.getNamedInstance(NumEvaluators.class);
      final int numTasks = injector.getNamedInstance(NumTasks.class);
      final int delay = injector.getNamedInstance(Delay.class);
      final int jobNum = injector.getNamedInstance(JobId.class);

      final String jobId = String.format("pool.e_%d.a_%d.d_%d.%d",
          numEvaluators, numTasks, delay, jobNum < 0 ? System.currentTimeMillis() : jobNum);

      // Timeout: delay + 6 extra seconds per Task per Evaluator + 2 minutes to allocate each Evaluator:
      final int timeout = numTasks * (delay + 6) * 1000 / numEvaluators + numEvaluators * 120000;

      final Configuration runtimeConfig = getClientConfiguration(commandLineConf, isLocal);
      LOG.log(Level.INFO, "TIME: Start Client {0} with timeout {1} sec. Configuration:\n--\n{2}--",
          new Object[] {jobId, timeout / 1000, Configurations.toString(runtimeConfig, true)});

      final Configuration driverConfig = DriverConfiguration.CONF
          .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(JobDriver.class))
          .set(DriverConfiguration.DRIVER_IDENTIFIER, jobId)
          .set(DriverConfiguration.ON_DRIVER_STARTED, JobDriver.StartHandler.class)
          .set(DriverConfiguration.ON_DRIVER_STOP, JobDriver.StopHandler.class)
          .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, JobDriver.AllocatedEvaluatorHandler.class)
          .set(DriverConfiguration.ON_CONTEXT_ACTIVE, JobDriver.ActiveContextHandler.class)
          .set(DriverConfiguration.ON_TASK_RUNNING, JobDriver.RunningTaskHandler.class)
          .set(DriverConfiguration.ON_TASK_COMPLETED, JobDriver.CompletedTaskHandler.class)
          .set(DriverConfiguration.ON_EVALUATOR_COMPLETED, JobDriver.CompletedEvaluatorHandler.class)
          .build();

      final Configuration submittedConfiguration = Tang.Factory.getTang()
          .newConfigurationBuilder(driverConfig, commandLineConf).build();

      DriverLauncher.getLauncher(runtimeConfig).run(submittedConfiguration, timeout);

      LOG.log(Level.INFO, "TIME: Stop Client {0}", jobId);

    } catch (final BindException | InjectionException | IOException ex) {
      LOG.log(Level.SEVERE, "Job configuration error", ex);
    }
  }
647754
public static void runShellCommand(String[] cmd,
                                     StringBuilder outputLines)
    throws IOException {
    runShellCommand(cmd, outputLines, null);
  }
180049
@Override
   public void execute()  throws MojoExecutionException, MojoFailureException
   {
      ClassLoader oldCL = SecurityActions.getThreadContextClassLoader();
      try 
      {
         SecurityActions.setThreadContextClassLoader(SecurityActions.getClassLoader(ValidatorMojo.class));

         Validation.validate(getRarFile().toURI().toURL(), 
            getOutputDir(), getClasspath());
      }
      catch (Throwable t) 
      {
         t.printStackTrace();
      }
      finally
      {
         SecurityActions.setThreadContextClassLoader(oldCL);
      }
   }
584818
private void executeMvnCommand(final String... args)
            throws CommandLineException, MojoFailureException {
        executeCommand(cmdMvn, true, argLine, args);
    }
281519
public static void executeCommand(String[] args) throws Exception {
        String subCmd = (args.length > 0) ? args[0] : "";
        args = AdminToolUtils.copyArrayCutFirst(args);
        if(subCmd.equals("query-keys")) {
            SubCommandDebugQueryKeys.executeCommand(args);
        } else if(subCmd.equals("route")) {
            SubCommandDebugRoute.executeCommand(args);
        } else {
            printHelp(System.out);
        }
    }
704307
@SuppressWarnings("unchecked")
        public static void executeCommand(String[] args) throws IOException {

            OptionParser parser = getParser();

            // declare parameters
            List<String> metaKeys = null;
            String url = null;

            // parse command-line input
            args = AdminToolUtils.copyArrayAddFirst(args, "--" + OPT_HEAD_META_CHECK);
            OptionSet options = parser.parse(args);
            if(options.has(AdminParserUtils.OPT_HELP)) {
                printHelp(System.out);
                return;
            }

            // check required options and/or conflicting options
            AdminParserUtils.checkRequired(options, OPT_HEAD_META_CHECK);
            AdminParserUtils.checkRequired(options, AdminParserUtils.OPT_URL);

            // load parameters
            metaKeys = (List<String>) options.valuesOf(OPT_HEAD_META_CHECK);
            url = (String) options.valueOf(AdminParserUtils.OPT_URL);


            // execute command
            if(metaKeys.size() == 0
               || (metaKeys.size() == 1 && metaKeys.get(0).equals(METAKEY_ALL))) {
                metaKeys = Lists.newArrayList();
                metaKeys.add(MetadataStore.CLUSTER_KEY);
                metaKeys.add(MetadataStore.STORES_KEY);
                metaKeys.add(MetadataStore.SERVER_STATE_KEY);
            }

            AdminClient adminClient = AdminToolUtils.getAdminClient(url);

            doMetaCheck(adminClient, metaKeys);
        }
402116
public void executeOnDaemon(Runnable command) {

        int id = 0;
        final Runnable commandToRun = command;

        synchronized (this) {
            this.daemonId++;
            id = this.daemonId;
        }

        final String runId = name + " : DMN" + id; // d185137.2

        Thread t = (Thread) AccessController.doPrivileged(new PrivilegedAction()
        { // d185137.2
            public Object run()
        {
            // return new Thread(commandToRun); // d185137.2
            Thread temp = new Thread(commandToRun, runId); // d185137.2
            temp.setDaemon(true);
            return temp;
        }
        });
        t.start();
    }
1179433
private void execute(String command) throws XAException {
    try {
      connection.createStatement().execute(command);
    } catch (SQLException sqle) {
      throw mapXaException(sqle);
    }
  }
319881
public static void runShellCommand(String cmd,
                                     StringBuilder outputLines,
                                     StringBuilder errorLines)
    throws IOException {
    runShellCommand(new String[] {cmd}, outputLines, errorLines);
  }
211281
private void execute(Command command, CommandLineParser lineParser) {
        ConsoleWrapper wrappedConsole = new ConsoleWrapper(console);
        PrintWriter outputWriter = null;
        try {
            ParsedOptions options = lineParser.parseOptions(command.getOptions());
            outputWriter = OutputRedirection.determineOutputWriter(lineParser.getRedirectionList(), wrappedConsole);
            wrappedConsole.setWriter(outputWriter);
            command.execute(options, wrappedConsole);
        } catch (ConsoleTerminatedException e) {
            throw e;
        } catch (OptionParserException e) {
            wrappedConsole.writeError(e.getMessage());
            command.printHelp(wrappedConsole);
        } catch (Exception e) {
            log.error("Failed to execute command: " + lineParser.getCommandLine(), e);
        } finally {
            if (outputWriter != null) {
                outputWriter.close();
            }
        }
    }
99331
public static void main(final String[] args) throws InjectionException, IOException {

    final JavaConfigurationBuilder driverConfigBuilder = TANG.newConfigurationBuilder(STATIC_DRIVER_CONFIG);

    new CommandLine(driverConfigBuilder)
        .registerShortNameOfClass(Command.class)
        .registerShortNameOfClass(NumEvaluators.class)
        .registerShortNameOfClass(RuntimeName.class)
        .processCommandLine(args);

    final Configuration driverConfig = driverConfigBuilder.build();

    final Injector injector = TANG.newInjector(driverConfig);

    final int numEvaluators = injector.getNamedInstance(NumEvaluators.class);
    final String runtimeName = injector.getNamedInstance(RuntimeName.class);
    final String command = injector.getNamedInstance(Command.class);

    LOG.log(Level.INFO, "REEF distributed shell: {0} evaluators on {1} runtime :: {2}",
        new Object[] {numEvaluators, runtimeName, command});

    final Configuration runtimeConfig;

    switch (runtimeName) {
    case "local":
      runtimeConfig = LocalRuntimeConfiguration.CONF
          .set(LocalRuntimeConfiguration.MAX_NUMBER_OF_EVALUATORS, numEvaluators)
          .build();
      break;
    case "yarn":
      runtimeConfig = YarnClientConfiguration.CONF.build();
      break;
    default:
      LOG.log(Level.SEVERE, "Unknown runtime: {0}", runtimeName);
      throw new IllegalArgumentException("Unknown runtime: " + runtimeName);
    }

    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfig).run(driverConfig, JOB_TIMEOUT);

    LOG.log(Level.INFO, "REEF job completed: {0}", status);
  }
1228645
@SuppressWarnings("unchecked")
        public static void executeCommand(String[] args) throws IOException {

            OptionParser parser = getParser();

            // declare parameters
            List<String> metaKeys = null;
            String url = null;
            List<Integer> nodeIds = null;
            Boolean allNodes = true;
            List<String> storeNames = null;

            // parse command-line input
            args = AdminToolUtils.copyArrayAddFirst(args, "--" + OPT_HEAD_META_GET_RO);
            OptionSet options = parser.parse(args);
            if(options.has(AdminParserUtils.OPT_HELP)) {
                printHelp(System.out);
                return;
            }

            // check required options and/or conflicting options
            AdminParserUtils.checkRequired(options, OPT_HEAD_META_GET_RO);
            AdminParserUtils.checkRequired(options, AdminParserUtils.OPT_URL);
            AdminParserUtils.checkOptional(options,
                                           AdminParserUtils.OPT_NODE,
                                           AdminParserUtils.OPT_ALL_NODES);
            AdminParserUtils.checkRequired(options, AdminParserUtils.OPT_STORE);

            // load parameters
            metaKeys = (List<String>) options.valuesOf(OPT_HEAD_META_GET_RO);
            url = (String) options.valueOf(AdminParserUtils.OPT_URL);
            if(options.has(AdminParserUtils.OPT_NODE)) {
                nodeIds = (List<Integer>) options.valuesOf(AdminParserUtils.OPT_NODE);
                allNodes = false;
            }
            storeNames = (List<String>) options.valuesOf(AdminParserUtils.OPT_STORE);

            // execute command
            AdminClient adminClient = AdminToolUtils.getAdminClient(url);

            if(allNodes) {
                nodeIds = AdminToolUtils.getAllNodeIds(adminClient);
            }

            if(metaKeys.size() == 1 && metaKeys.get(0).equals(METAKEY_ALL)) {
                metaKeys = Lists.newArrayList();
                metaKeys.add(KEY_MAX_VERSION);
                metaKeys.add(KEY_CURRENT_VERSION);
                metaKeys.add(KEY_STORAGE_FORMAT);
            }

            doMetaGetRO(adminClient, nodeIds, storeNames, metaKeys);
        }
268815
public static void executeCommand(String[] args) throws IOException {

            OptionParser parser = getParser();

            // declare parameters
            String url = null;

            // parse command-line input
            OptionSet options = parser.parse(args);
            if(options.has(AdminParserUtils.OPT_HELP)) {
                printHelp(System.out);
                return;
            }

            // check required options and/or conflicting options
            AdminParserUtils.checkRequired(options, AdminParserUtils.OPT_URL);

            // load parameters
            url = (String) options.valueOf(AdminParserUtils.OPT_URL);

            // execute command
            AdminClient adminClient = AdminToolUtils.getAdminClient(url);

            doMetaCheckVersion(adminClient);
        }
61216
@Override
    protected void executeImpl(CommandLine cmd) {
        try {
            List<PropertyDefinition> defintions =
                new PropertyDefinitionListBuilder().addMillDb()
                                                   .addManifestExpirationDate()
                                                   .build();
            PropertyVerifier verifier = new PropertyVerifier(defintions);
            verifier.verify(System.getProperties());
            String time = System.getProperty(ConfigConstants.MANIFEST_EXPIRATION_TIME);
            Date expirationDate;
            expirationDate = parseExpirationDate(time);

            ApplicationContext context = new AnnotationConfigApplicationContext("org.duracloud.mill");
            log.info("spring context initialized.");
            ManifestStore store = context.getBean(ManifestStore.class);
            log.info("beginning purge of deleted items");

            long deleted = 0l;
            long total = 0l;
            while ((deleted = store.purgeDeletedItemsBefore(expirationDate)) > 0) {
                total += deleted;
                log.info("Deleted {} items that were flagged as deleted before {}",
                         deleted,
                         expirationDate);
            }

            log.info("Purge completed: Deleted a grand total of {} items that were flagged as deleted before {}",
                     total,
                     expirationDate);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            log.info("exiting...");
        }
    }
1244932
@Override
    protected void doExecute() throws Exception {
        final CommandHandler commandHandler = new CommandHandlerImpl(this.getLog());

        checkStageDirectoryExistence();

        checkRuntimeExistence(commandHandler);

        runFunctions(commandHandler);
    }
673068
public static void main(final String[] args) throws InjectionException, IOException {

    final ClientProtocol.DriverClientConfiguration.Builder builder =
        ClientProtocol.DriverClientConfiguration.newBuilder();
    builder.setJobid("HelloREEF");
    builder.setEnableHttpDriver(false);
    builder.setOperatingSystem(ClientProtocol.DriverClientConfiguration.OS.LINUX);
    builder.setAzbatchRuntime(ClientProtocol.AzureBatchRuntimeParameters.newBuilder()
        .build());
    builder.addGlobalLibraries(EnvironmentUtils.getClassLocation(HelloDriver.class));

    JavaClientLauncher.submit(builder.build(), DRIVER_CONFIG);
    LOG.log(Level.INFO, "REEF job completed");
    ThreadLogger.logThreads(LOG, Level.FINE, "Threads running at the end of HelloREEF:");
  }