cloud_powers 0.2.7.23 → 1.0.0

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.test.env.example +6 -6
  4. data/.travis.yml +1 -1
  5. data/README +190 -0
  6. data/cloud_powers.gemspec +4 -4
  7. data/lib/cloud_powers.rb +3 -13
  8. data/lib/cloud_powers/aws_resources.rb +21 -4
  9. data/lib/cloud_powers/creatable.rb +122 -0
  10. data/lib/cloud_powers/helpers.rb +58 -0
  11. data/lib/cloud_powers/helpers/lang_help.rb +288 -0
  12. data/lib/cloud_powers/helpers/logic_help.rb +152 -0
  13. data/lib/cloud_powers/helpers/path_help.rb +90 -0
  14. data/lib/cloud_powers/node.rb +69 -68
  15. data/lib/cloud_powers/node/instance.rb +52 -0
  16. data/lib/cloud_powers/resource.rb +44 -0
  17. data/lib/cloud_powers/storage.rb +27 -14
  18. data/lib/{stubs → cloud_powers/stubs}/aws_stubs.rb +37 -14
  19. data/lib/cloud_powers/synapse/broadcast.rb +117 -0
  20. data/lib/cloud_powers/synapse/broadcast/channel.rb +44 -0
  21. data/lib/cloud_powers/synapse/pipe.rb +211 -0
  22. data/lib/cloud_powers/synapse/pipe/stream.rb +41 -0
  23. data/lib/cloud_powers/synapse/queue.rb +357 -0
  24. data/lib/cloud_powers/synapse/queue/board.rb +61 -95
  25. data/lib/cloud_powers/synapse/queue/poller.rb +29 -0
  26. data/lib/cloud_powers/synapse/synapse.rb +10 -12
  27. data/lib/cloud_powers/synapse/web_soc.rb +13 -0
  28. data/lib/cloud_powers/synapse/web_soc/soc_client.rb +52 -0
  29. data/lib/cloud_powers/synapse/web_soc/soc_server.rb +48 -0
  30. data/lib/cloud_powers/version.rb +1 -1
  31. data/lib/cloud_powers/zenv.rb +13 -12
  32. metadata +24 -13
  33. data/lib/cloud_powers/context.rb +0 -275
  34. data/lib/cloud_powers/delegator.rb +0 -113
  35. data/lib/cloud_powers/helper.rb +0 -453
  36. data/lib/cloud_powers/synapse/websocket/websocclient.rb +0 -53
  37. data/lib/cloud_powers/synapse/websocket/websocserver.rb +0 -46
  38. data/lib/cloud_powers/workflow_factory.rb +0 -160
@@ -1,53 +0,0 @@
1
- require 'websocket-eventmachine-client'
2
-
3
- module Smash
4
- module CloudPowers
5
- module Synapse
6
- module WebSocClient
7
-
8
- def create_websoc_client(opts = {})
9
- ws = {}
10
- Thread.new(ws) do
11
- EM.run do
12
- ws = WebSocket::EventMachine::Client.connect(:uri => 'ws://' + opts[:host] + ':' + opts[:port])
13
-
14
- client_name = opts[:client] || 'default_client'
15
-
16
- instance_variable_set(:"@#{client_name}",ws)
17
-
18
- open_callback = opts[:on_open] || Proc.new do
19
- puts "Connected"
20
- end
21
-
22
- ws.onopen &open_callback
23
-
24
- on_message_callback = opts[:on_message] || Proc.new do |msg, type|
25
- puts "Received message: #{msg}"
26
- end
27
-
28
- ws.onmessage &on_message_callback
29
-
30
- on_error_callback = opts[:on_error] || Proc.new do |error|
31
- puts "Error ==> #{error}"
32
- end
33
-
34
- ws.onerror &on_error_callback
35
-
36
- on_close_callback = opts[:on_close] || Proc.new do |code, reason|
37
- puts "Disconnected with status code: #{code}"
38
- puts "Disconnected with status message: #{reason}"
39
- end
40
-
41
- ws.onclose &on_close_callback
42
-
43
- end
44
-
45
- end
46
- end
47
-
48
- end
49
- end
50
- end
51
- end
52
-
53
-
@@ -1,46 +0,0 @@
1
- require 'websocket-eventmachine-server'
2
- module Smash
3
- module CloudPowers
4
- module Synapse
5
- module WebSocServer
6
- def create_websoc_server(opts = {})
7
- channel = opts[:channel] || EM::Channel.new
8
- Thread.new do
9
- EM.run do
10
- WebSocket::EventMachine::Server.start(:host => opts[:host], :port => opts[:port]) do |ws|
11
- sid = nil
12
-
13
- open_callback = opts[:on_open] || Proc.new do
14
- puts "Client connected"
15
- sid = channel.subscribe { |msg| ws.send msg }
16
- end
17
- ws.onopen &open_callback
18
-
19
- on_message_callback = opts[:on_message] || Proc.new do |msg, type|
20
- @current_websocket_message = msg
21
- end
22
- ws.onmessage &on_message_callback
23
-
24
- on_error_callback = opts[:on_error] || Proc.new do |error|
25
- puts "Error occured: #{error}"
26
- end
27
- ws.onerror &on_error_callback
28
-
29
- on_close_callback = opts[:on_close] || Proc.new do
30
- puts "Client disconnected"
31
- channel.unsubscribe(sid) unless channel.nil?
32
- end
33
- ws.onclose &on_close_callback
34
- end
35
- end
36
- end
37
- channel
38
- end
39
-
40
- def broadcast_message(channel, msg)
41
- channel.push msg
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,160 +0,0 @@
1
- require 'workflow'
2
-
3
- module Smash
4
- module CloudPowers
5
- # The WorkflowFactory module provides you with a custom, embeddable workflow
6
- # for classes. To do this, it takes a description of the workflow, in
7
- # the form of a <tt>Hash</tt> and injects it into the class' Singleton/Eigan
8
- # class. It uses the +workflow+ gem to handle the workflow stuff for now
9
- # but after MVP, this will be a roll-our-own implementation, to cut down on
10
- # all dependencies possible.
11
- module WorkflowFactory
12
- # This is the method responsible for injecting the workflow on the instance
13
- # it is called on. After this method is called on an instance of some class,
14
- # you can then access any of the described states as methods on that instance.
15
- #
16
- # Parameters
17
- # * description +Hash+ - Describe the workflow you want to use. The format
18
- # follows the actual Workflow Specification(s) from the gem that you would
19
- # normally write onto the class like normal.
20
- #
21
- # * Example +description+ +Hash+
22
- # * * this description would give you a workflow that starts in the +new+
23
- # state and when the <tt>#build!()</tt> method was called on the object
24
- # that has this workflow, the state would transition into the +building+
25
- # state. The workflow would then listen for the <tt>run!()</tt> method
26
- # call, which would progress the state to the +in_progress+ state. Next,
27
- # the workflow would listen for the <tt>post_results!()</tt> method
28
- # call. When someone or something calls it, the state will progress to
29
- # the final state, +done+, from which no more workflow stuff will happen.
30
- #
31
- # description = {
32
- # workflow: {
33
- # states: [
34
- # { new: { event: :build, transitions_to: :building } },
35
- # { building: { event: :run, transitions_to: :in_progress } },
36
- # { in_progress: { event: :post_results, transitions_to: :done } },
37
- # { done: nil }
38
- # ]
39
- # }
40
- # }
41
- #
42
- # Returns
43
- # * +nil+
44
- #
45
- # Example
46
- # * build the workflow using the description from above
47
- # class Job
48
- # # code code code...
49
- # def insert_my_workflow(description)
50
- # class << build_workflow(description)
51
- # end
52
- # end
53
- #
54
- # Which would yield this workflow, from the Workflow gem
55
- #
56
- # class Job
57
- # # all the commented lines below are what `WorkflowFactory#inject_workflow()`
58
- # # did for you. These lines don't need to actually be in your class.
59
- #
60
- # # include Workflow
61
- # #
62
- # # workflow do
63
- # # state :new do
64
- # # event :build, :transitions_to => :building
65
- # # end
66
- # # state :building do
67
- # # event :run, :transitions_to => :in_progress
68
- # # end
69
- # # state :in_progress do
70
- # # event :post_results, :transitions_to => :done
71
- # # end
72
- # # state :done
73
- # # end
74
- # end
75
- #
76
- # job = Job.new
77
- # # => #<Job:0x007fdaba8956b0>
78
- # job.done?
79
- # # => NoMethodError
80
- # job.insert_workflow(description)
81
- # # => nil
82
- # job.done?
83
- # # => false
84
- # job.current_state
85
- # # => :building
86
- #
87
- # Notes
88
- # * See <tt>description_to_s()</tt>
89
- # * TODO: There has got to be a better way, so if any of you have suggestions...
90
- # The fact that the eval gets evaluated and invoked in the workflow gem
91
- # is of little comfort, despite how nice the gem is. Long story short,
92
- # be comfortable with what you're doing.
93
- # * see the workflow gem docs and question me if you want some nice ways
94
- # to really use this module. {workflow homepage}[https://github.com/geekq/workflow]
95
- def inject_workflow(description)
96
- workflow_spec_string = description_to_s(description)
97
- begin
98
- self.class.class_eval(workflow_spec_string)
99
- define_singleton_method(:has_workflow?) { true }
100
- rescue Exception => e
101
- define_singleton_method(:has_workflow?) { !!(puts e.backtrace) }
102
- end
103
- end
104
-
105
- # Takes a description and turns it into a string that would describe the
106
- # workflow you want to insert.
107
- #
108
- # Parameters
109
- # * +description+ +Hash+ - of the format
110
- # {
111
- # workflow: {
112
- # states: [
113
- # { state_name: { event: :event_name, transitions_to: :transition_to_name } },
114
- # { state_name: nil }
115
- # ]
116
- # }
117
- # }
118
- #
119
- # Returns
120
- # +String+
121
- #
122
- # Example
123
- # # given the description seen in <tt>inject_workflow()</tt>
124
- # puts description_to_s(description)
125
- # # =>
126
- # workflow do
127
- # state :new do
128
- # event :build, :transitions_to => :building
129
- # end
130
- # state :building do
131
- # event :run, :transitions_to => :in_progress
132
- # end
133
- # state :in_progress do
134
- # event :post_results, :transitions_to => :done
135
- # end
136
- # state :done
137
- # end
138
- # Notes
139
- # * See <tt>inject_workflow()</tt>
140
- def description_to_s(description)
141
- description_string_builder = ['include Workflow', 'workflow do']
142
- description[:workflow][:states].each do |state|
143
- state.map do |name, state_description|
144
- if state_description.nil? # if this is a final state...
145
- description_string_builder << "state :#{name}"
146
- else # because it is not a final state, add event information too.
147
- description_string_builder.concat([
148
- "state :#{name} do",
149
- "event :#{state_description[:event]}, transitions_to: :#{state_description[:transitions_to]}",
150
- "end"
151
- ])
152
- end
153
- end
154
- end
155
- description_string_builder << "end\n"
156
- description_string_builder.join("\n")
157
- end
158
- end
159
- end
160
- end