forked from puppetlabs/puppet
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/2.7.x/9051-storeconfig-backend-should-be-config…
…urable' into 2.7.x * feature/2.7.x/9051-storeconfig-backend-should-be-configurable: (puppetlabs#9051) de-ActiveRecord-ify Collection expressions. (puppetlabs#9051) Port query tests into the indirection. (puppetlabs#9051) Implement the `resource` terminus for StoreConfigs. (puppetlabs#9051) Make generic tagging imported resource origins. (puppetlabs#9051) Whitespace cleanup for puppet/parser/collector (puppetlabs#9051) Dead code elimination in the compiler terminus. (puppetlabs#9051) Get the compiler out of the ActiveRecord business. (puppetlabs#9051) Implement the StoreConfigs indirection itself. (puppetlabs#9051) Add configuration around StoreConfigs indirection. Reviewed-by: Jeff McCune
- Loading branch information
Showing
29 changed files
with
628 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'puppet/indirector/store_configs' | ||
require 'puppet/resource/catalog' | ||
|
||
class Puppet::Resource::Catalog::StoreConfigs < Puppet::Indirector::StoreConfigs | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'puppet/node/facts' | ||
require 'puppet/indirector/store_configs' | ||
|
||
class Puppet::Node::Facts::StoreConfigs < Puppet::Indirector::StoreConfigs | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'puppet/indirector/store_configs' | ||
require 'puppet/node' | ||
|
||
class Puppet::Node::StoreConfigs < Puppet::Indirector::StoreConfigs | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require 'puppet/indirector/active_record' | ||
|
||
class Puppet::Resource::ActiveRecord < Puppet::Indirector::ActiveRecord | ||
def search(request) | ||
type = request_to_type_name(request) | ||
host = request.options[:host] | ||
filter = request.options[:filter] | ||
|
||
query = build_active_record_query(type, host, filter) | ||
Puppet::Rails::Resource.find(:all, query) | ||
end | ||
|
||
private | ||
def request_to_type_name(request) | ||
name = request.key.split('/', 2)[0] | ||
type = Puppet::Type.type(name) or raise Puppet::Error, "Could not find type #{name}" | ||
type.name | ||
end | ||
|
||
def filter_to_active_record(filter) | ||
# Don't call me if you don't have a filter, please. | ||
filter.is_a?(Array) or raise ArgumentError, "active record filters must be arrays" | ||
a, op, b = filter | ||
|
||
case op | ||
when /^(and|or)$/i then | ||
extra = [] | ||
first, args = filter_to_active_record a | ||
extra += args | ||
|
||
second, args = filter_to_active_record b | ||
extra += args | ||
|
||
return "(#{first}) #{op.upcase} (#{second})", extra | ||
|
||
when "==", "!=" then | ||
op = '=' if op == '==' # SQL, yayz! | ||
case a | ||
when "title" then | ||
return "title #{op} ?", [b] | ||
|
||
when "tag" then | ||
return "puppet_tags.name #{op} ?", [b] | ||
|
||
else | ||
return "param_names.name = ? AND param_values.value #{op} ?", [a, b] | ||
end | ||
|
||
else | ||
raise ArgumentError, "unknown operator #{op.inspect} in #{filter.inspect}" | ||
end | ||
end | ||
|
||
def build_active_record_query(type, host, filter) | ||
raise Puppet::DevError, "Cannot collect resources for a nil host" unless host | ||
|
||
search = "(exported=? AND restype=?)" | ||
arguments = [true, type] | ||
|
||
if filter then | ||
sql, values = filter_to_active_record(filter) | ||
search += " AND #{sql}" | ||
arguments += values | ||
end | ||
|
||
# note: we're not eagerly including any relations here because it can | ||
# create large numbers of objects that we will just throw out later. We | ||
# used to eagerly include param_names/values but the way the search filter | ||
# is built ruined those efforts and we were eagerly loading only the | ||
# searched parameter and not the other ones. | ||
query = {} | ||
case search | ||
when /puppet_tags/ | ||
query = { :joins => { :resource_tags => :puppet_tag } } | ||
when /param_name/ | ||
query = { :joins => { :param_values => :param_name } } | ||
end | ||
|
||
# We're going to collect objects from rails, but we don't want any | ||
# objects from this host. | ||
if host = Puppet::Rails::Host.find_by_name(host) | ||
search += " AND (host_id != ?)" | ||
arguments << host.id | ||
end | ||
|
||
query[:conditions] = [search, *arguments] | ||
|
||
query | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'puppet/indirector/store_configs' | ||
class Puppet::Resource::StoreConfigs < Puppet::Indirector::StoreConfigs | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Puppet::Indirector::StoreConfigs < Puppet::Indirector::Terminus | ||
def initialize | ||
super | ||
# This will raise if the indirection can't be found, so we can assume it | ||
# is always set to a valid instance from here on in. | ||
@target = indirection.terminus Puppet[:storeconfigs_backend] | ||
end | ||
|
||
attr_reader :target | ||
|
||
def head(request) | ||
target.head request | ||
end | ||
|
||
def find(request) | ||
target.find request | ||
end | ||
|
||
def search(request) | ||
target.search request | ||
end | ||
|
||
def save(request) | ||
target.save request | ||
end | ||
|
||
def destroy(request) | ||
target.save request | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.