-
Notifications
You must be signed in to change notification settings - Fork 17
/
JobStatusImplementation.java
188 lines (168 loc) · 5.64 KB
/
JobStatusImplementation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright 2013 Netherlands eScience Center
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.esciencecenter.xenon.adaptors.schedulers;
import java.util.Map;
import java.util.Objects;
import nl.esciencecenter.xenon.XenonException;
import nl.esciencecenter.xenon.schedulers.JobStatus;
/**
* JobStatus contains status information for a specific job.
*
* @version 1.0
* @since 1.0
*/
public class JobStatusImplementation implements JobStatus {
private final String jobIdentifier;
private final String name;
private final String state;
private final Integer exitCode;
private final XenonException exception;
private final boolean running;
private final boolean done;
private final Map<String, String> schedulerSpecificInformation;
/**
* Create a JobStatus.
*
* @param jobIdentifier
* the identifier of the job for which this status was created.
* @param name
* the name of the job for which this status was created.
* @param state
* the state of the <code>Job</code> at the time this status was created.
* @param exitCode
* the exit code of the <code>Job</code> (if the jobs has finished).
* @param exception
* the exception produced when running <code>Job</code> (if the jobs has failed).
* @param running
* is the <code>Job</code> running ?
* @param done
* is the <code>Job</code> finished ?
* @param schedulerSpecificInformation
* a map of scheduler implementation specific information on the job.
*/
public JobStatusImplementation(String jobIdentifier, String name, String state, Integer exitCode, XenonException exception, boolean running, boolean done,
Map<String, String> schedulerSpecificInformation) {
if (jobIdentifier == null) {
throw new IllegalArgumentException("Job may not be null!");
}
this.jobIdentifier = jobIdentifier;
this.name = name;
this.state = state;
this.exitCode = exitCode;
this.exception = exception;
this.running = running;
this.done = done;
this.schedulerSpecificInformation = schedulerSpecificInformation;
}
/**
* Get the job identifier of the Job for which this JobStatus was created.
*
* @return the Job.
*/
public String getJobIdentifier() {
return jobIdentifier;
}
/**
* Get the name of the Job for which this JobStatus was created.
*
* @return the Job.
*/
public String getName() {
return name;
}
/**
* Get the state of the Job.
*
* @return the state of the Job.
*/
public String getState() {
return state;
}
/**
* Get the exit code for the Job.
*
* @return the exit code for the Job.
*/
public Integer getExitCode() {
return exitCode;
}
/**
* Get the exception produced by the Job or while retrieving the status. If a job was canceled, will return a JobCanceledException.
*
* @return the exception.
*/
public XenonException getException() {
return exception;
}
@Override
public void maybeThrowException() throws XenonException {
if (hasException()) {
throw getException();
}
}
/**
* Is the Job running.
*
* @return if the Job is running.
*/
public boolean isRunning() {
return running;
}
/**
* Is the Job done.
*
* @return if the Job is done.
*/
public boolean isDone() {
return done;
}
/**
* Has the Job or job retrieval produced a exception ?
*
* @return if the Job has an exception.
*/
public boolean hasException() {
return (exception != null);
}
/**
* Get scheduler specific information on the Job.
*
* @return scheduler specific information on the Job.
*/
public Map<String, String> getSchedulerSpecificInformation() {
return schedulerSpecificInformation;
}
@Override
public String toString() {
return "JobStatus [jobIdentifier=" + jobIdentifier + ", state=" + state + ", exitCode=" + exitCode + ", exception=" + exception + ", running=" + running
+ ", done=" + done + ", schedulerSpecificInformation=" + schedulerSpecificInformation + "]";
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
JobStatusImplementation that = (JobStatusImplementation) o;
return running == that.running && done == that.done && Objects.equals(jobIdentifier, that.jobIdentifier) && Objects.equals(state, that.state)
&& Objects.equals(exitCode, that.exitCode) && Objects.equals(exception, that.exception)
&& Objects.equals(schedulerSpecificInformation, that.schedulerSpecificInformation);
}
@Override
public int hashCode() {
return Objects.hash(jobIdentifier, state, exitCode, exception, running, done, schedulerSpecificInformation);
}
}