Class: KPM::BaseInstaller
- Inherits:
-
Object
- Object
- KPM::BaseInstaller
- Defined in:
- lib/kpm/base_installer.rb
Direct Known Subclasses
Constant Summary collapse
- LATEST_VERSION =
'LATEST'- SHA1_FILENAME =
'sha1.yml'- DEFAULT_BUNDLES_DIR =
Pathname.new('/var').join('tmp').join('bundles').to_s
Instance Method Summary collapse
-
#initialize(logger, nexus_config = nil, nexus_ssl_verify = nil) ⇒ BaseInstaller
constructor
A new instance of BaseInstaller.
- #install_default_bundles(bundles_dir, specified_version = nil, kb_version = nil, force_download = false, verify_sha1 = true) ⇒ Object
- #install_kaui(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true) ⇒ Object
- #install_killbill_server(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true) ⇒ Object
- #install_plugin(plugin_key, raw_kb_version = nil, specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, bundles_dir = nil, specified_type = nil, force_download = false, verify_sha1 = true, verify_jruby_jar = false) ⇒ Object
- #install_plugin_from_fs(plugin_key, raw_file_path, name, version, bundles_dir = nil, type = 'java') ⇒ Object
- #uninstall_plugin(plugin_name_or_key, plugin_version = nil, bundles_dir = nil) ⇒ Object
Constructor Details
#initialize(logger, nexus_config = nil, nexus_ssl_verify = nil) ⇒ BaseInstaller
Returns a new instance of BaseInstaller.
12 13 14 15 16 17 |
# File 'lib/kpm/base_installer.rb', line 12 def initialize(logger, nexus_config = nil, nexus_ssl_verify = nil) @logger = logger @nexus_config = nexus_config @nexus_ssl_verify = nexus_ssl_verify @trace_logger = KPM::TraceLogger.new end |
Instance Method Details
#install_default_bundles(bundles_dir, specified_version = nil, kb_version = nil, force_download = false, verify_sha1 = true) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/kpm/base_installer.rb', line 212 def install_default_bundles(bundles_dir, specified_version = nil, kb_version = nil, force_download = false, verify_sha1 = true) group_id = 'org.kill-bill.billing' artifact_id = 'killbill-platform-osgi-bundles-defaultbundles' packaging = 'tar.gz' classifier = nil version = specified_version if version.nil? || version == LATEST_VERSION sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}" info = KPM::KillbillServerArtifact.info(kb_version || LATEST_VERSION, sha1_file, force_download, verify_sha1, @nexus_config, @nexus_ssl_verify) version = info['killbill-platform'] end version ||= LATEST_VERSION bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR). destination = bundles_dir.join('platform') sha1_file = bundles_dir.join(SHA1_FILENAME) @logger.debug("Installing default bundles: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} destination=#{destination}") info = KPM::BaseArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, destination, sha1_file, force_download, verify_sha1, @nexus_config, @nexus_ssl_verify) @trace_logger.add('default_bundles', nil, info.merge('status' => (info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'), :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier)) # The special JRuby bundle needs to be called jruby.jar # TODO .first - code smell File.rename Dir.glob("#{destination}/killbill-platform-osgi-bundles-jruby-*.jar").first, destination.join('jruby.jar') unless info[:skipped] info end |
#install_kaui(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/kpm/base_installer.rb', line 53 def install_kaui(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true) group_id = specified_group_id || KPM::BaseArtifact::KAUI_GROUP_ID artifact_id = specified_artifact_id || KPM::BaseArtifact::KAUI_ARTIFACT_ID packaging = specified_packaging || KPM::BaseArtifact::KAUI_PACKAGING classifier = specified_classifier || KPM::BaseArtifact::KAUI_CLASSIFIER version = specified_version || LATEST_VERSION webapp_path = specified_webapp_path || KPM.root bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR). sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}" @logger.debug("Installing Kaui: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} webapp_path=#{webapp_path}") artifact_info = KPM::KauiArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, webapp_path, sha1_file, force_download, verify_sha1, @nexus_config, @nexus_ssl_verify) # store trace info to be returned as JSON by the KPM::Installer.install method @trace_logger.add('kaui', nil, artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'), :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier)) end |
#install_killbill_server(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kpm/base_installer.rb', line 19 def install_killbill_server(specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, specified_webapp_path = nil, bundles_dir = nil, force_download = false, verify_sha1 = true) group_id = specified_group_id || KPM::BaseArtifact::KILLBILL_GROUP_ID artifact_id = specified_artifact_id || KPM::BaseArtifact::KILLBILL_ARTIFACT_ID packaging = specified_packaging || KPM::BaseArtifact::KILLBILL_PACKAGING classifier = specified_classifier || KPM::BaseArtifact::KILLBILL_CLASSIFIER version = specified_version || LATEST_VERSION webapp_path = specified_webapp_path || KPM.root bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR). sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}" if version == LATEST_VERSION latest_stable_version = KPM::Installer.get_kb_latest_stable_version version = latest_stable_version unless latest_stable_version.nil? end @logger.debug("Installing Kill Bill server: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} webapp_path=#{webapp_path}") artifact_info = KPM::KillbillServerArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, webapp_path, sha1_file, force_download, verify_sha1, @nexus_config, @nexus_ssl_verify) # store trace info to be returned as JSON by the KPM::Installer.install method @trace_logger.add('killbill', nil, artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'), :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier)) end |
#install_plugin(plugin_key, raw_kb_version = nil, specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, bundles_dir = nil, specified_type = nil, force_download = false, verify_sha1 = true, verify_jruby_jar = false) ⇒ Object
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/kpm/base_installer.rb', line 82 def install_plugin(plugin_key, raw_kb_version = nil, specified_group_id = nil, specified_artifact_id = nil, specified_packaging = nil, specified_classifier = nil, specified_version = nil, bundles_dir = nil, specified_type = nil, force_download = false, verify_sha1 = true, verify_jruby_jar = false) # plugin_key needs to exist raise ArgumentError, 'Aborting installation: User needs to specify a pluginKey' if plugin_key.nil? # Lookup artifact and perform validation against input looked_up_group_id, looked_up_artifact_id, looked_up_packaging, looked_up_classifier, looked_up_version, looked_up_type = KPM::PluginsDirectory.lookup(plugin_key, true, raw_kb_version) validate_installation_arg!(plugin_key, 'group_id', specified_group_id, looked_up_group_id) validate_installation_arg!(plugin_key, 'artifact_id', specified_artifact_id, looked_up_artifact_id) validate_installation_arg!(plugin_key, 'packaging', specified_packaging, looked_up_packaging) validate_installation_arg!(plugin_key, 'type', specified_type, looked_up_type) validate_installation_arg!(plugin_key, 'classifier', specified_classifier, looked_up_classifier) # If there is no entry in plugins_directory.yml and the group_id is not the killbill default group_id, the key provided must be a user key and must have a namespace if looked_up_artifact_id.nil? && specified_group_id != KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_GROUP_ID && specified_group_id != KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID && plugin_key.split(':').size == 1 raise ArgumentError, "Aborting installation: pluginKey = #{plugin_key} does not exist in plugin_directory.yml so format of the key must have a user namespace (e.g namespace:key)" end # Specified parameters have always precedence except for the artifact_id (to map stripe to stripe-plugin) artifact_id = looked_up_artifact_id || specified_artifact_id raise ArgumentError, "Aborting installation: unable to lookup plugin #{specified_artifact_id}" if artifact_id.nil? bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR). plugins_dir = bundles_dir.join('plugins') type = specified_type || looked_up_type if type.to_s == 'java' group_id = specified_group_id || looked_up_group_id || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_GROUP_ID packaging = specified_packaging || looked_up_packaging || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_PACKAGING classifier = specified_classifier || looked_up_classifier || KPM::BaseArtifact::KILLBILL_JAVA_PLUGIN_CLASSIFIER version = specified_version || looked_up_version || LATEST_VERSION destination = plugins_dir.join('java').join(artifact_id).join(version) else warn_if_jruby_jar_missing(bundles_dir) if verify_jruby_jar group_id = specified_group_id || looked_up_group_id || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_GROUP_ID packaging = specified_packaging || looked_up_packaging || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_PACKAGING classifier = specified_classifier || looked_up_classifier || KPM::BaseArtifact::KILLBILL_RUBY_PLUGIN_CLASSIFIER version = specified_version || looked_up_version || LATEST_VERSION destination = plugins_dir.join('ruby') end sha1_file = "#{bundles_dir}/#{SHA1_FILENAME}" plugins_manager = PluginsManager.new(plugins_dir, @logger) _, plugin_name = plugins_manager.get_plugin_key_and_name(plugin_key) # Before we do the install we verify that the entry we have in the plugin_identifiers.json matches our current request coordinate_map = { group_id: group_id, artifact_id: artifact_id, packaging: packaging, classifier: classifier } validate_plugin_key!(plugins_dir, plugin_key, coordinate_map) @logger.debug("Installing plugin: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} destination=#{destination}") artifact_info = KPM::KillbillPluginArtifact.pull(@logger, group_id, artifact_id, packaging, classifier, version, plugin_name, destination, sha1_file, force_download, verify_sha1, @nexus_config, @nexus_ssl_verify) # store trace info to be returned as JSON by the KPM::Installer.install method @trace_logger.add('plugins', plugin_key, artifact_info.merge('status' => (artifact_info[:skipped] ? 'UP_TO_DATE' : 'INSTALLED'), :group_id => group_id, :artifact_id => artifact_id, :packaging => packaging, :classifier => classifier)) # Update with resolved version coordinate_map[:version] = artifact_info[:version] mark_as_active(plugins_dir, artifact_info, artifact_id) update_plugin_identifier(plugins_dir, plugin_key, type.to_s, coordinate_map, artifact_info) artifact_info end |
#install_plugin_from_fs(plugin_key, raw_file_path, name, version, bundles_dir = nil, type = 'java') ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/kpm/base_installer.rb', line 163 def install_plugin_from_fs(plugin_key, raw_file_path, name, version, bundles_dir = nil, type = 'java') # Expand glob if needed file_paths = Dir.glob(raw_file_path) raise ArgumentError, "Cannot install plugin: no file found at #{raw_file_path}" if file_paths.empty? raise ArgumentError, "Cannot install plugin: multiple files found at #{raw_file_path}" if file_paths.size > 1 file_path = file_paths[0] bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR). plugins_dir = bundles_dir.join('plugins') version = Utils.get_version_from_file_path(file_path) if version.nil? raise ArgumentError, 'Cannot install plugin: missing version' if version.nil? if type.to_s == 'java' plugin_name = name.nil? ? Utils.get_plugin_name_from_file_path(file_path) : name destination = plugins_dir.join('java').join(plugin_name).join(version) else destination = plugins_dir.join('ruby') end artifact_info = KPM::KillbillPluginArtifact.pull_from_fs(@logger, file_path, destination) artifact_info[:version] ||= version mark_as_active(plugins_dir, artifact_info) update_plugin_identifier(plugins_dir, plugin_key, type.to_s, nil, artifact_info) # store trace info to be returned as JSON by the KPM::Installer.install method @trace_logger.add('plugins', plugin_key, artifact_info.merge('status' => 'INSTALLED')) artifact_info end |
#uninstall_plugin(plugin_name_or_key, plugin_version = nil, bundles_dir = nil) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/kpm/base_installer.rb', line 198 def uninstall_plugin(plugin_name_or_key, plugin_version = nil, bundles_dir = nil) bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR). plugins_dir = bundles_dir.join('plugins') plugins_manager = PluginsManager.new(plugins_dir, @logger) plugin_key, plugin_name = plugins_manager.get_plugin_key_and_name(plugin_name_or_key) raise ArgumentError, "Cannot uninstall plugin: Unknown plugin name or plugin key = #{plugin_name_or_key}" if plugin_name.nil? modified = plugins_manager.uninstall(plugin_name, plugin_version || :all) plugins_manager.remove_plugin_identifier_key(plugin_key) modified end |