Ejemplo n.º 1
0
 public static void main(String[] args) {
   DeploymentDaemon daemon = new DeploymentDaemon();
   try {
     int replicaID = Integer.parseInt(args[0]);
     daemon.open(HermesConfig.getNodeIP(replicaID), HermesConfig.getNodeDaemonPort());
     // daemon.open(HermesConfig.getNodeDaemonIP(), HermesConfig.getNodeDaemonPort());
     System.out.println("After Init server");
   } catch (IOException ex) {
     Logger.getLogger(DeploymentDaemon.class.getName())
         .log(Level.SEVERE, "DeploymentDaemon: main(): failed to open server", ex);
   }
   while (true) {
     try {
       // Loop forever, until it is killed
       Thread.sleep(10000);
     } catch (InterruptedException ex) {
       Logger.getLogger(DeploymentDaemon.class.getName())
           .log(Level.SEVERE, "HermesNodeDaemon: main(): failed to sleep", ex);
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * Bootstrap an application in this node
   *
   * @param binary Binary to launch
   * @param args Arguments to used in the launch
   * @param envElements Environment variables to be set
   * @return true, if successful, false, otherwise
   */
  public boolean boostrapApplication(String binary, String[] args, EnvElement[] envElements) {
    if (HermesConfig.DEBUG) {
      /*Logger.getLogger(DeploymentDaemon.class.getName()).
      log(Level.INFO,
      "DeploymentDaemon: boostrapApplication(): {0} {1} {2} {3} {4}",
      new Object[]{binary, args[0], args[1], args[2], args[3]});*/
      String s = "";
      for (String arg : args) {
        s += " " + arg;
      }
      Logger.getLogger(DeploymentDaemon.class.getName())
          .log(Level.INFO, "DeploymentDaemon: boostrapApplication(): " + binary + " " + s);
    }
    String[] command = null;
    if (args == null || args.length == 0) {
      command = new String[] {binary};
    } else {
      command = new String[args.length + 1];
      command[0] = binary;
      System.arraycopy(args, 0, command, 1, args.length);
    }
    final ProcessBuilder pb = new ProcessBuilder(command);
    pb.redirectErrorStream(true);
    // pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
    Logger.getLogger(DeploymentDaemon.class.getName())
        .log(
            Level.INFO,
            "DeploymentDaemon: boostrapApplication(): WorkingDir:" + HermesConfig.getWorkingDir());
    pb.directory(new File(HermesConfig.getWorkingDir()));

    Map<String, String> env = pb.environment();
    if (envElements != null) {
      for (int i = 0; i < envElements.length; i++) {
        env.put(envElements[i].getVar(), envElements[i].getValue());
      }
    }
    try {
      final Process p = pb.start();
      System.out.println("Start1");
      new Thread() {
        @Override
        public void run() {
          System.out.println("Start2");
          String s;
          BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
          try {
            while ((s = stdout.readLine()) != null) {
              System.out.println(s);
            }
          } catch (IOException ex) {
            Logger.getLogger(HermesNodeServerChannel.class.getName())
                .log(Level.SEVERE, "DeploymentDaemon: boostrapApplication(): EXIT THREAD");
          }
        }
      }.start();
      try {
        // Quirk mode
        // sleep to check if application bootstrap correctly
        Thread.sleep(QUIRK_SLEEP_TIME);
      } catch (InterruptedException ex) {
      }
      try {
        int exitValue = p.exitValue();
        if (exitValue != 0) {
          Logger.getLogger(HermesNodeServerChannel.class.getName())
              .log(
                  Level.SEVERE,
                  "DeploymentDaemon: boostrapApplication(): TERMINATED {0}",
                  new Object[] {binary});

          return false;
        }
      } catch (IllegalThreadStateException pEx) {
      }
      m_listOfProcesses.add(p);
      if (HermesConfig.DEBUG) {
        Logger.getLogger(DeploymentDaemon.class.getName())
            .log(Level.INFO, "DeploymentDaemon: boostrapApplication sucessful");
      }
      return true;
    } catch (IOException ex) {
      Logger.getLogger(DeploymentDaemon.class.getName())
          .log(
              Level.SEVERE, "DeploymentDaemon: boostrapApplication(): failed to start application");
      return false;
    }
  }