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.
Files changed (77) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +38 -0
  3. data/.travis.yml +17 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +21 -0
  6. data/README.md +308 -0
  7. data/Rakefile +23 -0
  8. data/TO_BE_MIGRATED.txt +9 -0
  9. data/architecture.png +0 -0
  10. data/automations/direct_execute.meta +10 -0
  11. data/automations/direct_execute.rb +10 -0
  12. data/automations/install_module.meta +10 -0
  13. data/automations/install_module.rb +13 -0
  14. data/bin/brpm_install +30 -0
  15. data/bin/brpm_uninstall +30 -0
  16. data/bin/event_handler +63 -0
  17. data/bin/webhook_receiver +49 -0
  18. data/brpm_content.gemspec +31 -0
  19. data/config.yml +8 -0
  20. data/infrastructure/.bashrc +6 -0
  21. data/infrastructure/.brpm +2 -0
  22. data/infrastructure/config/customer_include.rb +26 -0
  23. data/infrastructure/config/server.yml +3 -0
  24. data/infrastructure/log.html +39 -0
  25. data/infrastructure/scripts/backup_database.sh +19 -0
  26. data/infrastructure/scripts/ddns.sh +10 -0
  27. data/infrastructure/scripts/install_brpm.sh +63 -0
  28. data/infrastructure/scripts/maintenance.sh +4 -0
  29. data/infrastructure/scripts/patch_brpm.sh +90 -0
  30. data/infrastructure/scripts/restore_database.sh +33 -0
  31. data/infrastructure/scripts/run_event_handler.cmd +19 -0
  32. data/infrastructure/scripts/run_event_handler.sh +20 -0
  33. data/infrastructure/scripts/run_webhook_receiver.cmd +15 -0
  34. data/infrastructure/scripts/run_webhook_receiver.sh +15 -0
  35. data/infrastructure/silent_install_options_4.6.txt +93 -0
  36. data/infrastructure/silent_install_options_upgrade_4.6.txt +92 -0
  37. data/infrastructure/smtp_settings.rb +42 -0
  38. data/lib/brpm_auto.rb +358 -0
  39. data/lib/brpm_script_executor.rb +80 -0
  40. data/lib/logging/brpm_logger.rb +39 -0
  41. data/lib/logging/logger_base.rb +36 -0
  42. data/lib/logging/simple_logger.rb +27 -0
  43. data/lib/module_installer.rb +483 -0
  44. data/lib/params/all_params.rb +80 -0
  45. data/lib/params/integration_settings.rb +27 -0
  46. data/lib/params/params.rb +174 -0
  47. data/lib/params/params_base.rb +81 -0
  48. data/lib/params/request_params.rb +38 -0
  49. data/lib/rest_api.rb +155 -0
  50. data/lib/semaphore.rb +79 -0
  51. data/lib/utilities.rb +317 -0
  52. data/lib/version_control/git.rb +192 -0
  53. data/lib/version_control/svn.rb +221 -0
  54. data/lib/write_to.rb +1 -0
  55. data/tests/all_params_spec.rb +116 -0
  56. data/tests/brpm_auto_spec.rb +84 -0
  57. data/tests/customer_include/config/customer_include.rb +10 -0
  58. data/tests/customer_include/config/server.yml +3 -0
  59. data/tests/customer_include_spec.rb +29 -0
  60. data/tests/gemspec_spec.rb +11 -0
  61. data/tests/module_installer_spec.rb +46 -0
  62. data/tests/params_spec.rb +172 -0
  63. data/tests/request_params_spec.rb +86 -0
  64. data/tests/server_yaml_spec.rb +19 -0
  65. data/tests/spec_helper.rb +64 -0
  66. data/to_be_migrated/brpm_framework.rb +88 -0
  67. data/to_be_migrated/customer_include_default.rb +25 -0
  68. data/to_be_migrated/local_jirb.rb +15 -0
  69. data/to_be_migrated/resource_framework.rb +211 -0
  70. data/transport/dispatch_baa.rb +355 -0
  71. data/transport/dispatch_base.rb +345 -0
  72. data/transport/dispatch_nsh.rb +248 -0
  73. data/transport/dispatch_ssh.rb +154 -0
  74. data/transport/transport_baa.rb +1095 -0
  75. data/transport/transport_nsh.rb +359 -0
  76. data/transport/transport_ssh.rb +220 -0
  77. metadata +204 -0
@@ -0,0 +1,355 @@
1
+ # dispatch_srun.rb
2
+ # Module for action dispatch with nsh protocol
3
+ libDir = File.expand_path(File.dirname(__FILE__))
4
+ require "#{libDir}/dispatch_base"
5
+
6
+
7
+ class DispatchBAA < DispatchBase
8
+ # Initialize the class
9
+ #
10
+ # ==== Attributes
11
+ #
12
+ # * +baa_object+ - handle to an BAA object
13
+ # * +options+ - hash of options to use, send "output_file" to point to the logging file
14
+ # * +test_mode+ - true/false to simulate commands instead of running them
15
+ #
16
+ def initialize(baa_object, options = {}, compat_options = {})
17
+ self.extend Utilities
18
+ if options.has_key?("SS_output_dir")
19
+ BrpmAuto.log "Load for this class has changed, no longer necessary to send params as 2nd argument"
20
+ options = compat_options
21
+ end
22
+ @baa = baa_object
23
+ @verbose = get_option(options, "verbose", false)
24
+ @output_dir = get_param("SS_output_dir")
25
+ end
26
+
27
+ # Packages passed references in BAA using a component template
28
+ # --- note: artifacts all need to reside on the same server
29
+ # --- note: end a directory path with a / or it will be treated as a file
30
+
31
+ # ==== Attributes
32
+ #
33
+ # * +artifact_list+ - array of file/nsh paths
34
+ # * +group_path+ - path in Blade to store package
35
+ # * +artifacts+ - array of file/nsh paths
36
+ # * +options+ - hash of options, includes:
37
+ # package_name - to override default package name (component_request_id_version),
38
+ # group_path - to override default group_path (app/version/component),
39
+ # transfer_properties - hash of properties to transfer
40
+ # version - to override use of component version
41
+ #
42
+ # ==== Returns
43
+ #
44
+ # * hash - {package_id, status, template_db_key, stagin_server}
45
+ def package_artifacts(artifact_list, options = {})
46
+ version = get_option(options,"version", get_param("step_version"))
47
+ package_name = get_option(options, "package_name", default_item_name(version))
48
+ group_path = get_option(options, "group_path", default_group_path(version))
49
+ transfer_properties = get_option(options, "transfer_properties", {})
50
+ path_property_name = get_option(options, "BAA_PATH_PROPERTY", "BAA_BASE_PATH")
51
+ path_property_value = get_option(transfer_properties, path_property_name, nil)
52
+ path_property = "#{path_property_name}=#{path_property_value}"
53
+ message_box "Packaging Files via BAA"
54
+ log "\t StagingPath: #{group_path}"
55
+ result = {"status" => "ERROR", "group_path" => group_path, "package_name" => package_name}
56
+ artifact_hash = {}
57
+ artifact_list.each{|l| artifact_hash[l] = l.end_with?("/") ? "directory" : "file" }
58
+ pair = split_nsh_path(artifact_hash.keys.first)
59
+ raise "Command_Failed: no staging server in artifacts" if pair[0].length < 2
60
+ staging_server = pair[0]
61
+ result["staging_server"] = staging_server
62
+ group_id = @baa.ensure_group_path(group_path, "Template")
63
+ templates_in_path = @baa.get_group_items(group_path, "Template", true, options)
64
+ cur_templates = templates_in_path.map{|l| l["name"] }
65
+ if cur_templates.include?(package_name)
66
+ log "#=> Component Template exists: #{package_name}"
67
+ template_id = templates_in_path[cur_templates.index(package_name)]["dbKey"]
68
+ else # Create a new one
69
+ log "#=> Create Component Template: #{package_name}"
70
+ template_id = @baa.create_empty_template(package_name, group_id)
71
+ log "\tApplying properties...to template with id #{template_id}" if transfer_properties.size > 0
72
+ template_id = @baa.set_template_properties(package_name, group_path, transfer_properties) if transfer_properties.size > 0
73
+ end
74
+ log "\tAdd content to template #{template_id}\nPath property: #{path_property}"
75
+ template_options = {}
76
+ template_options["path_property"] = path_property unless path_property_value.nil?
77
+ template_id = @baa.add_template_content(template_id, artifact_hash, template_options)
78
+ result["template_db_key"] = template_id
79
+ raise "Command_Failed: #{template_id}" if template_id.start_with?("ERROR")
80
+ log "#=> Create component package: #{staging_server}\n"
81
+ depot_group_id = @baa.ensure_group_path(group_path, "BlPackage")
82
+ package_id = @baa.create_component_package(package_name, depot_group_id, template_id, staging_server)
83
+ raise "Command_Failed: #{package_id}" if package_id.start_with?("ERROR")
84
+ result["status"] = "SUCCESS"
85
+ result["path_property"] = path_property unless path_property_value.nil?
86
+ result["package_id"] = package_id
87
+ result["instance_path"] = "#{group_path}/#{package_name}"
88
+ result["md5"] = "000"
89
+ result
90
+ end
91
+
92
+ # Deploys an existing Package in BAA to target servers
93
+ #
94
+ # ==== Attributes
95
+ #
96
+ # * +package_id+ - id of existing package
97
+ # * +options+ - hash of options, includes:
98
+ # job_name - to override the default job name,
99
+ # group_path - to override the default group path,
100
+ # execute_now - (true/false to execute the job immediately default - true),
101
+ # transfer_properties (hash of name/values to set),
102
+ # version - to override use of component version
103
+ #
104
+ # ==== Returns
105
+ #
106
+ # * hash of job results, includes - job_run_id, job_status
107
+ def deploy_package_instance(package_info, options = {})
108
+ package_id = package_info["package_id"]
109
+ path_property = get_option(package_info,"path_property", nil)
110
+ version = get_option(options,"version", get_param("SS_component_version"))
111
+ execute_now = get_option(options,"execute_now", true)
112
+ job_base_name = get_option(options, "job_name", default_item_name(version))
113
+ group_path = get_option(options, "group_path", default_group_path(version, true))
114
+ transfer_properties = get_option(options, "transfer_properties", {})
115
+ unless path_property.nil?
116
+ package_property = path_property.split("=")[0]
117
+ deploy_property = "#{package_property}_DEPLOY"
118
+ log "\t No corresponding deploy property for #{package_property} (should be #{deploy_property})", "WARN" if !transfer_properties.has_key?(deploy_property)
119
+ transfer_properties[package_property] = transfer_properties[deploy_property] if transfer_properties.has_key?(deploy_property)
120
+ end
121
+ message_box "Packaging Files via BAA"
122
+ log "\t StagingPath: #{group_path}"
123
+ result = {"status" => "ERROR", "results" => "", "group_path" => group_path, "job_names" => []}
124
+ raise "ERROR: No servers found" if get_server_list.empty?
125
+ log "\tBuilding group path..."
126
+ job_group_id = @baa.ensure_group_path(group_path, "Jobs")
127
+ # Loop through the platforms
128
+ OS_PLATFORMS.each do |os, os_details|
129
+ servers = BrpmAuto.params.get_servers_by_os_platform(os)
130
+ message_box "OS Platform: #{os_details["name"]}"
131
+ log "No servers selected for: #{os_details["name"]}" if servers.size == 0
132
+ next if servers.size == 0
133
+ job_name = "#{job_base_name}_#{os}"
134
+ result["job_names"] << job_name
135
+ log "#=> Building Job from Package:\n\tGroup: #{group_path}\n\tPackage: #{package_id}"
136
+ log "# #{os_details["name"]} - Targets: #{servers.inspect}"
137
+ targets = @baa.baa_soap_map_server_names_to_rest_uri(server_dns_names(servers))
138
+ log "\tCreating package job..."
139
+ cur_jobs = @baa.execute_cli_command("Job","listAllByGroup",[group_path])
140
+ if cur_jobs.split("\n").include?(job_name)
141
+ log "\tJob Exists: deleting..."
142
+ ans = @baa.execute_cli_command("DeployJob","deleteJobByGroupAndName",[group_path, job_name])
143
+ end
144
+ job_db_key = @baa.create_package_job(job_name, job_group_id, package_id, server_dns_names(servers))
145
+ if job_db_key.start_with?("ERROR")
146
+ log job_db_key
147
+ raise "Command_Failed: job creation failed"
148
+ end
149
+ result["job_db_key"] = job_db_key
150
+ result["status"] = "JOB_CREATED_SUCCESSFULLY"
151
+ log "\tApplying properties..."
152
+ prop_results = @baa.set_job_properties(job_name, group_path, transfer_properties)
153
+ result["property_results"] = prop_results
154
+ if execute_now
155
+ log "#=> Executing Job"
156
+ execute_results = @baa.execute_job_with_results(job_db_key, result)
157
+ result["results"] += "#{os} - #{execute_results}"
158
+ execute_results.each{|k,v| log("#{k}: #{v}")}
159
+ end
160
+ end
161
+ result
162
+ end
163
+
164
+ # Creates an NSH Script Job in BAA to target servers
165
+ #
166
+ # ==== Attributes
167
+ #
168
+ # * +script_name+ - name of nsh script
169
+ # * +script_group+ - path in depot to script
170
+ # * +job_params+ - array of params (in order) for script job
171
+ # * +options+ - hash of options, includes: execute_now,
172
+ # num_par_proces (max parallel processes),
173
+ # target_type (servers/groups),
174
+ # job_name - to override the default job name,
175
+ # group_path - to override the default group path,
176
+ # version - to override use of component version
177
+ #
178
+ # ==== Returns
179
+ #
180
+ # * hash of job results, includes - job_run_id, job_status
181
+ def create_nsh_script_job(script_name, script_group, job_params, options = {})
182
+ result = {"status" => "ERROR"}
183
+ job_type = "NSHScriptJob"
184
+ version = get_option(options,"version", get_param("SS_component_version"))
185
+ targets = get_option(options, "servers")
186
+ if targets == ""
187
+ servers = get_server_list
188
+ targets = server_dns_names(servers)
189
+ end
190
+ script_group = "/#{script_group}" unless script_group.start_with?("/")
191
+ num_par_procs = get_option(options,"num_par_procs", 50)
192
+ execute_now = get_option(options,"execute_now", false)
193
+ target_type = get_option(options,"target_type", "servers")
194
+ job_name = get_option(options, "job_name", default_item_name)
195
+ group_path = get_option(options, "group_path", default_group_path(version, true))
196
+ log "\tBuilding group path..."
197
+ job_group_id = @baa.ensure_group_path(group_path, "Jobs")
198
+ args = [
199
+ group_path, #jobGroup
200
+ job_name, #jobName
201
+ "Script job from automation", #description
202
+ script_group,
203
+ script_name,
204
+ num_par_procs # number of parallel processes
205
+ ]
206
+ ss_job_key = @baa.execute_cli_command(job_type,"createNSHScriptJob",args)
207
+ raise "Command_Failed: cannot create job: #{ss_job_key}" if ss_job_key.include?("ERROR")
208
+ log "Created: #{job_name} in group: #{group_path}"
209
+ #targets.collect!{|k| k.gsub(/^\//,"/Servers/") unless k.start_with?("/Servers") }
210
+ #c. Make the call to addTargetGroup (should be a new method)
211
+ if targets.is_a?(String) || targets.size < 2
212
+ method_call = target_type == "servers" ? "addTargetServer" : "addTargetGroup"
213
+ servers = targets.first if targets.is_a?(Array)
214
+ else
215
+ method_call = target_type == "servers" ? "addTargetServers" : "addTargetGroups"
216
+ servers = targets.join(",")
217
+ end
218
+ ss_job_key = @baa.execute_cli_command("Job", method_call,
219
+ [
220
+ ss_job_key, #jobName
221
+ servers #comma separated list of groups
222
+ ])
223
+ raise "Command_Failed: cannot add targets: #{ss_job_key}" if ss_job_key.include?("ERROR")
224
+ if execute_now
225
+ param_result = @baa.set_nsh_script_params(job_name, group_path, job_params, false)
226
+ raise "Command_Failed: cannot set job parameters: #{param_result}" if param_result.include?("ERROR")
227
+ execute_result = @baa.execute_job_with_results(param_result["job_db_key"], result)
228
+ raise "Command_Failed: cannot execute job: #{execute_result.inspect}" if execute_result["status"].include?("ERROR")
229
+ end
230
+ result["job_db_key"] = ss_job_key
231
+ result["status"] = "SUCCESS"
232
+ result
233
+ end
234
+
235
+ # Wrapper to run a shell action
236
+ # opens passed script path, or executes passed text
237
+ # processes the script in erb first to allow param substitution
238
+ # note script may have keyword directives (see additional docs)
239
+ # uses BAA_FRAMEWORK_NSH_SCRIPT to locate the nsh_script
240
+ # ==== Attributes
241
+ #
242
+ # * +script_file+ - the path to the script or the text of the script
243
+ # * +options+ - hash of options, includes:
244
+ # servers - to override step servers
245
+ # version - to override use of component version
246
+ # nsh_script_name - name of nsh_script to call
247
+ # nsh_script_group - group path of nsh script
248
+ # ==== Returns
249
+ #
250
+ # action output
251
+ #
252
+ def execute_script(script_file, options = {})
253
+ # get the body of the action
254
+ content = File.open(script_file).read
255
+ seed_servers = get_option(options, "servers")
256
+ transfer_properties = get_option(options, "transfer_properties",{})
257
+ nsh_script_group = get_option(options, "nsh_script_group")
258
+ nsh_script_name = get_option(options, "nsh_script_name")
259
+ version = get_option(options,"version", get_param("SS_component_version"))
260
+ group_path = get_option(options, "group_path", default_group_path(version, true))
261
+ job_name = get_option(options, "job_name", default_item_name)
262
+ if nsh_script_name == "" && defined?(BAA_FRAMEWORK_NSH_SCRIPT)
263
+ log "Using BAA_FRAMEWORK_NSH_SCRIPT defined in customer_include"
264
+ nsh_script_group = File.dirname(BAA_FRAMEWORK_NSH_SCRIPT)
265
+ nsh_script_name = File.basename(BAA_FRAMEWORK_NSH_SCRIPT)
266
+ else
267
+ raise "Command_Failed: BAA_FRAMEWORK_NSH_SCRIPT must be defined in customer_include.rb"
268
+ end
269
+ keyword_items = get_keyword_items(content)
270
+ log "\tBuilding group path..."
271
+ job_group_id = @baa.ensure_group_path(group_path, "Jobs")
272
+ params_filter = keyword_items.has_key?("RPM_PARAMS_FILTER") ? keyword_items["RPM_PARAMS_FILTER"] : DEFAULT_PARAMS_FILTER
273
+ transfer_properties.merge!(get_transfer_properties(params_filter, strip_prefix = true))
274
+ log "#----------- Executing Script on Remote Hosts -----------------#"
275
+ log "# Script: #{script_file}"
276
+ result = "No servers to execute on"
277
+ # Loop through the platforms
278
+ OS_PLATFORMS.each do |os, os_details|
279
+ servers = BrpmAuto.params.get_servers_by_os_platform(os) if seed_servers == ""
280
+ servers = BrpmAuto.params.get_servers_by_os_platform(os, seed_servers) if seed_servers != ""
281
+ message_box "OS Platform: #{os_details["name"]}"
282
+ log "No servers selected for: #{os_details["name"]}" if servers.size == 0
283
+ next if servers.size == 0
284
+ log "# #{os_details["name"]} - Targets: #{servers.inspect}"
285
+ log "# Setting Properties:"
286
+ add_channel_properties(transfer_properties, servers, os)
287
+ brpd_compatibility(transfer_properties)
288
+ transfer_properties.each{|k,v| log "\t#{k} => #{v}" }
289
+ shebang = read_shebang(os, content)
290
+ log "Shebang: #{shebang.inspect}"
291
+ wrapper_path = build_wrapper_script(os, shebang, transfer_properties, {"script_target" => File.basename(script_file)})
292
+ log "# Wrapper: #{wrapper_path}"
293
+ target_path = @baa.nsh_path(transfer_properties["RPM_CHANNEL_ROOT"])
294
+ log "# Copying script to target: "
295
+ clean_line_breaks(os, script_file, content)
296
+ files_to_deploy = ["//#{BAA_RPM_HOSTNAME}#{script_file}", "//#{BAA_RPM_HOSTNAME}#{wrapper_path}"]
297
+ result = @baa.create_file_deploy_job(job_name, group_path, files_to_deploy, target_path, server_dns_names(servers), {"execute_now" => true})
298
+ result.each{|k,v| log("#{k}: #{v}") }
299
+ log "# Executing script on target via wrapper:"
300
+ job_params = [@params["SS_application"],
301
+ @params["SS_component"],
302
+ @params["SS_environment"],
303
+ @params["SS_component_version"],
304
+ @params["request_id"],
305
+ target_path,
306
+ File.basename(wrapper_path)
307
+ ]
308
+ result = create_nsh_script_job(nsh_script_name, nsh_script_group, job_params, {"servers" => server_dns_names(servers), "execute_now" => true})
309
+ result.each{|k,v| log("#{k}: #{v}") }
310
+ end
311
+ result
312
+ end
313
+
314
+ # Creates a group path for BAA storage
315
+ # optionally uses BAA_BASE_GROUP from customer_include, otherwise "BRPM"
316
+ #
317
+ # ==== Attributes
318
+ #
319
+ # * +version+ - version name
320
+ # * +deploy+ - true if path is for deploy and hence needs environment tag
321
+ #
322
+ # ==== Returns
323
+ #
324
+ # * group_path string
325
+ def default_group_path(version = nil, deploy = false)
326
+ base_grp = defined?(BAA_BASE_GROUP) ? BAA_BASE_GROUP : "BRPM"
327
+ version = precision_timestamp if version.nil? || version == ""
328
+ result = "/#{base_grp}/#{get_param("SS_application")}/#{version}/#{get_param("SS_component")}"
329
+ result.gsub!(version,"#{version}/#{get_param("SS_environment")}") if deploy
330
+ result
331
+ end
332
+
333
+ # Creates a unique item name for BAA storage
334
+ #
335
+ # ==== Attributes
336
+ #
337
+ # * +version+ - version name
338
+ #
339
+ # ==== Returns
340
+ #
341
+ # * item name string
342
+ def default_item_name(version = nil)
343
+ version = precision_timestamp if version.nil? || version == ""
344
+ "#{get_param("SS_component")}_nsh_#{get_param("request_id")}_#{version}"
345
+ end
346
+
347
+ end
348
+
349
+ require "#{@params["SS_script_support_path"]}/baa_utilities"
350
+ @rpm.log "Initializing BAA transport"
351
+ baa_path = defined?(BAA_BASE_PATH) ? BAA_BASE_PATH : "/opt/bmc/bladelogic"
352
+ baa_url = defined?(SS_integration_dns) ? SS_integration_dns : "http://unknownBladelogicServerSetIntegration"
353
+ @baa = TransportBAA.new(baa_url)
354
+ @rpm.log "Path to BAA: #{BAA_BASE_PATH}"
355
+ @transport = DispatchBAA.new(@baa)