View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.job.api;
23  
24  import java.net.URI;
25  import java.util.Date;
26  import java.util.List;
27  
28  /**
29   * Represents a long running, asynchronous process. A Job may be used to track any task, whether it is queued to run in
30   * the future, currently running, or has run in the past.
31   */
32  public interface Job {
33  
34    /** The status of the job that this receipt represents */
35    enum Status {
36      QUEUED, PAUSED, RUNNING, FINISHED, FAILED, DELETED, INSTANTIATED, DISPATCHING, RESTART, CANCELLED, WAITING;
37  
38      /** Return if the job is terminated. */
39      public boolean isTerminated() {
40        switch (this) {
41          case CANCELLED:
42          case DELETED:
43          case FAILED:
44          case FINISHED:
45            return true;
46          default:
47            return false;
48        }
49      }
50  
51      /** Check if the job is still active, e.g. RUNNING or QUEUED. This is the negation of {@link #isTerminated()}. */
52      public boolean isActive() {
53        return !isTerminated();
54      }
55    }
56  
57    /** Reason for failure */
58    enum FailureReason {
59      NONE, DATA, PROCESSING
60    }
61  
62    /**
63     * Gets the job identifier.
64     *
65     * @return the identifier
66     */
67    long getId();
68  
69    /**
70     * Gets the username of the subject responsible for creating the job initially. This job will execute with this user's
71     * roles and permissions.
72     *
73     * @return the username that created the job
74     */
75    String getCreator();
76  
77    void setCreator(String creator);
78  
79    /**
80     * Returns the identifier of the organization that the creator is associated with.
81     *
82     * @return the organization
83     */
84    String getOrganization();
85  
86    void setOrganization(String organization);
87  
88    /**
89     * Gets the version of this job. Each time the job is updated, the version number is incremented. If a process
90     * attempts to save a job that has been updated in another thread or on another host while the job was in memory, an
91     * optimistic locking exception will be thrown.
92     *
93     * @return the version number of this job
94     */
95    long getVersion();
96  
97    /**
98     * Gets the job type, which determines the type of service that runs the job.
99     *
100    * @return the job type
101    */
102   String getJobType();
103 
104   void setJobType(String jobType);
105 
106   /**
107    * The operation type, which can be used by the service responsible for the job to determine the service method to
108    * execute.
109    *
110    * @return The operation
111    */
112   String getOperation();
113 
114   void setOperation(String operation);
115 
116   /**
117    * The arguments passed to the service and operation. Each argument must be serializable to a string.
118    *
119    * @return the arguments passed to the service operation
120    */
121   List<String> getArguments();
122 
123   void setArguments(List<String> arguments);
124 
125   /**
126    * Gets the receipt's current {@link Status}
127    *
128    * @return the current status
129    */
130   Status getStatus();
131 
132   void setStatus(Status status);
133 
134   /**
135    * Sets the receipt's current {@link Status} along with the {@link FailureReason} to indicate why - in the case of
136    * failure - the job failed.
137    *
138    * @param status
139    *          the status to set
140    * @param reason
141    *          failure reason
142    */
143   void setStatus(Status status, FailureReason reason);
144 
145   /**
146    * In the case of failure, returns whether the failure had to do with data or with processing. Depending on the
147    * reason, processing services might be marked not to accept new jobs.
148    *
149    * @return the failure reason
150    */
151   FailureReason getFailureReason();
152 
153   /**
154    * Gets the host that created this job.
155    *
156    * @return the server that originally created the job
157    */
158   String getCreatedHost();
159 
160   /**
161    * Gets the host responsible for running this job.
162    *
163    * @return the server running the job, or null if the job hasn't yet started
164    */
165   String getProcessingHost();
166 
167   void setProcessingHost(String processingHost);
168 
169   /**
170    * The date this job was created.
171    *
172    * @return the date the job was created
173    */
174   Date getDateCreated();
175 
176   void setDateCreated(Date created);
177 
178   /**
179    * The date this job was started. If the job was queued, this can be significantly later than the date created.
180    *
181    * @return the date the job was started
182    */
183   Date getDateStarted();
184 
185   void setDateStarted(Date started);
186 
187   /**
188    * The number of milliseconds that this job has waited in a queue before execution. This value will be null if the job
189    * has not yet started execution.
190    *
191    * @return the total run time
192    */
193   Long getQueueTime();
194 
195   void setQueueTime(Long queueTime);
196 
197   /**
198    * The number of milliseconds that this job took to execute. This value will be null if the job has not yet finished
199    * execution.
200    *
201    * @return the total run time
202    */
203   Long getRunTime();
204 
205   void setRunTime(Long runTime);
206 
207   /**
208    * The date this job was completed
209    *
210    * @return the date completed
211    */
212   Date getDateCompleted();
213 
214   void setDateCompleted(Date dateCompleted);
215 
216   /**
217    * Gets the serialized output that was produced by this job, or null if nothing was produced, or if it has yet to be
218    * produced.
219    *
220    * @return the output of the job
221    */
222   String getPayload();
223 
224   void setPayload(String payload);
225 
226   /**
227    *
228    * @return
229    */
230   int getSignature();
231 
232   /**
233    * Gets the parent job identifier, or null if there is no parent.
234    *
235    * @return the parent identifier
236    */
237   Long getParentJobId();
238 
239   void setParentJobId(Long parentJobId);
240 
241   /**
242    * Gets the root job identifier, or null if this is the root job.
243    *
244    * @return the root job identifier
245    */
246   Long getRootJobId();
247 
248   /**
249    * Gets whether this job may be dispatched.
250    *
251    * @return whether the job can be queued for dispatch or not
252    */
253   boolean isDispatchable();
254 
255   void setDispatchable(boolean dispatchable);
256 
257   /**
258    * Gets the URI of this job, which can be used to check its status.
259    *
260    * @return the job's URI
261    */
262   URI getUri();
263 
264   /**
265    * Gets the job's load.  For example, a job which uses four cores would have a load of 4.0. This should be roughly the
266    * number of cores that this job occupies while running.
267    *
268    * @return the job's load
269    */
270   Float getJobLoad();
271 
272   void setJobLoad(Float load);
273 
274 }