brpm_module_brpm 0.1.10
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/.ruby-version +1 -0
- data/.travis.yml +18 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +7 -0
- data/Rakefile +24 -0
- data/automations/create_release_from_excel.rb +34 -0
- data/automations/create_release_from_excel.txt +5 -0
- data/automations/create_release_request.rb +100 -0
- data/automations/create_release_request.txt +5 -0
- data/automations/create_request.rb +73 -0
- data/automations/create_request.txt +23 -0
- data/automations/promote_request.rb +197 -0
- data/automations/promote_request.txt +24 -0
- data/automations/select_application_version.rb +22 -0
- data/automations/select_application_version.txt +17 -0
- data/automations/select_component_version.rb +12 -0
- data/automations/select_component_version.txt +5 -0
- data/automations/select_request_template.rb +6 -0
- data/automations/select_request_template.txt +13 -0
- data/automations/wait_for_step_in_other_request.rb +11 -0
- data/automations/wait_for_step_in_other_request.txt +13 -0
- data/automations/wait_till_promoted_request_is_completed.rb +9 -0
- data/automations/wait_till_promoted_request_is_completed.txt +5 -0
- data/bin/create_release_request +23 -0
- data/brpm_module_brpm.gemspec +39 -0
- data/config.yml +11 -0
- data/lib/brpm_request.rb +207 -0
- data/lib/brpm_rest.rb +312 -0
- data/lib/brpm_rest_client.rb +1501 -0
- data/resource_automations/select_application.rb +16 -0
- data/resource_automations/select_application.txt +5 -0
- data/resource_automations/select_environment.rb +14 -0
- data/resource_automations/select_environment.txt +5 -0
- data/resource_automations/select_request_template.rb +16 -0
- data/resource_automations/select_request_template.txt +5 -0
- data/resource_automations/select_step_in_request.rb +33 -0
- data/resource_automations/select_step_in_request.txt +5 -0
- data/tests/create_release_request_spec.rb +66 -0
- data/tests/create_request_spec.rb +84 -0
- data/tests/select_application_version_spec.rb +47 -0
- data/tests/spec_helper.rb +71 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2ZhNDlhYmE2YzVmNTUwZjM1MTI5NjJmNzg3NTVmNWVjY2MyYmZmMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjFlZGFkYTY0MGRjOTJkZGY5ODZiZWQ3MzgwNTUwZDEzMTY5MjU2Zg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDJjYTk1N2RjMDM3ODFiNmFjZTBkMzUxOTlhYzVjNDBiNDNlZWYwMWQwNjk5
|
10
|
+
NjY4ZTcxYjE3NGE0MmUxNTEzYzQ5Y2Y0NDRmMDQ4ODE3ZjZiYjhmMjI0MGRi
|
11
|
+
Mzg3NTY4MGMwYjhjM2Y5ZWQ2YTc1NWM5YjIwNzU3MjhiM2ZmZGQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YmQyOWExMWU5OTM5OWU5ZTlkOWE3MGJjMWYyMmFjMWQ0Y2E1ZGE5NTY0OTg4
|
14
|
+
ZjA5NjkyYzg2ODhkYjA3YjQ5YTIwODg3NmVmMzU0YjRkMjlkYmMyZWY4ZWQ5
|
15
|
+
MWUxYTJkMTBhM2NlNjc4NjdhYWY2NjM0Mjc1NDNiZjc1ZmUxYWE=
|
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
Gemfile.lock
|
30
|
+
.ruby-gemset
|
31
|
+
|
32
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
33
|
+
.rvmrc
|
34
|
+
|
35
|
+
.DS_Store
|
36
|
+
|
37
|
+
.idea
|
38
|
+
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p392
|
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
before_install:
|
4
|
+
- gem update --system 2.1.9
|
5
|
+
|
6
|
+
bundler_args: '' #remove the --deployment flag that causes the gems to be installed in .../1.9.1/...
|
7
|
+
|
8
|
+
script:
|
9
|
+
- rspec tests --format documentation --color
|
10
|
+
|
11
|
+
notifications:
|
12
|
+
email:
|
13
|
+
- niek.bartholomeus@gmail.com
|
14
|
+
|
15
|
+
branches:
|
16
|
+
except:
|
17
|
+
- /^v[0-9.]*/
|
18
|
+
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 BMC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# BRPM module for BRPM
|
2
|
+
|
3
|
+
[](https://travis-ci.org/BMC-RLM/brpm_module_brpm)
|
4
|
+
|
5
|
+
[](http://badge.fury.io/rb/brpm_module_brpm)
|
6
|
+
|
7
|
+
This repository represents an external module for BRPM, to be used on top of the [BRPM content repository](https://github.com/BMC-RLM/brpm_content)
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copied from https://github.com/mitchellh/vagrant-aws/blob/master/Rakefile
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
# Immediately sync all stdout so that tools like buildbot can
|
7
|
+
# immediately load in the output.
|
8
|
+
$stdout.sync = true
|
9
|
+
$stderr.sync = true
|
10
|
+
|
11
|
+
# Change to the directory of this file.
|
12
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
13
|
+
|
14
|
+
# This installs the tasks that help with gem creation and
|
15
|
+
# publishing.
|
16
|
+
Bundler::GemHelper.install_tasks
|
17
|
+
|
18
|
+
# Install the `spec` task so that we can run tests.
|
19
|
+
RSpec::Core::RakeTask.new do |task|
|
20
|
+
task.pattern = "tests/**/*_spec.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Default task is to run the unit tests
|
24
|
+
task :default => "spec"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simple_xlsx_reader'
|
2
|
+
|
3
|
+
brpm_rest_client = BrpmRestClient.new
|
4
|
+
params = BrpmAuto.params
|
5
|
+
|
6
|
+
doc = SimpleXlsxReader.open(params["step_attachment_0"])
|
7
|
+
BrpmAuto.log doc.sheets.first.rows.inspect
|
8
|
+
|
9
|
+
plan = nil
|
10
|
+
env_name = nil
|
11
|
+
stage_name = nil
|
12
|
+
sub_stage_name = nil
|
13
|
+
app_name = nil
|
14
|
+
request = nil
|
15
|
+
|
16
|
+
doc.sheets.first.rows.each do |row|
|
17
|
+
if !row[0].nil?
|
18
|
+
BrpmAuto.log "Creating a new plan from template 'My Release Plan' for release #{row[0]} ..."
|
19
|
+
plan = brpm_rest_client.create_plan("My Release Plan", row[0], Time.now)
|
20
|
+
elsif !row[1].nil?
|
21
|
+
env_name = row[1].downcase
|
22
|
+
stage_name = row[1]
|
23
|
+
elsif !row[2].nil?
|
24
|
+
sub_stage_name = row[2]
|
25
|
+
elsif !row[3].nil?
|
26
|
+
app_name = row[3]
|
27
|
+
elsif !row[4].nil?
|
28
|
+
BrpmAuto.log "Creating a new request '#{row[4]}' for plan '#{plan["name"]}', stage '#{stage_name} - #{sub_stage_name}' and app '#{app_name}' ..."
|
29
|
+
request = brpm_rest_client.create_request_for_plan(plan["id"], "#{stage_name} - #{sub_stage_name}", row[4], 1, app_name, env_name, false)
|
30
|
+
elsif !row[5].nil?
|
31
|
+
BrpmAuto.log "Creating a new step '#{row[5]}' for request '#{request["name"]}' ..."
|
32
|
+
brpm_rest_client.create_step(request["id"], row[5], "User", 1)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
params["direct_execute"] = "true"
|
2
|
+
|
3
|
+
require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
|
4
|
+
|
5
|
+
BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_brpm", "create_release_from_excel", params)
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# TODO workaround bug fix where the request params are not transferred to the updated application's directory
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
brpm_rest_client = BrpmRestClient.new
|
5
|
+
|
6
|
+
BrpmAuto.log "Retrieving the application..."
|
7
|
+
application = brpm_rest_client.get_app_by_name(BrpmAuto.params["application_name"])
|
8
|
+
application_version = BrpmAuto.params["application_version"]
|
9
|
+
|
10
|
+
release_request_template_name = BrpmAuto.params["release_request_template_name"] || "Release application"
|
11
|
+
release_plan_template_name = BrpmAuto.params["release_plan_template_name"]
|
12
|
+
release_plan_name = BrpmAuto.params["release_plan_name"]
|
13
|
+
|
14
|
+
request_name = "Release #{application["name"]} #{application_version}"
|
15
|
+
|
16
|
+
request_params = {}
|
17
|
+
request_params["auto_created"] = true
|
18
|
+
request_params["application_version"] = application_version
|
19
|
+
request_params["component_versions"] = {}
|
20
|
+
request_params["component_versions"]["EF - .NET web front end"] = BrpmAuto.params["ef_net_version"]
|
21
|
+
request_params["component_versions"]["EF - Java calculation engine"] = BrpmAuto.params["ef_java_version"]
|
22
|
+
|
23
|
+
if release_plan_template_name or release_plan_name
|
24
|
+
if release_plan_template_name
|
25
|
+
BrpmAuto.log "Creating a new plan from template '#{release_plan_template_name}' for #{application["name"]} v#{application_version} ..."
|
26
|
+
plan = brpm_rest_client.create_plan(release_plan_template_name, "Release #{BrpmAuto.params["application_name"]} v#{application_version}", Time.now)
|
27
|
+
|
28
|
+
BrpmAuto.log "Planning the plan ..."
|
29
|
+
brpm_rest_client.plan_plan(plan["id"])
|
30
|
+
|
31
|
+
BrpmAuto.log "Starting the plan ..."
|
32
|
+
brpm_rest_client.start_plan(plan["id"])
|
33
|
+
elsif release_plan_name
|
34
|
+
plan = brpm_rest_client.get_plan_by_name(release_plan_name)
|
35
|
+
raise "Release plan '#{release_plan_name}' doesn't exist." unless plan
|
36
|
+
end
|
37
|
+
|
38
|
+
BrpmAuto.log "Creating a new request '#{request_name}' from template '#{release_request_template_name}' for application '#{application["name"]}' and plan #{plan["name"]}..."
|
39
|
+
target_request = brpm_rest_client.create_request_for_plan_from_template(
|
40
|
+
plan["id"],
|
41
|
+
"Release",
|
42
|
+
release_request_template_name,
|
43
|
+
request_name,
|
44
|
+
"release",
|
45
|
+
false, # execute_now
|
46
|
+
request_params
|
47
|
+
)
|
48
|
+
|
49
|
+
else
|
50
|
+
BrpmAuto.log "Creating a new request '#{request_name}' from template '#{release_request_template_name}' for application '#{application["name"]}'..."
|
51
|
+
target_request = brpm_rest_client.create_request(
|
52
|
+
release_request_template_name,
|
53
|
+
request_name,
|
54
|
+
"release",
|
55
|
+
false, # execute_now
|
56
|
+
request_params
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
unless target_request["apps"].first["id"] == application["id"]
|
61
|
+
BrpmAuto.log "The application from the template is different than the application we want to use so updating the request with the correct application..."
|
62
|
+
request = {}
|
63
|
+
request["id"] = target_request["id"]
|
64
|
+
request["app_ids"] = [application["id"]]
|
65
|
+
target_request = brpm_rest_client.update_request_from_hash(request)
|
66
|
+
|
67
|
+
# TODO workaround bug fix where the request params are not transferred to the updated application's directory
|
68
|
+
Dir.mkdir "#{BrpmAuto.params.automation_results_dir}/request/#{application["name"]}/#{1000 + target_request["id"].to_i}"
|
69
|
+
json = FileUtils.mv("#{BrpmAuto.params.automation_results_dir}/request/#{target_request["apps"].first["name"]}/#{1000 + target_request["id"].to_i}/request_data.json", "#{BrpmAuto.params.automation_results_dir}/request/#{application["name"]}/#{1000 + target_request["id"].to_i}/request_data.json")
|
70
|
+
|
71
|
+
BrpmAuto.log "Setting the owner of the manual steps to the groups that belong to application '#{application["name"]}'..."
|
72
|
+
target_request["steps"].select{ |step| step["manual"] }.each do |step|
|
73
|
+
BrpmAuto.log "Retrieving the details of step #{step["id"]} '#{step["name"]}'..."
|
74
|
+
step_details = brpm_rest_client.get_step_by_id(step["id"])
|
75
|
+
|
76
|
+
next if step_details["procedure"]
|
77
|
+
|
78
|
+
group_name = "#{step_details["owner"]["name"]} - #{application["name"]}"
|
79
|
+
|
80
|
+
BrpmAuto.log "Retrieving group #{group_name}..."
|
81
|
+
group = brpm_rest_client.get_group_by_name(group_name)
|
82
|
+
raise "Group '#{group_name}' doesn't exist" if group.nil?
|
83
|
+
|
84
|
+
step_to_update = {}
|
85
|
+
step_to_update["id"] = step["id"]
|
86
|
+
step_to_update["owner_id"] = group["id"]
|
87
|
+
step_to_update["owner_type"] = "Group"
|
88
|
+
brpm_rest_client.update_step_from_hash step_to_update
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
BrpmAuto.log "Planning the request ... "
|
93
|
+
brpm_rest_client.plan_request(target_request["id"])
|
94
|
+
|
95
|
+
BrpmAuto.log "Starting the request ... "
|
96
|
+
brpm_rest_client.start_request(target_request["id"])
|
97
|
+
|
98
|
+
BrpmAuto.params["result"] = {}
|
99
|
+
BrpmAuto.params["result"]["request_id"] = target_request["id"]
|
100
|
+
|
@@ -0,0 +1,5 @@
|
|
1
|
+
params["direct_execute"] = "true"
|
2
|
+
|
3
|
+
require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
|
4
|
+
|
5
|
+
BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_brpm", "create_release_request", params)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
brpm_rest_client = BrpmRestClient.new
|
2
|
+
params = BrpmAuto.params
|
3
|
+
request_params = BrpmAuto.request_params
|
4
|
+
|
5
|
+
BrpmAuto.log "Retrieving the application..."
|
6
|
+
application = brpm_rest_client.get_app_by_name(params["application"])
|
7
|
+
application_version = request_params["application_version"] || ""
|
8
|
+
|
9
|
+
BrpmAuto.log "Retrieving the environment..."
|
10
|
+
target_environment = brpm_rest_client.get_environment_by_id(params["target_environment_id"])
|
11
|
+
|
12
|
+
if request_params.has_key? "request_template_id"
|
13
|
+
request_template_id = request_params["request_template_id"]
|
14
|
+
request_template_name = nil
|
15
|
+
else
|
16
|
+
request_template_id = nil
|
17
|
+
request_template_name = "Deploy #{application["name"]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
BrpmAuto.log "Creating request 'Deploy #{application["name"]} #{application_version}' from template '#{request_template_id || request_template_name}' for application '#{application["name"]}' and environment '#{target_environment["name"]}'..."
|
21
|
+
request = {}
|
22
|
+
request["request_template_id"] = request_template_id
|
23
|
+
request["template_name"] = request_template_name
|
24
|
+
request["name"] = "Deploy #{application["name"]} #{application_version}"
|
25
|
+
request["environment"] = target_environment["name"]
|
26
|
+
request["execute_now"] = false
|
27
|
+
request["app_ids"] = [ application["id"] ]
|
28
|
+
|
29
|
+
if params.request_plan_id and ! params.request_plan_id.empty? and params["target_stage"] and ! params["target_stage"].empty?
|
30
|
+
plan_stage_id = brpm_rest_client.get_plan_stage_id(params.request_plan_id, params["target_stage"])
|
31
|
+
request["plan_member_attributes"] = { "plan_id" => params.request_plan_id, "plan_stage_id" => plan_stage_id }
|
32
|
+
end
|
33
|
+
|
34
|
+
target_request = brpm_rest_client.create_request_from_hash(request)
|
35
|
+
|
36
|
+
unless target_request["apps"].first["id"] == application["id"]
|
37
|
+
BrpmAuto.log "The application from the template is different than the application we want to use so updating the request with the correct application..."
|
38
|
+
request = {}
|
39
|
+
request["id"] = target_request["id"]
|
40
|
+
request["app_ids"] = [application["id"]]
|
41
|
+
target_request = brpm_rest_client.update_request_from_hash(request)
|
42
|
+
end
|
43
|
+
|
44
|
+
if request_params.has_key?"component_versions"
|
45
|
+
BrpmAuto.log "Component versions found in the request params so setting the version number of the components... "
|
46
|
+
request_params["component_versions"].each do |component_name, component_version|
|
47
|
+
BrpmAuto.log "Setting the version of component '#{component_name}' to '#{component_version}'... "
|
48
|
+
brpm_rest_client.set_version_tag_of_steps_for_component(target_request, component_name, component_version)
|
49
|
+
end
|
50
|
+
elsif ! application_version.empty?
|
51
|
+
BrpmAuto.log "Application version found so setting the version number of all components to #{application_version}... "
|
52
|
+
application["components"].each do |component|
|
53
|
+
brpm_rest_client.set_version_tag_of_steps_for_component(target_request, component["name"], application_version)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if params["execute_target_request"].downcase.include?("execute")
|
58
|
+
BrpmAuto.log "Planning the request ... "
|
59
|
+
brpm_rest_client.plan_request(target_request["id"])
|
60
|
+
|
61
|
+
BrpmAuto.log "Starting the request ... "
|
62
|
+
brpm_rest_client.start_request(target_request["id"])
|
63
|
+
end
|
64
|
+
|
65
|
+
if params["execute_target_request"].downcase.include?("monitor")
|
66
|
+
BrpmAuto.log "Waiting until the request has finished ..."
|
67
|
+
brpm_rest_client.monitor_request(target_request["id"])
|
68
|
+
end
|
69
|
+
|
70
|
+
BrpmAuto.log "Adding the created request' id to the request_params ..."
|
71
|
+
request_params["target_request_id"] = target_request["id"]
|
72
|
+
|
73
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
###
|
2
|
+
# target_environment_id:
|
3
|
+
# name: Target environment
|
4
|
+
# required: yes
|
5
|
+
# position: A1:C1
|
6
|
+
# type: in-external-single-select
|
7
|
+
# external_resource: select_environment
|
8
|
+
# target_stage:
|
9
|
+
# name: Target stage
|
10
|
+
# required: no
|
11
|
+
# position: A2:C2
|
12
|
+
# execute_target_request:
|
13
|
+
# name: execute_target_request
|
14
|
+
# required: yes
|
15
|
+
# type: in-list-single
|
16
|
+
# list_pairs: 1,No|2,Execute|3,Execute and monitor
|
17
|
+
# position: A3:C3
|
18
|
+
###
|
19
|
+
params["direct_execute"] = "true"
|
20
|
+
|
21
|
+
require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
|
22
|
+
|
23
|
+
BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_brpm", "create_request", params)
|
@@ -0,0 +1,197 @@
|
|
1
|
+
def get_source_requests(params)
|
2
|
+
brpm_rest_client = BrpmRestClient.new
|
3
|
+
|
4
|
+
source_request_ids = brpm_rest_client.get_requests_by_plan_id_and_stage_name_and_app_name(params["request_plan_id"], params["source_stage"], params["application"])
|
5
|
+
|
6
|
+
raise "No requests found for application '#{params["application"]}' in stage '#{params["source_stage"]}' of this plan" if source_request_ids.count == 0
|
7
|
+
|
8
|
+
source_requests = source_request_ids.map { |source_request_id| brpm_rest_client.get_request_by_id(source_request_id) }
|
9
|
+
.sort_by { |request| request["created_at"] }
|
10
|
+
|
11
|
+
source_requests
|
12
|
+
end
|
13
|
+
|
14
|
+
def step_has_incremental_deployment(correction_source_step, source_steps_with_same_name)
|
15
|
+
brpm_rest_client = BrpmRestClient.new
|
16
|
+
|
17
|
+
incremental_deployment = false
|
18
|
+
if source_steps_with_same_name.count > 1
|
19
|
+
BrpmAuto.log "Already multiple steps with the same name, this means that it is a step that has a component with incremental deploy."
|
20
|
+
incremental_deployment = true
|
21
|
+
else
|
22
|
+
if !source_steps_with_same_name.first["component"].nil? and !correction_source_step["component"].nil?
|
23
|
+
if source_steps_with_same_name.first["component"]["id"] == correction_source_step["component"]["id"]
|
24
|
+
if !source_steps_with_same_name.first["version_tag"].nil? and !correction_source_step["version_tag"].nil?
|
25
|
+
BrpmAuto.log "Verifying if the associated component '#{correction_source_step["component"]["name"]}' uses incremental deployment ..."
|
26
|
+
component = brpm_rest_client.get_component_by_id(correction_source_step["component"]["id"])
|
27
|
+
incremental_deployment = (component.has_key?("properties") and component["properties"].any? { |property| property["name"] == "incremental_deployment" })
|
28
|
+
|
29
|
+
if incremental_deployment and source_steps_with_same_name.first["version_tag"]["name"] == correction_source_step["version_tag"]["name"]
|
30
|
+
raise "This component has incremental deployment and there already exists a step with the same component and version number."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
incremental_deployment
|
38
|
+
end
|
39
|
+
|
40
|
+
def merge_source_request_steps(source_requests)
|
41
|
+
brpm_rest_client = BrpmRestClient.new
|
42
|
+
|
43
|
+
BrpmAuto.log "Getting the step details of the initial request ..."
|
44
|
+
source_steps = source_requests.first["steps"].map { |source_step_summary| brpm_rest_client.get_step_by_id(source_step_summary["id"]) }
|
45
|
+
.sort_by { |step| step["number"].to_f }
|
46
|
+
|
47
|
+
#TODO: use work tasks to find the first post-deploy step
|
48
|
+
post_deploy_step = source_steps.find { |step| step["name"] == "Post-deploy" }
|
49
|
+
|
50
|
+
BrpmAuto.log "Merging the correction requests with the original request ..."
|
51
|
+
source_requests[1..source_requests.count].each do |source_request|
|
52
|
+
BrpmAuto.log "Merging the steps from correction request #{source_request["id"]} - #{source_request["name"] || "<no name>"} (#{source_request["steps"].count} steps)"
|
53
|
+
source_request["steps"].sort_by { |step| step["number"].to_f }.each do |correction_source_step_summary|
|
54
|
+
correction_source_step = brpm_rest_client.get_step_by_id(correction_source_step_summary["id"])
|
55
|
+
BrpmAuto.log "Merging step '#{correction_source_step["name"]}' ..."
|
56
|
+
|
57
|
+
source_steps_with_same_name = source_steps.find_all { |source_step| source_step["name"] == correction_source_step["name"] }
|
58
|
+
|
59
|
+
if source_steps_with_same_name.count == 0
|
60
|
+
BrpmAuto.log "No steps yet with the same name, so adding this step to the list ..."
|
61
|
+
index = source_steps.index(post_deploy_step)
|
62
|
+
source_steps.insert(index, correction_source_step)
|
63
|
+
next
|
64
|
+
end
|
65
|
+
|
66
|
+
BrpmAuto.log "Verifying if the step has a component with incremental deployment ..."
|
67
|
+
incremental_deployment = step_has_incremental_deployment(correction_source_step, source_steps_with_same_name)
|
68
|
+
|
69
|
+
if incremental_deployment
|
70
|
+
BrpmAuto.log "This step has a component with incremental deployment so adding it to the list ..."
|
71
|
+
index = source_steps.index(source_steps_with_same_name.last)
|
72
|
+
source_steps.insert(index + 1, correction_source_step)
|
73
|
+
else
|
74
|
+
BrpmAuto.log "Replacing the original step with this one in the list ..."
|
75
|
+
index = source_steps.index(source_steps_with_same_name.first)
|
76
|
+
source_steps[index] = correction_source_step
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
source_steps
|
82
|
+
end
|
83
|
+
|
84
|
+
def create_target_request(initial_source_request, source_steps, params)
|
85
|
+
brpm_rest_client = BrpmRestClient.new
|
86
|
+
|
87
|
+
target_request = {}
|
88
|
+
target_request["name"] = params["request_name"].sub("Release", "Deploy")
|
89
|
+
target_request["description"] = initial_source_request["description"]
|
90
|
+
target_request["estimate"] = initial_source_request["estimate"]
|
91
|
+
target_request["owner_id"] = initial_source_request["owner"]["id"]
|
92
|
+
target_request["requestor_id"] = initial_source_request["requestor"]["id"]
|
93
|
+
target_request["deployment_coordinator_id"] = initial_source_request["deployment_coordinator"]["id"]
|
94
|
+
target_request["app_ids"] = initial_source_request["apps"][0]["id"]
|
95
|
+
|
96
|
+
plan_stage_id = brpm_rest_client.get_plan_stage_id(params["request_plan_id"], params["target_stage"])
|
97
|
+
target_request["plan_member_attributes"] = { "plan_id" => params["request_plan_id"], "plan_stage_id" => plan_stage_id }
|
98
|
+
target_request["environment"] = params["target_env"]
|
99
|
+
target_request["execute_now"] = (params["execute_target_request"] == 'Yes') #TODO: doesn't work - maybe try starting it explicitly after creation
|
100
|
+
|
101
|
+
BrpmAuto.log "Creating the target request ..."
|
102
|
+
target_request = brpm_rest_client.create_request_from_hash(target_request)
|
103
|
+
|
104
|
+
BrpmAuto.log "Creating the target steps ..."
|
105
|
+
procedure_mapping = {}
|
106
|
+
source_steps.each do |source_step|
|
107
|
+
BrpmAuto.log "Creating target step for step #{source_step["name"]} ..."
|
108
|
+
|
109
|
+
target_step = {}
|
110
|
+
if source_step["procedure"]
|
111
|
+
#TODO doesnt work yet
|
112
|
+
target_step["parent_id"] = procedure_mapping[source_step["parent_id"]]
|
113
|
+
end
|
114
|
+
target_step["request_id"] = target_request["id"]
|
115
|
+
target_step["name"] = source_step["name"]
|
116
|
+
target_step["description"] = source_step["description"]
|
117
|
+
target_step["owner_type"] = source_step["owner_type"]
|
118
|
+
target_step["owner_id"] = source_step["owner"]["id"] unless source_step["owner"].nil?
|
119
|
+
target_step["manual"] = source_step["manual"]
|
120
|
+
target_step["script_id"] = source_step["script"]["id"] unless source_step["script"].nil?
|
121
|
+
target_step["script_type"] = source_step["script_type"]
|
122
|
+
target_step["procedure"] = source_step["procedure"]
|
123
|
+
|
124
|
+
unless source_step["installed_component"].nil?
|
125
|
+
installed_components = brpm_rest_client.get_installed_components_by({ "app_name" => source_step["installed_component"]["app"]["name"],
|
126
|
+
"component_name" => source_step["installed_component"]["component"]["name"],
|
127
|
+
"environment_name" => params["target_env"] })
|
128
|
+
|
129
|
+
raise "No installed component found for app '#{source_step["installed_component"]["app"]["name"]}', component '#{source_step["installed_component"]["component"]["name"]}' and environment '#{source_step["installed_component"]["environment"]["name"]}'" if installed_components.count == 0
|
130
|
+
|
131
|
+
target_step["installed_component_id"] = installed_components[0]["id"]
|
132
|
+
|
133
|
+
unless source_step["version_tag"].nil?
|
134
|
+
version_tags = brpm_rest_client.get_version_tags_by({ "name" => source_step["version_tag"]["name"],
|
135
|
+
"app_name" => source_step["installed_component"]["app"]["name"],
|
136
|
+
"component_name" => source_step["installed_component"]["component"]["name"],
|
137
|
+
"environment_name" => params["target_env"] })
|
138
|
+
|
139
|
+
raise "No version tag found for app '#{source_step["installed_component"]["app"]["name"]}', component '#{source_step["installed_component"]["component"]["name"]}', environment '#{params["target_env"]}' and version '#{source_step["version_tag"]["name"]}'" if version_tags.count == 0
|
140
|
+
|
141
|
+
target_step["version_tag_id"] = version_tags[0]["id"]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
target_step["component_id"] = source_step["component"]["id"] unless source_step["component"].nil?
|
146
|
+
|
147
|
+
target_step["own_version"] = source_step["own_version"]
|
148
|
+
target_step["component_version"] = source_step["component_version"]
|
149
|
+
target_step["custom_ticket_id"] = source_step["custom_ticket_id"]
|
150
|
+
target_step["release_content_item_id"] = source_step["release_content_item_id"]
|
151
|
+
target_step["on_plan"] = source_step["on_plan"]
|
152
|
+
target_step["should_execute"] = source_step["should_execute"]
|
153
|
+
target_step["execute_anytime"] = source_step["execute_anytime"]
|
154
|
+
target_step["start_by"] = source_step["start_by"]
|
155
|
+
target_step["location_detail"] = source_step["location_detail"]
|
156
|
+
target_step["estimate"] = source_step["estimate"]
|
157
|
+
target_step["different_level_from_previous"] = source_step["different_level_from_previous"]
|
158
|
+
target_step["phase_id"] = source_step["phase"]["id"] unless source_step["phase"].nil?
|
159
|
+
target_step["runtime_phase_id"] = source_step["runtime_phase"]["id"] unless source_step["runtime_phase"].nil?
|
160
|
+
|
161
|
+
target_step = brpm_rest_client.create_step_from_hash(target_step)
|
162
|
+
|
163
|
+
BrpmAuto.log "Created target step for step #{source_step["name"]} (#{target_step["position"]})."
|
164
|
+
|
165
|
+
procedure_mapping[source_step["id"]] = target_step["id"] if source_step["procedure"]
|
166
|
+
end
|
167
|
+
|
168
|
+
target_request
|
169
|
+
end
|
170
|
+
|
171
|
+
brpm_rest_client = BrpmRestClient.new
|
172
|
+
params = BrpmAuto.params
|
173
|
+
|
174
|
+
BrpmAuto.log "Getting the source requests ..."
|
175
|
+
source_requests = brpm_rest_client.get_source_requests(params)
|
176
|
+
|
177
|
+
if params["request_template"].nil? || params["request_template"].empty?
|
178
|
+
initial_source_request = source_requests.first
|
179
|
+
BrpmAuto.log "Found initial source request #{initial_source_request["id"]} - #{initial_source_request["name"] || "<no name>"}"
|
180
|
+
|
181
|
+
BrpmAuto.log "Merging the source request steps ..."
|
182
|
+
source_steps = merge_source_request_steps(source_requests)
|
183
|
+
|
184
|
+
BrpmAuto.log "Creating the target request ..."
|
185
|
+
target_request = create_target_request(initial_source_request, source_steps, params)
|
186
|
+
else
|
187
|
+
target_request = brpm_rest_client.create_request_for_plan_from_template(params["request_plan_id"], params["target_stage"], params["request_template"], params["request_name"].sub("Release", "Deploy"), params["target_env"], (params["execute_target_request"] == 'Yes'))
|
188
|
+
end
|
189
|
+
|
190
|
+
BrpmAuto.log "Moving the source requests to the stage '#{params["source_stage"]} - Archived' ..."
|
191
|
+
source_requests.each do |source_request|
|
192
|
+
brpm_rest_client.move_request_to_plan_and_stage(source_request["id"], params["request_plan_id"], "#{params["source_stage"]} - Archived")
|
193
|
+
end
|
194
|
+
|
195
|
+
BrpmAuto.log "Adding the promoted request' id to the request_params ..."
|
196
|
+
BrpmAuto.request_params["promoted_request_id"] = target_request["id"]
|
197
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
###
|
2
|
+
# request_template:
|
3
|
+
# name: request_template
|
4
|
+
# required: no
|
5
|
+
# source_stage:
|
6
|
+
# name: source_stage
|
7
|
+
# required: yes
|
8
|
+
# target_stage:
|
9
|
+
# name: target_stage
|
10
|
+
# required: yes
|
11
|
+
# target_env:
|
12
|
+
# name: target_env
|
13
|
+
# required: yes
|
14
|
+
# execute_target_request:
|
15
|
+
# name: execute_target_request
|
16
|
+
# required: yes
|
17
|
+
# type: in-list-single
|
18
|
+
# list_pairs: true,Yes|false,No
|
19
|
+
###
|
20
|
+
params["direct_execute"] = "true"
|
21
|
+
|
22
|
+
require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
|
23
|
+
|
24
|
+
BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_brpm", "promote_request", params)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
brpm_rest_client = BrpmRestClient.new
|
2
|
+
|
3
|
+
if BrpmAuto.request_params["auto_created"]
|
4
|
+
BrpmAuto.log "The request was created in an automated way, not overriding the request params from the manual input step."
|
5
|
+
application_version = BrpmAuto.request_params["application_version"]
|
6
|
+
else
|
7
|
+
BrpmAuto.log "Storing the input parameters ..."
|
8
|
+
BrpmAuto.request_params["application_version"] = BrpmAuto.params["application_version"]
|
9
|
+
|
10
|
+
application_version = BrpmAuto.params["application_version"]
|
11
|
+
end
|
12
|
+
|
13
|
+
BrpmAuto.log "Creating version tags for all components..."
|
14
|
+
application = brpm_rest_client.get_app_by_name(BrpmAuto.params["application"])
|
15
|
+
|
16
|
+
application["components"].each do |component|
|
17
|
+
application["environments"].each do |environment|
|
18
|
+
brpm_rest_client.create_version_tag(application["name"], component["name"], environment["name"], application_version)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
###
|
2
|
+
# application_id:
|
3
|
+
# name: Application
|
4
|
+
# position: A1:C1
|
5
|
+
# type: in-external-single-select
|
6
|
+
# external_resource: select_application
|
7
|
+
# required: yes
|
8
|
+
# application_version:
|
9
|
+
# name: Version
|
10
|
+
# position: A2:B2
|
11
|
+
# required: yes
|
12
|
+
###
|
13
|
+
params["direct_execute"] = "true"
|
14
|
+
|
15
|
+
require "#{ENV["BRPM_CONTENT_HOME"] || "#{ENV["BRPM_HOME"]}/modules"}/gems/brpm_content-#{ENV["BRPM_CONTENT_VERSION"] || "latest"}/modules/framework/brpm_script_executor.rb"
|
16
|
+
|
17
|
+
BrpmScriptExecutor.execute_automation_script_from_gem("brpm_module_brpm", "select_application_version", params)
|