bosh_agent 1.5.0.pre.1257 → 1.5.0.pre.1259
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bosh_agent/apply_plan/helpers.rb +12 -6
- data/lib/bosh_agent/apply_plan/job.rb +5 -1
- data/lib/bosh_agent/apply_plan/package.rb +5 -4
- data/lib/bosh_agent/apply_plan/plan.rb +0 -4
- data/lib/bosh_agent/message/apply.rb +2 -6
- data/lib/bosh_agent/message/prepare.rb +14 -75
- data/lib/bosh_agent/util.rb +11 -5
- data/lib/bosh_agent/version.rb +1 -1
- metadata +9 -9
@@ -6,15 +6,13 @@ module Bosh::Agent
|
|
6
6
|
|
7
7
|
def validate_spec(spec)
|
8
8
|
unless spec.is_a?(Hash)
|
9
|
-
raise ArgumentError, "Invalid #{self.class} spec: "
|
10
|
-
"Hash expected, #{spec.class} given"
|
9
|
+
raise ArgumentError, "Invalid #{self.class} spec: Hash expected, #{spec.class} given"
|
11
10
|
end
|
12
11
|
|
13
12
|
required_keys = %w(name version sha1 blobstore_id)
|
14
13
|
missing_keys = required_keys.select { |k| spec[k].nil? }
|
15
14
|
unless missing_keys.empty?
|
16
|
-
raise ArgumentError, "Invalid #{self.class} spec: "
|
17
|
-
"#{missing_keys.join(', ')} missing"
|
15
|
+
raise ArgumentError, "Invalid #{self.class} spec: #{missing_keys.join(', ')} missing"
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
@@ -22,9 +20,17 @@ module Bosh::Agent
|
|
22
20
|
FileUtils.mkdir_p(File.dirname(@install_path))
|
23
21
|
FileUtils.mkdir_p(File.dirname(@link_path))
|
24
22
|
|
25
|
-
|
23
|
+
# Once directory is created we'll never do the fetch a second time;
|
24
|
+
# we make a best effort to ensure directory is in a consistent state
|
25
|
+
unless Dir.exist?(@install_path)
|
26
|
+
Bosh::Agent::Util.unpack_blob(@blobstore_id, @checksum, @install_path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def fetch_bits_and_symlink
|
31
|
+
fetch_bits
|
26
32
|
Bosh::Agent::Util.create_symlink(@install_path, @link_path)
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
30
|
-
end
|
36
|
+
end
|
@@ -39,8 +39,12 @@ module Bosh::Agent
|
|
39
39
|
@link_path = File.join(@base_dir, 'jobs', @template)
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def prepare_for_install
|
43
43
|
fetch_bits
|
44
|
+
end
|
45
|
+
|
46
|
+
def install
|
47
|
+
fetch_bits_and_symlink
|
44
48
|
bind_configuration
|
45
49
|
harden_permissions
|
46
50
|
rescue SystemCallError => e
|
@@ -25,11 +25,12 @@ module Bosh::Agent
|
|
25
25
|
@link_path = File.join(@base_dir, 'packages', @name)
|
26
26
|
end
|
27
27
|
|
28
|
+
def prepare_for_install
|
29
|
+
fetch_bits
|
30
|
+
end
|
31
|
+
|
28
32
|
def install_for_job(job)
|
29
|
-
|
30
|
-
fetch_bits
|
31
|
-
@installed_for_sys = true
|
32
|
-
end
|
33
|
+
fetch_bits_and_symlink
|
33
34
|
create_symlink_in_job(job) if job
|
34
35
|
rescue SystemCallError => e
|
35
36
|
install_failed("System call error: #{e.message}")
|
@@ -108,9 +108,7 @@ module Bosh::Agent
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def apply_job
|
111
|
-
if @
|
112
|
-
logger.info("New jobs already installed")
|
113
|
-
elsif @new_plan.has_jobs?
|
111
|
+
if @new_plan.has_jobs?
|
114
112
|
@new_plan.install_jobs
|
115
113
|
else
|
116
114
|
logger.info("No job")
|
@@ -118,9 +116,7 @@ module Bosh::Agent
|
|
118
116
|
end
|
119
117
|
|
120
118
|
def apply_packages
|
121
|
-
if @
|
122
|
-
logger.info("New packages already installed")
|
123
|
-
elsif @new_plan.has_packages?
|
119
|
+
if @new_plan.has_packages?
|
124
120
|
@new_plan.install_packages
|
125
121
|
else
|
126
122
|
logger.info("No packages")
|
@@ -1,86 +1,25 @@
|
|
1
1
|
module Bosh::Agent::Message
|
2
2
|
class Prepare < Base
|
3
|
-
def
|
4
|
-
|
5
|
-
|
6
|
-
if args.size < 1
|
7
|
-
raise ArgumentError, "not enough arguments"
|
8
|
-
end
|
9
|
-
|
10
|
-
@new_spec = args.first
|
11
|
-
unless @new_spec.is_a?(Hash)
|
12
|
-
raise ArgumentError, "invalid spec, Hash expected, " +
|
13
|
-
"#{@new_spec.class} given"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def prepare
|
18
|
-
initialize_plans
|
19
|
-
|
20
|
-
%w(bosh jobs packages monit).each do |dir|
|
21
|
-
FileUtils.mkdir_p(File.join(base_dir, dir))
|
22
|
-
end
|
23
|
-
|
24
|
-
logger.info("Preparing: #{@new_spec.inspect}")
|
25
|
-
|
26
|
-
if @new_plan.configured?
|
27
|
-
begin
|
28
|
-
apply_job
|
29
|
-
apply_packages
|
30
|
-
log_bit_download_with_agent_state
|
31
|
-
rescue Exception => e
|
32
|
-
raise Bosh::Agent::MessageHandlerError,
|
33
|
-
"#{e.message}: #{e.backtrace}"
|
34
|
-
end
|
35
|
-
end
|
3
|
+
def self.process(args)
|
4
|
+
new(*args).run
|
36
5
|
end
|
37
6
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
initialize_networks
|
42
|
-
|
43
|
-
@old_spec = Bosh::Agent::Config.state.to_hash
|
44
|
-
|
45
|
-
@old_plan = Bosh::Agent::ApplyPlan::Plan.new(@old_spec)
|
46
|
-
@new_plan = Bosh::Agent::ApplyPlan::Plan.new(@new_spec)
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize_networks
|
50
|
-
if @new_spec["networks"]
|
51
|
-
@new_spec["networks"].each do |network, properties|
|
52
|
-
infrastructure = Bosh::Agent::Config.infrastructure
|
53
|
-
network_settings =
|
54
|
-
infrastructure.get_network_settings(network, properties)
|
55
|
-
logger.debug("current network settings from VM: #{network_settings.inspect}")
|
56
|
-
logger.debug("new network settings to be applied: #{properties.inspect}")
|
57
|
-
if network_settings
|
58
|
-
@new_spec["networks"][network].merge!(network_settings)
|
59
|
-
logger.debug("merged network settings: #{@new_spec["networks"].inspect}")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def apply_job
|
66
|
-
if @new_plan.has_jobs?
|
67
|
-
@new_plan.install_jobs
|
68
|
-
else
|
69
|
-
logger.info("No job")
|
70
|
-
end
|
71
|
-
end
|
7
|
+
def initialize(apply_spec)
|
8
|
+
@platform = Bosh::Agent::Config.platform
|
9
|
+
@apply_spec = apply_spec
|
72
10
|
|
73
|
-
|
74
|
-
|
75
|
-
@new_plan.install_packages
|
76
|
-
else
|
77
|
-
logger.info("No packages")
|
11
|
+
unless @apply_spec.is_a?(Hash)
|
12
|
+
raise ArgumentError, "invalid spec, Hash expected, #{@apply_spec.class} given"
|
78
13
|
end
|
79
14
|
end
|
80
15
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
16
|
+
def run
|
17
|
+
plan = Bosh::Agent::ApplyPlan::Plan.new(@apply_spec)
|
18
|
+
plan.jobs.each(&:prepare_for_install)
|
19
|
+
plan.packages.each(&:prepare_for_install)
|
20
|
+
{}
|
21
|
+
rescue Exception => e
|
22
|
+
raise Bosh::Agent::MessageHandlerError, "#{e.inspect}\n#{e.backtrace}"
|
84
23
|
end
|
85
24
|
end
|
86
25
|
end
|
data/lib/bosh_agent/util.rb
CHANGED
@@ -31,16 +31,22 @@ module Bosh::Agent
|
|
31
31
|
raise Bosh::Agent::MessageHandlerError.new(e.inspect)
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
partial_install_path = "#{install_path}-bosh-agent-unpack"
|
35
|
+
logger.info("Creating '#{partial_install_path}'")
|
36
|
+
FileUtils.rm_rf(partial_install_path)
|
37
|
+
FileUtils.mkdir_p(partial_install_path)
|
36
38
|
|
37
|
-
logger.info("Installing to '#{
|
38
|
-
Dir.chdir(
|
39
|
+
logger.info("Installing to '#{partial_install_path}'")
|
40
|
+
Dir.chdir(partial_install_path) do
|
39
41
|
output = `tar --no-same-owner -zxvf #{tf.path} 2>&1`
|
40
42
|
unless $?.exitstatus == 0
|
41
|
-
raise Bosh::Agent::MessageHandlerError.new(
|
43
|
+
raise Bosh::Agent::MessageHandlerError.new('Failed to unpack blob', output)
|
42
44
|
end
|
43
45
|
end
|
46
|
+
|
47
|
+
# Only move contents of the blob to install path at the end
|
48
|
+
# to avoid corrupted package directory
|
49
|
+
FileUtils.mv(partial_install_path, install_path)
|
44
50
|
rescue Exception => e
|
45
51
|
logger.info("Failure unpacking blob: #{e.inspect} #{e.backtrace}")
|
46
52
|
raise e
|
data/lib/bosh_agent/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bosh_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.0.pre.
|
4
|
+
version: 1.5.0.pre.1259
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: netaddr
|
@@ -162,7 +162,7 @@ dependencies:
|
|
162
162
|
requirements:
|
163
163
|
- - ~>
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version: 1.5.0.pre.
|
165
|
+
version: 1.5.0.pre.1259
|
166
166
|
type: :runtime
|
167
167
|
prerelease: false
|
168
168
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -170,7 +170,7 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - ~>
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.5.0.pre.
|
173
|
+
version: 1.5.0.pre.1259
|
174
174
|
- !ruby/object:Gem::Dependency
|
175
175
|
name: bosh_common
|
176
176
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,7 +178,7 @@ dependencies:
|
|
178
178
|
requirements:
|
179
179
|
- - ~>
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version: 1.5.0.pre.
|
181
|
+
version: 1.5.0.pre.1259
|
182
182
|
type: :runtime
|
183
183
|
prerelease: false
|
184
184
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -186,7 +186,7 @@ dependencies:
|
|
186
186
|
requirements:
|
187
187
|
- - ~>
|
188
188
|
- !ruby/object:Gem::Version
|
189
|
-
version: 1.5.0.pre.
|
189
|
+
version: 1.5.0.pre.1259
|
190
190
|
- !ruby/object:Gem::Dependency
|
191
191
|
name: blobstore_client
|
192
192
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,7 +194,7 @@ dependencies:
|
|
194
194
|
requirements:
|
195
195
|
- - ~>
|
196
196
|
- !ruby/object:Gem::Version
|
197
|
-
version: 1.5.0.pre.
|
197
|
+
version: 1.5.0.pre.1259
|
198
198
|
type: :runtime
|
199
199
|
prerelease: false
|
200
200
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -202,7 +202,7 @@ dependencies:
|
|
202
202
|
requirements:
|
203
203
|
- - ~>
|
204
204
|
- !ruby/object:Gem::Version
|
205
|
-
version: 1.5.0.pre.
|
205
|
+
version: 1.5.0.pre.1259
|
206
206
|
- !ruby/object:Gem::Dependency
|
207
207
|
name: rspec-fire
|
208
208
|
requirement: !ruby/object:Gem::Requirement
|
@@ -222,7 +222,7 @@ dependencies:
|
|
222
222
|
description: ! 'This agent listens for instructions from the bosh director on each
|
223
223
|
server that bosh manages.
|
224
224
|
|
225
|
-
|
225
|
+
65813d'
|
226
226
|
email: support@cloudfoundry.com
|
227
227
|
executables:
|
228
228
|
- bosh_agent
|