epc 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. data/CHANGELOG +1 -0
  2. data/Gemfile +22 -0
  3. data/Rakefile +67 -0
  4. data/Rakefile.gem +1 -0
  5. data/bin/epc +10 -0
  6. data/lib/epc.rb +126 -0
  7. data/lib/epc/client/base_client.rb +80 -0
  8. data/lib/epc/client/http_client.rb +19 -0
  9. data/lib/epc/client/json_client.rb +48 -0
  10. data/lib/epc/command/archive_project_command.rb +24 -0
  11. data/lib/epc/command/archive_solution_command.rb +21 -0
  12. data/lib/epc/command/attach_library_command.rb +82 -0
  13. data/lib/epc/command/attach_libraryset_command.rb +32 -0
  14. data/lib/epc/command/attach_runtime_command.rb +27 -0
  15. data/lib/epc/command/base_command.rb +451 -0
  16. data/lib/epc/command/bind_service_command.rb +35 -0
  17. data/lib/epc/command/build_command.rb +83 -0
  18. data/lib/epc/command/config/create_config_command.rb +55 -0
  19. data/lib/epc/command/copy_deployment_command.rb +21 -0
  20. data/lib/epc/command/create_command.rb +13 -0
  21. data/lib/epc/command/create_dependency_command.rb +43 -0
  22. data/lib/epc/command/define_service_command.rb +37 -0
  23. data/lib/epc/command/delete_config_command.rb +63 -0
  24. data/lib/epc/command/delete_dependency_command.rb +40 -0
  25. data/lib/epc/command/delete_group_command.rb +40 -0
  26. data/lib/epc/command/delete_library_command.rb +30 -0
  27. data/lib/epc/command/delete_librarylanguage_command.rb +40 -0
  28. data/lib/epc/command/delete_libraryset_command.rb +40 -0
  29. data/lib/epc/command/delete_project_command.rb +54 -0
  30. data/lib/epc/command/delete_role_command.rb +25 -0
  31. data/lib/epc/command/delete_serviceversion_command.rb +52 -0
  32. data/lib/epc/command/delete_solution_command.rb +39 -0
  33. data/lib/epc/command/delete_user_command.rb +31 -0
  34. data/lib/epc/command/deploy_command.rb +142 -0
  35. data/lib/epc/command/deployment/create_deployment_command.rb +82 -0
  36. data/lib/epc/command/detach_library_command.rb +35 -0
  37. data/lib/epc/command/detach_libraryset_command.rb +8 -0
  38. data/lib/epc/command/group/create_group_command.rb +21 -0
  39. data/lib/epc/command/info_command.rb +11 -0
  40. data/lib/epc/command/library/create_library_command.rb +45 -0
  41. data/lib/epc/command/librarylanguage/create_librarylanguage_command.rb +24 -0
  42. data/lib/epc/command/libraryset/create_libraryset_command.rb +54 -0
  43. data/lib/epc/command/list_approvals_command.rb +27 -0
  44. data/lib/epc/command/list_attachedlibraries_command.rb +42 -0
  45. data/lib/epc/command/list_boundservices_command.rb +40 -0
  46. data/lib/epc/command/list_config_command.rb +60 -0
  47. data/lib/epc/command/list_dependencies_command.rb +43 -0
  48. data/lib/epc/command/list_deployments_command.rb +68 -0
  49. data/lib/epc/command/list_groups_command.rb +19 -0
  50. data/lib/epc/command/list_libraries_command.rb +19 -0
  51. data/lib/epc/command/list_librarylanguages_command.rb +19 -0
  52. data/lib/epc/command/list_librarysets_command.rb +26 -0
  53. data/lib/epc/command/list_objectroles_command.rb +25 -0
  54. data/lib/epc/command/list_objecttypes_command.rb +20 -0
  55. data/lib/epc/command/list_permissiongroups_command.rb +20 -0
  56. data/lib/epc/command/list_projects_command.rb +36 -0
  57. data/lib/epc/command/list_projecttypes_command.rb +20 -0
  58. data/lib/epc/command/list_rolepermissions_command.rb +21 -0
  59. data/lib/epc/command/list_roles_command.rb +26 -0
  60. data/lib/epc/command/list_runtimes_command.rb +16 -0
  61. data/lib/epc/command/list_service_types_command.rb +19 -0
  62. data/lib/epc/command/list_servicedefinitions_command.rb +19 -0
  63. data/lib/epc/command/list_serviceversions_command.rb +21 -0
  64. data/lib/epc/command/list_solutions_command.rb +25 -0
  65. data/lib/epc/command/list_stages_command.rb +21 -0
  66. data/lib/epc/command/list_users_command.rb +26 -0
  67. data/lib/epc/command/list_versions_command.rb +39 -0
  68. data/lib/epc/command/login_command.rb +32 -0
  69. data/lib/epc/command/logout_command.rb +20 -0
  70. data/lib/epc/command/objectrole/create_objectrole_command.rb +19 -0
  71. data/lib/epc/command/project/create_project_command.rb +78 -0
  72. data/lib/epc/command/pull_command.rb +209 -0
  73. data/lib/epc/command/push_command.rb +194 -0
  74. data/lib/epc/command/refresh_solution_command.rb +71 -0
  75. data/lib/epc/command/renew_command.rb +19 -0
  76. data/lib/epc/command/request_passwordchange_command.rb +23 -0
  77. data/lib/epc/command/role/create_role_command.rb +17 -0
  78. data/lib/epc/command/serviceversion/create_serviceversion_command.rb +33 -0
  79. data/lib/epc/command/show_deployment_command.rb +57 -0
  80. data/lib/epc/command/show_group_command.rb +35 -0
  81. data/lib/epc/command/show_libraryset_command.rb +54 -0
  82. data/lib/epc/command/show_project_command.rb +74 -0
  83. data/lib/epc/command/show_projecttype_command.rb +18 -0
  84. data/lib/epc/command/show_role_command.rb +46 -0
  85. data/lib/epc/command/show_solution_command.rb +54 -0
  86. data/lib/epc/command/show_user_command.rb +42 -0
  87. data/lib/epc/command/solution/create_solution_command.rb +34 -0
  88. data/lib/epc/command/solution/list_solutions_command.rb +25 -0
  89. data/lib/epc/command/solution/update_solution_command.rb +43 -0
  90. data/lib/epc/command/submit_deployment_command.rb +19 -0
  91. data/lib/epc/command/target_command.rb +26 -0
  92. data/lib/epc/command/unarchive_project_command.rb +23 -0
  93. data/lib/epc/command/unarchive_solution_command.rb +21 -0
  94. data/lib/epc/command/unbind_service_command.rb +42 -0
  95. data/lib/epc/command/undefine_service_command.rb +33 -0
  96. data/lib/epc/command/undeploy_command.rb +106 -0
  97. data/lib/epc/command/update_config_command.rb +62 -0
  98. data/lib/epc/command/update_deploymentproject_command.rb +54 -0
  99. data/lib/epc/command/update_group_command.rb +43 -0
  100. data/lib/epc/command/update_librarylanguage_command.rb +28 -0
  101. data/lib/epc/command/update_libraryset_command.rb +80 -0
  102. data/lib/epc/command/update_project_command.rb +49 -0
  103. data/lib/epc/command/update_role_command.rb +47 -0
  104. data/lib/epc/command/update_rolepermissions_command.rb +83 -0
  105. data/lib/epc/command/update_solution_command.rb +45 -0
  106. data/lib/epc/command/update_user_command.rb +57 -0
  107. data/lib/epc/command/user/create_user_command.rb +27 -0
  108. data/lib/epc/command/vote_deployment_command.rb +29 -0
  109. data/lib/epc/config.rb +245 -0
  110. data/lib/epc/error/basic_error.rb +6 -0
  111. data/lib/epc/error/fatal_error.rb +6 -0
  112. data/lib/epc/error/input_error.rb +6 -0
  113. data/lib/epc/error/internal_error.rb +6 -0
  114. data/lib/epc/help.rb +292 -0
  115. data/lib/epc/persistent_attributes.rb +18 -0
  116. data/lib/epc/runner.rb +177 -0
  117. data/lib/epc/tabular_outputter.rb +161 -0
  118. data/lib/epc/version.rb +3 -0
  119. data/lib/fixnum.rb +9 -0
  120. data/lib/object.rb +13 -0
  121. data/test/command/archive_project_command_test.rb +41 -0
  122. data/test/command/archive_solution_command_test.rb +40 -0
  123. data/test/command/attach_library_command_test.rb +124 -0
  124. data/test/command/attach_libraryset_command_test.rb +49 -0
  125. data/test/command/attach_runtime_command_test.rb +44 -0
  126. data/test/command/base_command_test.rb +276 -0
  127. data/test/command/bind_service_command_test.rb +46 -0
  128. data/test/command/build_command_test.rb +103 -0
  129. data/test/command/copy_deployment_command_test.rb +38 -0
  130. data/test/command/create_config_command_test.rb +124 -0
  131. data/test/command/create_dependency_command_test.rb +55 -0
  132. data/test/command/create_deployment_command_test.rb +136 -0
  133. data/test/command/create_group_command_test.rb +34 -0
  134. data/test/command/create_library_command_test.rb +61 -0
  135. data/test/command/create_librarylanguage_command_test.rb +51 -0
  136. data/test/command/create_libraryset_command_test.rb +81 -0
  137. data/test/command/create_objectrole_command_test.rb +37 -0
  138. data/test/command/create_project_command_test.rb +102 -0
  139. data/test/command/create_role_command_test.rb +31 -0
  140. data/test/command/create_serviceversion_command_test.rb +60 -0
  141. data/test/command/create_solution_command_test.rb +70 -0
  142. data/test/command/create_user_command_test.rb +54 -0
  143. data/test/command/define_service_command_test.rb +55 -0
  144. data/test/command/delete_config_command_test.rb +82 -0
  145. data/test/command/delete_dependency_command_test.rb +50 -0
  146. data/test/command/delete_group_command_test.rb +56 -0
  147. data/test/command/delete_library_command_test.rb +43 -0
  148. data/test/command/delete_librarylanguage_command_test.rb +55 -0
  149. data/test/command/delete_libraryset_command_test.rb +55 -0
  150. data/test/command/delete_project_command_test.rb +76 -0
  151. data/test/command/delete_role_command_test.rb +41 -0
  152. data/test/command/delete_serviceversion_command_test.rb +53 -0
  153. data/test/command/delete_solution_command_test.rb +79 -0
  154. data/test/command/delete_user_command_test.rb +56 -0
  155. data/test/command/deploy_command_test.rb +185 -0
  156. data/test/command/detach_library_command_test.rb +53 -0
  157. data/test/command/info_command_test.rb +17 -0
  158. data/test/command/list_approvals_command_test.rb +41 -0
  159. data/test/command/list_boundservices_command_test.rb +46 -0
  160. data/test/command/list_config_command_test.rb +72 -0
  161. data/test/command/list_dependencies_command_test.rb +46 -0
  162. data/test/command/list_deployments_command_test.rb +112 -0
  163. data/test/command/list_deploymentstages_command_test.rb +44 -0
  164. data/test/command/list_libraries_command_test.rb +42 -0
  165. data/test/command/list_librarylanguages_command_test.rb +34 -0
  166. data/test/command/list_librarysets_command_test.rb +33 -0
  167. data/test/command/list_objectroles_command_test.rb +41 -0
  168. data/test/command/list_objecttypes_command_test.rb +25 -0
  169. data/test/command/list_permissiongroups_command_test.rb +25 -0
  170. data/test/command/list_projects_command_test.rb +63 -0
  171. data/test/command/list_projecttypes_command_test.rb +39 -0
  172. data/test/command/list_rolepermissions_command_test.rb +39 -0
  173. data/test/command/list_roles_command_test.rb +46 -0
  174. data/test/command/list_runtimes_command_test.rb +30 -0
  175. data/test/command/list_service_types_command_test.rb +44 -0
  176. data/test/command/list_servicedefinitions_command_test.rb +44 -0
  177. data/test/command/list_serviceversions_command_test.rb +47 -0
  178. data/test/command/list_solutions_command_test.rb +48 -0
  179. data/test/command/list_users_command_test.rb +33 -0
  180. data/test/command/login_command_test.rb +83 -0
  181. data/test/command/logout_command_test.rb +30 -0
  182. data/test/command/pull_command_test.rb +229 -0
  183. data/test/command/push_command_test.rb +246 -0
  184. data/test/command/refresh_solution_command_test.rb +35 -0
  185. data/test/command/renew_command_test.rb +43 -0
  186. data/test/command/request_passwordchange_command_test.rb +31 -0
  187. data/test/command/show_group_command_test.rb +50 -0
  188. data/test/command/show_libraryset_command_test.rb +51 -0
  189. data/test/command/show_project_command_test.rb +57 -0
  190. data/test/command/show_projecttype_command_test.rb +46 -0
  191. data/test/command/show_role_command_test.rb +37 -0
  192. data/test/command/show_solution_command_test.rb +59 -0
  193. data/test/command/show_user_command_test.rb +50 -0
  194. data/test/command/submit_deployment_command_test.rb +37 -0
  195. data/test/command/target_command_test.rb +58 -0
  196. data/test/command/unarchive_project_command_test.rb +45 -0
  197. data/test/command/unarchive_solution_command_test.rb +43 -0
  198. data/test/command/unbind_service_command_test.rb +48 -0
  199. data/test/command/undefine_service_command_test.rb +49 -0
  200. data/test/command/update_config_command_test.rb +74 -0
  201. data/test/command/update_deploymentproject_command_test.rb +77 -0
  202. data/test/command/update_group_command_test.rb +69 -0
  203. data/test/command/update_librarylanguage_command_test.rb +43 -0
  204. data/test/command/update_libraryset_command_test.rb +113 -0
  205. data/test/command/update_project_command_test.rb +56 -0
  206. data/test/command/update_role_command_test.rb +42 -0
  207. data/test/command/update_rolepermissions_command_test.rb +54 -0
  208. data/test/command/update_solution_command_test.rb +58 -0
  209. data/test/command/update_user_command_test.rb +76 -0
  210. data/test/command/vote_deployment_command_test.rb +33 -0
  211. data/test/config_test.rb +70 -0
  212. data/test/successful_test.rb +21 -0
  213. data/test/test_files/pom.xml +273 -0
  214. data/test/test_helper.rb +25 -0
  215. metadata +470 -0
@@ -0,0 +1,32 @@
1
+ module EPC::Command
2
+ class AttachLibrarysetCommand < BaseCommand
3
+ required_arguments_count 1, :message => "You must specify a library-set"
4
+
5
+ def execute(set = nil)
6
+ path = File.expand_path(".")
7
+ solution_id, solution_name = infer_solution_context(@options[:solution_name], path)
8
+ project_id, project_name = infer_project_context(@options[:project_name], path, solution_id)
9
+
10
+ raise InputError, "Project could not be inferred" if project_id.nil?
11
+
12
+ set_id = retrieve_library_set_identifier(set)
13
+
14
+ if @options[:detach].present? && @options[:detach]
15
+ status, response, headers = client.delete(EPC::Config::PROJECTS_PATH + "/#{project_id}/detach_set/#{set_id}")
16
+ else
17
+ status, response, headers = client.post(EPC::Config::PROJECTS_PATH + "/#{project_id}/attach_set/#{set_id}")
18
+ end
19
+
20
+ if status.successful?
21
+ say("Library set #{@options[:detach] ? "detached" : "attached"}")
22
+ else
23
+ say("Request failed: [#{response[:message]}]")
24
+ end
25
+
26
+ return status
27
+
28
+
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ module EPC::Command
2
+ class AttachRuntimeCommand < BaseCommand
3
+ required_arguments_count 1, :message => "You must specify a runtime id"
4
+ required_options :stage, :mode => :any?, :message => "You must specify the stage"
5
+
6
+ def execute(runtime = nil)
7
+
8
+ path = File.expand_path(".")
9
+
10
+ solution_id, solution_name = infer_solution_context(@options[:solution_name], path)
11
+ project_id, project_name = infer_project_context(@options[:project_name], path, solution_id)
12
+
13
+ raise InputError, "Project could not be inferred" if project_id.nil?
14
+
15
+ status, response, headers = client.put(EPC::Config::PROJECTS_PATH + "/#{project_id}/set_runtime_env", {:runtime_env_id => runtime, :stage_name => @options[:stage]})
16
+
17
+ if status.successful?
18
+ say("Runtime attached")
19
+ else
20
+ say("Request failed: [#{response[:message]}]")
21
+ end
22
+
23
+ return status
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,451 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ module EPC
5
+ module Command
6
+ class BaseCommand
7
+ include PersistentAttributes
8
+ include Error
9
+
10
+ attr_reader :client
11
+ attr_reader :options
12
+
13
+ @@retrieval_rules = {
14
+ :system_role => {
15
+ :match_attribute => :name,
16
+ :required_attribute => :id,
17
+ :required_type => :numeric,
18
+ :source => EPC::Config::ROLES_PATH + "/system/true"
19
+ },
20
+ :user => {
21
+ :match_attribute => :name,
22
+ :required_attribute => :id,
23
+ :required_type => :numeric,
24
+ :source => EPC::Config::USERS_PATH
25
+ },
26
+ :user_group => {
27
+ :match_attribute => :name,
28
+ :required_attribute => :id,
29
+ :required_type => :numeric,
30
+ :source => EPC::Config::GROUPS_PATH
31
+ },
32
+ :library_set => {
33
+ :match_attribute => :name,
34
+ :required_attribute => :id,
35
+ :required_type => :numeric,
36
+ :source => EPC::Config::LIBRARY_SETS_PATH
37
+
38
+ }
39
+ }
40
+
41
+ @@required_arguments = {:count => 0}
42
+ @@required_options = []
43
+
44
+ SLEEP_TIME = 1
45
+
46
+ # Numerators are in secs
47
+ TICKER_TICKS = 25/SLEEP_TIME
48
+ GIVEUP_TICKS = 120/SLEEP_TIME
49
+
50
+ def method_missing(method, *args, &block)
51
+ if method.to_s =~ /^retrieve_(.+)_identifier$/
52
+ retrieve_identifier_for($1, *args, &block)
53
+ else
54
+ super
55
+ end
56
+ end
57
+
58
+ def respond_to?(meth)
59
+ if meth.to_s =~ /^retrieve_.*_identifier$/
60
+ true
61
+ else
62
+ super
63
+ end
64
+ end
65
+
66
+ def self.inherited(subklass)
67
+ # Here login is required for all commands that inherit
68
+ subklass.require_login
69
+ end
70
+
71
+ def self.required_arguments_count(count, options_hash = {})
72
+ opt = {
73
+ :message => "Please specify all the mandatory arguments"
74
+ }.merge(options_hash)
75
+ @@required_arguments = {:count => count, :message => opt[:message]}
76
+ end
77
+
78
+ def self.required_options(*opts, opt_hash)
79
+ options_hash = {
80
+ :mode => :any?,
81
+ :message => "You need to specify all required options"
82
+ }.merge(opt_hash)
83
+ @@required_options << {:name => opts, :mode => options_hash[:mode], :message => options_hash[:message]}
84
+ end
85
+
86
+ def initialize(client, options = {})
87
+ @client = client
88
+ @options = options.dup
89
+ if @options[:skip_prompts].present?
90
+ create_method(:ask) {|text, arr| return "Y"}
91
+ end
92
+ end
93
+
94
+ def go(*args)
95
+ if (login_required?) && (!logged_in?)
96
+ say("You must be logged in to run this command")
97
+ return 1
98
+ else
99
+ check_requirements(*args)
100
+ return translate_status_to_exit_code(execute(*args))
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def translate_status_to_exit_code(status)
107
+ if status.successful?
108
+ return 0
109
+ else
110
+ return status
111
+ end
112
+ end
113
+
114
+ def self.dont_require_login
115
+ @login_required = false
116
+ end
117
+
118
+ def self.require_login
119
+ @login_required = true
120
+ end
121
+
122
+ def self.login_required?
123
+ !!@login_required
124
+ end
125
+
126
+ def login_required?
127
+ self.class.login_required?
128
+ end
129
+
130
+ def create_method(name, &block)
131
+ self.class.send(:define_method, :ask, &block)
132
+ end
133
+
134
+ def logged_in?
135
+ !(auth_token.nil? || auth_token.empty?)
136
+ end
137
+
138
+ def blank?(value)
139
+ value.respond_to?(:empty?) ? value.empty? : !value
140
+ end
141
+
142
+ def check_requirements(*args)
143
+ raise FatalError, @@required_arguments[:message] if args.size < @@required_arguments[:count]
144
+ @@required_options.each do |req_opt|
145
+ raise FatalError, req_opt[:message] unless req_opt[:name].map{|opt| @options[opt].present?}.send(req_opt[:mode])
146
+ end
147
+ end
148
+
149
+ def numeric?(value)
150
+ return value.is_a?(Integer) || (value =~ /\d/) == 0
151
+ end
152
+
153
+ def ask_yn(question)
154
+ return ask(question, ["Y", "y", "N", "n", ""])
155
+ end
156
+
157
+ def mkdir(name, options = {})
158
+ result = :ok
159
+
160
+ begin
161
+ FileUtils.mkdir(name, options)
162
+ rescue SystemCallError => ex
163
+ result = :failed
164
+ say("Failed to create local directory [#{name}] - [#{ex}]")
165
+ end
166
+
167
+ result
168
+ end
169
+
170
+ def read_file(path)
171
+ begin
172
+ content = File.read(path)
173
+ rescue Exception => ex
174
+ say("Failed to read file at #{path}: [#{ex}]")
175
+ end
176
+ content
177
+ end
178
+
179
+ def parse_timeout_value
180
+ return if @options[:timeout].blank?
181
+ if numeric?(@options[:timeout][-1])
182
+ @timeout = @options[:timeout].to_i
183
+ return
184
+ end
185
+ unit = @options[:timeout][-1]
186
+ time = @options[:timeout][0...-1].to_i
187
+ if unit.downcase == "m"
188
+ @timeout = 60 * time
189
+ return
190
+ end
191
+ @timeout = time
192
+ end
193
+
194
+ def project_solution_path(path)
195
+ return path if EPC::Config.is_solution_dir?(path)
196
+ return File.join(File.split(path)[0...-1])
197
+ end
198
+
199
+ def normalize_params(params)
200
+ return params if is_target_param?(params.first)
201
+ return params.insert(0, "")
202
+ end
203
+
204
+ def is_target_param?(param)
205
+ target_type = param.split(":").first rescue ""
206
+ return object_types.include?(target_type.downcase)
207
+ end
208
+
209
+ def object_types
210
+ return ["solution", "project"]
211
+ end
212
+
213
+ def retrieve_identifier_for(entity, *args, &block)
214
+ entity = entity.to_sym
215
+ match_value = args.first
216
+ raise InternalError if match_value.blank?
217
+ raise InternalError unless @@retrieval_rules.keys.include?(entity)
218
+ rule = @@retrieval_rules[entity]
219
+ if rule[:required_type] == :numeric
220
+ if numeric?(match_value)
221
+ return match_value.to_i
222
+ elsif
223
+ entity_identifier = get_resource_attribute(rule[:source],
224
+ rule[:required_attribute],
225
+ rule[:match_attribute],
226
+ match_value)
227
+ end
228
+ end
229
+
230
+ raise InputError, "Request failed: [Resource Not Found]" if entity_identifier.nil?
231
+ return entity_identifier
232
+ end
233
+
234
+ def infer_solution_context(s_identifier, path, options = {})
235
+ if s_identifier.nil?
236
+ if EPC::Config.is_solution_dir?(path)
237
+ solution_id = EPC::Config.get_solution_value(path, "id")
238
+ solution_name = EPC::Config.get_solution_value(path, "name")
239
+ return solution_id, solution_name
240
+ elsif EPC::Config.is_project_dir?(path)
241
+ solution_path = project_solution_path(path)
242
+ solution_id = EPC::Config.get_solution_value(solution_path, "id")
243
+ solution_name = EPC::Config.get_solution_value(solution_path, "name")
244
+ return solution_id, solution_name
245
+ else
246
+ return [nil, nil]
247
+ end
248
+ else
249
+ if numeric?(s_identifier)
250
+ s_identifier = s_identifier.to_i
251
+ if options[:get_solution_name].present? && options[:get_solution_name]
252
+ solution_name = get_resource_name(EPC::Config::SOLUTIONS_PATH + "?include=archived", :id, s_identifier)
253
+ end
254
+ return s_identifier, solution_name
255
+ else
256
+ if EPC::Config.is_solution_dir?(path)
257
+ path_solution_name = EPC::Config.get_solution_value(path, "name")
258
+ if path_solution_name == s_identifier
259
+ solution_id = EPC::Config.get_solution_value(path, "id")
260
+ solution_name = EPC::Config.get_solution_value(path, "name")
261
+ return solution_id, solution_name
262
+ end
263
+ elsif EPC::Config.is_project_dir?(path)
264
+ solution_path = project_solution_path(path)
265
+ path_solution_name = EPC::Config.get_solution_value(solution_path, "name")
266
+ if path_solution_name == s_identifier
267
+ solution_id = EPC::Config.get_solution_value(solution_path, "id")
268
+ solution_name = EPC::Config.get_solution_value(solution_path, "name")
269
+ return solution_id, solution_name
270
+ end
271
+ end
272
+ solution_id = get_resource_id(EPC::Config::SOLUTIONS_PATH + "?include=archived", :name, s_identifier)
273
+ return solution_id, s_identifier
274
+ end
275
+ end
276
+ end
277
+
278
+ # OPTIONS:
279
+ # :get_project_name : for when you have a numeric project_id, but you also want the name
280
+ def infer_project_context(p_identifier, path, s_identifier = nil, options = {})
281
+ if p_identifier.nil?
282
+
283
+ if EPC::Config.is_project_dir?(path)
284
+ project_id = EPC::Config.get_project_value(path, "id")
285
+ project_name = EPC::Config.get_project_value(path, "name")
286
+ return project_id, project_name
287
+ else
288
+ return nil, nil
289
+ end
290
+
291
+ else
292
+
293
+ if numeric?(p_identifier)
294
+ if !options[:get_project_name].nil? && options[:get_project_name] && !s_identifier.nil?
295
+ project_name = get_resource_name(EPC::Config::SOLUTIONS_PATH + "/#{s_identifier}/projects?include=archived", :id, p_identifier)
296
+ end
297
+ return p_identifier, project_name
298
+ else
299
+ if s_identifier.present?
300
+ project_id = get_resource_id(EPC::Config::SOLUTIONS_PATH + "/#{s_identifier}/projects?include=archived", :name, p_identifier)
301
+ return project_id, p_identifier
302
+ elsif EPC::Config.is_solution_dir?(path)
303
+ project_path = File.join(path, p_identifier)
304
+ if File.exists?(project_path)
305
+ project_id = EPC::Config.get_project_value(project_path, "id")
306
+ return project_id, p_identifier
307
+ end
308
+ elsif EPC::Config.is_project_dir?(path)
309
+ path_project_name = EPC::Config.get_project_value(path, "name")
310
+ if path_project_name == p_identifier
311
+ return EPC::Config.get_project_value(path, "id"), p_identifier
312
+ end
313
+ else
314
+ return nil, p_identifier
315
+ end
316
+ end
317
+
318
+ end
319
+ end
320
+
321
+ def retrieve_libraries(libraries)
322
+ status, response, headers = @client.get(EPC::Config::LIBRARIES_PATH)
323
+ raise FatalError, "Library retrieval failed: [#{response['message']}]" if status.failure?
324
+
325
+ ids = []
326
+ libraries.each do |lib|
327
+ raise FatalError, "An entry is missing the name" if lib[:name].nil?
328
+ lib_id = response.detect { |rlib|
329
+ found = (rlib[:name] == lib[:name])
330
+ found = found && (rlib[:library_version].to_s == lib[:library_version])
331
+ found = found && (rlib[:group].to_s == lib[:group])
332
+ found
333
+ }[:id] rescue nil
334
+
335
+ raise FatalError, "Could not find [#{lib[:name]}] library" if lib_id.nil?
336
+ ids << lib_id
337
+ end
338
+
339
+ ids
340
+ end
341
+
342
+
343
+ def get_resource_name(url, field, field_value)
344
+ return get_resource_attribute(url, :name, field, field_value.to_i)
345
+ end
346
+
347
+ def get_resource_id(url, field, field_value, options = {})
348
+ return get_resource_attribute(url, :id, field, field_value, options)
349
+ end
350
+
351
+ def get_resource_attribute(url, attribute, match_field, match_value, options = {})
352
+ opt = {
353
+ :case_sensitivity => true
354
+ }.merge(options)
355
+
356
+ status, response, message = client.get(url)
357
+ raise InputError, "Retrieval failed with message [#{response[:message]}]" unless status.successful?
358
+ value = response.detect do |entity|
359
+ if opt[:case_sensitivity]
360
+ entity[match_field.to_sym] == match_value
361
+ else
362
+ entity[match_field.to_sym].downcase == match_value.downcase
363
+ end
364
+ end
365
+ return value[attribute.to_sym] rescue nil
366
+ end
367
+
368
+ def http_client
369
+ return @http_client if @http_client
370
+ @http_client = EPC::Client::HttpClient.new(target_url, caller_id, auth_token)
371
+ end
372
+
373
+ def sha1(zip_path)
374
+ digest = Digest::SHA1.new
375
+
376
+ buffer_size = 1024
377
+ buffer = String.new
378
+
379
+ open(zip_path) { |io|
380
+ digest.update(buffer) while io.read(buffer_size, buffer)
381
+ }
382
+
383
+ digest.hexdigest
384
+ end
385
+
386
+ def extract_configuration_level(path, target_string)
387
+ config_type, config_id = target_string.split(":") rescue [nil, nil]
388
+
389
+ if config_id.nil?
390
+ if EPC::Config.is_project_dir?(path)
391
+ config_id = EPC::Config.get_project_value(path, "id")
392
+ config_type = "Project"
393
+ elsif EPC::Config.is_solution_dir?(path)
394
+ config_id = EPC::Config.get_solution_value(path, "id")
395
+ config_type = "Solution"
396
+ end
397
+ end
398
+
399
+ return [config_type, config_id]
400
+ end
401
+
402
+ def show_build_status(build_id)
403
+ status, response, headers = client.get("#{EPC::Config::BUILDS_PATH}/#{build_id}/status")
404
+ @status = status
405
+ if status.successful?
406
+ return true, response[:id], response[:message], response[:status]
407
+ else
408
+ return false
409
+ end
410
+ end
411
+
412
+
413
+ def poll_for_build_status(build_id)
414
+ count = 0
415
+ failed = false
416
+
417
+ while count <= @timeout
418
+ STDOUT.print('.')
419
+ STDOUT.flush
420
+ sleep(SLEEP_TIME)
421
+
422
+ shown, id, message, status = show_build_status(build_id)
423
+ if shown
424
+ count += 1
425
+ next unless status == "BUILT" || status == "FAILED" || status == "ERROR"
426
+
427
+ if status == "BUILT"
428
+ say("\nBuild completed successfully.")
429
+ return 0
430
+ else
431
+ say("\nBuild failed: #{status} - #{message}")
432
+ return 1
433
+ end
434
+ break
435
+ else
436
+ say("Poller failed to get the build status. Aborting.")
437
+ return 1
438
+ end
439
+ end
440
+
441
+ unless failed
442
+ if count > @timeout
443
+ say("\nServer is taking too long to update the build status. Please contact the AgileMethods support team.")
444
+ return 1
445
+ end
446
+ end
447
+ end
448
+
449
+ end
450
+ end
451
+ end