bosh-director 1.3202.0 → 1.3213.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrations/director/20151223172000_rename_requires_json.rb +7 -0
  3. data/db/migrations/director/20160106162749_runtime_configs.rb +19 -0
  4. data/db/migrations/director/20160106163433_add_runtime_configs_to_deployments.rb +7 -0
  5. data/db/migrations/director/20160202162216_add_post_start_completed_to_instance.rb +7 -0
  6. data/db/migrations/director/20160210201838_denormalize_compiled_package_stemcell_id_to_stemcell_name_and_version.rb +57 -0
  7. data/db/migrations/director/20160219175840_add_column_teams_to_deployments.rb +8 -0
  8. data/db/migrations/director/20160224222508_add_deployment_name_to_task.rb +7 -0
  9. data/db/migrations/director/20160225182206_rename_post_start_completed.rb +8 -0
  10. data/lib/bosh/director.rb +9 -0
  11. data/lib/bosh/director/api.rb +1 -1
  12. data/lib/bosh/director/api/api_helper.rb +27 -0
  13. data/lib/bosh/director/api/controllers/base_controller.rb +28 -5
  14. data/lib/bosh/director/api/controllers/cloud_configs_controller.rb +4 -3
  15. data/lib/bosh/director/api/controllers/deployments_controller.rb +165 -81
  16. data/lib/bosh/director/api/controllers/locks_controller.rb +1 -1
  17. data/lib/bosh/director/api/controllers/packages_controller.rb +4 -35
  18. data/lib/bosh/director/api/controllers/releases_controller.rb +6 -4
  19. data/lib/bosh/director/api/controllers/runtime_configs_controller.rb +41 -0
  20. data/lib/bosh/director/api/controllers/stemcells_controller.rb +1 -1
  21. data/lib/bosh/director/api/controllers/tasks_controller.rb +72 -5
  22. data/lib/bosh/director/api/deployment_manager.rb +10 -42
  23. data/lib/bosh/director/api/extensions/scoping.rb +11 -24
  24. data/lib/bosh/director/api/instance_lookup.rb +10 -22
  25. data/lib/bosh/director/api/instance_manager.rb +27 -15
  26. data/lib/bosh/director/api/local_identity_provider.rb +0 -8
  27. data/lib/bosh/director/api/problem_manager.rb +7 -19
  28. data/lib/bosh/director/api/property_manager.rb +12 -21
  29. data/lib/bosh/director/api/resurrector_manager.rb +4 -4
  30. data/lib/bosh/director/api/route_configuration.rb +1 -0
  31. data/lib/bosh/director/api/runtime_config_manager.rb +35 -0
  32. data/lib/bosh/director/api/snapshot_manager.rb +2 -2
  33. data/lib/bosh/director/api/task_helper.rb +2 -1
  34. data/lib/bosh/director/api/task_manager.rb +2 -8
  35. data/lib/bosh/director/api/uaa_identity_provider.rb +0 -16
  36. data/lib/bosh/director/blob_util.rb +3 -2
  37. data/lib/bosh/director/cloudcheck_helper.rb +17 -3
  38. data/lib/bosh/director/compile_task.rb +53 -24
  39. data/lib/bosh/director/compile_task_generator.rb +6 -6
  40. data/lib/bosh/director/compiled_package_group.rb +4 -3
  41. data/lib/bosh/director/compiled_release.rb +6 -0
  42. data/lib/bosh/director/compiled_release/manifest.rb +30 -0
  43. data/lib/bosh/director/compiled_release_manifest.rb +3 -3
  44. data/lib/bosh/director/config.rb +11 -1
  45. data/lib/bosh/director/deployment_plan.rb +1 -0
  46. data/lib/bosh/director/deployment_plan/assembler.rb +6 -2
  47. data/lib/bosh/director/deployment_plan/cloud_manifest_parser.rb +26 -10
  48. data/lib/bosh/director/deployment_plan/compilation_config.rb +43 -7
  49. data/lib/bosh/director/deployment_plan/compilation_instance_pool.rb +10 -3
  50. data/lib/bosh/director/deployment_plan/deployment_repo.rb +4 -10
  51. data/lib/bosh/director/deployment_plan/dynamic_network.rb +1 -1
  52. data/lib/bosh/director/deployment_plan/instance.rb +36 -17
  53. data/lib/bosh/director/deployment_plan/instance_plan.rb +13 -2
  54. data/lib/bosh/director/deployment_plan/instance_spec.rb +12 -4
  55. data/lib/bosh/director/deployment_plan/job.rb +73 -39
  56. data/lib/bosh/director/deployment_plan/job_availability_zone_parser.rb +4 -4
  57. data/lib/bosh/director/deployment_plan/job_migrator.rb +7 -7
  58. data/lib/bosh/director/deployment_plan/job_network_parser.rb +6 -6
  59. data/lib/bosh/director/deployment_plan/job_spec_parser.rb +91 -33
  60. data/lib/bosh/director/deployment_plan/links/link.rb +9 -4
  61. data/lib/bosh/director/deployment_plan/links/link_lookup.rb +23 -15
  62. data/lib/bosh/director/deployment_plan/links/link_path.rb +168 -15
  63. data/lib/bosh/director/deployment_plan/links/links_resolver.rb +34 -32
  64. data/lib/bosh/director/deployment_plan/links/template_link.rb +28 -8
  65. data/lib/bosh/director/deployment_plan/manifest_validator.rb +1 -1
  66. data/lib/bosh/director/deployment_plan/network_settings.rb +27 -13
  67. data/lib/bosh/director/deployment_plan/package_validator.rb +9 -5
  68. data/lib/bosh/director/deployment_plan/placement_planner/networks_to_static_ips.rb +4 -4
  69. data/lib/bosh/director/deployment_plan/planner.rb +31 -7
  70. data/lib/bosh/director/deployment_plan/planner_factory.rb +147 -6
  71. data/lib/bosh/director/deployment_plan/runtime_manifest_parser.rb +142 -0
  72. data/lib/bosh/director/deployment_plan/stemcell.rb +2 -2
  73. data/lib/bosh/director/deployment_plan/steps/package_compile_step.rb +3 -2
  74. data/lib/bosh/director/deployment_plan/template.rb +93 -8
  75. data/lib/bosh/director/deployment_plan/update_config.rb +10 -0
  76. data/lib/bosh/director/deployment_plan/vm_extension.rb +27 -0
  77. data/lib/bosh/director/errand/runner.rb +1 -1
  78. data/lib/bosh/director/errors.rb +11 -1
  79. data/lib/bosh/director/instance_updater.rb +46 -57
  80. data/lib/bosh/director/instance_updater/instance_state.rb +9 -0
  81. data/lib/bosh/director/instance_updater/state_applier.rb +18 -5
  82. data/lib/bosh/director/job_queue.rb +2 -2
  83. data/lib/bosh/director/job_renderer.rb +2 -2
  84. data/lib/bosh/director/job_updater.rb +7 -1
  85. data/lib/bosh/director/jobs/attach_disk.rb +2 -2
  86. data/lib/bosh/director/jobs/cloud_check/apply_resolutions.rb +6 -1
  87. data/lib/bosh/director/jobs/cloud_check/scan_and_fix.rb +14 -3
  88. data/lib/bosh/director/jobs/export_release.rb +1 -1
  89. data/lib/bosh/director/jobs/fetch_logs.rb +1 -4
  90. data/lib/bosh/director/jobs/helpers/compiled_package_deleter.rb +1 -2
  91. data/lib/bosh/director/jobs/helpers/stemcell_deleter.rb +0 -16
  92. data/lib/bosh/director/jobs/release/release_job.rb +7 -7
  93. data/lib/bosh/director/jobs/run_errand.rb +5 -5
  94. data/lib/bosh/director/jobs/ssh.rb +3 -3
  95. data/lib/bosh/director/jobs/update_deployment.rb +41 -5
  96. data/lib/bosh/director/jobs/update_release.rb +78 -82
  97. data/lib/bosh/director/jobs/update_stemcell.rb +1 -1
  98. data/lib/bosh/director/jobs/vm_state.rb +34 -21
  99. data/lib/bosh/director/key_generator.rb +54 -0
  100. data/lib/bosh/director/lock.rb +2 -2
  101. data/lib/bosh/director/log_bundles_cleaner.rb +1 -0
  102. data/lib/bosh/director/manifest/changeset.rb +39 -22
  103. data/lib/bosh/director/manifest/diff_lines.rb +1 -27
  104. data/lib/bosh/director/manifest/manifest.rb +22 -7
  105. data/lib/bosh/director/manifest/redactor.rb +44 -0
  106. data/lib/bosh/director/models.rb +1 -0
  107. data/lib/bosh/director/models/compiled_package.rb +21 -15
  108. data/lib/bosh/director/models/deployment.rb +10 -0
  109. data/lib/bosh/director/models/instance.rb +2 -1
  110. data/lib/bosh/director/models/release_version.rb +0 -16
  111. data/lib/bosh/director/models/runtime_config.rb +19 -0
  112. data/lib/bosh/director/models/template.rb +4 -4
  113. data/lib/bosh/director/package_dependencies_manager.rb +22 -0
  114. data/lib/bosh/director/password_helper.rb +18 -0
  115. data/lib/bosh/director/permission_authorizer.rb +50 -30
  116. data/lib/bosh/director/post_deployment_script_runner.rb +40 -0
  117. data/lib/bosh/director/problem_handlers/missing_disk.rb +2 -2
  118. data/lib/bosh/director/problem_resolver.rb +8 -2
  119. data/lib/bosh/director/problem_scanner/scanner.rb +1 -1
  120. data/lib/bosh/director/problem_scanner/vm_scan_stage.rb +1 -1
  121. data/lib/bosh/director/validation_helper.rb +5 -5
  122. data/lib/bosh/director/version.rb +1 -1
  123. data/lib/bosh/director/vm_creator.rb +8 -0
  124. data/lib/cloud/dummy.rb +1 -0
  125. metadata +51 -19
  126. data/lib/bosh/director/api/vm_state_manager.rb +0 -9
  127. data/lib/bosh/director/compiled_package/blob_sha_mismatch_error.rb +0 -5
  128. data/lib/bosh/director/compiled_package/compiled_package.rb +0 -30
@@ -5,14 +5,18 @@ module Bosh::Director
5
5
  class Link
6
6
  attr_reader :name
7
7
 
8
- def initialize(name, source)
8
+ def initialize(name, source, template, network_name = nil)
9
9
  @name = name
10
10
  @source = source
11
+ @network_name = network_name
12
+ @template = template
11
13
  end
12
14
 
13
15
  def spec
14
16
  {
15
- 'nodes' => @source.needed_instance_plans.map do |instance_plan|
17
+ 'networks' => @source.networks.map { |network| network.name },
18
+ 'properties' => @template.provides_link_info(@source.name, @name)['mapped_properties'],
19
+ 'instances' => @source.needed_instance_plans.map do |instance_plan|
16
20
  instance = instance_plan.instance
17
21
  availability_zone = instance.availability_zone.name if instance.availability_zone
18
22
  {
@@ -20,11 +24,12 @@ module Bosh::Director
20
24
  'index' => instance.index,
21
25
  'id' => instance.uuid,
22
26
  'az' => availability_zone,
23
- 'networks' => instance_plan.network_addresses
27
+ 'address' => instance_plan.network_address(@network_name),
28
+ 'addresses' => instance_plan.network_addresses,
24
29
  }
25
30
  end
26
31
  }
27
32
  end
28
33
  end
29
34
  end
30
- end
35
+ end
@@ -3,16 +3,16 @@ module Bosh::Director
3
3
  # tested in link_resolver_spec
4
4
 
5
5
  class LinkLookupFactory
6
- def self.create(required_link, link_path, deployment_plan)
6
+ def self.create(consumed_link, link_path, deployment_plan, link_network, consumes_job, consumes_template)
7
7
  if link_path.deployment == deployment_plan.name
8
- PlannerLinkLookup.new(required_link, link_path, deployment_plan)
8
+ PlannerLinkLookup.new(consumed_link, link_path, deployment_plan, link_network)
9
9
  else
10
10
  deployment = Models::Deployment.find(name: link_path.deployment)
11
11
  unless deployment
12
- raise DeploymentInvalidLink, "Link '#{required_link}' references unknown deployment '#{link_path.deployment}'"
12
+ raise DeploymentInvalidLink, "Link '#{consumed_link}' references unknown deployment '#{link_path.deployment}'"
13
13
  end
14
-
15
- DeploymentLinkSpecLookup.new(required_link, link_path, deployment.link_spec)
14
+
15
+ DeploymentLinkSpecLookup.new(consumed_link, link_path, deployment.link_spec, link_network)
16
16
  end
17
17
  end
18
18
  end
@@ -21,10 +21,11 @@ module Bosh::Director
21
21
 
22
22
  # Used to find link source from deployment plan
23
23
  class PlannerLinkLookup
24
- def initialize(required_link, link_path, deployment_plan)
25
- @required_link = required_link
24
+ def initialize(consumed_link, link_path, deployment_plan, link_network)
25
+ @consumed_link = consumed_link
26
26
  @link_path = link_path
27
27
  @jobs = deployment_plan.jobs
28
+ @link_network = link_network
28
29
  end
29
30
 
30
31
  def find_link_spec
@@ -34,19 +35,20 @@ module Bosh::Director
34
35
  template = job.templates.find { |t| t.name == @link_path.template }
35
36
  return nil unless template
36
37
 
37
- found = template.provided_links.find { |p| p.name == @link_path.name && p.type == @required_link.type }
38
+ found = template.provided_links(job.name).find { |p| p.name == @link_path.name && p.type == @consumed_link.type }
38
39
  return nil unless found
39
40
 
40
- Link.new(@link_path.name, job).spec
41
+ Link.new(@link_path.name, job, template, @link_network).spec
41
42
  end
42
43
  end
43
44
 
44
45
  # Used to find link source from link spec in deployment model (saved in DB)
45
46
  class DeploymentLinkSpecLookup
46
- def initialize(required_link, link_path, deployment_link_spec)
47
- @required_link = required_link
47
+ def initialize(consumed_link, link_path, deployment_link_spec, link_network)
48
+ @consumed_link = consumed_link
48
49
  @link_path = link_path
49
50
  @deployment_link_spec = deployment_link_spec
51
+ @link_network = link_network
50
52
  end
51
53
 
52
54
  def find_link_spec
@@ -56,11 +58,17 @@ module Bosh::Director
56
58
  template = job[@link_path.template]
57
59
  return nil unless template
58
60
 
59
- link_path = template.fetch(@link_path.name, {})[@required_link.type]
60
- return nil unless link_path
61
+ link_spec = template.fetch(@link_path.name, {})[@consumed_link.type]
62
+ return nil unless link_spec
63
+
64
+ if @link_network
65
+ link_spec['instances'].each do |instance|
66
+ instance['address'] = instance['addresses'][@link_network]
67
+ end
68
+ end
61
69
 
62
- link_path
70
+ link_spec
63
71
  end
64
72
  end
65
73
  end
66
- end
74
+ end
@@ -1,27 +1,180 @@
1
1
  module Bosh::Director
2
2
  module DeploymentPlan
3
- class LinkPath < Struct.new(:deployment, :job, :template, :name, :path)
4
- def self.parse(current_deployment_name, path, logger)
5
- parts = path.split('.')
3
+ class LinkPath
4
+ attr_reader :deployment, :job, :template, :name, :path, :skip
6
5
 
7
- if parts.size == 3
8
- logger.debug("Link '#{path}' does not specify deployment, using current deployment")
9
- parts.unshift(current_deployment_name)
10
- end
6
+ def initialize(deployment_plan, job_name, template_name)
7
+ @deployment_plan = deployment_plan
8
+ @consumes_job_name = job_name
9
+ @consumes_template_name = template_name
10
+ @deployment = nil
11
+ @job = nil
12
+ @template = nil
13
+ @name = nil
14
+ @path = nil
15
+ @skip = false
16
+ end
11
17
 
12
- if parts.size != 4
13
- logger.error("Invalid link format: #{path}")
14
- raise DeploymentInvalidLink,
15
- "Link '#{path}' is invalid. A link must have either 3 or 4 parts: " +
16
- "[deployment_name.]job_name.template_name.link_name"
18
+ def parse(link_info)
19
+ # in case the link was explicitly set to the string `nil', do not add it
20
+ # to the link paths, even if the link provider exist, since the user intent
21
+ # was explicitly set to not consume any link
22
+
23
+ if link_info["skip_link"] && link_info["skip_link"] == true
24
+ @skip = true
25
+ return
17
26
  end
18
27
 
19
- new(*parts, path)
28
+ if link_info.has_key?("from")
29
+ link_path = fulfill_explicit_link(link_info)
30
+ else
31
+ link_path = fulfill_implicit_link(link_info)
32
+ end
33
+ if link_path != nil
34
+ @deployment, @job, @template, @name = link_path.values_at(:deployment, :job, :template, :name)
35
+ @path = "#{link_path[:deployment]}.#{link_path[:job]}.#{link_path[:template]}.#{link_path[:name]}"
36
+ else
37
+ @skip = true
38
+ end
20
39
  end
21
40
 
22
41
  def to_s
23
- path
42
+ "#{deployment}.#{job}.#{template}.#{name}"
43
+ end
44
+
45
+ private
46
+
47
+ def fulfill_implicit_link(link_info)
48
+ link_type = link_info["type"]
49
+ link_network = link_info["network"]
50
+ found_link_paths = []
51
+
52
+ @deployment_plan.jobs.each do |provides_job|
53
+ if !link_network || provides_job.has_network?(link_network)
54
+ provides_job.templates.each do |provides_template|
55
+ if provides_template.link_infos.has_key?(provides_job.name) && provides_template.link_infos[provides_job.name].has_key?('provides')
56
+ matching_links = provides_template.link_infos[provides_job.name]["provides"].select { |_,v| v["type"] == link_type }
57
+ matching_links.each do |_, matching_link_values|
58
+ link_name = matching_link_values.has_key?("as") ? matching_link_values['as'] : matching_link_values['name']
59
+ found_link_paths.push({:deployment => @deployment_plan.name, :job => provides_job.name, :template => provides_template.name, :name => link_name})
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ if found_link_paths.size == 1
67
+ return found_link_paths[0]
68
+ elsif found_link_paths.size > 1
69
+ all_link_paths = ""
70
+ found_link_paths.each do |link_path|
71
+ all_link_paths = all_link_paths + "\n #{link_path[:deployment]}.#{link_path[:job]}.#{link_path[:template]}.#{link_path[:name]}"
72
+ end
73
+ raise "Multiple instance groups provide links of type '#{link_type}'. Cannot decide which one to use for instance group '#{@consumes_job_name}'.#{all_link_paths}"
74
+ else
75
+ # Only raise an exception if no linkpath was found, and the link is not optional
76
+ if !link_info["optional"]
77
+ raise "Can't find link with type: '#{link_type}' in deployment '#{@deployment_plan.name}'#{" and network '#{link_network}''" unless link_network.to_s.empty?}"
78
+ end
79
+ end
80
+ end
81
+
82
+ def fulfill_explicit_link(link_info)
83
+ from_where = link_info['from']
84
+ link_network = link_info['network']
85
+ parts = from_where.split('.') # the string might be formatted like 'deployment.link_name'
86
+ from_name = parts.shift
87
+
88
+ if parts.size >= 1 # given a deployment name
89
+ deployment_name = from_name
90
+ from_name = parts.shift
91
+ if parts.size >= 1
92
+ raise "From string #{from_where} is poorly formatted. It should look like 'link_name' or 'deployment_name.link_name'"
93
+ end
94
+
95
+ if deployment_name == @deployment_plan.name
96
+ link_path = get_link_path_from_deployment_plan(from_name, link_network)
97
+ else
98
+ link_path = find_deployment_and_get_link_path(deployment_name, from_name, link_network)
99
+ end
100
+ else # given no deployment name
101
+ link_path = get_link_path_from_deployment_plan(from_name, link_network) # search the jobs for the current deployment for a provides
102
+ end
103
+ link_path[:name] = from_name
104
+ return link_path
105
+ end
106
+
107
+ def get_link_path_from_deployment_plan(name, link_network)
108
+ found_link_paths = []
109
+ @deployment_plan.jobs.each do |job|
110
+ if !link_network || job.has_network?(link_network)
111
+ job.templates.each do |template|
112
+ if template.link_infos.has_key?(job.name) && template.link_infos[job.name].has_key?('provides')
113
+ template.link_infos[job.name]['provides'].to_a.each do |provides_name, source|
114
+ link_name = source.has_key?("as") ? source['as'] : source['name']
115
+ if link_name == name
116
+ found_link_paths.push({:deployment => @deployment_plan.name, :job => job.name, :template => template.name, :name => name})
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ if found_link_paths.size == 1
124
+ return found_link_paths[0]
125
+ elsif found_link_paths.size > 1
126
+ all_link_paths = ""
127
+ found_link_paths.each do |link_path|
128
+ all_link_paths = all_link_paths + "\n #{link_path[:deployment]}.#{link_path[:job]}.#{link_path[:template]}.#{link_path[:name]}"
129
+ end
130
+ link_str = "#{@deployment_plan.name}.#{@consumes_job_name}.#{@consumes_template_name}.#{name}"
131
+ raise "Cannot resolve ambiguous link '#{link_str}' in deployment #{@deployment_plan.name}:#{all_link_paths}"
132
+ else
133
+ raise "Can't resolve link '#{name}' in instance group '#{@consumes_job_name}' on job '#{@consumes_template_name}' in deployment '#{@deployment_plan.name}'#{" and network '#{link_network}'" unless link_network.to_s.empty?}."
134
+ end
24
135
  end
136
+
137
+ def find_deployment_and_get_link_path(deployment_name, name, link_network)
138
+ deployment_model = Models::Deployment.where(:name => deployment_name)
139
+
140
+ # get the link path from that deployment
141
+ if deployment_model.count != 0
142
+ return find_link_path_with_name(deployment_model.first, name, link_network)
143
+ else
144
+ raise "Can't find deployment #{deployment_name}"
145
+ end
146
+ end
147
+
148
+ def find_link_path_with_name(deployment, name, link_network)
149
+ deployment_link_spec = deployment.link_spec
150
+ found_link_paths = []
151
+ deployment_link_spec.keys.each do |job|
152
+ deployment_link_spec[job].keys.each do |template|
153
+ deployment_link_spec[job][template].keys.each do |link|
154
+ if link == name
155
+ deployment_link_spec[job][template][link].keys.each do |type|
156
+ if !link_network || (deployment_link_spec[job][template][link][type]['networks'].include? link_network)
157
+ found_link_paths.push({:deployment => deployment.name, :job => job, :template => template, :name => name})
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ if found_link_paths.size == 1
165
+ return found_link_paths[0]
166
+ elsif found_link_paths.size > 1
167
+ all_link_paths = ""
168
+ found_link_paths.each do |link_path|
169
+ all_link_paths = all_link_paths + "\n #{link_path[:deployment]}.#{link_path[:job]}.#{link_path[:template]}.#{link_path[:name]}"
170
+ end
171
+ link_str = "#{@deployment_plan.name}.#{@consumes_job_name}.#{@consumes_template_name}.#{name}"
172
+ raise "Cannot resolve ambiguous link '#{link_str}' in deployment #{deployment.name}:#{all_link_paths}"
173
+ else
174
+ raise "Can't resolve link '#{name}' in instance group '#{@consumes_job_name}' on job '#{@consumes_template_name}' in deployment '#{@deployment_plan.name}'#{" and network '#{link_network}''" unless link_network.to_s.empty?}. Please make sure the link was provided and shared."
175
+ end
176
+ end
177
+
25
178
  end
26
179
  end
27
- end
180
+ end
@@ -7,61 +7,63 @@ module Bosh::Director
7
7
  end
8
8
 
9
9
  def resolve(job)
10
- @logger.debug("Resolving links for job '#{job.name}'")
10
+ @logger.debug("Resolving links for instance group '#{job.name}'")
11
11
 
12
12
  job.templates.each do |template|
13
- resolve_required_links(job, template)
13
+ resolve_consumed_links(job, template)
14
+ ensure_all_links_in_consumes_block_are_mentioned_in_spec(job, template)
14
15
  save_provided_links(job, template)
15
16
  end
16
17
  end
17
18
 
18
19
  private
19
20
 
20
- def resolve_required_links(job, template)
21
- template.required_links.each do |required_link|
22
- link_name = required_link.name
23
-
24
- @logger.debug("Looking for link '#{link_name}' for job '#{job.name}'")
21
+ def resolve_consumed_links(job, template)
22
+ template.model_consumed_links.each do |consumed_link|
23
+ link_name = consumed_link.name
25
24
 
26
25
  link_path = job.link_path(template.name, link_name)
27
- unless link_path
28
- raise JobMissingLink,
29
- "Link path was not provided for required link '#{link_name}' in job '#{job.name}'"
30
- end
31
26
 
32
- link_lookup = LinkLookupFactory.create(required_link, link_path, @deployment_plan)
33
- link_spec = link_lookup.find_link_spec
27
+ if link_path.nil?
28
+ # Only raise an exception when the link_path is nil, and it is not optional
29
+ if !consumed_link.optional
30
+ raise JobMissingLink, "Link path was not provided for required link '#{link_name}' in instance group '#{job.name}'"
31
+ end
32
+ else
33
+ link_network = template.consumes_link_info(job.name, link_name)['network']
34
+ link_lookup = LinkLookupFactory.create(consumed_link, link_path, @deployment_plan, link_network, job.name, template.name)
35
+ link_spec = link_lookup.find_link_spec
34
36
 
35
- unless link_spec
36
- raise DeploymentInvalidLink,
37
- "Cannot resolve link path '#{link_path}' required for link '#{link_name}' " +
38
- "in job '#{job.name}' on template '#{template.name}'"
39
- end
37
+ unless link_spec
38
+ raise DeploymentInvalidLink, "Cannot resolve link path '#{link_path}' required for link '#{link_name}' in instance group '#{job.name}' on job '#{template.name}'"
39
+ end
40
40
 
41
- job.add_resolved_link(link_name, link_spec)
42
- end
41
+ link_spec['instances'].each do |instance|
42
+ instance.delete('addresses')
43
+ end
43
44
 
44
- ensure_provided_links_are_used(job, template)
45
+ job.add_resolved_link(link_name, link_spec)
46
+ end
47
+ end
45
48
  end
46
49
 
47
50
  def save_provided_links(job, template)
48
- template.provided_links.each do |provided_link|
49
- link_spec = Link.new(provided_link.name, job).spec
50
-
51
- @logger.debug("Saving link spec for job '#{job.name}', template: '#{template.name}', " +
52
- "link: '#{provided_link}', spec: '#{link_spec}'")
53
-
54
- @deployment_plan.link_spec[job.name][template.name][provided_link.name][provided_link.type] = link_spec
51
+ template.provided_links(job.name).each do |provided_link|
52
+ if provided_link.shared
53
+ link_spec = Link.new(provided_link.name, job, template).spec
54
+ @logger.debug("Saving link spec for job '#{job.name}', template: '#{template.name}', link: '#{provided_link}', spec: '#{link_spec}'")
55
+ @deployment_plan.link_spec[job.name][template.name][provided_link.name][provided_link.type] = link_spec
56
+ end
55
57
  end
56
58
  end
57
59
 
58
- def ensure_provided_links_are_used(job, template)
60
+ def ensure_all_links_in_consumes_block_are_mentioned_in_spec(job, template)
59
61
  return if job.link_paths.empty?
60
62
  job.link_paths[template.name].to_a.each do |link_name, _|
61
- unless template.required_links.map(&:name).include?(link_name)
63
+ unless template.model_consumed_links.map(&:name).include?(link_name)
62
64
  raise Bosh::Director::UnusedProvidedLink,
63
- "Template '#{template.name}' in job '#{job.name}' specifies link '#{link_name}', " +
64
- "but the release job does not require it."
65
+ "Job '#{template.name}' in instance group '#{job.name}' specifies link '#{link_name}', " +
66
+ "but the release job does not consume it."
65
67
  end
66
68
  end
67
69
  end
@@ -1,20 +1,40 @@
1
1
  module Bosh::Director
2
2
  module DeploymentPlan
3
- class TemplateLink < Struct.new(:name, :type)
4
- def self.parse(link_def)
5
- if link_def.is_a?(String)
6
- return new(link_def, link_def)
3
+ class TemplateLink < Struct.new(:name, :type, :optional, :shared)
4
+ def self.parse(kind, link_def)
5
+ if kind == "consumes"
6
+ return self.parse_consumes_link(link_def)
7
+ elsif kind == "provides"
8
+ return self.parse_provides_link(link_def)
7
9
  end
10
+ end
8
11
 
9
- if link_def.is_a?(Hash) && link_def.has_key?('name') && link_def.has_key?('type')
10
- return new(link_def['name'], link_def['type'])
12
+ def self.parse_consumes_link(link_def)
13
+ if link_def.is_a?(Hash) && link_def.has_key?('type') && link_def.has_key?('name')
14
+ if link_def.has_key?('from')
15
+ return new(link_def['from'].split(".")[-1], link_def['type'], link_def['optional'] || false)
16
+ else
17
+ return new(link_def['name'], link_def['type'], link_def['optional'] || false)
18
+ end
11
19
  end
20
+ raise JobInvalidLinkSpec, "Link '#{link_def}' must be a hash with name and type"
21
+ end
12
22
 
13
- raise JobInvalidLinkSpec, "Link '#{link_def}' must be either string or hash with name and type"
23
+ def self.parse_provides_link(link_def)
24
+ if link_def.is_a?(Hash) && link_def.has_key?('type') && link_def.has_key?('name')
25
+ if link_def.has_key?('optional')
26
+ raise JobInvalidLinkSpec, "Link '#{link_def['name']}' of type '#{link_def['type']}' is a provides link, not allowed to have `optional' key"
27
+ elsif link_def.has_key?('as')
28
+ return new(link_def['as'], link_def['type'], false, link_def['shared'] || false)
29
+ else
30
+ return new(link_def['name'], link_def['type'], false, link_def['shared'] || false)
31
+ end
32
+ end
33
+ raise JobInvalidLinkSpec, "Link '#{link_def}' must be a hash with name and type"
14
34
  end
15
35
 
16
36
  def to_s
17
- "name: #{name}, type: #{type}"
37
+ "name: #{name}, type: #{type}, shared: #{shared || false}"
18
38
  end
19
39
  end
20
40
  end