forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_update.rb
More file actions
30 lines (25 loc) · 943 Bytes
/
stack_update.rb
File metadata and controls
30 lines (25 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'repositories/stack_event_repository'
module VCAP::CloudController
class StackUpdate
class InvalidStack < StandardError
end
def initialize(user_audit_info)
@user_audit_info = user_audit_info
@logger = Steno.logger('cc.action.stack_update')
end
def update(stack, message)
stack.db.transaction do
stack_updates = {}
stack_updates[:state] = message.state if message.requested?(:state)
stack_updates[:state_reason] = message.state_reason if message.state_reason_requested?
stack.update(stack_updates) if stack_updates.any?
MetadataUpdate.update(stack, message)
Repositories::StackEventRepository.new.record_stack_update(stack, @user_audit_info, message.audit_hash)
end
@logger.info("Finished updating stack #{stack.guid}")
stack
rescue Sequel::ValidationFailed => e
raise InvalidStack.new(e.message)
end
end
end