capistrano-karaf 1.6.3 → 1.6.4

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.
@@ -127,6 +127,16 @@ module Capistrano_Karaf
127
127
  execute(:startlevel, level)
128
128
  end
129
129
 
130
+ def startlevel
131
+ r = capture(:startlevel)
132
+ m = r.match(/Level (\d+)/)
133
+ if m then
134
+ m[0].to_i
135
+ else
136
+ raise 'Invalid response from startlevel'
137
+ end
138
+ end
139
+
130
140
 
131
141
  # Start a bundle with the specified bundleId on the karaf server
132
142
  #
@@ -12,7 +12,18 @@ module Install
12
12
  include Semantic_Versions
13
13
 
14
14
  # Upgrade a list of projects in karaf
15
- #
15
+ #
16
+ # The following steps are performed to do an upgrade action:
17
+ #
18
+ # - Compare the requested features with the installed features.
19
+ # This will generate a list of features to remove and to install.
20
+ # - Reduce the runlevel to the level configured in the :startlevel_before_upgrade option.
21
+ # This ensures that the dependencies are stopped when the startlevels are managed properly.
22
+ # - Uninstall the features to uninstall in reverse order.
23
+ # - Install the features to install.
24
+ # - Reset the runlevel to the previous state.
25
+ # - Restart failed bundles.
26
+ #
16
27
  # projects - a list of hashes containing either:
17
28
  # - :feature_url - the string containing the feature url
18
29
  # - :feature - the string containing the feature name to upgrade
@@ -43,8 +54,6 @@ module Install
43
54
  #
44
55
  # args - a hash containing optional args:
45
56
  # - :startlevel_before_upgrade - the number of the startlevel to go to before upgrading
46
- # - :startlevel_after_upgrade - the number of the startlevel to go to after upgrading
47
- #
48
57
  #
49
58
  # Examples
50
59
  # upgrade([{:feature_url => "mvn:repository/featurea/xml/features/1.1.0",
@@ -66,52 +75,42 @@ module Install
66
75
  #
67
76
  # Returns nothing
68
77
  def upgrade (projects, args={})
69
- args = {:startlevel_before_upgrade => 60, :startlevel_after_upgrade => 100}.merge(args)
78
+ args = {:startlevel_before_upgrade => 60}.merge(args)
79
+ initial_level = startlevel
70
80
  features = list_features()
71
81
 
72
82
  to_uninstall, to_install = calculate_upgrade_actions(projects, features)
73
83
 
74
- # decrease the start level
75
- startlevel_set args[:startlevel_before_upgrade]
84
+ begin
85
+ # decrease the start level
86
+ startlevel_set args[:startlevel_before_upgrade]
87
+ ensure_all_bundles_are_stopped args[:startlevel_before_upgrade]
76
88
 
77
- wait_for_all_bundles(:timeout => 180, :sleeptime => 10) do |b|
78
- if b[:level].to_i > args[:startlevel_before_upgrade]
79
- ["Resolved", "Installed"].include? b[:status]
80
- else
81
- true
89
+ # uninstall the calculated features in reverse order
90
+ to_uninstall.reverse.each do |f|
91
+ trigger_event(f, :before_uninstall_feature)
92
+ feature_uninstall(f[:name], f[:version])
93
+ trigger_event(f, :after_uninstall_feature)
82
94
  end
83
- end
84
-
85
- # first start uninstalling features in reverse order
86
- to_uninstall.reverse.each do |f|
87
- trigger_event(f, :before_uninstall_feature)
88
- feature_uninstall(f[:name], f[:version])
89
- trigger_event(f, :after_uninstall_feature)
90
- end
91
95
 
92
- # now install the new features
93
- to_install.each do |f|
94
- remove_otherversion_urls(f[:feature_url])
95
- add_url(f[:feature_url])
96
- trigger_event(f, :before_install_feature)
97
- feature_install(f[:feature])
98
- trigger_event(f, :after_install_feature)
96
+ # install the new features
97
+ to_install.each do |f|
98
+ remove_otherversion_urls(f[:feature_url])
99
+ add_url(f[:feature_url])
100
+ trigger_event(f, :before_install_feature)
101
+ feature_install(f[:feature])
102
+ trigger_event(f, :after_install_feature)
103
+ end
104
+ rescue
105
+ # restore the runlevel to the level before upgrading
106
+ startlevel_set initial_level
107
+ ensure_all_bundles_are_restarted args[:startlevel_before_upgrade], initial_level
99
108
  end
100
-
109
+
101
110
  # increase the start level
102
111
  startlevel_set args[:startlevel_after_upgrade]
103
- wait_for_all_bundles(:timeout => 180, :sleeptime => 10) do |b|
104
- if (b[:level].to_i > args[:startlevel_before_upgrade] and
105
- b[:level].to_i <= args[:startlevel_after_upgrade])
106
- ["Active","Resolved"].include? b[:status]
107
- else
108
- true
109
- end
110
- end
111
-
112
- list_bundles.find_all {|b| !b[:fragment] && b[:context] == "Failed"}
113
- .each {|b| restart_bundle b[:id]}
114
112
 
113
+ restart_failed_bundles
115
114
  end
116
115
 
117
116
  # Extract the latest version from a maven-metadata file
@@ -218,4 +217,30 @@ module Install
218
217
  stop id
219
218
  start id
220
219
  end
220
+
221
+ def ensure_all_bundles_are_stopped (level_before_upgrade)
222
+ wait_for_all_bundles(:timeout => 180, :sleeptime => 10) do |b|
223
+ if b[:level].to_i > level_before_upgrade
224
+ ["Resolved", "Installed"].include? b[:status]
225
+ else
226
+ true
227
+ end
228
+ end
229
+ end
230
+
231
+ def ensure_all_bundles_are_restarted (level_before_upgrade, initial_level)
232
+ wait_for_all_bundles(:timeout => 180, :sleeptime => 10) do |b|
233
+ if (b[:level].to_i > level_before_upgrade and
234
+ b[:level].to_i <= initial_level)
235
+ ["Active","Resolved"].include? b[:status]
236
+ else
237
+ true
238
+ end
239
+ end
240
+ end
241
+
242
+ def restart_failed_bundles
243
+ list_bundles.find_all {|b| !b[:fragment] && b[:context] == "Failed"}
244
+ .each {|b| restart_bundle b[:id]}
245
+ end
221
246
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-karaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-20 00:00:00.000000000 Z
12
+ date: 2014-07-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: brecht.hoflack@gmail.com