Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.ws.jws2.jabaws2

File JabawsServiceInstance.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

22
69
10
1
213
179
23
0.33
6.9
10
2.3

Classes

Class Line # Actions
JabawsServiceInstance 31 69 23
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.ws.jws2.jabaws2;
2   
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;
13   
14    import java.util.ArrayList;
15    import java.util.HashMap;
16    import java.util.List;
17    import java.util.Map;
18   
19    import compbio.metadata.Argument;
20    import compbio.metadata.ChunkHolder;
21    import compbio.metadata.JobStatus;
22    import compbio.metadata.Preset;
23   
24    /**
25    * Base class for JABAWS service instances. Provides helper methods for
26    * interfacing with Jalview.
27    *
28    * @author jprocter
29    *
30    */
 
31    public class JabawsServiceInstance<T extends compbio.data.msa.JManagement>
32    implements
33    jalview.ws.api.JalviewWebServiceI, jalview.ws.api.CancellableI
34    {
35    /**
36    * our service instance handler generated by the discoverer
37    */
38    Jws2Instance our;
39    protected T service;
40    protected Map<JobStatus, JobState> jwsState = new HashMap<>();
41   
 
42  0 toggle @Override
43    public boolean cancel(WsJob job)
44    {
45  0 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.
49   
50  0 return true;
51    }
52   
53   
 
54  0 toggle public JabawsServiceInstance(Jws2Instance handle)
55    {
56  0 our = handle;
57  0 service = (T) handle.service;
58    }
59   
 
60  0 toggle @Override
61    public void updateStatus(WsJob job)
62    {
63  0 JobStatus jwsstatus = service.getJobStatus(job.getJobId());
64  0 job.setState(jwsState.get(jwsstatus));
65    }
66   
 
67  0 toggle @Override
68    public boolean updateJobProgress(WsJob job) throws Exception
69    {
70  0 StringBuilder response = new StringBuilder(job.getStatus());
71  0 long lastchunk = job.getNextChunk();
72  0 if (lastchunk == -1)
73    {
74  0 Console.debug("No more status messages for job " + job.getJobId());
75  0 return false;
76    }
77  0 boolean changed = false;
78  0 do
79    {
80  0 ChunkHolder chunk = service.pullExecStatistics(job.getJobId(),
81    lastchunk);
82  0 if (chunk != null)
83    {
84  0 changed |= chunk.getChunk().length() > 0;
85  0 response.append(chunk.getChunk());
86  0 lastchunk = chunk.getNextPosition();
87  0 try
88    {
89  0 Thread.sleep(50);
90    } catch (InterruptedException x)
91    {
92    }
93  0 ;
94    }
95  0 ;
96  0 job.setnextChunk(lastchunk);
97  0 } while (lastchunk >= 0 && job.getNextChunk() != lastchunk);
98  0 if (job instanceof WsJob)
99    {
100    // TODO decide if WsJob will be the bean for all ng-webservices
101  0 job.setStatus(response.toString());
102    }
103  0 return changed;
104    }
105   
 
106  0 toggle {
107  0 jwsState.put(JobStatus.CANCELLED, JobState.CANCELLED);
108  0 jwsState.put(JobStatus.COLLECTED, JobState.FINISHED);
109  0 jwsState.put(JobStatus.FAILED, JobState.FAILED);
110  0 jwsState.put(JobStatus.FINISHED, JobState.FINISHED);
111  0 jwsState.put(JobStatus.PENDING, JobState.QUEUED);
112  0 jwsState.put(JobStatus.RUNNING, JobState.RUNNING);
113  0 jwsState.put(JobStatus.STARTED, JobState.RUNNING);
114  0 jwsState.put(JobStatus.SUBMITTED, JobState.SUBMITTED);
115  0 jwsState.put(JobStatus.UNDEFINED, JobState.UNKNOWN);
116    }
117   
 
118  0 toggle public boolean isPresetJob(WsJob job)
119    {
120  0 return job.getPreset() != null && job.getPreset() instanceof JabaPreset;
121    }
122   
 
123  0 toggle public Preset getServerPreset(WsJob job)
124    {
125  0 return (isPresetJob(job))
126    ? ((JabaPreset) job.getPreset()).getJabaPreset()
127    : null;
128    }
129   
 
130  0 toggle public List<Argument> getJabaArguments(WsParamSetI preset)
131    {
132  0 List<Argument> newargs = new ArrayList<>();
133  0 if (preset != null)
134    {
135  0 if (preset instanceof JabaWsParamSet)
136    {
137  0 newargs.addAll(((JabaWsParamSet) preset).getjabaArguments());
138    }
139    else
140    {
141  0 newargs.addAll(
142    JabaParamStore.getJabafromJwsArgs(preset.getArguments()));
143    }
144    }
145  0 return newargs;
146    }
147   
 
148  0 toggle @Override
149    public boolean handleSubmitError(Throwable _lex, WsJob j,
150    WebserviceInfo wsInfo) throws Exception, Error
151    {
152  0 if (_lex instanceof compbio.metadata.UnsupportedRuntimeException)
153    {
154  0 wsInfo.appendProgressText(MessageManager.formatMessage(
155    "info.job_couldnt_be_run_server_doesnt_support_program",
156    new String[]
157    { _lex.getMessage() }));
158  0 wsInfo.warnUser(_lex.getMessage(),
159    MessageManager.getString("warn.service_not_supported"));
160  0 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
161  0 wsInfo.setStatus(j.getJobnum(),
162    WebserviceInfo.STATE_STOPPED_SERVERERROR);
163  0 return true;
164    }
165  0 if (_lex instanceof compbio.metadata.LimitExceededException)
166    {
167  0 wsInfo.appendProgressText(MessageManager.formatMessage(
168    "info.job_couldnt_be_run_exceeded_hard_limit", new String[]
169    { _lex.getMessage() }));
170  0 wsInfo.warnUser(_lex.getMessage(),
171    MessageManager.getString("warn.input_is_too_big"));
172  0 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
173  0 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
174  0 return true;
175    }
176  0 if (_lex instanceof compbio.metadata.WrongParameterException)
177    {
178  0 wsInfo.warnUser(_lex.getMessage(),
179    MessageManager.getString("warn.invalid_job_param_set"));
180  0 wsInfo.appendProgressText(MessageManager.formatMessage(
181    "info.job_couldnt_be_run_incorrect_param_setting",
182    new String[]
183    { _lex.getMessage() }));
184  0 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
185  0 wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_ERROR);
186  0 return true;
187    }
188    // pass on to generic error handler
189  0 return false;
190    }
191   
 
192  0 toggle @Override
193    public boolean handleCollectionException(Exception ex, WsJob msjob,
194    WebserviceInfo wsInfo)
195    {
196  0 if (ex instanceof compbio.metadata.ResultNotAvailableException)
197    {
198    // job has failed for some reason - probably due to invalid
199    // parameters
200  0 Console.debug(
201    "Results not available for finished job - marking as broken job.",
202    ex);
203  0 String status = msjob.getStatus();
204   
205  0 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  0 msjob.setState(WsJob.JobState.BROKEN);
209  0 return true;
210    }
211  0 return false;
212    }
213    }