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.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
38 public abstract class GenericMetadataService<T> {
\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
47 * FIXME - instances of the Runner (?) and their types should be defined in
\r
50 GenericMetadataService(SkeletalExecutable<T> exec, Logger log) {
\r
52 assert exec != null;
\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
60 ConfiguredExecutable<T> init(List<FastaSequence> sequences)
\r
61 throws JobSubmissionException {
\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
72 exec.setInput(SkeletalExecutable.INPUT)
\r
73 .setOutput(SkeletalExecutable.OUTPUT)
\r
74 .setError(SkeletalExecutable.ERROR);
\r
75 return Configurator.configureExecutable(exec, sequences);
\r
78 public boolean cancelJob(String jobId) {
\r
79 WSUtil.validateJobId(jobId);
\r
80 return WSUtil.cancelJob(jobId);
\r
83 public JobStatus getJobStatus(String jobId) {
\r
84 WSUtil.validateJobId(jobId);
\r
85 return WSUtil.getJobStatus(jobId);
\r
88 public Limit<T> getLimit(String presetName) {
\r
89 if (limitMan == null) {
\r
90 // Limit is not defined
\r
93 return limitMan.getLimitByName(presetName);
\r
96 public LimitsManager<T> getLimits() {
\r
100 public PresetManager<T> getPresets() {
\r
101 return aaconPresets;
\r
104 public RunnerConfig<T> getRunnerOptions() {
\r
105 return aaconOptions;
\r
109 * Assume statistics is not supported
\r
113 * @return ChunkHolder
\r
115 public ChunkHolder pullExecStatistics(String jobId, long position) {
\r
116 // Execution stat is not supported
\r
117 return new ChunkHolder("", -1);
\r