-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[private-chef-cookbooks] Add support for ElasticSearch index creation
`chef-server-ctl reconfigure` can now correctly create the required elasticsearch search index for chef-server.
- Loading branch information
1 parent
c0f7dde
commit 1aeeb89
Showing
4 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
omnibus/files/private-chef-cookbooks/private-chef/libraries/elasticsearch_index_provider.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 15 additions & 0 deletions
15
omnibus/files/private-chef-cookbooks/private-chef/libraries/elasticsearch_index_resource.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters