Package org.platformlayer.ops

Examples of org.platformlayer.ops.Command


    //
    // Command copy = Command.build("cp {0} {1}", fileOnTarget, destinationPath);
    // target.executeCommand(copy);

    if (destination.isSameMachine(target)) {
      Command copyCommand = Command.build("cp {0} {1}", imageFile, destinationPath);
      destination.executeCommand(copyCommand.setTimeout(TimeSpan.FIVE_MINUTES));
    } else {
      PeerToPeerCopy peerToPeerCopy = Injection.getInstance(PeerToPeerCopy.class);
      peerToPeerCopy.copy(target, imageFile, destination, destinationPath);

      // throw new OpsException("SCPing images between machines not yet implemented");
View Full Code Here


      String archiveFileName = archiveFile.getName();

      if (archiveFileName.endsWith(".zip")) {
        // -u = update, for (something close to) idempotency
        // -o = overwrite (no prompt)
        Command unzipCommand = Command.build("unzip -u -o {0} -d {1}", archiveFile, extractPath);
        target.executeCommand(unzipCommand.setTimeout(TimeSpan.FIVE_MINUTES));
      } else if (archiveFileName.endsWith(".tgz") || archiveFileName.endsWith(".tar.gz")) {
        Command unzipCommand = Command.build("cd {0}; tar zxf {1}", extractPath, archiveFile);
        target.executeCommand(unzipCommand.setTimeout(TimeSpan.FIVE_MINUTES));
      } else {
        throw new UnsupportedOperationException();
      }
    }
  }
View Full Code Here

        } else {
          sshSrc += InetAddresses.toAddrString(srcHost);
        }
        sshSrc += ":" + srcFile.getAbsolutePath();

        Command pullCommand = Command.build("scp -o StrictHostKeyChecking=no {0} {1}", sshSrc, tempDest);

        pullCommand.setKeyPair(srcSshOpsTarget.getKeyPair());

        dest.executeCommand(pullCommand.setTimeout(TimeSpan.TEN_MINUTES));

        Md5Hash targetHash = dest.getFileHash(tempDest);
        Md5Hash srcHash = src.getFileHash(srcFile);

        if (!Objects.equal(srcHash, targetHash)) {
View Full Code Here

            // TODO: Secure this better (using host address is probably sufficient, but then we need a full
            // network map to know which IP to use)
            // Command sendCommand = Command.build("socat -u OPEN:{0},rdonly TCP4-LISTEN:{1},range={2}",
            // srcImageFile, port, targetAddress.getHostAddress() + "/32");
            Command pushCommand = Command.build("socat -u OPEN:{0},rdonly {1}", srcFile,
                toSocatPush(channel.dest, listenPort));
            return src.executeCommand(pushCommand.setTimeout(TimeSpan.TEN_MINUTES));
          }
        };

        Callable<ProcessExecution> listenFile = new Callable<ProcessExecution>() {
          @Override
          public ProcessExecution call() throws Exception {
            // TODO: This is actually _really_ problematic because pkill kills proceses in guests also...
            // TODO: Check no concurrent socats?? Move to a better system??
            Command killExistingSocats = Command.build("pkill socat || true");
            dest.executeCommand(killExistingSocats);

            try {
              Command listenCommand = Command.build("socat -u {0} CREATE:{1}",
                  toSocatListen(channel.src, listenPort), tempDest);
              return dest.executeCommand(listenCommand.setTimeout(TimeSpan.TEN_MINUTES));
            } catch (ProcessExecutionException e) {
              log.warn("Error running listen process for P2P copy: " + channel, e);
              throw new OpsException("Error running listen process", e);
            }
          }
View Full Code Here

    return new InetAddressPair(srcAddress, targetAddress);
  }

  private Inet6Address findIpv6(OpsTarget target) throws OpsException {
    Command command = Command.build("cat /proc/net/if_inet6");
    ProcessExecution execution = target.executeCommand(command);
    String inet6 = execution.getStdOut();

    // This didn't work for some reason (??)
    // String inet6 = target.readTextFile(new File("/proc/net/if_inet6"));
View Full Code Here

  public void add(Command command) {
    commands.add(command.buildCommandString());
  }

  public void add(String literal, Object... args) {
    Command command = Command.build(literal, args);
    add(command);
  }
View Full Code Here

      CurlRequest curlRequest = new CurlRequest(url);
      curlRequest.bareRequest = true;

      CommandEnvironment commandEnvironment = httpProxies.getHttpProxyEnvironment(target, Usage.General, url);

      Command curlCommand = curlRequest.toCommand();
      curlCommand.addLiteral(">");
      curlCommand.addFile(remoteFilePath);
      curlCommand.setEnvironment(commandEnvironment);
      curlCommand.setTimeout(TimeSpan.FIVE_MINUTES);

      // TODO: Can we cache into CAS instead??
      log.info("Not found in CAS system; downloading directly: " + url);
      target.executeCommand(curlCommand);
    } else {
View Full Code Here

  @Override
  protected void doUpdateAction(OpsTarget target) throws OpsException {
    super.doUpdateAction(target);

    Command executeScript = Command.build("{0}", getFilePath());
    target.executeCommand(executeScript);
  }
View Full Code Here

  @Override
  protected void doDeleteAction(OpsTarget target) throws OpsException {
    super.doDeleteAction(target);

    Command removeRule = buildIptablesDeleteCommand();
    target.executeCommand(removeRule);
  }
View Full Code Here

    target.executeCommand(removeRule);
  }

  @Override
  protected byte[] getContentsBytes() throws OpsException {
    Command command = buildIptablesAddCommand();

    ScriptBuilder sb = new ScriptBuilder();
    sb.addMetadata("key", ruleKey);
    sb.add(command);
View Full Code Here

TOP

Related Classes of org.platformlayer.ops.Command

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.