Skip to content

Commit 4317c20

Browse files
committed
Wrapup of new app service code for new release.
1 parent 146f420 commit 4317c20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3119
-757
lines changed

AppConfig.pm.tt

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,35 @@ use constant binning_spades_threads => '[% binning_spades_threads %]';
1616
use constant binning_spades_ram => '[% binning_spades_ram %]';
1717

1818
use constant sched_db_host => '[% sched_db_host %]';
19+
use constant sched_db_port => '[% sched_db_port %]';
1920
use constant sched_db_user => '[% sched_db_user %]';
2021
use constant sched_db_pass => '[% sched_db_pass %]';
2122
use constant sched_db_name => '[% sched_db_name %]';
2223

24+
use constant redis_host => '[% redis_host %]';
25+
use constant redis_port => '[% redis_port %]';
26+
use constant redis_db => '[% redis_db %]';
27+
2328
use constant slurm_control_task_partition => '[% slurm_control_task_partition %]';
2429

2530
use constant bebop_binning_user => '[% bebop_binning_user %]';
2631
use constant bebop_binning_key => '[% bebop_binning_key %]';
2732

33+
use constant app_directory => '[% app_directory %]';
34+
use constant app_service_url => '[% app_service_url %]';
35+
2836
use base 'Exporter';
2937
our @EXPORT_OK = qw(data_api_url github_issue_repo_owner github_issue_repo_name github_issue_token
3038
db_host db_user db_pass db_name
3139
seedtk reference_data_dir
3240
bebop_binning_user bebop_binning_key
33-
sched_db_host sched_db_user sched_db_pass sched_db_name
41+
sched_db_host sched_db_port sched_db_user sched_db_pass sched_db_name
3442
slurm_control_task_partition
3543
binning_spades_threads binning_spades_ram
36-
binning_genome_annotation_clientgroup mash_reference_sketch);
44+
binning_genome_annotation_clientgroup mash_reference_sketch
45+
app_directory app_service_url
46+
redis_host redis_port redis_db
47+
);
3748
our %EXPORT_TAGS = (all => [@EXPORT_OK]);
3849
1;
3950

AppService.spec

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module AppService
4242
string submit_time;
4343
string start_time;
4444
string completed_time;
45+
string elapsed_time;
4546

4647
string stdout_shock_node;
4748
string stderr_shock_node;
@@ -79,6 +80,8 @@ module AppService
7980

8081
funcdef query_task_summary() returns (mapping<task_status status, int count> status);
8182

83+
funcdef query_app_summary() returns (mapping<app_id app, int count> status);
84+
8285
typedef structure {
8386
string stdout_url;
8487
string stderr_url;
@@ -91,6 +94,17 @@ module AppService
9194
funcdef enumerate_tasks(int offset, int count)
9295
returns (list<Task>);
9396

97+
typedef structure {
98+
string start_time;
99+
string end_time;
100+
app_id app;
101+
string search;
102+
string status;
103+
} SimpleTaskFilter;
104+
funcdef enumerate_tasks_filtered(int offset, int count, SimpleTaskFilter simple_filter)
105+
returns (list<Task> tasks, int total_tasks);
106+
94107
funcdef kill_task(task_id id) returns (int killed, string msg);
95-
funcdef rerun_task(task_id id) returns (task_id new_task);
108+
funcdef kill_tasks(list<task_id> ids) returns (mapping<task_id, structure { int killed; string msg; }>);
109+
funcdef rerun_task(task_id id) returns (Task task);
96110
};

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SERVICE_MODULE = lib/Bio/KBase/AppService/Service.pm
1111
SERVICE = app_service
1212
SERVICE_PORT = 7124
1313

14+
SLURM_PATH = /disks/patric-common/slurm
1415
SLURM_CONTROL_TASK_PARTITION = watcher
1516

1617
SERVICE_URL = http://p3.theseed.org/services/$(SERVICE)
@@ -19,6 +20,7 @@ SERVICE_NAME = AppService
1920
SERVICE_NAME_PY = $(SERVICE_NAME)
2021

2122
SERVICE_PSGI_FILE = $(SERVICE_NAME).psgi
23+
SERVICE_ASYNC_PSGI_FILE = $(SERVICE_NAME)Async.psgi
2224

2325
SRC_SERVICE_PERL = $(wildcard service-scripts/*.pl)
2426
BIN_SERVICE_PERL = $(addprefix $(BIN_DIR)/,$(basename $(notdir $(SRC_SERVICE_PERL))))
@@ -41,6 +43,8 @@ REFERENCE_DATA_DIR = /tmp
4143

4244
MASH_REFERENCE_SKETCH = /vol/patric3/production/data/trees/listOfRepRefGenomeFnaFiles.txt.msh
4345

46+
APP_DIRECTORY = app_specs
47+
4448
ifdef TEMPDIR
4549
TPAGE_TEMPDIR = --define kb_tempdir=$(TEMPDIR)
4650
endif
@@ -62,16 +66,22 @@ TPAGE_ARGS = \
6266
--define kb_service_name=$(SERVICE) \
6367
--define kb_service_port=$(SERVICE_PORT) \
6468
--define kb_psgi=$(SERVICE_PSGI_FILE) \
69+
--define kb_async_psgi=$(SERVICE_ASYNC_PSGI_FILE) \
6570
--define kb_starman_workers=$(STARMAN_WORKERS) \
6671
--define data_api_url=$(DATA_API_URL) \
72+
--define redis_host=$(REDIS_HOST) \
73+
--define redis_port=$(REDIS_PORT) \
74+
--define redis_db=$(REDIS_DB) \
6775
--define db_host=$(DB_HOST) \
6876
--define db_user=$(DB_USER) \
6977
--define db_pass=$(DB_PASS) \
7078
--define db_name=$(DB_NAME) \
7179
--define sched_db_host=$(SCHED_DB_HOST) \
80+
--define sched_db_port=$(SCHED_DB_PORT) \
7281
--define sched_db_user=$(SCHED_DB_USER) \
7382
--define sched_db_pass=$(SCHED_DB_PASS) \
7483
--define sched_db_name=$(SCHED_DB_NAME) \
84+
--define slurm_path=$(SLURM_PATH) \
7585
--define slurm_control_task_partition=$(SLURM_CONTROL_TASK_PARTITION) \
7686
--define seedtk=$(SEEDTK) \
7787
--define github_issue_repo_owner=$(GITHUB_ISSUE_REPO_OWNER) \
@@ -84,6 +94,8 @@ TPAGE_ARGS = \
8494
--define bebop_binning_key=$(BEBOP_BINNING_KEY) \
8595
--define bebop_binning_user=$(BEBOP_BINNING_USER) \
8696
--define mash_reference_sketch=$(MASH_REFERENCE_SKETCH) \
97+
--define app_directory=$(APP_DIRECTORY) \
98+
--define app_service_url=$(SERVICE_URL) \
8799
$(TPAGE_SERVICE_LOGDIR) \
88100
$(TPAGE_TEMPDIR)
89101

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
app_service
22
=================
3+

app_specs/GenomeAssembly2.json

+8
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@
179179
"default": null,
180180
"desc": "Basename for the generated output files. Defaults to the basename of the input data.",
181181
"type": "wsid"
182+
},
183+
{
184+
"id": "debug_level",
185+
"label": "Debug level",
186+
"required": 0,
187+
"default": 0,
188+
"desc": "Debugging level.",
189+
"type": "int"
182190
}
183191
]
184192
}

app_specs/MetagenomicReadMapping.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "MetagenomicReadMapping",
33
"label": "Metagenomic read mapping",
4-
"script": "AppWrapper-MetagenomicReadMapping",
4+
"script": "App-MetagenomicReadMapping",
55
"description": "Map metagenomic reads to a defined gene set",
66
"default_memory": "100G",
77
"parameters": [

deploy.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ app-directory = app_specs
99
; Directory into which task status (stdout/err etc) are written
1010
;
1111

12-
; task-status-dir =
12+
task-status-dir = /disks/p3/task_status
1313

1414
;
1515
; AWE client group to submit jobs iwth

lib/AppServiceAsync.psgi

+29-40
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,59 @@
1+
use Twiggy;
2+
13
use Bio::KBase::AppService::AppServiceImpl;
24
use Bio::KBase::AppService::Monitor;
35
use Bio::KBase::AppService::Quick;
46
use Bio::KBase::AppService::AsyncService;
57

68
use Bio::KBase::AppService::AppSpecs;
7-
use Bio::KBase::AppService::Scheduler;
89
use Bio::KBase::AppService::SlurmCluster;
910

10-
#use Carp::Always;
11+
# use Carp::Always;
1112

1213
use Plack::Middleware::CrossOrigin;
1314
use Plack::Builder;
1415
use Data::Dumper;
16+
use Log::Dispatch;
17+
use Log::Dispatch::File;
1518

1619
my @dispatch;
1720

1821
my $obj = Bio::KBase::AppService::AppServiceImpl->new;
1922

20-
my $specs = Bio::KBase::AppService::AppSpecs->new($obj->{app_dir});
21-
print Dumper($specs);
22-
23-
my $sched = Bio::KBase::AppService::Scheduler->new(specs => $specs);
24-
$sched->{task_start_disable} = 0;
25-
$sched->load_apps();
26-
27-
my $cluster = Bio::KBase::AppService::SlurmCluster->new('TSlurm',
28-
schema => $sched->schema);
29-
30-
my $shared_cluster = Bio::KBase::AppService::SlurmCluster->new('Bebop',
31-
schema => $sched->schema,
32-
resources => ["-p bdws",
33-
"-N 1",
34-
"--ntasks-per-node 1",
35-
"--time 1:00:00"]);
36-
my $bebop_cluster = Bio::KBase::AppService::SlurmCluster->new('Bebop',
37-
schema => $sched->schema,
38-
resources => [
39-
"-p bdwd",
40-
"-x bdwd-0050",
41-
# "-p bdwall",
42-
"-N 1",
43-
"-A PATRIC",
44-
"--ntasks-per-node 1"],
45-
environment_config => ['module add jdk'], ['module add gnuplot']);
23+
my $logger;
24+
if (my $f = $ENV{APP_SERVICE_STDERR})
25+
{
26+
$logger = Log::Dispatch->new;
27+
$logger->add( Log::Dispatch::File->new(filename => $f, min_level => 'debug'));
28+
}
4629

4730

31+
my $specs = Bio::KBase::AppService::AppSpecs->new($obj->{app_dir});
32+
print Dumper($specs);
4833

49-
$sched->default_cluster($cluster);
50-
51-
$obj->{util}->scheduler($sched);
5234
Bio::KBase::AppService::Monitor::set_impl($obj);
5335
Bio::KBase::AppService::Quick::set_impl($obj);
5436

5537
my $server = Bio::KBase::AppService::AsyncService->new(impl => $obj);
5638

5739
my $rpc_handler = sub { $server->handle_rpc(@_); };
5840

41+
print Dumper($logger);
42+
5943
$handler = builder {
60-
mount "/ping" => sub { $server->ping(@_); };
61-
mount "/auth_ping" => sub { $server->auth_ping(@_); };
62-
mount "/task_info" => sub { $obj->_task_info(@_); };
63-
mount "/monitor" => Bio::KBase::AppService::Monitor->psgi_app;
64-
mount "/quick" => Bio::KBase::AppService::Quick->psgi_app;
65-
mount "/" => $rpc_handler;
44+
if ($logger)
45+
{
46+
enable 'LogDispatch', logger => $logger;
47+
enable 'LogStderr', no_tie => 1;
48+
}
49+
builder {
50+
mount "/ping" => sub { $server->ping(@_); };
51+
mount "/auth_ping" => sub { $server->auth_ping(@_); };
52+
mount "/task_info" => sub { $obj->_task_info(@_); };
53+
mount "/monitor" => Bio::KBase::AppService::Monitor->psgi_app;
54+
mount "/quick" => Bio::KBase::AppService::Quick->psgi_app;
55+
mount "/" => $rpc_handler;
56+
};
6657
};
6758

68-
$sched->start_timers();
69-
70-
$handler = Plack::Middleware::CrossOrigin->wrap( $handler, origins => "*", headers => "*");
59+
$handler = Plack::Middleware::CrossOrigin->wrap( $handler, origins => "*", headers => "*", max_age => 86400);

lib/Bio/KBase/AppService/AppScript-devslurm.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ sub run
216216
{
217217
open(my $fh, ">", $opt->preflight) or die "Cannot write preflight to " . $opt->preflight . ": $!";
218218
my $data = $self->run_preflight();
219-
print Dumper($data);
219+
print STDERR Dumper($data);
220220
if (ref($data) eq 'HASH')
221221
{
222222
print $fh $self->json->encode($data);

lib/Bio/KBase/AppService/AppScript.pm

+40-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use Data::Dumper;
2525

2626
__PACKAGE__->mk_accessors(qw(execute_callback preflight_callback donot_create_job_result donot_create_result_folder
2727
workspace_url workspace params raw_params app_definition result_folder
28-
json host
28+
json
2929
task_id app_service_url));
3030

3131
=head1 NAME
@@ -172,15 +172,10 @@ sub new
172172
{
173173
my($class, $execute_callback, $preflight_callback) = @_;
174174

175-
my $host = `hostname -f`;
176-
$host = `hostname` if !$host;
177-
chomp $host;
178-
179175
my $self = {
180176
execute_callback => $execute_callback,
181177
preflight_callback => $preflight_callback,
182178
start_time => scalar gettimeofday,
183-
host => $host,
184179
json => JSON::XS->new->pretty(1),
185180
};
186181

@@ -191,6 +186,20 @@ sub new
191186
return $self;
192187
}
193188

189+
sub host
190+
{
191+
my($self) = @_;
192+
my $host;
193+
if (!defined($host = $self->{host}))
194+
{
195+
$host = `hostname -f`;
196+
$host = `hostname` if !$host;
197+
chomp $host;
198+
$self->{host} = $host;
199+
}
200+
return $host;
201+
}
202+
194203
sub run_preflight
195204
{
196205
my($self) = @_;
@@ -257,7 +266,6 @@ sub run
257266
{
258267
open(my $fh, ">", $opt->preflight) or die "Cannot write preflight to " . $opt->preflight . ": $!";
259268
my $data = $self->run_preflight();
260-
print Dumper($data);
261269
if (ref($data) eq 'HASH')
262270
{
263271
print $fh $self->json->encode($data);
@@ -427,10 +435,6 @@ sub set_task_id
427435
#
428436
# Hack to finding task id.
429437
#
430-
my $host = `hostname -f`;
431-
$host = `hostname` if !$host;
432-
chomp $host;
433-
$self->host($host);
434438

435439
my $task_id = 'TBD';
436440
if ($ENV{AWE_TASK_ID})
@@ -447,6 +451,7 @@ sub set_task_id
447451
}
448452
else
449453
{
454+
my $host = $self->host;
450455
$task_id = "UNK-$host-$$";
451456
$task_id =~ s/\./_/g;
452457
}
@@ -462,6 +467,14 @@ sub create_result_folder
462467
my $result_folder = $base_folder . "/." . $self->params->{output_file};
463468
$self->result_folder($result_folder);
464469
$self->workspace->create({overwrite => 1, objects => [[$result_folder, 'folder', { application_type => $self->app_definition->{id}}]]});
470+
471+
#
472+
# Remove any job failed reports that were left from a prior run.
473+
#
474+
eval { $self->workspace->delete({ objects => ["$result_folder/JobFailed.txt"] }) };
475+
# if ($@) { warn "delete $result_folder/JobFailed.txt failed: $@"; }
476+
eval { $self->workspace->delete({ objects => ["$result_folder/JobFailed.html"] }) };
477+
# if ($@) { warn "delete $result_folder/JobFailed.html failed: $@"; }
465478
}
466479

467480
sub token
@@ -521,6 +534,22 @@ sub preprocess_parameters
521534
if (exists($params->{$id}))
522535
{
523536
my $value = $params->{$param->{id}};
537+
538+
if ($param->{type} eq 'bool')
539+
{
540+
if ($value eq 'false')
541+
{
542+
print STDERR "Fixing false value to 0 for $id\n";
543+
$value = 0;
544+
}
545+
elsif ($value eq 'true')
546+
{
547+
print STDERR "Fixing true value to 1 for $id\n";
548+
$value = 1;
549+
}
550+
}
551+
552+
524553
#
525554
# Maybe validate.
526555
#

0 commit comments

Comments
 (0)