From af62734c0587ed88371299318314e17d357a9a25 Mon Sep 17 00:00:00 2001 From: Terry Brady Date: Fri, 1 Nov 2024 16:19:52 -0700 Subject: [PATCH] rm legacy methods --- src/main/ruby/legacy_test.rb | 13 --- src/main/ruby/lib/merritt_zk_access.rb | 67 +------------ src/main/ruby/lib/merritt_zk_job.rb | 105 --------------------- src/main/ruby/lib/merritt_zk_queue_item.rb | 75 --------------- 4 files changed, 1 insertion(+), 259 deletions(-) delete mode 100644 src/main/ruby/legacy_test.rb diff --git a/src/main/ruby/legacy_test.rb b/src/main/ruby/legacy_test.rb deleted file mode 100644 index dcf4db6..0000000 --- a/src/main/ruby/legacy_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# test the ability to read legacy ingest queue ZK nodes -require_relative 'lib/merritt_zk' -require 'zk' - -puts 'testing mrt-zk gem load' -# run the following from the target env -# export ZKCONN=`get_ssm_value_by_name inventory/zoo/queueService` -zk = ZK.new(ENV.fetch('ZKCONN', 'localhost:8084')) -MerrittZK::LegacyIngestJob.list_jobs_as_json(zk).each do |j| - puts "#{j.fetch(:id, '')}: #{j.fetch(:title, '')} #{j.fetch(:status, '')}\n\t#{j.fetch(:date, '')} " -end diff --git a/src/main/ruby/lib/merritt_zk_access.rb b/src/main/ruby/lib/merritt_zk_access.rb index 9a15ace..1b53a6b 100644 --- a/src/main/ruby/lib/merritt_zk_access.rb +++ b/src/main/ruby/lib/merritt_zk_access.rb @@ -72,7 +72,6 @@ def delete(zk) ## # List jobs as a json object that will be consumed by the admin tool. - # This is a transitional representation that can be compatible with legacy job listings. def self.list_jobs_as_json(zk) jobs = [] [SMALL, LARGE].each do |queue| @@ -94,68 +93,4 @@ def self.list_jobs_as_json(zk) jobs end end - - ## - # Legacy Merritt Access Job record. - # This class will be removed after the migration is complete - class LegacyAccessJob < LegacyItem - def initialize(dir, cp) - @dir = dir - super(cp) - end - - attr_reader :dir - - def json? - true - end - - def payload_object - payload = super - payload[:queueNode] = dir - payload - end - - ## - # List legacy access jobs as a json object that will be consumed by the admin tool. - def self.list_jobs_as_json(zk) - jobs = [] - if zk.exists?(LargeLegacyAccessJob::DIR) - zk.children(LargeLegacyAccessJob::DIR).sort.each do |cp| - lj = LargeLegacyAccessJob.new(cp) - lj.load(zk) - jobs.append(lj.payload_object) - end - end - - if zk.exists?(SmallLegacyAccessJob::DIR) - zk.children(SmallLegacyAccessJob::DIR).sort.each do |cp| - lj = SmallLegacyAccessJob.new(cp) - lj.load(zk) - jobs.append(lj.payload_object) - end - end - jobs - end - end - - ## - # Legacy Merritt Small Access Job record. - # This class will be removed after the migration is complete - class SmallLegacyAccessJob < LegacyAccessJob - DIR = '/accessSmall.1' - def initialize(cp) - super(DIR, cp) - end - end - - ## - # Legacy Merritt Large Access Job record. - # This class will be removed after the migration is complete - class LargeLegacyAccessJob < LegacyAccessJob - DIR = '/accessLarge.1' - def initialize(cp) - super(DIR, cp) - end - end -end +end \ No newline at end of file diff --git a/src/main/ruby/lib/merritt_zk_job.rb b/src/main/ruby/lib/merritt_zk_job.rb index f90836d..61ae498 100644 --- a/src/main/ruby/lib/merritt_zk_job.rb +++ b/src/main/ruby/lib/merritt_zk_job.rb @@ -199,7 +199,6 @@ def delete(zk) ## # List jobs as a json object that will be consumed by the admin tool. - # This is a transitional representation that can be compatible with legacy job listings. def self.list_jobs_as_json(zk) jobs = [] zk.children(DIR).sort.each do |cp| @@ -256,108 +255,4 @@ def title data_prop('title', '') end end - - ## - # Legacy Merritt Ingest Job record. - # This class will be removed after the migration is complete - class LegacyIngestJob < LegacyItem - DIR = '/ingest' - def dir - DIR - end - - def submitter - @payload.fetch(:submitter, '') - end - - def creator - @payload.fetch(:creator, '') - end - - def profile - @payload.fetch(:profile, '') - end - - def response_form - @payload.fetch(:responseForm, '') - end - - def filename - @payload.fetch(:filename, '') - end - - def udpate - @payload.fetch(:update, false) - end - - def type - @payload.fetch(:type, '') - end - - def title - @payload.fetch(:title, '') - end - - def bid - @payload.fetch(:bid, '') - end - - def priority - @payload.fetch(:priority, 0) - end - - def space_needed - @payload.fetch(:space_needed, 0) - end - - ## - # List legacy ingest jobs as a json object that will be consumed by the admin tool. - def self.list_jobs_as_json(zk) - jobs = [] - return jobs unless zk.exists?(DIR) - - zk.children(DIR).sort.each do |cp| - lj = LegacyIngestJob.new(cp) - lj.load(zk) - jobs.append(lj.payload_object) - end - jobs - end - end - - ## - # Legacy Merritt Inventory Job record. - # This class will be removed after the migration is complete - class LegacyInventoryJob < LegacyItem - DIR = '/mrt.inventory.full' - def dir - DIR - end - - def json? - false - end - - def payload_object - payload = super - m = /(http:[^<]*)/.match(payload[:payload]) - payload[:queueNode] = DIR - payload[:manifestURL] = m[1] - payload - end - - ## - # List legacy inventory jobs as a json object that will be consumed by the admin tool. - def self.list_jobs_as_json(zk) - jobs = [] - return jobs unless zk.exists?(DIR) - - zk.children(DIR).sort.each do |cp| - lj = LegacyInventoryJob.new(cp) - lj.load(zk) - jobs.append(lj.payload_object) - end - jobs - end - end end diff --git a/src/main/ruby/lib/merritt_zk_queue_item.rb b/src/main/ruby/lib/merritt_zk_queue_item.rb index f8b61b2..c64dd37 100644 --- a/src/main/ruby/lib/merritt_zk_queue_item.rb +++ b/src/main/ruby/lib/merritt_zk_queue_item.rb @@ -152,79 +152,4 @@ def data_prop(_prop, defval) end end - ## - # Base class for Legacy Merritt ZooKeeper Queue Items. - # This class will be removed after the migration is successfully completed - class LegacyItem - DIR = '/na' - STATUS_VALS = %w[Pending Consumed Deleted Failed Completed Held].freeze - def dir - DIR - end - - def path - "#{dir}/#{id}" - end - - def status_vals - STATUS_VALS - end - - def initialize(id) - @id = id - @data = {} - @bytes = [] - @payload = {} - end - - def load(zk) - arr = zk.get("#{dir}/#{@id}") - return if arr.nil? - - payload = arr[0] - @bytes = payload.nil? ? [] : payload.bytes - @payload = payload_object - end - - def status_byte - @bytes.empty? ? 0 : @bytes[0] - end - - def status_name - return 'NA' if status_byte > status_vals.length - - status_vals[status_byte] - end - - def json? - true - end - - def time - return nil if @bytes.length < 9 - - # https://stackoverflow.com/a/68855488/3846548 - t = @bytes[1..8].inject(0) { |m, b| (m << 8) + b } - Time.at(t / 1000) - end - - def payload_text - return '' if @bytes.length < 10 - - @bytes[9..].pack('c*') - end - - def payload_object - json = { payload: payload_text } - json = JSON.parse(payload_text, symbolize_names: true) if json? - json[:queueNode] = dir - json[:id] = @id - json[:date] = time.to_s - json[:status] = status_name - json[:path] = path - json - end - - attr_reader :id - end end