Skip to content

Instantly share code, notes, and snippets.

@vholer
Created June 5, 2017 10:30
Show Gist options
  • Save vholer/e9480efccf395990e7223ba3d2f7aa8a to your computer and use it in GitHub Desktop.
Save vholer/e9480efccf395990e7223ba3d2f7aa8a to your computer and use it in GitHub Desktop.
if !ONE_LOCATION
LOG_LOCATION = "/var/log/one"
else
LOG_LOCATION = ONE_LOCATION + "/var"
end
LOG = LOG_LOCATION + "/onedb-fsck.log"
require 'nokogiri'
module OneDBPatch
VERSION = ["4.90.0", "5.2.0"]
def is_hot_patch(ops)
return false
end
def check_db_version(ops)
db_version = read_db_version()
unless VERSION.include?(db_version[:version])
raise <<-EOT
Version mismatch: patch file is for version
Shared: #{VERSION}
Current database is version
Shared: #{db_version[:version]}
EOT
end
end
def patch(ops)
init_log_time()
puts "This patch will clean the MarketPlace Appliances with MARKET_MAD=one"
@db.transaction do
@db.fetch("SELECT * FROM marketplace_pool") do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c| c.default_xml.noblanks }
# only marketplaces with the MAD "one"
mad = doc.xpath("/MARKETPLACE/MARKET_MAD")
next if mad.nil? or (mad.text != 'one')
# clean all referenced appliances
doc.xpath("/MARKETPLACE/MARKETPLACEAPPS/ID").each do |app|
oid = app.text.to_i
puts "Deleting appliance OID=#{oid}"
@db[:marketplaceapp_pool].where(:oid => oid).delete
# remove app. reference from XML
app.remove
end
@db[:marketplace_pool].where(:oid => row[:oid]).update(
:body => doc.root.to_s)
end
end
log_time()
return true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment