Skip to content

Commit

Permalink
[private-chef-cookbooks] Add support for ElasticSearch index creation
Browse files Browse the repository at this point in the history
`chef-server-ctl reconfigure` can now correctly create the required
elasticsearch search index for chef-server.
  • Loading branch information
stevendanna committed Oct 29, 2015
1 parent c0f7dde commit 1aeeb89
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'chef/provider/lwrp_base'

class Chef
class Provider
class ElasticSearchIndex < Chef::Provider::LWRPBase
use_inline_resources if defined?(:use_inlined_resources)

action :create do
if ! index_exists?
converge_by "Creating elasticsearch index #{new_resource.index_name}" do
solr_server.put(new_resource.index_name, Chef::JSONCompat.to_json(new_resource.index_definition))
end
end
end

action :destroy do
if index_exists?
converge_by "Deleting elasticsearch index #{new_resource.index_name}" do
solr_server.delete(new_resource.index_name)
end
end
end

def index_exists?
solr_server.get("/#{new_resource.index_name}")
true
rescue Net::HTTPServerException => e
if e.response && e.response.code == "404"
false
else
raise
end
end

def solr_server
@solr_server ||= Chef::HTTP.new(new_resource.server_url)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'chef/resource/lwrp_base'

class Chef
class Resource
class ElasticSearchIndex < Chef::Resource::LWRPBase
self.resource_name = 'elasticsearch_index'

actions [:create, :destroy]
default_action :create
attribute :index_name, :name_attribute => true
attribute :server_url, :kind_of => String
attribute :index_definition, :kind_of => Hash
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,55 @@
# limitations under the License.
#

Chef::Log.warn("External Solr Support does not include configuring the Solr/Cloudsearch schema.")

case node['private_chef']['opscode-erchef']['search_provider']
when 'solr'
Chef::Log.warn("External Solr Support does not include configuring the Solr schema.")
when 'elasticsearch'
elasticsearch_index "chef" do
server_url node['private_chef']['opscode-solr4']['external_url']
index_definition({"settings" => {
"analysis" => {
"analyzer" => {
"default" => {
"type" => "whitespace"
}
}
}
},
"mappings" => {
"object" => {
"_source" => { "enabled" => false },
"_all" => { "enabled" => false },
"properties" => {
"X_CHEF_database_CHEF_X" => { "type" => "string",
"index" => "not_analyzed",
"norms" => {
"enabled" => false
}
},
"X_CHEF_type_CHEF_X" => { "type" => "string",
"index" => "not_analyzed",
"norms" => {
"enabled" => false
}
},
"X_CHEF_id_CHEF_X" => { "type" => "string",
"index" => "not_analyzed",
"norms" => {
"enabled" => false
}
},
"data_bag" => { "type" => "string",
"index" => "not_analyzed",
"norms" => {
"enabled" => false
}
},
"content" => { "type" => "string", "index" => "analyzed"}
}
}
}
})
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
{max_request_size, <%= node['private_chef']['opscode-erchef']['max_request_size'] %>},
{server_version, "<%= node['private_chef']['version'] %>"},
{health_ping_timeout, 400},
{health_ping_modules, [oc_chef_authz, chef_sql, chef_solr]},
{health_ping_modules, [oc_chef_authz, chef_sql, chef_<%= node['private_chef']['opscode-erchef']['search_provider'] %>]},
{base_resource_url, <%= @helper.erl_atom_or_string(node['private_chef']['opscode-erchef']['base_resource_url']) %>},
{bulk_fetch_batch_size, <%= @bulk_fetch_batch_size %>},
{strict_search_result_acls, <%= @strict_search_result_acls %>},
Expand Down

0 comments on commit 1aeeb89

Please sign in to comment.