1 package jalview.ws.jws2.jabaws2;
3 import jalview.bin.Cache;
4 import jalview.datamodel.AlignmentI;
5 import jalview.datamodel.Sequence;
6 import jalview.datamodel.SequenceI;
7 import jalview.gui.WebserviceInfo;
8 import jalview.util.MessageManager;
9 import jalview.ws.api.CancellableI;
10 import jalview.ws.api.JobId;
11 import jalview.ws.api.MultipleSequenceAlignmentI;
12 import jalview.ws.gui.WsJob;
13 import jalview.ws.gui.WsJob.JobState;
14 import jalview.ws.jws2.JabaParamStore;
15 import jalview.ws.jws2.JabaPreset;
16 import jalview.ws.jws2.dm.JabaWsParamSet;
17 import jalview.ws.params.ArgumentI;
18 import jalview.ws.params.InvalidArgumentException;
19 import jalview.ws.params.WsParamSetI;
21 import java.io.IOError;
22 import java.rmi.ServerError;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
28 import compbio.data.msa.MsaWS;
29 import compbio.data.sequence.Alignment;
30 import compbio.data.sequence.FastaSequence;
31 import compbio.metadata.Argument;
32 import compbio.metadata.ChunkHolder;
33 import compbio.metadata.JobStatus;
34 import compbio.metadata.Preset;
35 import compbio.metadata.ResultNotAvailableException;
37 public class JabawsMsaInstance
38 implements MultipleSequenceAlignmentI, CancellableI
41 * our service instance handler generated by the discoverer
48 public JobId align(List<SequenceI> toalign, WsParamSetI parameters,
49 List<ArgumentI> arguments) throws Throwable
51 List<compbio.data.sequence.FastaSequence> seqs = new ArrayList<>();
52 for (SequenceI seq : toalign)
54 seqs.add(new FastaSequence(seq.getName(), seq.getSequenceAsString()));
57 if (parameters != null)
59 if (parameters instanceof JabaPreset)
61 jobid = service.presetAlign(seqs,
62 ((JabaPreset) parameters).getJabaPreset());
66 jobid = service.customAlign(seqs, JabaParamStore
67 .getJabafromJwsArgs(parameters.getArguments()));
70 else if (arguments != null && arguments.size() > 0)
72 jobid = service.customAlign(seqs,
73 JabaParamStore.getJabafromJwsArgs(arguments));
77 jobid = service.align(seqs);
84 return new JobId(our.getServiceType(), our.getName(), jobid);
88 public AlignmentI getAlignmentFor(JobId jobId)
89 throws InvalidArgumentException, ServerError, IOError
91 Alignment alignment = null;
94 alignment = service.getResult(jobId.getJobId());
95 } catch (ResultNotAvailableException rnotav)
98 // TODO - migrate JABA exception
99 // throw new ServerError("Couldn't get result for job",rnotav);
103 if (alignment.getSequences().size() == 0)
108 alseqs = new SequenceI[alignment.getSequences().size()];
109 for (compbio.data.sequence.FastaSequence seq : alignment.getSequences())
111 alseqs[alseq_l++] = new Sequence(seq.getId(), seq.getSequence());
113 AlignmentI jv_al = new jalview.datamodel.Alignment(alseqs);
114 jv_al.setGapCharacter(alignment.getMetadata().getGapchar());
119 public JabawsMsaInstance(Jws2Instance handle)
122 service = (MsaWS<?>) our.service;
126 public boolean cancel(WsJob job)
128 service.cancelJob(job.getJobId());
129 // if the Jaba server indicates the job can't be cancelled, its
130 // because its running on the server's local execution engine
131 // so we just close the window anyway.
136 Map<JobStatus, JobState> jwsState = new HashMap<>();
138 jwsState.put(JobStatus.CANCELLED, JobState.CANCELLED);
139 jwsState.put(JobStatus.COLLECTED, JobState.FINISHED);
140 jwsState.put(JobStatus.FAILED, JobState.FAILED);
141 jwsState.put(JobStatus.FINISHED, JobState.FINISHED);
142 jwsState.put(JobStatus.PENDING, JobState.QUEUED);
143 jwsState.put(JobStatus.RUNNING, JobState.RUNNING);
144 jwsState.put(JobStatus.STARTED, JobState.RUNNING);
145 jwsState.put(JobStatus.SUBMITTED, JobState.SUBMITTED);
146 jwsState.put(JobStatus.UNDEFINED, JobState.UNKNOWN);
149 public void updateStatus(WsJob job)
151 JobStatus jwsstatus = service.getJobStatus(job.getJobId());
152 job.setState(jwsState.get(jwsstatus));
156 public boolean updateJobProgress(WsJob job) throws Exception
158 StringBuilder response = new StringBuilder(job.getStatus());
159 long lastchunk = job.getNextChunk();
160 boolean changed = false;
163 ChunkHolder chunk = service.pullExecStatistics(job.getJobId(),
167 changed |= chunk.getChunk().length() > 0;
168 response.append(chunk.getChunk());
169 lastchunk = chunk.getNextPosition();
173 } catch (InterruptedException x)
179 job.setnextChunk(lastchunk);
180 } while (lastchunk >= 0 && job.getNextChunk() != lastchunk);
181 if (job instanceof WsJob)
183 // TODO decide if WsJob will be the bean for all ng-webservices
184 job.setStatus(response.toString());
189 public boolean isPresetJob(WsJob job)
191 return job.getPreset() != null && job.getPreset() instanceof JabaPreset;
194 public Preset getServerPreset(WsJob job)
196 return (isPresetJob(job))
197 ? ((JabaPreset) job.getPreset()).getJabaPreset()
201 public List<Argument> getJabaArguments(WsParamSetI preset)
203 List<Argument> newargs = new ArrayList<>();
206 if (preset instanceof JabaWsParamSet)
208 newargs.addAll(((JabaWsParamSet) preset).getjabaArguments());
213 JabaParamStore.getJabafromJwsArgs(preset.getArguments()));
220 public boolean handleSubmitError(Throwable _lex, WsJob j,
221 WebserviceInfo wsInfo) throws Exception, Error
223 if (_lex instanceof compbio.metadata.UnsupportedRuntimeException)
225 wsInfo.appendProgressText(MessageManager.formatMessage(
226 "info.job_couldnt_be_run_server_doesnt_support_program",
228 { _lex.getMessage() }));
229 wsInfo.warnUser(_lex.getMessage(),
230 MessageManager.getString("warn.service_not_supported"));
231 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
232 wsInfo.setStatus(j.getJobnum(),
233 WebserviceInfo.STATE_STOPPED_SERVERERROR);
236 if (_lex instanceof compbio.metadata.LimitExceededException)
238 wsInfo.appendProgressText(MessageManager.formatMessage(
239 "info.job_couldnt_be_run_exceeded_hard_limit", new String[]
240 { _lex.getMessage() }));
241 wsInfo.warnUser(_lex.getMessage(),
242 MessageManager.getString("warn.input_is_too_big"));
243 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
244 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
247 if (_lex instanceof compbio.metadata.WrongParameterException)
249 wsInfo.warnUser(_lex.getMessage(),
250 MessageManager.getString("warn.invalid_job_param_set"));
251 wsInfo.appendProgressText(MessageManager.formatMessage(
252 "info.job_couldnt_be_run_incorrect_param_setting",
254 { _lex.getMessage() }));
255 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
256 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
259 // pass on to generic error handler
264 public boolean handleCollectionException(Exception ex, WsJob msjob,
265 WebserviceInfo wsInfo)
267 if (ex instanceof compbio.metadata.ResultNotAvailableException)
269 // job has failed for some reason - probably due to invalid
272 "Results not available for finished job - marking as broken job.",
274 String status = msjob.getStatus();
276 msjob.setStatus(status
278 "\nResult not available. Probably due to invalid input or parameter settings. Server error message below:\n\n"
279 + ex.getLocalizedMessage());
280 msjob.setState(WsJob.JobState.BROKEN);