Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cookbook compatible with Chef 13+ #83

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions attributes/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
3 changes: 3 additions & 0 deletions libraries/bucket_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion libraries/bucket_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions libraries/cluster_provider.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions libraries/cluster_resource.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 4 additions & 12 deletions libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions libraries/node_provider.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 6 additions & 3 deletions libraries/node_resource.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions libraries/settings_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libraries/settings_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 24 additions & 20 deletions recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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']

Expand Down