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



42
43
44
# File 'app/models/job_invocation_composer.rb', line 42

def blank_to_nil(thing)
  thing.presence
end

#concurrency_control_paramsObject



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

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

#execution_timeout_intervalObject



35
36
37
38
39
40
# File 'app/models/job_invocation_composer.rb', line 35

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



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

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
# 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],
    :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,
    :template_invocations => template_invocations_params }.with_indifferent_access
end

#providers_baseObject



31
32
33
# File 'app/models/job_invocation_composer.rb', line 31

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

#targeting(targeting_params) ⇒ Object



96
97
98
# File 'app/models/job_invocation_composer.rb', line 96

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

}



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

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



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

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