Class: KPM::BaseInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/kpm/base_installer.rb

Direct Known Subclasses

Installer

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

Constructor Details

#initialize(logger, nexus_config = nil, nexus_ssl_verify = nil) ⇒ BaseInstaller

Returns a new instance of BaseInstaller.



11
12
13
14
15
# File 'lib/kpm/base_installer.rb', line 11

def initialize(logger, nexus_config = nil, nexus_ssl_verify = nil)
  @logger = logger
  @nexus_config = nexus_config
  @nexus_ssl_verify = nexus_ssl_verify
end

Instance Method Details

#install_default_bundles(bundles_dir, specified_version = nil, kb_version = nil, force_download = false, verify_sha1 = true) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/kpm/base_installer.rb', line 188

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?
    info = KPM::KillbillServerArtifact.info(kb_version || LATEST_VERSION, @nexus_config, @nexus_ssl_verify)
    version = info['killbill-platform']
  end
  version ||= LATEST_VERSION

  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
  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)

  # The special JRuby bundle needs to be called jruby.jar
  # TODO .first - code smell
  unless info[:skipped]
    File.rename Dir.glob("#{destination}/killbill-platform-osgi-bundles-jruby-*.jar").first, destination.join('jruby.jar')
  end

  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, force_download = false, verify_sha1 = true) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/kpm/base_installer.rb', line 39

def install_kaui(specified_group_id=nil, specified_artifact_id=nil, specified_packaging=nil, specified_classifier=nil, specified_version=nil, specified_webapp_path=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

  @logger.debug("Installing Kaui: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} webapp_path=#{webapp_path}")
  KPM::KauiArtifact.pull(@logger,
                         group_id,
                         artifact_id,
                         packaging,
                         classifier,
                         version,
                         webapp_path,
                         nil,
                         force_download,
                         verify_sha1,
                         @nexus_config,
                         @nexus_ssl_verify)
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, force_download = false, verify_sha1 = true) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kpm/base_installer.rb', line 17

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, 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
  @logger.debug("Installing Kill Bill server: group_id=#{group_id} artifact_id=#{artifact_id} packaging=#{packaging} classifier=#{classifier} version=#{version} webapp_path=#{webapp_path}")
  KPM::KillbillServerArtifact.pull(@logger,
                                   group_id,
                                   artifact_id,
                                   packaging,
                                   classifier,
                                   version,
                                   webapp_path,
                                   nil,
                                   force_download,
                                   verify_sha1,
                                   @nexus_config,
                                   @nexus_ssl_verify)
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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
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
# File 'lib/kpm/base_installer.rb', line 62

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
  if plugin_key.nil?
    @logger.warn('Aborting installation: User needs to specify a pluginKey')
    return nil
  end

  # 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)
  return if !validate_installation_arg(plugin_key, 'group_id', specified_group_id, looked_up_group_id)
  return if !validate_installation_arg(plugin_key, 'artifact_id', specified_artifact_id, looked_up_artifact_id)
  return if !validate_installation_arg(plugin_key, 'packaging', specified_packaging, looked_up_packaging)
  return if !validate_installation_arg(plugin_key, 'type', specified_type, looked_up_type)
  return if !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
    @logger.warn("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)")
    return nil
  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
  if artifact_id.nil?
    @logger.warn("Aborting installation: unable to lookup plugin #{specified_artifact_id}")
    return nil
  end

  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
  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}
  return if !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)

  # 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, file_path, name, version, bundles_dir = nil, type = 'java') ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/kpm/base_installer.rb', line 151

def install_plugin_from_fs(plugin_key, file_path, name, version, bundles_dir=nil, type='java')
  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
  plugins_dir = bundles_dir.join('plugins')

  if type.to_s == 'java'
    destination = plugins_dir.join('java').join(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)

  artifact_info
end

#uninstall_plugin(plugin_name_or_key, plugin_version = nil, bundles_dir = nil) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/kpm/base_installer.rb', line 171

def uninstall_plugin(plugin_name_or_key, plugin_version=nil, bundles_dir=nil)
  bundles_dir = Pathname.new(bundles_dir || DEFAULT_BUNDLES_DIR).expand_path
  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)
  if plugin_name.nil?
    @logger.warn("Cannot uninstall plugin: Unknown plugin name or plugin key = #{plugin_name_or_key}");
    return
  end

  modified = plugins_manager.uninstall(plugin_name, plugin_version || :all)
  plugins_manager.remove_plugin_identifier_key(plugin_key)
  modified
end