cloud_powers 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2eb2fb62a14e0c435b743193307d0a5873418966
4
- data.tar.gz: 0bb16fc127344ec9db8c2c907ee255cb7a98600f
3
+ metadata.gz: 391860e2ec54145cbb41486fd29c2915caaaf7b5
4
+ data.tar.gz: 1bccfe4b9cbb9f3293c2c3a740567edc0e9eb9d5
5
5
  SHA512:
6
- metadata.gz: 5f681808bafeb4d0971964879fa92e6f7dbc167dcfcac1b316605cf1863090d21417ceb9e0ca3e881a21567225da0fbf87e81ecc60b2e7bb2513c7564479c52b
7
- data.tar.gz: 7327c2caf73b637e606df4779ea40db93f2ea5e18ac5d4bd5e7ebc2530b6d2dbd95f0d6e67278d5969a401fd9b89a359afd1b84b073652efc5c8d5e251e16439
6
+ metadata.gz: 83e75d3065430d6e2123a4b7e7104818c2fbcf9f0a091022c6e85aec929bc7d335bb0abdda6393e8435eb0e9ee533fd0a4eae8d17cfac3be93f7a505de410ae1
7
+ data.tar.gz: f1c12786a596e76cd4d87aefff57a8d8d2abf4924a80c8653624c3749c4aec290dbe2cc9e81c4696c813fd7930b6c2faac31f0d50eea5e285b9f76923ff25f47
data/.byebug_history CHANGED
@@ -1,19 +1,256 @@
1
+ exit
2
+ Smash::CloudPowers.included_modules
3
+ Smash::CloudPowers
4
+ Pipe
5
+ Queue
6
+ CloudPowers.public_methods(false)
7
+ CloudPowers.public_methods
8
+ CloudPowers.included_modules
9
+ CloudPowers.methods.sort
10
+ CloudPowers
11
+ self.methods.sort
12
+ self.modules
1
13
  c
2
14
  exit
3
- q = Boogs.new
15
+ Smash.const_get(to_pascal(task)).new
16
+ Smash.const_get(to_pascal(task))
17
+ to_pascal(task)
18
+ c
19
+ exit
20
+ n
21
+ var.to_s[/\.{1}[a-z]+$/]
22
+ l
23
+ l-
24
+ u = basename(Pathname(var))
25
+ u
26
+ v
27
+ var.to_s.gsub(/\.\w+$/, '').gsub(/\W/, '_').downcase + (file_ext || '')
28
+ var.to_s.gsub(/\.\w+$/, '').gsub(/\W/, '_').downcase + file_ext
29
+ file_ext = var.to_s[/\.{1}[a-z]+$/]
30
+ var.to_s[/\.{1}[a-z]+$/]
31
+ var.to_s
32
+ eval 'var'
33
+ var
34
+ s
35
+ name
36
+ to_snake(name)
37
+ s
38
+ task
39
+ n
40
+ body
41
+ n
42
+ s
43
+ c
44
+ n
45
+ s
46
+ c
47
+ n
48
+ exit
49
+ FileUtils::touch(task_path('testinz.rb'))
50
+ FileUtils::mkdir_p task_path
51
+ task_path
52
+ FileUtils::touch(task_path('testinz.rb'))
53
+ task_path('testinz.rb')
54
+ exit
55
+ Pathname(__FILE__).parent.dirname + "tasks/#{to_snake(file)}"
56
+ file.empty?
57
+ s
58
+ exit
59
+ Pathname(__FILE__).dirname.parent + 'tasks' + ''
60
+ to_snake(t_p)
61
+ t_p
62
+ file.empty? ? t_p : Pathname(to_snake(t_p))
63
+ file
64
+ t_p
65
+ n
66
+ s
67
+ c
68
+ b = ok['.rb']
69
+ ok
70
+ ok['.rb']
71
+ ok = 'bla.rb'
72
+ s3
73
+ s3.stub_responses(:list_buckets, [])
74
+ c
75
+ exit
76
+ @uuu
77
+ n
78
+ exit
79
+ File.open '/Users/adam/code/cloud_powers/lib/tasks/testinz.rb'
80
+ task_path 'testinz'
81
+ task_path
82
+ task_path_name
4
83
  exit
84
+ ext
85
+ exit
86
+ FileUtils.ls(task_path '')
87
+ FileUtils.ls(task_path)
88
+ task_path('testinz') + '.rb'
89
+ c
90
+ exit
91
+ puts ENV.keys.sort
92
+ ENV
93
+ key
94
+ s
95
+ region
96
+ s
97
+ s3.list_objects(bucket: bucket).contents
98
+ bucket = 'jobRequests'
99
+ bucket
100
+ n
101
+ task_path(file).exist?
102
+ n
103
+ s
104
+ n
105
+ s
106
+ c
107
+ s
108
+ n
109
+ task
110
+ n
111
+ msg.body
112
+ msg
113
+ s
114
+ Smash::Testinz.new
115
+ Smash::Testinz
116
+ c
117
+ name
118
+ s
119
+ c
120
+ b = OpenStruct.new(name: 'yo', body: {})
121
+ require 'ostruct'
122
+ k = Struct.new(name: 'ok')
123
+ JSON.parse(msg.body)
124
+ s
125
+ exit
126
+ exception
127
+ n
128
+ { body: {} }.to_json
129
+ c
130
+ exit
131
+ self.class
5
132
  build
6
- self.extend Smash::Delegator
133
+ Delegator.build
134
+ c
135
+ exit
136
+ Delegator.build
7
137
  exit
8
138
  build
9
- self.extend Smash::Delegator
139
+ l-
140
+ Smash::CloudPowers::Delegator.methods.sort
141
+ puts Delegator.class
142
+ puts Delegator.methods.sort
143
+ Delegator.class
144
+ Delegator
145
+ c
10
146
  exit
11
- self
12
- self.extend Delegator
147
+ @instance_url =~ URI::regexp
148
+ @instance_url
149
+ exit
150
+ get_instance_url
151
+ instance_url
152
+ @instance_url
153
+ c
154
+ n
155
+ c
156
+ expect(now).to be_less_than(boot_time)
157
+ boot_time
158
+ task_name
159
+ @boot_time
160
+ @task_name
161
+ n
162
+ s
163
+ exit
164
+ l
165
+ l-
166
+ ec2.describe_instances(instance_ids: [ids].flatten).reservations[0].instances[0].tags.select { |t| t.value if t.key == 'taskType' }
167
+ env '*'
168
+ env *
169
+ env
170
+ ec2.describe_instances(instance_ids: [ids].flatten).reservations[0].instances[0].tags.select { |t| t.value if t.key == 'taskType' }
171
+ ec2.stub_responses
172
+ ec2.stub_response
173
+ ec2.describe_instances(instance_ids: [ids].flatten)
174
+ ids
175
+ s
176
+ @task_name
177
+ s
178
+ n
179
+ @boot_time
180
+ n
181
+ c
182
+ exit
183
+ e
184
+ format_error_message e
185
+ e
186
+ s
187
+ format_error_message e
188
+ format_error_message
189
+ n
190
+ ec2.describe_instances(dry_run: env('testing'), instance_ids:[@instance_id]).reservations[0].instances[0].launch_time.to_i
191
+ @instance_id
192
+ n
193
+ s
194
+ n
195
+ exit
196
+ n
197
+ value
198
+ key
199
+ n
200
+ key
201
+ n
202
+ s
203
+ block_given?
204
+ key
205
+ n
206
+ s
207
+ keys
208
+ n
209
+ key
210
+ n
211
+ env('TESTING')
212
+ s
213
+ exit
214
+ get_awareness!
215
+ methods.sort
216
+ get!
217
+ @instance_id
218
+ @boot_time
219
+ n
220
+ s
221
+ exit
222
+ region
223
+ boot_time
224
+ exit
225
+ f = File.new('.test.env')
226
+ `pwd`
227
+ pwd
228
+ Dotenv.load('.test.env')
229
+ Dotenv.load(.test.env)
230
+ require 'dotenv'
231
+ c
232
+ exit
233
+ ENV[to_snake(key).upcase]
234
+ require 'dotenv'
235
+ s
236
+ n
237
+ s
238
+ l-
239
+ l
240
+ puts ENV.keys.sort
241
+ ENV['TESTING']
242
+ ENV['testing']
243
+ region
244
+ n
245
+ s
246
+ c
247
+ exit
248
+ q = Boogs.new
249
+ exit
250
+ build
13
251
  self.extend Smash::Delegator
14
252
  exit
253
+ build
15
254
  self.extend Smash::Delegator
16
- Delegator.class
17
- Delegator
18
- self.extend Delegator
255
+ exit
19
256
  self
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.env
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloud_powers (0.1.3)
4
+ cloud_powers (0.1.4)
5
5
  activesupport-core-ext (~> 4)
6
6
  aws-sdk (~> 2)
7
7
  dotenv (~> 2.1)
@@ -1,9 +1,11 @@
1
1
  require_relative 'auth'
2
+ require_relative 'helper'
2
3
 
3
4
  module Smash
4
5
  module CloudPowers
5
6
  module AwsResources
6
- extend Smash::CloudPowers::Auth
7
+ include Smash::CloudPowers::Auth
8
+ include Smash::CloudPowers::Helper
7
9
 
8
10
  def region
9
11
  env('Aws Region')
@@ -28,6 +30,13 @@ module Smash
28
30
  credentials: Auth.creds,
29
31
  )
30
32
  end
33
+
34
+ def s3
35
+ @s3 ||= Aws::S3::Client.new(
36
+ region: region,
37
+ credentials: Auth.creds
38
+ )
39
+ end
31
40
  end
32
41
  end
33
42
  end
@@ -1,7 +1,8 @@
1
1
  # require 'auth'
2
2
  # require 'aws_resources'
3
- # require 'helper'
4
- # require 'storage'
3
+ require 'json'
4
+ require_relative 'helper'
5
+ require_relative 'storage'
5
6
 
6
7
  module Smash
7
8
  module CloudPowers
@@ -20,7 +21,7 @@ module Smash
20
21
  require_relative task_require_path(task)
21
22
  Smash.const_get(to_pascal(task)).new(id, msg)
22
23
  else
23
- Task.new(id, msg) # returns a default Task
24
+ Smash::Task.new(id, msg) # returns a default Task
24
25
  end
25
26
  rescue JSON::ParserError => e
26
27
  message = [msg.body, format_error_message(e)].join("\n")
@@ -31,7 +32,7 @@ module Smash
31
32
 
32
33
  def approved_task?(name = nil)
33
34
  # TODO: improve this
34
- ['demo', 'testinz'].include? name
35
+ ['demo', 'testinz'].include? to_snake(name)
35
36
  end
36
37
  end
37
38
  end
@@ -62,8 +62,13 @@ module Smash
62
62
  end
63
63
  end
64
64
 
65
- def task_path(file)
66
- Pathname(__FILE__).parent.dirname + 'tasks' + to_ruby_file_name(file)
65
+ def task_path(file = '')
66
+ # t_p = Pathname(__FILE__).parent.dirname + 'tasks'
67
+ if file.empty?
68
+ Pathname(__FILE__).parent.dirname + 'tasks'
69
+ else
70
+ Pathname(__FILE__).parent.dirname + "tasks/#{to_snake(file)}"
71
+ end
67
72
  end
68
73
 
69
74
  def task_require_path(file_name)
@@ -92,8 +97,8 @@ module Smash
92
97
  end
93
98
 
94
99
  def to_snake(var)
95
- var = var.to_s unless var.kind_of? String
96
- var.gsub(/\W/, '_').downcase
100
+ file_ext = var.to_s[/\.{1}[a-z]+$/] || ''
101
+ var.to_s.gsub(/\.\w+$/, '').gsub(/\W/, '_').downcase + file_ext
97
102
  end
98
103
 
99
104
  def update_message_body(opts = {})
@@ -1,18 +1,17 @@
1
1
  require 'aws-sdk'
2
2
  Aws.use_bundled_cert!
3
3
  require 'httparty'
4
+ require_relative 'aws_resources'
4
5
  require_relative 'helper'
5
6
  require_relative './synapse/synapse'
6
7
 
7
8
  module Smash
8
9
  module CloudPowers
9
- extend Smash::CloudPowers::Synapse::Pipe
10
- extend Smash::CloudPowers::Synapse::Queue
11
-
12
10
  module SelfAwareness
13
11
  extend Smash::CloudPowers::Helper
14
12
  extend Smash::CloudPowers::Synapse::Pipe
15
13
  extend Smash::CloudPowers::Synapse::Queue
14
+ include Smash::CloudPowers::AwsResources
16
15
 
17
16
  def boot_time
18
17
  begin
@@ -20,7 +19,7 @@ module Smash
20
19
  ec2.describe_instances(dry_run: env('testing'), instance_ids:[@instance_id]).
21
20
  reservations[0].instances[0].launch_time.to_i
22
21
  rescue Aws::EC2::Errors::DryRunOperation => e
23
- logger.info "dry run for testing: #{format_error_message(e)}"
22
+ logger.info "dry run for testing: #{e}"
24
23
  @boot_time ||= Time.now.to_i # comment the code below for development mode
25
24
  end
26
25
  end
@@ -51,27 +50,32 @@ module Smash
51
50
  end
52
51
  end
53
52
 
53
+ # Get resource metadata, public host, boot time and task name
54
+ # and set them as instance variables
54
55
  def get_awareness!
55
56
  keys = metadata_request
56
57
  attr_map!(keys) { |key| metadata_request(key) }
57
- boot_time # sets @boot_time
58
+ boot_time # gets and sets @boot_time
58
59
  task_name # gets and sets @task_name
60
+ instance_url # gets and sets @instance_url
59
61
  end
60
62
 
61
- def task_name(ids = @instance_id)
62
- # check tags for 'task'
63
- if @task_name.nil?
64
- resp = ec2.describe_instances(instance_ids: [ids].flatten)
65
- @task_name = resp.reservations[0].instances[0].tags.select do |t|
66
- t.value if t.key == 'taskType'
67
- end
68
- else
69
- @task_name
70
- end
63
+ # Check self-tags for 'task' and act as an attr_accessor.
64
+ # A different node's tag's can be checked for a task by passing
65
+ # the id param
66
+ # see also: SelfAwareness#task_names
67
+ def task_name(id = @instance_id)
68
+ # get @task_name
69
+ return @task_name unless @task_name.nil?
70
+ # set @task_name
71
+ resp = ec2.describe_instances(instance_ids: [id].flatten)
72
+ @task_name = resp.reservations[0].instances[0].tags.select do |t|
73
+ t.value if t.key == 'taskType'
74
+ end.first
71
75
  end
72
76
 
73
- def get_instance_url
74
- if env('TESTING')
77
+ def instance_url
78
+ @instance_url ||= if env('TESTING')
75
79
  'https://test-url.com'
76
80
  else
77
81
  hostname_uri = 'http://169.254.169.254/latest/meta-data/public-hostname'
@@ -1,11 +1,13 @@
1
1
  require 'pathname'
2
+ require_relative 'aws_resources'
2
3
 
3
4
  module Smash
4
5
  module CloudPowers
5
6
  module Storage
7
+ include Smash::CloudPowers::AwsResources
8
+
6
9
  def source_task(file)
7
10
  # TODO: better path management
8
- # byebug TODO: replace this full path business
9
11
  bucket = env('task storage')
10
12
  unless task_path(file).exist?
11
13
  objects = s3.list_objects(bucket: bucket).contents.select do |f|
@@ -23,13 +25,6 @@ module Smash
23
25
  end
24
26
  end
25
27
 
26
- def s3
27
- @s3 ||= Aws::S3::Client.new(
28
- region: region,
29
- credentials: Auth.creds
30
- )
31
- end
32
-
33
28
  def send_logs_to_s3
34
29
  File.open(log_file) do |file|
35
30
  s3.put_object(
@@ -1,3 +1,5 @@
1
+ require_relative '../helper'
2
+
1
3
  module Smash
2
4
  module CloudPowers
3
5
  module Synapse
@@ -1,6 +1,5 @@
1
- # require 'helper'
2
- # require 'queue'
3
- # require 'pipe'
1
+ require_relative 'queue'
2
+ require_relative 'pipe'
4
3
 
5
4
  module Smash
6
5
  module CloudPowers
@@ -1,3 +1,3 @@
1
1
  module CloudPowers
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_powers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Phillipps
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2016-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport-core-ext
@@ -171,7 +171,6 @@ files:
171
171
  - Rakefile
172
172
  - bin/console
173
173
  - bin/setup
174
- - cloud_powers-0.1.2.gem
175
174
  - cloud_powers.gemspec
176
175
  - lib/cloud_powers.rb
177
176
  - lib/cloud_powers/auth.rb
Binary file