2 # Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
3 # Copyright [2016-2023] EMBL-European Bioinformatics Institute
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # An equivalent of 'bjobs' for Docker Swarm meadow
20 # For REST API documentation see https://docs.docker.com/engine/api/v1.30/
26 my $docker_master_addr = $ENV{DOCKER_MASTER_ADDR}
27 || die
"Please make sure the environment variable DOCKER_MASTER_ADDR is set to your Docker Master's IP followed by colon and Docker REST port number (usually 2375)\n";
29 my $optional_service_name = $ARGV[0]; #
this is the only optional argument of
this script
31 my $common_url =
"http://$docker_master_addr/v1.30";
34 my $swarm_id = $rest_client->GET(
'/swarm' )->{
'ID'};
36 my $nodes_listref = $rest_client->GET(
'/nodes' );
37 #my %node_id2addr = map { $_->{'ID'} => $_->{'Status'}{'Addr'} } @$nodes_listref;
38 #my %node_id2name = map { $_->{'ID'} => $_->{'Description'}{'Hostname'} } @$nodes_listref; # NB: these are not unique!
39 my %node_id2addrname =
map { $_->{
'ID'} => $_->{
'Status'}{
'Addr'} .
'/'. $_->{
'Description'}{
'Hostname'} } @$nodes_listref;
41 my $services_listref = $rest_client->GET(
'/services',
'services.json');
42 my %service_id2name =
map { $_->{
'ID'} => $_->{
'Spec'}{
'Name'} } @$services_listref;
44 my $service_tasks_list = $optional_service_name
45 ? $rest_client->GET(
'/tasks?filters={"name":["' . $optional_service_name .
'"]}' ) # either filtered data...
46 : $rest_client->GET(
'/tasks' ); # ... or all available task data
48 print join(
"\t",
'Service_ID',
'Service_name_and_index',
'Task_ID',
'Status',
'Node_ID',
'Node_name').
"\n";
49 foreach my $entry (sort { ($a->{
'ServiceID'} cmp $b->{
'ServiceID'}) or ($a->{
'Slot'} <=> $b->{
'Slot'}) } @$service_tasks_list) {
50 my $service_id = $entry->{
'ServiceID'};
51 my $service_name = $service_id2name{ $service_id };
52 my $slot = $entry->{
'Slot'};
53 my $task_id = $entry->{
'ID'};
54 my $status = $entry->{
'Status'}{
'State'};
55 my $node_id = $entry->{
'NodeID'};
56 my $node_name = $node_id && $node_id2addrname{ $node_id };
58 print join(
"\t", $service_id, $service_name.
'['.$slot.
']', $task_id, $status, $node_id ||
'-', $node_name ||
'-').
"\n";