Skip to content

Commit

Permalink
Fix display_status when resource deadline is exceeded for lantern res…
Browse files Browse the repository at this point in the history
…ource and gcp_vm
  • Loading branch information
var77 committed May 3, 2024
1 parent 0ca6ef5 commit 5295374
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 30 deletions.
8 changes: 8 additions & 0 deletions model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ def monitoring_interval
end
end

module DisplayStatusMethods
def set_failed_on_deadline
if display_state != "failed" && Page.from_tag_parts("Deadline", id, strand.prog, strand.stack.first["deadline_target"])
update(display_state: "failed")
end
end
end

if (level = Config.database_logger_level)
require "logger"
DB.loggers << Logger.new($stdout, level: level)
Expand Down
1 change: 1 addition & 0 deletions model/gcp_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class GcpVm < Sequel::Model

include ResourceMethods
include SemaphoreMethods
include DisplayStatusMethods
semaphore :destroy, :start_vm, :stop_vm, :update_storage, :update_size

include Authorization::HyperTagMethods
Expand Down
1 change: 1 addition & 0 deletions model/lantern/lantern_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LanternResource < Sequel::Model

include ResourceMethods
include SemaphoreMethods
include DisplayStatusMethods
include Authorization::HyperTagMethods
include Authorization::TaggableMethods

Expand Down
9 changes: 3 additions & 6 deletions prog/gcp_vm/nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def host
end

label def wait_create_vm
gcp_vm.set_failed_on_deadline
gcp_client = Hosting::GcpApis.new
vm = gcp_client.get_vm(gcp_vm.name, "#{gcp_vm.location}-a")
if vm["status"] == "RUNNING"
Expand All @@ -90,11 +91,12 @@ def host
end

label def start
register_deadline(:failed_provisioning, 10 * 60)
register_deadline(:wait, 10 * 60)
hop_create_vm
end

label def create_vm
gcp_vm.set_failed_on_deadline
gcp_client = Hosting::GcpApis.new
labels = frame["labels"]
gcp_client.create_vm(gcp_vm.name, "#{gcp_vm.location}-a", gcp_vm.boot_image, gcp_vm.public_key, gcp_vm.unix_user, "#{gcp_vm.family}-#{gcp_vm.cores}", gcp_vm.storage_size_gib, labels: labels)
Expand All @@ -108,11 +110,6 @@ def host
hop_wait_create_vm
end

label def failed_provisioning
gcp_vm.update(display_state: "failed")
hop_wait
end

label def wait_sshable
addr = gcp_vm.sshable.host

Expand Down
11 changes: 3 additions & 8 deletions prog/lantern/lantern_resource_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,13 @@ def before_run

label def start
nap 5 unless representative_server.vm.strand.label == "wait"
# TODO fix
# register_deadline(:failed_provisioning, 10 * 60)
register_deadline(:wait, 10 * 60)
# bud self.class, frame, :trigger_pg_current_xact_id_on_parent if lantern_resource.parent

# hop_wait_trigger_pg_current_xact_id_on_parent
hop_wait_servers
end

label def failed_provisioning
lantern_resource.update(display_state: "failed")
hop_wait
end

# TODO:: check why is this needed
# label def trigger_pg_current_xact_id_on_parent
# lantern_resource.parent.representative_server.run_query("SELECT pg_current_xact_id()")
Expand All @@ -138,6 +132,7 @@ def before_run
# end

label def wait_servers
lantern_resource.set_failed_on_deadline
nap 5 if servers.any? { _1.strand.label != "wait" }
hop_wait
end
Expand All @@ -148,7 +143,7 @@ def before_run
Prog::Lantern::LanternServerNexus.assemble(resource_id: lantern_resource.id, timeline_id: lantern_resource.timeline.id, timeline_access: "fetch")
end

if lantern_resource.display_state == "failed" && servers.any? { _1.strand.label == "wait" }
if lantern_resource.display_state == "failed"
lantern_resource.update(display_state: nil)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/coverage_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# rhizome (dataplane) and controlplane should have separate coverage reports.
# They will have different coverage suites in future.
add_filter "/rhizome"
add_filter "/misc"

# No need to check coverage for them
add_filter "/misc"
add_filter "/migrate/"
add_filter "/spec/"
add_filter "/db.rb"
Expand Down
16 changes: 16 additions & 0 deletions spec/model/display_status_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require_relative "../spec_helper"

RSpec.describe DisplayStatusMethods do
it "updates display_state to failed" do
[GcpVm, LanternResource].each do |klass|
instance = klass.new
expect(instance).to receive(:display_state).and_return("starting")
expect(instance).to receive(:strand).and_return(instance_double(Strand, prog: klass.name, stack: [{}])).at_least(:once)
expect(Page).to receive(:from_tag_parts).and_return(instance_double(Page))
expect(instance).to receive(:update).with(display_state: "failed")
expect { instance.set_failed_on_deadline }.not_to raise_error
end
end
end
12 changes: 4 additions & 8 deletions spec/prog/gcp_vm/nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

describe "#create_vm" do
it "Hops to create_vm on start" do
expect(nx).to receive(:register_deadline).with(:failed_provisioning, 10 * 60)
expect(nx).to receive(:register_deadline).with(:wait, 10 * 60)
expect { nx.start }.to hop("create_vm")
end

Expand All @@ -76,13 +76,15 @@
expect(nx.strand).to receive(:stack).and_return([frame]).at_least(:once)
expect(nx.strand).to receive(:modified!).with(:stack).at_least(:once)
expect(nx.strand).to receive(:save_changes).at_least(:once)
expect(gcp_vm).to receive(:strand).and_return(instance_double(Strand, prog: "GcpVm", stack: [{}])).at_least(:once)
expect { nx.create_vm }.to hop("wait_create_vm")
end

it "Naps 10 seconds if vm is not running" do
gcp_api = instance_double(Hosting::GcpApis)
expect(Hosting::GcpApis).to receive(:new).and_return(gcp_api)
expect(gcp_api).to receive(:get_vm).with("dummy-vm", "us-central1-a").and_return({"status" => "PROVISIONING"})
expect(gcp_vm).to receive(:strand).and_return(instance_double(Strand, prog: "GcpVm", stack: [{}])).at_least(:once)
expect { nx.wait_create_vm }.to nap(10)
end

Expand All @@ -91,6 +93,7 @@
expect(Hosting::GcpApis).to receive(:new).and_return(gcp_api)
expect(gcp_api).to receive(:get_vm).with("dummy-vm", "us-central1-a").and_return({"status" => "RUNNING"})
expect(gcp_api).to receive(:create_static_ipv4).with("dummy-vm", "us-central1").and_return({})
expect(gcp_vm).to receive(:strand).and_return(instance_double(Strand, prog: "GcpVm", stack: [{}])).at_least(:once)
expect { nx.wait_create_vm }.to hop("wait_ipv4")
end

Expand Down Expand Up @@ -276,12 +279,5 @@
expect(gcp_vm).to receive(:sshable).and_return(sshable)
expect(nx.host).to eq("1.1.1.1")
end

describe "#failed_provisioning" do
it "updates display state" do
expect(gcp_vm).to receive(:update).with(display_state: "failed")
expect { nx.failed_provisioning }.to hop("wait")
end
end
end
end
7 changes: 0 additions & 7 deletions spec/prog/lantern/lantern_resource_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,4 @@
expect { nx.destroy }.to exit({"msg" => "lantern resource is deleted"})
end
end

describe "#failed_provisioning" do
it "updates display state" do
expect(lantern_resource).to receive(:update).with(display_state: "failed")
expect { nx.failed_provisioning }.to hop("wait")
end
end
end

0 comments on commit 5295374

Please sign in to comment.