cuboid 0.2.11 → 0.2.12

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
  SHA256:
3
- metadata.gz: c89df73b039d72a4e7ba39d3bd4061ccb6a7725db1283499a7f0f267b2b871b2
4
- data.tar.gz: c9e8eb873600484f75d0ef20acb7e97bdf77275dc494c204fd6acea1c0164cce
3
+ metadata.gz: 1c60a30f1e751d2c66d99373ad8f928e0ba903ee49cfc2d3af4f9913cf77e35e
4
+ data.tar.gz: 39fb0c5585c7f164df0fbbf378aebd8347a9f6037cc5e68f0cc3cf24166f277e
5
5
  SHA512:
6
- metadata.gz: 25a3cb88bc17702e1f6a1f5fd7a53ef3505a61100978449cf19430434ca03ea050b774c798b097b2d4506a825953d86b7ed1fe121324202dc580594a0701ae35
7
- data.tar.gz: 7492bd6c97cffaff9657584a2c960f62af6f83ef960fbbf6115a8e40ff95acd79833bc9f0a9b8ab8e657952c05cb6ae132f032a3a7bd256a90880c5f5266791b
6
+ metadata.gz: 978048c874d5735f231adecf85777d9a091709203616bc30ca37d58d98a0e93e42ccf4d8d88d1454367118a09b94ac249cf79fccc37027ba280e4f097fde7e73
7
+ data.tar.gz: a2304bb473bce181b003a0d173ac6920ad1dbb8b03eb695befff39eb0d559c4a1cb3b057dfd19b10093396d23b7a7f20f4eccfa9ba549eacb1dc37f977719e22
@@ -32,6 +32,23 @@ module Instances
32
32
  json id: instance.token
33
33
  end
34
34
 
35
+ app.post '/instances/restore' do
36
+ max_utilization! if !agent && System.max_utilization?
37
+
38
+ options = ::JSON.load( request.body.read ) || {}
39
+
40
+ instance = get_instance
41
+ max_utilization! if !instance
42
+
43
+ handle_error proc { instance.shutdown } do
44
+ instance.restore!( options['session'] )
45
+ end
46
+
47
+ instances[instance.token] = instance
48
+
49
+ json id: instance.token
50
+ end
51
+
35
52
  # Progress
36
53
  app.get '/instances/:instance' do
37
54
  ensure_instance!
@@ -106,6 +123,14 @@ module Instances
106
123
  end
107
124
  end
108
125
 
126
+ app.put '/instances/:instance/abort' do
127
+ ensure_instance!
128
+
129
+ instance_for( params[:instance] ) do |instance|
130
+ json instance.abort!
131
+ end
132
+ end
133
+
109
134
  # Abort/shutdown
110
135
  app.delete '/instances/:instance' do
111
136
  ensure_instance!
@@ -44,7 +44,7 @@ class ApplicationWrapper
44
44
  # `true` If the system is scanning, `false` if {#run} hasn't been called
45
45
  # yet or if the scan has finished.
46
46
  def busy?
47
- ![:ready, :done, :suspended].include?( @application.status ) &&
47
+ ![:ready, :done, :suspended, :aborted].include?( @application.status ) &&
48
48
  !!@extended_running
49
49
  end
50
50
 
@@ -58,6 +58,7 @@ class ApplicationWrapper
58
58
  # Start the scan -- we can't block the RPC server so we're using a Thread.
59
59
  Thread.new do
60
60
  @application.run
61
+ @extended_running = false
61
62
  end
62
63
 
63
64
  true
@@ -66,10 +67,10 @@ class ApplicationWrapper
66
67
  def clean_up
67
68
  return false if @rpc_cleaned_up
68
69
 
70
+ @application.clean_up
71
+
69
72
  @rpc_cleaned_up = true
70
73
  @extended_running = false
71
-
72
- @application.clean_up
73
74
  end
74
75
 
75
76
  # @param [Integer] starting_line
@@ -109,7 +110,7 @@ class ApplicationWrapper
109
110
 
110
111
  data = {
111
112
  status: status,
112
- busy: running?,
113
+ busy: @extended_running,
113
114
  application: @application.class.to_s,
114
115
  seed: Utilities.random_seed,
115
116
  agent_url: Cuboid::Options.agent.url,
@@ -103,8 +103,15 @@ class Instance
103
103
  # @see #suspend
104
104
  # @see #snapshot_path
105
105
  def restore!( snapshot )
106
+ # If the instance isn't clean bail out now.
107
+ return false if busy? || @called
108
+
109
+ @called = @run_initializing = true
110
+
106
111
  Thread.new do
107
- @application.restore!( snapshot ).run
112
+ @application.restore!( snapshot )
113
+ @application.run
114
+ @run_initializing = false
108
115
  end
109
116
 
110
117
  true
@@ -140,6 +140,7 @@ class Application
140
140
  def aborted
141
141
  @abort = false
142
142
  @status = :aborted
143
+ @running = false
143
144
  nil
144
145
  end
145
146
 
data/lib/version CHANGED
@@ -1 +1 @@
1
- 0.2.11
1
+ 0.2.12
@@ -251,6 +251,26 @@ describe Cuboid::Rest::Server do
251
251
  end
252
252
  end
253
253
 
254
+ describe 'POST /instances/restore' do
255
+ let(:tpl_url) { '/instances/restore' }
256
+
257
+ it 'creates an instance from a restores session'
258
+
259
+ context 'when given invalid options' do
260
+ it 'returns a 500'
261
+
262
+ it 'does not list the instance on the index'
263
+ end
264
+
265
+ context 'when the system is at max utilization' do
266
+ it 'returns a 503'
267
+ end
268
+
269
+ context 'when a Agent has been set' do
270
+ it 'uses it'
271
+ end
272
+ end
273
+
254
274
  describe 'GET /instances/:instance' do
255
275
  let(:tpl_url) { '/instances/%s' }
256
276
 
@@ -567,7 +587,59 @@ describe Cuboid::Rest::Server do
567
587
  end
568
588
  end
569
589
  end
570
-
590
+
591
+ describe 'PUT /instances/:instance/abort' do
592
+ let(:tpl_url) { '/instances/%s/abort' }
593
+
594
+ before do
595
+ @id = create_instance
596
+ end
597
+
598
+ it 'aborts the instance' do
599
+ put url
600
+ expect(response_code).to eq 200
601
+
602
+ get "/instances/#{id}"
603
+ expect(['aborting', 'aborted']).to include response_data['status']
604
+ end
605
+
606
+ context 'when passed a non-existent id' do
607
+ let(:id) { non_existent_id }
608
+
609
+ it 'returns 404' do
610
+ put url
611
+ expect(response_code).to eq 404
612
+ end
613
+ end
614
+
615
+ context 'when the instance is from the Scheduler' do
616
+ before do
617
+ put '/scheduler/url', scheduler.url
618
+ end
619
+
620
+ it 'includes it' do
621
+ @id = scheduler.push( options )
622
+ sleep 0.1 while scheduler.running.empty?
623
+
624
+ put url
625
+ expect(response_code).to eq 200
626
+
627
+ get "/instances/#{id}"
628
+ expect(['aborting', 'aborted']).to include response_data['status']
629
+ end
630
+
631
+ context 'when the instance completes' do
632
+ it 'is removed' do
633
+ @id = scheduler.push( options )
634
+ sleep 0.1 while scheduler.completed.empty?
635
+
636
+ put url
637
+ expect(response_code).to be 404
638
+ end
639
+ end
640
+ end
641
+ end
642
+
571
643
  describe 'DELETE /instances/:instance' do
572
644
  let(:tpl_url) { '/instances/%s' }
573
645
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuboid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-03 00:00:00.000000000 Z
11
+ date: 2025-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print