brpm_content 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +38 -0
  3. data/.travis.yml +14 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +21 -0
  6. data/README.md +308 -0
  7. data/Rakefile +24 -0
  8. data/TO_BE_MIGRATED.txt +8 -0
  9. data/architecture.png +0 -0
  10. data/brpm_content.gemspec +31 -0
  11. data/customers/demo/integrations/brpm/process_event_handler_event.rb +183 -0
  12. data/customers/demo/integrations/jenkins/spec/api/applications_spec.rb +89 -0
  13. data/customers/demo/integrations/jenkins/spec/api/plans_spec.rb +69 -0
  14. data/customers/demo/integrations/jenkins/spec/api/requests_spec.rb +57 -0
  15. data/customers/demo/integrations/jenkins/spec/spec_helper.rb +33 -0
  16. data/customers/demo/integrations/jira/process_webhook_event.rb +33 -0
  17. data/customers/demo/jira_mappings.rb +29 -0
  18. data/infrastructure/integrations/event_handler.rb +62 -0
  19. data/infrastructure/integrations/webhook_receiver.rb +49 -0
  20. data/infrastructure/shell_scripts/backup_database.sh +19 -0
  21. data/infrastructure/shell_scripts/create_bl_package.sh +34 -0
  22. data/infrastructure/shell_scripts/create_release_request.sh +34 -0
  23. data/infrastructure/shell_scripts/ddns.sh +10 -0
  24. data/infrastructure/shell_scripts/install_brpm.sh +63 -0
  25. data/infrastructure/shell_scripts/install_content_module.sh +66 -0
  26. data/infrastructure/shell_scripts/install_content_repo.sh +60 -0
  27. data/infrastructure/shell_scripts/install_module_from_gem.sh +80 -0
  28. data/infrastructure/shell_scripts/maintenance.sh +4 -0
  29. data/infrastructure/shell_scripts/patch_brpm.sh +90 -0
  30. data/infrastructure/shell_scripts/restore_database.sh +33 -0
  31. data/infrastructure/shell_scripts/run_event_handler.cmd +16 -0
  32. data/infrastructure/shell_scripts/run_event_handler.sh +20 -0
  33. data/infrastructure/shell_scripts/run_webhook_receiver.cmd +14 -0
  34. data/infrastructure/shell_scripts/run_webhook_receiver.sh +15 -0
  35. data/infrastructure/shell_scripts/update_content_repo.sh +21 -0
  36. data/infrastructure/silent_install_options_4.6.txt +93 -0
  37. data/infrastructure/silent_install_options_upgrade_4.6.txt +92 -0
  38. data/infrastructure/smtp_settings.rb +42 -0
  39. data/infrastructure/ssh_script_header_additions.rb +21 -0
  40. data/modules/ansible/automations/execute_role.rb +3 -0
  41. data/modules/ansible/automations/execute_role.txt +12 -0
  42. data/modules/ansible/config.yml +5 -0
  43. data/modules/ansible/lib/ansible.rb +41 -0
  44. data/modules/atrium_orchestrator/automations/execute_workflow.rb +12 -0
  45. data/modules/atrium_orchestrator/automations/execute_workflow.txt +25 -0
  46. data/modules/atrium_orchestrator/automations/reserve_ip_address.rb +22 -0
  47. data/modules/atrium_orchestrator/automations/reserve_ip_address.txt +21 -0
  48. data/modules/atrium_orchestrator/config.yml +7 -0
  49. data/modules/atrium_orchestrator/lib/ao_soap_client.rb +94 -0
  50. data/modules/bladelogic/automations/create_package.rb +29 -0
  51. data/modules/bladelogic/automations/create_package.txt +26 -0
  52. data/modules/bladelogic/automations/deploy_package.rb +137 -0
  53. data/modules/bladelogic/automations/deploy_package.txt +53 -0
  54. data/modules/bladelogic/config.yml +7 -0
  55. data/modules/bladelogic/lib/bl_rest/bsa_rest_client.rb +65 -0
  56. data/modules/bladelogic/lib/bl_soap/blpackage.rb +43 -0
  57. data/modules/bladelogic/lib/bl_soap/bsa_soap_base.rb +118 -0
  58. data/modules/bladelogic/lib/bl_soap/bsa_soap_client.rb +34 -0
  59. data/modules/bladelogic/lib/bl_soap/compliance_job.rb +155 -0
  60. data/modules/bladelogic/lib/bl_soap/deploy_job.rb +48 -0
  61. data/modules/bladelogic/lib/bl_soap/depot_group.rb +47 -0
  62. data/modules/bladelogic/lib/bl_soap/job.rb +376 -0
  63. data/modules/bladelogic/lib/bl_soap/job_group.rb +72 -0
  64. data/modules/bladelogic/lib/bl_soap/job_management.rb +22 -0
  65. data/modules/bladelogic/lib/bl_soap/job_result.rb +12 -0
  66. data/modules/bladelogic/lib/bl_soap/job_run.rb +271 -0
  67. data/modules/bladelogic/lib/bl_soap/login.rb +47 -0
  68. data/modules/bladelogic/lib/bl_soap/nsh_script_job.rb +14 -0
  69. data/modules/bladelogic/lib/bl_soap/patch_catalog.rb +178 -0
  70. data/modules/bladelogic/lib/bl_soap/patch_remediation_job.rb +137 -0
  71. data/modules/bladelogic/lib/bl_soap/patching_job.rb +250 -0
  72. data/modules/bladelogic/lib/bl_soap/server.rb +12 -0
  73. data/modules/bladelogic/lib/bl_soap/template.rb +13 -0
  74. data/modules/bladelogic/lib/bl_soap/utility.rb +99 -0
  75. data/modules/bladelogic/resource_automations/select_job.rb +33 -0
  76. data/modules/bladelogic/resource_automations/select_job.txt +15 -0
  77. data/modules/bladelogic/tests/create_package_spec.rb +28 -0
  78. data/modules/bladelogic/tests/deploy_package_spec.rb +23 -0
  79. data/modules/bladelogic/tests/spec_helper.rb +82 -0
  80. data/modules/brpm/automations/create_release_from_excel.rb +34 -0
  81. data/modules/brpm/automations/create_release_from_excel.txt +5 -0
  82. data/modules/brpm/automations/create_release_request.rb +100 -0
  83. data/modules/brpm/automations/create_release_request.txt +5 -0
  84. data/modules/brpm/automations/create_request.rb +73 -0
  85. data/modules/brpm/automations/create_request.txt +23 -0
  86. data/modules/brpm/automations/promote_request.rb +197 -0
  87. data/modules/brpm/automations/promote_request.txt +24 -0
  88. data/modules/brpm/automations/select_application_version.rb +22 -0
  89. data/modules/brpm/automations/select_application_version.txt +17 -0
  90. data/modules/brpm/automations/select_component_version.rb +12 -0
  91. data/modules/brpm/automations/select_component_version.txt +5 -0
  92. data/modules/brpm/automations/select_request_template.rb +6 -0
  93. data/modules/brpm/automations/select_request_template.txt +13 -0
  94. data/modules/brpm/automations/wait_for_step_in_other_request.rb +11 -0
  95. data/modules/brpm/automations/wait_for_step_in_other_request.txt +13 -0
  96. data/modules/brpm/automations/wait_till_promoted_request_is_completed.rb +9 -0
  97. data/modules/brpm/automations/wait_till_promoted_request_is_completed.txt +5 -0
  98. data/modules/brpm/config.yml +6 -0
  99. data/modules/brpm/lib/brpm_request.rb +207 -0
  100. data/modules/brpm/lib/brpm_rest.rb +312 -0
  101. data/modules/brpm/lib/brpm_rest_client.rb +1501 -0
  102. data/modules/brpm/resource_automations/select_application.rb +16 -0
  103. data/modules/brpm/resource_automations/select_application.txt +5 -0
  104. data/modules/brpm/resource_automations/select_environment.rb +14 -0
  105. data/modules/brpm/resource_automations/select_environment.txt +5 -0
  106. data/modules/brpm/resource_automations/select_request_template.rb +16 -0
  107. data/modules/brpm/resource_automations/select_request_template.txt +5 -0
  108. data/modules/brpm/resource_automations/select_step_in_request.rb +33 -0
  109. data/modules/brpm/resource_automations/select_step_in_request.txt +5 -0
  110. data/modules/brpm/sample_applications/e-finance.json +0 -0
  111. data/modules/brpm/tests/create_release_request_spec.rb +66 -0
  112. data/modules/brpm/tests/create_request_spec.rb +84 -0
  113. data/modules/brpm/tests/select_application_version_spec.rb +47 -0
  114. data/modules/brpm/tests/spec_helper.rb +63 -0
  115. data/modules/docker_brpm/automations/create_brpm_instance_input_params.rb +10 -0
  116. data/modules/docker_brpm/automations/create_brpm_instance_input_params.txt +17 -0
  117. data/modules/docker_brpm/automations/create_brpm_instance_one_shot.rb +60 -0
  118. data/modules/docker_brpm/automations/create_brpm_instance_one_shot.txt +14 -0
  119. data/modules/docker_brpm/automations/create_brpm_instance_show_results.rb +23 -0
  120. data/modules/docker_brpm/automations/create_brpm_instance_show_results.txt +13 -0
  121. data/modules/docker_brpm/automations/create_database.rb +24 -0
  122. data/modules/docker_brpm/automations/create_database.txt +3 -0
  123. data/modules/docker_brpm/automations/create_environment.rb +14 -0
  124. data/modules/docker_brpm/automations/create_environment.txt +3 -0
  125. data/modules/docker_brpm/automations/create_image_for_application.rb +23 -0
  126. data/modules/docker_brpm/automations/create_image_for_application.txt +6 -0
  127. data/modules/docker_brpm/automations/create_image_for_brpm_application_input_params.rb +7 -0
  128. data/modules/docker_brpm/automations/create_image_for_brpm_application_input_params.txt +8 -0
  129. data/modules/docker_brpm/automations/create_image_for_brpm_database_creator_input_params.rb +7 -0
  130. data/modules/docker_brpm/automations/create_image_for_brpm_database_creator_input_params.txt +8 -0
  131. data/modules/docker_brpm/automations/create_image_for_database_creator.rb +21 -0
  132. data/modules/docker_brpm/automations/create_image_for_database_creator.txt +6 -0
  133. data/modules/docker_brpm/automations/create_installed_component_for_application.rb +11 -0
  134. data/modules/docker_brpm/automations/create_installed_component_for_application.txt +3 -0
  135. data/modules/docker_brpm/automations/create_installed_component_for_database.rb +7 -0
  136. data/modules/docker_brpm/automations/create_installed_component_for_database.txt +3 -0
  137. data/modules/docker_brpm/automations/create_installed_component_for_database_creator.rb +8 -0
  138. data/modules/docker_brpm/automations/create_installed_component_for_database_creator.txt +3 -0
  139. data/modules/docker_brpm/automations/create_installed_component_for_utilities.rb +7 -0
  140. data/modules/docker_brpm/automations/create_installed_component_for_utilities.txt +3 -0
  141. data/modules/docker_brpm/automations/create_version_tags_for_component_in_all_envs.rb +13 -0
  142. data/modules/docker_brpm/automations/create_version_tags_for_component_in_all_envs.txt +6 -0
  143. data/modules/docker_brpm/automations/delete_brpm_instance.rb +38 -0
  144. data/modules/docker_brpm/automations/delete_brpm_instance.txt +8 -0
  145. data/modules/docker_brpm/automations/execute_test_run_in_jenkins.rb +43 -0
  146. data/modules/docker_brpm/automations/execute_test_run_in_jenkins.txt +13 -0
  147. data/modules/docker_brpm/automations/execute_test_run_in_jenkins_show_results.rb +5 -0
  148. data/modules/docker_brpm/automations/execute_test_run_in_jenkins_show_results.txt +9 -0
  149. data/modules/docker_brpm/automations/launch_create_image_for_brpm_application_request.rb +27 -0
  150. data/modules/docker_brpm/automations/launch_create_image_for_brpm_application_request.txt +3 -0
  151. data/modules/docker_brpm/automations/launch_test_run_request.rb +30 -0
  152. data/modules/docker_brpm/automations/launch_test_run_request.txt +14 -0
  153. data/modules/docker_brpm/automations/release_brpm_input_params.rb +7 -0
  154. data/modules/docker_brpm/automations/release_brpm_input_params.txt +8 -0
  155. data/modules/docker_brpm/automations/run_application_container.rb +27 -0
  156. data/modules/docker_brpm/automations/run_application_container.txt +3 -0
  157. data/modules/docker_brpm/automations/run_database_container.rb +14 -0
  158. data/modules/docker_brpm/automations/run_database_container.txt +3 -0
  159. data/modules/docker_brpm/automations/stop_application_container.rb +11 -0
  160. data/modules/docker_brpm/automations/stop_application_container.txt +3 -0
  161. data/modules/docker_brpm/automations/stop_database_container.rb +11 -0
  162. data/modules/docker_brpm/automations/stop_database_container.txt +3 -0
  163. data/modules/docker_brpm/automations/test_rest_api.rb +18 -0
  164. data/modules/docker_brpm/automations/test_rest_api.txt +3 -0
  165. data/modules/docker_brpm/automations/upgrade_database.rb +19 -0
  166. data/modules/docker_brpm/automations/upgrade_database.txt +8 -0
  167. data/modules/docker_brpm/config.yml +8 -0
  168. data/modules/docker_brpm/lib/docker.rb +39 -0
  169. data/modules/docker_brpm/lib/git.rb +16 -0
  170. data/modules/docker_brpm/sample_applications/dockerizedbrpm.json +0 -0
  171. data/modules/email/automations/send_notification.rb +48 -0
  172. data/modules/email/automations/send_notification.txt +27 -0
  173. data/modules/email/config.yml +6 -0
  174. data/modules/framework/automations/direct_execute.rb +10 -0
  175. data/modules/framework/automations/direct_execute.txt +16 -0
  176. data/modules/framework/automations/install_module.rb +13 -0
  177. data/modules/framework/automations/install_module.txt +16 -0
  178. data/modules/framework/bin/brpm_install +106 -0
  179. data/modules/framework/bin/event_handler +63 -0
  180. data/modules/framework/bin/webhook_receiver +49 -0
  181. data/modules/framework/brpm_auto.rb +307 -0
  182. data/modules/framework/brpm_framework.rb +88 -0
  183. data/modules/framework/brpm_script_executor.rb +146 -0
  184. data/modules/framework/config.yml +7 -0
  185. data/modules/framework/config/customer_include.rb +26 -0
  186. data/modules/framework/config/server.yml +3 -0
  187. data/modules/framework/customer_include_default.rb +25 -0
  188. data/modules/framework/lib/logging/brpm_logger.rb +39 -0
  189. data/modules/framework/lib/logging/logger_base.rb +36 -0
  190. data/modules/framework/lib/logging/simple_logger.rb +27 -0
  191. data/modules/framework/lib/params/all_params.rb +80 -0
  192. data/modules/framework/lib/params/integration_settings.rb +27 -0
  193. data/modules/framework/lib/params/params.rb +172 -0
  194. data/modules/framework/lib/params/params_base.rb +81 -0
  195. data/modules/framework/lib/params/request_params.rb +38 -0
  196. data/modules/framework/lib/resource_framework.rb +211 -0
  197. data/modules/framework/lib/rest_api.rb +155 -0
  198. data/modules/framework/lib/semaphore.rb +79 -0
  199. data/modules/framework/lib/utilities.rb +317 -0
  200. data/modules/framework/lib/version_control/git.rb +192 -0
  201. data/modules/framework/lib/version_control/svn.rb +221 -0
  202. data/modules/framework/log.html +39 -0
  203. data/modules/framework/tests/all_params_spec.rb +116 -0
  204. data/modules/framework/tests/brpm_auto_spec.rb +84 -0
  205. data/modules/framework/tests/customer_include/config/customer_include.rb +10 -0
  206. data/modules/framework/tests/customer_include/config/server.yml +3 -0
  207. data/modules/framework/tests/customer_include_spec.rb +29 -0
  208. data/modules/framework/tests/local_jirb.rb +15 -0
  209. data/modules/framework/tests/params_spec.rb +172 -0
  210. data/modules/framework/tests/request_params_spec.rb +86 -0
  211. data/modules/framework/tests/server_yaml_spec.rb +19 -0
  212. data/modules/framework/tests/spec_helper.rb +42 -0
  213. data/modules/framework/transport/dispatch_baa.rb +355 -0
  214. data/modules/framework/transport/dispatch_base.rb +345 -0
  215. data/modules/framework/transport/dispatch_nsh.rb +248 -0
  216. data/modules/framework/transport/dispatch_ssh.rb +154 -0
  217. data/modules/framework/transport/transport_baa.rb +1095 -0
  218. data/modules/framework/transport/transport_nsh.rb +359 -0
  219. data/modules/framework/transport/transport_ssh.rb +220 -0
  220. data/modules/framework/write_to.rb +1 -0
  221. data/modules/jenkins/automations/create_release.rb +4 -0
  222. data/modules/jenkins/automations/create_release.txt +23 -0
  223. data/modules/jenkins/automations/f2_downloadJenkinsArtifact.rb +126 -0
  224. data/modules/jenkins/config.yml +7 -0
  225. data/modules/jenkins/lib/jenkins.rb +300 -0
  226. data/modules/jenkins/resource_automations/f2_rsc_jenkinsJobs.rb +58 -0
  227. data/modules/jira/automations/add_comment.rb +4 -0
  228. data/modules/jira/automations/add_comment.txt +23 -0
  229. data/modules/jira/automations/create_release.rb +4 -0
  230. data/modules/jira/automations/create_release.txt +23 -0
  231. data/modules/jira/automations/delete_release.rb +4 -0
  232. data/modules/jira/automations/delete_release.txt +23 -0
  233. data/modules/jira/automations/transition_issue.rb +4 -0
  234. data/modules/jira/automations/transition_issue.txt +23 -0
  235. data/modules/jira/automations/transition_issues_for_request.rb +29 -0
  236. data/modules/jira/automations/transition_issues_for_request.txt +20 -0
  237. data/modules/jira/automations/transition_issues_for_run.rb +26 -0
  238. data/modules/jira/automations/transition_issues_for_run.txt +20 -0
  239. data/modules/jira/automations/update_release.rb +4 -0
  240. data/modules/jira/automations/update_release.txt +26 -0
  241. data/modules/jira/config.yml +7 -0
  242. data/modules/jira/lib/jira_rest_client.rb +185 -0
  243. data/modules/jira/tests/create_read_update_delete_release_spec.rb +39 -0
  244. data/modules/jira/tests/spec_helper.rb +39 -0
  245. data/modules/jira/tests/transition_issue_spec.rb +32 -0
  246. data/modules/patch_process_management/automations/execute_job/script.rb +105 -0
  247. data/modules/patch_process_management/automations/execute_job/wrapper.txt +39 -0
  248. data/modules/patch_process_management/automations/patch_analysis/script.rb +107 -0
  249. data/modules/patch_process_management/automations/patch_analysis/wrapper.txt +33 -0
  250. data/modules/patch_process_management/automations/patch_readiness/script.rb +89 -0
  251. data/modules/patch_process_management/automations/patch_readiness/wrapper.txt +33 -0
  252. data/modules/patch_process_management/automations/patch_remediation/script.rb +217 -0
  253. data/modules/patch_process_management/automations/patch_remediation/wrapper.txt +40 -0
  254. data/modules/patch_process_management/config.yml +10 -0
  255. data/modules/teamcity/automations/trigger_build.rb +4 -0
  256. data/modules/teamcity/automations/trigger_build.txt +14 -0
  257. data/modules/teamcity/config.yml +7 -0
  258. data/modules/teamcity/lib/teamcity_rest_client.rb +17 -0
  259. data/modules/teamcity/tests/spec_helper.rb +34 -0
  260. data/modules/teamcity/tests/trigger_build_spec.rb +27 -0
  261. data/modules/windows/automations/deploy_directory_over_windows_shares/script.rb +87 -0
  262. data/modules/windows/automations/deploy_directory_over_windows_shares/wrapper.txt +29 -0
  263. data/modules/windows/automations/deploy_file_over_windows_shares/script.rb +31 -0
  264. data/modules/windows/automations/deploy_file_over_windows_shares/wrapper.txt +24 -0
  265. data/modules/windows/config.yml +6 -0
  266. data/modules/windows/lib/samba.rb +29 -0
  267. metadata +397 -0
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'torquebox'
4
+ require 'torquebox-messaging'
5
+ require 'xmlsimple'
6
+ require "brpm_script_executor"
7
+
8
+ BrpmAuto.initialize_logger(ENV["EVENT_HANDLER_LOG_FILE"])
9
+
10
+ host = ENV["EVENT_HANDLER_BRPM_HOST"]
11
+ port = ENV["EVENT_HANDLER_MESSAGING_PORT"]
12
+ username = ENV["EVENT_HANDLER_MESSAGING_USERNAME"]
13
+ password = ENV["EVENT_HANDLER_MESSAGING_PASSWORD"]
14
+ process_event_script = ENV["EVENT_HANDLER_PROCESS_EVENT_SCRIPT"]
15
+
16
+ require process_event_script
17
+
18
+ class MessagingProcessor < TorqueBox::Messaging::MessageProcessor
19
+
20
+ MESSAGING_PATH = '/topics/messaging/brpm_event_queue'
21
+
22
+ def initialize(host, port, username, password)
23
+ BrpmAuto.log "Initializing the message processor..."
24
+ @destination = TorqueBox::Messaging::Topic.new(
25
+ MESSAGING_PATH,
26
+ :host => host,
27
+ :port => port,
28
+ :username => username,
29
+ :password => password
30
+ )
31
+ end
32
+
33
+ def run
34
+ begin
35
+ xml = "<root>#{@destination.receive}</root>"
36
+
37
+ BrpmAuto.log "Processing new event..."
38
+ BrpmAuto.log xml if ENV["EVENT_HANDLER_LOG_EVENT"]=="1"
39
+
40
+ event = XmlSimple.xml_in(xml)
41
+
42
+ process_event(event)
43
+
44
+ rescue Exception => e
45
+ BrpmAuto.log_error(e)
46
+ BrpmAuto.log e.backtrace.join("\n\t")
47
+ end
48
+ end
49
+ end
50
+
51
+ begin
52
+ consumer = MessagingProcessor.new(host, port, username, password)
53
+ BrpmAuto.log "Starting to listen for events ..."
54
+ loop do
55
+ consumer.run
56
+ end
57
+
58
+ rescue Exception => e
59
+ BrpmAuto.log_error(e)
60
+ BrpmAuto.log e.backtrace.join("\n\t")
61
+
62
+ raise e
63
+ end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'json'
4
+ require 'rest-client'
5
+ require 'webrick'
6
+ require "brpm_script_executor"
7
+
8
+ BrpmAuto.initialize_logger(ENV["WEBHOOK_RECEIVER_LOG_FILE"])
9
+
10
+ port = ENV["WEBHOOK_RECEIVER_PORT"]
11
+ mount_point = "/#{ENV["WEBHOOK_RECEIVER_MOUNT_POINT"]}"
12
+ process_event_script = ENV["WEBHOOK_RECEIVER_PROCESS_EVENT_SCRIPT"]
13
+
14
+ require process_event_script
15
+
16
+ class EventProcessor < WEBrick::HTTPServlet::AbstractServlet
17
+ def do_POST(request, response)
18
+ begin
19
+ event = JSON.parse(request.body)
20
+
21
+ BrpmAuto.log "Processing new event..."
22
+ process_event(event)
23
+
24
+ response.status = 200
25
+ response['Content-Type'] = "text/plain"
26
+ response.body = "OK"
27
+ rescue Exception => e
28
+ BrpmAuto.log_error(e)
29
+ BrpmAuto.log e.backtrace.join("\n\t")
30
+ end
31
+ end
32
+ end
33
+
34
+ begin
35
+ server = WEBrick::HTTPServer.new(:Port => port)
36
+ server.mount mount_point, EventProcessor
37
+
38
+ trap("INT") {
39
+ server.shutdown
40
+ }
41
+
42
+ BrpmAuto.log "Starting the server..."
43
+ server.start
44
+ rescue Exception => e
45
+ BrpmAuto.log_error(e)
46
+ BrpmAuto.log e.backtrace.join("\n\t")
47
+
48
+ raise e
49
+ end
@@ -0,0 +1,307 @@
1
+ require "bundler"
2
+ require "yaml"
3
+
4
+ class BrpmAuto
5
+ private_class_method :new
6
+
7
+ class << self
8
+ attr_reader :config
9
+ attr_reader :version
10
+ attr_reader :logger
11
+ attr_reader :params
12
+ attr_reader :request_params
13
+ attr_reader :all_params
14
+ attr_reader :integration_settings
15
+
16
+ attr_reader :framework_root_path
17
+
18
+ attr_reader :gems_root_path
19
+ attr_reader :gemfile_lock
20
+
21
+ attr_reader :modules_root_path
22
+ attr_reader :external_modules_root_path
23
+
24
+ def init
25
+ @config = get_config
26
+ @version = @config["version"]
27
+
28
+ @framework_root_path = File.expand_path("#{File.dirname(__FILE__)}")
29
+
30
+ @gems_root_path = get_gems_root_path
31
+
32
+ @modules_root_path = File.expand_path("#{@framework_root_path}/..")
33
+ @external_modules_root_path = File.expand_path("#{@modules_root_path}/../../modules")
34
+
35
+ require_relative "lib/logging/brpm_logger"
36
+
37
+ require_libs_no_file_logging "#{@modules_root_path}/framework"
38
+
39
+ self.extend Utilities
40
+ end
41
+
42
+ def setup(params = {})
43
+ @params = Params.new(params)
44
+
45
+ load_server_params
46
+ load_customer_include_file
47
+
48
+ if @params.run_from_brpm
49
+ @logger = BrpmLogger.new
50
+ @request_params = RequestParams.new_for_request(@params.automation_results_dir, @params.application, @params.request_id)
51
+ else
52
+ initialize_logger(@params.log_file, @params.also_log_to_console)
53
+ initialize_request_params(@params.output_dir)
54
+ end
55
+
56
+ @all_params = AllParams.new(@params, @request_params)
57
+
58
+ if @params["SS_integration_dns"]
59
+ @integration_settings = IntegrationSettings.new(
60
+ @params["SS_integration_dns"],
61
+ @params["SS_integration_username"],
62
+ @params["SS_integration_password"],
63
+ @params["SS_integration_details"],
64
+ @params["SS_project_server"],
65
+ @params["SS_project_server_id"]
66
+ )
67
+ elsif defined?(SS_integration_dns)
68
+ @integration_settings = IntegrationSettings.new(
69
+ SS_integration_dns,
70
+ SS_integration_username,
71
+ SS_integration_password,
72
+ SS_integration_details,
73
+ SS_project_server,
74
+ SS_project_server_id
75
+ )
76
+ end
77
+ end
78
+
79
+ def require_module(module_name)
80
+ BrpmAuto.log "Loading module #{module_name}..."
81
+
82
+ internal_module_path = "#{@modules_root_path}/#{module_name}"
83
+ external_module_path = "#{@external_modules_root_path}/#{module_name}"
84
+
85
+ if File.exists?(internal_module_path)
86
+ module_path = internal_module_path
87
+ BrpmAuto.log "Found the module in framework module path #{module_path}."
88
+ elsif File.exists?(external_module_path)
89
+ module_path = external_module_path
90
+ BrpmAuto.log "Found the module in external module path #{module_path}."
91
+ else
92
+ raise "Module #{module_name} is not installed.\nSearched in:\n - internal path: #{internal_module_path}\n - external path: #{external_module_path}"
93
+ end
94
+
95
+ module_config_file_path = "#{module_path}/config.yml"
96
+ if File.exist?(module_config_file_path)
97
+ module_config = YAML.load_file(module_config_file_path)
98
+ if module_config["dependencies"]
99
+ BrpmAuto.log "Loading the dependent modules..."
100
+ module_config["dependencies"].each do |dependency|
101
+ require_module(dependency)
102
+ end
103
+ end
104
+ else
105
+ BrpmAuto.log "No config file found."
106
+ end
107
+
108
+ BrpmAuto.log "Loading the libraries of module #{module_name}..."
109
+ require_libs(module_path)
110
+
111
+ module_path
112
+ end
113
+
114
+ def require_module_from_gem(module_name, module_version = nil)
115
+ module_version ||= get_latest_installed_version(module_name)
116
+
117
+ module_gem_path = get_module_gem_path(module_name, module_version)
118
+
119
+ if File.exists?(module_gem_path)
120
+ BrpmAuto.log "Found the module in gem path #{module_gem_path}."
121
+ else
122
+ raise "Module #{module_name} version #{module_version} is not installed. Expected it on path #{module_gem_path}."
123
+ end
124
+
125
+ gemfile_lock_path = "#{module_gem_path}/Gemfile.lock"
126
+ if File.exists?(gemfile_lock_path)
127
+ BrpmAuto.log "Found a Gemfile.lock: #{gemfile_lock_path}. Parsing the version numbers for later usage..."
128
+ @gemfile_lock = Bundler::LockfileParser.new(Bundler.read_file(gemfile_lock_path))
129
+ end
130
+
131
+ require_module_internal(module_name, module_version)
132
+ end
133
+
134
+ def require_libs_no_file_logging(module_path)
135
+ require_libs(module_path, false)
136
+ end
137
+
138
+ def require_libs(module_path, log = true)
139
+ lib_path = "#{module_path}/lib/**/*.rb"
140
+ require_files(Dir[lib_path], log)
141
+ end
142
+
143
+ def require_files(files, log = true)
144
+ failed_files = []
145
+ error_messages = []
146
+ files.each do |file|
147
+ if File.file?(file)
148
+ log ? (BrpmAuto.log "Loading #{file}...") : (print "Loading #{file}...\n")
149
+
150
+ begin
151
+ require file
152
+ rescue NameError => ne # when we require a set of files with inter-dependencies, the order is important, therefore we will retry the failed files later
153
+ failed_files << file
154
+ error_messages << ne
155
+ end
156
+ end
157
+ end
158
+ if failed_files.count > 0
159
+ if failed_files.count == files.count
160
+ raise NameError, "Following files failed loading: #{failed_files.join(", ")}\nError messages: #{error_messages.join(", ")}"
161
+ else
162
+ require_files(failed_files, log)
163
+ end
164
+ end
165
+ end
166
+
167
+ def load_server_params
168
+ server_config_file_path = "#{self.params.config_dir}/server.yml"
169
+ if File.exists?(server_config_file_path)
170
+ server_config = YAML.load_file(server_config_file_path)
171
+ server_config.each do |key, value|
172
+ @params[key] = value unless @params.has_key?(key)
173
+ end
174
+ end
175
+ end
176
+
177
+ def load_customer_include_file
178
+ customer_include_file_path = "#{self.params.config_dir}/customer_include.rb"
179
+ if File.exists?(customer_include_file_path)
180
+ load customer_include_file_path # use load instead of require to avoid having to restart BRPM after modifying the customer include file in a resource automation scenario
181
+ if defined?(get_customer_include_params)
182
+ customer_include_params = get_customer_include_params
183
+ customer_include_params.each do |key, value|
184
+ @params[key] = value
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ def initialize_logger(log_file, also_log_to_console = false)
191
+ @logger = SimpleLogger.new(log_file, also_log_to_console)
192
+ end
193
+
194
+ def log(message)
195
+ @logger.log(message)
196
+ end
197
+
198
+ def log_error(message)
199
+ @logger.log_error(message)
200
+ end
201
+
202
+ def message_box(message, m_type = "sep")
203
+ @logger.message_box(message, m_type)
204
+ end
205
+
206
+ def initialize_request_params(path)
207
+ @request_params = RequestParams.new(path)
208
+ end
209
+
210
+ def get_request_params_for_request(automation_results_dir, application, request_id)
211
+ RequestParams.new_for_request(automation_results_dir, application, request_id)
212
+ end
213
+
214
+ def initialize_integration_settings(dns, username, password, details)
215
+ @integration_settings = IntegrationSettings.new(dns, username, password, details)
216
+ end
217
+
218
+ private
219
+
220
+ def require_module_internal(module_name, module_version)
221
+ module_path = get_module_gem_path(module_name, module_version)
222
+
223
+ module_config_file_path = "#{module_path}/config.yml"
224
+ if File.exist?(module_config_file_path)
225
+ module_config = YAML.load_file(module_config_file_path)
226
+ if module_config["dependencies"]
227
+ BrpmAuto.log "Loading the dependent modules..."
228
+ module_config["dependencies"].each do |dependency|
229
+ if dependency.is_a?(Hash)
230
+ dep_module_name = dependency.keys[0]
231
+ if @gemfile_lock
232
+ dep_module_version = get_version_from_gemfile_lock(dep_module_name)
233
+ else
234
+ dep_module_version = dependency.values[0]["version"]
235
+ end
236
+ else
237
+ dep_module_name = dependency
238
+
239
+ if ["brpm", "bladelogic", "jira"].include?(dep_module_name)
240
+ require_module(dep_module_name)
241
+ next
242
+ end
243
+
244
+ if @gemfile_lock
245
+ dep_module_version = get_version_from_gemfile_lock(dep_module_name)
246
+ else
247
+ dep_module_version = get_latest_installed_version(dep_module_name)
248
+ end
249
+ end
250
+
251
+ BrpmAuto.log "Loading module #{dep_module_name} version #{dep_module_version}..."
252
+ require_module_internal(dep_module_name, dep_module_version)
253
+ end
254
+ end
255
+ else
256
+ BrpmAuto.log "No config file found."
257
+ end
258
+
259
+ BrpmAuto.log "Loading the libraries of module #{module_name}..."
260
+ require_libs(module_path)
261
+
262
+ module_path
263
+ end
264
+
265
+ def get_config
266
+ YAML.load_file(File.expand_path("#{File.dirname(__FILE__)}/config.yml"))
267
+ end
268
+
269
+ def get_gems_root_path
270
+ if ENV["BRPM_CONTENT_HOME"]
271
+ ENV["BRPM_CONTENT_HOME"] # gemset location is overridden
272
+ elsif ENV["BRPM_HOME"]
273
+ "#{ENV["BRPM_HOME"]}/modules" # default gemset location when BRPM is installed
274
+ elsif ENV["GEM_HOME"]
275
+ ENV["GEM_HOME"] # default gemset location when BRPM is not installed
276
+ else
277
+ raise "Unable to find out the gems root path."
278
+ end
279
+ end
280
+
281
+ def get_module_gem_path(module_name, module_version)
282
+ "#{@gems_root_path}/gems/#{module_name}-#{module_version}"
283
+ end
284
+
285
+ def get_latest_installed_version(module_name)
286
+ latest_version_path = get_module_gem_path(module_name, "latest")
287
+ return "latest" if File.exists?(latest_version_path)
288
+
289
+ all_version_search = get_module_gem_path(module_name, "*")
290
+ version_paths = Dir.glob(all_version_search)
291
+
292
+ raise "Could not find any installed version of module #{module_name}. Expected them in #{get_module_gem_path(module_name, "*")}" if version_paths.empty?
293
+
294
+ versions = version_paths.map { |path| File.basename(path).sub("#{module_name}-", "") }
295
+
296
+ versions.sort{ |a, b| Gem::Version.new(a) <=> Gem::Version.new(b) }.last
297
+ end
298
+
299
+ def get_version_from_gemfile_lock(module_name)
300
+ spec = @gemfile_lock.specs.find { |spec| spec.name == module_name }
301
+ spec.version
302
+ end
303
+ end
304
+
305
+ self.init
306
+ end
307
+
@@ -0,0 +1,88 @@
1
+ # = BRPM Automation Framework
2
+ # BMC Software - BJB 8/22/2014, BJB 9/17/14
3
+ # ==== A collection of classes to simplify building BRPM automation
4
+ # === Instructions
5
+ # In your BRPM automation include a block like this to pull in the library
6
+ # <tt> params["direct_execute"] = true #Set for local execution
7
+ # <tt> require @params["SS_automation_results_dir"].gsub("automation_results","persist/automation_lib/brpm_framework.rb")
8
+ require 'popen4'
9
+ require 'timeout'
10
+ require 'rest-client'
11
+
12
+ SleepDelay = [5,10,25,60] # Pattern for sleep pause in polling
13
+ RLM_BASE_PROPERTIES = ["SS_application", "SS_environment", "SS_component", "SS_component_version", "request_id", "step_name"]
14
+ KEYWORD_SWITCHES = ["RPM_PARAMS_FILTER","RPM_SRUN_WRAPPER","RPM_INCLUDE"] unless defined?(KEYWORD_SWITCHES)
15
+ FRAMEWORK_DIR = File.dirname(File.expand_path(__FILE__)) unless defined?(FRAMEWORK_DIR)
16
+
17
+ def rpm_load_module(*module_names)
18
+ result = ""
19
+ module_names.each do |mod_name|
20
+ user_load_path = defined?(CUSTOMER_LIB_DIR) ? "#{CUSTOMER_LIB_DIR}/lib/#{mod_name}" : nil
21
+ load_path = "#{FRAMEWORK_DIR}/lib/#{mod_name}"
22
+ transport_load_path = "#{FRAMEWORK_DIR}/transport/#{mod_name}"
23
+ if File.exist?("#{load_path}.rb")
24
+ require load_path
25
+ result += "success - #{load_path}\n"
26
+ elsif File.exist?("#{transport_load_path}.rb")
27
+ require transport_load_path
28
+ result += "success - #{load_path}\n"
29
+ elsif !user_load_path.nil? && File.exist?("#{user_load_path}.rb")
30
+ require user_load_path
31
+ result += "success - #{load_path}\n"
32
+ else
33
+ result += "ERROR - file not found #{load_path}\n"
34
+ end
35
+ end
36
+ result
37
+ end
38
+
39
+ def update_output
40
+ load "#{FRAMEWORK_DIR}/write_to.rb" if BrpmAuto.params.run_from_brpm
41
+ end
42
+
43
+ # == Initialization on Include
44
+ # Objects are set for most of the classes on requiring the file
45
+ # these will be available in the BRPM automation
46
+ # Customers should modify the BAA_BASE_PATH constant
47
+ # == Note the customer_include.rb reference. To add your own routines and override methods use this file.
48
+ customer_include_file = File.join(FRAMEWORK_DIR.gsub("/brpm_content/modules/framework", ""), "/customer_include.rb")
49
+ customer_include_file = File.join(CUSTOMER_LIB_DIR,"customer_include.rb") if defined?(CUSTOMER_LIB_DIR)
50
+ customer_include_file = File.join(FRAMEWORK_DIR,"customer_include_default.rb") if !File.exist?(customer_include_file)
51
+
52
+ conts = File.open(customer_include_file).read
53
+ eval conts # Use eval for resource automation to be dynamic
54
+
55
+ if @params.nil? || @params["SS_script_target"] == "resource_automation"
56
+ puts "Loading customer include file: #{customer_include_file}"
57
+ conts = File.open(File.join(File.dirname(FRAMEWORK_DIR),"brpm", "lib","resource_framework.rb")).read
58
+ eval conts
59
+ else
60
+ require "#{FRAMEWORK_DIR}/brpm_auto"
61
+ @rpm = BrpmAuto
62
+ @rpm.setup(@params)
63
+ @rpm.log "Loading customer include file: #{customer_include_file}"
64
+ if @params["SS_script_type"] != 'test' && @params["SS_script_target"] != "resource_automation" && !@params.has_key?("SS_no_framework")
65
+ automation_settings = @params["SS_script_support_path"].gsub("lib/script_support","config/automation_settings.rb")
66
+ require "#{automation_settings}" if File.exist?(automation_settings)
67
+ end
68
+ @request_params = {} if not defined?(@request_params)
69
+ SS_output_file = @params["SS_output_file"]
70
+ BrpmAuto.require_module("brpm")
71
+ @p = BrpmAuto.all_params
72
+ @request_params = BrpmAuto.request_params
73
+ ARG_PREFIX = "ARG_" unless defined?(ARG_PREFIX)
74
+ @rest = BrpmRest.new(@p.SS_base_url)
75
+ if @p.get("SS_skip_transport") == ""
76
+ #Load the transport for the step, transport follows environment property SS_transport
77
+ transport = @p.get("ss_transport")
78
+ if transport == ""
79
+ transport = @p.get("SS_transport", "nsh")
80
+ @p.assign_local_param("ss_transport", transport)
81
+ @p.find_or_add("SS_transport", transport)
82
+ @p.save_local_params
83
+ end
84
+ @rpm.log "Loading transport modules for: #{transport}"
85
+ res = rpm_load_module("transport_#{transport}", "dispatch_#{transport}")
86
+ @rpm.log res if res.include?("ERROR")
87
+ end
88
+ end