summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrajaktaPurohit <prajakta@opscode.com>2014-01-27 16:38:32 -0800
committerPrajaktaPurohit <prajakta@opscode.com>2014-01-27 16:38:32 -0800
commitc60a7de1b7cf2d22c9f6d35d73aa149311e80c71 (patch)
tree34515e4a6cc210a3bf467e81ba53fc08a4a203ed
parent307facf534bb26caab8756f9c95e7dd7da3526c1 (diff)
downloadchef-praj/OC-10990/runid_in_CC_API_calls.tar.gz
renaming run_id to request_idpraj/OC-10990/runid_in_CC_API_calls
-rw-r--r--lib/chef/client.rb11
-rw-r--r--lib/chef/http/remote_request_id.rb42
-rw-r--r--lib/chef/http/request_id.rb20
-rw-r--r--lib/chef/knife/raw.rb1
-rw-r--r--lib/chef/request_id.rb37
-rw-r--r--lib/chef/rest.rb4
-rw-r--r--lib/chef/run_id.rb19
-rw-r--r--lib/chef/server_api.rb4
-rw-r--r--spec/unit/rest_spec.rb18
9 files changed, 100 insertions, 56 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index c8e6460585..0f250d3d32 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -44,7 +44,7 @@ require 'chef/version'
require 'chef/resource_reporter'
require 'chef/run_lock'
require 'chef/policy_builder'
-require 'chef/run_id'
+require 'chef/request_id'
require 'ohai'
require 'rbconfig'
@@ -363,13 +363,12 @@ class Chef
# don't add code that may fail before entering this section to be sure to release lock
begin
runlock.save_pid
- Chef::RunID.instance.reset_run_id
- @run_id = Chef::RunID.instance.run_id
+ request_id = Chef::RequestID.instance.request_id
run_context = nil
@events.run_start(Chef::VERSION)
Chef::Log.info("*** Chef #{Chef::VERSION} ***")
Chef::Log.info "Chef-client pid: #{Process.pid}"
- Chef::Log.debug("Chef-client run_id: #{@run_id}")
+ Chef::Log.debug("Chef-client request_id: #{request_id}")
enforce_path_sanity
run_ohai
@events.ohai_completed(node)
@@ -379,7 +378,7 @@ class Chef
build_node
- run_status.run_id = @run_id
+ run_status.run_id = request_id
run_status.start_clock
Chef::Log.info("Starting Chef Run for #{node.name}")
run_started
@@ -410,6 +409,8 @@ class Chef
@events.run_failed(e)
raise
ensure
+ Chef::RequestID.instance.reset_request_id
+ request_id = nil
@run_status = nil
run_context = nil
runlock.release
diff --git a/lib/chef/http/remote_request_id.rb b/lib/chef/http/remote_request_id.rb
new file mode 100644
index 0000000000..37b09fd352
--- /dev/null
+++ b/lib/chef/http/remote_request_id.rb
@@ -0,0 +1,42 @@
+# Author:: Prajakta Purohit (<prajakta@opscode.com>)
+# Copyright:: Copyright (c) 2009, 2010, 2013, 2014 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/request_id'
+
+class Chef
+ class HTTP
+ class RemoteRequestID
+
+ def initialize(opts={})
+ end
+
+ def handle_request(method, url, headers={}, data=false)
+ headers.merge!({'X-REMOTE-REQUEST-ID' => Chef::RequestID.instance.request_id})
+ [method, url, headers, data]
+ end
+
+ def handle_response(http_response, rest_request, return_value)
+ [http_response, rest_request, return_value]
+ end
+
+ def stream_response_handler(response)
+ nil
+ end
+
+ end
+ end
+end
diff --git a/lib/chef/http/request_id.rb b/lib/chef/http/request_id.rb
deleted file mode 100644
index 02a57c7541..0000000000
--- a/lib/chef/http/request_id.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-class Chef
- class HTTP
- class RequestID
-
- def handle_request(method, url, headers={}, data=false)
- headers.merge!({'X-Ops-RequestId' => Chef::RunID.instance.run_id})
- [method, url, headers, data]
- end
-
- def handle_response(http_response, rest_request, return_value)
- [http_response, rest_request, return_value]
- end
-
- def stream_response_handler(response)
- nil
- end
-
- end
- end
-end
diff --git a/lib/chef/knife/raw.rb b/lib/chef/knife/raw.rb
index 2756de1a5a..954d46beee 100644
--- a/lib/chef/knife/raw.rb
+++ b/lib/chef/knife/raw.rb
@@ -42,6 +42,7 @@ class Chef
use Chef::HTTP::CookieManager
use Chef::HTTP::Decompressor
use Chef::HTTP::Authenticator
+ use Chef::HTTP::RemoteRequestID
end
def run
diff --git a/lib/chef/request_id.rb b/lib/chef/request_id.rb
new file mode 100644
index 0000000000..2c7af01879
--- /dev/null
+++ b/lib/chef/request_id.rb
@@ -0,0 +1,37 @@
+# Author:: Prajakta Purohit (<prajakta@opscode.com>)
+# Copyright:: Copyright (c) 2009, 2010, 2013, 2014 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 'securerandom'
+require 'singleton'
+
+class Chef
+ class RequestID
+ include Singleton
+
+ def reset_request_id
+ @request_id = nil
+ end
+
+ def request_id
+ @request_id ||= generate_request_id
+ end
+
+ def generate_request_id
+ SecureRandom.uuid
+ end
+ end
+end
diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb
index 39e338963c..0803d3b39a 100644
--- a/lib/chef/rest.rb
+++ b/lib/chef/rest.rb
@@ -35,7 +35,7 @@ require 'chef/http/cookie_manager'
require 'chef/config'
require 'chef/exceptions'
require 'chef/platform/query_helpers'
-require 'chef/http/request_id'
+require 'chef/http/remote_request_id'
class Chef
# == Chef::REST
@@ -62,7 +62,7 @@ class Chef
@decompressor = Decompressor.new(options)
@authenticator = Authenticator.new(options)
- @request_id = RequestID.new
+ @request_id = RemoteRequestID.new(options)
@middlewares << JSONInput.new(options)
@middlewares << JSONToModelOutput.new(options)
diff --git a/lib/chef/run_id.rb b/lib/chef/run_id.rb
deleted file mode 100644
index 9756d81b71..0000000000
--- a/lib/chef/run_id.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require 'singleton'
-
-class Chef
- class RunID
- include Singleton
-
- def reset_run_id
- @run_id = nil
- end
-
- def run_id
- @run_id ||= generate_run_id
- end
-
- def generate_run_id
- SecureRandom.uuid
- end
- end
-end
diff --git a/lib/chef/server_api.rb b/lib/chef/server_api.rb
index e9e7593dd6..8cdcd7a09d 100644
--- a/lib/chef/server_api.rb
+++ b/lib/chef/server_api.rb
@@ -22,6 +22,7 @@ require 'chef/http/cookie_manager'
require 'chef/http/decompressor'
require 'chef/http/json_input'
require 'chef/http/json_output'
+require 'chef/http/remote_request_id'
class Chef
class ServerAPI < Chef::HTTP
@@ -37,5 +38,6 @@ class Chef
use Chef::HTTP::CookieManager
use Chef::HTTP::Decompressor
use Chef::HTTP::Authenticator
+ use Chef::HTTP::RemoteRequestID
end
-end \ No newline at end of file
+end
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
index cc7a4ce7bb..e62c469884 100644
--- a/spec/unit/rest_spec.rb
+++ b/spec/unit/rest_spec.rb
@@ -64,13 +64,13 @@ describe Chef::REST do
Chef::REST::CookieJar.instance.clear
@request_id_mock = "1234"
- Chef::RunID.instance.stub(:run_id).and_return(@request_id_mock)
+ Chef::RequestID.instance.stub(:request_id).and_return(@request_id_mock)
end
describe "calling an HTTP verb on a path or absolute URL" do
- STANDARD_READ_HEADERS = {"Accept"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", 'X-Ops-RequestId'=>"1234"}
- STANDARD_WRITE_HEADERS = {"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", 'X-Ops-RequestId'=>"1234"}
+ STANDARD_READ_HEADERS = {"Accept"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", 'X-REMOTE-REQUEST-ID'=>"1234"}
+ STANDARD_WRITE_HEADERS = {"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", 'X-REMOTE-REQUEST-ID'=>"1234"}
it "adds a relative URL to the base url it was initialized with" do
@rest.create_url("foo/bar/baz").should == URI.parse(@base_url + "/foo/bar/baz")
@@ -243,7 +243,7 @@ describe Chef::REST do
@request_mock = {}
Net::HTTP::Get.stub(:new).and_return(@request_mock)
@request_id_mock = "1234"
- Chef::RunID.instance.stub(:run_id).and_return(@request_id_mock)
+ Chef::RequestID.instance.stub(:request_id).and_return(@request_id_mock)
end
it "should build a new HTTP GET request without the application/json accept header" do
@@ -251,7 +251,7 @@ describe Chef::REST do
'X-Chef-Version' => Chef::VERSION,
'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
'Host' => @host_header,
- 'X-Ops-RequestId' => @request_id_mock}
+ 'X-REMOTE-REQUEST-ID' => @request_id_mock}
Net::HTTP::Get.should_receive(:new).with("/?foo=bar", expected_headers).and_return(@request_mock)
@rest.streaming_request(@url, {})
end
@@ -295,13 +295,13 @@ describe Chef::REST do
@request_mock = {}
Net::HTTP::Get.stub(:new).and_return(@request_mock)
@request_id_mock = "1234"
- Chef::RunID.instance.stub(:run_id).and_return(@request_id_mock)
+ Chef::RequestID.instance.stub(:request_id).and_return(@request_id_mock)
@base_headers = {"Accept" => "application/json",
"X-Chef-Version" => Chef::VERSION,
"Accept-Encoding" => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
"Host" => @host_header,
- 'X-Ops-RequestId' => @request_id_mock
+ 'X-REMOTE-REQUEST-ID' => @request_id_mock
}
end
@@ -494,7 +494,7 @@ describe Chef::REST do
@http_response.stub(:read_body)
@http_client.stub(:request).and_yield(@http_response).and_return(@http_response)
@request_id_mock = "1234"
- Chef::RunID.instance.stub(:run_id).and_return(@request_id_mock)
+ Chef::RequestID.instance.stub(:request_id).and_return(@request_id_mock)
end
after do
@@ -506,7 +506,7 @@ describe Chef::REST do
'X-Chef-Version' => Chef::VERSION,
'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
'Host' => @host_header,
- 'X-Ops-RequestId' => @request_id_mock}
+ 'X-REMOTE-REQUEST-ID' => @request_id_mock}
Net::HTTP::Get.should_receive(:new).with("/?foo=bar", expected_headers).and_return(@request_mock)
@rest.streaming_request(@url, {})
end