dtk-shell 0.10.0
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 +7 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +13 -0
- data/README.md +121 -0
- data/bin/dtk-execute +32 -0
- data/bin/dtk-run +92 -0
- data/bin/dtk-shell +31 -0
- data/dtk-shell.gemspec +50 -0
- data/lib/auxiliary.rb +61 -0
- data/lib/bundler_monkey_patch.rb +26 -0
- data/lib/client.rb +58 -0
- data/lib/command_helper.rb +33 -0
- data/lib/command_helpers/git_repo.rb +589 -0
- data/lib/command_helpers/git_repo/merge.rb +153 -0
- data/lib/command_helpers/jenkins_client.rb +106 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
- data/lib/command_helpers/service_importer.rb +251 -0
- data/lib/command_helpers/service_link.rb +33 -0
- data/lib/command_helpers/test_module_creator.rb +69 -0
- data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
- data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
- data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
- data/lib/commands.rb +57 -0
- data/lib/commands/common/thor/access_control.rb +133 -0
- data/lib/commands/common/thor/action_result_handler.rb +74 -0
- data/lib/commands/common/thor/assembly_template.rb +92 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
- data/lib/commands/common/thor/base_command_helper.rb +59 -0
- data/lib/commands/common/thor/clone.rb +82 -0
- data/lib/commands/common/thor/common.rb +88 -0
- data/lib/commands/common/thor/common_base.rb +49 -0
- data/lib/commands/common/thor/create_target.rb +70 -0
- data/lib/commands/common/thor/edit.rb +255 -0
- data/lib/commands/common/thor/inventory_parser.rb +98 -0
- data/lib/commands/common/thor/list_diffs.rb +128 -0
- data/lib/commands/common/thor/module.rb +1011 -0
- data/lib/commands/common/thor/module/import.rb +210 -0
- data/lib/commands/common/thor/node.rb +53 -0
- data/lib/commands/common/thor/poller.rb +65 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
- data/lib/commands/common/thor/pull_from_remote.rb +152 -0
- data/lib/commands/common/thor/puppet_forge.rb +72 -0
- data/lib/commands/common/thor/purge_clone.rb +101 -0
- data/lib/commands/common/thor/push_clone_changes.rb +162 -0
- data/lib/commands/common/thor/push_to_remote.rb +94 -0
- data/lib/commands/common/thor/remotes.rb +71 -0
- data/lib/commands/common/thor/reparse.rb +40 -0
- data/lib/commands/common/thor/set_required_attributes.rb +46 -0
- data/lib/commands/thor/account.rb +239 -0
- data/lib/commands/thor/assembly.rb +356 -0
- data/lib/commands/thor/attribute.rb +79 -0
- data/lib/commands/thor/component.rb +70 -0
- data/lib/commands/thor/component_module.rb +501 -0
- data/lib/commands/thor/component_template.rb +174 -0
- data/lib/commands/thor/dependency.rb +34 -0
- data/lib/commands/thor/developer.rb +144 -0
- data/lib/commands/thor/dtk.rb +152 -0
- data/lib/commands/thor/library.rb +125 -0
- data/lib/commands/thor/node.rb +504 -0
- data/lib/commands/thor/node_template.rb +94 -0
- data/lib/commands/thor/project.rb +34 -0
- data/lib/commands/thor/provider.rb +233 -0
- data/lib/commands/thor/remotes.rb +49 -0
- data/lib/commands/thor/service.rb +941 -0
- data/lib/commands/thor/service_module.rb +914 -0
- data/lib/commands/thor/state_change.rb +25 -0
- data/lib/commands/thor/target.rb +250 -0
- data/lib/commands/thor/task.rb +116 -0
- data/lib/commands/thor/test_module.rb +310 -0
- data/lib/commands/thor/utils.rb +21 -0
- data/lib/commands/thor/workspace.rb +685 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +20 -0
- data/lib/config/configuration.rb +99 -0
- data/lib/config/default.conf +16 -0
- data/lib/config/disk_cacher.rb +80 -0
- data/lib/configurator.rb +176 -0
- data/lib/context_router.rb +44 -0
- data/lib/core.rb +497 -0
- data/lib/domain/git_adapter.rb +412 -0
- data/lib/domain/git_error_handler.rb +64 -0
- data/lib/domain/response.rb +285 -0
- data/lib/domain/response/error_handler.rb +86 -0
- data/lib/dtk-shell/version.rb +20 -0
- data/lib/dtk_constants.rb +40 -0
- data/lib/dtk_error.rb +114 -0
- data/lib/dtk_logger.rb +126 -0
- data/lib/dtk_shell.rb +31 -0
- data/lib/error.rb +85 -0
- data/lib/execute.rb +29 -0
- data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
- data/lib/execute/command.rb +40 -0
- data/lib/execute/command/api_call.rb +60 -0
- data/lib/execute/command/api_call/map.rb +60 -0
- data/lib/execute/command/api_call/service.rb +91 -0
- data/lib/execute/command/api_call/translation_term.rb +119 -0
- data/lib/execute/command/rest_call.rb +37 -0
- data/lib/execute/command_processor.rb +30 -0
- data/lib/execute/command_processor/rest_call.rb +59 -0
- data/lib/execute/error_usage.rb +21 -0
- data/lib/execute/execute_context.rb +86 -0
- data/lib/execute/execute_context/result_store.rb +37 -0
- data/lib/execute/script.rb +64 -0
- data/lib/execute/script/add_tenant.rb +121 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +70 -0
- data/lib/parser/adapters/thor.rb +555 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
- data/lib/require_first.rb +104 -0
- data/lib/search_hash.rb +44 -0
- data/lib/shell.rb +261 -0
- data/lib/shell/context.rb +1065 -0
- data/lib/shell/context_aux.rb +46 -0
- data/lib/shell/domain/active_context.rb +186 -0
- data/lib/shell/domain/context_entity.rb +89 -0
- data/lib/shell/domain/context_params.rb +223 -0
- data/lib/shell/domain/override_tasks.rb +88 -0
- data/lib/shell/domain/shadow_entity.rb +76 -0
- data/lib/shell/header_shell.rb +44 -0
- data/lib/shell/help_monkey_patch.rb +283 -0
- data/lib/shell/interactive_wizard.rb +225 -0
- data/lib/shell/message_queue.rb +63 -0
- data/lib/shell/parse_monkey_patch.rb +39 -0
- data/lib/shell/status_monitor.rb +124 -0
- data/lib/task_status.rb +83 -0
- data/lib/task_status/refresh_mode.rb +77 -0
- data/lib/task_status/snapshot_mode.rb +28 -0
- data/lib/task_status/stream_mode.rb +48 -0
- data/lib/task_status/stream_mode/element.rb +101 -0
- data/lib/task_status/stream_mode/element/format.rb +101 -0
- data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
- data/lib/task_status/stream_mode/element/no_results.rb +26 -0
- data/lib/task_status/stream_mode/element/render.rb +59 -0
- data/lib/task_status/stream_mode/element/stage.rb +84 -0
- data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
- data/lib/task_status/stream_mode/element/task_end.rb +35 -0
- data/lib/task_status/stream_mode/element/task_start.rb +37 -0
- data/lib/util/common_util.rb +37 -0
- data/lib/util/console.rb +235 -0
- data/lib/util/dtk_puppet.rb +65 -0
- data/lib/util/module_util.rb +66 -0
- data/lib/util/os_util.rb +385 -0
- data/lib/util/permission_util.rb +31 -0
- data/lib/util/remote_dependency_util.rb +84 -0
- data/lib/util/ssh_util.rb +94 -0
- data/lib/view_processor.rb +129 -0
- data/lib/view_processor/augmented_simple_list.rb +44 -0
- data/lib/view_processor/hash_pretty_print.rb +123 -0
- data/lib/view_processor/simple_list.rb +156 -0
- data/lib/view_processor/table_print.rb +309 -0
- data/lib/violation.rb +86 -0
- data/lib/violation/attribute.rb +76 -0
- data/lib/violation/fix.rb +26 -0
- data/lib/violation/fix/result.rb +73 -0
- data/lib/violation/fix/result/error.rb +34 -0
- data/lib/violation/fix/set_attribute.rb +41 -0
- data/lib/violation/sub_classes.rb +60 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +35 -0
- data/puppet/templates/bash_profile.erb +2 -0
- data/puppet/templates/client.conf.erb +1 -0
- data/puppet/templates/dtkclient.erb +2 -0
- data/spec/component_module_spec.rb +34 -0
- data/spec/dependency_spec.rb +6 -0
- data/spec/dtk_shell_spec.rb +13 -0
- data/spec/dtk_spec.rb +33 -0
- data/spec/lib/spec_helper.rb +10 -0
- data/spec/lib/spec_thor.rb +108 -0
- data/spec/node_template_spec.rb +24 -0
- data/spec/project_spec.rb +6 -0
- data/spec/repo_spec.rb +7 -0
- data/spec/response_spec.rb +52 -0
- data/spec/service_module_spec.rb +38 -0
- data/spec/service_spec.rb +50 -0
- data/spec/state_change_spec.rb +7 -0
- data/spec/table_print_spec.rb +48 -0
- data/spec/target_spec.rb +57 -0
- data/spec/task_spec.rb +28 -0
- data/views/assembly/augmented_simple_list.rb +12 -0
- data/views/assembly_template/augmented_simple_list.rb +12 -0
- data/views/list_task/augmented_simple_list.rb +12 -0
- metadata +421 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module DTK; module Client; class CommandHelper
|
|
19
|
+
class GitRepo
|
|
20
|
+
class Merge
|
|
21
|
+
|
|
22
|
+
def initialize(repo, remote_branch_ref, opts = {})
|
|
23
|
+
@repo = repo
|
|
24
|
+
@remote_branch_ref = remote_branch_ref
|
|
25
|
+
@local_branch = repo.local_branch_name
|
|
26
|
+
|
|
27
|
+
# options
|
|
28
|
+
@opts_commit_sha = opts[:commit_sha]
|
|
29
|
+
@opts_force = opts[:force]
|
|
30
|
+
@opts_ignore_dependency_merge_conflict = opts[:ignore_dependency_merge_conflict]
|
|
31
|
+
@opts_full_module_name = opts[:full_module_name]
|
|
32
|
+
@opts_command = opts[:command]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.merge(repo, remote_branch_ref, opts = {})
|
|
36
|
+
new(repo, remote_branch_ref, opts).merge
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def merge
|
|
40
|
+
if @opts_force
|
|
41
|
+
merge_force()
|
|
42
|
+
else
|
|
43
|
+
# check if merge needed
|
|
44
|
+
merge_rel = merge_relationship()
|
|
45
|
+
case merge_rel
|
|
46
|
+
when :equal
|
|
47
|
+
response__no_diffs()
|
|
48
|
+
when :local_ahead, :branchpoint
|
|
49
|
+
merge_not_fast_forward(merge_rel)
|
|
50
|
+
when :local_behind
|
|
51
|
+
merge_simple()
|
|
52
|
+
else
|
|
53
|
+
raise Error.new("Unexpected merge_rel (#{merge_rel})")
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def merge_force
|
|
61
|
+
diffs = compute_diffs()
|
|
62
|
+
# TODO: should put in a commit message that merged from remote repo
|
|
63
|
+
@repo.merge_theirs(@remote_branch_ref)
|
|
64
|
+
response(diffs)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def merge_not_fast_forward(merge_rel)
|
|
68
|
+
if any_conflicts?
|
|
69
|
+
# @opts_ignore_dependency_merge_conflict means called indirectly
|
|
70
|
+
if @opts_ignore_dependency_merge_conflict
|
|
71
|
+
# TODO: hard-wired that dependency is a component module in message: 'component-module/..
|
|
72
|
+
custom_message = "Unable to do fast-forward merge. You can go to 'component-module/#{@opts_full_module_name}' and pull with --force option but all local changes will be lost."
|
|
73
|
+
response(compute_diffs, :custom_message => custom_message)
|
|
74
|
+
else
|
|
75
|
+
err_msg = 'Unable to do fast-forward merge. You can use --force'
|
|
76
|
+
err_msg << " on #{@opts_command}" if @opts_command
|
|
77
|
+
err_msg << ', but all local changes will be lost on target that is being pushed to.'
|
|
78
|
+
raise ErrorUsage.new(err_msg)
|
|
79
|
+
end
|
|
80
|
+
elsif merge_rel == :local_ahead
|
|
81
|
+
response__no_diffs(:custom_message => 'No op because local module is ahead')
|
|
82
|
+
else
|
|
83
|
+
merge_simple()
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def merge_simple
|
|
88
|
+
# see if any diffs between fetched remote and local branch
|
|
89
|
+
# this has be done after commit
|
|
90
|
+
diffs = compute_diffs()
|
|
91
|
+
return diffs unless diffs.any_diffs?()
|
|
92
|
+
|
|
93
|
+
safe_execute do
|
|
94
|
+
# TODO: should put in a commit message that merged from remote repo
|
|
95
|
+
@repo.merge(@remote_branch_ref)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
if commit_sha = @opts_commit_sha
|
|
99
|
+
if commit_sha != @repo.head_commit_sha()
|
|
100
|
+
raise Error.new("Git synchronization problem: expected local head to have sha (#{commit_sha})")
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
response(diffs)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def merge_relationship
|
|
108
|
+
@repo.merge_relationship(:remote_branch, @remote_branch_ref)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def any_conflicts?
|
|
112
|
+
# TODO: optimization is to combine this with mereg to have merge_if_no_conflics?
|
|
113
|
+
# and if no conflicts just commit and merge --no-commit
|
|
114
|
+
ret = nil
|
|
115
|
+
begin
|
|
116
|
+
@repo.command('merge',['--no-commit', @remote_branch_ref])
|
|
117
|
+
rescue ::Git::GitExecuteError
|
|
118
|
+
ret = true
|
|
119
|
+
ensure
|
|
120
|
+
safe_execute do
|
|
121
|
+
@repo.command('merge',['--abort'])
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
ret
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def response__no_diffs(opts_response = {})
|
|
128
|
+
response(diffs__no_diffs(), opts_response)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def response(diffs, opts_response = {})
|
|
132
|
+
{ :diffs => diffs, :commit_sha => @repo.head_commit_sha() }.merge(opts_response)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def diffs__no_diffs
|
|
136
|
+
GitRepo.diffs__no_diffs
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def compute_diffs
|
|
140
|
+
GitRepo.compute_diffs(@repo, @remote_branch_ref)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def safe_execute(&block)
|
|
144
|
+
begin
|
|
145
|
+
yield
|
|
146
|
+
rescue Exception
|
|
147
|
+
nil
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end; end; end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
# TODO: Marked for removal [Haris] - Do we need this?
|
|
19
|
+
require 'jenkins-client'
|
|
20
|
+
module DTK; module Client
|
|
21
|
+
class JenkinsClient
|
|
22
|
+
require File.expand_path('jenkins_client/config_xml', File.dirname(__FILE__))
|
|
23
|
+
|
|
24
|
+
def self.create_service_module_project(module_id,module_name,repo_url,branch)
|
|
25
|
+
jenkins_project_name = module_name
|
|
26
|
+
config_xml_contents = ConfigXML.generate_service_module_project(repo_url,module_id,branch)
|
|
27
|
+
connection().create_job(jenkins_project_name,config_xml_contents)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.create_service_module_project?(module_id,module_name,repo_url,branch)
|
|
31
|
+
jenkins_project_name = module_name
|
|
32
|
+
jobs = get_jobs()||[]
|
|
33
|
+
#no op if job exists already
|
|
34
|
+
unless jobs.find{|j|j["name"] == jenkins_project_name}
|
|
35
|
+
create_service_module_project(module_id,module_name,repo_url,branch)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.create_assembly_project(assembly_name,assembly_id)
|
|
40
|
+
jenkins_project_name = assembly_name.gsub(/::/,"-")
|
|
41
|
+
config_xml_contents = ConfigXML.generate_assembly_project(assembly_id)
|
|
42
|
+
connection().create_job(jenkins_project_name,config_xml_contents)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.create_assembly_project?(assembly_name,assembly_id)
|
|
46
|
+
jenkins_project_name = assembly_name.gsub(/::/,"-")
|
|
47
|
+
jobs = get_jobs()||[]
|
|
48
|
+
#no op if job exists already
|
|
49
|
+
unless jobs.find{|j|j["name"] == jenkins_project_name}
|
|
50
|
+
create_assembly_project(assembly_name,assembly_id)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.get_jobs()
|
|
55
|
+
connection().get_jobs()
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
def self.connection()
|
|
60
|
+
return @connection if @connection
|
|
61
|
+
#TODO: hardwired
|
|
62
|
+
connection_hash = {
|
|
63
|
+
:username => "rich",
|
|
64
|
+
:password => "test",
|
|
65
|
+
:url => "http://ec2-107-22-254-226.compute-1.amazonaws.com:8080"
|
|
66
|
+
}
|
|
67
|
+
@connection = Connection.new(connection_hash)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class Connection < Hash
|
|
71
|
+
def initialize(connection_hash)
|
|
72
|
+
super()
|
|
73
|
+
merge!(connection_hash)
|
|
74
|
+
set_connection()
|
|
75
|
+
end
|
|
76
|
+
def create_job(job_name,config_xml_contents)
|
|
77
|
+
::Jenkins::Client::Job.create(job_name, config_xml_contents)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def get_info()
|
|
81
|
+
get('api/json')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def get_jobs()
|
|
85
|
+
get_info()["jobs"]
|
|
86
|
+
end
|
|
87
|
+
private
|
|
88
|
+
#TODO: one issue with the jenkins-client adapter is that it a singleton and thus only allows connection under one user to one jenkins server
|
|
89
|
+
def set_connection()
|
|
90
|
+
::Jenkins::Client.configure do |c|
|
|
91
|
+
c.username = self[:username]
|
|
92
|
+
c.password = self[:password]
|
|
93
|
+
c.url = self[:url]
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def get(path)
|
|
98
|
+
faraday_response = ::Jenkins::Client.get(path)
|
|
99
|
+
unless [200].include?(faraday_response.status)
|
|
100
|
+
raise Error.new("Bad response from Jenkins (status = #{faraday_response.status.to_s})")
|
|
101
|
+
end
|
|
102
|
+
faraday_response.body
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end; end
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
#TODO: should haev separet file sfor each template
|
|
19
|
+
require 'erubis'
|
|
20
|
+
class DTK::Client::JenkinsClient
|
|
21
|
+
module ConfigXML
|
|
22
|
+
#TODO: this is not working now
|
|
23
|
+
def self.generate_service_module_project(repo_url,module_id,branch)
|
|
24
|
+
#TODO: not using branch argument
|
|
25
|
+
#TODO: did not put in module_id yet
|
|
26
|
+
template_bindings = {
|
|
27
|
+
:repo_url => repo_url
|
|
28
|
+
}
|
|
29
|
+
ConfigXMLTemplateServiceModule.result(template_bindings)
|
|
30
|
+
end
|
|
31
|
+
def self.generate_assembly_project(assembly_id)
|
|
32
|
+
#TODO: not using branch argument
|
|
33
|
+
#TODO: did not put in module_id yet
|
|
34
|
+
template_bindings = {
|
|
35
|
+
:assembly_id => assembly_id
|
|
36
|
+
}
|
|
37
|
+
ConfigXMLTemplateAssembly.result(template_bindings)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
ConfigXMLTemplateServiceModule = Erubis::Eruby.new <<eos
|
|
41
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
|
42
|
+
<project>
|
|
43
|
+
<actions/>
|
|
44
|
+
<description></description>
|
|
45
|
+
<keepDependencies>false</keepDependencies>
|
|
46
|
+
<properties>
|
|
47
|
+
<com.gmail.ikeike443.PlayAutoTestJobProperty/>
|
|
48
|
+
</properties>
|
|
49
|
+
<scm class="hudson.plugins.git.GitSCM">
|
|
50
|
+
<configVersion>2</configVersion>
|
|
51
|
+
<userRemoteConfigs>
|
|
52
|
+
<hudson.plugins.git.UserRemoteConfig>
|
|
53
|
+
<name></name>
|
|
54
|
+
<refspec></refspec>
|
|
55
|
+
<url><%= repo_url %></url>
|
|
56
|
+
</hudson.plugins.git.UserRemoteConfig>
|
|
57
|
+
</userRemoteConfigs>
|
|
58
|
+
<branches>
|
|
59
|
+
<hudson.plugins.git.BranchSpec>
|
|
60
|
+
<name>**</name>
|
|
61
|
+
</hudson.plugins.git.BranchSpec>
|
|
62
|
+
</branches>
|
|
63
|
+
<disableSubmodules>false</disableSubmodules>
|
|
64
|
+
<recursiveSubmodules>false</recursiveSubmodules>
|
|
65
|
+
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
|
|
66
|
+
<authorOrCommitter>false</authorOrCommitter>
|
|
67
|
+
<clean>false</clean>
|
|
68
|
+
<wipeOutWorkspace>false</wipeOutWorkspace>
|
|
69
|
+
<pruneBranches>false</pruneBranches>
|
|
70
|
+
<remotePoll>false</remotePoll>
|
|
71
|
+
<ignoreNotifyCommit>false</ignoreNotifyCommit>
|
|
72
|
+
<buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
|
|
73
|
+
<gitTool>Default</gitTool>
|
|
74
|
+
<submoduleCfg class="list"/>
|
|
75
|
+
<relativeTargetDir></relativeTargetDir>
|
|
76
|
+
<reference></reference>
|
|
77
|
+
<excludedRegions></excludedRegions>
|
|
78
|
+
<excludedUsers></excludedUsers>
|
|
79
|
+
<gitConfigName></gitConfigName>
|
|
80
|
+
<gitConfigEmail></gitConfigEmail>
|
|
81
|
+
<skipTag>false</skipTag>
|
|
82
|
+
<includedRegions></includedRegions>
|
|
83
|
+
<scmName></scmName>
|
|
84
|
+
</scm>
|
|
85
|
+
<canRoam>true</canRoam>
|
|
86
|
+
<disabled>false</disabled>
|
|
87
|
+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
|
88
|
+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
|
89
|
+
<triggers class="vector"/>
|
|
90
|
+
<concurrentBuild>false</concurrentBuild>
|
|
91
|
+
<builders>
|
|
92
|
+
<hudson.tasks.Shell>
|
|
93
|
+
<command>ruby /var/lib/jenkins/r8_e2e.rb</command>
|
|
94
|
+
</hudson.tasks.Shell>
|
|
95
|
+
</builders>
|
|
96
|
+
<publishers>
|
|
97
|
+
<hudson.plugins.emailext.ExtendedEmailPublisher>
|
|
98
|
+
<recipientList>$DEFAULT_RECIPIENTS</recipientList>
|
|
99
|
+
<configuredTriggers>
|
|
100
|
+
<hudson.plugins.emailext.plugins.trigger.FailureTrigger>
|
|
101
|
+
<email>
|
|
102
|
+
<recipientList></recipientList>
|
|
103
|
+
<subject>$PROJECT_DEFAULT_SUBJECT</subject>
|
|
104
|
+
<body>$PROJECT_DEFAULT_CONTENT</body>
|
|
105
|
+
<sendToDevelopers>true</sendToDevelopers>
|
|
106
|
+
<sendToRequester>false</sendToRequester>
|
|
107
|
+
<includeCulprits>false</includeCulprits>
|
|
108
|
+
<sendToRecipientList>true</sendToRecipientList>
|
|
109
|
+
</email>
|
|
110
|
+
</hudson.plugins.emailext.plugins.trigger.FailureTrigger>
|
|
111
|
+
<hudson.plugins.emailext.plugins.trigger.StillFailingTrigger>
|
|
112
|
+
<email>
|
|
113
|
+
<recipientList></recipientList>
|
|
114
|
+
<subject>$PROJECT_DEFAULT_SUBJECT</subject>
|
|
115
|
+
<body>$PROJECT_DEFAULT_CONTENT</body>
|
|
116
|
+
<sendToDevelopers>true</sendToDevelopers>
|
|
117
|
+
<sendToRequester>false</sendToRequester>
|
|
118
|
+
<includeCulprits>false</includeCulprits>
|
|
119
|
+
<sendToRecipientList>false</sendToRecipientList>
|
|
120
|
+
</email>
|
|
121
|
+
</hudson.plugins.emailext.plugins.trigger.StillFailingTrigger>
|
|
122
|
+
<hudson.plugins.emailext.plugins.trigger.FixedTrigger>
|
|
123
|
+
<email>
|
|
124
|
+
<recipientList></recipientList>
|
|
125
|
+
<subject>$PROJECT_DEFAULT_SUBJECT</subject>
|
|
126
|
+
<body>$PROJECT_DEFAULT_CONTENT</body>
|
|
127
|
+
<sendToDevelopers>true</sendToDevelopers>
|
|
128
|
+
<sendToRequester>false</sendToRequester>
|
|
129
|
+
<includeCulprits>false</includeCulprits>
|
|
130
|
+
<sendToRecipientList>true</sendToRecipientList>
|
|
131
|
+
</email>
|
|
132
|
+
</hudson.plugins.emailext.plugins.trigger.FixedTrigger>
|
|
133
|
+
</configuredTriggers>
|
|
134
|
+
<contentType>default</contentType>
|
|
135
|
+
<defaultSubject>$DEFAULT_SUBJECT</defaultSubject>
|
|
136
|
+
<defaultContent>${JELLY_SCRIPT,template="html"}</defaultContent>
|
|
137
|
+
<attachmentsPattern></attachmentsPattern>
|
|
138
|
+
</hudson.plugins.emailext.ExtendedEmailPublisher>
|
|
139
|
+
</publishers>
|
|
140
|
+
<buildWrappers/>
|
|
141
|
+
</project>
|
|
142
|
+
eos
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
ConfigXMLTemplateAssembly = Erubis::Eruby.new <<eos
|
|
146
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
|
147
|
+
<project>
|
|
148
|
+
<actions/>
|
|
149
|
+
<description></description>
|
|
150
|
+
<keepDependencies>false</keepDependencies>
|
|
151
|
+
<properties>
|
|
152
|
+
<com.gmail.ikeike443.PlayAutoTestJobProperty/>
|
|
153
|
+
</properties>
|
|
154
|
+
<scm class="hudson.scm.NullSCM"/>
|
|
155
|
+
<canRoam>true</canRoam>
|
|
156
|
+
<disabled>false</disabled>
|
|
157
|
+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
|
158
|
+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
|
159
|
+
<triggers class="vector"/>
|
|
160
|
+
<concurrentBuild>false</concurrentBuild>
|
|
161
|
+
<builders>
|
|
162
|
+
<hudson.tasks.Shell>
|
|
163
|
+
<command>#!/usr/bin/env ruby
|
|
164
|
+
|
|
165
|
+
require 'rubygems'
|
|
166
|
+
require 'rest_client'
|
|
167
|
+
require 'pp'
|
|
168
|
+
require 'json'
|
|
169
|
+
|
|
170
|
+
STDOUT.sync = true
|
|
171
|
+
|
|
172
|
+
ENDPOINT = 'http://ec2-54-247-191-95.eu-west-1.compute.amazonaws.com:7000'
|
|
173
|
+
ASSEMBLY_ID = '<%= assembly_id %>'
|
|
174
|
+
|
|
175
|
+
# controling 'pretty-print' in log file
|
|
176
|
+
JSON_OUTPUT_ENABLED = false
|
|
177
|
+
|
|
178
|
+
# Method for deleting assembly instances
|
|
179
|
+
def deleteAssembly(assemblyId)
|
|
180
|
+
responseAssemblyDelete = RestClient.post(ENDPOINT + '/rest/assembly/delete', 'assembly_id' => assemblyId)
|
|
181
|
+
puts "Assembly has been deleted! Response: #{responseAssemblyDelete}"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
#
|
|
185
|
+
# Method for pretty print of json responses
|
|
186
|
+
def json_print(json)
|
|
187
|
+
pp json if JSON_OUTPUT_ENABLED
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
pp "Script has been started!"
|
|
191
|
+
|
|
192
|
+
puts "Using template ID: #{ASSEMBLY_ID}"
|
|
193
|
+
|
|
194
|
+
# Stage the assembly
|
|
195
|
+
stageAssembly = RestClient.post(ENDPOINT + '/rest/assembly/stage', 'assembly_id' => ASSEMBLY_ID)
|
|
196
|
+
assemblyId = JSON.parse(stageAssembly)["data"]["assembly_id"]
|
|
197
|
+
|
|
198
|
+
puts "Using stage assembly ID: #{assemblyId}"
|
|
199
|
+
|
|
200
|
+
# Create a task for the cloned assembly instance
|
|
201
|
+
responseTask = RestClient.post(ENDPOINT + '/rest/assembly/create_task', 'assembly_id' => assemblyId)
|
|
202
|
+
# Extract task id
|
|
203
|
+
taskId = JSON.parse(responseTask)["data"]["task_id"]
|
|
204
|
+
# Execute the task
|
|
205
|
+
puts "Starting task id: #{taskId}"
|
|
206
|
+
responseTaskExecute = RestClient.post(ENDPOINT + '/rest/task/execute', 'task_id' => taskId)
|
|
207
|
+
|
|
208
|
+
taskStatus = 'executing'
|
|
209
|
+
|
|
210
|
+
while taskStatus.include? 'executing'
|
|
211
|
+
sleep 20
|
|
212
|
+
responseTaskStatus = RestClient.post(ENDPOINT + '/rest/task/status', 'task_id '=> taskId)
|
|
213
|
+
taskFullResponse = JSON.parse(responseTaskStatus)
|
|
214
|
+
taskStatus = taskFullResponse["data"]["status"]
|
|
215
|
+
puts "Task status: #{taskStatus}"
|
|
216
|
+
json_print JSON.parse(responseTaskStatus)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
if taskStatus.include? 'fail'
|
|
220
|
+
# Print error response from the service
|
|
221
|
+
puts "Smoke test failed, response: "
|
|
222
|
+
pp taskFullResponse
|
|
223
|
+
# Delete the cloned assembly's instance
|
|
224
|
+
deleteAssembly(assemblyId)
|
|
225
|
+
abort("Task with ID #{taskId} failed!")
|
|
226
|
+
else
|
|
227
|
+
puts "Task with ID #{taskId} success!"
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
#Create a task for the smoke test
|
|
232
|
+
responseSmokeTest = RestClient.post(ENDPOINT + '/rest/assembly/create_smoketests_task', 'assembly_id' => assemblyId)
|
|
233
|
+
json_print responseSmokeTest
|
|
234
|
+
|
|
235
|
+
#Extract task id
|
|
236
|
+
smokeTestId = JSON.parse(responseSmokeTest)["data"]["task_id"]
|
|
237
|
+
puts "Created smoke test task with ID: #{smokeTestId}"
|
|
238
|
+
#Execute the task
|
|
239
|
+
responseSmokeExecute = RestClient.post(ENDPOINT + '/rest/task/execute', 'task_id' => smokeTestId)
|
|
240
|
+
|
|
241
|
+
json_print JSON.parse(responseSmokeExecute)
|
|
242
|
+
|
|
243
|
+
puts "Starting smoke test task with ID: #{smokeTestId}"
|
|
244
|
+
|
|
245
|
+
smokeStatus = 'executing'
|
|
246
|
+
|
|
247
|
+
while smokeStatus.include? 'executing'
|
|
248
|
+
sleep 20
|
|
249
|
+
responseSmokeStatus = RestClient.post(ENDPOINT + '/rest/task/status', 'task_id '=> smokeTestId)
|
|
250
|
+
fullResponse = JSON.parse(responseSmokeStatus)
|
|
251
|
+
smokeStatus = fullResponse["data"]["status"]
|
|
252
|
+
puts "Smoke test status: #{smokeStatus}"
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
if smokeStatus.include? 'failed'
|
|
256
|
+
# Delete the cloned assembly's instance
|
|
257
|
+
puts "Smoke test failed, response: "
|
|
258
|
+
pp fullResponse
|
|
259
|
+
|
|
260
|
+
# Getting log files for failed jobs
|
|
261
|
+
task_log_response = RestClient.post(ENDPOINT + '/rest/task/get_logs', 'task_id '=> smokeTestId)
|
|
262
|
+
puts "Logs response:"
|
|
263
|
+
pp JSON.parse(task_log_response)
|
|
264
|
+
|
|
265
|
+
deleteAssembly(assemblyId)
|
|
266
|
+
abort("Smoke test failed.")
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
# Delete the cloned assembly's instance, this is the must!
|
|
270
|
+
#deleteAssembly(assemblyId)
|
|
271
|
+
|
|
272
|
+
#abort("Testing failure mail report.")
|
|
273
|
+
</command>
|
|
274
|
+
</hudson.tasks.Shell>
|
|
275
|
+
</builders>
|
|
276
|
+
<publishers>
|
|
277
|
+
<hudson.tasks.Mailer>
|
|
278
|
+
<recipients>r8-jenkins@atlantbh.com</recipients>
|
|
279
|
+
<dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild>
|
|
280
|
+
<sendToIndividuals>false</sendToIndividuals>
|
|
281
|
+
</hudson.tasks.Mailer>
|
|
282
|
+
</publishers>
|
|
283
|
+
<buildWrappers/>
|
|
284
|
+
</project>
|
|
285
|
+
eos
|
|
286
|
+
|
|
287
|
+
end
|
|
288
|
+
end
|