180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/cluster/infrastructures/amazon.rb', line 180
def update_instances
iss, terminated = instance_list
begin
res = sdb.select "select * from #{domain} where entry='machine'"
rescue RightAws::AwsError
unless domains.include? domain
sdb.create_domain domain
retry
end
end
sdbs = self.class.from_sdb_results res
sdbs.each do |sd|
aid = sd[:aws_id]
iid = sd['ec2_id']
if !iid
started = sd['start_time_sorted'] && Time.parse(sd['start_time_sorted'])
diff = started && (Time.now - started)
if diff and diff < (12 * 3600)
ins = AmazonInstance.new
ins.set_sdb_attributes sd
iss.push ins
else
$stderr.puts "Cannot find machine #{aid} -- old entry being removed."
sdb.delete_attributes domain, aid
end
else
if ins = iss.detect {|i| i.id.eql? iid }
ins.set_sdb_attributes sd
elsif terminated.include? iid
$stderr.puts "Removing terminated entry #{iid}"
sdb.delete_attributes domain, aid
else
$stderr.puts "Orphaned cluster record of #{aid}. (Just started?) [#{sd.inspect}]"
end
end
end
iss.each do |ins|
if ins.no_sdb?
puts "Cannot find cluster registration for #{ins.ec2_id} -- creating."
end
sdb.put_attributes domain, ins.aws_id, ins.attributes, :replace
end
iss
end
|