예제 #1
0
  private void deployWars(Map wars) throws Exception {
    for (Iterator iter = wars.entrySet().iterator(); iter.hasNext(); ) {
      Map.Entry entry = (Entry) iter.next();

      String warName = (String) entry.getKey();
      File warFile = (File) entry.getValue();

      System.err.println("Deploying war [" + warName + "] on " + instanceDir.getName());

      List cmd = new ArrayList();
      cmd.add(getAsadminScript().getAbsolutePath());
      cmd.add("deploy");
      cmd.add("--interactive=false");
      cmd.add("--user");
      cmd.add(ADMIN_USER);
      cmd.add("--passwordfile");
      cmd.add(getPasswdFile().getAbsolutePath());
      cmd.add("--contextroot=" + warName);
      cmd.add("--port=" + adminPort);
      cmd.add(warFile.getAbsolutePath());

      Result result = Exec.execute((String[]) cmd.toArray(new String[] {}));
      if (result.getExitCode() != 0) {
        throw new RuntimeException("Deploy failed for " + warName + ": " + result);
      }
    }
  }
예제 #2
0
  public static String ps_grep_java() {
    File jps = getProgram("jps");
    if (jps.isFile()) {
      try {
        Exec.Result result = Exec.execute(new String[] {jps.getAbsolutePath(), "-mlv"});

        return result.getStdout().trim() + "\n" + result.getStderr().trim();
      } catch (Exception e) {
        e.printStackTrace();
        return "jps failure";
      }
    } else {
      return "jps not found";
    }
  }
예제 #3
0
  private void createDomain(AppServerParameters params) throws Exception {
    File asAdminScript = getAsadminScript();

    List cmd = new ArrayList();
    cmd.add(asAdminScript.getAbsolutePath());
    cmd.add("create-domain");
    cmd.add("--interactive=false");
    cmd.add("--domaindir=" + sandboxDirectory());
    cmd.add("--adminport");
    cmd.add(String.valueOf(adminPort));
    cmd.add("--adminuser");
    cmd.add(ADMIN_USER);
    cmd.add("--passwordfile");
    cmd.add(getPasswdFile().getAbsolutePath());
    cmd.add("--instanceport");
    cmd.add(String.valueOf(httpPort));
    cmd.add("--savemasterpassword=true");
    cmd.add("--domainproperties");
    cmd.add(
        "jms.port="
            + pc.chooseRandomPort()
            + ":"
            + "orb.listener.port="
            + pc.chooseRandomPort()
            + ":"
            + "http.ssl.port="
            + pc.chooseRandomPort()
            + ":"
            + "orb.ssl.port="
            + pc.chooseRandomPort()
            + ":"
            + "orb.mutualauth.port="
            + pc.chooseRandomPort()
            + ":"
            + "domain.jmxPort="
            + pc.chooseRandomPort());
    cmd.add("--savelogin=true");
    cmd.add(params.instanceName());

    Result result =
        Exec.execute(
            (String[]) cmd.toArray(new String[] {}), null, null, asAdminScript.getParentFile());

    if (result.getExitCode() != 0) {
      throw new RuntimeException(result.toString());
    }
  }
예제 #4
0
  public void stop() throws Exception {
    System.err.println("Stopping instance on port " + httpPort + "...");

    File stopScript = getInstanceFile("bin/" + getPlatformScript("stopserv"));
    Result result =
        Exec.execute(
            new String[] {stopScript.getAbsolutePath()}, null, null, stopScript.getParentFile());
    if (result.getExitCode() != 0) {
      System.err.println(result);
    }

    if (runner != null) {
      runner.join(START_STOP_TIMEOUT);
    }

    if (runner.isAlive()) {
      Banner.errorBanner("instance still running on port " + httpPort);
    } else {
      System.err.println("Stopped instance on port " + httpPort);
    }
  }
예제 #5
0
  private String[] getStartupCommand(AppServerParameters params) throws Exception {
    File startScript = getInstanceFile("bin/" + getPlatformScript("startserv"));

    Result result =
        Exec.execute(
            new String[] {startScript.getAbsolutePath(), "display"},
            null,
            null,
            startScript.getParentFile());
    if (result.getExitCode() != 0) {
      throw new RuntimeException("error executing startserv script: " + result);
    }

    String output = result.getStdout().trim();

    if (!output.startsWith("STARTOFCOMMAND|") || !output.endsWith("|ENDOFCOMMAND|")) {
      throw new RuntimeException("cannot parse output: " + output);
    }

    output = output.substring("STARTOFCOMMAND|".length());
    output = output.substring(0, output.length() - "|ENDOFCOMMAND|".length());

    List cmd = new ArrayList(Arrays.asList(output.split("\\|")));

    // add the linked java process stuff to classpath
    for (int i = 0; i < cmd.size(); i++) {
      String s = (String) cmd.get(i);

      if (s.toLowerCase().trim().equals("-classpath") || s.toLowerCase().trim().equals("-cp")) {
        // the classpath is set with java.class.path system property, check these just for good
        // measure
        throw new RuntimeException("unexpected classpath arguments in startup command " + cmd);
      }

      if (s.startsWith("-Djava.class.path=")) {
        cmd.set(
            i,
            s + File.pathSeparator + TestConfigObject.getInstance().linkedChildProcessClasspath());
        break;
      }
    }

    String mainArg = (String) cmd.remove(cmd.size() - 1);
    String mainClass = (String) cmd.remove(cmd.size() - 1);

    if (!"com.sun.enterprise.server.PELaunch".equals(mainClass)) {
      throw new RuntimeException("Unexpected main class: " + mainClass);
    }
    if (!"start".equals(mainArg)) {
      throw new RuntimeException("unexpected main argument: " + mainArg);
    }

    cmd.add(CargoLinkedChildProcess.class.getName());
    cmd.add(mainClass);
    cmd.add(String.valueOf(HeartBeatService.listenPort()));
    cmd.add(instanceDir.toString());
    cmd.add(mainArg);

    cmd.add(0, JAVA_CMD);
    return (String[]) cmd.toArray(new String[] {});
  }