View Javadoc

1   package fr.in2p3.jsaga.adaptor.job;
2   
3   import fr.in2p3.jsaga.adaptor.job.monitor.JobStatus;
4   import fr.in2p3.jsaga.adaptor.job.monitor.QueryIndividualJob;
5   import org.ogf.saga.error.NoSuccessException;
6   import org.ogf.saga.error.TimeoutException;
7   
8   import java.io.*;
9   
10  /* ***************************************************
11  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
12  * ***             http://cc.in2p3.fr/             ***
13  * ***************************************************
14  * File:   EmulatorJobMonitorAdaptor
15  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
16  * Date:   27 oct. 2008
17  * ***************************************************
18  * Description:                                      */
19  /**
20   *
21   */
22  public class EmulatorJobMonitorAdaptor extends EmulatorJobAdaptorAbstract implements QueryIndividualJob {
23      public int getDefaultPort() {return 5678;}
24  
25      public JobStatus getStatus(String nativeJobId) throws TimeoutException, NoSuccessException {
26          File job = super.getJob(nativeJobId);
27          if (job.exists()) {
28              long endTime;
29              try {
30                  // read file
31                  BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(job)));
32                  String line = in.readLine();
33                  in.close();
34  
35                  // get end time
36                  endTime = Long.parseLong(line);
37              } catch (Exception e) {
38                  SubState status = SubState.FAILED_ERROR;
39                  return new EmulatorJobStatus(nativeJobId, status, e);
40              }
41              SubState status;
42              if (endTime == 0L) {
43                  status = SubState.CANCELED;
44              } else if (System.currentTimeMillis() > endTime) {
45                  status = SubState.DONE;
46              } else {
47                  status = SubState.RUNNING_ACTIVE;
48              }
49              return new EmulatorJobStatus(nativeJobId, status);
50          } else {
51              throw new NoSuccessException("Job does not exist: "+nativeJobId);
52          }
53      }
54  }