diff --git a/attributes/cluster.rb b/attributes/cluster.rb index 382dd00..773e3ec 100644 --- a/attributes/cluster.rb +++ b/attributes/cluster.rb @@ -28,9 +28,9 @@ default['couchbase']['cluster'] = Chef::DataBagItem.load('couchbase', 'cluster')[node.chef_environment] rescue {} -node.set['couchbase']['cluster']['name'] = "default" unless node['couchbase']['cluster']['name'] +default['couchbase']['cluster']['name'] = "default"# unless node['couchbase']['cluster']['name'] # If this server is a member of a cluster, the cluster settings should override some server settings -node.set['couchbase']['server']['username'] = node['couchbase']['cluster']['username'] -node.set['couchbase']['server']['password'] = node['couchbase']['cluster']['password'] -node.set['couchbase']['server']['memory_quota_mb'] = node['couchbase']['cluster']['memory_quota_mb'] +override['couchbase']['server']['username'] = node['couchbase']['cluster']['username'] if node['couchbase']['cluster']['username'] +override['couchbase']['server']['password'] = node['couchbase']['cluster']['password'] if node['couchbase']['cluster']['password'] +override['couchbase']['server']['memory_quota_mb'] = node['couchbase']['cluster']['memory_quota_mb'] if node['couchbase']['cluster']['memory_quota_mb'] diff --git a/libraries/bucket_provider.rb b/libraries/bucket_provider.rb index 81bb912..d1d5fa3 100644 --- a/libraries/bucket_provider.rb +++ b/libraries/bucket_provider.rb @@ -7,6 +7,9 @@ class Provider class CouchbaseBucket < Provider include Couchbase::Client include Couchbase::ClusterData + provides :couchbase_bucket + + def load_current_resource @current_resource = Resource::CouchbaseBucket.new @new_resource.name diff --git a/libraries/bucket_resource.rb b/libraries/bucket_resource.rb index f89ccd4..d07fffb 100644 --- a/libraries/bucket_resource.rb +++ b/libraries/bucket_resource.rb @@ -5,6 +5,7 @@ class Chef class Resource class CouchbaseBucket < Resource include Couchbase::CredentialsAttributes + provides :couchbase_bucket def bucket(arg=nil) set_or_return(:bucket, arg, :kind_of => String, :name_attribute => true) @@ -17,7 +18,7 @@ def cluster(arg=nil) def exists(arg=nil) set_or_return(:exists, arg, :kind_of => [TrueClass, FalseClass], :required => true) end - + def proxyport(arg=nil) set_or_return(:proxyport, arg, :kind_of => Integer) end diff --git a/libraries/cluster_provider.rb b/libraries/cluster_provider.rb index 430a96b..f268812 100644 --- a/libraries/cluster_provider.rb +++ b/libraries/cluster_provider.rb @@ -1,12 +1,13 @@ -require "chef/provider" -require File.join(File.dirname(__FILE__), "client") -require File.join(File.dirname(__FILE__), "cluster_data") +require 'chef/provider' +require_relative 'client' +require_relative 'cluster_data' class Chef class Provider - class CouchbaseCluster < Provider + class CouchbaseCluster < Chef::Provider include Couchbase::Client include Couchbase::ClusterData + provides :couchbase_cluster def load_current_resource @current_resource = Resource::CouchbaseCluster.new @new_resource.name diff --git a/libraries/cluster_resource.rb b/libraries/cluster_resource.rb index 3db1708..8eddba7 100644 --- a/libraries/cluster_resource.rb +++ b/libraries/cluster_resource.rb @@ -1,10 +1,11 @@ -require "chef/resource" -require File.join(File.dirname(__FILE__), "credentials_attributes") +require 'chef/resource' +require_relative 'credentials_attributes' class Chef class Resource class CouchbaseCluster < Resource include Couchbase::CredentialsAttributes + provides :couchbase_cluster def cluster(arg=nil) set_or_return(:cluster, arg, :kind_of => String, :name_attribute => true) diff --git a/libraries/helper.rb b/libraries/helper.rb index ad7b5c4..ec82037 100644 --- a/libraries/helper.rb +++ b/libraries/helper.rb @@ -23,7 +23,6 @@ # Shamelessly stolen from Opscode's jenkins cookbook. Works for now. require 'chef/mixin/shell_out' -require 'chef/rest' module CouchbaseHelper extend Chef::Mixin::ShellOut @@ -38,20 +37,13 @@ def self.service_listening?(port) end def self.endpoint_responding?(url) - # XXX Should probably not use Chef::REST for this. Chef::REST only - # Accepts application/json; why not just use Net::HTTP directly? - begin - response = Chef::REST::RESTRequest.new(:GET, url, nil).call - rescue Errno::ECONNREFUSED, Errno::ENETUNREACH - return false - end - if response.kind_of?(Net::HTTPSuccess) || - response.kind_of?(Net::HTTPRedirection) || - response.kind_of?(Net::HTTPForbidden) + response = Net::HTTP.get_response(url, nil) + case response + when Net::HTTPSuccess, Net::HTTPRedirection, Net::HTTPForbidden Chef::Log.debug("GET to #{url} successful") return true else - Chef::Log.debug("GET to #{url} returned #{response.code} / #{response.class}") + Chef::Log.debug("GET to #{url} returned #{response.body if response.response_body_permitted?} / #{response}") return false end rescue EOFError, Errno::ECONNREFUSED diff --git a/libraries/node_provider.rb b/libraries/node_provider.rb index 91a685f..901b964 100644 --- a/libraries/node_provider.rb +++ b/libraries/node_provider.rb @@ -1,11 +1,13 @@ -require "chef/provider" -require "net/http" -require File.join(File.dirname(__FILE__), "client") +require 'chef/provider' +require 'net/http' +require_relative 'client' class Chef class Provider - class CouchbaseNode < Provider + class CouchbaseNode < Chef::Provider include Couchbase::Client + provides :couchbase_node + def load_current_resource @current_resource = Chef::Resource::CouchbaseNode.new @new_resource.name diff --git a/libraries/node_resource.rb b/libraries/node_resource.rb index e65ad49..b873cf6 100644 --- a/libraries/node_resource.rb +++ b/libraries/node_resource.rb @@ -1,10 +1,13 @@ -require "chef/resource" -require File.join(File.dirname(__FILE__), "credentials_attributes") +require 'chef/resource' +require_relative 'credentials_attributes' +require_relative 'client' class Chef class Resource - class CouchbaseNode < Resource + class CouchbaseNode < Chef::Resource include Couchbase::CredentialsAttributes + include Couchbase::Client + provides :couchbase_node def id(arg=nil) set_or_return(:id, arg, :kind_of => String, :name_attribute => true) diff --git a/libraries/settings_provider.rb b/libraries/settings_provider.rb index af31f95..5f13a76 100644 --- a/libraries/settings_provider.rb +++ b/libraries/settings_provider.rb @@ -5,6 +5,7 @@ class Chef class Provider class CouchbaseSettings < Provider include Couchbase::Client + provides :couchbase_settings def load_current_resource @current_resource = Resource::CouchbaseSettings.new @new_resource.name diff --git a/libraries/settings_resource.rb b/libraries/settings_resource.rb index d660cae..a966256 100644 --- a/libraries/settings_resource.rb +++ b/libraries/settings_resource.rb @@ -5,6 +5,7 @@ class Chef class Resource class CouchbaseSettings < Resource include Couchbase::CredentialsAttributes + provides :couchbase_settings def group(arg=nil) set_or_return(:group, arg, :kind_of => String, :name_attribute => true) diff --git a/recipes/server.rb b/recipes/server.rb index 9c8a782..59e11b0 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -41,7 +41,7 @@ end else # generate all passwords - (node.set['couchbase']['server']['password'] = secure_password && node.save) unless node['couchbase']['server']['password'] + (node.default['couchbase']['server']['password'] = secure_password) unless node['couchbase']['server']['password'] end remote_file File.join(Chef::Config[:file_cache_path], node['couchbase']['server']['package_file']) do @@ -74,23 +74,7 @@ end end -ruby_block "block_until_operational" do - block do - Chef::Log.info "Waiting until Couchbase is listening on port #{node['couchbase']['server']['port']}" - until CouchbaseHelper.service_listening?(node['couchbase']['server']['port']) do - sleep 1 - Chef::Log.debug(".") - end - Chef::Log.info "Waiting until the Couchbase admin API is responding" - test_url = URI.parse("http://localhost:#{node['couchbase']['server']['port']}") - until CouchbaseHelper.endpoint_responding?(test_url) do - sleep 1 - Chef::Log.debug(".") - end - end - action :nothing -end directory node['couchbase']['server']['log_dir'] do owner "couchbase" @@ -128,12 +112,32 @@ end service node['couchbase']['server']['service_name'] do - supports :restart => true, :status => true + supports( + restart: true, + status: true + ) action [:enable, :start] - notifies :create, "ruby_block[block_until_operational]", :immediately + notifies :run, 'ruby_block[block_until_operational]', :immediately end -couchbase_node "self" do +ruby_block 'block_until_operational' do + block do + Chef::Log.info "Waiting until Couchbase is listening on port #{node['couchbase']['server']['port']}" + until CouchbaseHelper.service_listening?(node['couchbase']['server']['port']) do + sleep 1 + Chef::Log.info('.') + end + + Chef::Log.info 'Waiting until the Couchbase admin API is responding' + test_url = URI.parse("http://localhost:#{node['couchbase']['server']['port']}") + until CouchbaseHelper.endpoint_responding?(test_url) do + sleep 1 + Chef::Log.info('.') + end + end + action :run +end +couchbase_node 'self' do database_path node['couchbase']['server']['database_path'] index_path node['couchbase']['server']['index_path']