Examples of ProcessExecution


Examples of io.fathom.auto.processes.ProcessExecution

    public static boolean validate(File configFile) throws IOException {
        log.info("Doing haproxy validate");

        ProcessBuilder pb = new ProcessBuilder(HAPROXY_CMD.getAbsolutePath(), "-c", "-f", configFile.getAbsolutePath());

        ProcessExecution execution = Processes.run(pb, TimeSpan.seconds(10));
        if (!execution.didExit()) {
            log.warn("Timeout while validating haproxy config.");
        } else {
            int exitCode = execution.getExitCode();
            if (exitCode == 0) {
                log.info("Validated config file");
                return true;
            } else {
                log.warn("Error validating haproxy config.  Exit code {}", exitCode);

                String config = Files.toString(configFile, Charsets.UTF_8);
                log.warn("Bad haproxy config: {}", config);
            }
        }

        log.warn("stdout: {}", execution.getStdout());
        log.warn("stderr: {}", execution.getStderr());

        return false;
    }
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

    if (!Strings.isNullOrEmpty(filter)) {
      command.addQuoted(filter);
    }

    ProcessExecution processExecution = target.executeCommand(command);

    return LdifRecord.parse(processExecution.getStdOut());
  }
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

          drive.boot = true;
          drive.format = "raw";
          drive.media = "disk";

          OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
          ProcessExecution fileCommand;
          try {
            fileCommand = target.executeCommand(Command.build("file --brief {0}", getImagePath()));
          } catch (OpsException e) {
            throw new IllegalStateException("Error querying file type", e);
          }
          String fileStdout = fileCommand.getStdOut();
          if (fileStdout.contains("QCOW Image")) {
            drive.format = "qcow2";
          }

          drives.add(drive);
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

      boolean found = false;
      try {
        target.executeCommand(findCommand);
        found = true;
      } catch (ProcessExecutionException e) {
        ProcessExecution execution = e.getExecution();
        if (execution.getExitCode() == 1 && execution.getStdErr().contains("Device not found")) {
          found = false;
        } else {
          throw new OpsException("Error checking for interface", e);
        }
      }

      if (!found) {
        // This is actually idempotent, but I think it's scary to rely on it being so
        Command command = Command.build("/usr/sbin/tunctl -t {0}", interfaceName);
        target.executeCommand(command);
      }

      {
        // TODO: Safe to re-run?
        Command command = Command.build("ifconfig {0} up", interfaceName);
        target.executeCommand(command);
      }

      if (bridgeName != null) {
        // TODO: Safe to re-run?

        Command command = Command.build("brctl addif {0} {1}", bridgeName.get(), interfaceName);
        try {
          target.executeCommand(command);
        } catch (ProcessExecutionException e) {
          ProcessExecution execution = e.getExecution();
          if (execution.getExitCode() == 1 && execution.getStdErr().contains("already a member of a bridge")) {
            // OK
            // TODO: Check that the bridge is bridgeName
          } else {
            throw new OpsException("Error attaching interface to bridge", e);
          }
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

    void startedProcess(OutputStream processStdIn) throws IOException;
  }

  public ProcessExecution sshExecute(String command, TimeSpan timeout) throws SshException, IOException,
      InterruptedException {
    ProcessExecution execution = sshExecute0(command, timeout);

    return execution;
  }
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

    }
  }

  private List<String> listDatabases(OpsTarget target) throws OpsException {
    Command listDatabases = Command.build("su postgres -c \"psql -A -t -c 'select datname from pg_database'\"");
    ProcessExecution listDatabasesExecution = target.executeCommand(listDatabases);
    List<String> databases = Lists.newArrayList();
    for (String database : Splitter.on('\n').split(listDatabasesExecution.getStdOut())) {
      database = database.trim();
      if (database.isEmpty()) {
        continue;
      }
      databases.add(database);
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

    curlRequest.bodyFromStdin = true;

    Command curlCommand = curlRequest.toCommand();
    Command pipedCommand = dataSourceCommand.pipeTo(curlCommand);

    ProcessExecution execution = request.target.executeCommand(pipedCommand);

    CurlResult curlResult = curlRequest.parseResponse(execution);

    int httpResult = curlResult.getHttpResult();
    switch (httpResult) {
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

  public List<String> getInstalledPackageInfo(OpsTarget target) throws OpsException {
    AptInfoCache cached = getCache(target);

    if (cached.installedPackages == null) {
      Command command = Command.build("/usr/bin/dpkg --get-selections");
      ProcessExecution execution = target.executeCommand(command);

      final List<String> packages = Lists.newArrayList();
      for (String line : Splitter.on("\n").split(execution.getStdOut())) {
        line = line.trim();
        if (line.isEmpty()) {
          continue;
        }
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

  // server.simpleRun(command, new TimeSpan("15m"));
  // }

  public List<String> findOutOfDatePackages(OpsTarget target) throws OpsException {
    Command command = Command.build("apt-get -q -q --simulate dist-upgrade");
    ProcessExecution execution = target.executeCommand(command);

    final List<String> packages = Lists.newArrayList();
    for (String line : Splitter.on("\n").split(execution.getStdOut())) {
      line = line.trim();
      if (line.isEmpty()) {
        continue;
      }
View Full Code Here

Examples of org.platformlayer.ops.process.ProcessExecution

    for (int attempt = 0; attempt < 2; attempt++) {
      try {
        target.executeCommand(command);
      } catch (ProcessExecutionException e) {
        if (attempt == 0) {
          ProcessExecution execution = e.getExecution();
          if (execution != null) {
            String stdErr = execution.getStdErr();
            // Stderr=E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the
            // problem.
            if (stdErr.contains("dpkg --configure -a")) {
              log.warn("Detected that dpkg --configure -a is needed");
              doDpkgConfigure(target);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.