| 1 | # | ||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | # vim: set ts=2 sw=2 tw=0: | ||||||||||||||||||||
| 5 | # vim: set expandtab: | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | package Rex::JobControl::Helper::Project; | ||||||||||||||||||||
| 8 | 1 | $Rex::JobControl::Helper::Project::VERSION = '0.18.0'; | |||||||||||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use File::Path; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use YAML; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 1 | ▶ | use Digest::MD5 'md5_hex'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 1 | ▶ | use Rex::JobControl::Helper::Project::Job; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 1 | ▶ | use Rex::JobControl::Helper::Project::Rexfile; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | ▶ | use Rex::JobControl::Helper::Project::Formular; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 22 | 0 | my $that = shift; | |||||||||||||||||||
| 23 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 24 | 0 | my $self = {@_}; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | bless( $self, $proto ); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | $self->load; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | return $self; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | sub app { (shift)->{app}; } | ||||||||||||||||||
|
Subroutine
app: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 34 | 0 | ▶ | sub name { (shift)->{project_configuration}->{name}; } | ||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 35 | 0 | ▶ | sub directory { (shift)->{directory}; } | ||||||||||||||||||
|
Subroutine
directory: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | ▶ | sub dump { | ||||||||||||||||||
|
Subroutine
dump: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 38 | 0 | my ($self) = @_; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | $self->app->log->debug( Dumper($self) ); | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | ▶ | sub load { | ||||||||||||||||||
|
Subroutine
load: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 44 | 0 | my ($self) = @_; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | ▶ | if ( -f $self->_config_file() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | $self->{project_configuration} = YAML::LoadFile( $self->_config_file ); | |||||||||||||||||||
| 48 | 0 | $self->{name} = $self->{project_configuration}->{name}; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | #$self->{directory} = $self->{name}; | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | ▶ | sub _config_file { | ||||||||||||||||||
|
Subroutine
_config_file: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 55 | 0 | my ($self) = @_; | |||||||||||||||||||
| 56 | 0 | return $self->project_path() . "/project.conf.yml"; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | sub project_path { | ||||||||||||||||||
|
Subroutine
project_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 60 | 0 | my ($self) = @_; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | my $path = File::Spec->rel2abs( $self->app->config->{project_path} ); | |||||||||||||||||||
| 63 | 0 | my $project_path = File::Spec->catdir( $path, $self->{directory} ); | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | return $project_path; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | ▶ | sub get_last_job_execution { | ||||||||||||||||||
|
Subroutine
get_last_job_execution: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 69 | 0 | my ($self) = @_; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | my $last_run_status_file = File::Spec->catfile($self->project_path, "last.run.status.yml"); | |||||||||||||||||||
| 72 | 0 | ▶ | if(-f $last_run_status_file) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 0 | return YAML::LoadFile($last_run_status_file); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | return; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | sub create { | ||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 80 | 0 | my ($self) = @_; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | my $path = File::Spec->rel2abs( $self->app->config->{project_path} ); | |||||||||||||||||||
| 83 | 0 | my $project_path = File::Spec->catdir( $path, md5_hex( $self->{name} ) ); | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | $self->app->log->debug( | |||||||||||||||||||
| 86 | "Creating new project $self->{name} in $project_path."); | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | File::Path::make_path($project_path); | |||||||||||||||||||
| 89 | 0 | File::Path::make_path( File::Spec->catdir( $project_path, "jobs" ) ); | |||||||||||||||||||
| 90 | 0 | File::Path::make_path( File::Spec->catdir( $project_path, "rex" ) ); | |||||||||||||||||||
| 91 | 0 | File::Path::make_path( File::Spec->catdir( $project_path, "formulars" ) ); | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | my $project_configuration = { name => $self->{name}, }; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | YAML::DumpFile( "$project_path/project.conf.yml", $project_configuration ); | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | ▶ | sub update { | ||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 99 | 0 | my ($self) = @_; | |||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | my $project_path = $self->project_path; | |||||||||||||||||||
| 102 | YAML::DumpFile( "$project_path/project.conf.yml", | ||||||||||||||||||||
| 103 | 0 | $self->{project_configuration} ); | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | ▶ | sub add_node { | ||||||||||||||||||
|
Subroutine
add_node: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 107 | 0 | my ( $self, $host ) = @_; | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | if ( !exists $self->{project_configuration}->{nodes} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 0 | $self->{project_configuration}->{nodes} = []; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | push @{ $self->{project_configuration}->{nodes} }, $host; | |||||||||||||||||||
| 114 | 0 | $self->update; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | ▶ | sub job_count { | ||||||||||||||||||
|
Subroutine
job_count: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 118 | 0 | my ($self) = @_; | |||||||||||||||||||
| 119 | 0 | my $jobs = $self->jobs; | |||||||||||||||||||
| 120 | 0 | return scalar( @{$jobs} ); | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | ▶ | sub jobs { | ||||||||||||||||||
|
Subroutine
jobs: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 124 | 0 | my ($self) = @_; | |||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | my @jobs; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | ▶ | opendir( my $dh, $self->project_path() . "/jobs" ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | or die( "Error: $! (" . $self->project_path() . ")" ); | ||||||||||||||||||||
| 130 | 0 | ▶ | while ( my $entry = readdir($dh) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 131 | 0 | ▶ | next if ( !-f $self->project_path() . "/jobs/$entry/job.conf.yml" ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | 0 | push @jobs, | |||||||||||||||||||
| 133 | Rex::JobControl::Helper::Project::Job->new( | ||||||||||||||||||||
| 134 | directory => $entry, | ||||||||||||||||||||
| 135 | project => $self | ||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | 0 | closedir($dh); | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 0 | return \@jobs; | |||||||||||||||||||
| 141 | } | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 0 | ▶ | sub get_job { | ||||||||||||||||||
|
Subroutine
get_job: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 144 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||
| 145 | 0 | return Rex::JobControl::Helper::Project::Job->new( | |||||||||||||||||||
| 146 | directory => $dir, | ||||||||||||||||||||
| 147 | project => $self | ||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 0 | ▶ | sub create_job { | ||||||||||||||||||
|
Subroutine
create_job: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 152 | 0 | my ( $self, %data ) = @_; | |||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 0 | $data{directory} = md5_hex( $data{directory} ); | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 0 | my $job = | |||||||||||||||||||
| 157 | Rex::JobControl::Helper::Project::Job->new( project => $self, %data ); | ||||||||||||||||||||
| 158 | 0 | $job->create(%data); | |||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 0 | ▶ | sub rexfile_count { | ||||||||||||||||||
|
Subroutine
rexfile_count: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 162 | 0 | my ($self) = @_; | |||||||||||||||||||
| 163 | 0 | my $rexfiles = $self->rexfiles; | |||||||||||||||||||
| 164 | 0 | return scalar( @{$rexfiles} ); | |||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | 0 | ▶ | sub rexfiles { | ||||||||||||||||||
|
Subroutine
rexfiles: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 168 | 0 | my ($self) = @_; | |||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 0 | my @rexfiles; | |||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | 0 | ▶ | opendir( my $dh, $self->project_path() . "/rex" ) or die($!); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 173 | 0 | ▶ | while ( my $entry = readdir($dh) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | 0 | ▶ | next if ( !-f $self->project_path() . "/rex/$entry/rex.conf.yml" ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 175 | 0 | push @rexfiles, | |||||||||||||||||||
| 176 | Rex::JobControl::Helper::Project::Rexfile->new( | ||||||||||||||||||||
| 177 | directory => $entry, | ||||||||||||||||||||
| 178 | project => $self | ||||||||||||||||||||
| 179 | ); | ||||||||||||||||||||
| 180 | } | ||||||||||||||||||||
| 181 | 0 | closedir($dh); | |||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | 0 | return \@rexfiles; | |||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | 0 | ▶ | sub create_rexfile { | ||||||||||||||||||
|
Subroutine
create_rexfile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 187 | 0 | my ( $self, %data ) = @_; | |||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | 0 | $data{directory} = md5_hex( $data{directory} ); | |||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 0 | my $rexfile = | |||||||||||||||||||
| 192 | Rex::JobControl::Helper::Project::Rexfile->new( project => $self, %data ); | ||||||||||||||||||||
| 193 | 0 | $rexfile->create(%data); | |||||||||||||||||||
| 194 | } | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | 0 | ▶ | sub get_rexfile { | ||||||||||||||||||
|
Subroutine
get_rexfile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 197 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||
| 198 | 0 | return Rex::JobControl::Helper::Project::Rexfile->new( | |||||||||||||||||||
| 199 | directory => $dir, | ||||||||||||||||||||
| 200 | project => $self | ||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||
| 202 | } | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 0 | ▶ | sub all_server { | ||||||||||||||||||
|
Subroutine
all_server: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 205 | 0 | my ($self) = @_; | |||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | 0 | my @all_server; | |||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | 0 | for my $rex ( @{ $self->rexfiles } ) { | |||||||||||||||||||
| 210 | 0 | push @all_server, @{ $rex->all_server }; | |||||||||||||||||||
| 211 | } | ||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | 0 | $self->load; | |||||||||||||||||||
| 214 | 0 | for my $srv ( @{ $self->{project_configuration}->{nodes} } ) { | |||||||||||||||||||
| 215 | 0 | push @all_server, $srv; | |||||||||||||||||||
| 216 | } | ||||||||||||||||||||
| 217 | |||||||||||||||||||||
| 218 | 0 | return \@all_server; | |||||||||||||||||||
| 219 | } | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | 0 | ▶ | sub remove { | ||||||||||||||||||
|
Subroutine
remove: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 222 | 0 | my ($self) = @_; | |||||||||||||||||||
| 223 | 0 | File::Path::remove_tree( $self->project_path() ); | |||||||||||||||||||
| 224 | } | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | 0 | ▶ | sub formular_count { | ||||||||||||||||||
|
Subroutine
formular_count: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 227 | 0 | my ($self) = @_; | |||||||||||||||||||
| 228 | 0 | my $forms = $self->formulars; | |||||||||||||||||||
| 229 | 0 | return scalar( @{$forms} ); | |||||||||||||||||||
| 230 | } | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | 0 | ▶ | sub formulars { | ||||||||||||||||||
|
Subroutine
formulars: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 233 | 0 | my ($self) = @_; | |||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | 0 | my @formulars; | |||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | 0 | ▶ | if ( !-d $self->project_path() . "/formulars" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 238 | 0 | return []; | |||||||||||||||||||
| 239 | } | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | 0 | ▶ | opendir( my $dh, $self->project_path() . "/formulars" ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 242 | or die( "Error: $! (" . $self->project_path() . ")" ); | ||||||||||||||||||||
| 243 | 0 | ▶ | while ( my $entry = readdir($dh) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 244 | next | ||||||||||||||||||||
| 245 | 0 | ▶ | if ( !-f $self->project_path() . "/formulars/$entry/formular.conf.yml" ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 246 | 0 | push @formulars, | |||||||||||||||||||
| 247 | Rex::JobControl::Helper::Project::Formular->new( | ||||||||||||||||||||
| 248 | directory => $entry, | ||||||||||||||||||||
| 249 | project => $self | ||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||
| 251 | } | ||||||||||||||||||||
| 252 | 0 | closedir($dh); | |||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | 0 | return \@formulars; | |||||||||||||||||||
| 255 | } | ||||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | 0 | ▶ | sub get_formular { | ||||||||||||||||||
|
Subroutine
get_formular: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 258 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||
| 259 | 0 | return Rex::JobControl::Helper::Project::Formular->new( | |||||||||||||||||||
| 260 | directory => $dir, | ||||||||||||||||||||
| 261 | project => $self | ||||||||||||||||||||
| 262 | ); | ||||||||||||||||||||
| 263 | } | ||||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | 0 | ▶ | sub create_formular { | ||||||||||||||||||
|
Subroutine
create_formular: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 266 | 0 | my ( $self, %data ) = @_; | |||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | 0 | $data{directory} = md5_hex( $data{directory} ); | |||||||||||||||||||
| 269 | |||||||||||||||||||||
| 270 | 0 | my $form = | |||||||||||||||||||
| 271 | Rex::JobControl::Helper::Project::Formular->new( project => $self, %data ); | ||||||||||||||||||||
| 272 | |||||||||||||||||||||
| 273 | 0 | $form->create(%data); | |||||||||||||||||||
| 274 | } | ||||||||||||||||||||
| 275 | |||||||||||||||||||||
| 276 | 1 | 1; | |||||||||||||||||||