class DTK::State::CrdAssembly
Constants
- ASSEMBLY_CRD_VERSION
Attributes
component_objs[R]
components[RW]
crd_content[R]
name[R]
namespace[R]
references[R]
Public Class Methods
get(namespace, name, opts = {})
click to toggle source
# File lib/state/crd_assembly.rb, line 22 def self.get(namespace, name, opts = {}) opts[:apiVersion] = ASSEMBLY_CRD_VERSION crd_assembly = ::DTK::CrdClient.get_kubeclient(opts).get_assembly(name, namespace) CrdAssembly.new(namespace, name, crd_assembly) end
get_attributes_for(namespace, crd_component_name, components, opts = {})
click to toggle source
components can be:
'all' - print attributes for all components ['cmp1', 'cmp2', ...] - print attributes for set of components '<cmp_name>' - print attributes for single component
opts can have keys:
task_id format - format to print in (default is yaml)
# File lib/state/crd_assembly.rb, line 35 def self.get_attributes_for(namespace, crd_component_name, components, opts = {}) output = {} crd_component = get(namespace, crd_component_name, opts) crd_components = crd_component.components if components == 'all' crd_components.each do |kube_component| component_hash = kube_component.to_hash component_name = component_hash.keys.first component = Component.new(component_name, component_hash[component_name], crd_component, opts) output.merge!(component_name => component.attributes(opts)) end else components = [components] unless components.is_a?(Array) check_for_missing_components(crd_components, components) components.each do |component_name| matching_component = crd_components.find{ |cmp| cmp.to_hash.keys.first == component_name } component = Component.new(component_name, matching_component[component_name], crd_component, opts) output.merge!(component_name => component.attributes(opts)) end end output end
get_with_influx_data(namespace, assembly_name, opts = {})
click to toggle source
TODO: this is a temporal solution to avoid breaking backward compatibility; will change this soon
# File lib/state/crd_assembly.rb, line 63 def self.get_with_influx_data(namespace, assembly_name, opts = {}) assembly = get(namespace, assembly_name, opts) components_hash = {} assembly.components.each do |assembly_component| cmp_name = assembly_component.to_hash.keys.first components_hash[cmp_name] = assembly_component[cmp_name].to_hash end component_objs = Component.create_from_kube_array(assembly.components, assembly) component_objs.each do |component_obj| component_name = component_obj.name attr_type_info = component_obj.component_def.attribute_type_info attr_type_info.each do |attr_info| if attr_info.temporal attribute_name = attr_info.name influxdb = ::DTK::State::Component::Attribute::Influxdb.new(:attributes) influxdb_attribute = influxdb.get(namespace, component_name, assembly_name, attribute_name, opts) if valid_attribute = influxdb_attribute.first value = valid_attribute['_value'] if components_hash[component_name][:attributes][attribute_name].is_a?(String) components_hash[component_name][:attributes][attribute_name] = value else components_hash[component_name][:attributes][attribute_name][:value] = value end end end end end assembly.components = components_hash assembly end
new(namespace, name, crd_content)
click to toggle source
# File lib/state/crd_assembly.rb, line 10 def initialize(namespace, name, crd_content) @name = name @namespace = namespace @api_version = crd_content.apiVersion @kind = crd_content.kind @metadata = crd_content.metadata # @crd_content = crd_content @references = crd_content.references @components = crd_content[:spec][:components] || [] # @component_objs = Component.create_from_kube_array(@components, self) end
Private Class Methods
check_for_missing_components(crd_components, requested_components)
click to toggle source
# File lib/state/crd_assembly.rb, line 109 def self.check_for_missing_components(crd_components, requested_components) crd_component_names = crd_components.map{ |cmp| cmp.to_hash.keys.first } missing_components = requested_components - crd_component_names return if missing_components.empty? fail Error.new("You have requested following component(s) but they do not exist in crd instance: #{missing_components.join(', ')}") end
Public Instance Methods
to_hash()
click to toggle source
# File lib/state/crd_assembly.rb, line 97 def to_hash { apiVersion: @api_version, kind: @kind, metadata: filter_metadata(@metadata), references: @references.to_hash, spec: { components: @components.to_hash } } end