1 package jalview.ws.jws2.jabaws2;
3 import jalview.bin.Cache;
4 import jalview.bin.Console;
5 import jalview.gui.WebserviceInfo;
6 import jalview.util.MessageManager;
7 import jalview.ws.gui.WsJob;
8 import jalview.ws.gui.WsJob.JobState;
9 import jalview.ws.jws2.JabaParamStore;
10 import jalview.ws.jws2.JabaPreset;
11 import jalview.ws.jws2.dm.JabaWsParamSet;
12 import jalview.ws.params.WsParamSetI;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.List;
19 import compbio.metadata.Argument;
20 import compbio.metadata.ChunkHolder;
21 import compbio.metadata.JobStatus;
22 import compbio.metadata.Preset;
25 * Base class for JABAWS service instances. Provides helper methods for
26 * interfacing with Jalview.
31 public class JabawsServiceInstance<T extends compbio.data.msa.JManagement>
33 jalview.ws.api.JalviewWebServiceI, jalview.ws.api.CancellableI
36 * our service instance handler generated by the discoverer
40 protected Map<JobStatus, JobState> jwsState = new HashMap<>();
43 public boolean cancel(WsJob job)
45 service.cancelJob(job.getJobId());
46 // if the Jaba server indicates the job can't be cancelled, its
47 // because its running on the server's local execution engine
48 // so we just close the window anyway.
54 public JabawsServiceInstance(Jws2Instance handle)
57 service = (T) handle.service;
61 public void updateStatus(WsJob job)
63 JobStatus jwsstatus = service.getJobStatus(job.getJobId());
64 job.setState(jwsState.get(jwsstatus));
68 public boolean updateJobProgress(WsJob job) throws Exception
70 StringBuilder response = new StringBuilder(job.getStatus());
71 long lastchunk = job.getNextChunk();
74 Console.debug("No more status messages for job " + job.getJobId());
77 boolean changed = false;
80 ChunkHolder chunk = service.pullExecStatistics(job.getJobId(),
84 changed |= chunk.getChunk().length() > 0;
85 response.append(chunk.getChunk());
86 lastchunk = chunk.getNextPosition();
90 } catch (InterruptedException x)
96 job.setnextChunk(lastchunk);
97 } while (lastchunk >= 0 && job.getNextChunk() != lastchunk);
98 if (job instanceof WsJob)
100 // TODO decide if WsJob will be the bean for all ng-webservices
101 job.setStatus(response.toString());
107 jwsState.put(JobStatus.CANCELLED, JobState.CANCELLED);
108 jwsState.put(JobStatus.COLLECTED, JobState.FINISHED);
109 jwsState.put(JobStatus.FAILED, JobState.FAILED);
110 jwsState.put(JobStatus.FINISHED, JobState.FINISHED);
111 jwsState.put(JobStatus.PENDING, JobState.QUEUED);
112 jwsState.put(JobStatus.RUNNING, JobState.RUNNING);
113 jwsState.put(JobStatus.STARTED, JobState.RUNNING);
114 jwsState.put(JobStatus.SUBMITTED, JobState.SUBMITTED);
115 jwsState.put(JobStatus.UNDEFINED, JobState.UNKNOWN);
118 public boolean isPresetJob(WsJob job)
120 return job.getPreset() != null && job.getPreset() instanceof JabaPreset;
123 public Preset getServerPreset(WsJob job)
125 return (isPresetJob(job))
126 ? ((JabaPreset) job.getPreset()).getJabaPreset()
130 public List<Argument> getJabaArguments(WsParamSetI preset)
132 List<Argument> newargs = new ArrayList<>();
135 if (preset instanceof JabaWsParamSet)
137 newargs.addAll(((JabaWsParamSet) preset).getjabaArguments());
142 JabaParamStore.getJabafromJwsArgs(preset.getArguments()));
149 public boolean handleSubmitError(Throwable _lex, WsJob j,
150 WebserviceInfo wsInfo) throws Exception, Error
152 if (_lex instanceof compbio.metadata.UnsupportedRuntimeException)
154 wsInfo.appendProgressText(MessageManager.formatMessage(
155 "info.job_couldnt_be_run_server_doesnt_support_program",
157 { _lex.getMessage() }));
158 wsInfo.warnUser(_lex.getMessage(),
159 MessageManager.getString("warn.service_not_supported"));
160 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
161 wsInfo.setStatus(j.getJobnum(),
162 WebserviceInfo.STATE_STOPPED_SERVERERROR);
165 if (_lex instanceof compbio.metadata.LimitExceededException)
167 wsInfo.appendProgressText(MessageManager.formatMessage(
168 "info.job_couldnt_be_run_exceeded_hard_limit", new String[]
169 { _lex.getMessage() }));
170 wsInfo.warnUser(_lex.getMessage(),
171 MessageManager.getString("warn.input_is_too_big"));
172 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
173 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
176 if (_lex instanceof compbio.metadata.WrongParameterException)
178 wsInfo.warnUser(_lex.getMessage(),
179 MessageManager.getString("warn.invalid_job_param_set"));
180 wsInfo.appendProgressText(MessageManager.formatMessage(
181 "info.job_couldnt_be_run_incorrect_param_setting",
183 { _lex.getMessage() }));
184 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
185 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
188 // pass on to generic error handler
193 public boolean handleCollectionException(Exception ex, WsJob msjob,
194 WebserviceInfo wsInfo)
196 if (ex instanceof compbio.metadata.ResultNotAvailableException)
198 // job has failed for some reason - probably due to invalid
201 "Results not available for finished job - marking as broken job.",
203 String status = msjob.getStatus();
205 msjob.setStatus(status
206 + "\nResult not available. Probably due to invalid input or parameter settings. Server error message below:\n\n"
207 + ex.getLocalizedMessage());
208 msjob.setState(WsJob.JobState.BROKEN);