Right now, we define semaphores in both the model and prog, but they are generally the same. We can retrieve the list of semaphores from the subject in prog. We can still define semaphores in prog if it doesn't have a subject, like in Prog::Test::HetznerServer.
86 lines
2.0 KiB
Ruby
86 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../../lib/util"
|
|
|
|
class Prog::Minio::MinioPoolNexus < Prog::Base
|
|
subject_is :minio_pool
|
|
|
|
def self.assemble(cluster_id, start_index, server_count, drive_count, storage_size_gib, vm_size)
|
|
unless MinioCluster[cluster_id]
|
|
fail "No existing cluster"
|
|
end
|
|
|
|
DB.transaction do
|
|
ubid = MinioPool.generate_ubid
|
|
|
|
minio_pool = MinioPool.create(
|
|
cluster_id: cluster_id,
|
|
start_index: start_index,
|
|
server_count: server_count,
|
|
drive_count: drive_count,
|
|
storage_size_gib: storage_size_gib,
|
|
vm_size: vm_size
|
|
) { _1.id = ubid.to_uuid }
|
|
|
|
minio_pool.server_count.times do |i|
|
|
Prog::Minio::MinioServerNexus.assemble(minio_pool.id, minio_pool.start_index + i)
|
|
end
|
|
Strand.create(prog: "Minio::MinioPoolNexus", label: "wait_servers") { _1.id = minio_pool.id }
|
|
end
|
|
end
|
|
|
|
def self.assemble_additional_pool(cluster_id, server_count, drive_count, storage_size_gib, vm_size)
|
|
DB.transaction do
|
|
st = assemble(cluster_id, MinioCluster[cluster_id]&.server_count, server_count, drive_count, storage_size_gib, vm_size)
|
|
st.subject.incr_add_additional_pool
|
|
st
|
|
end
|
|
end
|
|
|
|
def before_run
|
|
when_destroy_set? do
|
|
unless ["destroy", "wait_servers_destroyed"].include?(strand.label)
|
|
hop_destroy
|
|
end
|
|
end
|
|
end
|
|
|
|
def cluster
|
|
@cluster ||= minio_pool.cluster
|
|
end
|
|
|
|
label def wait_servers
|
|
if minio_pool.servers.all? { _1.strand.label == "wait" }
|
|
when_add_additional_pool_set? do
|
|
decr_add_additional_pool
|
|
cluster.incr_reconfigure
|
|
end
|
|
|
|
hop_wait
|
|
end
|
|
|
|
nap 5
|
|
end
|
|
|
|
label def wait
|
|
nap 30
|
|
end
|
|
|
|
label def destroy
|
|
register_deadline(nil, 10 * 60)
|
|
decr_destroy
|
|
DB.transaction do
|
|
minio_pool.servers.each(&:incr_destroy)
|
|
end
|
|
|
|
hop_wait_servers_destroyed
|
|
end
|
|
|
|
label def wait_servers_destroyed
|
|
nap 5 unless minio_pool.servers.empty?
|
|
|
|
minio_pool.destroy
|
|
pop "pool destroyed"
|
|
end
|
|
end
|