Package org.platformlayer.ops.process

Examples of org.platformlayer.ops.process.ProcessExecution


    try {
      return TimeoutPoll.poll(TimeSpan.FIVE_MINUTES, TimeSpan.TEN_SECONDS, new PollFunction<String>() {
        @Override
        public String call() throws Exception {
          try {
            ProcessExecution execution = target.executeCommand("uname -srp");
            return execution.getStdOut();
          } catch (ProcessExecutionException e) {
            log.info("Waiting for machine; got process execution error", e);
            return null;
          }
        }
View Full Code Here


  }

  @Override
  public Md5Hash getFileHash(File filePath) throws OpsException {
    Command command = Command.build("md5sum {0}", filePath);
    ProcessExecution execution = executeCommandUnchecked(command);

    if (execution.getExitCode() == 1) {
      if (execution.getStdErr().contains("No such file or directory")) {
        return null;
      }
    }

    execution.checkExitCode();
    String stdout = execution.getStdOut();

    // Format is "hash filename"
    String[] items = stdout.split(" ");
    return new Md5Hash(items[0]);
  }
View Full Code Here

    log.info("Executing command: " + command.toString());
    if (command.getEnvironment() != null) {
      String s = Joiner.on(",").join(command.getEnvironment().keys());
      log.info("Environment keys set: " + s);
    }
    ProcessExecution execution = executeCommandUnchecked(command);
    if (execution.getExitCode() != 0) {
      throw new ProcessExecutionException("Unexpected exit code from running command.  Command="
          + command.toString(), execution);
    }
    return execution;
  }
View Full Code Here

      File tempDir = new File(tempDirBase, randomDirName);
      try {
        executeCommand("mkdir {0}", tempDir);
        return tempDir;
      } catch (ProcessExecutionException e) {
        ProcessExecution execution = e.getExecution();

        if (i < maxRetries && execution != null && execution.getExitCode() == 1
            && execution.getStdErr().contains("File exists")) {
          // Loop again
        } else {
          throw new OpsException("Error creating directory", e);
        }
      }
View Full Code Here

    Command curlCommand = curlRequest.toCommand();
    curlCommand.addLiteral(">");
    curlCommand.addFile(targetPath);

    ProcessExecution execution = target.executeCommand(curlCommand);

    // CurlResult curlResult = curlRequest.parseResponse(execution);
    //
    // int httpResult = curlResult.getHttpResult();
    // switch (httpResult) {
View Full Code Here

    }

    command.addLiteral("-printf");
    command.addQuoted(format.toString());

    ProcessExecution execution;
    try {
      execution = executeCommand(command);
    } catch (ProcessExecutionException e) {
      execution = e.getExecution();
      if (execution != null && execution.getExitCode() == 1
          && execution.getStdErr().contains("No such file or directory")) {
        return null;
      }

      throw new OpsException("Error executing find command", e);
    }
    List<FilesystemInfo> filesystemInfos = Lists.newArrayList();

    String stdout = execution.getStdOut();
    for (String line : stdout.split("\n")) {
      String[] fieldValues = line.split("\t");
      if (fieldValues.length != fields.length) {
        throw new OpsException("Cannot parse line: " + line);
      }
View Full Code Here

      ByteArrayOutputStream stdoutBinary = new ByteArrayOutputStream();
      ByteArrayOutputStream stderrBinary = new ByteArrayOutputStream();

      int exitCode = sshExecute(command, stdoutBinary, stderrBinary, null, timeout);

      ProcessExecution processExecution = new ProcessExecution(command, exitCode, stdoutBinary.toByteArray(),
          stderrBinary.toByteArray());
      return processExecution;
    } catch (RuntimeSshException e) {
      throw new SshException("Unexpected SSH error", e);
    }
View Full Code Here

  }

  public CurlResult executeRequest(OpsTarget target) throws OpsException {
    Command command = toCommand();

    ProcessExecution execution = target.executeCommand(command);

    return parseResponse(execution);
  }
View Full Code Here

      String testSql = "SHOW STATUS LIKE 'uptime'";

      execute(testSql);
      return true;
    } catch (ProcessExecutionException e) {
      ProcessExecution execution = e.getExecution();
      if (execution.getExitCode() == 1 && execution.getStdErr().contains("Access denied")) {
        return false;
      }
      throw new OpsException("Unexpected error connecting to MySQL", e);
    }
  }
View Full Code Here

    // image_size="${RAW_SIZE}" < disk.raw.gz

    command.addQuoted(glanceUploadUrl);
    command.setTimeout(TimeSpan.FIFTEEN_MINUTES);

    ProcessExecution execution = target.executeCommand(command);

    String imageId;
    // String imageLocation;
    {
      // {"image": {"status": "active", "name": null, "deleted": false,
      // "container_format": null, "created_at":
      // "2011-04-10T00:15:57.563479",
      // "disk_format": null, "updated_at":
      // "2011-04-10T00:21:29.300219", "id": 8, "location":
      // "file:///var/lib/glance/images/8", "checksum":
      // "bfbd641fe10edb3ecea933303e5408ec", "is_public": false,
      // "deleted_at":
      // null, "properties":
      // {}, "size": 8577351680}}

      // {"image": {"status": "active", "name": "image-1324662647963", "deleted": false, "container_format": null,
      // "created_at": "2011-12-23T17:50:48.265346", "disk_format": "qcow2",
      // "updated_at": "2011-12-23T17:51:42.229359", "properties": {}, "min_disk": 0, "id":
      // "f41d4043-f608-ea2f-a642-e7621bec2b66", "checksum": "ffeafdc8757658b481f3b1a3c2a33c98", "owner": null,
      // "is_public": true, "deleted_at": null, "min_ram": 0, "size": 925761536}}
      try {
        JSONObject json = new JSONObject(execution.getStdOut());
        JSONObject image = json.getJSONObject("image");
        // imageLocation = image.getString("location");
        imageId = image.getString("id");
      } catch (JSONException e) {
        log.warn("Image upload returned: " + execution.getStdOut());
        throw new OpsException("Error parsing return value from image upload", e);
      }
    }

    if (tags != null) {
View Full Code Here

TOP

Related Classes of org.platformlayer.ops.process.ProcessExecution

Copyright © 2018 www.massapicom. 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.