Example usage for org.apache.commons.exec CommandLine getArguments

List of usage examples for org.apache.commons.exec CommandLine getArguments

Introduction

In this page you can find the example usage for org.apache.commons.exec CommandLine getArguments.

Prototype

public String[] getArguments() 

Source Link

Document

Returns the expanded and quoted command line arguments.

Usage

From source file:info.pancancer.arch3.containerProvisioner.ContainerProvisionerThreads.java

/**
 * run the reaper//  w w w.j  a va 2 s .  c o  m
 *
 * @param settings
 * @param ipAddress
 *            specify an ip address (otherwise cleanup only failed deployments)
 * @throws JsonIOException
 * @throws IOException
 */
private static void runReaper(HierarchicalINIConfiguration settings, String ipAddress, String vmName)
        throws IOException {
    String param = settings.getString(Constants.PROVISION_YOUXIA_REAPER);
    CommandLine parse = CommandLine.parse("dummy " + (param == null ? "" : param));
    List<String> arguments = new ArrayList<>();
    arguments.addAll(Arrays.asList(parse.getArguments()));

    arguments.add("--kill-list");
    // create a json file with the one targetted ip address
    Gson gson = new Gson();
    // we can't use the full set of database records because unlike Amazon, OpenStack reuses private ip addresses (very quickly too)
    // String[] successfulVMAddresses = db.getSuccessfulVMAddresses();
    String[] successfulVMAddresses = new String[] {};
    if (ipAddress != null) {
        successfulVMAddresses = new String[] { ipAddress, vmName };
    }
    LOG.info("Kill list contains: " + Arrays.asList(successfulVMAddresses));
    Path createTempFile = Files.createTempFile("target", "json");
    try (BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(createTempFile.toFile()), StandardCharsets.UTF_8))) {
        gson.toJson(successfulVMAddresses, bw);
    }
    arguments.add(createTempFile.toAbsolutePath().toString());

    String[] toArray = arguments.toArray(new String[arguments.size()]);
    LOG.info("Running youxia reaper with following parameters:" + Arrays.toString(toArray));
    // need to make sure reaper and deployer do not overlap

    try {
        Reaper.main(toArray);
    } catch (Exception e) {
        LOG.error("Youxia reaper threw the following exception", e);
    }
}

From source file:com.adaptris.hpcc.DfuPlusConnectionTest.java

@Test
public void testSourceIp() throws Exception {

    DfuplusConnection conn = new DfuplusConnection();
    conn.setDfuplusCommand("/bin/dfuplus");
    conn.setSourceIp("1.2.3.4");
    conn.setServer("2.3.4.5");

    CommandLine cmdLine = new CommandLine("/bin/dfuplus");
    CommandLine cmd = conn.addArguments(cmdLine);
    assertEquals("server=2.3.4.5", cmd.getArguments()[0]);
    assertEquals("srcip=1.2.3.4", cmd.getArguments()[1]);
}

From source file:com.adaptris.hpcc.SprayToThorTest.java

@Test
public void testCSVFormat() throws Exception {
    SprayToThor sprayToThor = new SprayToThor();
    sprayToThor.setSprayFormat(new CSVSprayFormat());
    CommandLine cmdLine = new CommandLine("/bin/dfuplus");
    sprayToThor.addFormatArguments(cmdLine);
    assertEquals(1, cmdLine.getArguments().length);
    assertEquals("format=csv", cmdLine.getArguments()[0]);
}

From source file:com.adaptris.hpcc.SprayToThorTest.java

@Test
public void testLegacyCsvFormat() throws Exception {
    SprayToThor sprayToThor = new SprayToThor();
    sprayToThor.setFormat(SprayToThor.FORMAT.CSV);
    CommandLine cmdLine = new CommandLine("/bin/dfuplus");
    sprayToThor.addFormatArguments(cmdLine);
    assertEquals(2, cmdLine.getArguments().length);
    assertEquals("format=csv", cmdLine.getArguments()[0]);
    assertEquals("maxrecordsize=8192", cmdLine.getArguments()[1]);
}

From source file:com.adaptris.hpcc.SprayToThorTest.java

@Test
public void testFixed() throws Exception {
    SprayToThor sprayToThor = new SprayToThor();
    sprayToThor.setSprayFormat(new FixedSprayFormat(125));
    CommandLine cmdLine = new CommandLine("/bin/dfuplus");
    sprayToThor.addFormatArguments(cmdLine);
    assertEquals(2, cmdLine.getArguments().length);
    assertEquals("format=fixed", cmdLine.getArguments()[0]);
    assertEquals("recordsize=125", cmdLine.getArguments()[1]);
}

From source file:com.adaptris.hpcc.SprayToThorTest.java

@Test
public void testLegacyCsvFormatMaxRecordSize() throws Exception {
    SprayToThor sprayToThor = new SprayToThor();
    sprayToThor.setFormat(SprayToThor.FORMAT.CSV);
    sprayToThor.setMaxRecordSize(214);/*w  w  w  . ja  va2  s  .  co m*/
    CommandLine cmdLine = new CommandLine("/bin/dfuplus");
    sprayToThor.addFormatArguments(cmdLine);
    assertEquals(2, cmdLine.getArguments().length);
    assertEquals("format=csv", cmdLine.getArguments()[0]);
    assertEquals("maxrecordsize=214", cmdLine.getArguments()[1]);
}

From source file:com.adaptris.hpcc.SprayToThorTest.java

/**
 * Technically this won't work with dfuplus as it doesn't set <code>recordsize</code>.
 * @throws Exception/*from   w ww .j  a  v  a  2 s.co  m*/
 */
@Test
public void testLegacyFixedFormat() throws Exception {
    SprayToThor sprayToThor = new SprayToThor();
    sprayToThor.setFormat(SprayToThor.FORMAT.FIXED);
    CommandLine cmdLine = new CommandLine("/bin/dfuplus");
    sprayToThor.addFormatArguments(cmdLine);
    assertEquals(2, cmdLine.getArguments().length);
    assertEquals("format=fixed", cmdLine.getArguments()[0]);
    assertEquals("maxrecordsize=8192", cmdLine.getArguments()[1]);
}

From source file:com.adaptris.hpcc.SprayToThorTest.java

/**
 * Technically this won't work with dfuplus as it doesn't set <code>recordsize</code>.
 * @throws Exception//  www.java2 s  .  c  o m
 */
@Test
public void testLegacyFixedFormatMaxRecordSize() throws Exception {
    SprayToThor sprayToThor = new SprayToThor();
    sprayToThor.setFormat(SprayToThor.FORMAT.FIXED);
    sprayToThor.setMaxRecordSize(214);
    CommandLine cmdLine = new CommandLine("/bin/dfuplus");
    sprayToThor.addFormatArguments(cmdLine);
    assertEquals(2, cmdLine.getArguments().length);
    assertEquals("format=fixed", cmdLine.getArguments()[0]);
    assertEquals("maxrecordsize=214", cmdLine.getArguments()[1]);
}

From source file:com.adaptris.hpcc.SprayToThorTest.java

@Test
public void testCSVFormatMaxRecordSize() throws Exception {
    SprayToThor sprayToThor = new SprayToThor();
    CSVSprayFormat sprayFormat = new CSVSprayFormat();
    sprayFormat.setMaxRecordSize(214);//from   ww  w . j a  va2s. co m
    sprayToThor.setSprayFormat(sprayFormat);
    CommandLine cmdLine = new CommandLine("/bin/dfuplus");
    sprayToThor.addFormatArguments(cmdLine);
    assertEquals(2, cmdLine.getArguments().length);
    assertEquals("format=csv", cmdLine.getArguments()[0]);
    assertEquals("maxrecordsize=214", cmdLine.getArguments()[1]);
}

From source file:com.dangdang.ddframe.job.cloud.scheduler.mesos.TaskLaunchProcessor.java

private Protos.CommandInfo buildCommand(final Protos.CommandInfo.URI uri, final String bootstrapScript,
        final ShardingContexts shardingContexts, final boolean useDefaultExecutor) {
    Protos.CommandInfo.Builder result = Protos.CommandInfo.newBuilder().addUris(uri).setShell(true);
    if (useDefaultExecutor) {
        CommandLine commandLine = CommandLine.parse(bootstrapScript);
        commandLine.addArgument(GsonFactory.getGson().toJson(shardingContexts), false);
        result.setValue(Joiner.on(" ").join(commandLine.getExecutable(),
                Joiner.on(" ").join(commandLine.getArguments())));
    } else {/*  w w  w . j  a v a2s  .c  o m*/
        result.setValue(bootstrapScript);
    }
    return result.build();
}