Module: Install

Includes:
Semantic_Versions
Defined in:
lib/capistrano-karaf/install.rb

Defined Under Namespace

Classes: LatestVersionNotDefinedError

Instance Method Summary collapse

Methods included from Semantic_Versions

#eq, #gt, #lt

Instance Method Details

#all_bundles_started?(expected_bundles) ⇒ Boolean

Verify if all bundles are installed and started.

Parameters

- expected_bundles - A list of strings containing the bundle names.

Example

all_bundles_started? ["blub", "blubber"]
# returns true

Returns true when all bundles are correctly installed and started

Returns:

  • (Boolean)


130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/capistrano-karaf/install.rb', line 130

def all_bundles_started? (expected_bundles)
  installed_bundles = list_bundles.collect {|b| b[:name]}
  not_installed_bundles = expected_bundles - installed_bundles
  raise "The following bundles are missing: #{not_installed_bundles}" unless not_installed_bundles.empty?

  wait_for_all_bundles do |b|
    if expected_bundles.include? b[:name]
      b[:context] == "Started"
    else
      true
    end
  end
  true
end

#extract_latest_version(xml) ⇒ Object

Extract the latest version from a maven-metadata file

Parameters

- xml - A string containing the xml file

Example

extract_latest_version(xml)
# returns "2.19.1-SNAPSHOT"

Returns a string containing the version



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/capistrano-karaf/install.rb', line 158

def extract_latest_version (xml)
  doc = REXML::Document.new(xml)

  latest = nil
  REXML::XPath.each(doc, "/metadata/versioning/versions/version") do |el|
    if latest.nil?
      latest = el.text
    elsif gt(latest, el.text)
      latest = el.text
    end
  end

  unless latest.nil? then
    latest
  else
    raise LatestVersionNotDefinedError
  end
end

#upgrade(projects, args = {}) ⇒ Object

Upgrade a list of projects in karaf

The following steps are performed to do an upgrade action:

- Compare the requested features with the installed features.
  This will generate a list of features to remove and to install.
- Reduce the runlevel to the level configured in the :startlevel_before_upgrade option.
  This ensures that the dependencies are stopped when the startlevels are managed properly.
- Uninstall the features to uninstall in reverse order.
- Install the features to install.
- Reset the runlevel to the previous state.
- Restart failed bundles.

projects - a list of hashes containing either:

- :feature_url - the string containing the feature url
- :feature     - the string containing the feature name to upgrade
- :version     - the string containing the version
- :condition   - specifies when to upgrade the feature,  one of [ :lt, :eq, :gt ( the default ) ]
- :hooks       - a map containing the hook name and the list of methods to trigger
                   trigger can be one of :before_upgrade_feature,
                                         :before_uninstall_feature,
                                         :after_uninstall_feature,
                                         :before_install_feature,
                                         :after_install_feature,
                                         :after_upgrade_feature

or:
- :groupId     - the string containing the groupId of the repository
- :repository  - the string containing the name of the feature repository
- :feature     - the string containing the name of the feature
- :version     - the string containing the version or :latest
- :condition   - specifies when to upgrade the feature,  one of [ :lt, :eq, :gt ( the default ) ]
- :hooks       - a map containing the hook name and the list of methods to trigger
                   trigger can be one of :before_upgrade_feature,
                                         :before_uninstall_feature,
                                         :after_uninstall_feature,
                                         :before_install_feature,
                                         :after_install_feature,
                                         :after_upgrade_feature

args - a hash containing optional args:

- :startlevel_before_upgrade - the number of the startlevel to go to before upgrading
- :startlevel_after_upgrade - the number of the startlevel to go to after upgrading

Examples

 upgrade([{:feature_url => "mvn:repository/featurea/xml/features/1.1.0",
           :feature => "featurea",
           :version => "1.1.0",
           :condition => :gt
          },
          {:feature_url => "mvn:repository/featureb/xml/features/1.2.0",
           :feature => "featureb",
           :version => "1.2.0",
           :condition => :gt
          },
          {:groupId => "repository",
           :repository => "featureb",
           :feature => "featureb",
           :version => :latest             
          }])
# => nil

Returns nothing



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/capistrano-karaf/install.rb', line 78

def upgrade (projects, args={})
  args = {:startlevel_before_upgrade => 60, :startlevel_after_upgrade => 100}.merge(args)
  features = list_features
  puts "Features #{features}"
  to_uninstall, to_install = calculate_upgrade_actions(projects, features)
  puts "To uninstall #{to_uninstall}"
  puts "To install #{to_install}"

  begin
    # decrease the start level

    unless to_uninstall.empty?
      startlevel_set args[:startlevel_before_upgrade]
      ensure_all_bundles_are_stopped args[:startlevel_before_upgrade]

      # uninstall the calculated features in reverse order
      to_uninstall.reverse.each do |f| 
        trigger_event(f, :before_uninstall_feature)
        feature_uninstall(f[:name], f[:version])
        trigger_event(f, :after_uninstall_feature)
      end
    end

    # install the new features
    to_install.each do |f|
      remove_otherversion_urls(f[:feature_url])
      add_url(f[:feature_url])
      trigger_event(f, :before_install_feature)
      feature_install(f[:feature])
      trigger_event(f, :after_install_feature)
    end
  ensure
    puts "Restoring the level to #{args[:startlevel_after_upgrade]}"
    
    # restore the runlevel to the level before upgrading
    startlevel_set args[:startlevel_after_upgrade]
    ensure_all_bundles_are_restarted args[:startlevel_before_upgrade], args[:startlevel_after_upgrade]
  end
    
  restart_failed_bundles
end