summaryrefslogtreecommitdiffstats
path: root/sdc-os-chef/sdc-init-elasticsearch/chef-repo/cookbooks/init-sdc-elasticsearch/recipes/ES_2_create_resources_template.rb
blob: 11b8c9d060a4e1b04a241e8bed31416c2e9d85a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /
# Get the first es node in the list
es_node =  node['Nodes']['ES'].first

ruby_block "check_ElasticSearch_Cluster_Health" do
    block do
      #tricky way to load this Chef::Mixin::ShellOut utilities
      Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
      curl_command = "http://#{es_node}:9200/_cluster/health?pretty=true"
      resp = Net::HTTP.get_response URI.parse(curl_command)
      stat = JSON.parse(resp.read_body)['status']

      case stat
         when "green"
            printf("\033[32m%s\n\033[0m", "  ElasticSearch Cluster status is green.")
         when "yellow"
            printf("\033[33m%s\n\033[0m", "  ElasticSearch Cluster status is yellow...")
         when "red"
            printf("\033[31m%s\n\033[0m", "  ElasticSearch Cluster status is red!")
            break;
      end
   end
   retries 10
   retry_delay 2
end

bash "create resources mapping" do
	code <<-EOH	
		curl -i -X PUT -d '{ "order": 1, "template": "resources", "settings": {}, "mappings":
			{
				"esartifactdata": {
					"properties": {
						"id": { "include_in_all": true, "index": "not_analyzed", "type": "string" },
						"data": { "include_in_all": false, "type": "string" }
					},
					"_all": { "enabled": true } 
				}
			}
		}' http://#{es_node}:9200/_template/resources_template
	EOH
end