Skip to content

Commit

Permalink
rm legacy methods
Browse files Browse the repository at this point in the history
  • Loading branch information
terrywbrady committed Nov 1, 2024
1 parent 1a382de commit af62734
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 259 deletions.
13 changes: 0 additions & 13 deletions src/main/ruby/legacy_test.rb

This file was deleted.

67 changes: 1 addition & 66 deletions src/main/ruby/lib/merritt_zk_access.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
105 changes: 0 additions & 105 deletions src/main/ruby/lib/merritt_zk_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
75 changes: 0 additions & 75 deletions src/main/ruby/lib/merritt_zk_queue_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit af62734

Please sign in to comment.