right_agent 2.0.7-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +82 -0
  3. data/Rakefile +113 -0
  4. data/lib/right_agent.rb +59 -0
  5. data/lib/right_agent/actor.rb +182 -0
  6. data/lib/right_agent/actor_registry.rb +76 -0
  7. data/lib/right_agent/actors/agent_manager.rb +232 -0
  8. data/lib/right_agent/agent.rb +1149 -0
  9. data/lib/right_agent/agent_config.rb +480 -0
  10. data/lib/right_agent/agent_identity.rb +210 -0
  11. data/lib/right_agent/agent_tag_manager.rb +237 -0
  12. data/lib/right_agent/audit_formatter.rb +107 -0
  13. data/lib/right_agent/clients.rb +31 -0
  14. data/lib/right_agent/clients/api_client.rb +383 -0
  15. data/lib/right_agent/clients/auth_client.rb +247 -0
  16. data/lib/right_agent/clients/balanced_http_client.rb +369 -0
  17. data/lib/right_agent/clients/base_retry_client.rb +495 -0
  18. data/lib/right_agent/clients/right_http_client.rb +279 -0
  19. data/lib/right_agent/clients/router_client.rb +493 -0
  20. data/lib/right_agent/command.rb +30 -0
  21. data/lib/right_agent/command/agent_manager_commands.rb +150 -0
  22. data/lib/right_agent/command/command_client.rb +136 -0
  23. data/lib/right_agent/command/command_constants.rb +33 -0
  24. data/lib/right_agent/command/command_io.rb +126 -0
  25. data/lib/right_agent/command/command_parser.rb +87 -0
  26. data/lib/right_agent/command/command_runner.rb +118 -0
  27. data/lib/right_agent/command/command_serializer.rb +63 -0
  28. data/lib/right_agent/connectivity_checker.rb +179 -0
  29. data/lib/right_agent/console.rb +65 -0
  30. data/lib/right_agent/core_payload_types.rb +44 -0
  31. data/lib/right_agent/core_payload_types/cookbook.rb +61 -0
  32. data/lib/right_agent/core_payload_types/cookbook_position.rb +46 -0
  33. data/lib/right_agent/core_payload_types/cookbook_repository.rb +116 -0
  34. data/lib/right_agent/core_payload_types/cookbook_sequence.rb +70 -0
  35. data/lib/right_agent/core_payload_types/dev_repositories.rb +100 -0
  36. data/lib/right_agent/core_payload_types/dev_repository.rb +76 -0
  37. data/lib/right_agent/core_payload_types/event_categories.rb +38 -0
  38. data/lib/right_agent/core_payload_types/executable_bundle.rb +130 -0
  39. data/lib/right_agent/core_payload_types/login_policy.rb +72 -0
  40. data/lib/right_agent/core_payload_types/login_user.rb +79 -0
  41. data/lib/right_agent/core_payload_types/planned_volume.rb +94 -0
  42. data/lib/right_agent/core_payload_types/recipe_instantiation.rb +73 -0
  43. data/lib/right_agent/core_payload_types/repositories_bundle.rb +50 -0
  44. data/lib/right_agent/core_payload_types/right_script_attachment.rb +95 -0
  45. data/lib/right_agent/core_payload_types/right_script_instantiation.rb +94 -0
  46. data/lib/right_agent/core_payload_types/runlist_policy.rb +44 -0
  47. data/lib/right_agent/core_payload_types/secure_document.rb +66 -0
  48. data/lib/right_agent/core_payload_types/secure_document_location.rb +63 -0
  49. data/lib/right_agent/core_payload_types/software_repository_instantiation.rb +61 -0
  50. data/lib/right_agent/daemonize.rb +35 -0
  51. data/lib/right_agent/dispatched_cache.rb +109 -0
  52. data/lib/right_agent/dispatcher.rb +272 -0
  53. data/lib/right_agent/enrollment_result.rb +221 -0
  54. data/lib/right_agent/exceptions.rb +87 -0
  55. data/lib/right_agent/history.rb +145 -0
  56. data/lib/right_agent/log.rb +460 -0
  57. data/lib/right_agent/minimal.rb +46 -0
  58. data/lib/right_agent/monkey_patches.rb +30 -0
  59. data/lib/right_agent/monkey_patches/ruby_patch.rb +55 -0
  60. data/lib/right_agent/monkey_patches/ruby_patch/array_patch.rb +29 -0
  61. data/lib/right_agent/monkey_patches/ruby_patch/darwin_patch.rb +24 -0
  62. data/lib/right_agent/monkey_patches/ruby_patch/linux_patch.rb +24 -0
  63. data/lib/right_agent/monkey_patches/ruby_patch/linux_patch/file_patch.rb +30 -0
  64. data/lib/right_agent/monkey_patches/ruby_patch/object_patch.rb +49 -0
  65. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch.rb +32 -0
  66. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/file_patch.rb +60 -0
  67. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/process_patch.rb +63 -0
  68. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/stdio_patch.rb +27 -0
  69. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/time_patch.rb +55 -0
  70. data/lib/right_agent/monkey_patches/ruby_patch/windows_patch/win32ole_patch.rb +34 -0
  71. data/lib/right_agent/multiplexer.rb +102 -0
  72. data/lib/right_agent/offline_handler.rb +270 -0
  73. data/lib/right_agent/operation_result.rb +300 -0
  74. data/lib/right_agent/packets.rb +673 -0
  75. data/lib/right_agent/payload_formatter.rb +104 -0
  76. data/lib/right_agent/pending_requests.rb +128 -0
  77. data/lib/right_agent/pid_file.rb +159 -0
  78. data/lib/right_agent/platform.rb +770 -0
  79. data/lib/right_agent/platform/unix/darwin/platform.rb +102 -0
  80. data/lib/right_agent/platform/unix/linux/platform.rb +305 -0
  81. data/lib/right_agent/platform/unix/platform.rb +226 -0
  82. data/lib/right_agent/platform/windows/mingw/platform.rb +447 -0
  83. data/lib/right_agent/platform/windows/mswin/platform.rb +236 -0
  84. data/lib/right_agent/platform/windows/platform.rb +1808 -0
  85. data/lib/right_agent/protocol_version_mixin.rb +69 -0
  86. data/lib/right_agent/retryable_request.rb +195 -0
  87. data/lib/right_agent/scripts/agent_controller.rb +543 -0
  88. data/lib/right_agent/scripts/agent_deployer.rb +400 -0
  89. data/lib/right_agent/scripts/common_parser.rb +160 -0
  90. data/lib/right_agent/scripts/log_level_manager.rb +192 -0
  91. data/lib/right_agent/scripts/stats_manager.rb +268 -0
  92. data/lib/right_agent/scripts/usage.rb +58 -0
  93. data/lib/right_agent/secure_identity.rb +92 -0
  94. data/lib/right_agent/security.rb +32 -0
  95. data/lib/right_agent/security/cached_certificate_store_proxy.rb +77 -0
  96. data/lib/right_agent/security/certificate.rb +102 -0
  97. data/lib/right_agent/security/certificate_cache.rb +89 -0
  98. data/lib/right_agent/security/distinguished_name.rb +56 -0
  99. data/lib/right_agent/security/encrypted_document.rb +83 -0
  100. data/lib/right_agent/security/rsa_key_pair.rb +76 -0
  101. data/lib/right_agent/security/signature.rb +86 -0
  102. data/lib/right_agent/security/static_certificate_store.rb +85 -0
  103. data/lib/right_agent/sender.rb +792 -0
  104. data/lib/right_agent/serialize.rb +29 -0
  105. data/lib/right_agent/serialize/message_pack.rb +107 -0
  106. data/lib/right_agent/serialize/secure_serializer.rb +151 -0
  107. data/lib/right_agent/serialize/secure_serializer_initializer.rb +47 -0
  108. data/lib/right_agent/serialize/serializable.rb +151 -0
  109. data/lib/right_agent/serialize/serializer.rb +159 -0
  110. data/lib/right_agent/subprocess.rb +38 -0
  111. data/lib/right_agent/tracer.rb +124 -0
  112. data/right_agent.gemspec +101 -0
  113. data/spec/actor_registry_spec.rb +80 -0
  114. data/spec/actor_spec.rb +162 -0
  115. data/spec/agent_config_spec.rb +235 -0
  116. data/spec/agent_identity_spec.rb +78 -0
  117. data/spec/agent_spec.rb +734 -0
  118. data/spec/agent_tag_manager_spec.rb +319 -0
  119. data/spec/clients/api_client_spec.rb +423 -0
  120. data/spec/clients/auth_client_spec.rb +272 -0
  121. data/spec/clients/balanced_http_client_spec.rb +576 -0
  122. data/spec/clients/base_retry_client_spec.rb +635 -0
  123. data/spec/clients/router_client_spec.rb +594 -0
  124. data/spec/clients/spec_helper.rb +111 -0
  125. data/spec/command/agent_manager_commands_spec.rb +51 -0
  126. data/spec/command/command_io_spec.rb +93 -0
  127. data/spec/command/command_parser_spec.rb +79 -0
  128. data/spec/command/command_runner_spec.rb +107 -0
  129. data/spec/command/command_serializer_spec.rb +51 -0
  130. data/spec/connectivity_checker_spec.rb +83 -0
  131. data/spec/core_payload_types/dev_repositories_spec.rb +64 -0
  132. data/spec/core_payload_types/dev_repository_spec.rb +33 -0
  133. data/spec/core_payload_types/executable_bundle_spec.rb +67 -0
  134. data/spec/core_payload_types/login_user_spec.rb +102 -0
  135. data/spec/core_payload_types/recipe_instantiation_spec.rb +81 -0
  136. data/spec/core_payload_types/right_script_attachment_spec.rb +65 -0
  137. data/spec/core_payload_types/right_script_instantiation_spec.rb +79 -0
  138. data/spec/core_payload_types/spec_helper.rb +23 -0
  139. data/spec/dispatched_cache_spec.rb +136 -0
  140. data/spec/dispatcher_spec.rb +324 -0
  141. data/spec/enrollment_result_spec.rb +53 -0
  142. data/spec/history_spec.rb +246 -0
  143. data/spec/log_spec.rb +192 -0
  144. data/spec/monkey_patches/eventmachine_spec.rb +62 -0
  145. data/spec/multiplexer_spec.rb +48 -0
  146. data/spec/offline_handler_spec.rb +340 -0
  147. data/spec/operation_result_spec.rb +208 -0
  148. data/spec/packets_spec.rb +461 -0
  149. data/spec/pending_requests_spec.rb +136 -0
  150. data/spec/platform/spec_helper.rb +216 -0
  151. data/spec/platform/unix/darwin/platform_spec.rb +181 -0
  152. data/spec/platform/unix/linux/platform_spec.rb +540 -0
  153. data/spec/platform/unix/spec_helper.rb +149 -0
  154. data/spec/platform/windows/mingw/platform_spec.rb +222 -0
  155. data/spec/platform/windows/mswin/platform_spec.rb +259 -0
  156. data/spec/platform/windows/spec_helper.rb +720 -0
  157. data/spec/retryable_request_spec.rb +306 -0
  158. data/spec/secure_identity_spec.rb +50 -0
  159. data/spec/security/cached_certificate_store_proxy_spec.rb +62 -0
  160. data/spec/security/certificate_cache_spec.rb +71 -0
  161. data/spec/security/certificate_spec.rb +49 -0
  162. data/spec/security/distinguished_name_spec.rb +46 -0
  163. data/spec/security/encrypted_document_spec.rb +55 -0
  164. data/spec/security/rsa_key_pair_spec.rb +55 -0
  165. data/spec/security/signature_spec.rb +66 -0
  166. data/spec/security/static_certificate_store_spec.rb +58 -0
  167. data/spec/sender_spec.rb +1045 -0
  168. data/spec/serialize/message_pack_spec.rb +131 -0
  169. data/spec/serialize/secure_serializer_spec.rb +132 -0
  170. data/spec/serialize/serializable_spec.rb +90 -0
  171. data/spec/serialize/serializer_spec.rb +197 -0
  172. data/spec/spec.opts +2 -0
  173. data/spec/spec.win32.opts +1 -0
  174. data/spec/spec_helper.rb +130 -0
  175. data/spec/tracer_spec.rb +114 -0
  176. metadata +447 -0
@@ -0,0 +1,159 @@
1
+ #
2
+ # Copyright (c) 2009-2013 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ require 'time'
25
+ require 'date'
26
+ require 'json'
27
+
28
+ require File.normalize_path(File.join(File.dirname(__FILE__), 'message_pack'))
29
+
30
+ # Monkey patch common classes to support MessagePack serialization
31
+ # As with JSON, unserializing them is manual using existing methods such as parse
32
+ class Date
33
+ def to_msgpack(*a); to_s.to_msgpack(*a) end
34
+ end
35
+
36
+ class Time
37
+ def to_msgpack(*a); to_s.to_msgpack(*a) end
38
+ end
39
+
40
+ class DateTime
41
+ def to_msgpack(*a); to_s.to_msgpack(*a) end
42
+ end
43
+
44
+ module RightScale
45
+
46
+ # Cascade serializer supporting MessagePack and JSON serialization formats
47
+ # as well as secure serialization
48
+ class Serializer
49
+
50
+ class SerializationError < StandardError
51
+ attr_accessor :action, :packet
52
+ def initialize(action, packet, serializers, msg = nil)
53
+ @action, @packet = action, packet
54
+ msg = " (#{msg})" if msg && !msg.empty?
55
+ super("Could not #{action} packet using #{serializers.inspect}#{msg}")
56
+ end
57
+ end
58
+
59
+ # (Symbol) Preferred serialization format
60
+ attr_reader :format
61
+
62
+ # Initialize the serializer
63
+ # Do not cascade serializers if :secure is specified
64
+ #
65
+ # === Parameters
66
+ # preferred_format(Symbol|String):: Preferred serialization format: :msgpack, :json, or :secure
67
+ #
68
+ # === Raises
69
+ # ArgumentError:: If preferred format is not supported
70
+ def initialize(preferred_format = nil)
71
+ @format = (preferred_format ||= DEFAULT_FORMAT).to_sym
72
+ raise ArgumentError, "Serializer format #{@format.inspect} not one of #{FORMATS.inspect}" unless FORMATS.include?(@format)
73
+ @secure = (@format == :secure)
74
+ end
75
+
76
+ # Serialize object using preferred serializer
77
+ # Do not cascade
78
+ #
79
+ # === Parameters
80
+ # packet(Object):: Object to be serialized
81
+ # format(Symbol):: Override preferred format
82
+ #
83
+ # === Return
84
+ # (String):: Serialized object
85
+ def dump(packet, format = nil)
86
+ cascade_serializers(:dump, packet, [@secure ? SecureSerializer : SERIALIZERS[format || @format]])
87
+ end
88
+
89
+ # Unserialize object using cascaded serializers with order chosen by peaking at first byte
90
+ #
91
+ # === Parameters
92
+ # packet(String):: Data representing serialized object
93
+ # id(String|nil):: Optional identifier of source of data for use
94
+ # in determining who is the receiver
95
+ #
96
+ # === Return
97
+ # (Object):: Unserialized object
98
+ def load(packet, id = nil)
99
+ cascade_serializers(:load, packet, @secure ? [SecureSerializer] : order_serializers(packet), id)
100
+ end
101
+
102
+ private
103
+
104
+ # Supported serialization formats
105
+ SERIALIZERS = {:msgpack => MessagePack, :json => JSON}.freeze
106
+ MSGPACK_FIRST_SERIALIZERS = [MessagePack, JSON].freeze
107
+ JSON_FIRST_SERIALIZERS = MSGPACK_FIRST_SERIALIZERS.clone.reverse.freeze
108
+ FORMATS = (SERIALIZERS.keys + [:secure]).freeze
109
+ DEFAULT_FORMAT = :msgpack
110
+
111
+ # Apply serializers in order until one succeeds
112
+ #
113
+ # === Parameters
114
+ # action(Symbol):: Serialization action: :dump or :load
115
+ # packet(Object|String):: Object or serialized data on which action is to be performed
116
+ # serializers(Array):: Serializers to apply in order
117
+ # id(String):: Optional identifier of source of data for use in determining who is the receiver
118
+ #
119
+ # === Return
120
+ # (String|Object):: Result of serialization action
121
+ #
122
+ # === Raises
123
+ # SerializationError:: If none of the serializers can perform the requested action
124
+ def cascade_serializers(action, packet, serializers, id = nil)
125
+ errors = []
126
+ serializers.map do |serializer|
127
+ obj = nil
128
+ begin
129
+ obj = serializer == SecureSerializer ? serializer.send(action, packet, id) : serializer.send(action, packet)
130
+ rescue SecureSerializer::MissingCertificate, SecureSerializer::InvalidSignature => e
131
+ errors << Log.format("Failed to #{action} with #{serializer.name}", e)
132
+ rescue Exception => e
133
+ errors << Log.format("Failed to #{action} with #{serializer.name}", e, :trace)
134
+ end
135
+ return obj if obj
136
+ end
137
+ raise SerializationError.new(action, packet, serializers, errors.join("\n"))
138
+ end
139
+
140
+ # Determine likely serialization format and order serializers accordingly
141
+ #
142
+ # === Parameters
143
+ # packet(String):: Data representing serialized object
144
+ #
145
+ # === Return
146
+ # (Array):: Ordered serializers
147
+ def order_serializers(packet)
148
+ # note the following code for getting the ascii value of the first byte is
149
+ # efficient for a large packet because it returns an enumerator for the
150
+ # internal byte array. it is actually more efficient than extracting the
151
+ # first character as a string and converting it to bytes.
152
+ # also, the following line works for both ruby 1.8 and ruby 1.9 since the
153
+ # definition of the bracket operator has changed.
154
+ packet.bytes.first > 127 ? MSGPACK_FIRST_SERIALIZERS : JSON_FIRST_SERIALIZERS
155
+ end
156
+
157
+ end # Serializer
158
+
159
+ end # RightScale
@@ -0,0 +1,38 @@
1
+ #-- -*- mode: ruby; encoding: utf-8 -*-
2
+ # Copyright: Copyright (c) 2011 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ module RightScale
25
+ module SubprocessFormatting
26
+ module_function
27
+
28
+ SIGNAL_LOOKUP = Signal.list.invert
29
+
30
+ def reason(status)
31
+ if status.exitstatus.nil?
32
+ "terminated with SIG#{SIGNAL_LOOKUP[status.termsig]}"
33
+ else
34
+ "exited with #{status.exitstatus}"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,124 @@
1
+ #
2
+ # Copyright (c) 2009-2011 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ # This allows us to define class methods
24
+ class Object
25
+ def metaclass
26
+ class << self
27
+ self
28
+ end
29
+ end
30
+ end
31
+
32
+ module RightScale
33
+
34
+ class Tracer
35
+
36
+ NON_TRACEABLE_CLASSES = [ 'Kernel', 'Module', 'Object' , 'SyslogLogger', 'RightSupport::Log::SystemLogger' ] +
37
+ [ 'RightScale::Tracer', 'RightScale::Multiplexer' ] +
38
+ [ 'RightScale::Log', 'RightScale::Log::Formatter' ]
39
+
40
+ NON_TRACEABLE_METHODS = [ :metaclass, :method_missing, :method_added, :blank_slate_method_added, :[], :[]= ]
41
+
42
+ NON_TRACEABLE_CLASS_METHODS = [ :initialize, :initialize_copy, :inherited, :new, :allocate, :superclass ]
43
+
44
+ # Add logs when entering and exiting instance and class methods
45
+ # defined on given class
46
+ #
47
+ # === Parameters
48
+ # klass(Class):: Class whose methods should be traced
49
+ #
50
+ # === Return
51
+ # true:: Always return true
52
+ def self.add_tracing_to_class(klass)
53
+ return true if NON_TRACEABLE_CLASSES.include?(klass.to_s)
54
+ (klass.public_instance_methods(all=false) + klass.private_instance_methods(all=false) +
55
+ klass.protected_instance_methods(all=false)).each do |m|
56
+ if traceable(m)
57
+ old_m = klass.instance_method(m)
58
+ klass.module_eval <<-EOM
59
+ alias :o_l_d_#{m} :#{m}
60
+ def #{m}(*args, &blk)
61
+ Log.debug("<<< #{klass}##{m}(" + args.map(&:inspect).join(',') + ")")
62
+ res = o_l_d_#{m}(*args, &blk)
63
+ Log.debug(">>> #{klass}##{m}")
64
+ res
65
+ end
66
+ EOM
67
+ end
68
+ end
69
+ (klass.public_methods(all=false) + klass.private_methods(all=false) +
70
+ klass.protected_methods(all=false)).each do |m|
71
+ if traceable(m, static=true)
72
+ old_m = klass.method(m)
73
+ klass.module_eval <<-EOM
74
+ class << self
75
+ alias :o_l_d_#{m} :#{m}
76
+ def #{m}(*args, &blk)
77
+ Log.debug("<<< #{klass}.#{m}(" + args.map(&:inspect).join(',') + ")")
78
+ res = o_l_d_#{m}(*args, &blk)
79
+ Log.debug(">>> #{klass}.#{m}")
80
+ res
81
+ end
82
+ end
83
+ EOM
84
+ end
85
+ end
86
+ true
87
+ end
88
+
89
+ # Can method be traced?
90
+ #
91
+ # === Parameters
92
+ # m(String):: Method name
93
+ # static(Boolean):: Whether method is a class method
94
+ #
95
+ # === Return
96
+ # traceable(Boolean):: true if method can be traced, false otherwise
97
+ def self.traceable(m, static=false)
98
+ traceable = !NON_TRACEABLE_METHODS.include?(m.to_sym) && m =~ /[a-zA-Z0-9]$/
99
+ traceable &&= !NON_TRACEABLE_CLASS_METHODS.include?(m.to_sym) if static
100
+ traceable
101
+ end
102
+
103
+ # Add tracing to all classes in given namespaces
104
+ #
105
+ # === Parameters
106
+ # namespaces(Array|String):: Namespace(s) of classes whose methods should be traced
107
+ #
108
+ # === Return
109
+ # true:: Always return true
110
+ def self.add_tracing_to_namespaces(namespaces)
111
+ namespaces = [ namespaces ] unless namespaces.respond_to?(:inject)
112
+ regexps = namespaces.inject([]) { |reg, n| reg << "^#{n}::" }
113
+ unless regexps.empty?
114
+ ObjectSpace.each_object(Class) do |c|
115
+ if c.to_s =~ /#{regexps.join('|')}/
116
+ add_tracing_to_class(c)
117
+ end
118
+ end
119
+ end
120
+ true
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,101 @@
1
+ # -*-ruby-*-
2
+ # Copyright: Copyright (c) 2011-2013 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ require 'rbconfig'
25
+
26
+ Gem::Specification.new do |spec|
27
+ spec.name = 'right_agent'
28
+ spec.version = '2.0.7'
29
+ spec.date = '2014-02-28'
30
+ spec.authors = ['Lee Kirchhoff', 'Raphael Simon', 'Tony Spataro', 'Scott Messier']
31
+ spec.email = 'lee@rightscale.com'
32
+ spec.homepage = 'https://github.com/rightscale/right_agent'
33
+ spec.platform = Gem::Platform::RUBY
34
+ spec.summary = 'Agent for interfacing server with RightScale system'
35
+ spec.has_rdoc = true
36
+ spec.rdoc_options = ["--main", "README.rdoc", "--title", "RightAgent"]
37
+ spec.extra_rdoc_files = ["README.rdoc"]
38
+ spec.required_ruby_version = '>= 1.8.7'
39
+ spec.require_path = 'lib'
40
+
41
+ spec.add_dependency('right_support', ['>= 2.4.1', '< 3.0'])
42
+ spec.add_dependency('right_amqp', '~> 0.7')
43
+ spec.add_dependency('rest-client', '1.7.0.alpha')
44
+ spec.add_dependency('faye-websocket', '0.7.0')
45
+ spec.add_dependency('eventmachine', ['>= 0.12.10', '< 2.0'])
46
+ spec.add_dependency('net-ssh', '~> 2.0')
47
+
48
+ # TEAL HACK: rake gem may override current RUBY_PLATFORM to allow building
49
+ # gems for all supported platforms from any platform. rubygems 1.8.x makes it
50
+ # necessary to produce platform-specific gems with context-sensitive gemspecs
51
+ # in order to retain Windows (or Linux)-specific gem requirements. this works
52
+ # from any platform because there is no native code to pre-compile and package
53
+ # with this gem.
54
+ gem_platform = defined?(::RightScale::MultiPlatformGemTask.gem_platform_override) ?
55
+ ::RightScale::MultiPlatformGemTask.gem_platform_override :
56
+ nil
57
+ gem_platform ||= ::RbConfig::CONFIG['host_os']
58
+ case gem_platform
59
+ when /mswin/i
60
+ spec.add_dependency('win32-api', ['>= 1.4.5', '< 1.4.7'])
61
+ spec.add_dependency('win32-dir', '~> 0.3.5')
62
+ spec.add_dependency('win32-process', '~> 0.6.1')
63
+ spec.add_dependency('msgpack', ['>= 0.4.4', '< 0.5'])
64
+ spec.add_dependency('json', '1.4.6')
65
+ spec.platform = 'x86-mswin32-60'
66
+ when /mingw/i
67
+ spec.add_dependency('ffi')
68
+ spec.add_dependency('win32-dir', '>= 0.3.5')
69
+ spec.add_dependency('win32-process', '>= 0.6.1')
70
+ spec.add_dependency('msgpack', ['>= 0.4.4', '< 0.6'])
71
+ spec.add_dependency('json', '~> 1.4')
72
+ spec.platform = 'x86-mingw32'
73
+ when /win32|dos|cygwin|windows/i
74
+ raise ::NotImplementedError, 'Unsupported Ruby-on-Windows variant'
75
+ else
76
+ # ffi is not currently needed by Linux but it does no harm to have it and it
77
+ # allows bundler to generate a consistent Gemfile.lock when it is declared
78
+ # for both mingw and Linux.
79
+ spec.add_dependency('ffi')
80
+ spec.add_dependency('msgpack', ['>= 0.4.4', '< 0.6'])
81
+ spec.add_dependency('json', '~> 1.4')
82
+ end
83
+
84
+ spec.description = <<-EOF
85
+ RightAgent provides a foundation for running an agent on a server to interface
86
+ in a secure fashion with other agents in the RightScale system using RightNet,
87
+ which operates in either HTTP or AMQP mode. When using HTTP, RightAgent
88
+ makes requests to RightApi servers and receives requests using long-polling or
89
+ WebSockets via the RightNet router. To respond to requests it posts to the
90
+ HTTP router. When using AMQP, RightAgent uses RabbitMQ as the message bus and
91
+ the RightNet router as the routing node to make requests; to receives requests
92
+ routed to it by the RightNet router, it establishes a queue on startup. The
93
+ packets are structured to invoke services in the agent represented by actors
94
+ and methods. The RightAgent may respond to these requests with a result packet
95
+ that the router then routes to the originator.
96
+ EOF
97
+
98
+ candidates = Dir.glob("{lib,spec}/**/*") +
99
+ ["LICENSE", "README.rdoc", "Rakefile", "right_agent.gemspec"]
100
+ spec.files = candidates.sort
101
+ end
@@ -0,0 +1,80 @@
1
+ #
2
+ # Copyright (c) 2009-2011 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
24
+
25
+ describe RightScale::ActorRegistry do
26
+
27
+ class ::WebDocumentImporter
28
+ include RightScale::Actor
29
+ expose_non_idempotent :import, :cancel
30
+ expose_idempotent :special
31
+
32
+ def import; 1 end
33
+ def cancel; 0 end
34
+ def special; 2 end
35
+ end
36
+
37
+ module ::Actors
38
+ class ComedyActor
39
+ include RightScale::Actor
40
+ expose :fun_tricks
41
+ def fun_tricks
42
+ :rabbit_in_the_hat
43
+ end
44
+ end
45
+ end
46
+
47
+ before(:each) do
48
+ @registry = RightScale::ActorRegistry.new
49
+ end
50
+
51
+ it "should know about all services" do
52
+ @registry.register(WebDocumentImporter.new, nil)
53
+ @registry.register(Actors::ComedyActor.new, nil)
54
+ @registry.services.sort.should == ["/actors/comedy_actor/fun_tricks", "/web_document_importer/cancel",
55
+ "/web_document_importer/import", "/web_document_importer/special"]
56
+ end
57
+
58
+ it "should not register anything except RightScale::Actor" do
59
+ lambda { @registry.register(String.new, nil) }.should raise_error(ArgumentError)
60
+ end
61
+
62
+ it "should register an actor" do
63
+ importer = WebDocumentImporter.new
64
+ @registry.register(importer, nil)
65
+ @registry.actors['web_document_importer'].should == importer
66
+ end
67
+
68
+ it "should log info message that actor was registered" do
69
+ importer = WebDocumentImporter.new
70
+ flexmock(RightScale::Log).should_receive(:info).with("[actor] #{importer.class.to_s}").once
71
+ @registry.register(importer, nil)
72
+ end
73
+
74
+ it "should handle actors registered with a custom prefix" do
75
+ importer = WebDocumentImporter.new
76
+ @registry.register(importer, 'monkey')
77
+ @registry.actor_for('monkey').should == importer
78
+ end
79
+
80
+ end # RightScale::ActorRegistry