brpm_module_bladelogic 0.1.32 → 0.1.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/automations/execute_job.meta +31 -0
- data/automations/execute_job.rb +106 -0
- data/config.yml +1 -1
- data/lib/bl_soap/bsa_soap_client.rb +4 -0
- data/lib/bl_soap/job.rb +1 -1
- data/resource_automations/select_job.rb +1 -1
- data/tests/execute_job_spec.rb +25 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTk3YTUyNGJkZmY1ODYxOWM0MDE5YmVjZjQ0YTVkZWU4N2E1NDllYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTgxNzgyYTI0NmZiYmQ3MjAzYmRjYjY1OTEwYWUwZjJkNTU5MDlmOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjZhOGExYzY4NzEwZmI5OTY2ZjgwNzY3NTNlZTJmODg4NWExNzA0NzFjMmFl
|
10
|
+
NGIxNzAxZTc0NzJmZDE1NzJlYzMzMzg4YjVlY2ZlZDJlMzIyNDFmZGU5NDc2
|
11
|
+
OWJlNTZlZmU3NmE4NGMzYmUwZGRhMzRlZTg5YWUxMDNlYmQ4Yjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2M0YTVmODY5NzYzODAxOGQ1ZDhmMWVhOGQ0ZjhhMDRkMmI3M2UzOTllMzBi
|
14
|
+
MGYxMjkyYzMzMDVjNGVmMjM2ZDdlZTNiYTM4ZTBkYzQ2NjA4OWRiMjM2ZWU5
|
15
|
+
NDE2MjM4YzUxYWVmMjNjM2M3MTYzYTI2NjI5MGM1ZmM3YjYxNjk=
|
@@ -0,0 +1,31 @@
|
|
1
|
+
params:
|
2
|
+
job_type_and_name:
|
3
|
+
name: Job type and name
|
4
|
+
position: A1:F1
|
5
|
+
type: in-external-single-select
|
6
|
+
external_resource: select_job
|
7
|
+
target_type:
|
8
|
+
name: Target type
|
9
|
+
type: in-list-single
|
10
|
+
list_pairs: 0,Server group|1,Servers
|
11
|
+
position: A2:C2
|
12
|
+
job_status:
|
13
|
+
name: Job Status
|
14
|
+
type: out-text
|
15
|
+
position: A1:C1
|
16
|
+
results_summary:
|
17
|
+
name: Summary
|
18
|
+
type: out-text
|
19
|
+
position: A2:E2
|
20
|
+
results:
|
21
|
+
name: Installs
|
22
|
+
type: out-table
|
23
|
+
position: A3:E3
|
24
|
+
results_link:
|
25
|
+
name: Link
|
26
|
+
type: out-file
|
27
|
+
position: A4:E4
|
28
|
+
|
29
|
+
|
30
|
+
description: Executes a Bladelogic job
|
31
|
+
integration_server_type: Bladelogic
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'csv'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
def pack_response_for_result_summaries(csv_content)
|
6
|
+
logs = csv_content[6..-1] # remove the headers of the csv file
|
7
|
+
|
8
|
+
logs = logs.select { |log| !log[0].start_with?("Run at") }
|
9
|
+
|
10
|
+
logs.each do |log|
|
11
|
+
log[2] = DateTime.parse(log[2])
|
12
|
+
end
|
13
|
+
|
14
|
+
logs = logs.sort_by { |log| [log[0], log[2]] }
|
15
|
+
|
16
|
+
servers_with_logs = logs.group_by {|log| log[0] }
|
17
|
+
failed_servers_with_logs = servers_with_logs.select {|key, value| value.select{|log| log[1] == "Error"}.count>0}
|
18
|
+
|
19
|
+
BrpmAuto.pack_response "results_summary", "#{servers_with_logs.count - failed_servers_with_logs.count}/#{servers_with_logs.count} servers were successful"
|
20
|
+
|
21
|
+
table_data = [[' ', 'Server', 'Result', 'Error message']]
|
22
|
+
counter = 0
|
23
|
+
server_cache = ""
|
24
|
+
logs.select{|log| log[1] == "Error"}.each do |log|
|
25
|
+
if log[0] == server_cache
|
26
|
+
server = ""
|
27
|
+
else
|
28
|
+
server = log[0]
|
29
|
+
server_cache = log[0]
|
30
|
+
end
|
31
|
+
result = log[1]
|
32
|
+
message = log[3]
|
33
|
+
|
34
|
+
counter += 1
|
35
|
+
table_data << [counter, server, result, message]
|
36
|
+
end
|
37
|
+
|
38
|
+
BrpmAuto.pack_response "results", { :perPage => 10, :totalItems => table_data.count - 1, :data => table_data }
|
39
|
+
end
|
40
|
+
|
41
|
+
brpm_rest_client = BrpmRestClient.new
|
42
|
+
|
43
|
+
job_type_and_name = BrpmAuto.params["job_type_and_name"].split("|")
|
44
|
+
raise "Could not find out the job key or job name." unless job_type_and_name.count == 2
|
45
|
+
job_type = job_type_and_name[0]
|
46
|
+
job_name = job_type_and_name[1]
|
47
|
+
|
48
|
+
job_group = "/Applications/#{BrpmAuto.params["application"]}/#{job_type}"
|
49
|
+
BrpmAuto.log("The job to be executed is #{job_group}/#{job_name}")
|
50
|
+
|
51
|
+
BrpmAuto.log("Logging on to Bladelogic...")
|
52
|
+
bsa_soap_client = BsaSoapClient.new
|
53
|
+
|
54
|
+
BrpmAuto.log("Retrieving the job key of the job...")
|
55
|
+
job_db_key = bsa_soap_client.nsh_script_job.get_dbkey_by_group_and_name({:group_name => job_group, :job_name => job_name})
|
56
|
+
BrpmAuto.log("Job key is #{job_db_key}.")
|
57
|
+
|
58
|
+
job_run_key = nil
|
59
|
+
if BrpmAuto.params["target_type"] == "Server group"
|
60
|
+
BrpmAuto.log("Getting the server group from the step...")
|
61
|
+
server_group = "/#{brpm_rest_client.get_server_group_from_step_id(BrpmAuto.params["step_id"])}"
|
62
|
+
|
63
|
+
BrpmAuto.log("Executing the job on server group #{server_group}...")
|
64
|
+
job_run_key = bsa_soap_client.job.execute_against_server_groups_for_run_id({:job_key => job_db_key, :server_groups => server_group})
|
65
|
+
elsif BrpmAuto.params["target_type"] == "Servers"
|
66
|
+
servers = BrpmAuto.params.servers.keys.join(",")
|
67
|
+
BrpmAuto.log("Executing the job on servers #{servers}...")
|
68
|
+
job_run_key = bsa_soap_client.job.execute_against_servers_for_run_id({:job_key => job_db_key, :server_names => servers})
|
69
|
+
end
|
70
|
+
BrpmAuto.log("Job run is #{job_run_key}.")
|
71
|
+
|
72
|
+
|
73
|
+
BrpmAuto.log("Polling the job until it is finished...")
|
74
|
+
begin
|
75
|
+
sleep(10)
|
76
|
+
is_still_running = bsa_soap_client.job_run.get_job_run_is_running_by_run_key({:job_run_key => job_run_key})
|
77
|
+
end while is_still_running
|
78
|
+
BrpmAuto.log("The job has finished.")
|
79
|
+
|
80
|
+
BrpmAuto.log("Checking if the job finished successfully...")
|
81
|
+
had_errors = bsa_soap_client.job_run.get_job_run_had_errors({:job_run_key => job_run_key})
|
82
|
+
|
83
|
+
had_errors ? BrpmAuto.log("WARNING: The job had errors!") : BrpmAuto.log("The job had no errors.")
|
84
|
+
BrpmAuto.pack_response "job_status", had_errors ? "The job had errors" : "The job ran successfully"
|
85
|
+
|
86
|
+
BrpmAuto.log("Retrieving the job run id from the job run key...")
|
87
|
+
job_run_id = bsa_soap_client.job_run.job_run_key_to_job_run_id({:job_run_key => job_run_key})
|
88
|
+
|
89
|
+
BrpmAuto.log("Retrieving the results from the job run id...")
|
90
|
+
results_full_path = "#{BrpmAuto.params.output_dir}/#{job_name}_result.csv"
|
91
|
+
return_data = bsa_soap_client.utility.export_nsh_script_run({
|
92
|
+
:run_id => job_run_id,
|
93
|
+
:export_file_name => results_full_path})
|
94
|
+
results_content = Base64.decode64(return_data)
|
95
|
+
|
96
|
+
File.open(results_full_path, "w") do |f|
|
97
|
+
f.puts(results_content)
|
98
|
+
end
|
99
|
+
|
100
|
+
csv_content = CSV.parse(results_content)
|
101
|
+
|
102
|
+
pack_response_for_result_summaries(csv_content)
|
103
|
+
|
104
|
+
BrpmAuto.pack_response "results_link", results_full_path
|
105
|
+
|
106
|
+
raise "The job had errors!" if had_errors
|
data/config.yml
CHANGED
@@ -20,6 +20,10 @@ class BsaSoapClient < BsaSoapBase
|
|
20
20
|
@deploy_job ||= DeployJob.new(@url, @session_id)
|
21
21
|
end
|
22
22
|
|
23
|
+
def nsh_script_job
|
24
|
+
@nsh_script_job ||= NSHScriptJob.new(@url, @session_id)
|
25
|
+
end
|
26
|
+
|
23
27
|
def job_group
|
24
28
|
@job_group ||= JobGroup.new(@url, @session_id)
|
25
29
|
end
|
data/lib/bl_soap/job.rb
CHANGED
@@ -217,7 +217,7 @@ class Job < BsaSoapBase
|
|
217
217
|
options[:job_key], # Handle of the job to be updated
|
218
218
|
options[:server_names] # Name of server group(s) - comma-separated list of group names
|
219
219
|
])
|
220
|
-
job_run_key = get_cli_return_value(
|
220
|
+
job_run_key = get_cli_return_value(job_run_key_result)
|
221
221
|
rescue => exception
|
222
222
|
raise "#{self.class} Exception: #{exception.to_s}"
|
223
223
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
def execute_script(params, parent_id, offset, max_records)
|
2
|
-
root_group_name = "/#{params["application"]
|
2
|
+
root_group_name = "/Applications/#{params["application"]}"
|
3
3
|
|
4
4
|
BrpmAuto.log("Logging on to Bladelogic instance #{BsaSoapClient.get_url} with user #{BsaSoapClient.get_username} and role #{BsaSoapClient.get_role}...")
|
5
5
|
session_id = BsaSoapClient.login
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe 'execute job' do
|
4
|
+
before(:all) do
|
5
|
+
setup_brpm_auto
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
cleanup_request_params
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should execute a job to a list of server in BladeLogic' do
|
13
|
+
params = get_default_params
|
14
|
+
params = params.merge(get_integration_params_for_bladelogic)
|
15
|
+
|
16
|
+
params["application"] = 'E-Finance'
|
17
|
+
params["job_type_and_name"] = 'NSHScriptJob|echo'
|
18
|
+
params["target_type"] = "Servers"
|
19
|
+
params["server1000_name"] = "localhost"
|
20
|
+
|
21
|
+
BrpmScriptExecutor.execute_automation_script("brpm_module_bladelogic", "execute_job", params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brpm_module_bladelogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niek Bartholomeus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brpm_content_framework
|
@@ -87,6 +87,8 @@ files:
|
|
87
87
|
- automations/create_package.rb
|
88
88
|
- automations/deploy_package.meta
|
89
89
|
- automations/deploy_package.rb
|
90
|
+
- automations/execute_job.meta
|
91
|
+
- automations/execute_job.rb
|
90
92
|
- bin/bladelogic_connect
|
91
93
|
- bin/create_bl_package
|
92
94
|
- config.yml
|
@@ -118,6 +120,7 @@ files:
|
|
118
120
|
- resource_automations/select_job.rb
|
119
121
|
- tests/create_package_spec.rb
|
120
122
|
- tests/deploy_package_spec.rb
|
123
|
+
- tests/execute_job_spec.rb
|
121
124
|
- tests/gemspec_spec.rb
|
122
125
|
- tests/spec_helper.rb
|
123
126
|
homepage: https://github.com/BMC-RLM/brpm_module_bladelogic
|