Class: BrpmAuto
- Inherits:
-
Object
- Object
- BrpmAuto
- Defined in:
- lib/brpm_auto.rb
Class Attribute Summary collapse
-
.all_params ⇒ Object
readonly
Returns the value of attribute all_params.
-
.config ⇒ Object
readonly
Returns the value of attribute config.
-
.framework_root_path ⇒ Object
readonly
Returns the value of attribute framework_root_path.
-
.gemfile_lock ⇒ Object
readonly
Returns the value of attribute gemfile_lock.
-
.gems_root_path ⇒ Object
readonly
Returns the value of attribute gems_root_path.
-
.integration_settings ⇒ Object
readonly
Returns the value of attribute integration_settings.
-
.logger ⇒ Object
readonly
Returns the value of attribute logger.
-
.params ⇒ Object
readonly
Returns the value of attribute params.
-
.request_params ⇒ Object
readonly
Returns the value of attribute request_params.
-
.version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .get_gems_root_path ⇒ Object
- .get_request_params_for_request(automation_results_dir, application, request_id) ⇒ Object
- .init ⇒ Object
- .initialize_integration_settings(dns, username, password, details) ⇒ Object
- .initialize_logger(log_file, also_log_to_console = false) ⇒ Object
- .initialize_request_params(path) ⇒ Object
- .load_customer_include_file ⇒ Object
- .load_server_params ⇒ Object
- .log(message) ⇒ Object
- .log_error(message) ⇒ Object
- .message_box(message, m_type = "sep") ⇒ Object
- .pack_response(argument_name, response) ⇒ Object
- .require_files(files, log = true) ⇒ Object
- .require_libs(module_path, log = true) ⇒ Object
- .require_libs_no_file_logging(module_path) ⇒ Object
- .require_module(module_name, module_version = nil) ⇒ Object
- .run_from_brpm ⇒ Object
- .set_application_version(prop, value) ⇒ Object
- .set_build_flag_data(set_item, set_data, acceptable_titles) ⇒ Object
- .set_component_flag(components) ⇒ Object
-
.set_property_flag(prop, value = nil) ⇒ Object
Assure backward compatibility with the ssh_script_header methods when running the automation scripts in a separate process.
- .set_server_flag(servers) ⇒ Object
- .set_titles_acceptable?(cur_titles, acceptable_titles) ⇒ Boolean
- .setup(params = {}) ⇒ Object
Class Attribute Details
.all_params ⇒ Object (readonly)
Returns the value of attribute all_params.
13 14 15 |
# File 'lib/brpm_auto.rb', line 13 def all_params @all_params end |
.config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/brpm_auto.rb', line 8 def config @config end |
.framework_root_path ⇒ Object (readonly)
Returns the value of attribute framework_root_path.
16 17 18 |
# File 'lib/brpm_auto.rb', line 16 def framework_root_path @framework_root_path end |
.gemfile_lock ⇒ Object (readonly)
Returns the value of attribute gemfile_lock.
19 20 21 |
# File 'lib/brpm_auto.rb', line 19 def gemfile_lock @gemfile_lock end |
.gems_root_path ⇒ Object (readonly)
Returns the value of attribute gems_root_path.
18 19 20 |
# File 'lib/brpm_auto.rb', line 18 def gems_root_path @gems_root_path end |
.integration_settings ⇒ Object (readonly)
Returns the value of attribute integration_settings.
14 15 16 |
# File 'lib/brpm_auto.rb', line 14 def integration_settings @integration_settings end |
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/brpm_auto.rb', line 10 def logger @logger end |
.params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/brpm_auto.rb', line 11 def params @params end |
.request_params ⇒ Object (readonly)
Returns the value of attribute request_params.
12 13 14 |
# File 'lib/brpm_auto.rb', line 12 def request_params @request_params end |
.version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/brpm_auto.rb', line 9 def version @version end |
Class Method Details
.get_gems_root_path ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/brpm_auto.rb', line 182 def get_gems_root_path if ENV["BRPM_CONTENT_HOME"] ENV["BRPM_CONTENT_HOME"] # gemset location is overridden elsif ENV["BRPM_HOME"] "#{ENV["BRPM_HOME"]}/modules" # default gemset location when BRPM is installed elsif ENV["GEM_HOME"] ENV["GEM_HOME"] # default gemset location when BRPM is not installed else raise "Unable to find out the gems root path." end end |
.get_request_params_for_request(automation_results_dir, application, request_id) ⇒ Object
174 175 176 |
# File 'lib/brpm_auto.rb', line 174 def get_request_params_for_request(automation_results_dir, application, request_id) RequestParams.new_for_request(automation_results_dir, application, request_id) end |
.init ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/brpm_auto.rb', line 21 def init @framework_root_path = File.("#{File.dirname(__FILE__)}/..") require "logging/brpm_logger" require_libs_no_file_logging @framework_root_path self.extend Utilities @config = get_config @version = @config["version"] @gems_root_path = get_gems_root_path end |
.initialize_integration_settings(dns, username, password, details) ⇒ Object
178 179 180 |
# File 'lib/brpm_auto.rb', line 178 def initialize_integration_settings(dns, username, password, details) @integration_settings = IntegrationSettings.new(dns, username, password, details) end |
.initialize_logger(log_file, also_log_to_console = false) ⇒ Object
150 151 152 |
# File 'lib/brpm_auto.rb', line 150 def initialize_logger(log_file, also_log_to_console = false) @logger = SimpleLogger.new(log_file, also_log_to_console) end |
.initialize_request_params(path) ⇒ Object
170 171 172 |
# File 'lib/brpm_auto.rb', line 170 def initialize_request_params(path) @request_params = RequestParams.new(path) end |
.load_customer_include_file ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/brpm_auto.rb', line 137 def load_customer_include_file customer_include_file_path = "#{self.params.config_dir}/customer_include.rb" if File.exists?(customer_include_file_path) 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 if defined?(get_customer_include_params) customer_include_params = get_customer_include_params customer_include_params.each do |key, value| @params[key] = value end end end end |
.load_server_params ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/brpm_auto.rb', line 127 def load_server_params server_config_file_path = "#{self.params.config_dir}/server.yml" if File.exists?(server_config_file_path) server_config = YAML.load_file(server_config_file_path) server_config.each do |key, value| @params[key] = value unless @params.has_key?(key) end end end |
.log(message) ⇒ Object
158 159 160 |
# File 'lib/brpm_auto.rb', line 158 def log() @logger.log() end |
.log_error(message) ⇒ Object
162 163 164 |
# File 'lib/brpm_auto.rb', line 162 def log_error() @logger.log_error() end |
.message_box(message, m_type = "sep") ⇒ Object
166 167 168 |
# File 'lib/brpm_auto.rb', line 166 def (, m_type = "sep") @logger.(, m_type) end |
.pack_response(argument_name, response) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/brpm_auto.rb', line 263 def pack_response(argument_name, response) flag = "#------ Block to Set Pack Response ---------------#\n" unless argument_name.nil? if response.is_a?(Hash) # Used for out-table output parameter flag += "$$SS_Pack_Response{#{argument_name}@@#{response.to_json}}$$" else flag += "$$SS_Pack_Response{#{argument_name}=>#{response}}$$" end end flag += "\n#------- End Set Pack Response Block ---------------#\n" BrpmAuto.log flag flag end |
.require_files(files, log = true) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/brpm_auto.rb', line 103 def require_files(files, log = true) failed_files = [] = [] files.each do |file| if File.file?(file) log ? (BrpmAuto.log "Loading #{file}...") : (print "Loading #{file}...\n") begin require file 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 failed_files << file << ne end end end if failed_files.count > 0 if failed_files.count == files.count raise NameError, "Following files failed loading: #{failed_files.join(", ")}\nError messages: #{.join(", ")}" else require_files(failed_files, log) end end end |
.require_libs(module_path, log = true) ⇒ Object
98 99 100 101 |
# File 'lib/brpm_auto.rb', line 98 def require_libs(module_path, log = true) lib_path = "#{module_path}/lib/**/*.rb" require_files(Dir[lib_path], log) end |
.require_libs_no_file_logging(module_path) ⇒ Object
94 95 96 |
# File 'lib/brpm_auto.rb', line 94 def require_libs_no_file_logging(module_path) require_libs(module_path, false) end |
.require_module(module_name, module_version = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/brpm_auto.rb', line 73 def require_module(module_name, module_version = nil) module_version ||= get_latest_installed_version(module_name) module_gem_path = get_module_gem_path(module_name, module_version) if File.exists?(module_gem_path) BrpmAuto.log "Found module #{module_name} #{module_version || ""} in gem path #{module_gem_path}." else raise Gem::GemNotFoundException, "Module #{module_name} version #{module_version} is not installed. Expected it on path #{module_gem_path}." end gemfile_lock_path = "#{module_gem_path}/Gemfile.lock" if File.exists?(gemfile_lock_path) # TODO: decide how to react when multiple gems are 'required', each with a gemfile.lock BrpmAuto.log "Found a Gemfile.lock: #{gemfile_lock_path} so parsing the specified version numbers for later usage..." Dir.chdir(File.dirname(gemfile_lock_path)) do @gemfile_lock = Bundler::LockfileParser.new(Bundler.read_file(gemfile_lock_path)) end end require_module_internal(module_name, module_version) end |
.run_from_brpm ⇒ Object
154 155 156 |
# File 'lib/brpm_auto.rb', line 154 def run_from_brpm @params.run_from_brpm end |
.set_application_version(prop, value) ⇒ Object
254 255 256 257 258 259 260 261 |
# File 'lib/brpm_auto.rb', line 254 def set_application_version(prop, value) # set_application_flag(app_name, version) flag = "#------ Block to Set Application Version ---------------#\n" flag += "$$SS_Set_application{#{prop}=>#{value}}$$" flag += "\n#------ End Set Application ---------------#\n" BrpmAuto.log(flag) flag end |
.set_build_flag_data(set_item, set_data, acceptable_titles) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/brpm_auto.rb', line 233 def set_build_flag_data(set_item, set_data, acceptable_titles) flag = ""; msg = "" lines = set_data.split("\n") titles = lines[0].split(",").map{ |it| it.strip } if set_titles_acceptable?(titles, acceptable_titles) flag += "$$SS_Set_#{set_item}{\n" flag += "#{titles.join(", ")}\n" lines[1..-1].each do |line| if line.split(",").count == titles.count flag += "#{line}\n" else msg += "Skipped: #{line}" end end flag += "}$$\n" else flag += "ERROR - Unable to set #{set_item} - improper format\n" end flag += msg end |
.set_component_flag(components) ⇒ Object
219 220 221 222 223 224 225 226 227 |
# File 'lib/brpm_auto.rb', line 219 def set_component_flag(components) # comps = "comp_name, version\ncomp2_name, version2" flag = "#------ Block to Set Components ---------------#\n" acceptable_fields = ["name", "version", "environment", "application"] flag += set_build_flag_data("components", components, acceptable_fields) flag += "\n#------ End Set Components ---------------#\n" BrpmAuto.log flag flag end |
.set_property_flag(prop, value = nil) ⇒ Object
Assure backward compatibility with the ssh_script_header methods when running the automation scripts in a separate process
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/brpm_auto.rb', line 196 def set_property_flag(prop, value = nil) acceptable_fields = ["name", "value", "environment", "component", "global", "private"] flag = "#------ Block to Set Property ---------------#\n" if value.nil? flag += set_build_flag_data("properties", prop, acceptable_fields) else flag += "$$SS_Set_property{#{prop}=>#{value}}$$" end flag += "\n#------- End Set Property ---------------#\n" BrpmAuto.log flag flag end |
.set_server_flag(servers) ⇒ Object
209 210 211 212 213 214 215 216 217 |
# File 'lib/brpm_auto.rb', line 209 def set_server_flag(servers) # servers = "server_name, env\ncserver2_name, env2" acceptable_fields = ["name", "environment", "group"] flag = "#------ Block to Set Servers ---------------#\n" flag += set_build_flag_data("servers", servers, acceptable_fields) flag += "\n#------ End Set Servers ---------------#\n" BrpmAuto.log flag flag end |
.set_titles_acceptable?(cur_titles, acceptable_titles) ⇒ Boolean
229 230 231 |
# File 'lib/brpm_auto.rb', line 229 def set_titles_acceptable?(cur_titles, acceptable_titles) cur_titles.each.reject{ |cur| acceptable_titles.include?(cur)}.count == 0 end |
.setup(params = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/brpm_auto.rb', line 36 def setup(params = {}) @params = Params.new(params) load_server_params load_customer_include_file if @params.run_from_brpm @logger = BrpmLogger.new @request_params = RequestParams.new_for_request(@params.automation_results_dir, @params.application, @params.request_id) else initialize_logger(@params.log_file, @params.also_log_to_console) initialize_request_params(@params.output_dir) end @all_params = AllParams.new(@params, @request_params) if @params["SS_integration_dns"] @integration_settings = IntegrationSettings.new( @params["SS_integration_dns"], @params["SS_integration_username"], @params["SS_integration_password"], @params["SS_integration_details"], @params["SS_project_server"], @params["SS_project_server_id"] ) elsif defined?(SS_integration_dns) @integration_settings = IntegrationSettings.new( SS_integration_dns, SS_integration_username, SS_integration_password, SS_integration_details, SS_project_server, SS_project_server_id ) end end |