A web-service node type for Arborist
Create a new Webservice node.
# File lib/arborist/node/webservice.rb, line 26
def initialize( identifier, host, uri, attributes={}, &block )
attributes[:uri] = URI( uri )
attributes[:protocol] = 'tcp'
attributes[:app_protocol] = 'http'
attributes[:http_method] ||= DEFAULT_HTTP_METHOD
attributes[:http_version] ||= DEFAULT_HTTP_VERSION
attributes[:http_headers] ||= {}
attributes[:expected_status] ||= DEFAULT_EXPECTED_STATUS
attributes[:body] ||= ''
attributes[:body_mimetype] ||= DEFAULT_BODY_MIMETYPE
self.log.debug "Supering with attributes: %p " % [ attributes ]
super( identifier, host, attributes, &block )
end
The body used by the service
# File lib/arborist/node/webservice.rb, line 60
dsl_accessor :body
The #body_mimetype used by the service
# File lib/arborist/node/webservice.rb, line 64
dsl_accessor :body_mimetype
The #expected_status used by the service
# File lib/arborist/node/webservice.rb, line 56
dsl_accessor :expected_status
The #http_method used by the service
# File lib/arborist/node/webservice.rb, line 48
dsl_accessor :http_method
The http version used by the service
# File lib/arborist/node/webservice.rb, line 52
dsl_accessor :http_version
Returns true
if the node matches the specified
key
and val
criteria.
# File lib/arborist/node/webservice.rb, line 102
def match_criteria?( key, val )
self.log.debug "Matching %p: %p against %p" % [ key, val, self ]
return case key
when 'uri'
URI( self.uri ) == URI( val )
when 'http_method'
self.http_method == val
when 'http_version'
self.http_version == val
when 'expected_status'
self.expected_status == val
when 'body'
self.body == val
when 'body_mimetype'
self.body_mimetype == val
else
super
end
end
Set node attributes
from a Hash.
# File lib/arborist/node/webservice.rb, line 87
def modify( attributes )
attributes = stringify_keys( attributes )
super
self.uri( attributes['uri'] )
self.http_method( attributes['http_method'] )
self.http_version( attributes['http_version'] )
self.expected_status( attributes['expected_status'] )
self.body( attributes['body'] )
self.body_mimetype( attributes['body_mimetype'] )
end
Return service-node-specific information for inspect.
# File lib/arborist/node/webservice.rb, line 137
def node_description
desc = "%s %s %s/%s" % [
self.http_method,
self.uri,
self.app_protocol.upcase,
self.http_version,
]
if body && !body.empty?
desc << " {%s} (%s)" % [ self.body, self.body_mimetype ]
end
desc << ' -> %d response' % [ self.expected_status.to_i ]
return desc
end
Return a Hash of the operational values that are included with the node's monitor state.
# File lib/arborist/node/webservice.rb, line 125
def operational_values
return super.merge(
uri: self.uri,
http_method: self.http_method,
expected_status: self.expected_status,
body: self.body,
body_mimetype: self.body_mimetype
)
end
Serialize the resource node. Return a Hash of the host node's state.
# File lib/arborist/node/webservice.rb, line 156
def to_h( * )
return super.merge(
uri: self.uri,
http_method: self.http_method,
expected_status: self.expected_status,
body: self.body,
body_mimetype: self.body_mimetype
)
end
Get/set the URI of the service.
# File lib/arborist/node/webservice.rb, line 73
def uri( new_uri=nil )
if new_uri
@uri = URI( new_uri )
@uri.host ||= self.addresses.first.to_s
self.app_protocol( @uri.scheme )
self.port( @uri.port )
end
return @uri.to_s
end