Class: Haipa::Client::PollingState
- Inherits:
-
Object
- Object
- Haipa::Client::PollingState
- Defined in:
- lib/haipa_rest/polling_state.rb
Overview
Class which represents a state of Haipa long running operation.
Instance Attribute Summary collapse
-
#error_data ⇒ HaipaOperationError
The Haipa error data.
-
#Haipa_async_operation_header_link ⇒ String
The latest value captured from Haipa-AsyncOperation header.
-
#location_header_link ⇒ String
The latest value captured from Location header.
-
#request ⇒ Net::HTTPRequest
The HTTP request.
-
#resource ⇒ Object
The resource.
-
#response ⇒ Net::HTTPResponse
The HTTP response.
-
#status ⇒ String
Status of the long running operation.
Instance Method Summary collapse
-
#get_delay ⇒ Integer
Returns the amount of time in seconds for long running operation polling delay.
-
#get_operation_error ⇒ HaipaOperationError
Composes and returns cloud error.
-
#get_operation_response ⇒ Haipa::Client::HaipaOperationResponse
returns the Haipa’s response.
-
#get_provisioning_state ⇒ String
Returns the provisioning status of the resource.
- #get_request(options = {}) ⇒ Object
-
#initialize(haipa_response, retry_timeout) ⇒ PollingState
constructor
A new instance of PollingState.
-
#update_response(response) ⇒ Object
Updates the polling state from the fields of given response object.
Constructor Details
#initialize(haipa_response, retry_timeout) ⇒ PollingState
Returns a new instance of PollingState.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/haipa_rest/polling_state.rb', line 32 def initialize(haipa_response, retry_timeout) @retry_timeout = retry_timeout @request = haipa_response.request update_response(haipa_response.response) @resource = haipa_response.body case @response.status when 200 provisioning_state = get_provisioning_state @status = provisioning_state.nil?? (AsyncOperationStatus::SUCCESS_STATUS):provisioning_state when 201 provisioning_state = get_provisioning_state @status = provisioning_state.nil?? (AsyncOperationStatus::IN_PROGRESS_STATUS):provisioning_state when 202 @status = AsyncOperationStatus::IN_PROGRESS_STATUS when 204 @status = AsyncOperationStatus::SUCCESS_STATUS else @status = AsyncOperationStatus::FAILED_STATUS end end |
Instance Attribute Details
#error_data ⇒ HaipaOperationError
Returns the Haipa error data.
21 22 23 |
# File 'lib/haipa_rest/polling_state.rb', line 21 def error_data @error_data end |
#Haipa_async_operation_header_link ⇒ String
Returns the latest value captured from Haipa-AsyncOperation header.
24 25 26 |
# File 'lib/haipa_rest/polling_state.rb', line 24 def Haipa_async_operation_header_link @Haipa_async_operation_header_link end |
#location_header_link ⇒ String
Returns the latest value captured from Location header.
27 28 29 |
# File 'lib/haipa_rest/polling_state.rb', line 27 def location_header_link @location_header_link end |
#request ⇒ Net::HTTPRequest
Returns the HTTP request.
12 13 14 |
# File 'lib/haipa_rest/polling_state.rb', line 12 def request @request end |
#resource ⇒ Object
Returns the resource.
15 16 17 |
# File 'lib/haipa_rest/polling_state.rb', line 15 def resource @resource end |
#response ⇒ Net::HTTPResponse
Returns the HTTP response.
18 19 20 |
# File 'lib/haipa_rest/polling_state.rb', line 18 def response @response end |
#status ⇒ String
Returns status of the long running operation.
30 31 32 |
# File 'lib/haipa_rest/polling_state.rb', line 30 def status @status end |
Instance Method Details
#get_delay ⇒ Integer
Returns the amount of time in seconds for long running operation polling delay.
74 75 76 77 78 79 80 81 82 |
# File 'lib/haipa_rest/polling_state.rb', line 74 def get_delay return @retry_timeout unless @retry_timeout.nil? if !response.nil? && !response.headers['Retry-After'].nil? return response.headers['Retry-After'].to_i end return AsyncOperationStatus::DEFAULT_DELAY end |
#get_operation_error ⇒ HaipaOperationError
Composes and returns cloud error.
109 110 111 |
# File 'lib/haipa_rest/polling_state.rb', line 109 def get_operation_error HaipaOperationError.new @request, @response, @error_data, "Long running operation failed with status #{@status}" end |
#get_operation_response ⇒ Haipa::Client::HaipaOperationResponse
returns the Haipa’s response.
100 101 102 103 |
# File 'lib/haipa_rest/polling_state.rb', line 100 def get_operation_response haipa_response = HaipaOperationResponse.new(@request, @response, @resource) haipa_response end |
#get_provisioning_state ⇒ String
Returns the provisioning status of the resource
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/haipa_rest/polling_state.rb', line 58 def get_provisioning_state # On non flattened resource, we should find provisioning_state inside 'properties' if (!@resource.nil? && @resource.respond_to?(:properties) && @resource.properties.respond_to?(:provisioning_state) && !@resource.properties.provisioning_state.nil?) @resource.properties.provisioning_state # On flattened resource, we should find provisioning_state at the top level elsif !@resource.nil? && @resource.respond_to?(:provisioning_state) && !@resource.provisioning_state.nil? @resource.provisioning_state else nil end end |
#get_request(options = {}) ⇒ Object
113 114 115 116 117 |
# File 'lib/haipa_rest/polling_state.rb', line 113 def get_request( = {}) link = @Haipa_async_operation_header_link || @location_header_link [:connection] = create_connection([:base_uri]) MsRest::HttpOperationRequest.new(nil, link, :get, ) end |
#update_response(response) ⇒ Object
Updates the polling state from the fields of given response object.
87 88 89 90 91 92 93 94 |
# File 'lib/haipa_rest/polling_state.rb', line 87 def update_response(response) @response = response unless response.nil? @Haipa_async_operation_header_link = response.headers['Haipa-AsyncOperation'] unless response.headers['Haipa-AsyncOperation'].nil? @location_header_link = response.headers['Location'] unless response.headers['Location'].nil? end end |