Exemplo n.º 1
0
  public static void main(String[] args) {
    SessionFactory factory = SessionFactory.getFactory();
    Session session = factory.getSession();

    try {
      session.init("");
      JobTemplate jt = session.createJobTemplate();
      jt.setRemoteCommand("sleeper.sh");
      jt.setArgs(Collections.singletonList("5"));

      java.util.List ids = session.runBulkJobs(jt, 1, 30, 2);
      java.util.Iterator i = ids.iterator();

      while (i.hasNext()) {
        System.out.println("Your job has been submitted with id " + i.next());
      }

      session.deleteJobTemplate(jt);
      session.exit();
    } catch (DrmaaException e) {
      System.out.println("Error: " + e.getMessage());
    }
  }
Exemplo n.º 2
0
  public static void master(int numJobs) {
    SessionFactory factory = SessionFactory.getFactory();
    Session session = factory.getSession();
    try {
      session.init("");
      JobTemplate jt = session.createJobTemplate();

      jt.setRemoteCommand("java");
      String home = java.lang.System.getProperty("user.dir");
      jt.setWorkingDirectory(home);
      List<String> jobIds = Lists.newArrayList();
      for (int i = 0; i < numJobs; i++) {
        jt.setErrorPath(":" + home + "/error" + i + ".txt");
        jt.setOutputPath(":" + home + "/out" + i + ".txt");
        jt.setArgs(
            Lists.newArrayList(
                "-Djava.library.path=/opt/uge816/lib/lx-amd64/:/opt/ibm/ILOG/CPLEX_Studio125/cplex/bin/x86-64_sles10_4.1/",
                "-jar",
                home + "/drmaaTest.jar",
                "worker",
                Integer.toString(i)));
        String id = session.runJob(jt);
        System.out.println("Your job has been submitted with id " + id);
      }

      session.deleteJobTemplate(jt);
      session.synchronize(jobIds, Session.TIMEOUT_WAIT_FOREVER, true);
      System.out.println("All jobs finished!");
      session.exit();
      List<String> answers = Lists.newArrayList();
      for (int i = 0; i < numJobs; i++) {
        String ans = "error";
        String jobName = "job" + i + ".txt";
        File file = new File(jobName);
        long msToWait = 2000;
        while (!file.exists()) {
          System.out.println(
              "waiting for file system to show " + jobName + ".  Sleeping " + msToWait + "ms");
          try {
            Thread.sleep(msToWait);
          } catch (InterruptedException e) {
          }
          msToWait = 2 * msToWait;
        }
        if (file.exists()) {
          try {
            BufferedReader reader = new BufferedReader(new FileReader(jobName));
            String firstLine = reader.readLine();
            if (firstLine != null) {
              ans = firstLine;
            }
            reader.close();
          } catch (IOException e) {
            ans = "I/O error";
          }
        }
        answers.add(ans);
      }
      System.out.println("Answers: " + answers);
    } catch (DrmaaException e) {
      System.out.println("Error: " + e.getMessage());
      throw new RuntimeException(e);
    }
  }