~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jdrmaa/src/com/sun/grid/drmaa/howto/Howto3_2.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
 *
 
3
 *  The Contents of this file are made available subject to the terms of
 
4
 *  the Sun Industry Standards Source License Version 1.2
 
5
 *
 
6
 *  Sun Microsystems Inc., March, 2001
 
7
 *
 
8
 *
 
9
 *  Sun Industry Standards Source License Version 1.2
 
10
 *  =================================================
 
11
 *  The contents of this file are subject to the Sun Industry Standards
 
12
 *  Source License Version 1.2 (the "License"); You may not use this file
 
13
 *  except in compliance with the License. You may obtain a copy of the
 
14
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
15
 *
 
16
 *  Software provided under this License is provided on an "AS IS" basis,
 
17
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
18
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
19
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
20
 *  See the License for the specific provisions governing your rights and
 
21
 *  obligations concerning the Software.
 
22
 *
 
23
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
24
 *
 
25
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
26
 *
 
27
 *   All Rights Reserved.
 
28
 *
 
29
 ************************************************************************/
 
30
/*___INFO__MARK_END__*/
 
31
package com.sun.grid.drmaa.howto;
 
32
 
 
33
import java.util.Collections;
 
34
import java.util.Iterator;
 
35
import java.util.List;
 
36
import java.util.Map;
 
37
import org.ggf.drmaa.DrmaaException;
 
38
import org.ggf.drmaa.JobInfo;
 
39
import org.ggf.drmaa.JobTemplate;
 
40
import org.ggf.drmaa.Session;
 
41
import org.ggf.drmaa.SessionFactory;
 
42
 
 
43
public class Howto3_2 {
 
44
   public static void main(String[] args) {
 
45
      SessionFactory factory = SessionFactory.getFactory();
 
46
      Session session = factory.getSession();
 
47
      
 
48
      try {
 
49
         session.init("");
 
50
         JobTemplate jt = session.createJobTemplate();
 
51
         jt.setRemoteCommand("sleeper.sh");
 
52
         jt.setArgs(Collections.singletonList("5"));
 
53
         
 
54
         int start = 1;
 
55
         int end  = 30;
 
56
         int step = 2;
 
57
         
 
58
         List ids = session.runBulkJobs(jt, start, end, step);
 
59
         Iterator i = ids.iterator();
 
60
         
 
61
         while (i.hasNext()) {
 
62
            System.out.println("Your job has been submitted with id " + i.next());
 
63
         }
 
64
         
 
65
         session.deleteJobTemplate(jt);
 
66
         session.synchronize(Collections.singletonList(Session.JOB_IDS_SESSION_ALL),
 
67
               Session.TIMEOUT_WAIT_FOREVER, false);
 
68
         
 
69
         for (int count = start; count < end; count += step) {
 
70
            JobInfo info = session.wait(Session.JOB_IDS_SESSION_ANY,
 
71
                  Session.TIMEOUT_WAIT_FOREVER);
 
72
            
 
73
            if (info.wasAborted()) {
 
74
               System.out.println("Job " + info.getJobId() + " never ran");
 
75
            } else if (info.hasExited()) {
 
76
               System.out.println("Job " + info.getJobId() +
 
77
                     " finished regularly with exit status " +
 
78
                     info.getExitStatus());
 
79
            } else if (info.hasSignaled()) {
 
80
               System.out.println("Job " + info.getJobId() +
 
81
                     " finished due to signal " +
 
82
                     info.getTerminatingSignal());
 
83
            } else {
 
84
               System.out.println("Job " + info.getJobId() +
 
85
                     " finished with unclear conditions");
 
86
            }
 
87
            
 
88
            System.out.println("Job Usage:");
 
89
            
 
90
            Map rmap = info.getResourceUsage();
 
91
            Iterator r = rmap.keySet().iterator();
 
92
            
 
93
            while (r.hasNext()) {
 
94
               String name = (String)r.next();
 
95
               String value = (String)rmap.get(name);
 
96
               
 
97
               System.out.println("  " + name + "=" + value);
 
98
            }
 
99
         }
 
100
         
 
101
         session.exit();
 
102
      } catch (DrmaaException e) {
 
103
         System.out.println("Error: " + e.getMessage());
 
104
      }
 
105
   }
 
106
}