ensembl-hive-java  2.6
Job.java
Go to the documentation of this file.
1 /*
2  * Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
3  * Copyright [2016-2024] EMBL-European Bioinformatics Institute
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package org.ensembl.hive;
19 
20 import java.util.Map;
21 
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 
34 public class Job {
35 
36  private final transient ObjectMapper mapper = new ObjectMapper();
37 
38  private final Logger log = LoggerFactory.getLogger(this.getClass());
39 
40  private static final String INPUT_ID_KEY = "input_id";
41 
42  private static final String DB_ID_KEY = "dbID";
43 
44  private static final String RETRY_COUNT_KEY = "retry_count";
45 
46  private static final String PARAMETERS_KEY = "parameters";
47 
48  private final ParamContainer parameters;
49  private final int retryCount;
50  private final int dbID;
51  private final String inputId;
52 
53  private boolean autoflow = true;
54  private boolean lethalForWorker = false;
55  private boolean transientError = true;
56  private boolean complete = false;
57 
58  public Job(Map<String, Object> jobParams) {
59  log.debug("Building job with params with "+String.valueOf(jobParams.get(PARAMETERS_KEY)));
60  this.parameters = new ParamContainer(
61  (Map<String, Object>) (jobParams.get(PARAMETERS_KEY)));;
62  this.retryCount = Double.valueOf(
63  jobParams.get(RETRY_COUNT_KEY).toString()).intValue();
64  this.dbID = Double.valueOf(jobParams.get(DB_ID_KEY).toString())
65  .intValue();
66  this.inputId = (String) (jobParams.get(INPUT_ID_KEY));
67  }
68 
69  public Job(ParamContainer parameters, int retryCount, int dbID,
70  String inputId) {
71  super();
72  this.parameters = parameters;
73  this.retryCount = retryCount;
74  this.dbID = dbID;
75  this.inputId = inputId;
76  }
77 
78  public int getDbID() {
79  return dbID;
80  }
81 
82  public String getInputId() {
83  return inputId;
84  }
85 
87  return parameters;
88  }
89 
90  public int getRetryCount() {
91  return retryCount;
92  }
93 
94  public boolean isAutoflow() {
95  return autoflow;
96  }
97 
98  public void setAutoflow(boolean autoflow) {
99  this.autoflow = autoflow;
100  }
101 
102  public boolean isLethalForWorker() {
103  return lethalForWorker;
104  }
105 
106  public void setLethalForWorker(boolean lethalForWorker) {
107  this.lethalForWorker = lethalForWorker;
108  }
109 
110  public boolean isTransientError() {
111  return transientError;
112  }
113 
114  public void setTransientError(boolean transientError) {
115  this.transientError = transientError;
116  }
117 
118  public String toString() {
119  try {
120  return mapper.writeValueAsString(this);
121  } catch (JsonProcessingException e) {
122  throw new RuntimeException("Could not write job as JSON", e);
123  }
124  }
125 
126  public boolean isComplete() {
127  return complete;
128  }
129 
130  public void setComplete(boolean complete) {
131  this.complete = complete;
132  }
133 
141  public Object paramRequired(String paramName) {
142  boolean e = isTransientError();
143  setTransientError(false);
144  Object v = getParameters().getParam(paramName);
145  if (v == null) {
146  throw new NullParamException(paramName);
147  }
149  return v;
150  }
151 }
org.ensembl.hive.Job.isLethalForWorker
boolean isLethalForWorker()
Definition: Job.java:102
org.ensembl.hive.Job.Job
Job(Map< String, Object > jobParams)
Definition: Job.java:58
org.ensembl.hive.Job.isAutoflow
boolean isAutoflow()
Definition: Job.java:94
org.ensembl.hive.Job.isTransientError
boolean isTransientError()
Definition: Job.java:110
org.ensembl.hive.Job.getDbID
int getDbID()
Definition: Job.java:78
org.ensembl.hive.Job.getParameters
ParamContainer getParameters()
Definition: Job.java:86
org.ensembl.hive.ParamContainer
Definition: ParamContainer.java:37
org.ensembl.hive.Job.paramRequired
Object paramRequired(String paramName)
Definition: Job.java:141
org.ensembl.hive.Job
Definition: Job.java:34
org.ensembl.hive.Job.toString
String toString()
Definition: Job.java:118
org.ensembl.hive.Job.setLethalForWorker
void setLethalForWorker(boolean lethalForWorker)
Definition: Job.java:106
org.ensembl.hive.ParamContainer.getParam
Object getParam(String paramName)
Definition: ParamContainer.java:56
org.ensembl.hive.Job.Job
Job(ParamContainer parameters, int retryCount, int dbID, String inputId)
Definition: Job.java:69
org.ensembl.hive.Job.isComplete
boolean isComplete()
Definition: Job.java:126
org.ensembl.hive.Job.setAutoflow
void setAutoflow(boolean autoflow)
Definition: Job.java:98
org.ensembl.hive.NullParamException
Definition: NullParamException.java:20
org.ensembl.hive.Job.getInputId
String getInputId()
Definition: Job.java:82
org
org.ensembl.hive.Job.setTransientError
void setTransientError(boolean transientError)
Definition: Job.java:114
org.ensembl.hive.Job.setComplete
void setComplete(boolean complete)
Definition: Job.java:130
org.ensembl.hive.Job.getRetryCount
int getRetryCount()
Definition: Job.java:90