quandl_sandbox 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 191b24f362d9b5c0144dd44ffcf008ae39d84cad
4
- data.tar.gz: 9c33e859a5685e26b2d28e2f0b95d5b5d967b697
3
+ metadata.gz: 6e0dc5f353591da55a850a0076ba20382193fef0
4
+ data.tar.gz: e1089e784ea2d9e405f6fe10b4fe3329b0b4c095
5
5
  SHA512:
6
- metadata.gz: 8b309b71cccc432a123e7025a4a0d5a7a8217d84f1d62ea9cdb41e1f4b23b98e031038722e92e3a245490df825c926dfa293aabb5758a05193539bc772b5d921
7
- data.tar.gz: 6d802be7e7936959ef883453ed55a1e868ea020c63197f59d144103a8624d2cd154aa58ffabbe1c94c0608404be835c216ca327b02fa12f27991ad1673eb3078
6
+ metadata.gz: 8e318b6cb4718e4bea0f2bd2e802772cb179cfedce2a1f21ef58ed6f2fe7d8bcdc715c72043e6dce914b21a6ae22057d3b74798aba816d59646b85e16af1e90c
7
+ data.tar.gz: 9d1989f9164b8252a74c83d22ac348702a37cc0bc9938af30346d7d9528b1cf5e3e7775a9eb0ebdec8cdb0bf5c4267e478023561a41ad5d65c4524545f5d57cd
@@ -9,7 +9,7 @@ class Quandl::Sandbox::Dataset
9
9
  end
10
10
 
11
11
  def initialize(output)
12
- rows = output.to_s.rstrip.split("\n")
12
+ rows = output.split("\n")
13
13
  self.full_code = rows.shift.strip
14
14
  self.name = rows.shift.strip
15
15
  self.description = rows.shift.strip
@@ -16,7 +16,7 @@ class Quandl::Sandbox::EC2
16
16
  end
17
17
 
18
18
  def instances
19
- interface.instances.filter('subnet-id', Sandbox.configuration.subnet_id )
19
+ interface.instances.filter('subnet-id', Quandl::Sandbox.configuration.subnet_id )
20
20
  end
21
21
 
22
22
  def gateway_reset!
@@ -31,17 +31,17 @@ class Quandl::Sandbox::EC2
31
31
  end
32
32
 
33
33
  def gateway_user
34
- @gateway_user ||= Sandbox.configuration.ssh_gateway.split("@").first
34
+ @gateway_user ||= Quandl::Sandbox.configuration.ssh_gateway.split("@").first
35
35
  end
36
36
 
37
37
  def gateway_host
38
- @gateway_host ||= Sandbox.configuration.ssh_gateway.split("@").last
38
+ @gateway_host ||= Quandl::Sandbox.configuration.ssh_gateway.split("@").last
39
39
  end
40
40
 
41
41
  def interface
42
42
  @interface ||= AWS::EC2.new(
43
- access_key_id: Sandbox.configuration.aws_access_key_id,
44
- secret_access_key: Sandbox.configuration.aws_secret_access_key)
43
+ access_key_id: Quandl::Sandbox.configuration.aws_access_key_id,
44
+ secret_access_key: Quandl::Sandbox.configuration.aws_secret_access_key)
45
45
  end
46
46
 
47
47
  end
@@ -13,8 +13,6 @@ class Quandl::Sandbox::Job
13
13
  end
14
14
 
15
15
  def execute
16
- # ensure the ssh daemon has started
17
- server.ensure_connection_established!
18
16
  # run commands that need to happen before importer
19
17
  server.exec( repository.script.before_execute )
20
18
  # execute importer
@@ -21,7 +21,7 @@ module Quandl::Sandbox::Server::Instance
21
21
 
22
22
  def find(uid)
23
23
  # lookup instance
24
- instance = Sandbox::EC2.find(uid)
24
+ instance = Quandl::Sandbox::EC2.find(uid)
25
25
  # build server given instance
26
26
  instance.present? ? self.new( instance: instance ) : nil
27
27
  end
@@ -33,7 +33,7 @@ module Quandl::Sandbox::Server::Instance
33
33
  end
34
34
 
35
35
  def delete(id)
36
- i = Sandbox::EC2.find(id)
36
+ i = Quandl::Sandbox::EC2.find(id)
37
37
  i.present? ? i.delete : false
38
38
  end
39
39
 
@@ -61,9 +61,6 @@ module Quandl::Sandbox::Server::Instance
61
61
  end
62
62
 
63
63
  def launch!
64
- # only new servers can be launched
65
- return false unless new_record
66
- # create, tag, wait
67
64
  self.instance = create_instance!
68
65
  add_tags_to_instance
69
66
  end
@@ -92,7 +89,7 @@ module Quandl::Sandbox::Server::Instance
92
89
  end
93
90
 
94
91
  def create_instance!
95
- Sandbox::EC2.instances.create({
92
+ Quandl::Sandbox::EC2.instances.create({
96
93
  image_id: image,
97
94
  subnet_id: subnet_id,
98
95
  availability_zone: availability_zone,
@@ -2,8 +2,21 @@ module Quandl::Sandbox::Server::SSH
2
2
 
3
3
  extend ActiveSupport::Concern
4
4
 
5
- def ensure_connection_established!
6
- Sandbox::EC2.auto_retry(3){ exec("hostname") }
5
+ def launch!
6
+ # only new servers can be launched
7
+ return false unless new_record
8
+ # launch instance
9
+ super if defined?(super)
10
+ # wait for sshd to start on server
11
+ await_sshd_uninterruptedly
12
+ end
13
+
14
+ def await_sshd_uninterruptedly
15
+ t1 = Time.now
16
+ Quandl::Logger.debug("#{instance_id}: await_sshd_uninterruptedly")
17
+ @await_sshd_uninterruptedly ||= Quandl::Sandbox::EC2.auto_retry(3){ exec("hostname") }
18
+ Quandl::Logger.debug "#{instance_id}: await_sshd_uninterruptedly finished (#{t1.elapsed_ms})"
19
+ @await_sshd_uninterruptedly
7
20
  end
8
21
 
9
22
  def upload!(local_path, remote_path="/home/ubuntu/")
@@ -44,21 +57,21 @@ module Quandl::Sandbox::Server::SSH
44
57
  end
45
58
  channel.wait
46
59
  end
60
+ result[:stdout] = result[:stdout].to_s.strip.rstrip
61
+ result[:stderr] = result[:stderr].to_s.strip.rstrip
47
62
  result
48
63
  end
49
64
 
50
65
  def ssh(&block)
51
- # wait for server to be ready
66
+ # wait for server to launch
52
67
  await_instance_uninterruptedly unless running?
53
- # establish connection
54
- Quandl::Logger.debug "#{instance_id}: Waiting for sshd to start ... "
55
68
  # execute block through tunnel
56
69
  output = nil
57
- Sandbox::EC2.gateway.ssh( private_ip_address, ssh_user,
58
- key_data: Sandbox.configuration.key_data, keys_only: true ) do |ssh|
70
+ Quandl::Sandbox::EC2.gateway.ssh( private_ip_address, ssh_user,
71
+ key_data: Quandl::Sandbox.configuration.key_data, keys_only: true ) do |ssh|
59
72
  output = block.call(ssh)
60
73
  end
61
74
  output
62
75
  end
63
-
76
+
64
77
  end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Sandbox
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -23,7 +23,6 @@ describe Quandl::Sandbox::Job do
23
23
  its('data.count'){ should eq 10 }
24
24
  its('data.first.count'){ should eq 4 }
25
25
  end
26
-
27
-
26
+
28
27
  end
29
28
  end
@@ -51,7 +51,7 @@ describe Quandl::Sandbox::Server do
51
51
  describe "#exec" do
52
52
  it "should get the hostname" do
53
53
  # get internal_ip through exec('hostname')
54
- internal_ip = subject.exec('hostname').rstrip.split('-')[1..-1].join('.')
54
+ internal_ip = subject.exec('hostname')[:stdout].split('-')[1..-1].join('.')
55
55
  # compare against private ip address
56
56
  subject.private_ip_address.should eq internal_ip
57
57
  end
@@ -28,11 +28,12 @@ RSpec.configure do |config|
28
28
  end
29
29
 
30
30
  def stubbed_job_output
31
- 4.times.collect do |i|
31
+ { stdout: 4.times.collect do |i|
32
32
  "QUANDL_SANDBOX_TEST/DATASET_#{i}\n" +
33
33
  "Test Dataset #{i}\n" +
34
34
  "Description of the dataset #{i}\n" +
35
35
  "Date, High, Low, Average\n" +
36
36
  "#{Quandl::Fabricate::Data.rand(rows: 10, columns: 3).to_csv}}"
37
37
  end.join("----\n")
38
+ }
38
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_sandbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hilscher