1 package fr.in2p3.jsaga.impl.job.instance;
2
3 import fr.in2p3.jsaga.adaptor.job.control.staging.StagingTransfer;
4 import fr.in2p3.jsaga.impl.attributes.ScalarAttributeImpl;
5 import fr.in2p3.jsaga.impl.attributes.VectorAttributeImpl;
6 import fr.in2p3.jsaga.impl.monitoring.MetricMode;
7 import fr.in2p3.jsaga.impl.monitoring.MetricType;
8 import org.ogf.saga.error.*;
9 import org.ogf.saga.job.Job;
10
11 import java.util.Date;
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class JobAttributes implements Cloneable {
26 ScalarAttributeImpl<String> m_JobId;
27 ScalarAttributeImpl<String> m_ServiceUrl;
28 VectorAttributeImpl<String> m_ExecutionHosts;
29 ScalarAttributeImpl<Date> m_Created;
30 ScalarAttributeImpl<Date> m_Started;
31 ScalarAttributeImpl<Date> m_Finished;
32 ScalarAttributeImpl<Integer> m_ExitCode;
33
34 ScalarAttributeImpl<String> m_NativeJobDescription;
35
36 VectorAttributeImpl<String> m_outputURLs;
37
38
39 JobAttributes(final AbstractSyncJobImpl job) {
40 m_JobId = job._addAttribute(new ScalarAttributeImpl<String>(
41 Job.JOBID,
42 "SAGA representation of the job identifier",
43 MetricMode.ReadOnly,
44 MetricType.String,
45 null));
46 m_ServiceUrl = job._addAttribute(new ScalarAttributeImpl<String>(
47 Job.SERVICEURL,
48 "URL representation of the JobService that created the job",
49 MetricMode.ReadOnly,
50 MetricType.String,
51 null));
52 m_ExecutionHosts = job._addVectorAttribute(new VectorAttributeImpl<String>(
53 Job.EXECUTIONHOSTS,
54 "list of host names or IP addresses allocated to run this job",
55 MetricMode.ReadOnly,
56 MetricType.String,
57 null) {
58 public String[] getValues() throws NotImplementedException, IncorrectStateException, NoSuccessException {
59 if(job.getNativeJobId()==null) throw new IncorrectStateException("Job has not been submitted");
60 String[] result = job.getJobInfoAdaptor().getExecutionHosts(job.getNativeJobId());
61 if (result != null) {
62 return result;
63 } else {
64 throw new IncorrectStateException("Attribute may not be initialized yet: "+Job.EXECUTIONHOSTS);
65 }
66 }
67 });
68 m_Created = job._addAttribute(new ScalarAttributeImpl<Date>(
69 Job.CREATED,
70 "time stamp of the job creation in the resource manager",
71 MetricMode.ReadOnly,
72 MetricType.Time,
73 new Date(System.currentTimeMillis())) {
74 public String getValue() throws NotImplementedException, IncorrectStateException, NoSuccessException {
75 if(job.getNativeJobId()==null) throw new IncorrectStateException("Job has not been submitted");
76 Date result = job.getJobInfoAdaptor().getCreated(job.getNativeJobId());
77 if (result != null) {
78 return result.toString();
79 } else {
80 throw new IncorrectStateException("Attribute may not be initialized yet: "+Job.CREATED);
81 }
82 }
83 });
84 m_Started = job._addAttribute(new ScalarAttributeImpl<Date>(
85 Job.STARTED,
86 "time stamp indicating when the job started running",
87 MetricMode.ReadOnly,
88 MetricType.Time,
89 null) {
90 public String getValue() throws NotImplementedException, IncorrectStateException, NoSuccessException {
91 if(job.getNativeJobId()==null) throw new IncorrectStateException("Job has not been submitted");
92 Date result = job.getJobInfoAdaptor().getStarted(job.getNativeJobId());
93 if (result != null) {
94 return result.toString();
95 } else {
96 throw new IncorrectStateException("Attribute may not be initialized yet: "+Job.STARTED);
97 }
98 }
99 });
100 m_Finished = job._addAttribute(new ScalarAttributeImpl<Date>(
101 Job.FINISHED,
102 "time stamp indicating when the job completed",
103 MetricMode.ReadOnly,
104 MetricType.Time,
105 null) {
106 public String getValue() throws NotImplementedException, IncorrectStateException, NoSuccessException {
107 if(job.getNativeJobId()==null) throw new IncorrectStateException("Job has not been submitted");
108 Date result = job.getJobInfoAdaptor().getFinished(job.getNativeJobId());
109 if (result != null) {
110 return result.toString();
111 } else {
112 throw new IncorrectStateException("Attribute may not be initialized yet: "+Job.FINISHED);
113 }
114 }
115 });
116 m_ExitCode = job._addAttribute(new ScalarAttributeImpl<Integer>(
117 Job.EXITCODE,
118 "process exit code",
119 MetricMode.ReadOnly,
120 MetricType.Int,
121 null) {
122 public String getValue() throws NotImplementedException, IncorrectStateException, NoSuccessException {
123 if(job.getNativeJobId()==null) throw new IncorrectStateException("Job has not been submitted");
124 Integer result = job.getJobInfoAdaptor().getExitCode(job.getNativeJobId());
125 if (result != null) {
126 return result.toString();
127 } else {
128 throw new IncorrectStateException("Attribute may not be initialized yet: "+Job.EXITCODE);
129 }
130 }
131 });
132 m_NativeJobDescription = job._addAttribute(new ScalarAttributeImpl<String>(
133 AbstractSyncJobImpl.NATIVEJOBDESCRIPTION,
134 "job description understood by the job service (deviation from SAGA specification)",
135 MetricMode.ReadOnly,
136 MetricType.String,
137 null));
138
139 m_outputURLs = job._addVectorAttribute(new VectorAttributeImpl<String>(
140 AbstractSyncJobImpl.OUTPUTURL,
141 "output files staging URLs by the job service (deviation from SAGA specification)",
142 MetricMode.ReadOnly,
143 MetricType.String,
144 null){
145 public String[] getValues() throws NotImplementedException, IncorrectStateException, NoSuccessException {
146 if(job.getNativeJobId()==null) throw new IncorrectStateException("Job has not been submitted");
147 StagingTransfer[] stagingTransfers;
148 try {
149 stagingTransfers = job.getOutputStagingTransfer();
150 } catch (Exception e) {
151 throw new NoSuccessException(e);
152 }
153 if (stagingTransfers == null) {
154 return null;
155 }
156 String[] result = new String[stagingTransfers.length];
157 for (int i = 0; i < stagingTransfers.length; i++) {
158 result[i] = stagingTransfers[i].getTo();
159 }
160 return result;
161 }
162 });
163 }
164
165
166 public JobAttributes clone() throws CloneNotSupportedException {
167 JobAttributes clone = (JobAttributes) super.clone();
168 clone.m_JobId = m_JobId.clone();
169 clone.m_ServiceUrl = m_ServiceUrl.clone();
170 clone.m_ExecutionHosts = m_ExecutionHosts.clone();
171 clone.m_Created = m_Created.clone();
172 clone.m_Started = m_Started.clone();
173 clone.m_Finished = m_Finished.clone();
174 clone.m_ExitCode = m_ExitCode.clone();
175 clone.m_NativeJobDescription = m_NativeJobDescription.clone();
176 return clone;
177 }
178 }