<commit_before># -------------------------------------------------------------------------- #
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems                #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
#--------------------------------------------------------------------------- #

require 'set'
require 'base64'
require 'zlib'
require 'pathname'
require 'yaml'
require 'opennebula'
require 'vcenter_driver'

$LOAD_PATH << File.dirname(__FILE__)

include OpenNebula

module Migrator

    def db_version
        '5.7.80'
    end

    def one_version
        'OpenNebula 5.7.80'
    end

    def up
        feature_2944
        bug_2687 # MUST be run before 2489, which generates short body
        feature_2253
        feature_2489_2671
        feature_826
        feature_2966
        true
    end

    private

    def feature_2944
        vclient =->(hid){
            row = @db.fetch("SELECT * FROM host_pool WHERE oid = #{hid}").first
            raise "Host #{hid} not found in the OpenNebula DB" if !row[:body]
            xml = row[:body]

            doc = nokogiri_doc(xml, 'host_pool').root.at_xpath('/HOST/TEMPLATE')

            rp = doc.xpath("VCENTER_RESOURCE_POOL").first
            rp = rp.text if rp

            token    = File.read(VAR_LOCATION+'/.one/one_key')
            password = doc.xpath("VCENTER_PASSWORD").first.text
            password = VCenterDriver::VIClient::decrypt(password, token)

            connection = {
                :host     => doc.xpath("VCENTER_HOST").first.text,
                :user     => doc.xpath("VCENTER_USER").first.text,
                :rp       => rp,<commit_msg>F #3436: reduce memory use of onedb upgrade (#4452)<commit_after># -------------------------------------------------------------------------- #
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems                #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
#--------------------------------------------------------------------------- #

require 'set'
require 'base64'
require 'zlib'
require 'pathname'
require 'yaml'
require 'opennebula'
require 'vcenter_driver'

$LOAD_PATH << File.dirname(__FILE__)

include OpenNebula

module Migrator

    def db_version
        '5.7.80'
    end

    def one_version
        'OpenNebula 5.7.80'
    end

    def up
        feature_2944
        GC.start
        bug_2687 # MUST be run before 2489, which generates short body
        GC.start
        feature_2253
        GC.start
        feature_2489_2671
        GC.start
        feature_826
        GC.start
        feature_2966
        true
    end

    private

    def feature_2944
        vclient =->(hid){
            row = @db.fetch("SELECT * FROM host_pool WHERE oid = #{hid}").first
            raise "Host #{hid} not found in the OpenNebula DB" if !row[:body]
            xml = row[:body]

            doc = nokogiri_doc(xml, 'host_pool').root.at_xpath('/HOST/TEMPLATE')

            rp = doc.xpath("VCENTER_RESOURCE_POOL").first
            rp = rp.text if rp

            token    = File.read(VAR_LOCATION+'/.one/one_key')
            password = doc.xpath("VCENTER_PASSWORD").first.text
            password = VCenterDriver::VIClient::decrypt(password, token)

            connection = {
                :host     => doc.xpath("VCENTER_HOST").first.text,
                :user     => doc.xpath("VCENTER_USER").first.text,
                :rp       => rp,
{'fraction_non_alphanumeric': 0.1354826328919593, 'fraction_numerical': 0.02341201304931875, 'mean_word_length': 1.259211096662332, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7569951', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1258, 'n_words': 374}