Revert "Revert "upgrade to elasticsearch/elasticsearch 0.9.6""
[mirror/dsa-puppet.git] / 3rdparty / modules / elasticsearch / manifests / plugin.pp
1 # == Define: elasticsearch::plugin
2 #
3 # This define allows you to install arbitrary Elasticsearch plugins
4 # either by using the default repositories or by specifying an URL
5 #
6 # All default values are defined in the elasticsearch::params class.
7 #
8 #
9 # === Parameters
10 #
11 # [*module_dir*]
12 #   Directory name where the module will be installed
13 #   Value type is string
14 #   Default value: None
15 #   This variable is required
16 #
17 # [*ensure*]
18 #   Whether the plugin will be installed or removed.
19 #   Set to 'absent' to ensure a plugin is not installed
20 #   Value type is string
21 #   Default value: present
22 #   This variable is optional
23 #
24 # [*url*]
25 #   Specify an URL where to download the plugin from.
26 #   Value type is string
27 #   Default value: None
28 #   This variable is optional
29 #
30 # [*proxy_host*]
31 #   Proxy host to use when installing the plugin
32 #   Value type is string
33 #   Default value: None
34 #   This variable is optional
35 #
36 # [*proxy_port*]
37 #   Proxy port to use when installing the plugin
38 #   Value type is number
39 #   Default value: None
40 #   This variable is optional
41 #
42 # [*instances*]
43 #   Specify all the instances related
44 #   value type is string or array
45 #
46 # === Examples
47 #
48 # # From official repository
49 # elasticsearch::plugin{'mobz/elasticsearch-head': module_dir => 'head'}
50 #
51 # # From custom url
52 # elasticsearch::plugin{ 'elasticsearch-jetty':
53 #  module_dir => 'elasticsearch-jetty',
54 #  url        => 'https://oss-es-plugins.s3.amazonaws.com/elasticsearch-jetty/elasticsearch-jetty-0.90.0.zip',
55 # }
56 #
57 # === Authors
58 #
59 # * Matteo Sessa <mailto:matteo.sessa@catchoftheday.com.au>
60 # * Dennis Konert <mailto:dkonert@gmail.com>
61 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
62 #
63 define elasticsearch::plugin(
64     $module_dir,
65     $instances,
66     $ensure      = 'present',
67     $url         = undef,
68     $proxy_host  = undef,
69     $proxy_port  = undef,
70 ) {
71
72   include elasticsearch
73
74   Exec {
75     path      => [ '/bin', '/usr/bin', '/usr/local/bin' ],
76     cwd       => '/',
77     user      => $elasticsearch::elasticsearch_user,
78     tries     => 6,
79     try_sleep => 10,
80     timeout   => 600,
81   }
82
83   $notify_service = $elasticsearch::restart_on_change ? {
84     false   => undef,
85     default => Elasticsearch::Service[$instances],
86   }
87
88   if ($module_dir != '') {
89       validate_string($module_dir)
90   } else {
91       fail("module_dir undefined for plugin ${name}")
92   }
93
94   if ($proxy_host != undef and $proxy_port != undef) {
95     $proxy = " -DproxyPort=${proxy_port} -DproxyHost=${proxy_host}"
96   } else {
97     $proxy = '' # lint:ignore:empty_string_assignment
98   }
99
100   if ($url != '') {
101     validate_string($url)
102     $install_cmd = "${elasticsearch::plugintool}${proxy} -install ${name} -url ${url}"
103     $exec_rets = [0,1]
104   } else {
105     $install_cmd = "${elasticsearch::plugintool}${proxy} -install ${name}"
106     $exec_rets = [0,]
107   }
108
109   case $ensure {
110     'installed', 'present': {
111       $name_file_path = "${elasticsearch::plugindir}/${module_dir}/.name"
112       exec {"purge_plugin_${module_dir}_old":
113         command => "${elasticsearch::plugintool} --remove ${module_dir}",
114         onlyif  => "test -e ${elasticsearch::plugindir}/${module_dir} && test \"$(cat ${name_file_path})\" != '${name}'",
115         before  => Exec["install_plugin_${name}"],
116       }
117       exec {"install_plugin_${name}":
118         command => $install_cmd,
119         creates => "${elasticsearch::plugindir}/${module_dir}",
120         returns => $exec_rets,
121         notify  => $notify_service,
122         require => File[$elasticsearch::plugindir],
123       }
124       file {$name_file_path:
125         ensure  => file,
126         content => $name,
127         require => Exec["install_plugin_${name}"],
128       }
129     }
130     default: {
131       exec {"remove_plugin_${name}":
132         command => "${elasticsearch::plugintool} --remove ${module_dir}",
133         onlyif  => "test -d ${elasticsearch::plugindir}/${module_dir}",
134         notify  => $notify_service,
135       }
136     }
137   }
138 }