1 package jalview.ws.jws2.jabaws2;
3 import jalview.bin.Cache;
4 import jalview.gui.WebserviceInfo;
5 import jalview.util.MessageManager;
6 import jalview.ws.gui.WsJob;
7 import jalview.ws.gui.WsJob.JobState;
8 import jalview.ws.jws2.JabaParamStore;
9 import jalview.ws.jws2.JabaPreset;
10 import jalview.ws.jws2.dm.JabaWsParamSet;
11 import jalview.ws.params.WsParamSetI;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
18 import compbio.metadata.Argument;
19 import compbio.metadata.ChunkHolder;
20 import compbio.metadata.JobStatus;
21 import compbio.metadata.Preset;
24 * Base class for JABAWS service instances. Provides helper methods for
25 * interfacing with Jalview.
30 public class JabawsServiceInstance<T extends compbio.data.msa.JManagement>
32 jalview.ws.api.JalviewWebServiceI, jalview.ws.api.CancellableI
35 * our service instance handler generated by the discoverer
39 protected Map<JobStatus, JobState> jwsState = new HashMap<>();
42 public boolean cancel(WsJob job)
44 service.cancelJob(job.getJobId());
45 // if the Jaba server indicates the job can't be cancelled, its
46 // because its running on the server's local execution engine
47 // so we just close the window anyway.
53 public JabawsServiceInstance(Jws2Instance handle)
56 service = (T) handle.service;
60 public void updateStatus(WsJob job)
62 JobStatus jwsstatus = service.getJobStatus(job.getJobId());
63 job.setState(jwsState.get(jwsstatus));
67 public boolean updateJobProgress(WsJob job) throws Exception
69 StringBuilder response = new StringBuilder(job.getStatus());
70 long lastchunk = job.getNextChunk();
73 Cache.log.debug("No more status messages for job " + job.getJobId());
76 boolean changed = false;
79 ChunkHolder chunk = service.pullExecStatistics(job.getJobId(),
83 changed |= chunk.getChunk().length() > 0;
84 response.append(chunk.getChunk());
85 lastchunk = chunk.getNextPosition();
89 } catch (InterruptedException x)
95 job.setnextChunk(lastchunk);
96 } while (lastchunk >= 0 && job.getNextChunk() != lastchunk);
97 if (job instanceof WsJob)
99 // TODO decide if WsJob will be the bean for all ng-webservices
100 job.setStatus(response.toString());
106 jwsState.put(JobStatus.CANCELLED, JobState.CANCELLED);
107 jwsState.put(JobStatus.COLLECTED, JobState.FINISHED);
108 jwsState.put(JobStatus.FAILED, JobState.FAILED);
109 jwsState.put(JobStatus.FINISHED, JobState.FINISHED);
110 jwsState.put(JobStatus.PENDING, JobState.QUEUED);
111 jwsState.put(JobStatus.RUNNING, JobState.RUNNING);
112 jwsState.put(JobStatus.STARTED, JobState.RUNNING);
113 jwsState.put(JobStatus.SUBMITTED, JobState.SUBMITTED);
114 jwsState.put(JobStatus.UNDEFINED, JobState.UNKNOWN);
117 public boolean isPresetJob(WsJob job)
119 return job.getPreset() != null && job.getPreset() instanceof JabaPreset;
122 public Preset getServerPreset(WsJob job)
124 return (isPresetJob(job))
125 ? ((JabaPreset) job.getPreset()).getJabaPreset()
129 public List<Argument> getJabaArguments(WsParamSetI preset)
131 List<Argument> newargs = new ArrayList<>();
134 if (preset instanceof JabaWsParamSet)
136 newargs.addAll(((JabaWsParamSet) preset).getjabaArguments());
141 JabaParamStore.getJabafromJwsArgs(preset.getArguments()));
148 public boolean handleSubmitError(Throwable _lex, WsJob j,
149 WebserviceInfo wsInfo) throws Exception, Error
151 if (_lex instanceof compbio.metadata.UnsupportedRuntimeException)
153 wsInfo.appendProgressText(MessageManager.formatMessage(
154 "info.job_couldnt_be_run_server_doesnt_support_program",
156 { _lex.getMessage() }));
157 wsInfo.warnUser(_lex.getMessage(),
158 MessageManager.getString("warn.service_not_supported"));
159 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
160 wsInfo.setStatus(j.getJobnum(),
161 WebserviceInfo.STATE_STOPPED_SERVERERROR);
164 if (_lex instanceof compbio.metadata.LimitExceededException)
166 wsInfo.appendProgressText(MessageManager.formatMessage(
167 "info.job_couldnt_be_run_exceeded_hard_limit", new String[]
168 { _lex.getMessage() }));
169 wsInfo.warnUser(_lex.getMessage(),
170 MessageManager.getString("warn.input_is_too_big"));
171 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
172 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
175 if (_lex instanceof compbio.metadata.WrongParameterException)
177 wsInfo.warnUser(_lex.getMessage(),
178 MessageManager.getString("warn.invalid_job_param_set"));
179 wsInfo.appendProgressText(MessageManager.formatMessage(
180 "info.job_couldnt_be_run_incorrect_param_setting",
182 { _lex.getMessage() }));
183 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
184 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
187 // pass on to generic error handler
192 public boolean handleCollectionException(Exception ex, WsJob msjob,
193 WebserviceInfo wsInfo)
195 if (ex instanceof compbio.metadata.ResultNotAvailableException)
197 // job has failed for some reason - probably due to invalid
200 "Results not available for finished job - marking as broken job.",
202 String status = msjob.getStatus();
204 msjob.setStatus(status
205 + "\nResult not available. Probably due to invalid input or parameter settings. Server error message below:\n\n"
206 + ex.getLocalizedMessage());
207 msjob.setState(WsJob.JobState.BROKEN);