Skip to content

Commit

Permalink
Deprecate uninstall for Plugin Manager
Browse files Browse the repository at this point in the history
Adds remove and deprecates uninstall

Fixes elastic#6041

Fixes elastic#6042
  • Loading branch information
suyograo committed Oct 13, 2016
1 parent 3b1a0fd commit 44a52ff
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/static/glossary.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

[[glossary-plugin-manager]]plugin manager::
Accessed via the `bin/logstash-plugin` script, the plugin manager enables you to manage the lifecycle of
<<glossary-plugin,plugins>> in your Logstash deployment. You can install, uninstall, and upgrade plugins by using the
<<glossary-plugin,plugins>> in your Logstash deployment. You can install, remove, and upgrade plugins by using the
plugin manager Command Line Interface (CLI).

[[shipper]]shipper::
Expand Down
4 changes: 2 additions & 2 deletions docs/static/plugin-manager.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Logstash has a rich collection of input, filter, codec and output plugins. Plugins are available as self-contained
packages called gems and hosted on RubyGems.org. The plugin manager accessed via `bin/logstash-plugin` script is used to manage the
lifecycle of plugins in your Logstash deployment. You can install, uninstall and upgrade plugins using the Command Line
lifecycle of plugins in your Logstash deployment. You can install, remove and upgrade plugins using the Command Line
Interface (CLI) invocations described below.

[float]
Expand Down Expand Up @@ -94,7 +94,7 @@ If you need to remove plugins from your Logstash installation:

[source,shell]
----------------------------------
bin/logstash-plugin uninstall logstash-output-kafka
bin/logstash-plugin remove logstash-output-kafka
----------------------------------

[[proxy-plugins]]
Expand Down
7 changes: 5 additions & 2 deletions lib/pluginmanager/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module PluginManager
require "pluginmanager/gemfile"
require "pluginmanager/install"
require "pluginmanager/uninstall"
require "pluginmanager/remove"
require "pluginmanager/list"
require "pluginmanager/update"
require "pluginmanager/pack"
Expand All @@ -27,13 +28,15 @@ module PluginManager
class Error < StandardError; end

class Main < Clamp::Command
subcommand "install", "Install a plugin", LogStash::PluginManager::Install
subcommand "uninstall", "Uninstall a plugin", LogStash::PluginManager::Uninstall
subcommand "list", "List all installed Logstash plugins", LogStash::PluginManager::List
subcommand "install", "Install a Logstash plugin", LogStash::PluginManager::Install
subcommand "remove", "Remove a Logstash plugin", LogStash::PluginManager::Remove
subcommand "update", "Update a plugin", LogStash::PluginManager::Update
subcommand "pack", "Package currently installed plugins", LogStash::PluginManager::Pack
subcommand "unpack", "Unpack packaged plugins", LogStash::PluginManager::Unpack
subcommand "list", "List all installed plugins", LogStash::PluginManager::List
subcommand "generate", "Create the foundation for a new plugin", LogStash::PluginManager::Generate
subcommand "uninstall", "Uninstall a plugin. Deprecated: Please use remove instead", LogStash::PluginManager::Uninstall
end
end
end
Expand Down
41 changes: 41 additions & 0 deletions lib/pluginmanager/remove.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# encoding: utf-8
require "pluginmanager/command"

class LogStash::PluginManager::Remove < LogStash::PluginManager::Command

parameter "PLUGIN", "plugin name"

def execute
signal_error("File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)

##
# Need to setup the bundler status to enable uninstall of plugins
# installed as local_gems, otherwise gem:specification is not
# finding the plugins
##
LogStash::Bundler.setup!({:without => [:build, :development]})

# make sure this is an installed plugin and present in Gemfile.
# it is not possible to uninstall a dependency not listed in the Gemfile, for example a dependent codec
signal_error("This plugin has not been previously installed, aborting") unless LogStash::PluginManager.installed_plugin?(plugin, gemfile)

# since we previously did a gemfile.find(plugin) there is no reason why
# remove would not work (return nil) here
if gemfile.remove(plugin)
gemfile.save

puts("Removing #{plugin}")

# any errors will be logged to $stderr by invoke!
# output, exception = LogStash::Bundler.invoke!(:install => true, :clean => true)
output = LogStash::Bundler.invoke!(:install => true, :clean => true)

remove_unused_locally_installed_gems!
end
rescue => exception
gemfile.restore!
report_exception("Remove Aborted", exception)
ensure
display_bundler_output(output)
end
end
5 changes: 4 additions & 1 deletion lib/pluginmanager/uninstall.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# encoding: utf-8
require "pluginmanager/command"

# TODO: SR: Delete this file in 6.0, as we deprecated uninstall in favar of remove to be consistent with the stack

class LogStash::PluginManager::Uninstall < LogStash::PluginManager::Command

parameter "PLUGIN", "plugin name"

def execute
signal_error("File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
puts "uninstall subcommand is deprecated and will be removed in the next major version. Please use logstash-plugin remove instead."

signal_error("File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
##
# Need to setup the bundler status to enable uninstall of plugins
# installed as local_gems, otherwise gem:specification is not
Expand Down
2 changes: 2 additions & 0 deletions qa/acceptance/spec/lib/cli_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative "../shared_examples/cli/logstash-plugin/install"
require_relative "../shared_examples/cli/logstash-plugin/list"
require_relative "../shared_examples/cli/logstash-plugin/uninstall"
require_relative "../shared_examples/cli/logstash-plugin/remove"
require_relative "../shared_examples/cli/logstash-plugin/update"

# This is the collection of test for the CLI interface, this include the plugin manager behaviour,
Expand All @@ -16,6 +17,7 @@
it_behaves_like "logstash install", logstash
it_behaves_like "logstash list", logstash
it_behaves_like "logstash uninstall", logstash
it_behaves_like "logstash remove", logstash
it_behaves_like "logstash update", logstash
end
end
35 changes: 35 additions & 0 deletions qa/acceptance/spec/shared_examples/cli/logstash-plugin/remove.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# encoding: utf-8
require_relative "../../../spec_helper"
require "logstash/version"
require "fileutils"

shared_examples "logstash uninstall" do |logstash|
describe "logstash uninstall on #{logstash.hostname}" do
before :each do
logstash.install({:version => LOGSTASH_VERSION})
end

after :each do
logstash.uninstall
end

context "when the plugin isn't installed" do
it "fails to remove it" do
result = logstash.run_command_in_path("bin/logstash-plugin remove logstash-filter-qatest")
expect(result.stderr).to match(/ERROR: Remove Aborted, message: This plugin has not been previously installed, aborting/)
end
end

# Disabled because of this bug https://github.com/elastic/logstash/issues/5286
xcontext "when the plugin is installed" do
it "succesfully removes it" do
result = logstash.run_command_in_path("bin/logstash-plugin install logstash-filter-qatest")
expect(logstash).to have_installed?("logstash-filter-qatest")

result = logstash.run_command_in_path("bin/logstash-plugin remove logstash-filter-qatest")
expect(result.stdout).to match(/^Removing logstash-filter-qatest/)
expect(logstash).not_to have_installed?("logstash-filter-qatest")
end
end
end
end

0 comments on commit 44a52ff

Please sign in to comment.