From 5f7dd4aee57ad6ec47577df1100b5fbfe1003cba Mon Sep 17 00:00:00 2001 From: mschilli Date: Tue, 17 May 2011 07:26:18 -0700 Subject: [PATCH 1/5] pred/succ values are now defined, previously only their containing directories were created. --- lib/Pogo/Engine/Namespace.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Pogo/Engine/Namespace.pm b/lib/Pogo/Engine/Namespace.pm index 81359ef..ed2c911 100644 --- a/lib/Pogo/Engine/Namespace.pm +++ b/lib/Pogo/Engine/Namespace.pm @@ -467,9 +467,8 @@ sub set_conf # $second requires $first to go first within $env # $first is a predecessor of $second # $second is a successor of $first - # we just make sure these exist, don't define them - $conf->{seq}->{pred}->{$c_env_type}->{$second}->{$first}; - $conf->{seq}->{succ}->{$c_env_type}->{$first}->{$second}; + push @{ $conf->{seq}->{pred}->{$c_env_type}->{$second} }, $first; + push @{ $conf->{seq}->{succ}->{$c_env_type}->{$first} }, $second; } } From 2963f0b6c870e2fed353d56898205a8b5a496b19 Mon Sep 17 00:00:00 2001 From: mschilli Date: Fri, 20 May 2011 10:45:21 -0700 Subject: [PATCH 2/5] more tests --- t/13_unit_constrained.t | 23 ++++++++++++----------- t/conf/example.yaml | 4 +++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/t/13_unit_constrained.t b/t/13_unit_constrained.t index b947a4b..77e53e4 100644 --- a/t/13_unit_constrained.t +++ b/t/13_unit_constrained.t @@ -49,7 +49,7 @@ use File::Basename; use Pogo::Engine::Store qw(store); use Data::Dumper; -# Log::Log4perl->easy_init({ level => $DEBUG, layout => "%F{1}-%L-%M: %m%n" }); +Log::Log4perl->easy_init({ level => $DEBUG, layout => "%F{1}-%L-%M: %m%n" }); my $ns = Pogo::Engine::Namespace->new( nsname => "wonk", @@ -135,29 +135,30 @@ my $job = Pogo::Engine::Job->new({ exe_data => "wonk", }); +$job->start( + sub { ok 0, "err cont on start(): @_" }, + sub { ok 1, "success cont on start()"; + my($nqueued, $nwaiting) = @_; + is($nqueued, 4, "4 hosts enqueued"); + is($nwaiting, 0, "0 hosts waiting"); + }, +); + $ns->fetch_runnable_hosts( $job, $host_meta, sub { die "err cont: ", Dumper( \@_ ); }, sub { $result = \@_; + print "result=", Dumper( \@_ ); }, ); ok(1, "at the end" ); -# print store->_dump(); +print store->_dump(); __END__ -$job->start( - sub { ok 0, "err cont on start(): @_" }, - sub { ok 1, "success cont on start()"; - my($nqueued, $nwaiting) = @_; - is($nqueued, 4, "4 hosts enqueued"); - is($nwaiting, 0, "0 hosts waiting"); - }, -); - print Dumper($result); __END__ diff --git a/t/conf/example.yaml b/t/conf/example.yaml index 7b2c63a..46b58fa 100644 --- a/t/conf/example.yaml +++ b/t/conf/example.yaml @@ -10,6 +10,8 @@ apps: backend: - bar[1-10].east.example.com - bar[1-10].west.example.com + tail: + - zar[1-10].west.example.com envs: coast: @@ -26,4 +28,4 @@ constraints: - frontend: 25% - backend: 1 sequence: - - [ backend, frontend ] + - [ backend, frontend, tail ] From 84b69cc90b9615111ce091be22907e52e7d31497 Mon Sep 17 00:00:00 2001 From: mschilli Date: Fri, 20 May 2011 16:24:20 -0700 Subject: [PATCH 3/5] Constraint engine fixes --- lib/Pogo/Engine/Namespace.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/Pogo/Engine/Namespace.pm b/lib/Pogo/Engine/Namespace.pm index ed2c911..ab9393f 100644 --- a/lib/Pogo/Engine/Namespace.pm +++ b/lib/Pogo/Engine/Namespace.pm @@ -244,6 +244,8 @@ sub fetch_all_slots { $hostslots{$hostname} = []; + $DB::single = 1; + foreach my $app ( @{ $hostinfo->{apps} } ) { foreach my $envtype ( keys %{ $hostinfo->{envs} } ) @@ -267,10 +269,10 @@ sub fetch_all_slots } push @{ $hostslots{$hostname} }, $slot; - next unless exists $const->{$app} and - exists $const->{$app}->{$envtype}; + next unless exists $const->{$envtype} and + exists $const->{$envtype}->{$app}; - my $concur = $const->{$app}->{$envtype}; + my $concur = $const->{$envtype}->{$app}; if ( $concur !~ m{^(\d+)%$} ) { # not a percentage, a literal @@ -425,6 +427,8 @@ sub set_conf delete $conf_in->{envs}; + $DB::single = 1; + # constraint processing foreach my $c_env_type ( keys %{ $conf_in->{constraints} } ) { @@ -467,8 +471,8 @@ sub set_conf # $second requires $first to go first within $env # $first is a predecessor of $second # $second is a successor of $first - push @{ $conf->{seq}->{pred}->{$c_env_type}->{$second} }, $first; - push @{ $conf->{seq}->{succ}->{$c_env_type}->{$first} }, $second; + $conf->{seq}->{pred}->{$c_env_type}->{$second}->{$first} = 1; + $conf->{seq}->{succ}->{$c_env_type}->{$first}->{$second} = 1; } } @@ -919,8 +923,8 @@ Env settings: Sequences: - /pogo/ns/nsname/conf/seq/pred/coast/frontend: [] - /pogo/ns/nsname/conf/seq/succ/coast/backend: [] + /pogo/ns/nsname/conf/seq/pred/coast/frontend/backend + /pogo/ns/nsname/conf/seq/succ/coast/backend/frontend And even the plugin gets stored: From e38a376d92b3c87ccf3ddbf9755fec0a10252518 Mon Sep 17 00:00:00 2001 From: mschilli Date: Fri, 20 May 2011 16:29:36 -0700 Subject: [PATCH 4/5] JSON decoding bug fix in get_cur() --- lib/Pogo/Engine/Namespace.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Pogo/Engine/Namespace.pm b/lib/Pogo/Engine/Namespace.pm index ab9393f..d621490 100644 --- a/lib/Pogo/Engine/Namespace.pm +++ b/lib/Pogo/Engine/Namespace.pm @@ -631,7 +631,7 @@ sub get_cur { my ( $self, $app, $key ) = @_; my $c = store->get( $self->{path} . "/conf/cur/$app/$key" ); - return $c; + return JSON->new->utf8->allow_nonref->decode($c); } sub get_curs From a1ad22b37a7180d0d63174445e9707a3cdc362fb Mon Sep 17 00:00:00 2001 From: mschilli Date: Fri, 20 May 2011 16:43:15 -0700 Subject: [PATCH 5/5] implemented missing methods app_members and env_members --- lib/Pogo/Engine/Namespace.pm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/Pogo/Engine/Namespace.pm b/lib/Pogo/Engine/Namespace.pm index d621490..2ef6b28 100644 --- a/lib/Pogo/Engine/Namespace.pm +++ b/lib/Pogo/Engine/Namespace.pm @@ -244,7 +244,7 @@ sub fetch_all_slots { $hostslots{$hostname} = []; - $DB::single = 1; + #$DB::single = 1; foreach my $app ( @{ $hostinfo->{apps} } ) { @@ -427,7 +427,7 @@ sub set_conf delete $conf_in->{envs}; - $DB::single = 1; + #$DB::single = 1; # constraint processing foreach my $c_env_type ( keys %{ $conf_in->{constraints} } ) @@ -651,6 +651,23 @@ sub get_all_curs return { map { $_ => $self->get_curs($_) } store->get_children($path) }; } +sub app_members { + my $self = shift; + my $app = shift; + + my $path = $self->{path} . "/conf/apps/$app"; + return store->get_children("$path"); +} + +sub env_members { + my $self = shift; + my $envtype = shift; + my $envvalue = shift; + + my $path = $self->{path} . "/conf/envs/$envtype/$envvalue"; + return store->get_children("$path"); +} + sub get_all_seqs { my $self = shift;