Skip to content

Commit

Permalink
Fixes #7171: Add methods to help creating new generic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
peckpeck committed Sep 18, 2015
1 parent 3974d9f commit 577434b
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 0 deletions.
90 changes: 90 additions & 0 deletions tree/30_generic_methods/_classes_aggregate_four.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#####################################################################################
# Copyright 2013 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

# @name Class aggregate two
# @description Aggregate 2 class prefix into a new one
#
# @parameter first_prefix The first prefix of the source class to aggregate
# @parameter second_prefix The second prefix of the source class to aggregate
# @parameter third_prefix The third prefix of the source class to aggregate
# @parameter fourth_prefix The fourth prefix of the source class to aggregate
# @parameter destination_prefix The prefix of the destination class
#
# @class_prefix
# @class_parameter
# This bundle will define a class ${destination_prefix}_{kept,repaired,not_ok,ok,reached}
# based on ${first_prefix}_{kept,repaired,not_ok,ok,reached} and ${second_prefix}_{kept,repaired,not_ok,ok,reached}
# keeping the worst outcome

bundle agent _classes_aggregate_four(first_prefix, second_prefix, third_prefix, fourth_prefix, destination_prefix)
{
classes:
"first_reached" expression => "${first_prefix}_reached";
"second_reached" expression => "${second_prefix}_reached";
"third_reached" expression => "${third_prefix}_reached";
"fourth_reached" expression => "${fourth_prefix}_reached";

first_reached.second_reached.third_reached.fourth_reached::
"${destination_prefix}_ok" expression => "${first_prefix}_ok.${second_prefix}_ok.${third_prefix}_ok.${fourth_prefix}_ok",
scope => "namespace";

"${destination_prefix}_kept" expression => "${first_prefix}_kept.${second_prefix}_kept.${third_prefix}_kept.${fourth_prefix}_kept",
scope => "namespace";

"${destination_prefix}_repaired" expression => "(${first_prefix}_repaired.${second_prefix}_ok.${third_prefix}_ok.${fourth_prefix}_ok)|
(${first_prefix}_ok.${second_prefix}_repaired.${third_prefix}_ok.${fourth_prefix}_ok)|
(${first_prefix}_ok.${second_prefix}_ok.${third_prefix}_repaired.${fourth_prefix}_ok)|
(${first_prefix}_ok.${second_prefix}_ok.${third_prefix}_ok.${fourth_prefix}_repaired)",
scope => "namespace";

"${destination_prefix}_reached" expression => "${first_prefix}_reached|${second_prefix}_reached|${third_prefix}_reached|${fourth_prefix}_reached",
scope => "namespace";

"${destination_prefix}_failed" expression => "${first_prefix}_failed|${second_prefix}_failed|${third_prefix}_failed|${fourth_prefix}_failed",
scope => "namespace";

"${destination_prefix}_denied" expression => "${first_prefix}_denied|${second_prefix}_denied|${third_prefix}_denied|${fourth_prefix}_denied",
scope => "namespace";

"${destination_prefix}_timeout" expression => "${first_prefix}_timeout|${second_prefix}_timeout|${third_prefix}_timeout|${fourth_prefix}_timeout",
scope => "namespace";

"${destination_prefix}_error" expression => "${first_prefix}_error|${second_prefix}_error|${third_prefix}_error|${fourth_prefix}_error",
scope => "namespace";

"${destination_prefix}_not_ok" expression => "!${destination_prefix}_ok",
scope => "namespace";

"${destination_prefix}_not_kept" expression => "!${destination_prefix}_kept",
scope => "namespace";

"${destination_prefix}_not_repaired" expression => "!${destination_prefix}_repaired",
scope => "namespace";
methods:
!first_reached::
"no first" usebundle => _classes_aggregate_three("${second_prefix}", "${third_prefix}", "${fourth_prefix}", "${destination_prefix}");

first_reached.!second_reached::
"no second" usebundle => _classes_aggregate_three("${first_prefix}", "${third_prefix}", "${fourth_prefix}", "${destination_prefix}");

first_reached.second_reached.!third_reached::
"no third" usebundle => _classes_aggregate_three("${first_prefix}", "${second_prefix}", "${fourth_prefix}", "${destination_prefix}");

first_reached.second_reached.third_reached.!fourth_reached::
"no fourth" usebundle => _classes_aggregate_three("${first_prefix}", "${second_prefix}", "${third_prefix}", "${destination_prefix}");
}
72 changes: 72 additions & 0 deletions tree/30_generic_methods/_classes_aggregate_ifthenelse.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#####################################################################################
# Copyright 2013 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

# @name Class aggregate ifthenelse
# @description Aggregate class outcomes within an if then else structure
#
# @parameter test_prefix The prefix of classes comming from the test method
# @parameter then_prefix The prefix of classes comming from the method called in the 'then' case
# @parameter else_prefix The prefix of classes comming from the method called in the 'else' case
# @parameter destination_prefix The prefix of the destination class
#
# @class_prefix
# @class_parameter
# This bundle will define a class ${destination_prefix}_{kept,repaired,not_ok,ok,reached}
# based on the test result and the method called afterwards.
#
# If the if the 'if' call has a '_true' outcome then the 'then' result is copied to destination
# If the if the 'if' call has a '_false' outcome then the 'else' result is copied to destination
#
# 'then_prefix' and 'else_prefix' can be replaced by the litteral string "success" or "failure"
# In such case, the outcome is respectively replaced by a call to _classes_success or _classes_failure

bundle agent _classes_aggregate_two(test_prefix, then_prefix, else_prefix, destination_prefix)
{
classes:
"test_true" expression => "${test_prefix}_true";
"test_false" expression => "${test_prefix}_false";

"then_success" expression => strcmp("success", "${then_prefix}");
"then_failure" expression => strcmp("failure", "${then_prefix}");

"else_success" expression => strcmp("success", "${else_prefix}");
"else_failure" expression => strcmp("failure", "${else_prefix}");

methods:
test_true.then_success::
"success" usebundle => _classes_success("${destination_prefix}");

test_true.then_error::
"failure" usebundle => _classes_failure("${destination_prefix}");

test_true.!then_success.!then_error::
"copy then" usebundle => _classes_copy("${then_prefix}", "${destination_prefix}");

test_false.else_success::
"success" usebundle => _classes_success("${destination_prefix}");

test_false.else_error::
"failure" usebundle => _classes_failure("${destination_prefix}");

test_false.!else_success.!else_error::
"copy else" usebundle => _classes_copy("${else_prefix}", "${destination_prefix}");

!test_true.!test_false::
# this will copy if_prefix which contains a failure
"failure" usebundle => _classes_copy("${if_prefix}", "${destination_prefix}");
}
85 changes: 85 additions & 0 deletions tree/30_generic_methods/_classes_aggregate_three.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#####################################################################################
# Copyright 2013 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

# @name Class aggregate two
# @description Aggregate 2 class prefix into a new one
#
# @parameter first_prefix The first prefix of the source class to aggregate
# @parameter second_prefix The second prefix of the source class to aggregate
# @parameter third_prefix The third prefix of the source class to aggregate
# @parameter destination_prefix The prefix of the destination class
#
# @class_prefix
# @class_parameter
# This bundle will define a class ${destination_prefix}_{kept,repaired,not_ok,ok,reached}
# based on ${first_prefix}_{kept,repaired,not_ok,ok,reached} and ${second_prefix}_{kept,repaired,not_ok,ok,reached}
# keeping the worst outcome

bundle agent _classes_aggregate_three(first_prefix, second_prefix, third_prefix, destination_prefix)
{
classes:
"first_reached" expression => "${first_prefix}_reached";
"second_reached" expression => "${second_prefix}_reached";
"third_reached" expression => "${third_prefix}_reached";

first_reached.second_reached.third_reached::
"${destination_prefix}_ok" expression => "${first_prefix}_ok.${second_prefix}_ok.${third_prefix}_ok",
scope => "namespace";

"${destination_prefix}_kept" expression => "${first_prefix}_kept.${second_prefix}_kept.${third_prefix}_kept",
scope => "namespace";

"${destination_prefix}_repaired" expression => "(${first_prefix}_repaired.${second_prefix}_ok.${third_prefix}_ok)|
(${first_prefix}_ok.${second_prefix}_repaired.${third_prefix}_ok)|
(${first_prefix}_ok.${second_prefix}_ok.${third_prefix}_repaired)",
scope => "namespace";

"${destination_prefix}_reached" expression => "${first_prefix}_reached|${second_prefix}_reached|${third_prefix}_reached",
scope => "namespace";

"${destination_prefix}_failed" expression => "${first_prefix}_failed|${second_prefix}_failed|${third_prefix}_failed",
scope => "namespace";

"${destination_prefix}_denied" expression => "${first_prefix}_denied|${second_prefix}_denied|${third_prefix}_denied",
scope => "namespace";

"${destination_prefix}_timeout" expression => "${first_prefix}_timeout|${second_prefix}_timeout|${third_prefix}_timeout",
scope => "namespace";

"${destination_prefix}_error" expression => "${first_prefix}_error|${second_prefix}_error|${third_prefix}_error",
scope => "namespace";

"${destination_prefix}_not_ok" expression => "!${destination_prefix}_ok",
scope => "namespace";

"${destination_prefix}_not_kept" expression => "!${destination_prefix}_kept",
scope => "namespace";

"${destination_prefix}_not_repaired" expression => "!${destination_prefix}_repaired",
scope => "namespace";

methods:
!first_reached::
"no first" usebundle => _classes_aggregate_two("${second_prefix}", "${third_prefix}", "${destination_prefix}");

first_reached.!second_reached::
"no second" usebundle => _classes_aggregate_two("${first_prefix}", "${third_prefix}", "${destination_prefix}");

first_reached.second_reached.!third_reached::
"no third" usebundle => _classes_aggregate_two("${first_prefix}", "${second_prefix}", "${destination_prefix}");
}
78 changes: 78 additions & 0 deletions tree/30_generic_methods/_classes_aggregate_two.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#####################################################################################
# Copyright 2013 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

# @name Class aggregate two
# @description Aggregate 2 class prefix into a new one
#
# @parameter first_prefix The first prefix of the source class to aggregate
# @parameter second_prefix The second prefix of the source class to aggregate
# @parameter destination_prefix The prefix of the destination class
#
# @class_prefix
# @class_parameter
# This bundle will define a class ${destination_prefix}_{kept,repaired,not_ok,ok,reached}
# based on ${first_prefix}_{kept,repaired,not_ok,ok,reached} and ${second_prefix}_{kept,repaired,not_ok,ok,reached}
# keeping the worst outcome

bundle agent _classes_aggregate_two(first_prefix, second_prefix, destination_prefix)
{
classes:
"first_reached" expression => "${first_prefix}_reached";
"second_reached" expression => "${second_prefix}_reached";

first_reached.second_reached::
"${destination_prefix}_ok" expression => "${first_prefix}_ok.${second_prefix}_ok",
scope => "namespace";

"${destination_prefix}_kept" expression => "${first_prefix}_kept.${second_prefix}_kept",
scope => "namespace";

"${destination_prefix}_repaired" expression => "(${first_prefix}_ok.${second_prefix}_repaired)|(${first_prefix}_repaired.${second_prefix}_ok)",
scope => "namespace";

"${destination_prefix}_reached" expression => "${first_prefix}_reached|${second_prefix}_reached",
scope => "namespace";

"${destination_prefix}_failed" expression => "${first_prefix}_failed|${second_prefix}_failed",
scope => "namespace";

"${destination_prefix}_denied" expression => "${first_prefix}_denied|${second_prefix}_denied",
scope => "namespace";

"${destination_prefix}_timeout" expression => "${first_prefix}_timeout|${second_prefix}_timeout",
scope => "namespace";

"${destination_prefix}_error" expression => "${first_prefix}_error|${second_prefix}_error",
scope => "namespace";

"${destination_prefix}_not_ok" expression => "!${destination_prefix}_ok",
scope => "namespace";

"${destination_prefix}_not_kept" expression => "!${destination_prefix}_kept",
scope => "namespace";

"${destination_prefix}_not_repaired" expression => "!${destination_prefix}_repaired",
scope => "namespace";

methods:
first_reached.!second_reached::
"copy first" usebundle => _classes_copy("${first_prefix}", "${destination_prefix}");

!first_reached.second_reached::
"copy second" usebundle => _classes_copy("${second_prefix}", "${destination_prefix}");
}

0 comments on commit 577434b

Please sign in to comment.