brpm_content_framework 0.1.55
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.
- checksums.yaml +15 -0
- data/.gitignore +38 -0
- data/.travis.yml +17 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +308 -0
- data/Rakefile +23 -0
- data/TO_BE_MIGRATED.txt +9 -0
- data/architecture.png +0 -0
- data/automations/direct_execute.meta +10 -0
- data/automations/direct_execute.rb +10 -0
- data/automations/install_module.meta +10 -0
- data/automations/install_module.rb +13 -0
- data/bin/brpm_install +30 -0
- data/bin/brpm_uninstall +30 -0
- data/bin/event_handler +63 -0
- data/bin/webhook_receiver +49 -0
- data/brpm_content.gemspec +31 -0
- data/config.yml +8 -0
- data/infrastructure/.bashrc +6 -0
- data/infrastructure/.brpm +2 -0
- data/infrastructure/config/customer_include.rb +26 -0
- data/infrastructure/config/server.yml +3 -0
- data/infrastructure/log.html +39 -0
- data/infrastructure/scripts/backup_database.sh +19 -0
- data/infrastructure/scripts/ddns.sh +10 -0
- data/infrastructure/scripts/install_brpm.sh +63 -0
- data/infrastructure/scripts/maintenance.sh +4 -0
- data/infrastructure/scripts/patch_brpm.sh +90 -0
- data/infrastructure/scripts/restore_database.sh +33 -0
- data/infrastructure/scripts/run_event_handler.cmd +19 -0
- data/infrastructure/scripts/run_event_handler.sh +20 -0
- data/infrastructure/scripts/run_webhook_receiver.cmd +15 -0
- data/infrastructure/scripts/run_webhook_receiver.sh +15 -0
- data/infrastructure/silent_install_options_4.6.txt +93 -0
- data/infrastructure/silent_install_options_upgrade_4.6.txt +92 -0
- data/infrastructure/smtp_settings.rb +42 -0
- data/lib/brpm_auto.rb +358 -0
- data/lib/brpm_script_executor.rb +80 -0
- data/lib/logging/brpm_logger.rb +39 -0
- data/lib/logging/logger_base.rb +36 -0
- data/lib/logging/simple_logger.rb +27 -0
- data/lib/module_installer.rb +483 -0
- data/lib/params/all_params.rb +80 -0
- data/lib/params/integration_settings.rb +27 -0
- data/lib/params/params.rb +174 -0
- data/lib/params/params_base.rb +81 -0
- data/lib/params/request_params.rb +38 -0
- data/lib/rest_api.rb +155 -0
- data/lib/semaphore.rb +79 -0
- data/lib/utilities.rb +317 -0
- data/lib/version_control/git.rb +192 -0
- data/lib/version_control/svn.rb +221 -0
- data/lib/write_to.rb +1 -0
- data/tests/all_params_spec.rb +116 -0
- data/tests/brpm_auto_spec.rb +84 -0
- data/tests/customer_include/config/customer_include.rb +10 -0
- data/tests/customer_include/config/server.yml +3 -0
- data/tests/customer_include_spec.rb +29 -0
- data/tests/gemspec_spec.rb +11 -0
- data/tests/module_installer_spec.rb +46 -0
- data/tests/params_spec.rb +172 -0
- data/tests/request_params_spec.rb +86 -0
- data/tests/server_yaml_spec.rb +19 -0
- data/tests/spec_helper.rb +64 -0
- data/to_be_migrated/brpm_framework.rb +88 -0
- data/to_be_migrated/customer_include_default.rb +25 -0
- data/to_be_migrated/local_jirb.rb +15 -0
- data/to_be_migrated/resource_framework.rb +211 -0
- data/transport/dispatch_baa.rb +355 -0
- data/transport/dispatch_base.rb +345 -0
- data/transport/dispatch_nsh.rb +248 -0
- data/transport/dispatch_ssh.rb +154 -0
- data/transport/transport_baa.rb +1095 -0
- data/transport/transport_nsh.rb +359 -0
- data/transport/transport_ssh.rb +220 -0
- metadata +204 -0
@@ -0,0 +1,483 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'rubygems/package'
|
3
|
+
require 'rubygems/installer'
|
4
|
+
require "bundler"
|
5
|
+
|
6
|
+
class ModuleInstaller
|
7
|
+
def initialize
|
8
|
+
set_gem_home
|
9
|
+
end
|
10
|
+
|
11
|
+
def install_module(module_name_or_path, module_version = nil)
|
12
|
+
brpm_content_spec = nil
|
13
|
+
|
14
|
+
if true #TODO: support no-gem-install mode
|
15
|
+
module_spec, specs = install_gem(module_name_or_path, module_version)
|
16
|
+
|
17
|
+
brpm_content_spec = specs.find { |spec| spec.name == "brpm_content" } if specs
|
18
|
+
|
19
|
+
install_bundle_if_necessary(module_spec)
|
20
|
+
else
|
21
|
+
module_name = module_name_or_path
|
22
|
+
module_spec = Gem::Specification.find_by_name(module_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
if brpm_installed_locally?
|
26
|
+
BrpmAuto.log "A BRPM instance is installed locally"
|
27
|
+
|
28
|
+
if brpm_content_spec
|
29
|
+
if brpm_content_spec.version > Gem::Version.new(BrpmAuto.version) or ! File.exist?(get_symlink_path)
|
30
|
+
BrpmAuto.log "Updating the symlink to brpm_content-latest..."
|
31
|
+
update_symlink_to_brpm_content(brpm_content_spec.gem_dir)
|
32
|
+
end
|
33
|
+
|
34
|
+
if brpm_content_spec.version > Gem::Version.new(BrpmAuto.version) or ! File.exist?("#{ENV["BRPM_HOME"]}/automation_results/log.html")
|
35
|
+
BrpmAuto.log "Copying the log.html file to te automation_results directory..."
|
36
|
+
FileUtils.cp("#{brpm_content_spec.gem_dir}/infrastructure/log.html", "#{ENV["BRPM_HOME"]}/automation_results")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
BrpmAuto.log "Preparing the connectivity to BRPM..."
|
41
|
+
if prepare_brpm_connection
|
42
|
+
BrpmAuto.log "Creating an automation error for '******** ERROR ********' if one doesn't exist yet..."
|
43
|
+
create_automation_error_if_not_exists("******** ERROR ********")
|
44
|
+
|
45
|
+
module_friendly_name = get_module_friendly_name(module_spec)
|
46
|
+
BrpmAuto.log "Creating an automation category for #{module_friendly_name} if one doesn't exist yet..."
|
47
|
+
create_automation_category_if_not_exists(module_friendly_name)
|
48
|
+
|
49
|
+
BrpmAuto.log "Retrieving the integration servers..."
|
50
|
+
integration_servers = @brpm_rest_client.get_project_servers
|
51
|
+
|
52
|
+
BrpmAuto.log "Installing the automation script wrappers in the local BRPM instance..."
|
53
|
+
failed_scripts = each_auto_script_wrapper(module_spec.gem_dir) do |auto_script_path, automation_type|
|
54
|
+
BrpmAuto.log "Installing automation script wrapper for script #{auto_script_path}..."
|
55
|
+
install_auto_script_wrapper(auto_script_path, automation_type, module_spec.name, module_friendly_name, integration_servers)
|
56
|
+
end
|
57
|
+
|
58
|
+
if failed_scripts.size > 0
|
59
|
+
return false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def uninstall_module(module_name, module_version)
|
66
|
+
if brpm_installed_locally?
|
67
|
+
BrpmAuto.log "A BRPM instance is installed locally"
|
68
|
+
|
69
|
+
BrpmAuto.log "Preparing the connectivity to BRPM..."
|
70
|
+
if prepare_brpm_connection
|
71
|
+
version_req = Gem::Requirement.create(Gem::Version.new(module_version))
|
72
|
+
module_spec = Gem::Specification.find_by_name(module_name, version_req)
|
73
|
+
|
74
|
+
module_friendly_name = get_module_friendly_name(module_spec)
|
75
|
+
|
76
|
+
BrpmAuto.log "Uninstalling the automation script wrappers in the local BRPM instance..."
|
77
|
+
failed_scripts = each_auto_script_wrapper(module_spec.gem_dir) do |auto_script_path, automation_type|
|
78
|
+
BrpmAuto.log "Uninstalling automation script wrapper for script #{auto_script_path}..."
|
79
|
+
uninstall_auto_script_wrapper(auto_script_path, automation_type, module_friendly_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
if failed_scripts.size > 0
|
83
|
+
BrpmAuto.log "Aborting the uninstall."
|
84
|
+
return false
|
85
|
+
end
|
86
|
+
|
87
|
+
BrpmAuto.log "Deleting the automation category for #{module_friendly_name}..."
|
88
|
+
delete_automation_category(module_friendly_name)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
BrpmAuto.log "Uninstalling gem #{module_name} #{module_version}..."
|
93
|
+
BrpmAuto.log `gem uninstall #{module_name} -v #{module_version} -x`
|
94
|
+
|
95
|
+
return true
|
96
|
+
end
|
97
|
+
|
98
|
+
def module_installed?(module_name, module_version = nil)
|
99
|
+
Gem::Specification.find_by_name(module_name).size > 0
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def prepare_brpm_connection
|
105
|
+
brpm_file = File.expand_path("~/.brpm")
|
106
|
+
|
107
|
+
brpm_config = nil
|
108
|
+
if File.exists?(brpm_file)
|
109
|
+
brpm_config = YAML.load_file(brpm_file)
|
110
|
+
end
|
111
|
+
|
112
|
+
if brpm_config
|
113
|
+
unless brpm_config["brpm_url"] and brpm_config["brpm_api_token"]
|
114
|
+
BrpmAuto.log "WARNING - Properties brpm_url and/or brpm_api_token don't exist in file ~/.brpm so not installing the automation script wrappers in BRPM. If you want to install them the next time you should add brpm_url and brpm_api_token properties in yaml format in file ~/.brpm."
|
115
|
+
return false
|
116
|
+
end
|
117
|
+
else
|
118
|
+
BrpmAuto.log "WARNING - File ~/.brpm doesn't exist so not installing the automation script wrappers in BRPM. If you want to install them the next time you should create this file and add brpm_url and brpm_api_token properties in yaml format."
|
119
|
+
return false
|
120
|
+
end
|
121
|
+
|
122
|
+
begin
|
123
|
+
BrpmAuto.log "Loading brpm_module_brpm..."
|
124
|
+
BrpmAuto.require_module "brpm_module_brpm"
|
125
|
+
rescue Gem::GemNotFoundException
|
126
|
+
BrpmAuto.log "WARNING - Module brpm_module_brpm is not installed so not installing the automation script wrappers in BRPM."
|
127
|
+
return false
|
128
|
+
end
|
129
|
+
|
130
|
+
@brpm_rest_client = BrpmRestClient.new(brpm_config["brpm_url"], brpm_config["brpm_api_token"])
|
131
|
+
true
|
132
|
+
end
|
133
|
+
|
134
|
+
def install_gem(module_name_or_path, module_version)
|
135
|
+
if module_name_or_path =~ /\.gem$/ and File.file? module_name_or_path
|
136
|
+
BrpmAuto.log "Installing gem #{module_name_or_path}#{module_version.nil? ? "" : " " + module_version} from file..."
|
137
|
+
require 'rubygems/name_tuple'
|
138
|
+
source = Gem::Source::SpecificFile.new module_name_or_path
|
139
|
+
module_spec = source.spec
|
140
|
+
|
141
|
+
gem = source.download module_spec
|
142
|
+
|
143
|
+
inst = Gem::Installer.new gem
|
144
|
+
inst.install
|
145
|
+
BrpmAuto.log "Done."
|
146
|
+
else
|
147
|
+
BrpmAuto.log "Installing gem #{module_name_or_path}#{module_version.nil? ? "" : " " + module_version}..."
|
148
|
+
version_req = module_version ? Gem::Requirement.create(Gem::Version.new(module_version)) : Gem::Requirement.default
|
149
|
+
specs = Gem.install(module_name_or_path, version_req)
|
150
|
+
|
151
|
+
BrpmAuto.log "Installed gems:"
|
152
|
+
specs.each do |spec|
|
153
|
+
BrpmAuto.log " - #{spec.name} #{spec.version}"
|
154
|
+
end
|
155
|
+
|
156
|
+
module_spec = specs.find { |spec| spec.name == module_name_or_path}
|
157
|
+
end
|
158
|
+
|
159
|
+
return module_spec, specs
|
160
|
+
end
|
161
|
+
|
162
|
+
def set_gem_home
|
163
|
+
if BrpmAuto.run_from_brpm or BrpmAuto.params.unit_test
|
164
|
+
# we need to override the GEM_HOME env var, otherwise the gems will be installed in BRPM's own gemset
|
165
|
+
ENV["GEM_HOME"] = BrpmAuto.get_gems_root_path
|
166
|
+
Gem.paths = ENV
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def install_bundle_if_necessary(spec)
|
171
|
+
gemfile = File.join(spec.gem_dir, "Gemfile")
|
172
|
+
gemfile_lock = File.join(spec.gem_dir, "Gemfile.lock")
|
173
|
+
|
174
|
+
if File.exists?(gemfile) && File.exists?(gemfile_lock)
|
175
|
+
if BrpmAuto.run_from_brpm or BrpmAuto.params.unit_test
|
176
|
+
command = "cd #{spec.gem_dir}; export GEM_HOME=#{BrpmAuto.get_gems_root_path}; bundle install"
|
177
|
+
else
|
178
|
+
command = "cd #{spec.gem_dir}; bundle install"
|
179
|
+
end
|
180
|
+
BrpmAuto.log "Found a Gemfile.lock so executing command '#{command}'..."
|
181
|
+
result = BrpmAuto.execute_shell(command)
|
182
|
+
|
183
|
+
BrpmAuto.log result["stdout"] if result["stdout"] and !result["stdout"].empty?
|
184
|
+
unless result["status"] == 0
|
185
|
+
raise result["stderr"]
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_symlink_path
|
191
|
+
"#{ENV["GEM_HOME"]}/gems/brpm_content-latest"
|
192
|
+
end
|
193
|
+
|
194
|
+
def update_symlink_to_brpm_content(brpm_content_path)
|
195
|
+
new_version_path = brpm_content_path
|
196
|
+
symlink_path = get_symlink_path
|
197
|
+
|
198
|
+
BrpmAuto.log "Linking #{symlink_path} to #{new_version_path}..."
|
199
|
+
result = BrpmAuto.execute_shell("ln -sfn #{new_version_path} #{symlink_path}")
|
200
|
+
BrpmAuto.log result["stdout"] if result["stdout"] and !result["stdout"].empty?
|
201
|
+
unless result["status"] == 0
|
202
|
+
raise result["stderr"]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def brpm_installed_locally?
|
207
|
+
ENV["BRPM_HOME"] and !ENV["BRPM_HOME"].empty?
|
208
|
+
end
|
209
|
+
|
210
|
+
def get_module_friendly_name(module_spec)
|
211
|
+
module_config = YAML.load_file("#{module_spec.gem_dir}/config.yml")
|
212
|
+
|
213
|
+
module_config["name"] || "#{module_spec.name.sub("brpm_module_", "").capitalize}"
|
214
|
+
end
|
215
|
+
|
216
|
+
def create_automation_error_if_not_exists(automation_error)
|
217
|
+
list_item = @brpm_rest_client.get_list_item_by_name("AutomationErrors", automation_error)
|
218
|
+
|
219
|
+
unless list_item
|
220
|
+
BrpmAuto.log "Automation error #{automation_error} doesn't exist yet, so creating it now..."
|
221
|
+
list_item = {}
|
222
|
+
list_item["list_id"] = @brpm_rest_client.get_list_by_name("AutomationErrors")["id"]
|
223
|
+
list_item["value_text"] = automation_error
|
224
|
+
@brpm_rest_client.create_list_item_from_hash(list_item)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def create_automation_category_if_not_exists(module_friendly_name)
|
229
|
+
list_item = @brpm_rest_client.get_list_item_by_name("AutomationCategory", module_friendly_name)
|
230
|
+
|
231
|
+
unless list_item
|
232
|
+
BrpmAuto.log "Automation category #{module_friendly_name} doesn't exist yet, so creating it now..."
|
233
|
+
list_item = {}
|
234
|
+
list_item["list_id"] = @brpm_rest_client.get_list_by_name("AutomationCategory")["id"]
|
235
|
+
list_item["value_text"] = module_friendly_name
|
236
|
+
@brpm_rest_client.create_list_item_from_hash(list_item)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def delete_automation_category(module_friendly_name)
|
241
|
+
#TODO: first check if there are any manually created automation scripts added to this automation category. If yes then dont delete it
|
242
|
+
list_item = @brpm_rest_client.get_list_item_by_name("AutomationCategory", module_friendly_name)
|
243
|
+
|
244
|
+
if list_item
|
245
|
+
@brpm_rest_client.archive_list_item(list_item["id"])
|
246
|
+
@brpm_rest_client.delete_list_item(list_item["id"])
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def each_auto_script_wrapper(module_path)
|
251
|
+
# For resource automations
|
252
|
+
resource_automation_dir = "#{module_path}/resource_automations"
|
253
|
+
resource_automation_script_paths = Dir.glob("#{resource_automation_dir}/*.rb")
|
254
|
+
|
255
|
+
failed_scripts = []
|
256
|
+
if resource_automation_script_paths.size > 0
|
257
|
+
resource_automation_script_paths.each do |auto_script_path|
|
258
|
+
begin
|
259
|
+
yield auto_script_path, "ResourceAutomation"
|
260
|
+
rescue Exception => e
|
261
|
+
failed_scripts << auto_script_path
|
262
|
+
BrpmAuto.log_error(e)
|
263
|
+
BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# For automations
|
269
|
+
automation_dir = "#{module_path}/automations"
|
270
|
+
automation_script_paths = Dir.glob("#{automation_dir}/*.rb")
|
271
|
+
|
272
|
+
if automation_script_paths.size > 0
|
273
|
+
automation_script_paths.each do |auto_script_path|
|
274
|
+
begin
|
275
|
+
yield auto_script_path, "Automation"
|
276
|
+
rescue Exception => e
|
277
|
+
failed_scripts << auto_script_path
|
278
|
+
BrpmAuto.log_error(e)
|
279
|
+
BrpmAuto.log "\n\t" + e.backtrace.join("\n\t")
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
if failed_scripts.size > 0
|
285
|
+
BrpmAuto.log "The following wrapper scripts generated errors:"
|
286
|
+
failed_scripts.each do |failed_script|
|
287
|
+
BrpmAuto.log " - #{failed_script}"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
failed_scripts
|
292
|
+
end
|
293
|
+
|
294
|
+
def install_auto_script_wrapper(auto_script_path, automation_type, module_name, module_friendly_name, integration_servers)
|
295
|
+
auto_script_config = get_auto_script_config(auto_script_path, module_friendly_name)
|
296
|
+
|
297
|
+
BrpmAuto.log "Installing the wrapper script for automation script #{auto_script_config["name"]} (friendly name: #{auto_script_config["friendly_name"]}, automation type: #{automation_type})..."
|
298
|
+
|
299
|
+
if automation_type == "Automation"
|
300
|
+
add_version_params(auto_script_config["params"])
|
301
|
+
end
|
302
|
+
|
303
|
+
wrapper_script_content = ""
|
304
|
+
if auto_script_config["params"].size > 0
|
305
|
+
params_content = auto_script_config["params"].to_yaml
|
306
|
+
params_content.sub!("---\n", "") # Remove the yaml document separator line
|
307
|
+
params_content.gsub!(/(^)+/, "# ") # Prepend "# " to each line
|
308
|
+
wrapper_script_content = "###\n#{params_content}###\n"
|
309
|
+
end
|
310
|
+
|
311
|
+
integration_server = nil
|
312
|
+
if auto_script_config["integration_server_type"]
|
313
|
+
server_type_id = @brpm_rest_client.get_id_for_project_server_type(auto_script_config["integration_server_type"])
|
314
|
+
if server_type_id
|
315
|
+
integration_server = integration_servers.find { |integr_server| integr_server["server_name_id"] == server_type_id } #TODO: support multiple integration servers of same type (user should pick one)
|
316
|
+
else
|
317
|
+
integration_server = integration_servers.find { |integr_server| integr_server["name"].include?(auto_script_config["integration_server_type"]) } #TODO: support multiple integration servers of same type (user should pick one)
|
318
|
+
end
|
319
|
+
|
320
|
+
if integration_server
|
321
|
+
wrapper_script_content += "\n"
|
322
|
+
wrapper_script_content += get_integration_server_template(integration_server["id"], integration_server["name"], auto_script_config["integration_server_type"])
|
323
|
+
else
|
324
|
+
BrpmAuto.log "WARNING - An integration server of type #{auto_script_config["integration_server_type"]} (or that has #{auto_script_config["integration_server_type"]} in its name if the integration server type is not supported) doesn't exist so not setting the integration server in the wrapper script."
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
wrapper_script_content += "\n"
|
329
|
+
wrapper_script_content += get_script_executor_template(automation_type, module_name, auto_script_config["name"])
|
330
|
+
|
331
|
+
script = {}
|
332
|
+
script["name"] = auto_script_config["friendly_name"]
|
333
|
+
script["description"] = auto_script_config["description"] || ""
|
334
|
+
script["automation_type"] = automation_type
|
335
|
+
script["automation_category"] = module_friendly_name
|
336
|
+
script["content"] = wrapper_script_content
|
337
|
+
script["integration_id"] = integration_server["id"] if auto_script_config["integration_server_type"] and integration_server
|
338
|
+
if automation_type == "ResourceAutomation"
|
339
|
+
script["unique_identifier"] = auto_script_config["resource_id"] || auto_script_config["name"]
|
340
|
+
script["render_as"] = auto_script_config["render_as"] || "List"
|
341
|
+
end
|
342
|
+
|
343
|
+
script = @brpm_rest_client.create_or_update_script(script)
|
344
|
+
|
345
|
+
if script["aasm_state"] == "draft"
|
346
|
+
BrpmAuto.log "Updating the aasm_state of the wrapper script to 'pending'..."
|
347
|
+
script_to_update = {}
|
348
|
+
script_to_update["id"] = script["id"]
|
349
|
+
script_to_update["aasm_state"] = "pending"
|
350
|
+
script = @brpm_rest_client.update_script_from_hash(script_to_update)
|
351
|
+
end
|
352
|
+
|
353
|
+
if script["aasm_state"] == "pending"
|
354
|
+
BrpmAuto.log "Updating the aasm_state of the wrapper script to 'released'..."
|
355
|
+
script_to_update = {}
|
356
|
+
script_to_update["id"] = script["id"]
|
357
|
+
script_to_update["aasm_state"] = "released"
|
358
|
+
script = @brpm_rest_client.update_script_from_hash(script_to_update)
|
359
|
+
end
|
360
|
+
|
361
|
+
if script["aasm_state"] == "retired"
|
362
|
+
BrpmAuto.log "Updating the aasm_state of the wrapper script to 'released'..."
|
363
|
+
script_to_update = {}
|
364
|
+
script_to_update["id"] = script["id"]
|
365
|
+
script_to_update["aasm_state"] = "released"
|
366
|
+
script = @brpm_rest_client.update_script_from_hash(script_to_update)
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
def uninstall_auto_script_wrapper(auto_script_path, automation_type, module_friendly_name)
|
371
|
+
auto_script_config = get_auto_script_config(auto_script_path, module_friendly_name)
|
372
|
+
|
373
|
+
script = @brpm_rest_client.get_script_by_name(auto_script_config["friendly_name"])
|
374
|
+
|
375
|
+
unless script
|
376
|
+
BrpmAuto.log "Script #{auto_script_config["friendly_name"]} was not found, probably already deleted. Continuing."
|
377
|
+
return
|
378
|
+
end
|
379
|
+
|
380
|
+
if script["aasm_state"] == "released"
|
381
|
+
BrpmAuto.log "Updating the aasm_state of the wrapper script to 'retired'..."
|
382
|
+
script_to_update = {}
|
383
|
+
script_to_update["id"] = script["id"]
|
384
|
+
script_to_update["aasm_state"] = "retired"
|
385
|
+
script = @brpm_rest_client.update_script_from_hash(script_to_update)
|
386
|
+
end
|
387
|
+
|
388
|
+
if script["aasm_state"] == "retired"
|
389
|
+
BrpmAuto.log "Updating the aasm_state of the wrapper script to 'archived'..."
|
390
|
+
script_to_update = {}
|
391
|
+
script_to_update["id"] = script["id"]
|
392
|
+
script_to_update["aasm_state"] = "archived"
|
393
|
+
script = @brpm_rest_client.update_script_from_hash(script_to_update)
|
394
|
+
end
|
395
|
+
|
396
|
+
if script["aasm_state"] == "archived_state"
|
397
|
+
BrpmAuto.log "Deleting the wrapper script..."
|
398
|
+
@brpm_rest_client.delete_script(script["id"])
|
399
|
+
else
|
400
|
+
raise "Script #{auto_script_config["friendly_name"]} is not in aasm_state 'archived' so unable to delete it."
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
def get_auto_script_config(auto_script_path, module_friendly_name)
|
405
|
+
auto_script_name = File.basename(auto_script_path, ".rb")
|
406
|
+
auto_script_config_path = "#{File.dirname(auto_script_path)}/#{auto_script_name}.meta"
|
407
|
+
|
408
|
+
auto_script_config_content = File.exists?(auto_script_config_path) ? File.read(auto_script_config_path) : ""
|
409
|
+
auto_script_config = YAML.load(auto_script_config_content) || {}
|
410
|
+
auto_script_config["params"] = auto_script_config["params"] || {}
|
411
|
+
auto_script_config["name"] = File.basename(auto_script_path, ".rb")
|
412
|
+
auto_script_config["friendly_name"] = auto_script_config["friendly_name"] || "#{module_friendly_name} - #{auto_script_config["name"].gsub("_", " ").capitalize}"
|
413
|
+
|
414
|
+
auto_script_config
|
415
|
+
end
|
416
|
+
|
417
|
+
def add_version_params(auto_script_params)
|
418
|
+
include_position_attribute = false
|
419
|
+
if auto_script_params.find { |_, param| param.has_key?("position") }
|
420
|
+
include_position_attribute = true
|
421
|
+
end
|
422
|
+
|
423
|
+
input_params = auto_script_params.select do |_, param|
|
424
|
+
type = param["type"] || "in"
|
425
|
+
! type.start_with?("out")
|
426
|
+
end
|
427
|
+
|
428
|
+
module_version_param = {}
|
429
|
+
module_version_param["name"] = "module_version"
|
430
|
+
module_version_param["required"] = false
|
431
|
+
module_version_param["position"] = "A#{input_params.size + 1}:C#{input_params.size + 1}" if include_position_attribute
|
432
|
+
auto_script_params["module_version"] = module_version_param
|
433
|
+
|
434
|
+
framework_version_param = {}
|
435
|
+
framework_version_param["name"] = "framework_version"
|
436
|
+
framework_version_param["required"] = false
|
437
|
+
framework_version_param["position"] = "A#{input_params.size + 2}:C#{input_params.size + 2}" if include_position_attribute
|
438
|
+
auto_script_params["framework_version"] = framework_version_param
|
439
|
+
end
|
440
|
+
|
441
|
+
def get_integration_server_template(integration_server_id, integration_server_name, integration_server_type)
|
442
|
+
<<EOR
|
443
|
+
#=== #{integration_server_type} Integration Server: #{integration_server_name} ===#
|
444
|
+
# [integration_id=#{integration_server_id}]
|
445
|
+
#=== End ===#
|
446
|
+
|
447
|
+
params["SS_integration_dns"] = SS_integration_dns
|
448
|
+
params["SS_integration_username"] = SS_integration_username
|
449
|
+
params["SS_integration_password_enc"] = SS_integration_password_enc
|
450
|
+
params["SS_integration_details"] = YAML.load(SS_integration_details)
|
451
|
+
EOR
|
452
|
+
end
|
453
|
+
|
454
|
+
def get_script_executor_template(automation_type, module_name, auto_script_name)
|
455
|
+
template = <<EOR
|
456
|
+
params["direct_execute"] = "true"
|
457
|
+
|
458
|
+
params["framework_version"] = nil if params["framework_version"].empty?
|
459
|
+
params["module_version"] = nil if params["module_version"].empty?
|
460
|
+
|
461
|
+
require "\#{ENV["BRPM_CONTENT_HOME"] || "\#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-\#{params["framework_version"] || "latest"}/modules/framework/brpm_script_executor.rb"
|
462
|
+
EOR
|
463
|
+
|
464
|
+
if automation_type == "Automation"
|
465
|
+
|
466
|
+
template += <<EOR
|
467
|
+
|
468
|
+
BrpmScriptExecutor.execute_automation_script("#{module_name}", "#{auto_script_name}", params)
|
469
|
+
EOR
|
470
|
+
|
471
|
+
elsif automation_type == "ResourceAutomation"
|
472
|
+
|
473
|
+
template += <<EOR
|
474
|
+
|
475
|
+
def execute(script_params, parent_id, offset, max_records)
|
476
|
+
BrpmScriptExecutor.execute_resource_automation_script("#{module_name}", "#{auto_script_name}", script_params, parent_id, offset, max_records)
|
477
|
+
end
|
478
|
+
EOR
|
479
|
+
end
|
480
|
+
|
481
|
+
template
|
482
|
+
end
|
483
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class AllParams < ParamsBase
|
2
|
+
def initialize(params, request_params)
|
3
|
+
@params = params
|
4
|
+
@request_params = request_params
|
5
|
+
|
6
|
+
# this class acts as a virtual hash on top of two real hashes for all write-related methods (which need to be overriden)
|
7
|
+
# the values from both hashes are also synchronized in this class to avoid having to override all read-related methods
|
8
|
+
self.merge!(@params)
|
9
|
+
self.merge!(@request_params)
|
10
|
+
end
|
11
|
+
|
12
|
+
alias :super_add :[]=
|
13
|
+
|
14
|
+
def []=(key,val)
|
15
|
+
raise RuntimeError.new("This is a virtual hash based on two physical hashes, use the add method instead.")
|
16
|
+
end
|
17
|
+
|
18
|
+
#TODO: refactor out the where functionality
|
19
|
+
# Test if a param is present
|
20
|
+
#
|
21
|
+
# ==== Attributes
|
22
|
+
#
|
23
|
+
# * +key_name+ - key to look for
|
24
|
+
# * +where+ - if true returns the hash where the key was found
|
25
|
+
#
|
26
|
+
# ==== Returns
|
27
|
+
#
|
28
|
+
# * the param hash name if where=true, otherwise true/false
|
29
|
+
def present?(key_name, where = false)
|
30
|
+
ans = nil
|
31
|
+
ans = "params" if @params.has_key?(key_name)
|
32
|
+
ans = "json" if @request_params.has_key?(key_name)
|
33
|
+
where ? ans : !ans.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def present_json?(key_name)
|
37
|
+
@request_params.has_key?(key_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def present_local?(key_name)
|
41
|
+
@params.has_key?(key_name)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Adds a key/value to the params
|
45
|
+
#
|
46
|
+
# ==== Attributes
|
47
|
+
#
|
48
|
+
# * +key_name+ - key name
|
49
|
+
# * +value+ - value to assign
|
50
|
+
# * +store+ - place to add params or json (default = params)
|
51
|
+
#
|
52
|
+
# ==== Returns
|
53
|
+
#
|
54
|
+
# * value added
|
55
|
+
def add(key, value, store = "params")
|
56
|
+
if store == "params"
|
57
|
+
@params[key] = value
|
58
|
+
elsif store == "json"
|
59
|
+
@request_params[key] = value
|
60
|
+
end
|
61
|
+
super_add(key, value)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Adds a key/value to the params if not found
|
65
|
+
#
|
66
|
+
# ==== Attributes
|
67
|
+
#
|
68
|
+
# * +key_name+ - key name
|
69
|
+
# * +value+ - value to assign
|
70
|
+
# * +store+ - place to add params or json (default = params)
|
71
|
+
#
|
72
|
+
# ==== Returns
|
73
|
+
#
|
74
|
+
# * value of key
|
75
|
+
def find_or_add(key_name, value, store = "params")
|
76
|
+
ans = get(key_name)
|
77
|
+
add(key_name, value, store) if ans == ""
|
78
|
+
ans == "" ? value : ans
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class IntegrationSettings
|
2
|
+
attr_reader :project_server
|
3
|
+
attr_reader :project_server_id
|
4
|
+
attr_reader :dns
|
5
|
+
attr_reader :username
|
6
|
+
attr_reader :password
|
7
|
+
attr_reader :details
|
8
|
+
|
9
|
+
def initialize(dns, username, password, details = nil, project_server = nil, project_server_id = nil)
|
10
|
+
@dns = dns
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
@details = details
|
14
|
+
@project_server = project_server
|
15
|
+
@project_server_id = project_server_id
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_params
|
19
|
+
params = {}
|
20
|
+
params["SS_integration_dns"] = @dns
|
21
|
+
params["SS_integration_username"] = @username
|
22
|
+
params["SS_integration_password"] = @password
|
23
|
+
params["SS_integration_details"] = @details
|
24
|
+
|
25
|
+
params
|
26
|
+
end
|
27
|
+
end
|