예제 #1
0
 public DomainLifecycleUtil(final JBossAsManagedConfiguration configuration) throws IOException {
   this(configuration, DomainControllerClientConfig.create());
 }
예제 #2
0
  public void start() {
    try {
      configuration.validate();

      final String address =
          NetworkUtils.formatPossibleIpv6Address(
              configuration.getHostControllerManagementAddress());
      final int port = configuration.getHostControllerManagementPort();
      final URI connectionURI = new URI("remote://" + address + ":" + port);
      // Create the connection - this will try to connect on the first request
      connection = clientConfiguration.createConnection(connectionURI, getCallbackHandler());

      String jbossHomeDir = configuration.getJbossHome();

      final String additionalJavaOpts = System.getProperty("jboss.options");

      File modulesJar = new File(jbossHomeDir + "/jboss-modules.jar");
      if (modulesJar.exists() == false)
        throw new IllegalStateException("Cannot find: " + modulesJar);

      String javaHome = configuration.getJavaHome();
      String java = (javaHome != null) ? javaHome + "/bin/java" : "java";

      File domainDir =
          configuration.getDomainDirectory() != null
              ? new File(configuration.getDomainDirectory())
              : new File(new File(jbossHomeDir), "domain");
      String domainPath = domainDir.getAbsolutePath();

      final String modulePath;
      if (configuration.getModulePath() != null && !configuration.getModulePath().isEmpty()) {
        modulePath = configuration.getModulePath();
      } else {
        modulePath = jbossHomeDir + "/modules";
      }

      // No point backing up the file in a test scenario, just write what we need.
      File usersFile = new File(domainPath + "/configuration/mgmt-users.properties");
      FileOutputStream fos = new FileOutputStream(usersFile);
      PrintWriter pw = new PrintWriter(fos);
      pw.println(
          "slave="
              + new UsernamePasswordHashUtil()
                  .generateHashedHexURP(
                      "slave", "ManagementRealm", "slave_user_password".toCharArray()));
      pw.close();
      fos.close();

      List<String> cmd = new ArrayList<String>();
      cmd.add(java);
      if (additionalJavaOpts != null) {
        for (String opt : additionalJavaOpts.split("\\s+")) {
          cmd.add(opt);
        }
      }
      TestSuiteEnvironment.getIpv6Args(cmd);
      cmd.add("-Djboss.home.dir=" + jbossHomeDir);
      cmd.add("-Dorg.jboss.boot.log.file=" + domainPath + "/log/process-controller.log");
      cmd.add(
          "-Dlogging.configuration=file:"
              + jbossHomeDir
              + "/domain/configuration/logging.properties");
      cmd.add("-jar");
      cmd.add(modulesJar.getAbsolutePath());
      cmd.add("-mp");
      cmd.add(modulePath);
      // cmd.add("-jaxpmodule");
      // cmd.add("javax.xml.jaxp-provider");
      cmd.add("org.jboss.as.process-controller");
      cmd.add("-jboss-home");
      cmd.add(jbossHomeDir);
      cmd.add("-jvm");
      cmd.add(java);
      cmd.add("--");
      cmd.add("-Dorg.jboss.boot.log.file=" + domainPath + "/log/host-controller.log");
      cmd.add(
          "-Dlogging.configuration=file:"
              + jbossHomeDir
              + "/domain/configuration/logging.properties");
      TestSuiteEnvironment.getIpv6Args(cmd);
      if (additionalJavaOpts != null) {
        for (String opt : additionalJavaOpts.split("\\s+")) {
          cmd.add(opt);
        }
      }
      cmd.add("--");
      cmd.add("-default-jvm");
      cmd.add(java);
      if (configuration.getHostCommandLineProperties() != null) {
        for (String opt : configuration.getHostCommandLineProperties().split("\\s+")) {
          cmd.add(opt);
        }
      }

      String domainDirectory = configuration.getDomainDirectory();
      if (domainDirectory != null) {
        cmd.add("-Djboss.domain.base.dir=" + domainDirectory);
      } else {
        domainDirectory = domainPath;
      }
      if (configuration.getDomainConfigFile() != null) {
        String name =
            copyConfigFile(
                new File(configuration.getDomainConfigFile()),
                new File(domainDirectory, "configuration"));
        cmd.add("-domain-config");
        cmd.add(name);
      }
      if (configuration.getHostConfigFile() != null) {
        String name =
            copyConfigFile(
                new File(configuration.getHostConfigFile()),
                new File(domainDirectory, "configuration"));
        cmd.add("-host-config");
        cmd.add(name);
      }
      if (configuration.getHostControllerManagementAddress() != null) {
        cmd.add("--interprocess-hc-address");
        cmd.add(configuration.getHostControllerManagementAddress());
        cmd.add("--pc-address");
        cmd.add(configuration.getHostControllerManagementAddress());
      }
      // the process working dir
      final String workingDir = configuration.getDomainDirectory();

      // Start the process
      final ProcessWrapper wrapper =
          new ProcessWrapper(
              configuration.getHostName(), cmd, Collections.<String, String>emptyMap(), workingDir);
      wrapper.start();
      process = wrapper;

      // Wait for the servers to be started
      boolean serversAvailable = false;
      long start = System.currentTimeMillis();
      long deadline = start + configuration.getStartupTimeoutInSeconds() * 1000;
      // Wait a while before starting to check for the servers
      TimeUnit.SECONDS.sleep(2);
      while (serversAvailable == false) {
        long remaining = deadline - System.currentTimeMillis();
        if (remaining <= 0) {
          break;
        }
        if (!serversAvailable) {
          TimeUnit.MILLISECONDS.sleep(250);
        }
        serversAvailable = areServersStarted();
      }

      if (!serversAvailable) {
        throw new TimeoutException(
            String.format(
                "Managed servers were not started within [%d] seconds",
                configuration.getStartupTimeoutInSeconds()));
      }

      log.info("All servers started in " + (System.currentTimeMillis() - start) + " ms");
    } catch (Exception e) {
      throw new RuntimeException("Could not start container", e);
    }
  }