List of usage examples for org.apache.commons.exec CommandLine addArgument
public CommandLine addArgument(final String argument)
From source file:com.adaptris.hpcc.DesprayFromThor.java
@Override public AdaptrisMessage request(AdaptrisMessage msg, ProduceDestination destination, long timeoutMs) throws ProduceException { try {/*from w w w . j av a2s. co m*/ File destFile = createAndTrackFile(msg); CommandLine commandLine = retrieveConnection(DfuplusConnection.class).createCommand(); commandLine.addArgument("action=despray"); commandLine.addArgument(String.format("srcname=%s", destination.getDestination(msg))); commandLine.addArgument(String.format("dstfile=%s", destFile.getCanonicalPath())); commandLine.addArgument(String.format("dstip=%s", destIpAddress())); commandLine.addArgument("overwrite=1"); commandLine.addArgument("nowait=1"); log.trace("Executing {}", commandLine); execute(commandLine); fileToMessage(destFile, msg); } catch (Exception e) { throw ExceptionHelper.wrapProduceException(e); } return msg; }
From source file:beans.DeployManagerImpl.java
@Override public WidgetInstance uninstall(ServerNode serverNode) { WidgetInstance widgetInstance = serverNode.getWidgetInstance(); String installName = widgetInstance.getInstallName(); // TODO : maybe we should verify it is installed using the rest client? File script = widgetInstance.getRecipeType() == Recipe.Type.APPLICATION ? conf.cloudify.uninstallApplicationScript : conf.cloudify.uninstallServiceScript; CommandLine cmdLine = new CommandLine(script); cmdLine.addArgument(serverNode.getPublicIP()); cmdLine.addArgument(installName);/*from w w w . j a va 2 s . c om*/ logger.info("executing command [{}]", cmdLine); execute(cmdLine, serverNode); return widgetInstance; }
From source file:com.tribuneqa.utilities.FrameworkUtilities.java
public void appiumStart() throws IOException, InterruptedException { // Start command prompt In background. CommandLine command = new CommandLine("cmd"); // Add different arguments In command line which requires to start appium server. command.addArgument("/c"); // Add different arguments In command line which requires to start appium server. command.addArgument("appium"); command.addArgument("-a"); command.addArgument("10.20.121.69"); command.addArgument("-p"); command.addArgument("8001"); command.addArgument("-U"); command.addArgument("4d0081724d5741c7"); // Execute command line arguments to start appium server. DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(1);//from ww w . jav a 2 s . co m executor.execute(command, resultHandler); Thread.sleep(15000); }
From source file:com.comcast.tvx.haproxy.HAProxyServiceController.java
@Override public int reload() { if (!new File("/etc/init.d/haproxy").exists()) { logger.info("HaProxy is not installed"); throw new IllegalArgumentException("HaProxy is not installed"); }/* w w w .ja v a2 s . co m*/ CommandLine cmdLine = new CommandLine("sudo"); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); PumpStreamHandler psh = new PumpStreamHandler(stdout); cmdLine.addArgument("service"); cmdLine.addArgument("haproxy"); cmdLine.addArgument("reload"); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 0, 1 }); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); executor.setStreamHandler(psh); int exitValue; try { exitValue = executor.execute(cmdLine); } catch (ExecuteException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } logger.info("output from running process: " + stdout.toString()); logger.info("Exit value was: " + exitValue); return exitValue; }
From source file:com.adaptris.hpcc.SprayToThor.java
@Override public void produce(AdaptrisMessage msg, ProduceDestination destination) throws ProduceException { File sourceFile = saveFile(msg, msg); try {/* www . j a v a 2 s . c o m*/ CommandLine commandLine = createSprayCommand(msg); addFormatArguments(commandLine); commandLine.addArgument(String.format("srcfile=%s", sourceFile.getCanonicalPath())); commandLine.addArgument(String.format("dstname=%s", destination.getDestination(msg))); log.trace("Executing {}", commandLine); execute(commandLine); } catch (Exception e) { throw ExceptionHelper.wrapProduceException(e); } }
From source file:eu.creatingfuture.propeller.blocklyprop.propellent.Propellent.java
public List<String> getPorts() { List<String> ports = new ArrayList<>(); try {/*from ww w. j ava 2 s . c o m*/ CommandLine cmdLine = new CommandLine("propellent/Propellent.exe"); cmdLine.addArgument("/id"); cmdLine.addArgument("/gui").addArgument("OFF"); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 451, 301 }); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { // exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); return ports; } output = outputStream.toString(); // 301 = None found // 451 = Chip found if (exitValue == 301) { return ports; } // System.out.println("output: " + output); Scanner scanner = new Scanner(output); Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?"); Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$"); while (scanner.hasNextLine()) { String portLine = scanner.nextLine(); if (chipFoundPattern.matcher(portLine).matches()) { Matcher portMatch = pattern.matcher(portLine); if (portMatch.find()) { String port = portMatch.group("comport"); ports.add(port); } } } // System.out.println("output: " + output); // System.out.println("exitValue: " + exitValue); return ports; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); return null; } }
From source file:eu.creatingfuture.propeller.webLoader.propellent.Propellent.java
public List<String> getPorts() { List<String> ports = new ArrayList<String>(); try {/*from w w w . ja v a 2s. c o m*/ CommandLine cmdLine = new CommandLine("propellent/Propellent.exe"); cmdLine.addArgument("/id"); cmdLine.addArgument("/gui").addArgument("OFF"); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 451, 301 }); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { // exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); return ports; } output = outputStream.toString(); // 301 = None found // 451 = Chip found if (exitValue == 301) { return ports; } // System.out.println("output: " + output); Scanner scanner = new Scanner(output); Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?"); Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$"); while (scanner.hasNextLine()) { String portLine = scanner.nextLine(); if (chipFoundPattern.matcher(portLine).matches()) { Matcher portMatch = pattern.matcher(portLine); if (portMatch.find()) { String port = portMatch.group("comport"); ports.add(port); } } } // System.out.println("output: " + output); // System.out.println("exitValue: " + exitValue); return ports; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); return null; } }
From source file:eu.creatingfuture.propeller.blocklyprop.propellent.Propellent.java
public boolean compile(File file) { try {/*ww w . java2 s . co m*/ Map map = new HashMap(); map.put("file", file); CommandLine cmdLine = new CommandLine("propellent/Propellent.exe"); cmdLine.addArgument("/compile"); cmdLine.addArgument("/gui").addArgument("OFF"); cmdLine.addArgument("${file}"); cmdLine.setSubstitutionMap(map); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(new int[] { 402, 101 }); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); return false; } output = outputStream.toString(); // 101 = Compile error // 402 = Compile succesfull if (exitValue == 101) { return false; } // System.out.println("output: " + output); /* Scanner scanner = new Scanner(output); Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?"); Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$"); while (scanner.hasNextLine()) { String portLine = scanner.nextLine(); if (chipFoundPattern.matcher(portLine).matches()) { Matcher portMatch = pattern.matcher(portLine); if (portMatch.find()) { // String port = portMatch.group("comport"); } } } */ // System.out.println("output: " + output); // System.out.println("exitValue: " + exitValue); return true; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); return false; } }
From source file:com.adaptris.hpcc.SprayToThor.java
void addFormatArguments(CommandLine commandLine) { if (getSprayFormat() == null) { log.warn("Use spray-format instead"); commandLine.addArgument(String.format("format=%s", getFormat().name().toLowerCase())); commandLine.addArgument(String.format("maxrecordsize=%d", maxRecordSize())); } else {/*from w w w.ja va2 s.c o m*/ getSprayFormat().addArguments(commandLine); } }
From source file:com.netflix.genie.web.tasks.node.DiskCleanupTask.java
/** * Checks the disk for jobs on this host. Deletes any job directories that are older than the desired * retention and are complete./*from ww w. j a va2 s .co m*/ */ @Override public void run() { log.info("Running disk cleanup task..."); final File[] jobDirs = this.jobsDir.listFiles(); if (jobDirs == null) { log.warn("No job dirs found. Returning."); this.numberOfDeletedJobDirs.set(0); this.numberOfDirsUnableToDelete.set(0); return; } // For each of the directories figure out if we need to delete the files or not long deletedCount = 0; long unableToDeleteCount = 0; for (final File dir : jobDirs) { if (!dir.isDirectory()) { log.info("File {} isn't a directory. Skipping.", dir.getName()); continue; } final String id = dir.getName(); try { final Job job = this.jobSearchService.getJob(id); if (job.getStatus().isActive()) { // Don't want to delete anything still going continue; } // Delete anything with a finish time before today @12 AM UTC - retention final Calendar retentionThreshold = TaskUtils.getMidnightUTC(); TaskUtils.subtractDaysFromDate(retentionThreshold, this.properties.getRetention()); final Optional<Date> finished = job.getFinished(); if (finished.isPresent() && finished.get().before(retentionThreshold.getTime())) { log.info("Attempting to delete job directory for job {}", id); if (this.runAsUser) { final CommandLine commandLine = new CommandLine("sudo"); commandLine.addArgument("rm"); commandLine.addArgument("-rf"); commandLine.addArgument(dir.getAbsolutePath()); this.processExecutor.execute(commandLine); } else { // Save forking a process ourselves if we don't have to FileUtils.deleteDirectory(dir); } deletedCount++; log.info("Successfully deleted job directory for job {}", id); } } catch (final GenieException ge) { log.error("Unable to get job {}. Continuing.", id, ge); this.unableToGetJobCounter.increment(); unableToDeleteCount++; } catch (final IOException ioe) { log.error("Unable to delete job directory for job with id: {}", id, ioe); this.unableToDeleteJobDirCounter.increment(); unableToDeleteCount++; } } this.numberOfDeletedJobDirs.set(deletedCount); this.numberOfDirsUnableToDelete.set(unableToDeleteCount); }