Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Add plugin provider #115

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- 1.9.3
- 2.1.6
env:
- USE_SYSTEM_GECODE=1
before_install:
Expand Down
4 changes: 4 additions & 0 deletions chefignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ Vagrantfile
# Travis #
##########
.travis.yml

# Kitchen #
###########
.kitchen
90 changes: 90 additions & 0 deletions libraries/plugins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Encoding: utf-8
# Cookbook Name:: kibana
# Resrouce/Provider:: plugins
# Author:: John E. Vincent
# Author:: Paul Czarkowski
# License:: Apache 2.0
#
# Copyright 2014, John E. Vincent

class Chef
class Resource::KibanaPlugin < Chef::Resource::LWRPBase
provides :kibana_plugin
actions(:create, :remove)
default_action(:create)

attribute(:name, kind_of: String, name_attribute: true)
attribute(:base_directory, kind_of: String, default: lazy { node['kibana']['version'] })
attribute(:version, kind_of: String, default: lazy { node['kibana']['plugins_version'] })
attribute(:checksum, kind_of: String, default: lazy { node['kibana']['plugins_checksum'] })
attribute(:source_url, kind_of: String, default: lazy { node['kibana']['plugins_source_url'] })
attribute(:user, kind_of: String, default: lazy { node['kibana']['user'] })
attribute(:group, kind_of: String, default: lazy { node['kibana']['group'] })
attribute(:install_dir, kind_of: String, default: lazy { node['kibana']['install_dir'] })
attribute(:install_type, kind_of: String, default: lazy { node['kibana']['plugins_install_type'] })
attribute(:install_check, kind_of: String, default: lazy { node['kibana']['plugins_check_if_installed'] })
end

class Provider::KibanaPlugin < Chef::Provider::LWRPBase # ~FC057, ~FC058
provides :kibana_plugin
include Chef::DSL::Recipe # required under chef 12, see poise/poise #8

action :create do
kb_args = kibana_resources

case kb_args[:install_type]
when 'native'
ex = execute "bin/kibana plugin --install #{kb_args[:name]}" do
command "bin/kibana plugin --install #{kb_args[:name]}"
user kb_args[:user]
group kb_args[:group]
cwd "#{kb_args[:install_dir]}/kibana-#{kb_args[:base_directory]}"
notifies :restart, 'service[kibana]'
timeout 600
# this is a temp workaround to make the plugin command idempotent.
not_if { ::File.exist?("#kb_args[:install_dir]}/#{kb_args[:install_check]}") }
end
new_resource.updated_by_last_action(ex.updated_by_last_action?)
when 'tarball'
@run_context.include_recipe 'ark::default'
arkit = ark "#{kb_instance}_contrib" do
name kb_args[:kb_instance]
url kb_args[:kb_source_url]
checksum kb_args[:kb_checksum]
owner kb_args[:kb_user]
group kb_args[:kb_group]
mode 0755
version kb_args[:kb_version]
path kb_args[:kb_basedir]
action [:put]
notifies :restart, 'service[kibana]'
# this is a temp workaround to ensure idempotent.
not_if { ::File.exist?("#{kb_args[:install_dir]}/#{kb_args[:install_check]}") }
end
new_resource.updated_by_last_action(arkit.updated_by_last_action?)
else
Chef::Application.fatal!("Unknown install type: #{kb_args[:install_type]}")
end # case
end # action

action :remove do
Chef::Log.warn('Kibana plugin removal is not supported!')
end # action

private

def kibana_resources
kb = {
name: new_resource.name,
user: new_resource.user,
group: new_resource.group,
install_dir: new_resource.install_dir,
install_type: new_resource.install_type,
base_directory: new_resource.base_directory,
version: new_resource.version,
checksum: new_resource.checksum
}
kb
end # def
end # end class
end # end classes
6 changes: 6 additions & 0 deletions test/fixtures/kibana_test/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
include_recipe 'elasticsearch::default'
include_recipe 'kibana_lwrp::install'

# sample plugin installation
kibana_plugin 'kibana/timelion' do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be 'timelion' since that is the plugin name and directory name, right?

kibana_plugin 'timelion' do
  url 'kibana/timelion'
  action :install
end

If we had a resource with the actual plugin name, we might be able to better finagle an uninstall action using that name and looking for a directory by the same name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @davidski -- any thoughts on having the resource name be the plugin name?

install_type 'native'
action [:create]
end

elasticsearch_service 'elasticsearch' do
action :start
end