| 1 | package App::FargateStack::Builder::TaskDefinition; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use App::FargateStack::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use App::FargateStack::Builder::Utils qw(log_die choose); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Basename qw(fileparse); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Data::Compare; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use List::Util qw(uniq); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Test::More; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub register_task_definition { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_task_definition: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my ( $self, $task_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my ( $config, $tasks, $dryrun ) = $self->common_args(qw(config tasks dryrun)); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $ecs = $self->get_ecs; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my $family = $tasks->{$task_name}->{family}; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my @task_definitions = map { $_->[0] } | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | sort { $a->[1] <=> $b->[1] } | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | map { [ $_, /:(\d+)$/ ? $1 : 0 ] } @{ $ecs->list_task_definitions( $family, 'taskDefinitionArns' ) // [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$ecs->list_task_definitions($family, "taskDefinitionArns") // []
MC/DC0%0/1
$ecs->list_task_definitions($family, "taskDefinitionArns") // []
$ecs->list_task_definitions($family, "taskDefinitionArns")
Truth table0%0/2
A
A= $ecs->list_task_definitions($family, "taskDefinitionArns")
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( $self->taskdef_has_changed($task_name) || !@task_definitions ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->taskdef_has_changed($task_name) or not @task_definitions
MC/DC0%0/2
$self->taskdef_has_changed($task_name) or not @task_definitions
$self->taskdef_has_changed($task_name)
not @task_definitions
Truth table0%0/3
A or not(B)
A= $self->taskdef_has_changed($task_name)B= not @task_definitions
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $taskdef = @task_definitions ? $task_definitions[-1] : "arn:???/$task_name"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( $taskdef =~ /:(\d+)$/xsm ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $version = $1 + 1; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $taskdef =~ s/\d+$/$version/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | $self->inc_required_resources( | ||||||||||||||||||||||||||||||||||||||||||
| 44 | task => [ | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my ($dryrun) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return $taskdef | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | if $taskdef !~ /[?]/xsm; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return $dryrun ? $taskdef : $tasks->{$task_name}->{arn}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ] | |||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $task_definition = sprintf 'taskdef-%s.json', $task_name; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $self->log_warn( | |||||||||||||||||||||||||||||||||||||||||
| 59 | 'register-task-definition: task definition for [%s] changed or does is not registered...will be registered...%s', | ||||||||||||||||||||||||||||||||||||||||||
| 60 | $task_name, $dryrun ); | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $self->log_warn( 'register-task-definition: registering task definition [%s]...', $task_name ); | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $result = $ecs->register_task_definition($task_definition); | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | log_die( $self, "ERROR: unable to register task definition: [%s]\n%s", $task_definition, $ecs->get_error ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | if !$result; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $tasks->{$task_name}->{arn} = $result->{taskDefinition}->{taskDefinitionArn}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->log_info( 'register-task-definition: task definition for: [%s] has not changed...skipping', $task_name ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $tasks->{$task_name}->{arn} = $task_definitions[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $self->inc_existing_resources( task => [ $task_definitions[-1] ] ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( !$tasks->{$task_name}->{image_digest} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | # update image digest in configuration | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $latest_image = $self->get_latest_image($task_name); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $latest_digest = $latest_image->{imageDigest}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( !$latest_digest ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->log_error('register-task-definition: unable to retrieve image digest...did you push it to ECR?'); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $self->log_warn( 'register-task-definition: updating image digest in config: [%s]', $latest_digest ); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $tasks->{$task_name}->{image_digest} = $latest_digest; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub taskdef_has_changed { goto &taskdef_status; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
taskdef_has_changed: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub taskdef_status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
taskdef_status: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my ( $self, $task, $action ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $action //= 'status'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$action //= "status"
MC/DC0%0/1
$action //= "status"
$action
Truth table0%0/2
A
A= $action
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $taskdef = "taskdef-$task.json"; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my ( $name, $path, $ext ) = fileparse( $taskdef, qr/[.][^.]+$/xsm ); | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return !$self->get_taskdef_status->{$task}; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub create_role_arn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_role_arn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ( $self, $role_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return sprintf 'arn:aws:iam::%s:role/%s', $self->get_account, $role_name; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub define_port_mapping { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define_port_mapping: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my ( $task, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | return | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if !$type || $type !~ /^http/xsm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type and $type =~ /^http/msx
MC/DC0%0/2
$type and $type =~ /^http/msx
$type
$type =~ /^http/msx
Truth table0%0/3
A and B
A= $typeB= $type =~ /^http/msx
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # use port or specify container_port, host_port - pick your poison | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $port = $task->{port} // $DEFAULT_PORT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$task->{"port"} // $App::FargateStack::Builder::TaskDefinition::DEFAULT_PORT
MC/DC0%0/2
$task->{"port"} // $App::FargateStack::Builder::TaskDefinition::DEFAULT_PORT
$task->{"port"}
$App::FargateStack::Builder::TaskDefinition::DEFAULT_PORT
Truth table0%0/3
A // B
A= $task->{"port"}B= $App::FargateStack::Builder::TaskDefinition::DEFAULT_PORT
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $container_port = $task->{container_port} // $DEFAULT_PORT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$task->{"container_port"} // $App::FargateStack::Builder::TaskDefinition::DEFAULT_PORT
MC/DC0%0/2
$task->{"container_port"} // $App::FargateStack::Builder::TaskDefinition::DEFAULT_PORT
$task->{"container_port"}
$App::FargateStack::Builder::TaskDefinition::DEFAULT_PORT
Truth table0%0/3
A // B
A= $task->{"container_port"}B= $App::FargateStack::Builder::TaskDefinition::DEFAULT_PORT
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | { protocol => 'tcp', | |||||||||||||||||||||||||||||||||||||||||
| 140 | containerPort => 0 + $container_port, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | hostPort => 0 + $port, | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub define_task_size { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define_task_size: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my ( $task, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my ( $cpu, $memory, $size ) = @{$task}{qw(cpu memory size)}; | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | return ( $cpu, $memory, $size ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $size and defined $cpu and defined $memory
defined $size and defined $cpu
MC/DC0%0/3
defined $size and defined $cpu and defined $memory
defined $size
defined $cpu
defined $memory
Truth table0%0/4
A and B and C
A= defined $sizeB= defined $cpuC= defined $memory
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | if defined $size && defined $cpu && defined $memory; | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ( defined $cpu && defined $memory ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cpu and defined $memory
MC/DC0%0/2
defined $cpu and defined $memory
defined $cpu
defined $memory
Truth table0%0/3
A and B
A= defined $cpuB= defined $memory
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | ($size) = grep { $ECS_TASK_PROFILES{$_}->{cpu} eq $cpu && $ECS_TASK_PROFILES{$_}->{memory} eq $memory } | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILES{$_}{'cpu'} eq $cpu && $App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILES{$_}{'memory'} eq $memory
MC/DC0%0/2
$App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILES{$_}{'cpu'} eq $cpu && $App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILES{$_}{'memory'} eq $memory
$App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILES{$_}{'cpu'} eq $cpu
$App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILES{$_}{'memory'} eq $memory
Truth table0%0/3
A && B
A= $App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILES{$_}{'cpu'} eq $cpuB= $App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILES{$_}{'memory'} eq $memory
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | keys %ECS_TASK_PROFILES; | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ($size) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $task->{size} = $size; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | return ( $cpu, $memory, $size ); | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | my $logical_type = choose { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return 'web' if $type =~ /http/xsm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return 'daemon' if $type eq 'daemon'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return 'job' if $type eq 'task' && $task->{schedule}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "task" and $task->{"schedule"}
MC/DC0%0/2
$type eq "task" and $task->{"schedule"}
$type eq "task"
$task->{"schedule"}
Truth table0%0/3
A and B
A= $type eq "task"B= $task->{"schedule"}
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return 'task'; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $size //= $ECS_TASK_PROFILE_TYPES{$logical_type}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$size //= $App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILE_TYPES{$logical_type}
MC/DC0%0/2
$size //= $App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILE_TYPES{$logical_type}
$size
$App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILE_TYPES{$logical_type}
Truth table0%0/3
A //= B
A= $sizeB= $App::FargateStack::Builder::TaskDefinition::ECS_TASK_PROFILE_TYPES{$logical_type}
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if ($size) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $profile = $ECS_TASK_PROFILES{$size}; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | croak sprintf "ERROR: unknown profile: [%s], valid profiles: [%s]\n", $size, join q{,}, keys %ECS_TASK_PROFILES | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | if !$profile; | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | $cpu //= $profile->{cpu}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$cpu //= $profile->{"cpu"}
MC/DC0%0/2
$cpu //= $profile->{"cpu"}
$cpu
$profile->{"cpu"}
Truth table0%0/3
A //= B
A= $cpuB= $profile->{"cpu"}
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $memory //= $profile->{memory}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$memory //= $profile->{"memory"}
MC/DC0%0/2
$memory //= $profile->{"memory"}
$memory
$profile->{"memory"}
Truth table0%0/3
A //= B
A= $memoryB= $profile->{"memory"}
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return ( $cpu, $memory, $size ); | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub create_taskdef_files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_taskdef_files: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my ( $config, $services ) = $self->common_args(qw(config tasks)); | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | foreach my $task_name ( keys %{$services} ) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $task = $services->{$task_name}; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | $task->{type} //= 'task'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$task->{"type"} //= "task"
MC/DC0%0/1
$task->{"type"} //= "task"
$task->{"type"}
Truth table0%0/2
A
A= $task->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $type = $task->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | # -- port mappings -- | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $portMapping = define_port_mapping( $task, $type ); | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($portMapping) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | @{$task}{qw(container_port host_port)} = @{ $portMapping->[0] }{qw(containerPort hostPort)}; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # -- log group/stream prefix -- | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # Note: the default log group name was set earlier...and task will | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # be updated when (and if) we create the log group... | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $log_group = $config->{log_group}->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $stream_prefix = $config->{app}->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # -- image name -- | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $image = $self->resolve_image_name( $task->{image} ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # -- environment -- | ||||||||||||||||||||||||||||||||||||||||||
| 222 | my @environment | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | = map { { name => $_, value => $task->{environment}->{$_} } } keys %{ $task->{environment} // {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$task->{"environment"} // {}
MC/DC0%0/1
$task->{"environment"} // {}
$task->{"environment"}
Truth table0%0/2
A
A= $task->{"environment"}
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | # -- task name/family -- | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my ( $name, $family ) = @{$task}{qw(name family)}; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | $task->{name} //= $task_name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$task->{"name"} //= $task_name
MC/DC0%0/2
$task->{"name"} //= $task_name
$task->{"name"}
$task_name
Truth table0%0/3
A //= B
A= $task->{"name"}B= $task_name
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | $task->{family} //= $task_name; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$task->{"family"} //= $task_name
MC/DC0%0/2
$task->{"family"} //= $task_name
$task->{"family"}
$task_name
Truth table0%0/3
A //= B
A= $task->{"family"}B= $task_name
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | # -- task size -- | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my ( $cpu, $memory, $size ) = define_task_size( $task, $type ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | $task->{size} //= $size; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$task->{"size"} //= $size
MC/DC0%0/2
$task->{"size"} //= $size
$task->{"size"}
$size
Truth table0%0/3
A //= B
A= $task->{"size"}B= $size
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $task->{memory} //= $memory // $DEFAULT_MEMORY_SIZE; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$task->{"memory"} //= $memory // $App::FargateStack::Builder::TaskDefinition::DEFAULT_MEMORY_SIZE
$memory // $App::FargateStack::Builder::TaskDefinition::DEFAULT_MEMORY_SIZE
MC/DC0%0/3
$task->{"memory"} //= $memory // $App::FargateStack::Builder::TaskDefinition::DEFAULT_MEMORY_SIZE
$task->{"memory"}
$memory
$App::FargateStack::Builder::TaskDefinition::DEFAULT_MEMORY_SIZE
Truth table0%0/4
A //= B // C
A= $task->{"memory"}B= $memoryC= $App::FargateStack::Builder::TaskDefinition::DEFAULT_MEMORY_SIZE
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | $task->{cpu} //= $cpu // $DEFAULT_CPU_SIZE; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$task->{"cpu"} //= $cpu // $App::FargateStack::Builder::TaskDefinition::DEFAULT_CPU_SIZE
$cpu // $App::FargateStack::Builder::TaskDefinition::DEFAULT_CPU_SIZE
MC/DC0%0/3
$task->{"cpu"} //= $cpu // $App::FargateStack::Builder::TaskDefinition::DEFAULT_CPU_SIZE
$task->{"cpu"}
$cpu
$App::FargateStack::Builder::TaskDefinition::DEFAULT_CPU_SIZE
Truth table0%0/4
A //= B // C
A= $task->{"cpu"}B= $cpuC= $App::FargateStack::Builder::TaskDefinition::DEFAULT_CPU_SIZE
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | # -- secrets (from App::Fargate::Builder::Secrets) | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | my $secrets = $self->add_secrets($task) // []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->add_secrets($task) // []
MC/DC0%0/1
$self->add_secrets($task) // []
$self->add_secrets($task)
Truth table0%0/2
A
A= $self->add_secrets($task)
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # -- efs mounts -- | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my ( $volumes, $mount_points ) = $self->add_volumes($task); | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | my $role_name = $config->{role}->{name} // $self->create_default( 'role-name', 'ecs' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$config->{"role"}{"name"} // $self->create_default("role-name", "ecs")
MC/DC0%0/2
$config->{"role"}{"name"} // $self->create_default("role-name", "ecs")
$config->{"role"}{"name"}
$self->create_default("role-name", "ecs")
Truth table0%0/3
A // B
A= $config->{"role"}{"name"}B= $self->create_default("role-name", "ecs")
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my $task_role_name = $config->{task_role}->{name} // $self->create_default( 'role-name', 'task' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$config->{"task_role"}{"name"} // $self->create_default("role-name", "task")
MC/DC0%0/2
$config->{"task_role"}{"name"} // $self->create_default("role-name", "task")
$config->{"task_role"}{"name"}
$self->create_default("role-name", "task")
Truth table0%0/3
A // B
A= $config->{"task_role"}{"name"}B= $self->create_default("role-name", "task")
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # Note that we create the role ARNs rather than taking them from | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # the config. This is because we create the task definition before | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # we actually create the roles. The role ARN is determistic...so | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # why not? | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | my $taskdef = { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | executionRoleArn => $self->create_role_arn($role_name), | ||||||||||||||||||||||||||||||||||||||||||
| 252 | taskRoleArn => $self->create_role_arn($task_role_name), | ||||||||||||||||||||||||||||||||||||||||||
| 253 | memory => "$task->{memory}", | ||||||||||||||||||||||||||||||||||||||||||
| 254 | containerDefinitions => [ | ||||||||||||||||||||||||||||||||||||||||||
| 255 | { logConfiguration => { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | options => { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 'awslogs-region' => $config->{region}, | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 'awslogs-stream-prefix' => $stream_prefix, | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 'awslogs-group' => $log_group | ||||||||||||||||||||||||||||||||||||||||||
| 260 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | logDriver => q{awslogs} | ||||||||||||||||||||||||||||||||||||||||||
| 262 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 263 | environment => \@environment, | ||||||||||||||||||||||||||||||||||||||||||
| 264 | secrets => $secrets, | ||||||||||||||||||||||||||||||||||||||||||
| 265 | portMappings => $portMapping // [], | ||||||||||||||||||||||||||||||||||||||||||
| 266 | essential => JSON::true, | ||||||||||||||||||||||||||||||||||||||||||
| 267 | name => $task->{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 268 | $task->{command} ? ( command => [ $task->{command} ] ) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 269 | image => $image, | ||||||||||||||||||||||||||||||||||||||||||
| 270 | mountPoints => $mount_points // [], | ||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 273 | cpu => "$task->{cpu}", | ||||||||||||||||||||||||||||||||||||||||||
| 274 | requiresCompatibilities => [q{FARGATE}], | ||||||||||||||||||||||||||||||||||||||||||
| 275 | networkMode => q{awsvpc}, | ||||||||||||||||||||||||||||||||||||||||||
| 276 | family => $task->{family}, | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | volumes => $volumes // [], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$portMapping // []
$mount_points // []
$volumes // []
MC/DC0%0/1
$portMapping // []
$portMapping
MC/DC0%0/1
$mount_points // []
$mount_points
MC/DC0%0/1
$volumes // []
$volumes
Truth table0%0/2
A
A= $portMapping
Truth table0%0/2
A
A= $mount_points
Truth table0%0/2
A
A= $volumes
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | $self->log_trace( sub { return Dumper( [ taskdef => $taskdef ] ); } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $self->write_taskdef( $task_name, $taskdef ); | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return $TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | sub write_taskdef { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_taskdef: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my ( $self, $task_name, $taskdef ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $taskdef_file = sprintf 'taskdef-%s.json', $task_name; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $self->compare_task_definition( $task_name, $taskdef, $taskdef_file ); | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $self->log_info( 'task: [%s] saving task definition file...[%s]', $task_name, $taskdef_file ); | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | open my $fh, '>', $taskdef_file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | or croak "could not open $taskdef_file for writing\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | print {$fh} JSON->new->pretty->encode($taskdef); | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | sub compare_task_definition { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compare_task_definition: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my ( $self, $task_name, $taskdef, $taskdef_file ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $ecs = $self->get_ecs; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $task = $config->{tasks}->{$task_name}; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | my $taskdef_status = $self->get_taskdef_status // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->get_taskdef_status // {}
MC/DC0%0/1
$self->get_taskdef_status // {}
$self->get_taskdef_status
Truth table0%0/2
A
A= $self->get_taskdef_status
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $current_taskdef = $ecs->describe_task_definition( $task_name, 'taskDefinition' ); | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if ( !$current_taskdef ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $taskdef_status->{$task_name} = $FALSE; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $self->set_taskdef_status($taskdef_status); | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $config->{tasks}->{$task_name}->{arn} = $current_taskdef->{taskDefinitionArn}; | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | my $status = -s $taskdef_file ? $TRUE : $FALSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ( !$status ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $self->log_warn( 'task: [%s] no task definition file [%s]...forces new task definition', $task_name, $taskdef_file ); | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | foreach my $k ( keys %{$taskdef} ) { | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | next if $k eq 'containerDefinitions'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ( ref( $current_taskdef->{$k} ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | next if array_compare( $taskdef->{$k}, $current_taskdef->{$k} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | next if Compare( $taskdef->{$k}, $current_taskdef->{$k} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $self->log_warn( 'task: [%s] %s changed...forces new task definition', $task_name, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | $self->log_trace( | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | return Dumper( | ||||||||||||||||||||||||||||||||||||||||||
| 354 | [ taskdef => $taskdef->{$k}, | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | "current_$k" => $current_taskdef->{$k}, | |||||||||||||||||||||||||||||||||||||||||
| 356 | current => $current_taskdef | ||||||||||||||||||||||||||||||||||||||||||
| 357 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 358 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $self->display_diffs( $taskdef->{$k}, $current_taskdef->{$k}, { title => sprintf '%s changes', $k } ); | |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $status = $FALSE; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my $containerDefinitions = $taskdef->{containerDefinitions}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | my @keys_to_check = ( | ||||||||||||||||||||||||||||||||||||||||||
| 370 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 371 | mountPoints | ||||||||||||||||||||||||||||||||||||||||||
| 372 | portMappings | ||||||||||||||||||||||||||||||||||||||||||
| 373 | command | ||||||||||||||||||||||||||||||||||||||||||
| 374 | environment | ||||||||||||||||||||||||||||||||||||||||||
| 375 | image | ||||||||||||||||||||||||||||||||||||||||||
| 376 | name | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | secrets), keys %{$containerDefinitions} | |||||||||||||||||||||||||||||||||||||||||
| 378 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | foreach my $k ( uniq @keys_to_check ) { | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $current_elem = $current_taskdef->{containerDefinitions}->[0]->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if ( ref($current_elem) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | next if array_compare( $current_elem, $containerDefinitions->{$k} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | next if Compare( $containerDefinitions->{$k}, $current_elem ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $self->log_warn( 'task: [%s] %s changed...forces new task definition', $task_name, $k ); | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $self->display_diffs( $current_elem, $containerDefinitions->{$k}, { title => sprintf '%s changes', $k } ); | |||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $status = $FALSE; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $taskdef_status->{$task_name} = $status; | |||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->set_taskdef_status($taskdef_status); | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | sub array_compare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
array_compare: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my ( $array1, $array2 ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | return $FALSE | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$array1 and not $array2
MC/DC0%0/2
$array1 and not $array2
$array1
not $array2
Truth table0%0/3
A and not(B)
A= $array1B= not $array2
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | if $array1 && !$array2; | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | return $FALSE | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $array1 and $array2
MC/DC0%0/2
not $array1 and $array2
not $array1
$array2
Truth table0%0/3
not(A) and B
A= not $array1B= $array2
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | if !$array1 && $array2; | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | return $FALSE | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if @{$array1} != @{$array2}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my $json = JSON->new->canonical; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | my $array1_sorted = join q{}, sort map { ref $_ ? $json->encode($_) : $_ } @{$array1}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | my $array2_sorted = join q{}, sort map { ref $_ ? $json->encode($_) : $_ } @{$array2}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return $array1_sorted eq $array2_sorted; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||