capistrano-karaf 1.5.1 → 1.5.2
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.
- data/lib/capistrano-karaf/core.rb +112 -34
- data/lib/capistrano-karaf/extended.rb +5 -5
- data/lib/capistrano-karaf/install.rb +57 -26
- metadata +1 -1
@@ -11,8 +11,9 @@ SSHKit.config.command_map[:features_install] = 'features:install'
|
|
11
11
|
SSHKit.config.command_map[:features_uninstall] = 'features:uninstall'
|
12
12
|
SSHKit.config.command_map[:features_list] = 'features:list'
|
13
13
|
SSHKit.config.command_map[:features_info] = 'features:info'
|
14
|
-
SSHKit.config.command_map[:headers] = 'headers'
|
15
|
-
SSHKit.config.command_map[:list] = 'osgi:list
|
14
|
+
SSHKit.config.command_map[:headers] = 'osgi:headers --force'
|
15
|
+
SSHKit.config.command_map[:list] = 'osgi:list'
|
16
|
+
SSHKit.config.command_map[:list_all] = 'osgi:list -t 0'
|
16
17
|
SSHKit.config.command_map[:log_set] = 'log:set'
|
17
18
|
SSHKit.config.command_map[:stop] = 'osgi:stop'
|
18
19
|
SSHKit.config.command_map[:start] = 'osgi:start'
|
@@ -72,14 +73,28 @@ module Capistrano_Karaf
|
|
72
73
|
# Uninstall a feature on the karaf server
|
73
74
|
#
|
74
75
|
# name - the string containing the feature name
|
76
|
+
# version - the string containing the version number
|
75
77
|
#
|
76
78
|
# Examples
|
77
|
-
# feature_uninstall "hello"
|
79
|
+
# feature_uninstall "hello" "2.19.0"
|
78
80
|
# # => nil
|
79
81
|
#
|
80
82
|
# Returns nothing
|
81
|
-
def feature_uninstall
|
83
|
+
def feature_uninstall(name, version)
|
84
|
+
|
85
|
+
# Keep track of the bundles that are part of the feature
|
86
|
+
#bundles = feature_bundles(name, version)
|
82
87
|
execute(:features_uninstall, name)
|
88
|
+
|
89
|
+
# Verify all bundles have been uninstalled and remove the bundle if not
|
90
|
+
#headers = list_headers
|
91
|
+
#bundles.each do |b|
|
92
|
+
# matching_headers = headers.find do |h|
|
93
|
+
# h['Bundle-SymbolicName'] == b[:artifactId] && h['Bundle-Version'] == b[:version]
|
94
|
+
# end
|
95
|
+
|
96
|
+
# matching_headers.each {|h| uninstall['Bundle-Number']}
|
97
|
+
#end
|
83
98
|
end
|
84
99
|
|
85
100
|
# Set the log level on the karaf server
|
@@ -142,13 +157,14 @@ module Capistrano_Karaf
|
|
142
157
|
#
|
143
158
|
# Returns a list of hashmaps containing all feature repositories
|
144
159
|
def list_urls
|
145
|
-
url_line_matcher =
|
146
|
-
|
147
|
-
|
148
|
-
|
160
|
+
url_line_matcher =
|
161
|
+
%r{ (?<status> \w+){0}
|
162
|
+
(?<groupID> [\d\w\.\-]+){0}
|
163
|
+
(?<artifactID> [\w\.\-]+){0}
|
164
|
+
(?<version> [\w\.\-]+){0}
|
149
165
|
|
150
|
-
|
151
|
-
|
166
|
+
\s*\g<status>\s*mvn\:\g<groupID>\/\g<artifactID>\/\g<version>.*
|
167
|
+
}x
|
152
168
|
|
153
169
|
data = capture(:features_listurl)
|
154
170
|
matcher_to_hash(url_line_matcher, data)
|
@@ -162,13 +178,14 @@ module Capistrano_Karaf
|
|
162
178
|
#
|
163
179
|
# Returns a list of hashmaps containing all available features
|
164
180
|
def list_features
|
165
|
-
feature_line_matcher =
|
166
|
-
|
167
|
-
|
168
|
-
|
181
|
+
feature_line_matcher =
|
182
|
+
%r{ (?<status> \w+){0}
|
183
|
+
(?<version> [\d\w\-\.\s]+){0}
|
184
|
+
(?<name> [\w\-\.\:]+){0}
|
185
|
+
(?<repository> [\w\-\s\:\.]+){0}
|
169
186
|
|
170
|
-
|
171
|
-
|
187
|
+
^\[\s*\g<status>\s*\]\s\[\s*\g<version>\s*\]\s*\g<name>\s*\g<repository>
|
188
|
+
}x
|
172
189
|
|
173
190
|
data = capture(:features_list)
|
174
191
|
matcher_to_hash(feature_line_matcher, data)
|
@@ -182,21 +199,69 @@ module Capistrano_Karaf
|
|
182
199
|
#
|
183
200
|
# Returns a list of hashmaps containing the installed bundles
|
184
201
|
def list_bundles
|
185
|
-
bundle_line_matcher =
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
202
|
+
bundle_line_matcher =
|
203
|
+
%r{ (?<id> \d+){0}
|
204
|
+
(?<status> \w+){0}
|
205
|
+
(?<blueprint> \w*){0}
|
206
|
+
(?<context> \w*){0}
|
207
|
+
(?<level> \d+){0}
|
208
|
+
(?<name> [\w\s\.\-\:]+){0}
|
209
|
+
(?<version> .+){0}
|
210
|
+
|
211
|
+
^\[\s*\g<id>\]\s\[\s*\g<status>\s*\]\s\[\s*\g<blueprint>\s*\]\s\[\s*\g<context>\s*\]\s\[\s*\g<level>\s*\]\s\g<name>\s\(\g<version>\)
|
212
|
+
}x
|
213
|
+
|
214
|
+
fragments_matcher = /\s*Fragments: ([\d\s]+)\s*/
|
195
215
|
|
196
216
|
data = capture(:list)
|
217
|
+
|
218
|
+
fragments = []
|
219
|
+
bundles = []
|
220
|
+
|
221
|
+
data.lines.each do |line|
|
222
|
+
m1 = bundle_line_matcher.match line
|
223
|
+
m2 = fragments_matcher.match line
|
224
|
+
|
225
|
+
if m1 then
|
226
|
+
bundles.push(m1)
|
227
|
+
elsif m2 then
|
228
|
+
fragment_bundles = m2[1].split /\s+/
|
229
|
+
fragment_bundles.each {|fb| fragments.push fb}
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
bundles1 = bundles.collect {|m| Hash[m.names.collect {|k| k.to_sym }.zip(m.captures)]}
|
234
|
+
bundles1.collect do |b|
|
235
|
+
b[:fragment] = fragments.include? b[:id]
|
236
|
+
b
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# List all bundles on the karaf server
|
241
|
+
#
|
242
|
+
# Examples
|
243
|
+
# list_bundles
|
244
|
+
# # => [{:id => "10", :status => "INSTALLED", :blueprint => "", :context => "", :level => "60", :name => "camel-core", :version => "1.0.0"}]
|
245
|
+
#
|
246
|
+
# Returns a list of hashmaps containing the installed bundles
|
247
|
+
def list_all_bundles
|
248
|
+
bundle_line_matcher =
|
249
|
+
%r{ (?<id> \d+){0}
|
250
|
+
(?<status> \w+){0}
|
251
|
+
(?<blueprint> \w*){0}
|
252
|
+
(?<context> \w*){0}
|
253
|
+
(?<level> \d+){0}
|
254
|
+
(?<name> [\w\s\.\-\:]+){0}
|
255
|
+
(?<version> .+){0}
|
256
|
+
|
257
|
+
^\[\s*\g<id>\]\s\[\s*\g<status>\s*\]\s\[\s*\g<blueprint>\s*\]\s\[\s*\g<context>\s*\]\s\[\s*\g<level>\s*\]\s\g<name>\s\(\g<version>\)
|
258
|
+
}x
|
259
|
+
|
260
|
+
data = capture(:list_all)
|
197
261
|
matcher_to_hash(bundle_line_matcher, data)
|
198
262
|
end
|
199
263
|
|
264
|
+
|
200
265
|
# Get the headers for a bundle
|
201
266
|
#
|
202
267
|
# bundleId - A number containing the bundle id
|
@@ -211,17 +276,23 @@ module Capistrano_Karaf
|
|
211
276
|
extract_bundle_headers(data)
|
212
277
|
end
|
213
278
|
|
279
|
+
def list_headers
|
280
|
+
data = capture(:headers)
|
281
|
+
data.collect {|h| extract_bundles_from_feature(h)}
|
282
|
+
end
|
283
|
+
|
214
284
|
# List all bundles provided by a feature
|
215
285
|
#
|
216
286
|
# name - A string containing the name of the feature
|
287
|
+
# version - A string containing the version of the feature
|
217
288
|
#
|
218
289
|
# Examples
|
219
|
-
# feature_bundles "camel-core"
|
290
|
+
# feature_bundles "camel-core" "2.18"
|
220
291
|
# # => [{:groupId => "org.apache.camel", :artifactId => "camel-core", :version => "2.18"}]
|
221
292
|
#
|
222
293
|
# Returns a list containing the hashes with the bundle information
|
223
|
-
def feature_bundles
|
224
|
-
data = capture(:features_info, name)
|
294
|
+
def feature_bundles(name, version)
|
295
|
+
data = capture(:features_info, "#{name} #{version}")
|
225
296
|
extract_bundles_from_feature(data)
|
226
297
|
end
|
227
298
|
|
@@ -233,7 +304,7 @@ module Capistrano_Karaf
|
|
233
304
|
m = matcher.match(line)
|
234
305
|
breaklist.push(m) unless m.nil?
|
235
306
|
end
|
236
|
-
breaklist.collect {|m| Hash[m.names.zip(m.captures)]}
|
307
|
+
breaklist.collect {|m| Hash[m.names.collect {|n| n.to_sym}.zip(m.captures)]}
|
237
308
|
end
|
238
309
|
|
239
310
|
def extract_bundles_from_feature (data)
|
@@ -241,18 +312,25 @@ module Capistrano_Karaf
|
|
241
312
|
data.lines.each do |l|
|
242
313
|
m = l.match(/.*mvn:(?<GroupId>[\w\.]+)\/(?<ArtifactId>[-\w\.]+)\/(?<Version>[-\d\w\.]+)/)
|
243
314
|
if m then
|
244
|
-
bundles.push({:groupId => m['GroupId'],
|
315
|
+
bundles.push({ :groupId => m['GroupId'],
|
245
316
|
:artifactId => m['ArtifactId'],
|
246
|
-
:version
|
317
|
+
:version => m['Version']})
|
247
318
|
end
|
248
319
|
end
|
249
320
|
bundles
|
250
321
|
end
|
251
322
|
|
252
|
-
def extract_bundle_headers (
|
323
|
+
def extract_bundle_headers (hdrs)
|
253
324
|
re = /(.+) = (.+)/
|
254
325
|
header = {}
|
255
|
-
|
326
|
+
lines = hdrs.lines
|
327
|
+
lines.map {|l| m = l.match(re); if m then header[m[1].strip!] = m[2] end}
|
328
|
+
|
329
|
+
m = lines[2].match(/\w+ \(([\d+])\)/)
|
330
|
+
if m then
|
331
|
+
header['Bundle-Number'] = m[1].to_i
|
332
|
+
end
|
333
|
+
|
256
334
|
header
|
257
335
|
end
|
258
336
|
end
|
@@ -20,7 +20,7 @@ module Capistrano_Karaf
|
|
20
20
|
}x
|
21
21
|
urls_to_remove=matcher_to_hash(url_details_regex,url)
|
22
22
|
urls_to_remove.each do |u|
|
23
|
-
remove_artifact_urls(u[
|
23
|
+
remove_artifact_urls(u[:groupID],u[:artifactID])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -35,9 +35,9 @@ module Capistrano_Karaf
|
|
35
35
|
#
|
36
36
|
# Returns nothing
|
37
37
|
def remove_artifact_urls (groupID, artifactID)
|
38
|
-
urlsToRemove=list_urls.select {|url| url[
|
38
|
+
urlsToRemove=list_urls.select {|url| url[:groupID] == groupID && url[:artifactID] == artifactID}
|
39
39
|
urlsToRemove.each do |url|
|
40
|
-
remove_url "mvn:#{url[
|
40
|
+
remove_url "mvn:#{url[:groupID]}/#{url[:artifactID]}/#{url[:version]}/xml/features"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -126,8 +126,8 @@ module Capistrano_Karaf
|
|
126
126
|
#
|
127
127
|
# Returns true if the feature is installed
|
128
128
|
def feature_installed? (name)
|
129
|
-
feature = list_features.find {|f| f[
|
130
|
-
feature[
|
129
|
+
feature = list_features.find {|f| f[:name]==name}
|
130
|
+
feature[:status] == 'installed' unless feature.nil?
|
131
131
|
end
|
132
132
|
|
133
133
|
# Verify if a the bundle context is started
|
@@ -8,6 +8,7 @@ require 'net/http'
|
|
8
8
|
require 'rexml/document'
|
9
9
|
|
10
10
|
module Install
|
11
|
+
|
11
12
|
include Semantic_Versions
|
12
13
|
|
13
14
|
# Upgrade a list of projects in karaf
|
@@ -61,20 +62,27 @@ module Install
|
|
61
62
|
# Returns nothing
|
62
63
|
def upgrade (projects)
|
63
64
|
features = list_features()
|
64
|
-
projects.each do |project|
|
65
|
-
project = {:condition => :gt,
|
66
|
-
:hooks => {}}.merge(project)
|
67
|
-
|
68
|
-
install_new_feature = true
|
69
|
-
installed_features = find_installed_with_name(features, project[:feature])
|
70
65
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
66
|
+
to_uninstall, to_install = calculate_upgrade_actions(projects, features)
|
67
|
+
|
68
|
+
# first start uninstalling features in reverse order
|
69
|
+
to_uninstall.reverse.each do |f|
|
70
|
+
trigger_event(f, :before_uninstall_feature)
|
71
|
+
feature_uninstall(f[:name], f[:version])
|
72
|
+
trigger_event(f, :after_uninstall_feature)
|
73
|
+
end
|
74
|
+
|
75
|
+
# no install the new features
|
76
|
+
to_install.each do |f|
|
77
|
+
remove_otherversion_urls(f[:feature_url])
|
78
|
+
add_url(f[:feature_url])
|
79
|
+
trigger_event(f, :before_install_feature)
|
80
|
+
feature_install(f[:feature])
|
81
|
+
trigger_event(f, :after_install_feature)
|
77
82
|
end
|
83
|
+
|
84
|
+
list_bundles.find_all {|b| !b[:fragment] && b[:context] == "Failed"}
|
85
|
+
.each {|b| restart_bundle b[:id]}
|
78
86
|
end
|
79
87
|
|
80
88
|
# Extract the latest version from a maven-metadata file
|
@@ -101,33 +109,25 @@ module Install
|
|
101
109
|
end
|
102
110
|
|
103
111
|
def find_installed_with_name (features, name)
|
104
|
-
features.select {|f| f[
|
112
|
+
features.select {|f| f[:name] == name and f[:status] == "installed"}
|
105
113
|
end
|
106
114
|
|
107
|
-
def upgrade_feature(installed_features, feature)
|
115
|
+
def upgrade_feature(installed_features, feature, to_install, to_uninstall)
|
108
116
|
install_new_feature = true
|
109
117
|
p = method(feature[:condition])
|
110
118
|
|
111
119
|
installed_features.each do |f|
|
112
120
|
trigger_event(feature, :before_upgrade_feature)
|
113
|
-
if p.call(f[
|
114
|
-
|
115
|
-
feature_uninstall("#{feature[:feature]}/#{f['version']}")
|
116
|
-
trigger_event(feature, :after_uninstall_feature)
|
121
|
+
if p.call(f[:version], feature[:version])
|
122
|
+
to_uninstall << f
|
117
123
|
else
|
118
124
|
install_new_feature = false
|
119
125
|
end
|
120
126
|
end
|
121
127
|
|
122
|
-
|
123
|
-
|
124
|
-
remove_otherversion_urls(feature[:feature_url])
|
125
|
-
add_url(feature[:feature_url])
|
126
|
-
trigger_event(feature, :before_install_feature)
|
127
|
-
feature_install(feature[:feature])
|
128
|
-
trigger_event(feature, :after_install_feature)
|
128
|
+
if install_new_feature
|
129
|
+
to_install << feature
|
129
130
|
end
|
130
|
-
trigger_event(feature, :after_upgrade_feature)
|
131
131
|
end
|
132
132
|
|
133
133
|
def trigger_event (feature, event)
|
@@ -158,4 +158,35 @@ module Install
|
|
158
158
|
:hooks => hooks
|
159
159
|
}
|
160
160
|
end
|
161
|
+
|
162
|
+
def fragment_bundle? (bundle)
|
163
|
+
bundle[:fragment]
|
164
|
+
end
|
165
|
+
|
166
|
+
def calculate_upgrade_actions (projects, features)
|
167
|
+
to_uninstall = []
|
168
|
+
to_install = []
|
169
|
+
|
170
|
+
projects.each do |project|
|
171
|
+
project = {:condition => :gt,
|
172
|
+
:hooks => {}}.merge(project)
|
173
|
+
|
174
|
+
install_new_feature = true
|
175
|
+
installed_features = find_installed_with_name(features, project[:feature])
|
176
|
+
|
177
|
+
if project.keys.include? :groupId then
|
178
|
+
fh = create_feature_hash(project[:groupId], project[:repository], project[:feature], project[:version], project[:condition], project[:hooks])
|
179
|
+
upgrade_feature(installed_features, fh, to_install, to_uninstall)
|
180
|
+
else
|
181
|
+
upgrade_feature(installed_features, project, to_install, to_uninstall)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
return to_uninstall, to_install
|
186
|
+
end
|
187
|
+
|
188
|
+
def restart_bundle (id)
|
189
|
+
stop id
|
190
|
+
start id
|
191
|
+
end
|
161
192
|
end
|