Small internal code changes
[jabaws.git] / webservices / compbio / ws / server / GenericMetadataService.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.ws.server;\r
19 \r
20 import java.util.List;\r
21 \r
22 import org.apache.log4j.Logger;\r
23 \r
24 import compbio.data.sequence.FastaSequence;\r
25 import compbio.engine.Configurator;\r
26 import compbio.engine.client.ConfiguredExecutable;\r
27 import compbio.engine.client.Executable;\r
28 import compbio.engine.client.SkeletalExecutable;\r
29 import compbio.metadata.ChunkHolder;\r
30 import compbio.metadata.JobStatus;\r
31 import compbio.metadata.JobSubmissionException;\r
32 import compbio.metadata.Limit;\r
33 import compbio.metadata.LimitsManager;\r
34 import compbio.metadata.PresetManager;\r
35 import compbio.metadata.RunnerConfig;\r
36 import compbio.runner.Util;\r
37 \r
38 public abstract class GenericMetadataService<T> {\r
39 \r
40         private final RunnerConfig<T> aaconOptions;\r
41         private final PresetManager<T> aaconPresets;\r
42         private final LimitsManager<T> limitMan;\r
43         private SkeletalExecutable<T> exec;\r
44         final Logger log;\r
45 \r
46         /*\r
47          * FIXME - instances of the Runner (?) and their types should be defined in\r
48          * Executable IF\r
49          */\r
50         GenericMetadataService(SkeletalExecutable<T> exec, Logger log) {\r
51                 assert log != null;\r
52                 assert exec != null;\r
53                 this.log = log;\r
54                 this.exec = exec;\r
55                 this.limitMan = compbio.engine.client.Util.getLimits(exec.getType());\r
56                 this.aaconOptions = Util.getSupportedOptions((Class<? extends Executable<T>>) exec.getType());\r
57                 this.aaconPresets = Util.getPresets((Class<? extends Executable<T>>) exec.getType());\r
58         }\r
59 \r
60         ConfiguredExecutable<T> init(List<FastaSequence> sequences)\r
61                         throws JobSubmissionException {\r
62                 // FIXME\r
63                 try {\r
64                         exec = (SkeletalExecutable<T>) exec.getType().newInstance();\r
65                 } catch (InstantiationException e) {\r
66                         log.error(e.getLocalizedMessage(), e);\r
67                         throw new JobSubmissionException(e.getLocalizedMessage(), e);\r
68                 } catch (IllegalAccessException e) {\r
69                         log.error(e.getLocalizedMessage(), e);\r
70                         throw new JobSubmissionException(e.getLocalizedMessage(), e);\r
71                 }\r
72                 exec.setInput(SkeletalExecutable.INPUT)\r
73                                 .setOutput(SkeletalExecutable.OUTPUT)\r
74                                 .setError(SkeletalExecutable.ERROR);\r
75                 return Configurator.configureExecutable(exec, sequences);\r
76         }\r
77 \r
78         public boolean cancelJob(String jobId) {\r
79                 WSUtil.validateJobId(jobId);\r
80                 return WSUtil.cancelJob(jobId);\r
81         }\r
82 \r
83         public JobStatus getJobStatus(String jobId) {\r
84                 WSUtil.validateJobId(jobId);\r
85                 return WSUtil.getJobStatus(jobId);\r
86         }\r
87 \r
88         public Limit<T> getLimit(String presetName) {\r
89                 if (limitMan == null) {\r
90                         // Limit is not defined\r
91                         return null;\r
92                 }\r
93                 return limitMan.getLimitByName(presetName);\r
94         }\r
95 \r
96         public LimitsManager<T> getLimits() {\r
97                 return limitMan;\r
98         }\r
99 \r
100         public PresetManager<T> getPresets() {\r
101                 return aaconPresets;\r
102         }\r
103 \r
104         public RunnerConfig<T> getRunnerOptions() {\r
105                 return aaconOptions;\r
106         }\r
107 \r
108         /**\r
109          * Assume statistics is not supported\r
110          * \r
111          * @param jobId\r
112          * @param position\r
113          * @return ChunkHolder\r
114          */\r
115         public ChunkHolder pullExecStatistics(String jobId, long position) {\r
116                 // Execution stat is not supported\r
117                 return new ChunkHolder("", -1);\r
118         }\r
119 }\r