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.



5
6
7
# File 'app/models/job_invocation_composer.rb', line 5

def initialize(ui_params)
  @ui_params = ui_params
end

Instance Attribute Details

#ui_paramsObject (readonly)

Returns the value of attribute ui_params.



4
5
6
# File 'app/models/job_invocation_composer.rb', line 4

def ui_params
  @ui_params
end

Instance Method Details

#blank_to_nil(thing) ⇒ Object



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

def blank_to_nil(thing)
  thing.presence
end

#concurrency_control_paramsObject



71
72
73
74
75
76
# File 'app/models/job_invocation_composer.rb', line 71

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

#execution_timeout_intervalObject



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

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



24
25
26
# File 'app/models/job_invocation_composer.rb', line 24

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

#paramsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/job_invocation_composer.rb', line 9

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],
    :password => blank_to_nil(job_invocation_base[:password]),
    :key_passphrase => blank_to_nil(job_invocation_base[:key_passphrase]),
    :sudo_password => blank_to_nil(job_invocation_base[:sudo_password]),
    :concurrency_control => concurrency_control_params,
    :execution_timeout_interval => execution_timeout_interval,
    :template_invocations => template_invocations_params }.with_indifferent_access
end

#providers_baseObject



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

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

#targeting(targeting_params) ⇒ Object



89
90
91
# File 'app/models/job_invocation_composer.rb', line 89

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" => ""
    }
  }
}

}



58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/job_invocation_composer.rb', line 58

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

    template_base
  end
end

#triggeringObject



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

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