Package org.platformlayer.ops

Examples of org.platformlayer.ops.Command$Argument


    return new ZookeeperResponse(response);
  }

  public static ZookeeperResponse sendCommand(OpsTarget target, InetSocketAddress socketAddress, String zkCommand)
      throws OpsException {
    Command command = Command.build("echo {0} | nc {1} {2}", zkCommand,
        socketAddress.getAddress().getHostAddress(), socketAddress.getPort());

    ProcessExecution execution = target.executeCommand(command);

    return new ZookeeperResponse(execution.getStdOut());
View Full Code Here


  public void handler(OpsTarget target) throws OpsException {
    // Make sure openssh-server is manually installed (i.e. not through task-ssh-server)
    target.executeCommand("apt-get install openssh-server");

    // Only for wheezy? Squeeze has a depencency of install-info -> findutils
    Command command = Command
        .build("apt-get remove --yes aptitude tasksel tasksel-data man-db manpages libxapian22 libboost-iostreams1.49.0 info ");
    target.executeCommand(command);

    // Maybe:
View Full Code Here

public class SimpleIptablesRules implements Iterable<SimpleIptablesRule> {
  List<SimpleIptablesRule> rules = Lists.newArrayList();

  public static Command buildCommand(Transport transport, IptablesChain chain) {
    Command command;
    switch (transport) {
    case Ipv4:
      command = Command.build("iptables");
      break;
    case Ipv6:
      command = Command.build("ip6tables");
      break;
    default:
      throw new IllegalStateException();
    }

    command.addLiteral("-t").addQuoted(chain.toString().toLowerCase());
    return command;
  }
View Full Code Here

    if (InetAddressUtils.isPublic(host)) {
      CurlRequest curlRequest = new CurlRequest(uri);
      curlRequest.bareRequest = true;
      CommandEnvironment commandEnvironment = httpProxies.getHttpProxyEnvironment(target, Usage.General, uri);

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

      target.executeCommand(curlCommand);
    } else {
      log.warn("Address was not public: " + host + ", doing copy via ops system");
View Full Code Here

  }

  public static SimpleIptablesRules listRules(OpsTarget target, Transport transport, IptablesChain chain)
      throws OpsException {

    Command command = buildCommand(transport, chain);
    command.addLiteral("--list-rules");

    ProcessExecution iptablesExecution = target.executeCommand(command);
    SimpleIptablesRules ret = new SimpleIptablesRules();
    for (String line : Splitter.on("\n").split(iptablesExecution.getStdOut())) {
      SimpleIptablesRule rule = new SimpleIptablesRule(line);
View Full Code Here

    String imageId = UUID.randomUUID().toString();

    final File targetImageFile = getImageFile(imageId, null);

    if (srcImageHost.equals(target)) {
      Command copyCommand = Command.build("cp", srcImageFile, targetImageFile);
      target.executeCommand(copyCommand.setTimeout(TimeSpan.TEN_MINUTES));
    } else {
      PeerToPeerCopy peerToPeerCopy = Injection.getInstance(PeerToPeerCopy.class);
      peerToPeerCopy.copy(srcImageHost, srcImageFile, target, targetImageFile);
    }
View Full Code Here

    //
    // 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

TOP

Related Classes of org.platformlayer.ops.Command$Argument

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.