Package org.platformlayer.ops

Examples of org.platformlayer.ops.Command


  public void setMainClass(String mainClass) {
    this.mainClass = mainClass;
  }

  public Command get() {
    Command command = Command.build("java");
    command.addLiteral("-server");

    for (Map.Entry<String, String> define : defines.entrySet()) {
      command.addLiteral("-D" + define.getKey() + "=" + define.getValue());
    }

    StringBuilder cp = new StringBuilder();
    for (ClasspathEntry entry : classpath) {
      if (cp.length() != 0) {
        cp.append(":");
      }
      String s = entry.path.getAbsolutePath();
      if (entry.wildcard) {
        // TODO: Adding * is gross
        s += "/*";
      }
      cp.append(s);
    }

    // TODO: This is not nice either
    if (cp.length() == 0) {
      cp.append(".");
    } else {
      cp.append(":.");
    }

    command.addLiteral("-cp").addQuoted(cp.toString());

    if (jar != null) {
      command.addLiteral("-jar").addFile(jar);
    } else {
      command.addQuoted(mainClass);
    }

    for (Argument argument : arguments) {
      command.addArgument(argument);
    }

    return command;
  }
View Full Code Here


  }

  @Override
  public void configureAddRule(OpsTarget target, FirewallRecord add) throws OpsException {
    // OpsServer server = smartGetServer(true);
    Command command = IpTablesManager.buildCommandAddFirewallRule(target, add);

    String fileName = Sanitizer.forFileName().clean(add.buildKey());

    File scriptDirectory = new File("/etc/iptables/eth0");
    File transportDirectory;
    switch (add.getTransport()) {
    case Ipv4:
      transportDirectory = new File(scriptDirectory, "inet");
      break;
    case Ipv6:
      transportDirectory = new File(scriptDirectory, "inet6");
      break;
    default:
      throw new IllegalStateException();
    }
    File scriptFile = new File(transportDirectory, fileName);

    ScriptBuilder sb = new ScriptBuilder();
    sb.add(command);

    String script = sb.toString();

    String existing = target.readTextFile(scriptFile);

    boolean shouldUpload = true;
    if (existing != null) {
      if (Objects.equal(existing, script)) {
        shouldUpload = false;
      } else {
        // TODO: Put a UUID in there, check the UUID is the same??
        throw new OpsException("Script has changed: " + scriptFile);
      }
    }

    if (shouldUpload) {
      target.mkdir(transportDirectory);

      FileUpload upload = FileUpload.build(script);
      upload.path = scriptFile;
      upload.mode = "0755";
      target.doUpload(upload);
    }

    Command executeScript = Command.build("{0}", scriptFile);
    target.executeCommand(executeScript);

    // getCurrentFirewallState(operation).state.add(add);
  }
View Full Code Here

        sshKey = target.readTextFile(sshPublicKeyPath);
        if (sshKey == null) {
          // su -c "ssh-keygen -q -f /var/lib/jenkins/.ssh/id_rsa -N ''" jenkins

          Command keygenCommand = Command.build("su");
          keygenCommand.addLiteral("-c").addQuoted("ssh-keygen -q -f /var/lib/jenkins/.ssh/id_rsa -N ''");
          keygenCommand.addLiteral("jenkins");

          target.executeCommand(keygenCommand);

          sshKey = target.readTextFile(sshPublicKeyPath);
        }
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.