Module: VCAP::Services::Base::ProvisionerV2
- Defined in:
- lib/base/provisioner_v2.rb
Instance Attribute Summary collapse
-
#service_bindings ⇒ Object
Returns the value of attribute service_bindings.
-
#service_instances ⇒ Object
Returns the value of attribute service_instances.
Instance Method Summary collapse
- #add_binding_handle(entity) ⇒ Object
- #add_instance_handle(entity) ⇒ Object
- #delete_binding_handle(binding_handle) ⇒ Object
- #delete_instance_handle(instance_handle) ⇒ Object
- #find_instance_bindings(instance_id) ⇒ Object
- #get_all_binding_handles ⇒ Object
- #get_all_handles ⇒ Object
-
#get_all_instance_handles ⇒ Object
Helpers.
- #get_binding_handle(binding_id) ⇒ Object
- #get_instance_handle(instance_id) ⇒ Object
- #get_instance_id_list(node_id, &blk) ⇒ Object
- #indexing_handles(handles) ⇒ Object
- #update_binding_handles(binding_handles) ⇒ Object
-
#update_handles(handles) ⇒ Object
Updates our internal handle state from external v2 handles, e.g., ccdb handles.
- #update_instance_handles(instance_handles) ⇒ Object
- #verify_binding_handle_format(handle) ⇒ Object
- #verify_instance_handle_format(handle) ⇒ Object
Instance Attribute Details
#service_bindings ⇒ Object
Returns the value of attribute service_bindings.
10 11 12 |
# File 'lib/base/provisioner_v2.rb', line 10 def service_bindings @service_bindings end |
#service_instances ⇒ Object
Returns the value of attribute service_instances.
9 10 11 |
# File 'lib/base/provisioner_v2.rb', line 9 def service_instances @service_instances end |
Instance Method Details
#add_binding_handle(entity) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/base/provisioner_v2.rb', line 162 def add_binding_handle(entity) # NOTE this handle contains a subset of the information of the handles in ccdb # the handle will possess the full information after the next fetch handle operation # on the gateway and update the corresponding handle; but these information is sufficient # for current operations @service_bindings[entity[:service_id]] = { :credentials => entity[:credentials], :configuration => entity[:configuration], :gateway_name => entity[:service_id], } end |
#add_instance_handle(entity) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/base/provisioner_v2.rb', line 150 def add_instance_handle(entity) # NOTE this handle contains a subset of the information of the handles in ccdb # the handle will possess the full information after the next fetch handle operation # on the gateway and update the corresponding handle; but these information is sufficient # for current operations @service_instances[entity[:service_id]] = { :credentials => entity[:credentials], :configuration => entity[:configuration], :gateway_name => entity[:service_id], } end |
#delete_binding_handle(binding_handle) ⇒ Object
178 179 180 |
# File 'lib/base/provisioner_v2.rb', line 178 def delete_binding_handle(binding_handle) @service_bindings.delete(binding_handle[:gateway_name]) end |
#delete_instance_handle(instance_handle) ⇒ Object
174 175 176 |
# File 'lib/base/provisioner_v2.rb', line 174 def delete_instance_handle(instance_handle) @service_instances.delete(instance_handle[:credentials]["name"]) end |
#find_instance_bindings(instance_id) ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/base/provisioner_v2.rb', line 182 def find_instance_bindings(instance_id) binding_handles = [] @service_bindings.each do |_, handle| binding_handles << handle if handle[:credentials]["name"] == instance_id end binding_handles end |
#get_all_binding_handles ⇒ Object
136 137 138 139 140 |
# File 'lib/base/provisioner_v2.rb', line 136 def get_all_binding_handles binding_handles = @service_bindings.deep_dup binding_handles.each {|binding_id, handle| yield handle if block_given?} binding_handles end |
#get_all_handles ⇒ Object
190 191 192 |
# File 'lib/base/provisioner_v2.rb', line 190 def get_all_handles @service_instances.merge(@service_bindings).deep_dup end |
#get_all_instance_handles ⇒ Object
Helpers
130 131 132 133 134 |
# File 'lib/base/provisioner_v2.rb', line 130 def get_all_instance_handles instance_handles = @service_instances.deep_dup instance_handles.each {|instance_id, handle| yield handle if block_given?} instance_handles end |
#get_binding_handle(binding_id) ⇒ Object
146 147 148 |
# File 'lib/base/provisioner_v2.rb', line 146 def get_binding_handle(binding_id) @service_bindings[binding_id].deep_dup end |
#get_instance_handle(instance_id) ⇒ Object
142 143 144 |
# File 'lib/base/provisioner_v2.rb', line 142 def get_instance_handle(instance_id) @service_instances[instance_id].deep_dup end |
#get_instance_id_list(node_id, &blk) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/base/provisioner_v2.rb', line 116 def get_instance_id_list(node_id, &blk) @logger.debug("Get instance id list for migration") id_list = [] @service_instances.each do |service_id, entity| id_list << service_id if node_id == entity[:credentials]["node_id"] end blk.call(success(id_list)) end |
#indexing_handles(handles) ⇒ Object
indexing handles for (double) check orphan only @param: array handles
handles[0] contains an array of instance handles
handles[1] contains an array of binding handles
returns: array of handles which contains two hashes for instance handles and binding handle.
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/base/provisioner_v2.rb', line 103 def indexing_handles(handles) instance_handles = {} binding_handles = {} handles[0].each { |instance_id, _| instance_handles[instance_id] = nil } handles[1].each do |binding_id, binding_handle| user = binding_handle["credentials"]["username"] || binding_handle["credentials"]["user"] next unless user key = binding_handle["credentials"]["name"] + user binding_handles[key] = nil end [instance_handles, binding_handles] end |
#update_binding_handles(binding_handles) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/base/provisioner_v2.rb', line 57 def update_binding_handles(binding_handles) binding_handles.each do |binding_id, binding_handle| unless verify_binding_handle_format(binding_handle) @logger.warn("Skip not well-formed binding handle:#{binding_handle}.") next end handle = binding_handle.deep_dup @service_bindings[binding_id] = { :credentials => handle['credentials'], # NOTE on gateway we have have 'configuration' field in binding handle in replacement # of the 'gateway_data' field as in ccdb, this is for a easy management/translation # between gateway v1 and v2 provisioner code :configuration => handle['gateway_data'], :gateway_name => handle['gateway_name'], } end end |
#update_handles(handles) ⇒ Object
Updates our internal handle state from external v2 handles, e.g., ccdb handles
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/base/provisioner_v2.rb', line 16 def update_handles(handles) if handles.size == 2 @logger.info("[#{service_description}] Updating #{handles[0].size} instance handles and #{handles[1].size} binding handles in v2 api...") update_instance_handles(handles[0]) update_binding_handles(handles[1]) @logger.info("[#{service_description}] Handles updated") elsif handles.size == 1 # this is for the internal update when doing version update and some other updates # and thus it would only be updating either binding or instance handle; # binding handle would have a field of gateway_name but instance handle would not; if handles[0].has_key?('gateway_name') internal_handle = { handles[0]['gateway_name'] => handles[0] } update_binding_handles(internal_handle) else internal_handle = { handles[0]['credentials']['name'] => handles[0] } update_instance_handles(internal_handle) end else raise "unknown handle type in update handles v2" end end |
#update_instance_handles(instance_handles) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/base/provisioner_v2.rb', line 38 def update_instance_handles(instance_handles) instance_handles.each do |instance_id, instance_handle| unless verify_instance_handle_format(instance_handle) @logger.warn("Skip not well-formed instance handle:#{instance_handle}.") next end handle = instance_handle.deep_dup @service_instances[instance_id] = { :credentials => handle['credentials'], # NOTE on gateway we have have 'configuration' field in instance handle in replacement # of the 'gateway_data' field as in ccdb handle, this is for a easy management/translation # between gateway v1 and v2 provisioner code :configuration => handle['gateway_data'], :gateway_name => handle['credentials']['name'], } end end |
#verify_binding_handle_format(handle) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/base/provisioner_v2.rb', line 87 def verify_binding_handle_format(handle) return nil unless handle return nil unless handle.is_a? Hash VCAP::Services::Internal::ServiceBindingHandleV2.new(handle) true rescue => e @logger.warn("Verify v2 binding handle #{handle} failed:#{e}") return nil end |
#verify_instance_handle_format(handle) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/base/provisioner_v2.rb', line 76 def verify_instance_handle_format(handle) return nil unless handle return nil unless handle.is_a? Hash VCAP::Services::Internal::ServiceInstanceHandleV2.new(handle) true rescue => e @logger.warn("Verify v2 instance handle #{handle} failed:#{e}") return nil end |