summaryrefslogtreecommitdiff
path: root/chef/lib/chef
diff options
context:
space:
mode:
authorSeth Chisamore <schisamo@opscode.com>2012-10-30 10:04:20 -0400
committerSeth Chisamore <schisamo@opscode.com>2012-10-30 10:04:20 -0400
commit9348c1c9c80ee757354d624b7dc1b78ebc7605c4 (patch)
tree4b929d5421f514b477aaa82d98516f82f1e62045 /chef/lib/chef
parent265a1b898c7235198d60b14d83b75754133b0884 (diff)
parent8366c2259a62c02cee2137a869cb401b578bada0 (diff)
downloadchef-9348c1c9c80ee757354d624b7dc1b78ebc7605c4.tar.gz
Merge branch 'OC-3564-remove-chef-server'
Diffstat (limited to 'chef/lib/chef')
-rw-r--r--chef/lib/chef/api_client.rb92
-rw-r--r--chef/lib/chef/certificate.rb161
-rw-r--r--chef/lib/chef/checksum.rb167
-rw-r--r--chef/lib/chef/config.rb27
-rw-r--r--chef/lib/chef/cookbook_uploader.rb1
-rw-r--r--chef/lib/chef/cookbook_version.rb301
-rw-r--r--chef/lib/chef/cookbook_version_selector.rb168
-rw-r--r--chef/lib/chef/couchdb.rb246
-rw-r--r--chef/lib/chef/data_bag.rb96
-rw-r--r--chef/lib/chef/data_bag_item.rb67
-rw-r--r--chef/lib/chef/environment.rb181
-rw-r--r--chef/lib/chef/exceptions.rb3
-rw-r--r--chef/lib/chef/index_queue.rb29
-rw-r--r--chef/lib/chef/index_queue/amqp_client.rb116
-rw-r--r--chef/lib/chef/index_queue/consumer.rb76
-rw-r--r--chef/lib/chef/index_queue/indexable.rb109
-rw-r--r--chef/lib/chef/node.rb155
-rw-r--r--chef/lib/chef/openid_registration.rb187
-rw-r--r--chef/lib/chef/role.rb98
-rw-r--r--chef/lib/chef/run_list.rb2
-rw-r--r--chef/lib/chef/run_list/run_list_expansion.rb15
-rw-r--r--chef/lib/chef/sandbox.rb153
-rw-r--r--chef/lib/chef/solr_query.rb187
-rw-r--r--chef/lib/chef/solr_query/lucene.treetop150
-rw-r--r--chef/lib/chef/solr_query/lucene_nodes.rb285
-rw-r--r--chef/lib/chef/solr_query/query_transform.rb65
-rw-r--r--chef/lib/chef/solr_query/solr_http_request.rb132
-rw-r--r--chef/lib/chef/webui_user.rb156
28 files changed, 11 insertions, 3414 deletions
diff --git a/chef/lib/chef/api_client.rb b/chef/lib/chef/api_client.rb
index f95978afba..da05939c24 100644
--- a/chef/lib/chef/api_client.rb
+++ b/chef/lib/chef/api_client.rb
@@ -20,9 +20,6 @@
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
-require 'chef/certificate'
-require 'chef/index_queue'
require 'chef/mash'
require 'chef/json_compat'
require 'chef/search/query'
@@ -32,51 +29,13 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
-
-
- DESIGN_DOCUMENT = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "client") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "client") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- }
- }
- }
-
- INDEX_OBJECT_TYPE = 'client'.freeze
-
- def self.index_object_type
- INDEX_OBJECT_TYPE
- end
-
- attr_accessor :couchdb_rev, :couchdb_id, :couchdb
# Create a new Chef::ApiClient object.
- def initialize(couchdb=nil)
+ def initialize
@name = ''
@public_key = nil
@private_key = nil
- @couchdb_rev = nil
- @couchdb_id = nil
@admin = false
- @couchdb = (couchdb || Chef::CouchDB.new)
end
# Gets or sets the client name.
@@ -127,17 +86,6 @@ class Chef
)
end
- # Creates a new public/private key pair, and populates the public_key and
- # private_key attributes.
- #
- # @return [True]
- def create_keys
- results = Chef::Certificate.gen_keypair(self.name)
- self.public_key(results[0].to_s)
- self.private_key(results[1].to_s)
- true
- end
-
# The hash representation of the object. Includes the name and public_key,
# but never the private key.
#
@@ -150,7 +98,6 @@ class Chef
'json_class' => self.class.name,
"chef_type" => "client"
}
- result["_rev"] = @couchdb_rev if @couchdb_rev
result
end
@@ -166,20 +113,9 @@ class Chef
client.name(o["name"] || o["clientname"])
client.public_key(o["public_key"])
client.admin(o["admin"])
- client.couchdb_rev = o["_rev"]
- client.couchdb_id = o["_id"]
- client.index_id = client.couchdb_id
client
end
- # List all the Chef::ApiClient objects in the CouchDB. If inflate is set
- # to true, you will get the full list of all ApiClients, fully inflated.
- def self.cdb_list(inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).list("clients", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
def self.list(inflate=false)
if inflate
response = Hash.new
@@ -193,14 +129,6 @@ class Chef
end
end
- # Load a client by name from CouchDB
- #
- # @params [String] The name of the client to load
- # @return [Chef::ApiClient] The resulting Chef::ApiClient object
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("client", name)
- end
-
# Load a client by name via the API
def self.load(name)
response = Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("clients/#{name}")
@@ -213,24 +141,11 @@ class Chef
end
end
- # Remove this client from the CouchDB
- #
- # @params [String] The name of the client to delete
- # @return [Chef::ApiClient] The last version of the object
- def cdb_destroy
- @couchdb.delete("client", @name, @couchdb_rev)
- end
-
# Remove this client via the REST API
def destroy
Chef::REST.new(Chef::Config[:chef_server_url]).delete_rest("clients/#{@name}")
end
- # Save this client to the CouchDB
- def cdb_save
- @couchdb_rev = @couchdb.store("client", @name, self)["rev"]
- end
-
# Save this client via the REST API, returns a hash including the private key
def save(new_key=false, validation=false)
if validation
@@ -256,11 +171,6 @@ class Chef
Chef::REST.new(Chef::Config[:chef_server_url]).post_rest("clients", self)
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb ||= Chef::CouchDB.new).create_design_document("clients", DESIGN_DOCUMENT)
- end
-
# As a string
def to_s
"client[#{@name}]"
diff --git a/chef/lib/chef/certificate.rb b/chef/lib/chef/certificate.rb
deleted file mode 100644
index 7943589c8e..0000000000
--- a/chef/lib/chef/certificate.rb
+++ /dev/null
@@ -1,161 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Copyright:: Copyright (c) 2009 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/log'
-require 'chef/config'
-require 'chef/api_client'
-require 'openssl'
-require 'fileutils'
-
-class Chef
- class Certificate
- class << self
-
- # Generates a new CA Certificate and Key, and writes them out to
- # Chef::Config[:signing_ca_cert] and Chef::Config[:signing_ca_key].
- def generate_signing_ca
- ca_cert_file = Chef::Config[:signing_ca_cert]
- ca_keypair_file = Chef::Config[:signing_ca_key]
-
- unless File.exists?(ca_cert_file) && File.exists?(ca_keypair_file)
- Chef::Log.info("Creating new signing certificate")
-
- [ ca_cert_file, ca_keypair_file ].each do |f|
- ca_basedir = File.dirname(f)
- FileUtils.mkdir_p ca_basedir
- end
-
- keypair = OpenSSL::PKey::RSA.generate(1024)
-
- ca_cert = OpenSSL::X509::Certificate.new
- ca_cert.version = 3
- ca_cert.serial = 1
- info = [
- ["C", Chef::Config[:signing_ca_country]],
- ["ST", Chef::Config[:signing_ca_state]],
- ["L", Chef::Config[:signing_ca_location]],
- ["O", Chef::Config[:signing_ca_org]],
- ["OU", "Certificate Service"],
- ["CN", "#{Chef::Config[:signing_ca_domain]}/emailAddress=#{Chef::Config[:signing_ca_email]}"]
- ]
- ca_cert.subject = ca_cert.issuer = OpenSSL::X509::Name.new(info)
- ca_cert.not_before = Time.now
- ca_cert.not_after = Time.now + 10 * 365 * 24 * 60 * 60 # 10 years
- ca_cert.public_key = keypair.public_key
-
- ef = OpenSSL::X509::ExtensionFactory.new
- ef.subject_certificate = ca_cert
- ef.issuer_certificate = ca_cert
- ca_cert.extensions = [
- ef.create_extension("basicConstraints", "CA:TRUE", true),
- ef.create_extension("subjectKeyIdentifier", "hash"),
- ef.create_extension("keyUsage", "cRLSign,keyCertSign", true),
- ]
- ca_cert.add_extension ef.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
- ca_cert.sign keypair, OpenSSL::Digest::SHA1.new
-
- File.open(ca_cert_file, "w") { |f| f.write ca_cert.to_pem }
- File.open(ca_keypair_file, File::WRONLY|File::EXCL|File::CREAT, 0600) { |f| f.write keypair.to_pem }
- if (Chef::Config[:signing_ca_user] && Chef::Config[:signing_ca_group])
- FileUtils.chown(Chef::Config[:signing_ca_user], Chef::Config[:signing_ca_group], ca_keypair_file)
- end
- end
- self
- end
-
- # Creates a new key pair, and signs them with the signing certificate
- # and key generated from generate_signing_ca above.
- #
- # All arguments are unused, though two arguments are accepted for compatibility.
- #
- # returns an array of [public_key, private_key]
- def gen_keypair(common_name=nil, subject_alternative_name = nil)
-
- Chef::Log.info("Creating new key pair for #{common_name}")
-
- # generate client keypair
- client_keypair = OpenSSL::PKey::RSA.generate(2048)
-
- return client_keypair.public_key, client_keypair
- end
-
- def gen_validation_key(name=Chef::Config[:validation_client_name], key_file=Chef::Config[:validation_key], admin=false)
- # Create the validation key
- api_client = Chef::ApiClient.new
- api_client.name(name)
- api_client.admin(admin)
-
- begin
- # If both the couch record and file exist, don't do anything. Otherwise,
- # re-generate the validation key.
- Chef::ApiClient.cdb_load(name)
-
- # The couch document was loaded successfully if we got to here; if we
- # can't also load the file on the filesystem, we'll regenerate it all.
- File.open(key_file, "r") do |file|
- end
- rescue Chef::Exceptions::CouchDBNotFound
- create_validation_key(api_client, key_file)
- rescue
- if $!.class.name =~ /Errno::/
- Chef::Log.error("Error opening validation key: #{$!} -- destroying and regenerating")
- begin
- api_client.cdb_destroy
- rescue Bunny::ServerDownError => e
- # create_validation_key is gonna fail anyway, so let's just bail out.
- Chef::Log.fatal("Could not de-index (to rabbitmq) previous validation key - rabbitmq is down! Start rabbitmq then restart chef-server to re-generate it")
- raise
- end
-
- create_validation_key(api_client, key_file)
- else
- raise
- end
- end
- end
-
- private
- def create_validation_key(api_client, key_file)
- Chef::Log.info("Creating validation key...")
-
- api_client.create_keys
- begin
- api_client.cdb_save
- rescue Bunny::ServerDownError => e
- # If rabbitmq is down, the client will have been saved in CouchDB,
- # but not in the index.
- Chef::Log.fatal("Could not index (to rabbitmq) validation key - rabbitmq is down! Start rabbitmq then restart chef-server to re-generate it")
-
- # re-raise so the error bubbles out and nukes chef-server
- raise e
- end
-
- key_dir = File.dirname(key_file)
- FileUtils.mkdir_p(key_dir) unless File.directory?(key_dir)
- File.open(key_file, File::WRONLY|File::CREAT, 0600) do |f|
- f.print(api_client.private_key)
- end
- if (Chef::Config[:signing_ca_user] && Chef::Config[:signing_ca_group])
- FileUtils.chown(Chef::Config[:signing_ca_user], Chef::Config[:signing_ca_group], key_file)
- end
- end
-
- end
- end
-end
diff --git a/chef/lib/chef/checksum.rb b/chef/lib/chef/checksum.rb
deleted file mode 100644
index fc1931174b..0000000000
--- a/chef/lib/chef/checksum.rb
+++ /dev/null
@@ -1,167 +0,0 @@
-#
-# Author:: Tim Hinderliter (<tim@opscode.com>)
-# Copyright:: Copyright (c) 2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require 'chef/log'
-require 'chef/checksum/storage'
-require 'uuidtools'
-
-class Chef
- # == Chef::Checksum
- # Checksum for an individual file; e.g., used for sandbox/cookbook uploading
- # to track which files the system already manages.
- class Checksum
- attr_accessor :checksum, :create_time
- attr_accessor :couchdb_id, :couchdb_rev
-
- attr_reader :storage
-
- # When a Checksum commits a sandboxed file to its final home in the checksum
- # repo, this attribute will have the original on-disk path where the file
- # was stored; it will be used if the commit is reverted to restore the sandbox
- # to the pre-commit state.
- attr_reader :original_committed_file_location
-
- DESIGN_DOCUMENT = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "checksum") {
- emit(doc.checksum, doc);
- }
- }
- EOJS
- },
- }
- }
-
- # Creates a new Chef::Checksum object.
- # === Arguments
- # checksum::: the MD5 content hash of the file
- # couchdb::: An instance of Chef::CouchDB
- #
- # === Returns
- # object<Chef::Checksum>:: Duh. :)
- def initialize(checksum=nil, couchdb=nil)
- @create_time = Time.now.iso8601
- @checksum = checksum
- @original_committed_file_location = nil
- @storage = Storage::Filesystem.new(Chef::Config.checksum_path, checksum)
- end
-
- def to_json(*a)
- result = {
- :checksum => checksum,
- :create_time => create_time,
- :json_class => self.class.name,
- :chef_type => 'checksum',
-
- # For Chef::CouchDB (id_to_name, name_to_id)
- :name => checksum
- }
- result.to_json(*a)
- end
-
- def self.json_create(o)
- checksum = new(o['checksum'])
- checksum.create_time = o['create_time']
-
- if o.has_key?('_rev')
- checksum.couchdb_rev = o["_rev"]
- o.delete("_rev")
- end
- if o.has_key?("_id")
- checksum.couchdb_id = o["_id"]
- o.delete("_id")
- end
- checksum
- end
-
- # Moves the given +sandbox_file+ into the checksum repo using the path
- # given by +file_location+ and saves the Checksum to the database
- def commit_sandbox_file(sandbox_file)
- @original_committed_file_location = sandbox_file
- Chef::Log.info("Commiting sandbox file: move #{sandbox_file} to #{@storage}")
- @storage.commit(sandbox_file)
- cdb_save
- end
-
- # Moves the checksum file back to its pre-commit location and deletes
- # the checksum object from the database, effectively undoing +commit_sandbox_file+.
- # Raises Chef::Exceptions::IllegalChecksumRevert if the original file location
- # is unknown, which is will be the case if commit_sandbox_file was not
- # previously called
- def revert_sandbox_file_commit
- unless original_committed_file_location
- raise Chef::Exceptions::IllegalChecksumRevert, "Checksum #{self.inspect} cannot be reverted because the original sandbox file location is not known"
- end
-
- Chef::Log.warn("Reverting sandbox file commit: moving #{@storage} back to #{original_committed_file_location}")
- @storage.revert(original_committed_file_location)
- cdb_destroy
- end
-
- # Removes the on-disk file backing this checksum object, then removes it
- # from the database
- def purge
- purge_file
- cdb_destroy
- end
-
- ##
- # Couchdb
- ##
-
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("checksums", DESIGN_DOCUMENT)
- end
-
- def self.cdb_list(inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).list("checksums", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
- def self.cdb_all_checksums(couchdb = nil)
- rs = (couchdb || Chef::CouchDB.new).list("checksums", true)
- rs["rows"].inject({}) { |hash_result, r| hash_result[r['key']] = 1; hash_result }
- end
-
- def self.cdb_load(checksum, couchdb=nil)
- # Probably want to look for a view here at some point
- (couchdb || Chef::CouchDB.new).load("checksum", checksum)
- end
-
- def cdb_destroy(couchdb=nil)
- (couchdb || Chef::CouchDB.new).delete("checksum", checksum, @couchdb_rev)
- end
-
- def cdb_save(couchdb=nil)
- @couchdb_rev = (couchdb || Chef::CouchDB.new).store("checksum", checksum, self)["rev"]
- end
-
-
- private
-
- def purge_file
- @storage.purge
- end
-
- end
-end
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb
index 924a20ab3b..61c8806a66 100644
--- a/chef/lib/chef/config.rb
+++ b/chef/lib/chef/config.rb
@@ -130,8 +130,6 @@ class Chef
# Used when OpenID authentication is enabled in the Web UI
authorized_openid_identifiers nil
authorized_openid_providers nil
- openid_cstore_couchdb false
- openid_cstore_path "/var/chef/openid/cstore"
# The number of times the client should retry when registering with the server
client_registration_retries 5
@@ -150,11 +148,6 @@ class Chef
# Where cookbook files are stored on the server (by content checksum)
checksum_path "/var/chef/checksums"
- # CouchDB database name to use
- couchdb_database "chef"
-
- couchdb_url "http://localhost:5984"
-
# Where chef's cache files should be stored
file_cache_path platform_specific_path("/var/chef/cache")
@@ -173,7 +166,6 @@ class Chef
## Daemonization Settings ##
# What user should Chef run as?
user nil
- # What group should the chef-server, -solr, -solr-indexer run as
group nil
umask 0022
@@ -212,7 +204,7 @@ class Chef
client_fork false
enable_reporting true
enable_reporting_url_fatals false
-
+
# Set these to enable SSL authentication / mutual-authentication
# with the server
ssl_client_cert nil
@@ -230,23 +222,6 @@ class Chef
# Where should chef-solo download recipes from?
recipe_url nil
- solr_url "http://localhost:8983/solr"
- solr_jetty_path "/var/chef/solr-jetty"
- solr_data_path "/var/chef/solr/data"
- solr_home_path "/var/chef/solr"
- solr_heap_size "256M"
- solr_java_opts nil
-
- # Parameters for connecting to RabbitMQ
- amqp_host '0.0.0.0'
- amqp_port '5672'
- amqp_user 'chef'
- amqp_pass 'testing'
- amqp_vhost '/chef'
- # Setting this to a UUID string also makes the queue durable
- # (persist across rabbitmq restarts)
- amqp_consumer_id "default"
-
# Sets the version of the signed header authentication protocol to use (see
# the 'mixlib-authorization' project for more detail). Currently, versions
# 1.0 and 1.1 are available; however, the chef-server must first be
diff --git a/chef/lib/chef/cookbook_uploader.rb b/chef/lib/chef/cookbook_uploader.rb
index 351a239bb8..8dd50ac043 100644
--- a/chef/lib/chef/cookbook_uploader.rb
+++ b/chef/lib/chef/cookbook_uploader.rb
@@ -4,7 +4,6 @@ require 'rest_client'
require 'chef/exceptions'
require 'chef/knife/cookbook_metadata'
require 'chef/checksum_cache'
-require 'chef/sandbox'
require 'chef/cookbook_version'
require 'chef/cookbook/syntax_check'
require 'chef/cookbook/file_system_file_vendor'
diff --git a/chef/lib/chef/cookbook_version.rb b/chef/lib/chef/cookbook_version.rb
index a6f95e2c3b..0e11174a07 100644
--- a/chef/lib/chef/cookbook_version.rb
+++ b/chef/lib/chef/cookbook_version.rb
@@ -24,86 +24,11 @@ require 'chef/node'
require 'chef/resource_definition_list'
require 'chef/recipe'
require 'chef/cookbook/file_vendor'
-require 'chef/checksum'
require 'chef/cookbook/metadata'
require 'chef/version_class'
class Chef
- #== Chef::MinimalCookbookVersion
- # MinimalCookbookVersion is a duck type of CookbookVersion, used
- # internally by Chef Server as an optimization when determining the
- # optimal cookbook set for a chef-client.
- #
- # MinimalCookbookVersion objects contain only enough information to
- # solve the cookbook collection for a given run list. They *do not*
- # contain enough information to generate the response.
- #
- # See also: Chef::CookbookVersionSelector
- class MinimalCookbookVersion
-
- include Comparable
-
- ID = "id".freeze
- NAME = 'name'.freeze
- KEY = 'key'.freeze
- VERSION = 'version'.freeze
- VALUE = 'value'.freeze
- DEPS = 'deps'.freeze
-
- DEPENDENCIES = 'dependencies'.freeze
-
- # Loads the full list of cookbooks, using a couchdb view to fetch
- # only the id, name, version, and dependency constraints. This is
- # enough information to solve for the cookbook collection for a
- # given run list. After solving for the cookbook collection, you
- # need to call +load_full_versions_of+ to convert
- # MinimalCookbookVersion objects to their non-minimal counterparts
- def self.load_all(couchdb)
- # Example:
- # {"id"=>"1a806f1c-b409-4d8e-abab-fa414ff5b96d", "key"=>"activemq", "value"=>{"version"=>"0.3.3", "deps"=>{"java"=>">= 0.0.0", "runit"=>">= 0.0.0"}}}
- couchdb ||= Chef::CouchDB.new
- couchdb.get_view("cookbooks", "all_with_version_and_deps")["rows"].map {|params| self.new(params) }
- end
-
- # Loads the non-minimal CookbookVersion objects corresponding to
- # +minimal_cookbook_versions+ from couchdb using a bulk GET.
- def self.load_full_versions_of(minimal_cookbook_versions, couchdb)
- database_ids = Array(minimal_cookbook_versions).map {|mcv| mcv.couchdb_id }
- couchdb ||= Chef::CouchDB.new
- couchdb.bulk_get(*database_ids)
- end
-
- attr_reader :couchdb_id
- attr_reader :name
- attr_reader :version
- attr_reader :deps
-
- def initialize(params)
- @couchdb_id = params[ID]
- @name = params[KEY]
- @version = params[VALUE][VERSION]
- @deps = params[VALUE][DEPS]
- end
-
- # Returns the Cookbook::MinimalMetadata object for this cookbook
- # version.
- def metadata
- @metadata ||= Cookbook::MinimalMetadata.new(@name, DEPENDENCIES => @deps)
- end
-
- def legit_version
- @legit_version ||= Chef::Version.new(@version)
- end
-
- def <=>(o)
- raise Chef::Exceptions::CookbookVersionNameMismatch if self.name != o.name
- raise "Unexpected comparison to #{o}" unless o.respond_to?(:legit_version)
- legit_version <=> o.legit_version
- end
- end
-
-
# == Chef::CookbookVersion
# CookbookVersion is a model object encapsulating the data about a Chef
# cookbook. Chef supports maintaining multiple versions of a cookbook on a
@@ -113,140 +38,10 @@ class Chef
# TODO: timh/cw: 5-24-2010: mutators for files (e.g., recipe_filenames=,
# recipe_filenames.insert) should dirty the manifest so it gets regenerated.
class CookbookVersion
- include Chef::IndexQueue::Indexable
include Comparable
COOKBOOK_SEGMENTS = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
- DESIGN_DOCUMENT = {
- "version" => 8,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- },
- "all_with_version" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.cookbook_name, doc.version);
- }
- }
- EOJS
- },
- "all_with_version_and_deps" => {
- "map" => <<-JS
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.cookbook_name, {version: doc.version, deps: doc.metadata.dependencies});
- }
- }
- JS
- },
- "all_latest_version" => {
- "map" => %q@
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.cookbook_name, doc.version);
- }
- }
- @,
- "reduce" => %q@
- function(keys, values, rereduce) {
- var result = null;
-
- for (var idx in values) {
- var value = values[idx];
-
- if (idx == 0) {
- result = value;
- continue;
- }
-
- var valueParts = value.split('.').map(function(v) { return parseInt(v); });
- var resultParts = result.split('.').map(function(v) { return parseInt(v); });
-
- if (valueParts[0] != resultParts[0]) {
- if (valueParts[0] > resultParts[0]) {
- result = value;
- }
- }
- else if (valueParts[1] != resultParts[1]) {
- if (valueParts[1] > resultParts[1]) {
- result = value;
- }
- }
- else if (valueParts[2] != resultParts[2]) {
- if (valueParts[2] > resultParts[2]) {
- result = value;
- }
- }
- }
- return result;
- }
- @
- },
- "all_latest_version_by_id" => {
- "map" => %q@
- function(doc) {
- if (doc.chef_type == "cookbook_version") {
- emit(doc.cookbook_name, {version: doc.version, id:doc._id});
- }
- }
- @,
- "reduce" => %q@
- function(keys, values, rereduce) {
- var result = null;
-
- for (var idx in values) {
- var value = values[idx];
-
- if (idx == 0) {
- result = value;
- continue;
- }
-
- var valueParts = value.version.split('.').map(function(v) { return parseInt(v); });
- var resultParts = result.version.split('.').map(function(v) { return parseInt(v); });
-
- if (valueParts[0] != resultParts[0]) {
- if (valueParts[0] > resultParts[0]) {
- result = value;
- }
- }
- else if (valueParts[1] != resultParts[1]) {
- if (valueParts[1] > resultParts[1]) {
- result = value;
- }
- }
- else if (valueParts[2] != resultParts[2]) {
- if (valueParts[2] > resultParts[2]) {
- result = value;
- }
- }
- }
- return result;
- }
- @
- },
- }
- }
-
attr_accessor :root_dir
attr_accessor :definition_filenames
attr_accessor :template_filenames
@@ -259,10 +54,6 @@ class Chef
attr_accessor :metadata
attr_accessor :metadata_filenames
attr_accessor :status
- attr_accessor :couchdb_rev
- attr_accessor :couchdb
-
- attr_reader :couchdb_id
# attribute_filenames also has a setter that has non-default
# functionality.
@@ -401,7 +192,7 @@ class Chef
#
# === Returns
# object<Chef::CookbookVersion>:: Duh. :)
- def initialize(name, couchdb=nil)
+ def initialize(name)
@name = name
@frozen = false
@attribute_filenames = Array.new
@@ -416,9 +207,6 @@ class Chef
@metadata_filenames = Array.new
@root_dir = nil
@root_filenames = Array.new
- @couchdb_id = nil
- @couchdb = couchdb || Chef::CouchDB.new
- @couchdb_rev = nil
@status = :ready
@manifest = nil
@file_vendor = nil
@@ -761,7 +549,6 @@ class Chef
result = manifest.dup
result['frozen?'] = frozen_version?
result['chef_type'] = 'cookbook_version'
- result["_rev"] = couchdb_rev if couchdb_rev
result.to_hash
end
@@ -773,15 +560,6 @@ class Chef
def self.json_create(o)
cookbook_version = new(o["cookbook_name"])
- if o.has_key?('_rev')
- cookbook_version.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- o.delete("_rev")
- end
- if o.has_key?("_id")
- cookbook_version.couchdb_id = o["_id"] if o.has_key?("_id")
- cookbook_version.index_id = cookbook_version.couchdb_id
- o.delete("_id")
- end
# We want the Chef::Cookbook::Metadata object to always be inflated
cookbook_version.metadata = Chef::Cookbook::Metadata.from_hash(o["metadata"])
cookbook_version.manifest = o
@@ -888,83 +666,6 @@ class Chef
chef_server_rest.get_rest('cookbooks/_latest')
end
- ##
- # Couchdb
- ##
-
- def self.cdb_by_name(cookbook_name, couchdb=nil)
- cdb = (couchdb || Chef::CouchDB.new)
- options = { :startkey => cookbook_name, :endkey => cookbook_name }
- rs = cdb.get_view("cookbooks", "all_with_version", options)
- rs["rows"].inject({}) { |memo, row| memo.has_key?(row["key"]) ? memo[row["key"]] << row["value"] : memo[row["key"]] = [ row["value"] ]; memo }
- end
-
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("cookbooks", DESIGN_DOCUMENT)
- end
-
- def self.cdb_list_latest(inflate=false, couchdb=nil)
- couchdb ||= Chef::CouchDB.new
- if inflate
- doc_ids = cdb_list_latest_ids.map {|i|i["id"]}
- couchdb.bulk_get(doc_ids)
- else
- results = couchdb.get_view("cookbooks", "all_latest_version", :group=>true)["rows"]
- results.inject({}) { |mapped, row| mapped[row["key"]] = row["value"]; mapped}
- end
- end
-
- def self.cdb_list_latest_ids(inflate=false, couchdb=nil)
- couchdb ||= Chef::CouchDB.new
- results = couchdb.get_view("cookbooks", "all_latest_version_by_id", :group=>true)["rows"]
- results.map { |name_and_id| name_and_id["value"]}
- end
-
- def self.cdb_list(inflate=false, couchdb=nil)
- couchdb ||= Chef::CouchDB.new
- if inflate
- couchdb.list("cookbooks", true)["rows"].collect{|r| r["value"]}
- else
- # If you modify this, please make sure the desc sorted order on the versions doesn't get broken.
- couchdb.get_view("cookbooks", "all_with_version")["rows"].inject({}) { |mapped, row| mapped[row["key"]]||=Array.new; mapped[row["key"]].push(Chef::Version.new(row["value"])); mapped[row["key"]].sort!.reverse!; mapped}
- end
- end
-
- def self.cdb_load(name, version='latest', couchdb=nil)
- cdb = couchdb || Chef::CouchDB.new
- if version == "latest" || version == "_latest"
- rs = cdb.get_view("cookbooks", "all_latest_version", :key => name, :descending => true, :group => true, :reduce => true)["rows"].first
- cdb.load("cookbook_version", "#{rs["key"]}-#{rs["value"]}")
- else
- cdb.load("cookbook_version", "#{name}-#{version}")
- end
- end
-
- def cdb_destroy
- (couchdb || Chef::CouchDB.new).delete("cookbook_version", full_name, couchdb_rev)
- end
-
- # Runs on Chef Server (API); deletes the cookbook from couchdb and also destroys associated
- # checksum documents
- def purge
- checksums.keys.each do |checksum|
- begin
- Chef::Checksum.cdb_load(checksum, couchdb).purge
- rescue Chef::Exceptions::CouchDBNotFound
- end
- end
- cdb_destroy
- end
-
- def cdb_save
- @couchdb_rev = couchdb.store("cookbook_version", full_name, self)["rev"]
- end
-
- def couchdb_id=(value)
- @couchdb_id = value
- @index_id = value
- end
-
def <=>(o)
raise Chef::Exceptions::CookbookVersionNameMismatch if self.name != o.name
# FIXME: can we change the interface to the Metadata class such
diff --git a/chef/lib/chef/cookbook_version_selector.rb b/chef/lib/chef/cookbook_version_selector.rb
deleted file mode 100644
index 9e60f85639..0000000000
--- a/chef/lib/chef/cookbook_version_selector.rb
+++ /dev/null
@@ -1,168 +0,0 @@
-#
-# Author:: Tim Hinderliter (<tim@opscode.com>)
-# Copyright:: Copyright (c) 2011 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require 'dep_selector'
-
-class Chef
- module CookbookVersionSelector
- # This method replaces verbiage from DepSelector messages with
- # Chef-domain-specific verbiage, such as replacing package with
- # cookbook.
- #
- # TODO [cw, 2011/2/25]: this is a near-term hack. In the long run,
- # we'll do this better.
- def self.filter_dep_selector_message(message)
- m = message
- m.gsub!("Package", "Cookbook")
- m.gsub!("package", "cookbook")
- m.gsub!("Solution constraint", "Run list item")
- m.gsub!("solution constraint", "run list item")
- m
- end
-
- # all_cookbooks - a hash mapping cookbook names to an array of
- # available CookbookVersions.
- #
- # Creates a DependencyGraph from CookbookVersion objects
- def self.create_dependency_graph_from_cookbooks(all_cookbooks)
- dep_graph = DepSelector::DependencyGraph.new
-
- all_cookbooks.each do |cb_name, cb_versions|
- cb_versions.each do |cb_version|
- cb_version_deps = cb_version.metadata.dependencies
- # TODO [cw. 2011/2/10]: CookbookVersion#version returns a
- # String even though we're storing as a DepSelector::Version
- # object underneath. This should be changed so that we
- # return the object and handle proper serialization and
- # de-serialization. For now, I'm just going to create a
- # Version object from the String representation.
- pv = dep_graph.package(cb_name).add_version(Chef::Version.new(cb_version.version))
- cb_version_deps.each_pair do |dep_name, constraint_str|
- # if the dependency is specified as cookbook::recipe,
- # extract the cookbook component
- dep_cb_name = dep_name.split("::").first
- constraint = Chef::VersionConstraint.new(constraint_str)
- pv.dependencies << DepSelector::Dependency.new(dep_graph.package(dep_cb_name), constraint)
- end
- end
- end
-
- dep_graph
- end
-
- # Return a hash mapping cookbook names to a CookbookVersion
- # object. If there is no solution that satisfies the constraints,
- # the first run list item that caused unsatisfiability is
- # returned.
- #
- # This is the final version-resolved list of cookbooks for the
- # RunList.
- #
- # all_cookbooks - a hash mapping cookbook names to an array of
- # available CookbookVersions.
- #
- # recipe_constraints - an array of hashes describing the expanded
- # run list. Each element is a hash containing keys :name and
- # :version_constraint. The :name component is either the
- # fully-qualified recipe name (e.g. "cookbook1::non_default_recipe")
- # or just a cookbook name, indicating the default recipe is to be
- # run (e.g. "cookbook1").
- def self.constrain(all_cookbooks, recipe_constraints)
- dep_graph = create_dependency_graph_from_cookbooks(all_cookbooks)
-
- # extract cookbook names from (possibly) fully-qualified recipe names
- cookbook_constraints = recipe_constraints.map do |recipe_spec|
- cookbook_name = (recipe_spec[:name][/^(.+)::/, 1] || recipe_spec[:name])
- DepSelector::SolutionConstraint.new(dep_graph.package(cookbook_name),
- recipe_spec[:version_constraint])
- end
-
- # Pass in the list of all available cookbooks (packages) so that
- # DepSelector can distinguish between "no version available for
- # cookbook X" and "no such cookbook X" when an environment
- # filters out all versions for a given cookbook.
- all_packages = all_cookbooks.inject([]) do |acc, (cookbook_name, cookbook_versions)|
- acc << dep_graph.package(cookbook_name)
- acc
- end
-
- # find a valid assignment of CoookbookVersions. If no valid
- # assignment exists, indicate which run_list_item causes the
- # unsatisfiability and try to hint at what might be wrong.
- soln =
- begin
- DepSelector::Selector.new(dep_graph).find_solution(cookbook_constraints, all_packages)
- rescue DepSelector::Exceptions::InvalidSolutionConstraints => e
- non_existent_cookbooks = e.non_existent_packages.map {|constraint| constraint.package.name}
- cookbooks_with_no_matching_versions = e.constrained_to_no_versions.map {|constraint| constraint.package.name}
-
- # Spend a whole lot of effort for pluralizing and
- # prettifying the message.
- message = ""
- if non_existent_cookbooks.length > 0
- message += "no such " + (non_existent_cookbooks.length > 1 ? "cookbooks" : "cookbook")
- message += " #{non_existent_cookbooks.join(", ")}"
- end
-
- if cookbooks_with_no_matching_versions.length > 0
- if message.length > 0
- message += "; "
- end
-
- message += "no versions match the constraints on " + (cookbooks_with_no_matching_versions.length > 1 ? "cookbooks" : "cookbook")
- message += " #{cookbooks_with_no_matching_versions.join(", ")}"
- end
-
- message = "Run list contains invalid items: #{message}."
-
- raise Chef::Exceptions::CookbookVersionSelection::InvalidRunListItems.new(message, non_existent_cookbooks, cookbooks_with_no_matching_versions)
- rescue DepSelector::Exceptions::NoSolutionExists => e
- raise Chef::Exceptions::CookbookVersionSelection::UnsatisfiableRunListItem.new(filter_dep_selector_message(e.message), e.unsatisfiable_solution_constraint, e.disabled_non_existent_packages, e.disabled_most_constrained_packages)
- end
-
-
- # map assignment back to CookbookVersion objects
- selected_cookbooks = {}
- soln.each_pair do |cb_name, cb_version|
- # TODO [cw, 2011/2/10]: related to the TODO in
- # create_dependency_graph_from_cookbooks, cbv.version
- # currently returns a String, so we must compare to
- # cb_version.to_s, since it's a for-real Version object.
- selected_cookbooks[cb_name] = all_cookbooks[cb_name].find{|cbv| cbv.version == cb_version.to_s}
- end
- selected_cookbooks
- end
-
- # Expands the run_list, constrained to the environment's CookbookVersion
- # constraints.
- #
- # Returns:
- # Hash of: name to CookbookVersion
- def self.expand_to_cookbook_versions(run_list, environment, couchdb=nil)
- # expand any roles in this run_list.
- expanded_run_list = run_list.expand(environment, 'couchdb', :couchdb => couchdb).recipes.with_version_constraints
-
- cookbooks_for_environment = Chef::Environment.cdb_minimal_filtered_versions(environment, couchdb)
- cookbook_collection = constrain(cookbooks_for_environment, expanded_run_list)
- full_cookbooks = Chef::MinimalCookbookVersion.load_full_versions_of(cookbook_collection.values, couchdb)
- full_cookbooks.inject({}) do |cb_map, cookbook_version|
- cb_map[cookbook_version.name] = cookbook_version
- cb_map
- end
- end
- end
-end
diff --git a/chef/lib/chef/couchdb.rb b/chef/lib/chef/couchdb.rb
deleted file mode 100644
index 71ee196462..0000000000
--- a/chef/lib/chef/couchdb.rb
+++ /dev/null
@@ -1,246 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Christopher Brown (<cb@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require 'chef/mixin/params_validate'
-require 'chef/config'
-require 'chef/rest'
-require 'chef/log'
-require 'digest/sha2'
-require 'chef/json_compat'
-
-# We want to fail on create if uuidtools isn't installed
-begin
- require 'uuidtools'
-rescue LoadError
-end
-
-class Chef
- class CouchDB
- include Chef::Mixin::ParamsValidate
-
- def initialize(url=nil, db=Chef::Config[:couchdb_database])
- url ||= Chef::Config[:couchdb_url]
- @db = db
- @rest = Chef::REST.new(url, nil, nil)
- end
-
- def couchdb_database(args=nil)
- @db = args || @db
- end
-
- def create_id_map
- create_design_document(
- "id_map",
- {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "name_to_id" => {
- "map" => <<-EOJS
- function(doc) {
- emit([ doc.chef_type, doc.name], doc._id);
- }
- EOJS
- },
- "id_to_name" => {
- "map" => <<-EOJS
- function(doc) {
- emit(doc._id, [ doc.chef_type, doc.name ]);
- }
- EOJS
- }
- }
- }
- )
- end
-
- def create_db(check_for_existing=true)
- @database_list = @rest.get_rest("_all_dbs")
- if !check_for_existing || !@database_list.any? { |db| db == couchdb_database }
- response = @rest.put_rest(couchdb_database, Hash.new)
- end
- couchdb_database
- end
-
- def create_design_document(name, data)
- to_update = true
- begin
- old_doc = @rest.get_rest("#{couchdb_database}/_design/#{name}")
- if data["version"] != old_doc["version"]
- data["_rev"] = old_doc["_rev"]
- Chef::Log.debug("Updating #{name} views")
- else
- to_update = false
- end
- rescue
- Chef::Log.debug("Creating #{name} views for the first time because: #{$!}")
- end
- if to_update
- @rest.put_rest("#{couchdb_database}/_design%2F#{name}", data)
- end
- true
- end
-
- # Save the object to Couch. Add to index if the object supports it.
- def store(obj_type, name, object)
- validate(
- {
- :obj_type => obj_type,
- :name => name,
- :object => object,
- },
- {
- :object => { :respond_to => :to_json },
- }
- )
- rows = get_view("id_map", "name_to_id", :key => [ obj_type, name ])["rows"]
- uuid = rows.empty? ? UUIDTools::UUID.random_create.to_s : rows.first.fetch("id")
-
- db_put_response = @rest.put_rest("#{couchdb_database}/#{uuid}", object)
-
- if object.respond_to?(:add_to_index)
- Chef::Log.info("Sending #{obj_type}(#{uuid}) to the index queue for addition.")
- object.add_to_index(:database => couchdb_database, :id => uuid, :type => obj_type)
- end
-
- db_put_response
- end
-
- def load(obj_type, name)
- validate(
- {
- :obj_type => obj_type,
- :name => name,
- },
- {
- :obj_type => { :kind_of => String },
- :name => { :kind_of => String },
- }
- )
- doc = find_by_name(obj_type, name)
- doc.couchdb = self if doc.respond_to?(:couchdb)
- doc
- end
-
- def delete(obj_type, name, rev=nil)
- validate(
- {
- :obj_type => obj_type,
- :name => name,
- },
- {
- :obj_type => { :kind_of => String },
- :name => { :kind_of => String },
- }
- )
- del_id = nil
- object, uuid = find_by_name(obj_type, name, true)
- unless rev
- if object.respond_to?(:couchdb_rev)
- rev = object.couchdb_rev
- else
- rev = object['_rev']
- end
- end
- response = @rest.delete_rest("#{couchdb_database}/#{uuid}?rev=#{rev}")
- response.couchdb = self if response.respond_to?(:couchdb=)
-
- if object.respond_to?(:delete_from_index)
- Chef::Log.info("Sending #{obj_type}(#{uuid}) to the index queue for deletion..")
- object.delete_from_index(:database => couchdb_database, :id => uuid, :type => obj_type)
- end
-
- response
- end
-
- def list(view, inflate=false)
- validate(
- {
- :view => view,
- },
- {
- :view => { :kind_of => String }
- }
- )
- if inflate
- r = @rest.get_rest(view_uri(view, "all"))
- r["rows"].each { |i| i["value"].couchdb = self if i["value"].respond_to?(:couchdb=) }
- r
- else
- r = @rest.get_rest(view_uri(view, "all_id"))
- end
- r
- end
-
- def has_key?(obj_type, name)
- validate(
- {
- :obj_type => obj_type,
- :name => name,
- },
- {
- :obj_type => { :kind_of => String },
- :name => { :kind_of => String },
- }
- )
- begin
- find_by_name(obj_type, name)
- true
- rescue
- false
- end
- end
-
- def find_by_name(obj_type, name, with_id=false)
- r = get_view("id_map", "name_to_id", :key => [ obj_type, name ], :include_docs => true)
- if r["rows"].length == 0
- raise Chef::Exceptions::CouchDBNotFound, "Cannot find #{obj_type} #{name} in CouchDB!"
- end
- if with_id
- [ r["rows"][0]["doc"], r["rows"][0]["id"] ]
- else
- r["rows"][0]["doc"]
- end
- end
-
- def get_view(design, view, options={})
- view_string = view_uri(design, view)
- view_string << "?" if options.length != 0
- view_string << options.map { |k,v| "#{k}=#{URI.escape(v.to_json)}"}.join('&')
- @rest.get_rest(view_string)
- end
-
- def bulk_get(*to_fetch)
- response = @rest.post_rest("#{couchdb_database}/_all_docs?include_docs=true", { "keys" => to_fetch.flatten })
- response["rows"].collect { |r| r["doc"] }
- end
-
- def view_uri(design, view)
- "#{couchdb_database}/_design/#{design}/_view/#{view}"
- end
-
- def server_stats
- @rest.get_rest('/')
- end
-
- def db_stats
- @rest.get_rest("/#{@db}")
- end
-
- end
-end
diff --git a/chef/lib/chef/data_bag.rb b/chef/lib/chef/data_bag.rb
index 32188c0861..9ce6215b20 100644
--- a/chef/lib/chef/data_bag.rb
+++ b/chef/lib/chef/data_bag.rb
@@ -21,9 +21,7 @@
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
require 'chef/data_bag_item'
-require 'chef/index_queue'
require 'chef/mash'
require 'chef/json_compat'
@@ -32,58 +30,18 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
VALID_NAME = /^[\-[:alnum:]_]+$/
- DESIGN_DOCUMENT = {
- "version" => 2,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- },
- "entries" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag_item") {
- emit(doc.data_bag, doc.raw_data.id);
- }
- }
- EOJS
- }
- }
- }
-
def self.validate_name!(name)
unless name =~ VALID_NAME
raise Exceptions::InvalidDataBagName, "DataBags must have a name matching #{VALID_NAME.inspect}, you gave #{name.inspect}"
end
end
- attr_accessor :couchdb_rev, :couchdb_id, :couchdb
-
# Create a new Chef::DataBag
- def initialize(couchdb=nil)
+ def initialize
@name = ''
- @couchdb_rev = nil
- @couchdb_id = nil
- @couchdb = (couchdb || Chef::CouchDB.new)
end
def name(arg=nil)
@@ -100,7 +58,6 @@ class Chef
'json_class' => self.class.name,
"chef_type" => "data_bag",
}
- result["_rev"] = @couchdb_rev if @couchdb_rev
result
end
@@ -121,20 +78,9 @@ class Chef
def self.json_create(o)
bag = new
bag.name(o["name"])
- bag.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- bag.couchdb_id = o["_id"] if o.has_key?("_id")
- bag.index_id = bag.couchdb_id
bag
end
- # List all the Chef::DataBag objects in the CouchDB. If inflate is set to true, you will get
- # the full list of all Roles, fully inflated.
- def self.cdb_list(inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).list("data_bags", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
def self.list(inflate=false)
if inflate
# Can't search for all data bags like other objects, fall back to N+1 :(
@@ -147,11 +93,6 @@ class Chef
end
end
- # Load a Data Bag by name from CouchDB
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("data_bag", name)
- end
-
# Load a Data Bag by name via either the RESTful API or local data_bag_path if run in solo mode
def self.load(name)
if Chef::Config[:solo]
@@ -169,27 +110,10 @@ class Chef
end
end
- # Remove this Data Bag from CouchDB
- def cdb_destroy
- removed = @couchdb.delete("data_bag", @name, @couchdb_rev)
- rs = @couchdb.get_view("data_bags", "entries", :include_docs => true, :startkey => @name, :endkey => @name)
- rs["rows"].each do |row|
- row["doc"].couchdb = couchdb
- row["doc"].cdb_destroy
- end
- removed
- end
-
def destroy
chef_server_rest.delete_rest("data/#{@name}")
end
- # Save this Data Bag to the CouchDB
- def cdb_save
- results = @couchdb.store("data_bag", @name, self)
- @couchdb_rev = results["rev"]
- end
-
# Save the Data Bag via RESTful API
def save
begin
@@ -211,24 +135,6 @@ class Chef
self
end
- # List all the items in this Bag from CouchDB
- # The self.load method does this through the REST API
- def list(inflate=false)
- rs = nil
- if inflate
- rs = @couchdb.get_view("data_bags", "entries", :include_docs => true, :startkey => @name, :endkey => @name)
- rs["rows"].collect { |r| r["doc"] }
- else
- rs = @couchdb.get_view("data_bags", "entries", :startkey => @name, :endkey => @name)
- rs["rows"].collect { |r| r["value"] }
- end
- end
-
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("data_bags", DESIGN_DOCUMENT)
- end
-
# As a string
def to_s
"data_bag[#{@name}]"
diff --git a/chef/lib/chef/data_bag_item.rb b/chef/lib/chef/data_bag_item.rb
index 87bde509a5..3528ba724a 100644
--- a/chef/lib/chef/data_bag_item.rb
+++ b/chef/lib/chef/data_bag_item.rb
@@ -23,8 +23,6 @@ require 'forwardable'
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
-require 'chef/index_queue'
require 'chef/data_bag'
require 'chef/mash'
require 'chef/json_compat'
@@ -36,35 +34,9 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
VALID_ID = /^[\-[:alnum:]_]+$/
- DESIGN_DOCUMENT = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag_item") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "data_bag_item") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- }
- }
- }
-
def self.validate_id!(id_str)
if id_str.nil? || ( id_str !~ VALID_ID )
raise Exceptions::InvalidDataBagItemID, "Data Bag items must have an id matching #{VALID_ID.inspect}, you gave: #{id_str.inspect}"
@@ -74,16 +46,12 @@ class Chef
# Define all Hash's instance methods as delegating to @raw_data
def_delegators(:@raw_data, *(Hash.instance_methods - Object.instance_methods))
- attr_accessor :couchdb_rev, :couchdb_id, :couchdb
attr_reader :raw_data
# Create a new Chef::DataBagItem
- def initialize(couchdb=nil)
- @couchdb_rev = nil
- @couchdb_id = nil
+ def initialize
@data_bag = nil
@raw_data = Mash.new
- @couchdb = couchdb || Chef::CouchDB.new
end
def chef_server_rest
@@ -138,7 +106,6 @@ class Chef
result = self.raw_data
result["chef_type"] = "data_bag_item"
result["data_bag"] = self.data_bag
- result["_rev"] = @couchdb_rev if @couchdb_rev
result
end
@@ -151,7 +118,6 @@ class Chef
"data_bag" => self.data_bag,
"raw_data" => self.raw_data
}
- result["_rev"] = @couchdb_rev if @couchdb_rev
result.to_json(*a)
end
@@ -169,24 +135,11 @@ class Chef
o.delete("chef_type")
o.delete("json_class")
o.delete("name")
- if o.has_key?("_rev")
- bag_item.couchdb_rev = o["_rev"]
- o.delete("_rev")
- end
- if o.has_key?("_id")
- bag_item.couchdb_id = o["_id"]
- bag_item.index_id = bag_item.couchdb_id
- o.delete("_id")
- end
+
bag_item.raw_data = Mash.new(o["raw_data"])
bag_item
end
- # Load a Data Bag Item by name from CouchDB
- def self.cdb_load(data_bag, name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("data_bag_item", object_name(data_bag, name))
- end
-
# Load a Data Bag Item by name via either the RESTful API or local data_bag_path if run in solo mode
def self.load(data_bag, name)
if Chef::Config[:solo]
@@ -205,21 +158,10 @@ class Chef
end
end
- # Remove this Data Bag Item from CouchDB
- def cdb_destroy
- Chef::Log.debug "Destroying data bag item: #{self.inspect}"
- @couchdb.delete("data_bag_item", object_name, @couchdb_rev)
- end
-
def destroy(data_bag=data_bag, databag_item=name)
chef_server_rest.delete_rest("data/#{data_bag}/#{databag_item}")
end
- # Save this Data Bag Item to CouchDB
- def cdb_save
- @couchdb_rev = @couchdb.store("data_bag_item", object_name, self)["rev"]
- end
-
# Save this Data Bag Item via RESTful API
def save(item_id=@raw_data['id'])
r = chef_server_rest
@@ -242,11 +184,6 @@ class Chef
self
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("data_bag_items", DESIGN_DOCUMENT)
- end
-
def ==(other)
other.respond_to?(:to_hash) &&
other.respond_to?(:data_bag) &&
diff --git a/chef/lib/chef/environment.rb b/chef/lib/chef/environment.rb
index 1e2cea282b..00cc253083 100644
--- a/chef/lib/chef/environment.rb
+++ b/chef/lib/chef/environment.rb
@@ -22,8 +22,6 @@ require 'chef/config'
require 'chef/mash'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
-require 'chef/index_queue'
require 'chef/version_constraint'
class Chef
@@ -33,52 +31,15 @@ class Chef
include Chef::Mixin::ParamsValidate
include Chef::Mixin::FromFile
- include Chef::IndexQueue::Indexable
COMBINED_COOKBOOK_CONSTRAINT = /(.+)(?:[\s]+)((?:#{Chef::VersionConstraint::OPS.join('|')})(?:[\s]+).+)$/.freeze
- attr_accessor :couchdb, :couchdb_rev
- attr_reader :couchdb_id
-
- DESIGN_DOCUMENT = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "environment") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "environment") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- }
- }
- }
-
- def initialize(couchdb=nil)
+ def initialize
@name = ''
@description = ''
@default_attributes = Mash.new
@override_attributes = Mash.new
@cookbook_versions = Hash.new
- @couchdb_rev = nil
- @couchdb_id = nil
- @couchdb = couchdb || Chef::CouchDB.new
- end
-
- def couchdb_id=(value)
- @couchdb_id = value
- self.index_id = value
end
def chef_server_rest
@@ -163,7 +124,6 @@ class Chef
"default_attributes" => @default_attributes,
"override_attributes" => @override_attributes
}
- result["_rev"] = couchdb_rev if couchdb_rev
result
end
@@ -260,17 +220,9 @@ class Chef
environment.cookbook_versions(o["cookbook_versions"])
environment.default_attributes(o["default_attributes"])
environment.override_attributes(o["override_attributes"])
- environment.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- environment.couchdb_id = o["_id"] if o.has_key?("_id")
environment
end
- def self.cdb_list(inflate=false, couchdb=nil)
- es = (couchdb || Chef::CouchDB.new).list("environments", inflate)
- lookup = (inflate ? "value" : "key")
- es["rows"].collect { |e| e[lookup] }
- end
-
def self.list(inflate=false)
if inflate
response = Hash.new
@@ -283,34 +235,14 @@ class Chef
end
end
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("environment", name)
- end
-
def self.load(name)
chef_server_rest.get_rest("environments/#{name}")
end
- def self.exists?(name, couchdb)
- begin
- self.cdb_load(name, couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- nil
- end
- end
-
- def cdb_destroy
- couchdb.delete("environment", @name, couchdb_rev)
- end
-
def destroy
chef_server_rest.delete_rest("environments/#{@name}")
end
- def cdb_save
- self.couchdb_rev = couchdb.store("environment", @name, self)["rev"]
- end
-
def save
begin
chef_server_rest.put_rest("environments/#{@name}", self)
@@ -326,106 +258,6 @@ class Chef
self
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("environments", DESIGN_DOCUMENT)
- end
-
- # Loads the set of Chef::CookbookVersion objects available to a given environment
- # === Returns
- # Hash
- # i.e.
- # {
- # "cookbook_name" => [ Chef::CookbookVersion ... ] ## the array of CookbookVersions is sorted highest to lowest
- # }
- #
- # There will be a key for every cookbook. If no CookbookVersions
- # are available for the specified environment the value will be an
- # empty list.
- #
- def self.cdb_load_filtered_cookbook_versions(name, couchdb=nil)
- version_constraints = cdb_load(name, couchdb).cookbook_versions.inject({}) {|res, (k,v)| res[k] = Chef::VersionConstraint.new(v); res}
-
- # inject all cookbooks into the hash while filtering out restricted versions, then sort the individual arrays
- cookbook_list = Chef::CookbookVersion.cdb_list(true, couchdb)
-
- filtered_list = cookbook_list.inject({}) do |res, cookbook|
- # FIXME: should cookbook.version return a Chef::Version?
- version = Chef::Version.new(cookbook.version)
- requirement_satisfied = version_constraints.has_key?(cookbook.name) ? version_constraints[cookbook.name].include?(version) : true
- # we want a key for every cookbook, even if no versions are available
- res[cookbook.name] ||= []
- res[cookbook.name] << cookbook if requirement_satisfied
- res
- end
-
- sorted_list = filtered_list.inject({}) do |res, (cookbook_name, versions)|
- res[cookbook_name] = versions.sort.reverse
- res
- end
-
- sorted_list
- end
-
- # Like +cdb_load_filtered_cookbook_versions+, loads the set of
- # cookbooks available in a given environment. The difference is that
- # this method will load Chef::MinimalCookbookVersion objects that
- # contain only the information necessary for solving a cookbook
- # collection for a given run list. The user of this method must call
- # Chef::MinimalCookbookVersion.load_full_versions_of() after solving
- # the cookbook collection to get the full objects.
- # === Returns
- # Hash
- # i.e.
- # {
- # "cookbook_name" => [ Chef::CookbookVersion ... ] ## the array of CookbookVersions is sorted highest to lowest
- # }
- #
- # There will be a key for every cookbook. If no CookbookVersions
- # are available for the specified environment the value will be an
- # empty list.
- def self.cdb_minimal_filtered_versions(name, couchdb=nil)
- version_constraints = cdb_load(name, couchdb).cookbook_versions.inject({}) {|res, (k,v)| res[k] = Chef::VersionConstraint.new(v); res}
-
- # inject all cookbooks into the hash while filtering out restricted versions, then sort the individual arrays
- cookbook_list = Chef::MinimalCookbookVersion.load_all(couchdb)
-
- filtered_list = cookbook_list.inject({}) do |res, cookbook|
- # FIXME: should cookbook.version return a Chef::Version?
- version = Chef::Version.new(cookbook.version)
- requirement_satisfied = version_constraints.has_key?(cookbook.name) ? version_constraints[cookbook.name].include?(version) : true
- # we want a key for every cookbook, even if no versions are available
- res[cookbook.name] ||= []
- res[cookbook.name] << cookbook if requirement_satisfied
- res
- end
-
- sorted_list = filtered_list.inject({}) do |res, (cookbook_name, versions)|
- res[cookbook_name] = versions.sort.reverse
- res
- end
-
- sorted_list
- end
-
- def self.cdb_load_filtered_recipe_list(name, couchdb=nil)
- cdb_load_filtered_cookbook_versions(name, couchdb).map do |cb_name, cb|
- if cb.empty? # no available versions
- [] # empty list elided with flatten
- else
- latest_version = cb.first
- latest_version.recipe_filenames_by_name.keys.map do |recipe|
- case recipe
- when DEFAULT
- cb_name
- else
- "#{cb_name}::#{recipe}"
- end
- end
- end
- end.flatten
- end
-
def self.load_filtered_recipe_list(environment)
chef_server_rest.get_rest("environments/#{environment}/recipes")
end
@@ -451,16 +283,5 @@ class Chef
end
end
- def self.create_default_environment(couchdb=nil)
- couchdb = couchdb || Chef::CouchDB.new
- begin
- Chef::Environment.cdb_load('_default', couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- env = Chef::Environment.new(couchdb)
- env.name '_default'
- env.description 'The default Chef environment'
- env.cdb_save
- end
- end
end
end
diff --git a/chef/lib/chef/exceptions.rb b/chef/lib/chef/exceptions.rb
index c5d213f8b3..87802639d3 100644
--- a/chef/lib/chef/exceptions.rb
+++ b/chef/lib/chef/exceptions.rb
@@ -54,7 +54,6 @@ class Chef
class Group < RuntimeError; end
class Link < RuntimeError; end
class Mount < RuntimeError; end
- class CouchDBNotFound < RuntimeError; end
class PrivateKeyMissing < RuntimeError; end
class CannotWritePrivateKey < RuntimeError; end
class RoleNotFound < RuntimeError; end
@@ -112,7 +111,7 @@ class Chef
# File operation attempted but no permissions to perform it
class InsufficientPermissions < RuntimeError; end
-
+
# Ifconfig failed
class Ifconfig < RuntimeError; end
diff --git a/chef/lib/chef/index_queue.rb b/chef/lib/chef/index_queue.rb
deleted file mode 100644
index b350949aae..0000000000
--- a/chef/lib/chef/index_queue.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require "singleton"
-require "bunny"
-
-require "chef/index_queue/amqp_client"
-require "chef/index_queue/indexable"
-require "chef/index_queue/consumer"
-
-class Chef
- module IndexQueue
- end
-end
diff --git a/chef/lib/chef/index_queue/amqp_client.rb b/chef/lib/chef/index_queue/amqp_client.rb
deleted file mode 100644
index a7d155f4d1..0000000000
--- a/chef/lib/chef/index_queue/amqp_client.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-#
-# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-class Chef
- module IndexQueue
- class AmqpClient
- VNODES = 1024
-
- include Singleton
-
- def initialize
- reset!
- end
-
- def reset!
- @amqp_client && amqp_client.connected? && amqp_client.stop
- @amqp_client = nil
- @exchange = nil
- end
-
- def stop
- @amqp_client && @amqp_client.stop
- end
-
- def amqp_client
- unless @amqp_client
- begin
- @amqp_client = Bunny.new(amqp_opts)
- Chef::Log.debug "Starting AMQP connection with client settings: #{@amqp_client.inspect}"
- @amqp_client.start
- @amqp_client.qos(:prefetch_count => 1)
- rescue Bunny::ServerDownError => e
- Chef::Log.fatal "Could not connect to rabbitmq. Is it running, reachable, and configured correctly?"
- raise e
- rescue Bunny::ProtocolError => e
- Chef::Log.fatal "Connection to rabbitmq refused. Check your rabbitmq configuration and chef's amqp* settings"
- raise e
- end
- end
- @amqp_client
- end
-
- def exchange
- @exchange ||= amqp_client.exchange("chef-indexer", :durable => true, :type => :fanout)
- end
-
- def disconnected!
- Chef::Log.error("Disconnected from the AMQP Broker (RabbitMQ)")
- @amqp_client = nil
- reset!
- end
-
- def queue_for_object(obj_id)
- retries = 0
- vnode_tag = obj_id_to_int(obj_id) % VNODES
- begin
- yield amqp_client.queue("vnode-#{vnode_tag}", :passive => false, :durable => true, :exclusive => false, :auto_delete => false)
- rescue Bunny::ServerDownError, Bunny::ConnectionError, Errno::ECONNRESET
- disconnected!
- if (retries += 1) < 2
- Chef::Log.info("Attempting to reconnect to the AMQP broker")
- retry
- else
- Chef::Log.fatal("Could not re-connect to the AMQP broker, giving up")
- raise
- end
- end
- end
-
- private
-
- # Sometimes object ids are "proper" UUIDs, like "64bc00eb-120b-b6a2-ec0e-34fc90d151be"
- # and sometimes they omit the dashes, like "64bc00eb120bb6a2ec0e34fc90d151be"
- # UUIDTools uses different methods to parse the different styles.
- def obj_id_to_int(obj_id)
- UUIDTools::UUID.parse(obj_id).to_i
- rescue ArgumentError
- UUIDTools::UUID.parse_hexdigest(obj_id).to_i
- end
-
- def durable_queue?
- !!Chef::Config[:amqp_consumer_id]
- end
-
- def consumer_id
- Chef::Config[:amqp_consumer_id] || UUIDTools::UUID.random_create.to_s
- end
-
- def amqp_opts
- { :spec => '08',
- :host => Chef::Config[:amqp_host],
- :port => Chef::Config[:amqp_port],
- :user => Chef::Config[:amqp_user],
- :pass => Chef::Config[:amqp_pass],
- :vhost => Chef::Config[:amqp_vhost]}
- end
-
- end
- end
-end
-
diff --git a/chef/lib/chef/index_queue/consumer.rb b/chef/lib/chef/index_queue/consumer.rb
deleted file mode 100644
index 8701cffa47..0000000000
--- a/chef/lib/chef/index_queue/consumer.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-class Chef
- module IndexQueue
- module Consumer
- module ClassMethods
- def expose(*methods)
- @exposed_methods = Array(@exposed_methods)
- @exposed_methods += methods
- end
-
- def exposed_methods
- @exposed_methods || []
- end
-
- def whitelisted?(method_name)
- exposed_methods.include?(method_name)
- end
- end
-
- def self.included(including_class)
- including_class.send(:extend, ClassMethods)
- end
-
- def run
- Chef::Log.debug("Starting Index Queue Consumer")
- AmqpClient.instance.queue # triggers connection setup
-
- begin
- AmqpClient.instance.queue.subscribe(:ack => true, :timeout => false) do |message|
- call_action_for_message(message)
- end
- rescue Bunny::ConnectionError, Errno::ECONNRESET, Bunny::ServerDownError
- AmqpClient.instance.disconnected!
- Chef::Log.warn "Connection to rabbitmq lost. attempting to reconnect"
- sleep 1
- retry
- end
- end
- alias :start :run
-
- def call_action_for_message(message)
- amqp_payload = Chef::JSONCompat.from_json(message[:payload], :create_additions => false, :max_nesting => false)
- action = amqp_payload["action"].to_sym
- app_payload = amqp_payload["payload"]
- assert_method_whitelisted(action)
- send(action, app_payload)
- end
-
- private
-
- def assert_method_whitelisted(method_name)
- unless self.class.whitelisted?(method_name)
- raise ArgumentError, "non-exposed method #{method_name} called via index queue"
- end
- end
-
- end
- end
-end
diff --git a/chef/lib/chef/index_queue/indexable.rb b/chef/lib/chef/index_queue/indexable.rb
deleted file mode 100644
index 73fd08bbb5..0000000000
--- a/chef/lib/chef/index_queue/indexable.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-#
-# Author:: Daniel DeLeo (<dan@kallistec.com>)
-# Author:: Seth Falcon (<seth@opscode.com>)
-# Copyright:: Copyright (c) 2009 Daniel DeLeo
-# Copyright:: Copyright (c) 2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-require 'chef/json_compat'
-
-class Chef
- module IndexQueue
- module Indexable
-
- module ClassMethods
-
- def index_object_type(explicit_type_name=nil)
- @index_object_type = explicit_type_name.to_s if explicit_type_name
- @index_object_type
- end
-
- # Resets all metadata used for indexing to nil. Used for testing
- def reset_index_metadata!
- @index_object_type = nil
- end
-
- end
-
- def self.included(including_class)
- including_class.send(:extend, ClassMethods)
- end
-
- attr_accessor :index_id
-
- def index_object_type
- self.class.index_object_type || Mixin::ConvertToClassName.snake_case_basename(self.class.name)
- end
-
- def with_indexer_metadata(indexer_metadata={})
- # changing input param symbol keys to strings, as the keys in hash that goes to solr are expected to be strings [cb]
- # Ruby 1.9 hates you, cb [dan]
- with_metadata = {}
- indexer_metadata.each_key do |key|
- with_metadata[key.to_s] = indexer_metadata[key]
- end
-
- with_metadata["type"] ||= self.index_object_type
- with_metadata["id"] ||= self.index_id
- with_metadata["database"] ||= Chef::Config[:couchdb_database]
- with_metadata["item"] ||= self.to_hash
- with_metadata["enqueued_at"] ||= Time.now.utc.to_i
-
- raise ArgumentError, "Type, Id, or Database missing in index operation: #{with_metadata.inspect}" if (with_metadata["id"].nil? or with_metadata["type"].nil?)
- with_metadata
- end
-
- def add_to_index(metadata={})
- Chef::Log.debug("Pushing item to index queue for addition: #{self.with_indexer_metadata(metadata)}")
- object_with_metadata = with_indexer_metadata(metadata)
- obj_id = object_with_metadata["id"]
- obj = {:action => :add, :payload => self.with_indexer_metadata(metadata)}
-
- publish_object(obj_id, obj)
- end
-
- def delete_from_index(metadata={})
- Chef::Log.debug("Pushing item to index queue for deletion: #{self.with_indexer_metadata(metadata)}")
- object_with_metadata = with_indexer_metadata(metadata)
- obj_id = object_with_metadata["id"]
- obj = {:action => :delete, :payload => self.with_indexer_metadata(metadata)}
-
- publish_object(obj_id, obj)
- end
-
- private
-
- # Uses the publisher to update the object's queue. If
- # Chef::Config[:persistent_queue] is true, the update is wrapped
- # in a transaction.
- def publish_object(object_id, object)
- publisher = AmqpClient.instance
- begin
- publisher.amqp_client.tx_select if Chef::Config[:persistent_queue]
- publisher.queue_for_object(object_id) do |queue|
- queue.publish(Chef::JSONCompat.to_json(object), :persistent => Chef::Config[:persistent_queue])
- end
- publisher.amqp_client.tx_commit if Chef::Config[:persistent_queue]
- rescue
- publisher.amqp_client.tx_rollback if Chef::Config[:persistent_queue]
- raise
- end
-
- true
- end
-
- end
- end
-end
diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb
index 1229e0db28..92a2374bce 100644
--- a/chef/lib/chef/node.rb
+++ b/chef/lib/chef/node.rb
@@ -28,11 +28,9 @@ require 'chef/mixin/from_file'
require 'chef/mixin/deep_merge'
require 'chef/dsl/include_attribute'
require 'chef/environment'
-require 'chef/couchdb'
require 'chef/rest'
require 'chef/run_list'
require 'chef/node/attribute'
-require 'chef/index_queue'
require 'chef/mash'
require 'chef/json_compat'
require 'chef/search/query'
@@ -44,8 +42,7 @@ class Chef
def_delegators :attributes, :keys, :each_key, :each_value, :key?, :has_key?
- attr_accessor :recipe_list, :couchdb, :couchdb_rev, :run_state, :run_list
- attr_reader :couchdb_id
+ attr_accessor :recipe_list, :run_state, :run_list
attr_accessor :run_context
@@ -54,103 +51,9 @@ class Chef
include Chef::Mixin::CheckHelper
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
-
- DESIGN_DOCUMENT = {
- "version" => 11,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- },
- "status" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- var to_emit = { "name": doc.name, "chef_environment": doc.chef_environment };
- if (doc["attributes"]["fqdn"]) {
- to_emit["fqdn"] = doc["attributes"]["fqdn"];
- } else {
- to_emit["fqdn"] = "Undefined";
- }
- if (doc["attributes"]["ipaddress"]) {
- to_emit["ipaddress"] = doc["attributes"]["ipaddress"];
- } else {
- to_emit["ipaddress"] = "Undefined";
- }
- if (doc["attributes"]["ohai_time"]) {
- to_emit["ohai_time"] = doc["attributes"]["ohai_time"];
- } else {
- to_emit["ohai_time"] = "Undefined";
- }
- if (doc["attributes"]["uptime"]) {
- to_emit["uptime"] = doc["attributes"]["uptime"];
- } else {
- to_emit["uptime"] = "Undefined";
- }
- if (doc["attributes"]["platform"]) {
- to_emit["platform"] = doc["attributes"]["platform"];
- } else {
- to_emit["platform"] = "Undefined";
- }
- if (doc["attributes"]["platform_version"]) {
- to_emit["platform_version"] = doc["attributes"]["platform_version"];
- } else {
- to_emit["platform_version"] = "Undefined";
- }
- if (doc["run_list"]) {
- to_emit["run_list"] = doc["run_list"];
- } else {
- to_emit["run_list"] = "Undefined";
- }
- emit(doc.name, to_emit);
- }
- }
- EOJS
- },
- "by_run_list" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- if (doc['run_list']) {
- for (var i=0; i < doc.run_list.length; i++) {
- emit(doc['run_list'][i], doc.name);
- }
- }
- }
- }
- EOJS
- },
- "by_environment" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "node") {
- var env = (doc['chef_environment'] == null ? "_default" : doc['chef_environment']);
- emit(env, doc.name);
- }
- }
- EOJS
- }
- },
- }
# Create a new Chef::Node object.
- def initialize(couchdb=nil)
+ def initialize
@name = nil
@chef_environment = '_default'
@@ -158,18 +61,9 @@ class Chef
@attributes = Chef::Node::Attribute.new({}, {}, {}, {})
- @couchdb_rev = nil
- @couchdb_id = nil
- @couchdb = couchdb || Chef::CouchDB.new
-
@run_state = {}
end
- def couchdb_id=(value)
- @couchdb_id = value
- @index_id = value
- end
-
# Used by DSL
def node
self
@@ -470,7 +364,6 @@ class Chef
#Render correctly for run_list items so malformed json does not result
"run_list" => run_list.run_list.map { |item| item.to_s }
}
- result["_rev"] = couchdb_rev if couchdb_rev
result.to_json(*a)
end
@@ -502,17 +395,9 @@ class Chef
else
o["recipes"].each { |r| node.recipes << r }
end
- node.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- node.couchdb_id = o["_id"] if o.has_key?("_id")
- node.index_id = node.couchdb_id
node
end
- def self.cdb_list_by_environment(environment, inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).get_view("nodes", "by_environment", :include_docs => inflate, :startkey => environment, :endkey => environment)
- inflate ? rs["rows"].collect {|r| r["doc"]} : rs["rows"].collect {|r| r["value"]}
- end
-
def self.list_by_environment(environment, inflate=false)
if inflate
response = Hash.new
@@ -523,14 +408,6 @@ class Chef
end
end
- # List all the Chef::Node objects in the CouchDB. If inflate is set to true, you will get
- # the full list of all Nodes, fully inflated.
- def self.cdb_list(inflate=false, couchdb=nil)
- rs =(couchdb || Chef::CouchDB.new).list("nodes", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
def self.list(inflate=false)
if inflate
response = Hash.new
@@ -543,19 +420,6 @@ class Chef
end
end
- # Load a node by name from CouchDB
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("node", name)
- end
-
- def self.exists?(nodename, couchdb)
- begin
- self.cdb_load(nodename, couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- nil
- end
- end
-
def self.find_or_create(node_name)
load(node_name)
rescue Net::HTTPServerException => e
@@ -576,21 +440,11 @@ class Chef
Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes/#{name}")
end
- # Remove this node from the CouchDB
- def cdb_destroy
- couchdb.delete("node", name, couchdb_rev)
- end
-
# Remove this node via the REST API
def destroy
chef_server_rest.delete_rest("nodes/#{name}")
end
- # Save this node to the CouchDB
- def cdb_save
- @couchdb_rev = couchdb.store("node", name, self)["rev"]
- end
-
# Save this node via the REST API
def save
# Try PUT. If the node doesn't yet exist, PUT will return 404,
@@ -614,11 +468,6 @@ class Chef
self
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("nodes", DESIGN_DOCUMENT)
- end
-
def to_s
"node[#{name}]"
end
diff --git a/chef/lib/chef/openid_registration.rb b/chef/lib/chef/openid_registration.rb
deleted file mode 100644
index f7bb9595d9..0000000000
--- a/chef/lib/chef/openid_registration.rb
+++ /dev/null
@@ -1,187 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/config'
-require 'chef/mixin/params_validate'
-require 'chef/couchdb'
-require 'chef/index_queue'
-require 'digest/sha1'
-require 'chef/json_compat'
-
-class Chef
- class OpenIDRegistration
-
- attr_accessor :name, :salt, :validated, :password, :couchdb_rev, :admin
-
- include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
-
- DESIGN_DOCUMENT = {
- "version" => 3,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "openid_registration") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "openid_registration") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- },
- "validated" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "openid_registration") {
- if (doc.validated == true) {
- emit(doc.name, doc);
- }
- }
- }
- EOJS
- },
- "unvalidated" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "openid_registration") {
- if (doc.validated == false) {
- emit(doc.name, doc);
- }
- }
- }
- EOJS
- },
- },
- }
-
- # Create a new Chef::OpenIDRegistration object.
- def initialize()
- @name = nil
- @salt = nil
- @password = nil
- @validated = false
- @admin = false
- @couchdb_rev = nil
- @couchdb = Chef::CouchDB.new
- end
-
- def name=(n)
- @name = n.gsub(/\./, '_')
- end
-
- # Set the password for this object.
- def set_password(password)
- @salt = generate_salt
- @password = encrypt_password(@salt, password)
- end
-
- # Serialize this object as a hash
- def to_json(*a)
- attributes = Hash.new
- recipes = Array.new
- result = {
- 'name' => @name,
- 'json_class' => self.class.name,
- 'salt' => @salt,
- 'password' => @password,
- 'validated' => @validated,
- 'admin' => @admin,
- 'chef_type' => 'openid_registration',
- }
- result["_rev"] = @couchdb_rev if @couchdb_rev
- result.to_json(*a)
- end
-
- # Create a Chef::Node from JSON
- def self.json_create(o)
- me = new
- me.name = o["name"]
- me.salt = o["salt"]
- me.password = o["password"]
- me.validated = o["validated"]
- me.admin = o["admin"]
- me.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- me
- end
-
- # List all the Chef::OpenIDRegistration objects in the CouchDB. If inflate is set to true, you will get
- # the full list of all registration objects. Otherwise, you'll just get the IDs
- def self.list(inflate=false)
- rs = Chef::CouchDB.new.list("registrations", inflate)
- if inflate
- rs["rows"].collect { |r| r["value"] }
- else
- rs["rows"].collect { |r| r["key"] }
- end
- end
-
- def self.cdb_list(*args)
- list(*args)
- end
-
- # Load an OpenIDRegistration by name from CouchDB
- def self.load(name)
- Chef::CouchDB.new.load("openid_registration", name)
- end
-
- # Whether or not there is an OpenID Registration with this key.
- def self.has_key?(name)
- Chef::CouchDB.new.has_key?("openid_registration", name)
- end
-
- # Remove this OpenIDRegistration from the CouchDB
- def destroy
- @couchdb.delete("openid_registration", @name, @couchdb_rev)
- end
-
- # Save this OpenIDRegistration to the CouchDB
- def save
- results = @couchdb.store("openid_registration", @name, self)
- @couchdb_rev = results["rev"]
- end
-
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- couchdb ||= Chef::CouchDB.new
- couchdb.create_design_document("registrations", DESIGN_DOCUMENT)
- end
-
- protected
-
- def generate_salt
- salt = Time.now.to_s
- chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
- 1.upto(30) { |i| salt << chars[rand(chars.size-1)] }
- salt
- end
-
- def encrypt_password(salt, password)
- Digest::SHA1.hexdigest("--#{salt}--#{password}--")
- end
-
- end
-end
diff --git a/chef/lib/chef/role.rb b/chef/lib/chef/role.rb
index c428472f1f..78bbfadb88 100644
--- a/chef/lib/chef/role.rb
+++ b/chef/lib/chef/role.rb
@@ -21,9 +21,7 @@
require 'chef/config'
require 'chef/mixin/params_validate'
require 'chef/mixin/from_file'
-require 'chef/couchdb'
require 'chef/run_list'
-require 'chef/index_queue'
require 'chef/mash'
require 'chef/json_compat'
require 'chef/search/query'
@@ -33,51 +31,14 @@ class Chef
include Chef::Mixin::FromFile
include Chef::Mixin::ParamsValidate
- include Chef::IndexQueue::Indexable
-
- DESIGN_DOCUMENT = {
- "version" => 6,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "role") {
- emit(doc.name, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "role") {
- emit(doc.name, doc.name);
- }
- }
- EOJS
- }
- }
- }
-
- attr_accessor :couchdb_rev, :couchdb
- attr_reader :couchdb_id
# Create a new Chef::Role object.
- def initialize(couchdb=nil)
+ def initialize
@name = ''
@description = ''
@default_attributes = Mash.new
@override_attributes = Mash.new
@env_run_lists = {"_default" => Chef::RunList.new}
- @couchdb_rev = nil
- @couchdb_id = nil
- @couchdb = couchdb || Chef::CouchDB.new
- end
-
- def couchdb_id=(value)
- @couchdb_id = value
- self.index_id = value
end
def chef_server_rest
@@ -177,7 +138,6 @@ class Chef
accumulator
end
}
- result["_rev"] = couchdb_rev if couchdb_rev
result
end
@@ -214,20 +174,9 @@ class Chef
end
role.env_run_lists(env_run_list_hash)
- role.couchdb_rev = o["_rev"] if o.has_key?("_rev")
- role.index_id = role.couchdb_id
- role.couchdb_id = o["_id"] if o.has_key?("_id")
role
end
- # List all the Chef::Role objects in the CouchDB. If inflate is set to true, you will get
- # the full list of all Roles, fully inflated.
- def self.cdb_list(inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).list("roles", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
# Get the list of all roles from the API.
def self.list(inflate=false)
if inflate
@@ -241,24 +190,11 @@ class Chef
end
end
- # Load a role by name from CouchDB
- def self.cdb_load(name, couchdb=nil)
- (couchdb || Chef::CouchDB.new).load("role", name)
- end
-
# Load a role by name from the API
def self.load(name)
chef_server_rest.get_rest("roles/#{name}")
end
- def self.exists?(rolename, couchdb)
- begin
- self.cdb_load(rolename, couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- nil
- end
- end
-
def environment(env_name)
chef_server_rest.get_rest("roles/#{@name}/environments/#{env_name}")
end
@@ -267,21 +203,11 @@ class Chef
chef_server_rest.get_rest("roles/#{@name}/environments")
end
- # Remove this role from the CouchDB
- def cdb_destroy
- couchdb.delete("role", @name, couchdb_rev)
- end
-
# Remove this role via the REST API
def destroy
chef_server_rest.delete_rest("roles/#{@name}")
end
- # Save this role to the CouchDB
- def cdb_save
- self.couchdb_rev = couchdb.store("role", @name, self)["rev"]
- end
-
# Save this role via the REST API
def save
begin
@@ -299,11 +225,6 @@ class Chef
self
end
- # Set up our CouchDB design document
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("roles", DESIGN_DOCUMENT)
- end
-
# As a string
def to_s
"role[#{@name}]"
@@ -328,22 +249,5 @@ class Chef
end
end
- # Sync all the json roles with couchdb from disk
- def self.sync_from_disk_to_couchdb
- Dir[File.join(Chef::Config[:role_path], "*.json")].each do |role_file|
- short_name = File.basename(role_file, ".json")
- Chef::Log.warn("Loading #{short_name}")
- r = Chef::Role.from_disk(short_name, "json")
- begin
- couch_role = Chef::Role.cdb_load(short_name)
- r.couchdb_rev = couch_role.couchdb_rev
- Chef::Log.debug("Replacing role #{short_name} with data from #{role_file}")
- rescue Chef::Exceptions::CouchDBNotFound
- Chef::Log.debug("Creating role #{short_name} with data from #{role_file}")
- end
- r.cdb_save
- end
- end
-
end
end
diff --git a/chef/lib/chef/run_list.rb b/chef/lib/chef/run_list.rb
index 1e4bdd255a..684c5e19fc 100644
--- a/chef/lib/chef/run_list.rb
+++ b/chef/lib/chef/run_list.rb
@@ -155,8 +155,6 @@ class Chef
RunListExpansionFromDisk.new(environment, @run_list_items)
when 'server'
RunListExpansionFromAPI.new(environment, @run_list_items, opts[:rest])
- when 'couchdb'
- RunListExpansionFromCouchDB.new(environment, @run_list_items, opts[:couchdb])
end
end
diff --git a/chef/lib/chef/run_list/run_list_expansion.rb b/chef/lib/chef/run_list/run_list_expansion.rb
index 690eb3392b..7b8108a2d4 100644
--- a/chef/lib/chef/run_list/run_list_expansion.rb
+++ b/chef/lib/chef/run_list/run_list_expansion.rb
@@ -21,7 +21,6 @@ require 'chef/mash'
require 'chef/mixin/deep_merge'
require 'chef/role'
-require 'chef/couchdb'
require 'chef/rest'
class Chef
@@ -188,19 +187,5 @@ class Chef
end
end
- # Expand a run list from couchdb. Used in chef-server-api
- class RunListExpansionFromCouchDB < RunListExpansion
-
- def couchdb
- source
- end
-
- def fetch_role(name, included_by)
- Chef::Role.cdb_load(name, couchdb)
- rescue Chef::Exceptions::CouchDBNotFound
- role_not_found(name, included_by)
- end
-
- end
end
end
diff --git a/chef/lib/chef/sandbox.rb b/chef/lib/chef/sandbox.rb
deleted file mode 100644
index 4d05a1db70..0000000000
--- a/chef/lib/chef/sandbox.rb
+++ /dev/null
@@ -1,153 +0,0 @@
-#
-# Author:: Tim Hinderliter (<tim@opscode.com>)
-# Copyright:: Copyright (c) 2010 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require 'chef/log'
-require 'uuidtools'
-
-class Chef
- class Sandbox
- attr_accessor :is_completed, :create_time
- alias_method :is_completed?, :is_completed
- attr_reader :guid
-
- alias :name :guid
-
- attr_accessor :couchdb, :couchdb_id, :couchdb_rev
-
- # list of checksum ids
- attr_accessor :checksums
-
- DESIGN_DOCUMENT = {
- "version" => 1,
- "language" => "javascript",
- "views" => {
- "all" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "sandbox") {
- emit(doc.guid, doc);
- }
- }
- EOJS
- },
- "all_id" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "sandbox") {
- emit(doc.guid, doc.guid);
- }
- }
- EOJS
- },
- "all_incomplete" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "sandbox" && !doc.is_completed) {
- emit(doc.guid, doc.guid);
- }
- }
- EOJS
- },
- "all_completed" => {
- "map" => <<-EOJS
- function(doc) {
- if (doc.chef_type == "sandbox" && doc.is_completed) {
- emit(doc.guid, doc.guid);
- }
- }
- EOJS
- },
- }
- }
-
- # Creates a new Chef::Sandbox object.
- #
- # === Returns
- # object<Chef::Sandbox>:: Duh. :)
- def initialize(guid=nil, couchdb=nil)
- @guid = guid || UUIDTools::UUID.random_create.to_s.gsub(/\-/,'').downcase
- @is_completed = false
- @create_time = Time.now.iso8601
- @checksums = Array.new
- end
-
- def include?(checksum)
- @checksums.include?(checksum)
- end
-
- alias :member? :include?
-
- def to_json(*a)
- result = {
- :guid => guid,
- :name => name, # same as guid, used for id_map
- :checksums => checksums,
- :create_time => create_time,
- :is_completed => is_completed,
- :json_class => self.class.name,
- :chef_type => 'sandbox'
- }
- result["_rev"] = @couchdb_rev if @couchdb_rev
- result.to_json(*a)
- end
-
- def self.json_create(o)
- sandbox = new(o['guid'])
- sandbox.checksums = o['checksums']
- sandbox.create_time = o['create_time']
- sandbox.is_completed = o['is_completed']
- if o.has_key?('_rev')
- sandbox.couchdb_rev = o["_rev"]
- o.delete("_rev")
- end
- if o.has_key?("_id")
- sandbox.couchdb_id = o["_id"]
- #sandbox.index_id = sandbox.couchdb_id
- o.delete("_id")
- end
- sandbox
- end
-
- ##
- # Couchdb
- ##
-
- def self.create_design_document(couchdb=nil)
- (couchdb || Chef::CouchDB.new).create_design_document("sandboxes", DESIGN_DOCUMENT)
- end
-
- def self.cdb_list(inflate=false, couchdb=nil)
- rs = (couchdb || Chef::CouchDB.new).list("sandboxes", inflate)
- lookup = (inflate ? "value" : "key")
- rs["rows"].collect { |r| r[lookup] }
- end
-
- def self.cdb_load(guid, couchdb=nil)
- # Probably want to look for a view here at some point
- (couchdb || Chef::CouchDB.new).load("sandbox", guid)
- end
-
- def cdb_destroy
- (couchdb || Chef::CouchDB.new).delete("sandbox", guid, @couchdb_rev)
- end
-
- def cdb_save(couchdb=nil)
- @couchdb_rev = (couchdb || Chef::CouchDB.new).store("sandbox", guid, self)["rev"]
- end
-
- end
-end
diff --git a/chef/lib/chef/solr_query.rb b/chef/lib/chef/solr_query.rb
deleted file mode 100644
index 3360ecc24d..0000000000
--- a/chef/lib/chef/solr_query.rb
+++ /dev/null
@@ -1,187 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Author:: Seth Falcon (<seth@opscode.com>)
-# Copyright:: Copyright (c) 2009-2011 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/mixin/xml_escape'
-require 'chef/log'
-require 'chef/config'
-require 'chef/couchdb'
-require 'chef/solr_query/solr_http_request'
-require 'chef/solr_query/query_transform'
-
-class Chef
- class SolrQuery
-
- ID_KEY = "X_CHEF_id_CHEF_X"
- DEFAULT_PARAMS = Mash.new(:start => 0, :rows => 1000, :sort => "#{ID_KEY} asc", :wt => 'json', :indent => 'off').freeze
- FILTER_PARAM_MAP = {:database => 'X_CHEF_database_CHEF_X', :type => "X_CHEF_type_CHEF_X", :data_bag => 'data_bag'}
- VALID_PARAMS = [:start,:rows,:sort,:q,:type]
- BUILTIN_SEARCH_TYPES = ["role","node","client","environment"]
- DATA_BAG_ITEM = 'data_bag_item'
-
- include Chef::Mixin::XMLEscape
-
- attr_accessor :query
- attr_accessor :params
-
- # Create a new Query object - takes the solr_url and optional
- # Chef::CouchDB object to inflate objects into.
- def initialize(couchdb = nil)
- @filter_query = {}
- @params = {}
-
- if couchdb.nil?
- @database = Chef::Config[:couchdb_database]
- @couchdb = Chef::CouchDB.new(nil, Chef::Config[:couchdb_database])
- else
- unless couchdb.respond_to?(:couchdb_database)
- Chef::Log.warn("Passing the database name to Chef::Solr::Query initialization is deprecated. Please pass in the Chef::CouchDB object instead.")
- @database = couchdb
- @couchdb = Chef::CouchDB.new(nil, couchdb)
- else
- @database = couchdb.couchdb_database
- @couchdb = couchdb
- end
- end
- end
-
- def self.from_params(params, couchdb=nil)
- query = new(couchdb)
- query.params = VALID_PARAMS.inject({}) do |p, param_name|
- p[param_name] = params[param_name] if params.key?(param_name)
- p
- end
- query.update_filter_query_from_params
- query.update_query_from_params
- query
- end
-
- def filter_by(filter_query_params)
- filter_query_params.each do |key, value|
- @filter_query[FILTER_PARAM_MAP[key]] = value
- end
- end
-
- def filter_query
- @filter_query.map { |param, value| "+#{param}:#{value}" }.join(' ')
- end
-
- def filter_by_type(type)
- case type
- when *BUILTIN_SEARCH_TYPES
- filter_by(:type => type)
- else
- filter_by(:type => DATA_BAG_ITEM, :data_bag => type)
- end
- end
-
- def update_filter_query_from_params
- filter_by(:database => @database)
- filter_by_type(params.delete(:type))
- end
-
- def update_query_from_params
- original_query = URI.decode(params.delete(:q) || "*:*")
- @query = Chef::SolrQuery::QueryTransform.transform(original_query)
- end
-
- def objects
- if !object_ids.empty?
- @bulk_objects ||= @couchdb.bulk_get(object_ids)
- Chef::Log.debug { "Bulk get of objects: #{@bulk_objects.inspect}" }
- @bulk_objects
- else
- []
- end
- end
-
- def object_ids
- @object_ids ||= results["response"]["docs"].map { |d| d[ID_KEY] }
- end
-
- def results
- @results ||= SolrHTTPRequest.select(self.to_hash)
- end
-
- # Search Solr for objects of a given type, for a given query.
- def search
- { "rows" => objects, "start" => results["response"]["start"],
- "total" => results["response"]["numFound"] }
- end
-
- def to_hash
- options = DEFAULT_PARAMS.merge(params)
- options[:fq] = filter_query
- options[:q] = @query
- options
- end
-
- START_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".freeze
- START_DELETE_BY_QUERY = "<delete><query>".freeze
- END_DELETE_BY_QUERY = "</query></delete>\n".freeze
- COMMIT = "<commit/>\n".freeze
-
- def commit(opts={})
- SolrHTTPRequest.update("#{START_XML}#{COMMIT}")
- end
-
- def delete_database(db)
- query_data = xml_escape("X_CHEF_database_CHEF_X:#{db}")
- xml = "#{START_XML}#{START_DELETE_BY_QUERY}#{query_data}#{END_DELETE_BY_QUERY}"
- SolrHTTPRequest.update(xml)
- commit
- end
-
- def rebuild_index(db=Chef::Config[:couchdb_database])
- delete_database(db)
-
- results = {}
- [Chef::ApiClient, Chef::Node, Chef::Role, Chef::Environment].each do |klass|
- results[klass.name] = reindex_all(klass) ? "success" : "failed"
- end
- databags = Chef::DataBag.cdb_list(true)
- Chef::Log.info("Reloading #{databags.size.to_s} #{Chef::DataBag} objects into the indexer")
- databags.each { |i| i.add_to_index; i.list(true).each { |x| x.add_to_index } }
- results[Chef::DataBag.name] = "success"
- results
- end
-
- def reindex_all(klass, metadata={})
- begin
- items = klass.cdb_list(true)
- Chef::Log.info("Reloading #{items.size.to_s} #{klass.name} objects into the indexer")
- items.each { |i| i.add_to_index }
- rescue Net::HTTPServerException => e
- # 404s are okay, there might not be any of that kind of object...
- if e.message =~ /Not Found/
- Chef::Log.warn("Could not load #{klass.name} objects from couch for re-indexing (this is ok if you don't have any of these)")
- return false
- else
- raise e
- end
- rescue Exception => e
- Chef::Log.fatal("Chef encountered an error while attempting to load #{klass.name} objects back into the index")
- raise e
- end
- true
- end
-
-
- end
-end
diff --git a/chef/lib/chef/solr_query/lucene.treetop b/chef/lib/chef/solr_query/lucene.treetop
deleted file mode 100644
index 99d3e1f709..0000000000
--- a/chef/lib/chef/solr_query/lucene.treetop
+++ /dev/null
@@ -1,150 +0,0 @@
-#
-# Author:: Seth Falcon (<seth@opscode.com>)
-# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-grammar Lucene
-
- rule body
- (expression / space)* <Body>
- end
-
- rule expression
- operation / group / field / field_range / term / string
- end
-
- rule term
- keyword valid_letter+ <Term> / !keyword !"?" valid_letter <Term>
- end
-
- rule field
- field_name ":" (term/string/group) <Field>
- end
-
- rule field_range
- field_name ":" "[" range_value " TO " range_value "]" <InclFieldRange>
- /
- field_name ":" "{" range_value " TO " range_value "}" <ExclFieldRange>
- end
-
- rule field_name
- !keyword valid_letter+ <FieldName>
- end
-
- rule range_value
- valid_letter+ <RangeValue> / "*" <RangeValue>
- end
-
- rule group
- space? '(' body ')' space? <Group>
- end
-
- rule operation
- binary_op / unary_op / fuzzy_op / boost_op
- end
-
- rule unary_op
- not_op / required_op / prohibited_op
- end
-
- rule binary_op
- (group / field / field_range / term) space? boolean_operator space+ body <BinaryOp>
- end
-
- rule boolean_operator
- and_operator / or_operator
- end
-
- rule and_operator
- 'AND' <AndOperator> / '&&' <AndOperator>
- end
-
- rule or_operator
- 'OR' <OrOperator> / '||' <OrOperator>
- end
-
- rule not_op
- not_operator space (group / field / field_range / term / string) <UnaryOp>
- /
- bang_operator space? (group / field / field_range / term / string) <UnaryOp>
- end
-
- rule not_operator
- 'NOT' <NotOperator>
- end
-
- rule bang_operator
- '!' <NotOperator>
- end
-
- rule required_op
- !valid_letter required_operator (term/string) <UnaryOp>
- /
- required_operator (term/string) <UnaryOp>
- end
-
- rule required_operator
- '+' <RequiredOperator>
- end
-
- rule prohibited_op
- !valid_letter prohibited_operator (field/field_range/term/string) <UnaryOp>
- end
-
- rule prohibited_operator
- '-' <ProhibitedOperator>
- end
-
- rule boost_op
- (term/string) '^' fuzzy_param <BoostOp>
- end
-
- rule fuzzy_op
- (term/string) '~' fuzzy_param? (space / !valid_letter) <FuzzyOp>
- end
-
- rule fuzzy_param
- [0-9] '.'? [0-9] <FuzzyParam> / [0-9]+ <FuzzyParam>
- end
-
- rule string
- '"' term (space term)* '"' <Phrase>
- end
-
- rule keyword
- 'AND' / 'OR' / 'NOT'
- end
-
- rule valid_letter
- start_letter+ ([a-zA-Z0-9@*?_.-] / '\\' special_char)*
- end
-
- rule start_letter
- [a-zA-Z0-9@._*] / '\\' special_char
- end
-
- rule end_letter
- [a-zA-Z0-9*?_.] / '\\' special_char
- end
-
- rule special_char
- [-+&|!(){}\[\]^"~*?:\\]
- end
-
- rule space
- [\s]+
- end
-end
diff --git a/chef/lib/chef/solr_query/lucene_nodes.rb b/chef/lib/chef/solr_query/lucene_nodes.rb
deleted file mode 100644
index c2d7777365..0000000000
--- a/chef/lib/chef/solr_query/lucene_nodes.rb
+++ /dev/null
@@ -1,285 +0,0 @@
-#
-# Author:: Seth Falcon (<seth@opscode.com>)
-# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'treetop'
-
-module Lucene
- SEP = "__=__"
-
- class Term < Treetop::Runtime::SyntaxNode
- def to_array
- "T:#{self.text_value}"
- end
-
- def transform
- self.text_value
- end
- end
-
- class Field < Treetop::Runtime::SyntaxNode
- def to_array
- field = self.elements[0].text_value
- term = self.elements[1].to_array
- "(F:#{field} #{term})"
- end
-
- def transform
- field = self.elements[0].text_value
- term = self.elements[1]
- if term.is_a? Phrase
- str = term.transform
- # remove quotes
- str = str[1 ... (str.length - 1)]
- "content:\"#{field}#{SEP}#{str}\""
- else
- "content:#{field}#{SEP}#{term.transform}"
- end
- end
- end
-
- class FieldRange < Treetop::Runtime::SyntaxNode
-
- def to_array
- field = self.elements[0].text_value
- range_start = self.elements[1].to_array
- range_end = self.elements[2].to_array
- "(FR:#{field} #{left}#{range_start}#{right} #{left}#{range_end}#{right})"
- end
-
- def transform
- field = self.elements[0].text_value
- range_start = self.elements[1].transform
- range_end = self.elements[2].transform
- # FIXME: handle special cases for missing start/end
- if ("*" == range_start && "*" == range_end)
- "content:#{field}#{SEP}*"
- elsif "*" == range_end
- "content:#{left}#{field}#{SEP}#{range_start} TO #{field}#{SEP}\\ufff0#{right}"
- elsif "*" == range_start
- "content:#{left}#{field}#{SEP} TO #{field}#{SEP}#{range_end}#{right}"
- else
- "content:#{left}#{field}#{SEP}#{range_start} TO #{field}#{SEP}#{range_end}#{right}"
- end
- end
-
- end
-
- class InclFieldRange < FieldRange
- def left
- "["
- end
- def right
- "]"
- end
- end
-
- class ExclFieldRange < FieldRange
- def left
- "{"
- end
- def right
- "}"
- end
- end
-
- class RangeValue < Treetop::Runtime::SyntaxNode
- def to_array
- self.text_value
- end
-
- def transform
- to_array
- end
- end
-
- class FieldName < Treetop::Runtime::SyntaxNode
- def to_array
- self.text_value
- end
-
- def transform
- to_array
- end
- end
-
-
- class Body < Treetop::Runtime::SyntaxNode
- def to_array
- self.elements.map { |x| x.to_array }.join(" ")
- end
-
- def transform
- self.elements.map { |x| x.transform }.join(" ")
- end
- end
-
- class Group < Treetop::Runtime::SyntaxNode
- def to_array
- "(" + self.elements[0].to_array + ")"
- end
-
- def transform
- "(" + self.elements[0].transform + ")"
- end
- end
-
- class BinaryOp < Treetop::Runtime::SyntaxNode
- def to_array
- op = self.elements[1].to_array
- a = self.elements[0].to_array
- b = self.elements[2].to_array
- "(#{op} #{a} #{b})"
- end
-
- def transform
- op = self.elements[1].transform
- a = self.elements[0].transform
- b = self.elements[2].transform
- "#{a} #{op} #{b}"
- end
- end
-
- class AndOperator < Treetop::Runtime::SyntaxNode
- def to_array
- "OP:AND"
- end
-
- def transform
- "AND"
- end
- end
-
- class OrOperator < Treetop::Runtime::SyntaxNode
- def to_array
- "OP:OR"
- end
-
- def transform
- "OR"
- end
- end
-
- class FuzzyOp < Treetop::Runtime::SyntaxNode
- def to_array
- a = self.elements[0].to_array
- param = self.elements[1]
- if param
- "(OP:~ #{a} #{param.to_array})"
- else
- "(OP:~ #{a})"
- end
- end
-
- def transform
- a = self.elements[0].transform
- param = self.elements[1]
- if param
- "#{a}~#{param.transform}"
- else
- "#{a}~"
- end
- end
- end
-
- class BoostOp < Treetop::Runtime::SyntaxNode
- def to_array
- a = self.elements[0].to_array
- param = self.elements[1]
- "(OP:^ #{a} #{param.to_array})"
- end
-
- def transform
- a = self.elements[0].transform
- param = self.elements[1]
- "#{a}^#{param.transform}"
- end
- end
-
- class FuzzyParam < Treetop::Runtime::SyntaxNode
- def to_array
- self.text_value
- end
-
- def transform
- self.text_value
- end
- end
-
- class UnaryOp < Treetop::Runtime::SyntaxNode
- def to_array
- op = self.elements[0].to_array
- a = self.elements[1].to_array
- "(#{op} #{a})"
- end
-
- def transform
- op = self.elements[0].transform
- a = self.elements[1].transform
- spc = case op
- when "+", "-"
- ""
- else
- " "
- end
- "#{op}#{spc}#{a}"
- end
-
- end
-
- class NotOperator < Treetop::Runtime::SyntaxNode
- def to_array
- "OP:NOT"
- end
-
- def transform
- "NOT"
- end
-
- end
-
- class RequiredOperator < Treetop::Runtime::SyntaxNode
- def to_array
- "OP:+"
- end
-
- def transform
- "+"
- end
-
- end
-
- class ProhibitedOperator < Treetop::Runtime::SyntaxNode
- def to_array
- "OP:-"
- end
-
- def transform
- "-"
- end
- end
-
- class Phrase < Treetop::Runtime::SyntaxNode
- def to_array
- "STR:#{self.text_value}"
- end
-
- def transform
- "#{self.text_value}"
- end
- end
-end
diff --git a/chef/lib/chef/solr_query/query_transform.rb b/chef/lib/chef/solr_query/query_transform.rb
deleted file mode 100644
index 529f9de482..0000000000
--- a/chef/lib/chef/solr_query/query_transform.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-#
-# Author:: Seth Falcon (<seth@opscode.com>)
-# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-require 'treetop'
-require 'chef/solr_query/lucene_nodes'
-
-class Chef
- class Exceptions
- class QueryParseError < StandardError
- end
- end
-end
-
-class Chef
- class SolrQuery
- class QueryTransform
- @@base_path = File.expand_path(File.dirname(__FILE__))
- Treetop.load(File.join(@@base_path, 'lucene.treetop'))
- @@parser = LuceneParser.new
-
- def self.parse(data)
- tree = @@parser.parse(data)
- msg = "Parse error at offset: #{@@parser.index}\n"
- msg += "Reason: #{@@parser.failure_reason}"
- raise Chef::Exceptions::QueryParseError, msg if tree.nil?
- self.clean_tree(tree)
- tree.to_array
- end
-
- def self.transform(data)
- return "*:*" if data == "*:*"
- tree = @@parser.parse(data)
- msg = "Parse error at offset: #{@@parser.index}\n"
- msg += "Reason: #{@@parser.failure_reason}"
- raise Chef::Exceptions::QueryParseError, msg if tree.nil?
- self.clean_tree(tree)
- tree.transform
- end
-
- private
-
- def self.clean_tree(root_node)
- return if root_node.elements.nil?
- root_node.elements.delete_if do |node|
- node.class.name == "Treetop::Runtime::SyntaxNode"
- end
- root_node.elements.each { |node| self.clean_tree(node) }
- end
- end
- end
-end
diff --git a/chef/lib/chef/solr_query/solr_http_request.rb b/chef/lib/chef/solr_query/solr_http_request.rb
deleted file mode 100644
index e7ce1d5675..0000000000
--- a/chef/lib/chef/solr_query/solr_http_request.rb
+++ /dev/null
@@ -1,132 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Copyright:: Copyright (c) 2009-2011 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'net/http'
-require 'uri'
-require 'chef/json_compat'
-require 'chef/config'
-
-class Chef
- class SolrQuery
- class SolrHTTPRequest
- CLASS_FOR_METHOD = {:GET => Net::HTTP::Get, :POST => Net::HTTP::Post}
-
- TEXT_XML = {"Content-Type" => "text/xml"}
-
- def self.solr_url=(solr_url)
- @solr_url = solr_url
- @http_client = nil
- @url_prefix = nil
- end
-
- def self.solr_url
- @solr_url || Chef::Config[:solr_url]
- end
-
- def self.http_client
- @http_client ||= begin
- uri = URI.parse(solr_url)
- http_client = Net::HTTP.new(uri.host, uri.port)
- http_client.use_ssl = true if uri.port == 443
- http_client
- end
- end
-
- def self.url_prefix
- @url_prefix ||= begin
- uri = URI.parse(solr_url)
- if uri.path == ""
- "/solr"
- else
- uri.path.gsub(%r{/$}, '')
- end
- end
- end
-
- def self.select(params={})
- url = "#{url_prefix}/select?#{url_join(params)}"
- Chef::Log.debug("Sending #{url} to Solr")
- request = new(:GET, url)
- json_response = request.run("Search Query to Solr '#{solr_url}#{url}'")
- Chef::JSONCompat.from_json(json_response)
- end
-
- def self.update(doc)
- url = "#{url_prefix}/update"
- Chef::Log.debug("POSTing document to SOLR:\n#{doc}")
- request = new(:POST, url, TEXT_XML) { |req| req.body = doc.to_s }
- request.run("POST to Solr '#{solr_url}#{url}', data: #{doc}")
- end
-
- def self.url_join(params_hash={})
- params = params_hash.inject("") do |param_str, params|
- param_str << "#{params[0]}=#{escape(params[1])}&"
- end
- params.chop! # trailing &
- params
- end
-
- def self.escape(s)
- s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
- '%'+$1.unpack('H2'*$1.size).join('%').upcase
- }.tr(' ', '+')
- end
-
- def initialize(method, url, headers=nil)
- args = headers ? [url, headers] : url
- @request = CLASS_FOR_METHOD[method].new(*args)
- yield @request if block_given?
- end
-
- def http_client
- self.class.http_client
- end
-
- def solr_url
- self.class.solr_url
- end
-
- def run(description="HTTP Request to Solr")
- response = http_client.request(@request)
- request_failed!(response, description) unless response.kind_of?(Net::HTTPSuccess)
- response.body
- rescue NoMethodError => e
- # http://redmine.ruby-lang.org/issues/show/2708
- # http://redmine.ruby-lang.org/issues/show/2758
- if e.to_s =~ /#{Regexp.escape(%q|undefined method 'closed?' for nil:NilClass|)}/
- Chef::Log.fatal("#{description} failed. Chef::Exceptions::SolrConnectionError exception: Errno::ECONNREFUSED (net/http undefined method closed?) attempting to contact #{solr_url}")
- Chef::Log.debug("Rescued error in http connect, treating it as Errno::ECONNREFUSED to hide bug in net/http")
- Chef::Log.debug(e.backtrace.join("\n"))
- raise Chef::Exceptions::SolrConnectionError, "Errno::ECONNREFUSED: Connection refused attempting to contact #{solr_url}"
- else
- raise
- end
- end
-
- def request_failed!(response, description='HTTP call')
- Chef::Log.fatal("#{description} failed (#{response.class} #{response.code} #{response.message})")
- response.error!
- rescue Timeout::Error, Errno::EINVAL, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT => e
- Chef::Log.debug(e.backtrace.join("\n"))
- raise Chef::Exceptions::SolrConnectionError, "#{e.class.name}: #{e.to_s}"
- end
-
- end
- end
-end
diff --git a/chef/lib/chef/webui_user.rb b/chef/lib/chef/webui_user.rb
deleted file mode 100644
index e0dbde4a61..0000000000
--- a/chef/lib/chef/webui_user.rb
+++ /dev/null
@@ -1,156 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Nuo Yan (<nuo@opscode.com>)
-# Copyright:: Copyright (c) 2008 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require 'chef/config'
-require 'chef/mixin/params_validate'
-require 'chef/index_queue'
-require 'digest/sha1'
-require 'chef/json_compat'
-
-
-class Chef
- class WebUIUser
-
- attr_accessor :name, :validated, :admin, :openid, :couchdb
- attr_reader :password, :salt, :couchdb_id, :couchdb_rev
-
- include Chef::Mixin::ParamsValidate
-
- # Create a new Chef::WebUIUser object.
- def initialize(opts={})
- @name, @salt, @password = opts['name'], opts['salt'], opts['password']
- @openid = opts['openid']
- @admin = false
- end
-
- def name=(n)
- @name = n.gsub(/\./, '_')
- end
-
- def admin?
- admin
- end
-
- # Set the password for this object.
- def set_password(password, confirm_password=password)
- raise ArgumentError, "Passwords do not match" unless password == confirm_password
- raise ArgumentError, "Password cannot be blank" if (password.nil? || password.length==0)
- raise ArgumentError, "Password must be a minimum of 6 characters" if password.length < 6
- generate_salt
- @password = encrypt_password(password)
- end
-
- def set_openid(given_openid)
- @openid = given_openid
- end
-
- def verify_password(given_password)
- encrypt_password(given_password) == @password
- end
-
- # Serialize this object as a hash
- def to_json(*a)
- attributes = Hash.new
- recipes = Array.new
- result = {
- 'name' => name,
- 'json_class' => self.class.name,
- 'salt' => salt,
- 'password' => password,
- 'openid' => openid,
- 'admin' => admin,
- 'chef_type' => 'webui_user',
- }
- result["_id"] = @couchdb_id if @couchdb_id
- result["_rev"] = @couchdb_rev if @couchdb_rev
- result.to_json(*a)
- end
-
- # Create a Chef::WebUIUser from JSON
- def self.json_create(o)
- me = new(o)
- me.admin = o["admin"]
- me
- end
-
- def chef_server_rest
- Chef::REST.new(Chef::Config[:chef_server_url])
- end
-
- def self.chef_server_rest
- Chef::REST.new(Chef::Config[:chef_server_url])
- end
-
- def self.list(inflate=false)
- if inflate
- response = Hash.new
- Chef::Search::Query.new.search(:user) do |n|
- response[n.name] = n unless n.nil?
- end
- response
- else
- chef_server_rest.get_rest("users")
- end
- end
-
- # Load a User by name
- def self.load(name)
- chef_server_rest.get_rest("users/#{name}")
- end
-
- # Remove this WebUIUser via the REST API
- def destroy
- chef_server_rest.delete_rest("users/#{@name}")
- end
-
- # Save this WebUIUser via the REST API
- def save
- begin
- chef_server_rest.put_rest("users/#{@name}", self)
- rescue Net::HTTPServerException => e
- if e.response.code == "404"
- chef_server_rest.post_rest("users", self)
- else
- raise e
- end
- end
- self
- end
-
- # Create the WebUIUser via the REST API
- def create
- chef_server_rest.post_rest("users", self)
- self
- end
-
- protected
-
- def generate_salt
- @salt = Time.now.to_s
- chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
- 1.upto(30) { |i| @salt << chars[rand(chars.size-1)] }
- @salt
- end
-
- def encrypt_password(password)
- Digest::SHA1.hexdigest("--#{salt}--#{password}--")
- end
-
- end
-end