1 /* Copyright (c) 2011 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0
\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
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
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
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
18 package compbio.ws.server;
\r
20 import java.util.List;
\r
22 import org.apache.log4j.Logger;
\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.engine.client.EngineUtil;
\r
30 import compbio.metadata.ChunkHolder;
\r
31 import compbio.metadata.JobStatus;
\r
32 import compbio.metadata.JobSubmissionException;
\r
33 import compbio.metadata.Limit;
\r
34 import compbio.metadata.LimitsManager;
\r
35 import compbio.metadata.PresetManager;
\r
36 import compbio.metadata.RunnerConfig;
\r
37 import compbio.runner.RunnerUtil;
\r
39 public abstract class GenericMetadataService<T> {
\r
41 private final RunnerConfig<T> aaconOptions;
\r
42 private final PresetManager<T> aaconPresets;
\r
43 private final LimitsManager<T> limitMan;
\r
44 private SkeletalExecutable<T> exec;
\r
48 * FIXME - instances of the Runner (?) and their types should be defined in
\r
51 GenericMetadataService(SkeletalExecutable<T> exec, Logger log) {
\r
53 assert exec != null;
\r
56 this.limitMan = EngineUtil.getLimits(exec.getType());
\r
57 this.aaconOptions = RunnerUtil.getSupportedOptions((Class<? extends Executable<T>>) exec.getType());
\r
58 this.aaconPresets = RunnerUtil.getPresets((Class<? extends Executable<T>>) exec.getType());
\r
61 ConfiguredExecutable<T> init(List<FastaSequence> sequences)
\r
62 throws JobSubmissionException {
\r
65 exec = (SkeletalExecutable<T>) exec.getType().newInstance();
\r
66 } catch (InstantiationException e) {
\r
67 log.error(e.getLocalizedMessage(), e);
\r
68 throw new JobSubmissionException(e.getLocalizedMessage(), e);
\r
69 } catch (IllegalAccessException e) {
\r
70 log.error(e.getLocalizedMessage(), e);
\r
71 throw new JobSubmissionException(e.getLocalizedMessage(), e);
\r
73 exec.setInput(SkeletalExecutable.INPUT)
\r
74 .setOutput(SkeletalExecutable.OUTPUT)
\r
75 .setError(SkeletalExecutable.ERROR);
\r
76 return Configurator.configureExecutable(exec, sequences);
\r
79 public boolean cancelJob(String jobId) {
\r
80 WSUtil.validateJobId(jobId);
\r
81 return WSUtil.cancelJob(jobId);
\r
84 public JobStatus getJobStatus(String jobId) {
\r
85 WSUtil.validateJobId(jobId);
\r
86 return WSUtil.getJobStatus(jobId);
\r
89 public Limit<T> getLimit(String presetName) {
\r
90 if (limitMan == null) {
\r
91 // Limit is not defined
\r
94 return limitMan.getLimitByName(presetName);
\r
97 public LimitsManager<T> getLimits() {
\r
101 public PresetManager<T> getPresets() {
\r
102 return aaconPresets;
\r
105 public RunnerConfig<T> getRunnerOptions() {
\r
106 return aaconOptions;
\r
110 * Assume statistics is not supported
\r
114 * @return ChunkHolder
\r
116 public ChunkHolder pullExecStatistics(String jobId, long position) {
\r
117 // Execution stat is not supported
\r
118 return new ChunkHolder("", -1);
\r