Class: JobInvocationComposer::UiParams

Inherits:
Object
  • Object
show all
Defined in:
app/models/job_invocation_composer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ui_params) ⇒ UiParams

Returns a new instance of UiParams.



8
9
10
# File 'app/models/job_invocation_composer.rb', line 8

def initialize(ui_params)
  @ui_params = ui_params
end

Instance Attribute Details

#ui_paramsObject (readonly)

Returns the value of attribute ui_params.



7
8
9
# File 'app/models/job_invocation_composer.rb', line 7

def ui_params
  @ui_params
end

Instance Method Details

#blank_to_nil(thing) ⇒ Object



44
45
46
# File 'app/models/job_invocation_composer.rb', line 44

def blank_to_nil(thing)
  thing.presence
end

#concurrency_control_paramsObject



80
81
82
83
84
85
# File 'app/models/job_invocation_composer.rb', line 80

def concurrency_control_params
  {
    :time_span => job_invocation_base[:time_span],
    :level => job_invocation_base[:concurrency_level],
  }
end

#execution_timeout_intervalObject



37
38
39
40
41
42
# File 'app/models/job_invocation_composer.rb', line 37

def execution_timeout_interval
  providers_base.values.map do |provider|
    id = provider[:job_template_id]
    provider.fetch(:job_templates, {}).fetch(id, {})[:execution_timeout_interval]
  end.first
end

#job_invocation_baseObject



29
30
31
# File 'app/models/job_invocation_composer.rb', line 29

def job_invocation_base
  ui_params.fetch(:job_invocation, {})
end

#paramsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/job_invocation_composer.rb', line 12

def params
  { :job_category => job_invocation_base[:job_category],
    :targeting => targeting(ui_params.fetch(:targeting, {})),
    :triggering => triggering,
    :host_ids => ui_params[:host_ids],
    :remote_execution_feature_id => job_invocation_base[:remote_execution_feature_id],
    :description_format => job_invocation_base[:description_format],
    :ssh_user => blank_to_nil(job_invocation_base[:ssh_user]),
    :password => blank_to_nil(job_invocation_base[:password]),
    :key_passphrase => blank_to_nil(job_invocation_base[:key_passphrase]),
    :effective_user_password => blank_to_nil(job_invocation_base[:effective_user_password]),
    :concurrency_control => concurrency_control_params,
    :execution_timeout_interval => execution_timeout_interval,
    :time_to_pickup => job_invocation_base[:time_to_pickup],
    :template_invocations => template_invocations_params }.with_indifferent_access
end

#providers_baseObject



33
34
35
# File 'app/models/job_invocation_composer.rb', line 33

def providers_base
  job_invocation_base.fetch(:providers, {})
end

#targeting(targeting_params) ⇒ Object



98
99
100
# File 'app/models/job_invocation_composer.rb', line 98

def targeting(targeting_params)
  targeting_params.merge(:user_id => User.current.id)
end

#template_invocations_paramsObject

TODO: Fix this comment parses params to get job templates in form of id => attributes for selected job templates, e.g.

"459" => {,
"454" => {
  "input_values" => {
    "2" => {
      "value" => ""
    },
    "5" => {
      "value" => ""
    }
  }
}

}



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/job_invocation_composer.rb', line 63

def template_invocations_params
  providers_base.values.map do |template_params|
    template_base = template_params.fetch(:job_templates, {}).fetch(template_params[:job_template_id], {}).dup.with_indifferent_access
    template_base[:template_id] = template_params[:job_template_id]
    input_values_params = template_base.fetch(:input_values, {})
    template_base[:input_values] = input_values_params.map do |id, values|
      values.merge(:template_input_id => id)
    end

    provider_values_params = template_base.fetch(:provider_input_values, {})
    template_base[:provider_input_values] = provider_values_params.map do |key, hash|
      { :name => key, :value => hash[:value] }
    end
    template_base
  end
end

#triggeringObject



87
88
89
90
91
92
93
94
95
96
# File 'app/models/job_invocation_composer.rb', line 87

def triggering
  return {} unless ui_params.key?(:triggering)

  trig = ui_params[:triggering]
  keys = (1..5).map { |i| "end_time(#{i}i)" }
  values = trig.fetch(:end_time, {}).values_at(*keys)
  return trig if values.any?(&:nil?)

  trig.merge(:end_time => Time.local(*values))
end