Runs a specified script on the master node of your cluster.

@param script
The script to run.
@param args
Arguments that get passed to the script.
@return HadoopJarStepConfig that can be passed to your job flow.
559482
public HadoopJarStepConfig newScriptRunnerStep(String script, String... args) {
        List<String> argsList = new ArrayList<String>();
        argsList.add(script);
        for (String arg : args) {
            argsList.add(arg);
        }
        return new HadoopJarStepConfig()
            .withJar("s3://" + bucket + "/libs/script-runner/script-runner.jar")
            .withArgs(argsList);
    }
1004870
private void runScript(String alias, int levelC) throws IOException {
		String scriptFile = alias;
		InputStream stream;
		try {
			stream = getInputStream(scriptFile);
			if (stream == null) {
				System.out.println("Error.  Script file is not found: " + scriptFile);
				return;
			}
		} catch (IOException e) {
			System.out.println("Error.  Could not load script file " + scriptFile + ": " + e.getMessage());
			return;
		}
		final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
		try {
			doLines(levelC + 1, new LineReader() {
				@Override
				public String getNextLine(String prompt) throws IOException {
					return reader.readLine();
				}
			}, true);
		} finally {
			reader.close();
		}
	}
189020
@Help(
    help =
        "Executes a script at runtime for a VNFR of a defined VNFD in a running NSR with specific id"
  )
  public void executeScript(final String idNsr, final String idVnfr, String script)
      throws SDKException {
    String url = idNsr + "/vnfrecords" + "/" + idVnfr + "/execute-script";
    requestPost(url, script);
  }
1011664
@SneakyThrows
    public static <T> T executeGroovyScript(final GroovyObject groovyObject,
                                            final String methodName,
                                            final Object[] args,
                                            final Class<T> clazz,
                                            final boolean failOnError) {
        try {
            LOGGER.trace("Executing groovy script's [{}] method, with parameters [{}]", methodName, args);
            val result = groovyObject.invokeMethod(methodName, args);
            LOGGER.trace("Results returned by the groovy script are [{}]", result);

            if (!clazz.equals(Void.class)) {
                return getGroovyScriptExecutionResultOrThrow(clazz, result);
            }
        } catch (final Exception e) {
            var cause = (Throwable) null;
            if (e instanceof InvokerInvocationException) {
                cause = e.getCause();
            } else {
                cause = e;
            }
            if (failOnError) {
                throw cause;
            }
            LOGGER.error(cause.getMessage(), cause);
        }
        return null;
    }
282154
public int run(String[] args) throws ParseException, IOException,
      ClassNotFoundException, InterruptedException {

    Configuration hbaseConf = HBaseConfiguration.create(getConf());
    hdfs = FileSystem.get(hbaseConf);

    // Grab input args and allow for -Dxyz style arguments
    String[] otherArgs =
        new GenericOptionsParser(hbaseConf, args).getRemainingArgs();

    // Grab the arguments we're looking for.
    CommandLine commandLine = parseArgs(otherArgs);

    String input = null;
    boolean inputSpecified = commandLine.hasOption("i");
    if (inputSpecified) {
      // Grab the input path argument
      input = commandLine.getOptionValue("i");
      LOG.info("input=" + input);
    } else {
      LOG.info("Processing input from HBase ProcessRecords");
    }

    // Grab the cluster argument
    String cluster = commandLine.getOptionValue("c");
    LOG.info("cluster=" + cluster);

    String processFileSubstring = null;
    if (commandLine.hasOption("p")) {
      processFileSubstring = commandLine.getOptionValue("p");
    }
    LOG.info("processFileSubstring=" + processFileSubstring);

    boolean forceReprocess = commandLine.hasOption("f");
    LOG.info("forceReprocess: " + forceReprocess);

    // hbase.client.keyvalue.maxsize somehow defaults to 10 MB and we have
    // history files exceeding that. Disable limit.
    hbaseConf.setInt("hbase.client.keyvalue.maxsize", 0);

    // Shove this into the jobConf so that we can get it out on the task side.
    hbaseConf.setStrings(Constants.CLUSTER_JOB_CONF_KEY, cluster);

    boolean success = true;
    Connection hbaseConnection = null;
    try {
      hbaseConnection = ConnectionFactory.createConnection(hbaseConf);
      success = processRecordsFromHBase(hbaseConf, hbaseConnection, cluster,
          processFileSubstring, forceReprocess);
    } finally {
      if (hbaseConnection == null) {
        success = false;
      } else {
        hbaseConnection.close();
      }
    }

    // Return the status
    return success ? 0 : 1;
  }
455944
public static String executeGroovy(String script, @Nonnull VirtualChannel channel) throws IOException, InterruptedException {
        return channel.call(new Script(script));
    }
1341302
public static void main(String[] args) {
    SparkSession spark = SparkSession
      .builder()
      .appName("Java Spark SQL data sources example")
      .config("spark.some.config.option", "some-value")
      .getOrCreate();

    runBasicDataSourceExample(spark);
    runBasicParquetExample(spark);
    runParquetSchemaMergingExample(spark);
    runJsonDatasetExample(spark);
    runJdbcDatasetExample(spark);

    spark.stop();
  }
572720
public void execute() throws MojoExecutionException
    {
        if (properties == null)
        {
            getLog().warn("run-script failed: No properties supplied");
            return;
        }
        boolean bSuccess = false;
        Environment env = null;
        RunScriptProcess process = null;
        try {
            env = new Environment(properties);
            Application app = new ThinApplication(env, properties, null);
            Task task = new AutoTask(app, null, null);
            process = new RunScriptProcess(task, null, null);
            bSuccess = (process.doRunCommand(null, properties) == DBConstants.NORMAL_RETURN);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (process != null)
                process.free();
            if (env != null)
                env.free();
        }
        if (bSuccess)
            getLog().info("run-script ran successfully: " + properties.get(DBParams.PROCESS));
        else
            getLog().warn("run-script failed: " + properties.get(DBParams.PROCESS));
    }
858003
def run_hive_script(script):
    
    if not os.path.isfile(script):
        raise RuntimeError("Hive script: {0} does not exist.".format(script))
    return run_hive(['-f', script])
534556
public int run(String[] args) throws Exception {

    Configuration hbaseConf = HBaseConfiguration.create(getConf());

    // Grab input args and allow for -Dxyz style arguments
    String[] otherArgs =
        new GenericOptionsParser(hbaseConf, args).getRemainingArgs();

    // Grab the arguments we're looking for.
    CommandLine commandLine = parseArgs(otherArgs);

    // Grab the cluster argument
    String cluster = commandLine.getOptionValue("c");
    LOG.info("cluster=" + cluster);

    // Grab the cluster argument

    String processFileSubstring = null;
    if (commandLine.hasOption("p")) {
      processFileSubstring = commandLine.getOptionValue("p");
    }
    LOG.info("processFileSubstring=" + processFileSubstring);

    // Default to no max
    Integer maxCount = Integer.MAX_VALUE;
    if (commandLine.hasOption("m")) {
      try {
        maxCount = Integer.parseInt(commandLine.getOptionValue("m"));
      } catch (NumberFormatException nfe) {
        System.err.println("Error: " + NAME + " maxCount is not an integer: "
            + commandLine.getOptionValue("m"));
      }
    }

    boolean success = true;
    Connection hbaseConnection = null;
    try {
      hbaseConnection = ConnectionFactory.createConnection(hbaseConf);
      success = printProcessRecordsFromHBase(hbaseConf, hbaseConnection,
          cluster, maxCount, processFileSubstring);
    } finally {
      if (hbaseConnection == null) {
        success = false;
      } else {
        hbaseConnection.close();
      }
    }

    // Return the status
    return success ? 0 : 1;
  }
916751
public int run(String[] args) throws Exception {

    Configuration hbaseConf = HBaseConfiguration.create(getConf());

    // Grab input args and allow for -Dxyz style arguments
    String[] otherArgs =
        new GenericOptionsParser(hbaseConf, args).getRemainingArgs();

    // Grab the arguments we're looking for.
    CommandLine commandLine = parseArgs(otherArgs);

    // Grab the cluster argument
    String cluster = commandLine.getOptionValue("c");
    LOG.info("cluster=" + cluster);

    // Number of parallel threads to use
    int threadCount = 1;
    if (commandLine.hasOption("t")) {
      try {
        threadCount = Integer.parseInt(commandLine.getOptionValue("t"));
      } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException(
            "Provided thread-count argument (-t) is not a number: "
                + commandLine.getOptionValue("t"),
            nfe);
      }
      if (threadCount < 1) {
        throw new IllegalArgumentException(
            "Cannot run fewer than 1 thread. Provided thread-count argument (-t): "
                + threadCount);
      }
    }
    LOG.info("threadCount=" + threadCount);

    boolean reprocess = commandLine.hasOption("r");
    LOG.info("reprocess=" + reprocess);

    // Grab the batch-size argument
    int batchSize;
    if (commandLine.hasOption("b")) {
      try {
        batchSize = Integer.parseInt(commandLine.getOptionValue("b"));
      } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException(
            "batch size option -b is is not a valid number: "
                + commandLine.getOptionValue("b"),
            nfe);
      }
      // Additional check
      if (batchSize < 1) {
        throw new IllegalArgumentException(
            "Cannot process files in batches smaller than 1. Specified batch size option -b is: "
                + commandLine.getOptionValue("b"));
      }
    } else {
      batchSize = DEFAULT_BATCH_SIZE;
    }

    // Grab the costfile argument

    String costFilePath = commandLine.getOptionValue("zf");
    LOG.info("cost properties file on hdfs=" + costFilePath);
    if (costFilePath == null)
      costFilePath = Constants.COST_PROPERTIES_HDFS_DIR;
    Path hdfsPath = new Path(costFilePath + Constants.COST_PROPERTIES_FILENAME);
    // add to distributed cache
    DistributedCache.addCacheFile(hdfsPath.toUri(), hbaseConf);

    // Grab the machine type argument
    String machineType = commandLine.getOptionValue("m");
    // set it as part of conf so that the
    // hRaven job can access it in the mapper
    hbaseConf.set(Constants.HRAVEN_MACHINE_TYPE, machineType);

    // check if re-aggregate option is forced on
    // if yes, we need to aggregate for this job inspite of
    // job having aggregation done status in raw table
    boolean reAggregateFlagValue = false;
    if (commandLine.hasOption("ra")) {
      String reaggregateFlag = commandLine.getOptionValue("ra");
      // set it as part of conf so that the
      // hRaven jobProcessor can access it in the mapper
      if (StringUtils.isNotBlank(reaggregateFlag)) {
        LOG.info(" reaggregateFlag is: " + reaggregateFlag);
        if (StringUtils.equalsIgnoreCase(reaggregateFlag,
            Boolean.TRUE.toString())) {
          reAggregateFlagValue = true;
        }
      }
    }
    LOG.info(AggregationConstants.RE_AGGREGATION_FLAG_NAME + "="
        + reAggregateFlagValue);
    hbaseConf.setBoolean(AggregationConstants.RE_AGGREGATION_FLAG_NAME,
        reAggregateFlagValue);

    // set aggregation to off by default
    boolean aggFlagValue = false;
    if (commandLine.hasOption("a")) {
      String aggregateFlag = commandLine.getOptionValue("a");
      // set it as part of conf so that the
      // hRaven jobProcessor can access it in the mapper
      if (StringUtils.isNotBlank(aggregateFlag)) {
        LOG.info(" aggregateFlag is: " + aggregateFlag);
        if (StringUtils.equalsIgnoreCase(aggregateFlag,
            Boolean.TRUE.toString())) {
          aggFlagValue = true;
        }
      }
    }
    if (reprocess) {
      // turn off aggregation if reprocessing is true
      // we don't want to inadvertently aggregate again while re-processing
      // re-aggregation needs to be a conscious setting
      aggFlagValue = false;
    }
    LOG.info(AggregationConstants.AGGREGATION_FLAG_NAME + "=" + aggFlagValue);
    hbaseConf.setBoolean(AggregationConstants.AGGREGATION_FLAG_NAME,
        aggFlagValue);

    String processFileSubstring = null;
    if (commandLine.hasOption("p")) {
      processFileSubstring = commandLine.getOptionValue("p");
    }
    LOG.info("processFileSubstring=" + processFileSubstring);

    // hbase.client.keyvalue.maxsize somehow defaults to 10 MB and we have
    // history files exceeding that. Disable limit.
    hbaseConf.setInt("hbase.client.keyvalue.maxsize", 0);

    // Shove this into the jobConf so that we can get it out on the task side.
    hbaseConf.setStrings(Constants.CLUSTER_JOB_CONF_KEY, cluster);

    boolean success = false;
    Connection hbaseConnection = null;
    try {
      hbaseConnection = ConnectionFactory.createConnection(hbaseConf);
      if (reprocess) {
        success = reProcessRecords(hbaseConf, hbaseConnection, cluster,
            batchSize, threadCount);
      } else {
        success = processRecords(hbaseConf, hbaseConnection, cluster, batchSize,
            threadCount, processFileSubstring);
      }
    } finally {
      if (hbaseConnection == null) {
        success = false;
      } else {
        hbaseConnection.close();
      }
    }

    // Return the status
    return success ? 0 : 1;
  }
896595
public static void main(String[] args) {
    org.apache.hadoop.hdfs.DnsMonitorSecurityManager.setTheManager();
    int res = -1;

    // parse arguments
    Options opts = new Options();
    CommandLine commandLine = null;
    try {
      commandLine = parseArgs(opts, args);
    } catch (IllegalArgumentException iae) {
      commandLine = null;
    }

    if (commandLine == null) {
      // invalid arguments
      err("Invalid args");
      printUsage(opts);
      System.exit(-1);
    }

    JMXGet jm = new JMXGet();

    if (commandLine.hasOption("port")) {
      jm.setPort(commandLine.getOptionValue("port")); 
    }
    if (commandLine.hasOption("service")) {
      jm.setService(commandLine.getOptionValue("service")); 
    }
    if (commandLine.hasOption("server")) {
      jm.setServer(commandLine.getOptionValue("server")); 
    }

    if (commandLine.hasOption("localVM")) {
      // from the file /tmp/hsperfdata*
      jm.setLocalVMPid(commandLine.getOptionValue("localVM"));
    }

    if (commandLine.hasOption("help")) {
      printUsage(opts);
      System.exit(0);
    }

    // rest of args
    args = commandLine.getArgs();

    try {
      jm.init();

      if (args.length == 0) {
        jm.printAllValues();
      } else {
        for (String key: args) {
          err("key = " + key);
          String val = jm.getValue(key);
          if (val!=null)
            System.out.format(JMXGet.format,key,val);
        }
      }
      res = 0;
    } catch (Exception  re) {
      re.printStackTrace();
      res = -1;
    }

    System.exit(res);
  }
977454
public void run(final String[] args) throws CLIToolException {
        PropertyConfigurator.configure(Constants.getLog4jPropertiesFile().getAbsolutePath());
        CommandLine cli = parseArgs(args);
        validateOptions(cli,args);
        go();
    }
346010
public void setPreInstallScript( final String script) {
        setPreInstallProgram(readProgram(script));
        if ( script != null) format.getHeader().createEntry( PREINSCRIPT, script);
	}
503615
public ScriptResult runScript(String scriptName, Map<String, Object> parameters) {
    Script script =
        dataService.query(SCRIPT, Script.class).eq(ScriptMetadata.NAME, scriptName).findOne();
    if (script == null) {
      throw new UnknownEntityException(SCRIPT, scriptName);
    }

    if (script.getParameters() != null) {
      for (ScriptParameter param : script.getParameters()) {
        if (!parameters.containsKey(param.getName())) {
          throw new GenerateScriptException("Missing parameter [" + param + "]");
        }
      }
    }

    Map<String, Object> scriptParameters = new HashMap<>(parameters);
    if (script.isGenerateToken()) {
      String token =
          tokenService.generateAndStoreToken(
              SecurityUtils.getCurrentUsername(), "For script " + script.getName());
      scriptParameters.put("molgenisToken", token);
    }

    ScriptRunner scriptRunner =
        scriptRunnerFactory.getScriptRunner(script.getScriptType().getName());

    FileMeta fileMeta = null;
    if (scriptRunner.hasFileOutput(script)) {
      String name = generateRandomString();
      String resultFileExtension = script.getResultFileExtension();
      if (resultFileExtension != null) {
        name += "." + script.getResultFileExtension();
      }
      File file = fileStore.getFileUnchecked(name);
      scriptParameters.put("outputFile", file.getAbsolutePath());
      fileMeta = createFileMeta(name, file);
      dataService.add(FILE_META, fileMeta);
    }
    String output = scriptRunner.runScript(script, scriptParameters);

    return new ScriptResult(fileMeta, output);
  }
1120301
@Bean
  public JobFactory<ScriptJobExecution> scriptJobFactory() {
    return new JobFactory<ScriptJobExecution>() {
      @Override
      public Job<ScriptResult> createJob(ScriptJobExecution scriptJobExecution) {
        final String name = scriptJobExecution.getName();
        final String parameterString = scriptJobExecution.getParameters();
        return progress -> {
          Map<String, Object> params = new HashMap<>();
          params.putAll(gson.fromJson(parameterString, MAP_TOKEN));
          params.put("scriptJobExecutionId", scriptJobExecution.getIdValue());
          ScriptResult scriptResult = savedScriptRunner.runScript(name, params);
          if (scriptResult.getOutputFile() != null) {
            scriptJobExecution.setResultUrl(
                format("/files/%s", scriptResult.getOutputFile().getId()));
          }
          progress.status(format("Script output:%n%s", scriptResult.getOutput()));
          return scriptResult;
        };
      }
    };
  }
617921
private void run(String[] args) {
    Options options = new Options();
    JCommander jc = new JCommander(options);
    jc.setProgramName("java -jar graphwalker.jar");
    try {
      jc.parseWithoutValidation(args);
    } catch (Exception e) {
      // ignore
    }

    try {
      setLogLevel(options);

      if (options.help) {
        options = new Options();
        jc = new JCommander(options);
        offline = new Offline();
        jc.addCommand("offline", offline);

        online = new Online();
        jc.addCommand("online", online);

        methods = new Methods();
        jc.addCommand("methods", methods);

        requirements = new Requirements();
        jc.addCommand("requirements", requirements);

        convert = new Convert();
        jc.addCommand("convert", convert);

        source = new Source();
        jc.addCommand("source", source);

        check = new Check();
        jc.addCommand("check", check);

        jc.parse(args);
        jc.usage();
        return;
      } else if (options.version) {
        System.out.println(printVersionInformation());
        return;
      }

      // Need to instantiate options again to avoid
      // ParameterException "Can only specify option --debug once."
      options = new Options();
      jc = new JCommander(options);
      offline = new Offline();
      jc.addCommand("offline", offline);

      online = new Online();
      jc.addCommand("online", online);

      methods = new Methods();
      jc.addCommand("methods", methods);

      requirements = new Requirements();
      jc.addCommand("requirements", requirements);

      convert = new Convert();
      jc.addCommand("convert", convert);

      source = new Source();
      jc.addCommand("source", source);

      check = new Check();
      jc.addCommand("check", check);

      jc.parse(args);

      // Parse for commands
      if (jc.getParsedCommand() != null) {
        if (jc.getParsedCommand().equalsIgnoreCase("offline")) {
          command = Command.OFFLINE;
          runCommandOffline();
        } else if (jc.getParsedCommand().equalsIgnoreCase("online")) {
          command = Command.ONLINE;
          runCommandOnline();
        } else if (jc.getParsedCommand().equalsIgnoreCase("methods")) {
          command = Command.METHODS;
          runCommandMethods();
        } else if (jc.getParsedCommand().equalsIgnoreCase("requirements")) {
          command = Command.REQUIREMENTS;
          runCommandRequirements();
        } else if (jc.getParsedCommand().equalsIgnoreCase("convert")) {
          command = Command.CONVERT;
          runCommandConvert();
        } else if (jc.getParsedCommand().equalsIgnoreCase("source")) {
          command = Command.SOURCE;
          runCommandSource();
        } else if (jc.getParsedCommand().equalsIgnoreCase("check")) {
          command = Command.SOURCE;
          runCommandCheck();
        }
      }

      // No commands or options were found
      else {
        throw new MissingCommandException("Missing a command. Add '--help'");
      }

    } catch (UnsupportedFileFormat | MissingCommandException e) {
      System.err.println(e.getMessage() + System.lineSeparator());
    } catch (ParameterException e) {
      System.err.println("An error occurred when running command: " + StringUtils.join(args, " "));
      System.err.println(e.getMessage() + System.lineSeparator());
      if (jc.getParsedCommand() != null) {
        jc.usage(jc.getParsedCommand());
      }
    } catch (Exception e) {
      System.err.println("An error occurred when running command: " + StringUtils.join(args, " "));
      System.err.println(e.getMessage() + System.lineSeparator());
      logger.error("An error occurred when running command: " + StringUtils.join(args, " "), e);
    }
  }