Skip to content

Commit

Permalink
accept resource name when creating logical replica
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Nov 21, 2024
1 parent bbc0f59 commit 3834c13
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions model/lantern/lantern_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def mark_switchover_finish
representative_server.run_query("UPDATE _ldb_switchover_info SET finished_at=NOW()")
end

def create_logical_replica(lantern_version: nil, extras_version: nil, minor_version: nil, pg_upgrade: nil)
def create_logical_replica(resource_name: nil, lantern_version: nil, extras_version: nil, minor_version: nil, pg_upgrade: nil)
# TODO::
# 1. If new database will be created during logical replication it won't be added automatically
ubid = LanternResource.generate_ubid
Expand All @@ -265,7 +265,7 @@ def create_logical_replica(lantern_version: nil, extras_version: nil, minor_vers
Prog::Lantern::LanternResourceNexus.assemble(
project_id: project_id,
location: location,
name: "#{name}-#{Time.now.to_i}",
name: resource_name || "#{name}-#{Time.now.to_i}",
label: "#{label}-logical",
ubid: ubid,
target_vm_size: representative_server.target_vm_size,
Expand Down
2 changes: 1 addition & 1 deletion prog/lantern/lantern_resource_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def before_run

label def finish_take_over
# update display_states
lantern_resource.update(display_state: nil)
lantern_resource.update(display_state: nil, label: lantern_resource.parent.label)
lantern_resource.parent.update(display_state: nil, rollback_target: lantern_resource.id)

# remove fork association so parent can be deleted
Expand Down
4 changes: 3 additions & 1 deletion routes/api/project/location/lantern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ class CloverApi
extras_version = (r.params["extras_version"] && r.params["extras_version"].empty?) ? nil : r.params["extras_version"]
minor_version = (r.params["minor_version"] && r.params["minor_version"].empty?) ? nil : r.params["minor_version"]
pg_upgrade = (r.params["pg_upgrade"] && r.params["pg_upgrade"].empty?) ? nil : r.params["pg_upgrade"]
resource_name = (r.params["name"] && r.params["name"].empty?) ? nil : r.params["name"]
st = pg.create_logical_replica(
lantern_version: lantern_version,
extras_version: extras_version,
minor_version: minor_version,
pg_upgrade: pg_upgrade
pg_upgrade: pg_upgrade,
resource_name: resource_name
)
replica = LanternResource[st.id]
serialize(replica, :detailed)
Expand Down
7 changes: 4 additions & 3 deletions spec/model/lantern/lantern_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
logical_replication: true,
lantern_version: representative_server.lantern_version,
extras_version: representative_server.extras_version,
minor_version: representative_server.minor_version
minor_version: representative_server.minor_version,
))
expect { lantern_resource.create_logical_replica }.not_to raise_error
end
Expand All @@ -308,9 +308,10 @@
logical_replication: true,
lantern_version: "0.3.0",
extras_version: "0.2.6",
minor_version: "1"
minor_version: "1",
name: "test"
))
expect { lantern_resource.create_logical_replica(lantern_version: "0.3.0", extras_version: "0.2.6", minor_version: "1") }.not_to raise_error
expect { lantern_resource.create_logical_replica(resource_name: "test", lantern_version: "0.3.0", extras_version: "0.2.6", minor_version: "1") }.not_to raise_error
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/prog/lantern/lantern_resource_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,12 @@

describe "#finish_take_over" do
it "updates display states, and removes fork association" do
parent = instance_double(LanternResource)
parent = instance_double(LanternResource, label: "test")
timeline = instance_double(LanternTimeline)

expect(lantern_resource).to receive(:parent).and_return(parent).at_least(:once)

expect(lantern_resource).to receive(:update).with(display_state: nil)
expect(lantern_resource).to receive(:update).with(display_state: nil, label: parent.label)
expect(parent).to receive(:update).with(display_state: nil, rollback_target: lantern_resource.id)

expect(lantern_resource).to receive(:update).with(parent_id: nil)
Expand Down
9 changes: 6 additions & 3 deletions spec/routes/api/project/location/lantern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,11 @@
lantern_version: nil,
extras_version: nil,
minor_version: nil,
pg_upgrade: nil
pg_upgrade: nil,
resource_name: nil
).and_return(instance_double(Strand, id: pg.id))

post "/api/project/#{project.ubid}/location/#{pg.location}/lantern/instance-1/logical-replica", {lantern_version: "", extras_version: "", minor_version: "", pg_upgrade: ""}
post "/api/project/#{project.ubid}/location/#{pg.location}/lantern/instance-1/logical-replica", {lantern_version: "", extras_version: "", minor_version: "", pg_upgrade: "", name: ""}
expect(last_response.status).to eq(200)
expect(JSON.parse(last_response.body)["id"]).to eq(pg.id)
expect(JSON.parse(last_response.body)["name"]).to eq(pg.name)
Expand All @@ -351,14 +352,16 @@
lantern_version: "0.5.0",
extras_version: "0.5.0",
minor_version: "1",
resource_name: "test",
pg_upgrade: {"lantern_version" => "0.6.0", "extras_version" => "0.6.0", "minor_version" => "1", "pg_version" => "17"}
).and_return(instance_double(Strand, id: pg.id))

post "/api/project/#{project.ubid}/location/#{pg.location}/lantern/instance-1/logical-replica", {
lantern_version: "0.5.0",
extras_version: "0.5.0",
minor_version: "1",
pg_upgrade: {"lantern_version" => "0.6.0", "extras_version" => "0.6.0", "minor_version" => "1", "pg_version" => 17}
pg_upgrade: {"lantern_version" => "0.6.0", "extras_version" => "0.6.0", "minor_version" => "1", "pg_version" => 17},
name: "test"
}
expect(last_response.status).to eq(200)
end
Expand Down

0 comments on commit 3834c13

Please sign in to comment.