Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B #4212: add function to read table encoding #4218

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions src/onedb/fsck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,6 @@ def federated_tables
FEDERATED_TABLES
end

def nokogiri_doc(body, table = nil)
nk_enconding = NOKOGIRI_ENCODING

unless table.nil?
nk_enconding = get_table_enconding(table)
end

Nokogiri::XML(body, nil, nk_enconding) do |c|
c.default_xml.noblanks
end
end

def add_element(elem, name)
return elem.add_child(elem.document.create_element(name))
end
Expand Down Expand Up @@ -626,7 +614,7 @@ def get_image_from_id(id)
# No image found, so unable to get image TYPE
return nil if row.nil?

image = Nokogiri::XML(row[:body], nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
image = nokogiri_doc(row[:body], 'image_pool')
return image
end

Expand Down Expand Up @@ -658,7 +646,7 @@ def get_image_from_name(disk, template_uid)
# No image found, so unable to get image TYPE
return nil if row.nil?

image = Nokogiri::XML(row[:body], nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
image = nokogiri_doc(row[:body], 'image_pool')

return image
end
Expand Down
4 changes: 1 addition & 3 deletions src/onedb/fsck/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def check_group

@db.fetch('SELECT oid,body from group_pool') do |row|
gid = row[:oid]
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'group_pool')

users_elem = doc.root.at_xpath('USERS')
users_new_elem = doc.create_element('USERS')
Expand Down
2 changes: 1 addition & 1 deletion src/onedb/fsck/marketplace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def check_marketplace
# DATA: check marketplace pool
@db.fetch("SELECT oid,body FROM marketplace_pool") do |row|
market_id = row[:oid]
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'marketplace_pool')

apps_elem = doc.root.at_xpath("MARKETPLACEAPPS")
apps_elem.remove if !apps_elem.nil?
Expand Down
21 changes: 6 additions & 15 deletions src/onedb/fsck/quotas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def check_fix_quotas(resource, type = 'normal')
query = "SELECT * FROM old_#{table} WHERE #{resource}_oid>0"

@db.fetch(query) do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], "old_#{table}")

# resource[0] = u if user, g if group
id_field = "#{resource[0]}id"
Expand Down Expand Up @@ -84,7 +82,7 @@ def calculate_quotas(doc, filter, resource)
# Datastore quotas
query = "SELECT body FROM image_pool WHERE #{filter}"

calculate_ds_quotas(doc, query, resource, datastore_usage)
calculate_ds_quotas(doc, 'image_pool', query, resource, datastore_usage)
end

# Calculate running quotas
Expand All @@ -107,20 +105,17 @@ def calculate_running_quotas(doc, filter, resource)
# Calculate datastore quotas
#
# @param doc [Nokogiri::XML] xml document with all information
# @param table [String] database table
# @param query [String] database query
# @param resource [String] OpenNebula object
# @param datastore_usage [Object] object with datastore usage information
def calculate_ds_quotas(doc, query, resource, datastore_usage)
def calculate_ds_quotas(doc, table, query, resource, datastore_usage)
oid = doc.root.at_xpath('ID').text.to_i

ds_usage = {}

@db.fetch(query) do |img_row|
img_doc = Nokogiri::XML(img_row[:body],
nil,
NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
img_doc = nokogiri_doc(img_row[:body], table)

img_doc.root.xpath('DATASTORE_ID').each do |e|
ds_usage[e.text] = [0, 0] if ds_usage[e.text].nil?
Expand Down Expand Up @@ -442,11 +437,7 @@ def calculate_vnet_quotas(doc, queries, resource)
end

@db.fetch(queries[1]) do |vrouter_row|
vrouter_doc = Nokogiri::XML(vrouter_row[:body],
nil,
NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
vrouter_doc = nokogiri_doc(vrouter_row[:body], 'vrouter_pool')

vrouter_doc.root.xpath('TEMPLATE/NIC').each do |nic|
net_id = nil
Expand Down
2 changes: 1 addition & 1 deletion src/onedb/fsck/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def check_template
templates_fix = @fixes_template = {}

@db[:template_pool].each do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'template_pool')

boot = doc.root.at_xpath("TEMPLATE/OS/BOOT")

Expand Down
4 changes: 1 addition & 3 deletions src/onedb/fsck/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def check_user
end

@db.fetch('SELECT oid,body,gid,name FROM user_pool') do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'user_pool')

gid = doc.root.at_xpath('GID').text.to_i
auth_driver = doc.root.at_xpath('AUTH_DRIVER').text
Expand Down
6 changes: 3 additions & 3 deletions src/onedb/local/4.10.3_to_4.11.80.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def up

@db.transaction do
@db.fetch("SELECT * FROM old_network_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_network_pool')

template = doc.root.at_xpath("TEMPLATE")

Expand Down Expand Up @@ -110,7 +110,7 @@ def up

@db.transaction do
@db.fetch("SELECT * FROM old_datastore_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_datastore_pool')

doc.root.add_child(doc.create_element("STATE")).content = "0"

Expand Down Expand Up @@ -144,7 +144,7 @@ def up

@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool WHERE state<>6") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')

["STATE", "LCM_STATE"].each do |ename|
prev_elem = doc.root.at_xpath("PREV_#{ename}")
Expand Down
10 changes: 5 additions & 5 deletions src/onedb/local/4.11.80_to_4.13.80.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def up

@db.transaction do
@db.fetch("SELECT * FROM old_document_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_document_pool')

lock_elem = doc.create_element("LOCK")
lock_elem.add_child(doc.create_element("LOCKED")).content = "0"
Expand Down Expand Up @@ -99,7 +99,7 @@ def up
@db.transaction do
#@db.fetch("SELECT * FROM old_vm_pool WHERE state<>6") do |row|
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')

update_monitoring(doc.root.at_xpath("/VM"))

Expand Down Expand Up @@ -135,7 +135,7 @@ def up
@db.transaction do
#@db.fetch("SELECT * FROM old_history WHERE etime=0") do |row|
@db.fetch("SELECT * FROM old_history") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_history')

elem = doc.root.at_xpath("/HISTORY/VM")
if !elem.nil?
Expand All @@ -162,7 +162,7 @@ def up

@db.transaction do
@db.fetch("SELECT * FROM old_image_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_image_pool')

doc.root.add_child(doc.create_element("TARGET_SNAPSHOT")).content = "-1"
doc.root.add_child(doc.create_element("SNAPSHOTS"))
Expand Down Expand Up @@ -253,4 +253,4 @@ def update_monitoring(vm_elem)
mv_monitoring(vm_elem, "VMWARETOOLS_VERSION", "VMWARETOOLS_VERSION")
mv_monitoring(vm_elem, "VMWARETOOLS_VERSION_STATUS", "VMWARETOOLS_VERSION_STATUS")
end
end
end
14 changes: 7 additions & 7 deletions src/onedb/local/4.13.80_to_4.13.85.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def up
end

@db.fetch("SELECT * FROM old_user_quotas WHERE user_oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_quotas')

calculate_quotas(doc, "uid=#{row[:user_oid]}", "User")

Expand All @@ -62,7 +62,7 @@ def up
end

@db.fetch("SELECT * FROM old_group_quotas WHERE group_oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_group_quotas')

calculate_quotas(doc, "gid=#{row[:group_oid]}", "Group")

Expand All @@ -80,7 +80,7 @@ def up
default_group_quotas = nil

@db.fetch("SELECT * FROM system_attributes WHERE name = 'DEFAULT_USER_QUOTAS'") do |row|
default_user_quotas = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
default_user_quotas = nokogiri_doc(row[:body], 'system_attributes')

vm_elem = default_user_quotas.root.at_xpath("VM_QUOTA/VM")

Expand All @@ -91,7 +91,7 @@ def up
end

@db.fetch("SELECT * FROM system_attributes WHERE name = 'DEFAULT_GROUP_QUOTAS'") do |row|
default_group_quotas = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
default_group_quotas = nokogiri_doc(row[:body], 'system_attributes')

vm_elem = default_group_quotas.root.at_xpath("VM_QUOTA/VM")

Expand All @@ -118,7 +118,7 @@ def up

@db.transaction do
@db.fetch("SELECT * FROM old_host_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_host_pool')

doc.root.at_xpath("HOST_SHARE").add_child(doc.create_element("PCI_DEVICES"))

Expand Down Expand Up @@ -163,7 +163,7 @@ def calculate_quotas(doc, where_filter, resource)
sys_used = 0

@db.fetch("SELECT body FROM vm_pool WHERE #{where_filter} AND state<>6") do |vm_row|
vmdoc = Nokogiri::XML(vm_row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
vmdoc = nokogiri_doc(row[:body], 'vm_pool')

vmdoc.root.xpath("TEMPLATE/DISK").each { |e|
type = ""
Expand Down Expand Up @@ -235,4 +235,4 @@ def calculate_quotas(doc, where_filter, resource)
end
}
end
end
end
Loading