class Arborist::Node::Webservice
A web-service node type for Arborist
Public Class Methods
new( identifier, host, uri, attributes={}, &block )
click to toggle source
Create a new Webservice
node.
Calls superclass method
# 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
Public Instance Methods
body()
click to toggle source
The body used by the service
# File lib/arborist/node/webservice.rb, line 60 dsl_accessor :body
body_mimetype()
click to toggle source
The body_mimetype
used by the service
# File lib/arborist/node/webservice.rb, line 64 dsl_accessor :body_mimetype
expected_status()
click to toggle source
The expected_status
used by the service
# File lib/arborist/node/webservice.rb, line 56 dsl_accessor :expected_status
http_method()
click to toggle source
The http_method
used by the service
# File lib/arborist/node/webservice.rb, line 48 dsl_accessor :http_method
http_version()
click to toggle source
The http version used by the service
# File lib/arborist/node/webservice.rb, line 52 dsl_accessor :http_version
match_criteria?( key, val )
click to toggle source
Returns true
if the node matches the specified key
and val
criteria.
Calls superclass method
# 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.to_s == 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
modify( attributes )
click to toggle source
Set node attributes
from a Hash.
Calls superclass method
# 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
node_description()
click to toggle source
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
operational_values()
click to toggle source
Return a Hash of the operational values that are included with the node's monitor state.
Calls superclass method
# 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
to_h( * )
click to toggle source
Serialize the resource node. Return a Hash of the host node's state.
Calls superclass method
# 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
uri( new_uri=nil )
click to toggle source
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
Private Instance Methods
make_identifier_suffix( url )
click to toggle source
Make an identifier from the specified url
.
# File lib/arborist/node/webservice.rb, line 172 def make_identifier_suffix( url ) return url.to_s.gsub( /\W+/, '-' ) end