Class: Bosh::Cli::JobPropertyValidator
- Defined in:
- lib/cli/job_property_validator.rb
Defined Under Namespace
Classes: TemplateError
Instance Attribute Summary collapse
-
#jobs_without_properties ⇒ Object
readonly
Returns the value of attribute jobs_without_properties.
-
#template_errors ⇒ Object
readonly
Returns the value of attribute template_errors.
Instance Method Summary collapse
-
#initialize(built_jobs, manifest) ⇒ JobPropertyValidator
constructor
A new instance of JobPropertyValidator.
- #job_network_spec(job_spec) ⇒ Object
- #validate ⇒ Object
-
#validate_templates(job_spec) ⇒ Object
Tries to fill in each job template with job properties, collects errors.
Constructor Details
#initialize(built_jobs, manifest) ⇒ JobPropertyValidator
Returns a new instance of JobPropertyValidator.
11 12 13 14 15 16 17 18 19 20 21 22 23 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 |
# File 'lib/cli/job_property_validator.rb', line 11 def initialize(built_jobs, manifest) @built_jobs = {} @manifest = manifest @jobs_without_properties = [] built_jobs.each do |job| @built_jobs[job.name] = job if job.properties.empty? @jobs_without_properties << job end end unless @manifest["properties"].is_a?(Hash) bad_manifest("Invalid properties format in deployment " + "manifest, Hash expected, #{@manifest["properties"].class} given") end unless @manifest["jobs"].is_a?(Array) bad_manifest("Invalid jobs format in deployment " + "manifest, Array expected, #{@manifest["jobs"].class} given") end @manifest["jobs"].each do |job| unless job.is_a?(Hash) bad_manifest("Invalid job spec in the manifest " + "Hash expected, #{job.class} given") end job_name = job["name"] if job_name.nil? bad_manifest("Manifest contains at least one job without name") end if job["template"].nil? bad_manifest("Job `#{job_name}' doesn't have a template") end end @template_errors = [] end |
Instance Attribute Details
#jobs_without_properties ⇒ Object (readonly)
Returns the value of attribute jobs_without_properties.
7 8 9 |
# File 'lib/cli/job_property_validator.rb', line 7 def jobs_without_properties @jobs_without_properties end |
#template_errors ⇒ Object (readonly)
Returns the value of attribute template_errors.
6 7 8 |
# File 'lib/cli/job_property_validator.rb', line 6 def template_errors @template_errors end |
Instance Method Details
#job_network_spec(job_spec) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/cli/job_property_validator.rb', line 93 def job_network_spec(job_spec) job_spec['networks'].reduce({}) do |networks, network| networks[network['name']] = { 'ip' => '127.0.0.1', # faking the IP since it shouldn't affect logic 'netmask' => '255.255.255.0', 'gateway' => '127.0.0.2' } networks end end |
#validate ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cli/job_property_validator.rb', line 53 def validate @manifest["jobs"].each do |job_spec| job_templates = Array(job_spec['template']) job_templates.each do |job_template| job_spec_for_template = job_spec.dup job_spec_for_template['template'] = job_template validate_templates(job_spec_for_template) end end end |
#validate_templates(job_spec) ⇒ Object
Tries to fill in each job template with job properties, collects errors
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cli/job_property_validator.rb', line 66 def validate_templates(job_spec) built_job = @built_jobs[job_spec["template"]] if built_job.nil? raise CliError, "Job `#{job_spec["template"]}' has not been built" end collection = JobPropertyCollection.new( built_job, @manifest["properties"], job_spec["properties"], job_spec["property_mappings"]) # Spec is usually more than that but jobs rarely use anything but # networks and properties. spec = { 'job' => { 'name' => job_spec['name'] }, 'index' => 0, 'networks' => job_network_spec(job_spec), 'properties' => collection.to_hash } built_job.all_templates.each do |template_path| evaluate_template(built_job, template_path, spec) end end |