foreman_remote_execution 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.rubocop_todo.yml +0 -6
  4. data/app/assets/javascripts/template_input.js +5 -0
  5. data/app/assets/javascripts/template_invocation.js +44 -12
  6. data/app/controllers/api/v2/foreign_input_sets_controller.rb +80 -0
  7. data/app/controllers/api/v2/job_invocations_controller.rb +28 -14
  8. data/app/controllers/api/v2/job_templates_controller.rb +24 -20
  9. data/app/controllers/api/v2/template_inputs_controller.rb +10 -7
  10. data/app/controllers/job_invocations_controller.rb +18 -6
  11. data/app/controllers/job_templates_controller.rb +14 -4
  12. data/app/controllers/template_invocations_controller.rb +5 -3
  13. data/app/helpers/concerns/foreman_remote_execution/hosts_helper_extensions.rb +1 -1
  14. data/app/helpers/concerns/foreman_remote_execution/job_templates_extensions.rb +19 -0
  15. data/app/helpers/remote_execution_helper.rb +88 -39
  16. data/app/lib/actions/remote_execution/run_host_job.rb +11 -8
  17. data/app/lib/actions/remote_execution/run_hosts_job.rb +5 -2
  18. data/app/lib/actions/remote_execution/run_proxy_command.rb +9 -4
  19. data/app/models/concerns/foreman_remote_execution/errors_flattener.rb +2 -2
  20. data/app/models/concerns/foreman_remote_execution/host_extensions.rb +2 -2
  21. data/app/models/concerns/foreman_remote_execution/smart_proxy_extensions.rb +1 -1
  22. data/app/models/concerns/foreman_remote_execution/template_extensions.rb +9 -1
  23. data/app/models/foreign_input_set.rb +49 -0
  24. data/app/models/host_status/execution_status.rb +50 -5
  25. data/app/models/input_template_renderer.rb +52 -7
  26. data/app/models/job_invocation.rb +89 -32
  27. data/app/models/job_invocation_composer.rb +71 -55
  28. data/app/models/job_template.rb +43 -7
  29. data/app/models/remote_execution_provider.rb +1 -1
  30. data/app/models/setting/remote_execution.rb +7 -7
  31. data/app/models/ssh_execution_provider.rb +1 -1
  32. data/app/models/targeting.rb +1 -1
  33. data/app/models/template_invocation.rb +9 -4
  34. data/app/views/api/v2/foreign_input_sets/base.json.rabl +3 -0
  35. data/app/views/api/v2/foreign_input_sets/create.json.rabl +3 -0
  36. data/app/views/api/v2/foreign_input_sets/index.json.rabl +3 -0
  37. data/app/views/api/v2/foreign_input_sets/main.json.rabl +5 -0
  38. data/app/views/api/v2/foreign_input_sets/show.json.rabl +3 -0
  39. data/app/views/api/v2/job_invocations/base.json.rabl +10 -1
  40. data/app/views/api/v2/job_invocations/main.json.rabl +14 -1
  41. data/app/views/api/v2/job_templates/base.json.rabl +1 -1
  42. data/app/views/api/v2/job_templates/main.json.rabl +9 -1
  43. data/app/views/api/v2/job_templates/show.json.rabl +0 -10
  44. data/app/views/api/v2/template_inputs/main.json.rabl +2 -1
  45. data/app/views/job_invocation_task_groups/_job_invocation_task_group.html.erb +1 -1
  46. data/app/views/job_invocations/_description_fields.html.erb +4 -0
  47. data/app/views/job_invocations/_form.html.erb +73 -91
  48. data/app/views/job_invocations/_host_actions_td.html.erb +2 -2
  49. data/app/views/job_invocations/_host_name_td.html.erb +7 -0
  50. data/app/views/job_invocations/_tab_hosts.html.erb +6 -6
  51. data/app/views/job_invocations/_tab_overview.html.erb +3 -3
  52. data/app/views/job_invocations/index.html.erb +6 -4
  53. data/app/views/job_invocations/refresh.js.erb +1 -0
  54. data/app/views/job_invocations/show.html.erb +1 -1
  55. data/app/views/job_invocations/show.js.erb +6 -3
  56. data/app/views/job_templates/_custom_tabs.html.erb +24 -14
  57. data/app/views/job_templates/index.html.erb +3 -1
  58. data/app/views/template_inputs/_foreign_input_set_form.html.erb +12 -0
  59. data/app/views/template_inputs/_form.html.erb +11 -12
  60. data/app/views/template_invocations/show.html.erb +2 -2
  61. data/app/views/templates/package_action.erb +2 -2
  62. data/app/views/templates/puppet_run_once.erb +3 -3
  63. data/app/views/templates/run_command.erb +3 -3
  64. data/app/views/templates/service_action.erb +2 -2
  65. data/app/views/unattended/snippets/_remote_execution_ssh_keys.erb +1 -1
  66. data/config/routes.rb +5 -3
  67. data/db/migrate/20150616080015_create_template_input.rb +1 -1
  68. data/db/migrate/20150708133241_add_targeting.rb +7 -7
  69. data/db/migrate/20150708133242_add_invocation.rb +2 -2
  70. data/db/migrate/20150708133305_add_template_invocation.rb +6 -6
  71. data/db/migrate/20151215114631_add_host_id_to_template_invocation.rb +3 -3
  72. data/db/migrate/20151217092555_migrate_to_task_groups.rb +1 -1
  73. data/db/migrate/20160108134600_create_template_input_sets.rb +16 -0
  74. data/db/migrate/20160108141144_make_job_name_default_to_something.rb +9 -0
  75. data/db/migrate/20160111113032_upcase_ssh_feature.rb +19 -0
  76. data/db/migrate/20160113161916_add_run_host_job_task_id_to_template_invocation.rb +6 -0
  77. data/db/migrate/20160113162007_expand_all_template_invocations.rb +45 -0
  78. data/db/migrate/20160114120200_rename_job_categories.rb +20 -0
  79. data/db/migrate/20160114125628_rename_job_name_to_job_category.rb +19 -0
  80. data/db/seeds.d/60-ssh_proxy_feature.rb +1 -1
  81. data/db/seeds.d/80-provision_templates.rb +2 -2
  82. data/db/seeds.d/90-bookmarks.rb +19 -0
  83. data/doc/plugins/graphviz.rb +5 -5
  84. data/doc/plugins/plantuml.rb +6 -6
  85. data/doc/plugins/tags.rb +4 -4
  86. data/foreman_remote_execution.gemspec +3 -4
  87. data/lib/foreman_remote_execution/engine.rb +12 -9
  88. data/lib/foreman_remote_execution/version.rb +1 -1
  89. data/test/factories/foreman_remote_execution_factories.rb +11 -9
  90. data/test/functional/api/v2/foreign_input_sets_controller_test.rb +63 -0
  91. data/test/functional/api/v2/job_invocations_controller_test.rb +45 -13
  92. data/test/functional/api/v2/job_templates_controller_test.rb +6 -6
  93. data/test/functional/api/v2/template_inputs_controller_test.rb +3 -3
  94. data/test/unit/actions/run_hosts_job_test.rb +3 -4
  95. data/test/unit/actions/run_proxy_command_test.rb +7 -7
  96. data/test/unit/concerns/host_extensions_test.rb +1 -1
  97. data/test/unit/execution_task_status_mapper_test.rb +93 -0
  98. data/test/unit/input_template_renderer_test.rb +182 -9
  99. data/test/unit/job_invocation_composer_test.rb +144 -168
  100. data/test/unit/job_invocation_test.rb +67 -15
  101. data/test/unit/job_template_effective_user_test.rb +2 -2
  102. data/test/unit/job_template_test.rb +36 -12
  103. data/test/unit/remote_execution_provider_test.rb +6 -6
  104. data/test/unit/targeting_test.rb +2 -2
  105. metadata +27 -21
  106. data/app/models/concerns/foreman_remote_execution/template_relations.rb +0 -10
  107. data/app/views/job_invocations/_host_provider_td.html.erb +0 -3
  108. data/app/views/job_templates/auto_complete_job_name.json.erb +0 -3
@@ -1,18 +1,22 @@
1
1
  <div class="tab-pane" id="template_job">
2
2
 
3
- <%= field(f, :job_name) do %>
4
- <%= auto_complete_search(:job_name,
5
- f.object.job_name,
6
- :placeholder => _("Job name") + ' ...',
7
- :name => 'job_template[job_name]',
8
- :id => 'search') %>
3
+ <%= field(f, :job_category, :label => _('Job category')) do %>
4
+ <%= auto_complete_search(:job_category,
5
+ f.object.job_category,
6
+ :placeholder => _("Job category") + ' ...',
7
+ :name => 'job_template[job_category]',
8
+ :id => 'search',
9
+ :disabled => @template.locked?) %>
9
10
  <% end %>
10
11
 
11
12
  <%= text_f f, :description_format,
12
- :help_inline => popover(_('Explanation'), _('Description template determines the job name once it is submitted. Input values can become part of the name
13
- if they are specified using interpolation syntax, e.g. %{fqdn} where fqdn is the name of interpolated input.')) %>
13
+ :disabled => @template.locked?,
14
+ :help_inline => popover(_('Explanation'), _('This template is used to generate the description.
15
+ Input values can be used using the syntax %{package}.
16
+ You may also include the job category and template
17
+ name using %{job_category} and %{template_name}.')) %>
14
18
 
15
- <%= select_f f, :provider_type, providers_options, :first, :last %>
19
+ <%= select_f f, :provider_type, providers_options, :first, :last, :disabled => @template.locked? %>
16
20
 
17
21
  <div class="children_fields">
18
22
  <%= new_child_fields_template(f, :template_inputs, { :partial => "template_inputs/form" }) %>
@@ -21,16 +25,23 @@
21
25
  <%= render 'template_inputs/form', :f => ff %>
22
26
  </div>
23
27
  <% end %>
24
- <%= add_child_link '+ ' + _("Add Input"), :template_inputs, { :title => _('add a input for this template')} %>
28
+ <%= add_child_link '+ ' + _("Add Input"), :template_inputs, { :title => _('add a input for this template')} unless @template.locked? %>
29
+ <%= new_child_fields_template(f, :foreign_input_sets, { :partial => "template_inputs/foreign_input_set_form" }) %>
30
+ <%= f.fields_for :foreign_input_sets do |ff| %>
31
+ <div class="template_input_form fields">
32
+ <%= render 'template_inputs/foreign_input_set_form', :f => ff %>
33
+ </div>
34
+ <% end %>
35
+ <%= add_child_link '+ ' + _("Add Foreign Input Set"), :foreign_input_sets, { :title => _('add an input set for this template to reference a different template inputs') } unless @template.locked? %>
25
36
  </div>
26
37
 
27
38
  <div class="children_fields">
28
39
  <%= field_set_tag _("Effective user") do %>
29
40
  <%= f.fields_for :effective_user, @template.effective_user do |ff| %>
30
41
  <div class="effective_user_form fields">
31
- <%= text_f ff, :value %>
32
- <%= checkbox_f ff, :current_user %>
33
- <%= checkbox_f ff, :overridable %>
42
+ <%= text_f ff, :value, :disabled => @template.locked? %>
43
+ <%= checkbox_f ff, :current_user, :disabled => @template.locked? %>
44
+ <%= checkbox_f ff, :overridable, :disabled => @template.locked? %>
34
45
  </div>
35
46
  <% end %>
36
47
  <% end %>
@@ -38,7 +49,6 @@
38
49
 
39
50
  </div>
40
51
 
41
-
42
52
  <div class="tab-pane" id="template_type">
43
53
  <%= checkbox_f f, :snippet, :onchange => "snippet_changed(this)", :label=>_('Snippet'), :disabled => @template.locked? %>
44
54
  </div>
@@ -3,7 +3,9 @@
3
3
  <%= javascript 'template_input' %>
4
4
 
5
5
  <% title _("Job Templates") %>
6
- <% title_actions display_link_if_authorized(_("New Job Template"), hash_for_new_job_template_path) %>
6
+ <% title_actions(documentation_button_rex('3.1JobTemplates'),
7
+ display_link_if_authorized(_("New Job Template"),
8
+ hash_for_new_job_template_path)) %>
7
9
 
8
10
  <table class="table table-bordered table-striped table-two-pane">
9
11
  <thead>
@@ -0,0 +1,12 @@
1
+ <div class="fields">
2
+ <div class="form-group">
3
+ <%= field_set_tag _("Foreign input set").html_safe +
4
+ ' ' +
5
+ remove_child_link('x', f, {:rel => 'twipsy', "data-title" => _('remove template input set'), :'data-placement' => 'left', :class => 'fr badge badge-danger'}).html_safe do %>
6
+ <%= selectable_f f, :target_template_id, JobTemplate.all.map { |t| [ t.name, t.id ] }, {}, :class => 'input_type_selector without_select2' %>
7
+ <%= checkbox_f f, :include_all, :disabled => @template.locked?, :onchange => 'update_foreign_input_set_include(this)' %>
8
+ <%= text_f f, :include, :class => 'foreign_input_set_include', :disabled => (@template.locked? || f.object.include_all?), :help_inline => _("A comma separated list of input names to be included from the foreign template.") %>
9
+ <%= text_f f, :exclude, :disabled => @template.locked?, :help_inline => _("A comma separated list of input names to be excluded from the foreign template.") %>
10
+ <% end %>
11
+ </div>
12
+ </div>
@@ -1,25 +1,24 @@
1
1
  <div class="fields">
2
2
  <div class="form-group">
3
- <%= field_set_tag _("Template input").html_safe +
4
- ' ' +
5
- remove_child_link('x', f, {:rel => 'twipsy', "data-title" => _('remove template input'), :'data-placement' => 'left', :class => 'fr badge badge-danger'}).html_safe do %>
6
- <%= text_f f, :name %>
7
- <%= checkbox_f f, :required %>
8
- <%= selectable_f f, :input_type, template_input_types_options, {}, :class => 'input_type_selector without_select2' %>
3
+ <%= field_set_tag template_input_header(f, @template) do %>
4
+ <%= text_f f, :name, :disabled => @template.locked? %>
5
+ <%= checkbox_f f, :required, :disabled => @template.locked? %>
6
+ <%= selectable_f f, :input_type, template_input_types_options, {}, :class => 'input_type_selector without_select2', :disabled => @template.locked? %>
9
7
  <div class="fact_input_type custom_input_type_fields" style="<%= f.object.fact_template_input? ? '' : 'display:none' %>">
10
- <%= text_f f, :fact_name, :class => 'fact_input_type', :required => true %>
8
+ <%= text_f f, :fact_name, :class => 'fact_input_type', :required => true, :disabled => @template.locked? %>
11
9
  </div>
12
10
  <div class="variable_input_type custom_input_type_fields" style="<%= f.object.variable_template_input? ? '' : 'display:none' %>">
13
- <%= text_f f, :variable_name, :class => 'variable_input_type', :required => true %>
11
+ <%= text_f f, :variable_name, :class => 'variable_input_type', :required => true, :disabled => @template.locked? %>
14
12
  </div>
15
13
  <div class="puppet_parameter_input_type custom_input_type_fields" style="<%= f.object.puppet_parameter_template_input? ? '' : 'display:none' %>">
16
- <%= text_f f, :puppet_class_name, :class => 'puppet_parameter_input_type', :required => true %>
17
- <%= text_f f, :puppet_parameter_name, :class => 'puppet_parameter_input_type', :required => true %>
14
+ <%= text_f f, :puppet_class_name, :class => 'puppet_parameter_input_type', :required => true, :disabled => @template.locked? %>
15
+ <%= text_f f, :puppet_parameter_name, :class => 'puppet_parameter_input_type', :required => true, :disabled => @template.locked? %>
18
16
  </div>
19
17
  <div class="user_input_type custom_input_type_fields" style="<%= (f.object.user_template_input? || f.object.new_record?) ? '' : 'display:none' %>">
20
- <%= textarea_f f, :options, :rows => 3, :class => 'user_input_type', :help_inline => _("A list of options the user can select from. If not provided, the user will be given a free-form field") %>
18
+ <%= textarea_f f, :options, :rows => 3, :class => 'user_input_type', :help_inline => _("A list of options the user can select from. If not provided, the user will be given a free-form field"),
19
+ :disabled => @template.locked? %>
21
20
  </div>
22
- <%= textarea_f f, :description, :rows => 3 %>
21
+ <%= textarea_f f, :description, :rows => 3, :disabled => @template.locked? %>
23
22
  <% end %>
24
23
  </div>
25
24
  </div>
@@ -1,4 +1,4 @@
1
- <% title _('Detail of %s run') % @template_invocation.job_invocation.job_name %>
1
+ <% title _('Detail of %s run') % @template_invocation.job_invocation.job_category %>
2
2
  <% stylesheet 'template_invocation' %>
3
3
  <% javascript 'template_invocation' %>
4
4
 
@@ -19,7 +19,7 @@
19
19
  <%= preview_box(@template_invocation, @host) %>
20
20
  </div>
21
21
 
22
- <div class="terminal" data-refresh-url="<%= template_invocation_path(@template_invocation_task) %>">
22
+ <div class="terminal" data-refresh-url="<%= template_invocation_path(@template_invocation) %>">
23
23
  <% if @error %>
24
24
  <div class="line error"><%= @error %></div>
25
25
  <% else %>
@@ -1,9 +1,9 @@
1
1
  <%#
2
2
  kind: job_template
3
3
  name: Package Action - SSH Default
4
- job_name: Package Action
4
+ job_category: Packages
5
5
  description_format: "%{action} package(s) %{package}"
6
- provider_type: Ssh
6
+ provider_type: SSH
7
7
  template_inputs:
8
8
  - name: pre_script
9
9
  description: A script to run prior to the package action
@@ -1,9 +1,9 @@
1
1
  <%#
2
2
  kind: job_template
3
3
  name: Puppet Run Once - SSH Default
4
- job_name: Puppet Run Once
5
- description_format: '%{job_name} with "%{puppet_options}"'
6
- provider_type: Ssh
4
+ job_category: Puppet
5
+ description_format: '%{job_category} with "%{puppet_options}"'
6
+ provider_type: SSH
7
7
  template_inputs:
8
8
  - name: puppet_options
9
9
  description: Additional options to pass to puppet
@@ -1,9 +1,9 @@
1
1
  <%#
2
2
  kind: job_template
3
3
  name: Run Command - SSH Default
4
- job_name: Run Command
5
- description_format: "%{job_name} %{command}"
6
- provider_type: Ssh
4
+ job_category: Commands
5
+ description_format: "Run %{command}"
6
+ provider_type: SSH
7
7
  template_inputs:
8
8
  - name: command
9
9
  description: Command to run on the host
@@ -1,9 +1,9 @@
1
1
  <%#
2
2
  kind: job_template
3
3
  name: Service Action - SSH Default
4
- job_name: Service Action
4
+ job_category: Services
5
5
  description_format: '%{action} service %{service}'
6
- provider_type: Ssh
6
+ provider_type: SSH
7
7
  template_inputs:
8
8
  - name: action
9
9
  description: Action to perform on the service
@@ -3,7 +3,7 @@
3
3
  name: remote_execution_ssh_keys
4
4
  %>
5
5
 
6
- <% if @host.params['remote_execution_ssh_keys'].present? %>
6
+ <% if !@host.params['remote_execution_ssh_keys'].blank? %>
7
7
  <% ssh_user = @host.params['remote_execution_ssh_user'] || 'root' %>
8
8
  <% ssh_path = "~#{ssh_user}/.ssh" %>
9
9
 
data/config/routes.rb CHANGED
@@ -7,9 +7,10 @@ Rails.application.routes.draw do
7
7
  post 'preview'
8
8
  end
9
9
  collection do
10
+ post 'preview'
10
11
  get 'revision'
11
12
  get 'auto_complete_search'
12
- get 'auto_complete_job_name'
13
+ get 'auto_complete_job_category'
13
14
  end
14
15
  end
15
16
 
@@ -32,7 +33,7 @@ Rails.application.routes.draw do
32
33
  end
33
34
 
34
35
  namespace :api, :defaults => {:format => 'json'} do
35
- scope "(:apiv)", :module => :v2, :defaults => {:apiv => 'v2'}, :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2, :default => true) do
36
+ scope '(:apiv)', :module => :v2, :defaults => {:apiv => 'v2'}, :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2, :default => true) do
36
37
  resources :job_invocations, :except => [:new, :edit, :update, :destroy] do
37
38
  resources :hosts, :only => :none do
38
39
  get '/', :to => 'job_invocations#output'
@@ -49,7 +50,8 @@ Rails.application.routes.draw do
49
50
  end
50
51
 
51
52
  resources :templates, :only => :none do
52
- resources :template_inputs, :only => [:index, :show, :create, :new, :destroy, :update]
53
+ resources :template_inputs, :only => [:index, :show, :create, :destroy, :update]
54
+ resources :foreign_input_sets, :only => [:index, :show, :create, :destroy, :update]
53
55
  end
54
56
  end
55
57
  end
@@ -14,6 +14,6 @@ class CreateTemplateInput < ActiveRecord::Migration
14
14
  t.timestamps
15
15
  end
16
16
 
17
- add_foreign_key :template_inputs, :templates, :name => "templates_template_id_fk", :column => 'template_id'
17
+ add_foreign_key :template_inputs, :templates, :name => 'templates_template_id_fk', :column => 'template_id'
18
18
  end
19
19
  end
@@ -8,18 +8,18 @@ class AddTargeting < ActiveRecord::Migration
8
8
  t.timestamps
9
9
  end
10
10
 
11
- add_index :targetings, [:bookmark_id], :name => "targetings_bookmark_id"
12
- add_index :targetings, [:user_id], :name => "targetings_user_id"
13
- add_foreign_key :targetings, :bookmarks, :name => "targetings_bookmark_id", :column => 'bookmark_id'
14
- add_foreign_key :targetings, :users, :name => "targetings_user_id", :column => 'user_id'
11
+ add_index :targetings, [:bookmark_id], :name => 'targetings_bookmark_id'
12
+ add_index :targetings, [:user_id], :name => 'targetings_user_id'
13
+ add_foreign_key :targetings, :bookmarks, :name => 'targetings_bookmark_id', :column => 'bookmark_id'
14
+ add_foreign_key :targetings, :users, :name => 'targetings_user_id', :column => 'user_id'
15
15
 
16
16
  create_table :targeting_hosts do |t|
17
17
  t.references :host, :null => false
18
18
  t.references :targeting, :null => false
19
19
  end
20
20
 
21
- add_index :targeting_hosts, [:host_id, :targeting_id], :name => "targeting_hosts_host_targeting_ids"
22
- add_foreign_key :targeting_hosts, :hosts, :name => "targeting_hosts_host_id", :column => 'host_id'
23
- add_foreign_key :targeting_hosts, :targetings, :name => "targeting_hosts_targeting_id", :column => 'targeting_id'
21
+ add_index :targeting_hosts, [:host_id, :targeting_id], :name => 'targeting_hosts_host_targeting_ids'
22
+ add_foreign_key :targeting_hosts, :hosts, :name => 'targeting_hosts_host_id', :column => 'host_id'
23
+ add_foreign_key :targeting_hosts, :targetings, :name => 'targeting_hosts_targeting_id', :column => 'targeting_id'
24
24
  end
25
25
  end
@@ -5,7 +5,7 @@ class AddInvocation< ActiveRecord::Migration
5
5
  t.string :job_name, :null => false
6
6
  end
7
7
 
8
- add_index :job_invocations, [:targeting_id], :name => "job_invocations_targeting_id"
9
- add_foreign_key :job_invocations, :targetings, :name => "job_invocation_targeting_id", :column => 'targeting_id'
8
+ add_index :job_invocations, [:targeting_id], :name => 'job_invocations_targeting_id'
9
+ add_foreign_key :job_invocations, :targetings, :name => 'job_invocation_targeting_id', :column => 'targeting_id'
10
10
  end
11
11
  end
@@ -5,9 +5,9 @@ class AddTemplateInvocation < ActiveRecord::Migration
5
5
  t.references :job_invocation, :null => false
6
6
  end
7
7
 
8
- add_index :template_invocations, [:template_id, :job_invocation_id], :name => "targeting_invocation_template_ji_ids"
9
- add_foreign_key :template_invocations, :templates, :name => "template_invoc_template_id", :column => 'template_id'
10
- add_foreign_key :template_invocations, :job_invocations, :name => "template_invoc_job_invocation_id", :column => 'job_invocation_id'
8
+ add_index :template_invocations, [:template_id, :job_invocation_id], :name => 'targeting_invocation_template_ji_ids'
9
+ add_foreign_key :template_invocations, :templates, :name => 'template_invoc_template_id', :column => 'template_id'
10
+ add_foreign_key :template_invocations, :job_invocations, :name => 'template_invoc_job_invocation_id', :column => 'job_invocation_id'
11
11
 
12
12
  create_table :template_invocation_input_values do |t|
13
13
  t.references :template_invocation, :null => false
@@ -15,8 +15,8 @@ class AddTemplateInvocation < ActiveRecord::Migration
15
15
  t.string :value, :null => false
16
16
  end
17
17
 
18
- add_index :template_invocation_input_values, [:template_invocation_id, :template_input_id], :name => "template_invocation_input_values_ti_ti_ids"
19
- add_foreign_key :template_invocation_input_values, :template_invocations, :name => "template_invoc_input_values_template_invoc_id", :column => 'template_invocation_id'
20
- add_foreign_key :template_invocation_input_values, :template_inputs, :name => "template_invoc_input_values_template_input_id", :column => 'template_input_id'
18
+ add_index :template_invocation_input_values, [:template_invocation_id, :template_input_id], :name => 'template_invocation_input_values_ti_ti_ids'
19
+ add_foreign_key :template_invocation_input_values, :template_invocations, :name => 'template_invoc_input_values_template_invoc_id', :column => 'template_invocation_id'
20
+ add_foreign_key :template_invocation_input_values, :template_inputs, :name => 'template_invoc_input_values_template_input_id', :column => 'template_input_id'
21
21
  end
22
22
  end
@@ -1,11 +1,11 @@
1
1
  class AddHostIdToTemplateInvocation < ActiveRecord::Migration
2
2
  class FakeTemplateInvocation < ActiveRecord::Base
3
- set_table_name 'template_invocations'
3
+ self.table_name = 'template_invocations'
4
4
  end
5
5
 
6
6
  def up
7
7
  add_column :template_invocations, :host_id, :integer
8
- add_foreign_key "template_invocations", "hosts", :name => "template_invocations_hosts_id_fk", :column => 'host_id'
8
+ add_foreign_key 'template_invocations', 'hosts', :name => 'template_invocations_hosts_id_fk', :column => 'host_id'
9
9
  FakeTemplateInvocation.reset_column_information
10
10
 
11
11
  say 'Migrating existing execution locks to explicit relations, this may take a while'
@@ -23,7 +23,7 @@ class AddHostIdToTemplateInvocation < ActiveRecord::Migration
23
23
  end
24
24
 
25
25
  def down
26
- remove_foreign_key "template_invocations", :name => "template_invocations_hosts_id_fk"
26
+ remove_foreign_key 'template_invocations', :name => 'template_invocations_hosts_id_fk'
27
27
  remove_column :template_invocations, :host_id
28
28
  end
29
29
  end
@@ -1,6 +1,6 @@
1
1
  class MigrateToTaskGroups < ActiveRecord::Migration
2
2
  class FakeJobInvocation < ActiveRecord::Base
3
- set_table_name 'job_invocations'
3
+ self.table_name = 'job_invocations'
4
4
  end
5
5
 
6
6
  def up
@@ -0,0 +1,16 @@
1
+ class CreateTemplateInputSets < ActiveRecord::Migration
2
+ def change
3
+ create_table :foreign_input_sets do |t|
4
+ t.integer :template_id, :null => false
5
+ t.integer :target_template_id, :null => false
6
+ t.boolean :include_all, :null => false, :default => true
7
+ t.text :include
8
+ t.text :exclude
9
+ end
10
+ add_index :foreign_input_sets, :template_id
11
+ add_foreign_key :foreign_input_sets, :templates
12
+
13
+ add_index :foreign_input_sets, :target_template_id
14
+ add_foreign_key :foreign_input_sets, :templates, :column => :target_template_id
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ class MakeJobNameDefaultToSomething < ActiveRecord::Migration
2
+ def up
3
+ change_column :templates, :job_name, :string, :default => 'Miscellaneous'
4
+ end
5
+
6
+ def down
7
+ change_column :templates, :job_name, :string, :default => nil
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ class UpcaseSshFeature < ActiveRecord::Migration
2
+ class FakeFeature < ActiveRecord::Base
3
+ self.table_name = 'features'
4
+ end
5
+
6
+ def up
7
+ f = FakeFeature.where(:name => 'Ssh').first
8
+ f.update_attribute :name, 'SSH' if f.present?
9
+
10
+ JobTemplate.where(:provider_type => 'Ssh').update_all("provider_type = 'SSH'")
11
+ end
12
+
13
+ def down
14
+ f = FakeFeature.where(:name => 'SSH').first
15
+ f.update_attribute :name, 'Ssh' if f.present?
16
+
17
+ JobTemplate.where(:provider_type => 'SSH').update_all("provider_type = 'Ssh'")
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ class AddRunHostJobTaskIdToTemplateInvocation < ActiveRecord::Migration
2
+ def change
3
+ add_column :template_invocations, :run_host_job_task_id, :string
4
+ add_index :template_invocations, [:run_host_job_task_id], :name => 'template_invocations_run_host_job_task_id'
5
+ end
6
+ end
@@ -0,0 +1,45 @@
1
+ class ExpandAllTemplateInvocations < ActiveRecord::Migration
2
+ class FakeTemplateInvocation < ActiveRecord::Base
3
+ self.table_name = 'template_invocations'
4
+
5
+ has_many :input_values, :class_name => 'FakeInputValue', :foreign_key => 'template_invocation_id'
6
+ end
7
+
8
+ class FakeInputValue < ActiveRecord::Base
9
+ self.table_name = 'template_invocation_input_values'
10
+ end
11
+
12
+ def up
13
+ # make all template invocations pattern
14
+ FakeTemplateInvocation.update_all 'host_id = NULL'
15
+
16
+ # expand all pattern template invocations and link RunHostJob
17
+ JobInvocation.joins(:targeting).where("#{Targeting.table_name}.resolved_at IS NOT NULL").includes([ :pattern_template_invocations, :targeting, :sub_tasks => :locks ]).each do |job_invocation|
18
+ job_invocation.pattern_template_invocations.each do |pattern_template_invocation|
19
+ job_invocation.targeting.hosts.each do |host|
20
+ task = job_invocation.sub_tasks.find do |sub_task|
21
+ sub_task.locks.find { |lock| lock.resource_type == 'Host::Managed' && lock.resource_id == host.id && lock.name == 'link_resource'}.present?
22
+ end
23
+ next if task.nil? # job invocations with static targeting that failed too early
24
+
25
+ expanded_template_invocation = FakeTemplateInvocation.new
26
+ expanded_template_invocation.attributes = pattern_template_invocation.dup.attributes
27
+ pattern_template_invocation.input_values.each do |input_value|
28
+ input_value = input_value.dup
29
+ expanded_template_invocation.input_values.build(input_value.attributes.except('template_invocation_id'))
30
+ end
31
+ expanded_template_invocation.host_id = host.id
32
+ expanded_template_invocation.run_host_job_task_id = task.id
33
+ expanded_template_invocation.save!
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def down
40
+ # we can't determine the last host for pattern, but keeping template invocations as pattern is safe
41
+ JobInvocation.joins(:targeting).where("#{Targeting.table_name}.resolved_at IS NOT NULL").includes(:template_invocations).each do |job_invocation|
42
+ job_invocation.template_invocations.delete_all
43
+ end
44
+ end
45
+ end