summaryrefslogtreecommitdiff
path: root/lib/chef/data_collector.rb
diff options
context:
space:
mode:
authorAdam Leff <adam@leff.co>2016-10-28 15:43:34 -0700
committerAdam Leff <adam@leff.co>2016-10-28 21:13:36 -0700
commit3a4442b96ba2005a9616e0f3137f651580a06ee7 (patch)
tree54cf6b7960e61a38b9e3d169dc0b00461135cd79 /lib/chef/data_collector.rb
parentaa9bbabde662a58c581ed4d87707eac5534bc292 (diff)
downloadchef-3a4442b96ba2005a9616e0f3137f651580a06ee7.tar.gz
Add deprecations to Data Collector competion messageadamleff/deprecations-to-data-collector
By adding deprecation warnings to Data Collector, receivers of Data Collector messages can easily identify nodes that would need attention to their versions/cookbooks before a major version Chef upgrade would be successful. Signed-off-by: Adam Leff <adam@leff.co>
Diffstat (limited to 'lib/chef/data_collector.rb')
-rw-r--r--lib/chef/data_collector.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb
index dbb0b3771a..2aad0d74b0 100644
--- a/lib/chef/data_collector.rb
+++ b/lib/chef/data_collector.rb
@@ -23,6 +23,7 @@ require "chef/event_dispatch/base"
require "chef/data_collector/messages"
require "chef/data_collector/resource_report"
require "ostruct"
+require "set"
class Chef
@@ -54,7 +55,7 @@ class Chef
class Reporter < EventDispatch::Base
attr_reader :all_resource_reports, :status, :exception, :error_descriptions,
:expanded_run_list, :run_context, :run_status, :http,
- :current_resource_report, :enabled
+ :current_resource_report, :enabled, :deprecations
def initialize
validate_data_collector_server_url!
@@ -63,6 +64,7 @@ class Chef
@current_resource_loaded = nil
@error_descriptions = {}
@expanded_run_list = {}
+ @deprecations = Set.new
@http = Chef::HTTP.new(data_collector_server_url)
@enabled = true
end
@@ -223,6 +225,12 @@ class Chef
)
end
+ # see EventDispatch::Base#deprecation
+ # Append a received deprecation to the list of deprecations
+ def deprecation(message, location = caller(2..2)[0])
+ add_deprecation(message, location)
+ end
+
private
#
@@ -288,7 +296,8 @@ class Chef
expanded_run_list: expanded_run_list,
resources: all_resource_reports,
status: opts[:status],
- error_descriptions: error_descriptions
+ error_descriptions: error_descriptions,
+ deprecations: deprecations.to_a
).to_json
)
end
@@ -340,6 +349,10 @@ class Chef
@error_descriptions = discription_hash
end
+ def add_deprecation(message, location)
+ @deprecations << { message: message, location: location }
+ end
+
def create_resource_report(new_resource, action, current_resource = nil)
Chef::DataCollector::ResourceReport.new(
new_resource,