Class: Puppet::Parser::EnvironmentCompiler
- Defined in:
- lib/puppet/parser/environment_compiler.rb
Constant Summary
Constants included from Puppet::Pops::Evaluator::Runtime3Support
Puppet::Pops::Evaluator::Runtime3Support::CLASS_STRING, Puppet::Pops::Evaluator::Runtime3Support::NAME_SPACE_SEPARATOR
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Instance Attribute Summary
Attributes inherited from Compiler
#boot_injector, #catalog, #code_id, #collections, #facts, #injector, #loaders, #node, #relationships, #topscope
Class Method Summary collapse
Instance Method Summary collapse
- #add_catalog_validators ⇒ Object
- #add_resource(scope, resource) ⇒ Object
- #compile ⇒ Object
- #evaluate_applications ⇒ Object
- #evaluate_ast_node ⇒ Object
- #evaluate_classes(titles, scope, lazy) ⇒ Object
- #on_empty_site ⇒ Object
- #prune_catalog ⇒ Object private
-
#prune_env_catalog ⇒ Object
Prunes the catalog by dropping all resources that are not contained under the Site (if a site expression is used).
-
#resources ⇒ Object
Overrides the regular compiler to be able to return the list of resources after a prune has taken place in the graph representation.
Methods inherited from Compiler
#activate_binder, #add_catalog_validator, #add_class, #add_override, #assert_app_in_site, #context_overrides, #create_boot_injector, #environment, #evaluate_node_classes, #evaluate_relationships, #evaluate_site, #initialize, #newscope, #prune_node_catalog, #resource_overrides, #validate_catalog
Methods included from Puppet::Pops::Evaluator::Runtime3Support
#add_relationship, #call_function, #capitalize_qualified_name, #coerce_numeric, #convert, #create_local_scope_from, #create_match_scope_from, #create_resource_defaults, #create_resource_overrides, #create_resource_parameter, #create_resources, #diagnostic_producer, #external_call_function, #extract_file_line, #fail, #find_closest_positioned, #find_resource, #get_resource_parameter_value, #get_scope_nesting_level, #get_variable_value, #is_boolean?, #is_parameter_of_resource?, #is_true?, #optionally_fail, #resource_to_ptype, #set_match_data, #set_scope_nesting_level, #set_variable, #variable_bound?, #variable_exists?
Methods included from Resource::TypeCollectionHelper
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Constructor Details
This class inherits a constructor from Puppet::Parser::Compiler
Class Method Details
.compile(env) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/puppet/parser/environment_compiler.rb', line 4 def self.compile(env) begin env.check_for_reparse node = Puppet::Node.new(env) node.environment = env new(node).compile rescue => detail = "#{detail} in environment #{env.name}" Puppet.log_exception(detail, ) raise Puppet::Error, , detail.backtrace end end |
Instance Method Details
#add_catalog_validators ⇒ Object
18 19 20 21 22 |
# File 'lib/puppet/parser/environment_compiler.rb', line 18 def add_catalog_validators super add_catalog_validator(CatalogValidator::SiteValidator) add_catalog_validator(CatalogValidator::EnvironmentRelationshipValidator) end |
#add_resource(scope, resource) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/puppet/parser/environment_compiler.rb', line 94 def add_resource(scope, resource) @resources << resource @catalog.add_resource(resource) if !resource.class? && resource[:stage] raise ArgumentError, "Only classes can set 'stage'; normal resources like #{resource} cannot change run stage" end # Stages should not be inside of classes. They are always a # top-level container, regardless of where they appear in the # manifest. return if resource.stage? # This adds a resource to the class it lexically appears in in the # manifest. unless resource.class? @catalog.add_edge(scope.resource, resource) end resource.mark_unevaluated_consumer if is_capability_consumer?(resource) assert_app_in_site(scope, resource) end |
#compile ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/parser/environment_compiler.rb', line 24 def compile Puppet.override(@context_overrides, "For compiling environment catalog #{environment.name}") do @catalog.environment_instance = environment Puppet::Util::Profiler.profile("Env Compile: Created settings scope", [:compiler, :create_settings_scope]) { create_settings_scope } activate_binder Puppet::Util::Profiler.profile("Env Compile: Evaluated main", [:compiler, :evaluate_main]) { evaluate_main } Puppet::Util::Profiler.profile("Env Compile: Evaluated site", [:compiler, :evaluate_site]) { evaluate_site } Puppet::Util::Profiler.profile("Env Compile: Evaluated application instances", [:compiler, :evaluate_applications]) { evaluate_applications } Puppet::Util::Profiler.profile("Env Compile: Prune", [:compiler, :prune_catalog]) { prune_catalog } Puppet::Util::Profiler.profile("Env Compile: Validate Catalog pre-finish", [:compiler, :validate_pre_finish]) do validate_catalog(CatalogValidator::PRE_FINISH) end Puppet::Util::Profiler.profile("Env Compile: Finished catalog", [:compiler, :finish_catalog]) { finish } fail_on_unevaluated Puppet::Util::Profiler.profile("Env Compile: Validate Catalog final", [:compiler, :validate_final]) do validate_catalog(CatalogValidator::FINAL) end if block_given? yield @catalog else @catalog end end end |
#evaluate_applications ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/puppet/parser/environment_compiler.rb', line 124 def evaluate_applications exceptwrap do resources.select { |resource| type = resource.resource_type; type.is_a?(Puppet::Resource::Type) && type.application? }.each do |resource| Puppet::Util::Profiler.profile("Evaluated application #{resource}", [:compiler, :evaluate_resource, resource]) do resource.evaluate end end end end |
#evaluate_ast_node ⇒ Object
116 117 118 |
# File 'lib/puppet/parser/environment_compiler.rb', line 116 def evaluate_ast_node() # Do nothing, the environment catalog is not built for a particular node. end |
#evaluate_classes(titles, scope, lazy) ⇒ Object
134 135 136 137 |
# File 'lib/puppet/parser/environment_compiler.rb', line 134 def evaluate_classes(titles, scope, lazy) # Always lazy in an Environment compilation super(titles, scope, true) end |
#on_empty_site ⇒ Object
120 121 122 |
# File 'lib/puppet/parser/environment_compiler.rb', line 120 def on_empty_site Puppet.warning("Environment Compiler: Could not find a site definition to evaluate") end |
#prune_catalog ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 |
# File 'lib/puppet/parser/environment_compiler.rb', line 61 def prune_catalog prune_env_catalog end |
#prune_env_catalog ⇒ Object
Prunes the catalog by dropping all resources that are not contained under the Site (if a site expression is used). As a consequence all edges to/from dropped resources are also dropped. Once the pruning is performed, this compiler returns the pruned list when calling the #resources method. The pruning does not alter the order of resources in the resources list.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/puppet/parser/environment_compiler.rb', line 70 def prune_env_catalog # Everything under Class[main], that is not under (inclusive of) Site[site] should be pruned as those resources # are intended for nodes in a node catalog. # the_main_class_resource = @catalog.resource('Class', '') the_site_resource = @catalog.resource('Site', 'site') # Get downstream vertexes returns a hash where the keys are the resources and values nesting level rooted_in_main = @catalog.downstream_from_vertex(the_main_class_resource).keys to_be_removed = if the_site_resource keep_from_site = @catalog.downstream_from_vertex(the_site_resource).keys keep_from_site << the_site_resource rooted_in_main - keep_from_site else rooted_in_main end @catalog.remove_resource(*to_be_removed) # The compiler keeps a list of added resources, this shadows that list with the now pruned result @pruned_resources = @catalog.resources end |
#resources ⇒ Object
Overrides the regular compiler to be able to return the list of resources after a prune has taken place in the graph representation. Before a prune, the list is the same as in the regular compiler
143 144 145 |
# File 'lib/puppet/parser/environment_compiler.rb', line 143 def resources @pruned_resources || super end |