CLOUDSTACK-8070: Upgrade router.ram.size using encryption util Upgrade fails if value is set using plain text encoding, the value needs to be encrypted (if a key was provided during db was setup).
Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6321a29e Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6321a29e Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6321a29e Branch: refs/heads/master Commit: 6321a29e4336de9ffe96e27968f896ec5a8bf37d Parents: b07c9b7 Author: Rohit Yadav <rohit.ya...@shapeblue.com> Authored: Sat Dec 13 00:15:40 2014 +0530 Committer: Rohit Yadav <rohit.ya...@shapeblue.com> Committed: Sat Dec 13 00:17:09 2014 +0530 ---------------------------------------------------------------------- .../com/cloud/upgrade/dao/Upgrade442to450.java | 25 ++++++++++++++++++++ setup/db/db/schema-442to450.sql | 2 -- 2 files changed, 25 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6321a29e/engine/schema/src/com/cloud/upgrade/dao/Upgrade442to450.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade442to450.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade442to450.java index aeb44a1..e8a517b 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade442to450.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade442to450.java @@ -18,6 +18,7 @@ package com.cloud.upgrade.dao; import java.io.File; +import java.io.UnsupportedEncodingException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -30,6 +31,7 @@ import java.util.Map; import java.util.Set; import com.cloud.hypervisor.Hypervisor; +import com.cloud.utils.crypt.DBEncryptionUtil; import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; @@ -68,10 +70,33 @@ public class Upgrade442to450 implements DbUpgrade { updateSystemVmTemplates(conn); dropInvalidKeyFromStoragePoolTable(conn); dropDuplicatedForeignKeyFromAsyncJobTable(conn); + updateMaxRouterSizeConfig(conn); upgradeMemoryOfVirtualRoutervmOffering(conn); upgradeMemoryOfInternalLoadBalancervmOffering(conn); } + private void updateMaxRouterSizeConfig(Connection conn) { + PreparedStatement updatePstmt = null; + try { + String encryptedValue = DBEncryptionUtil.encrypt("256"); + updatePstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value=? WHERE name='router.ram.size' AND category='Hidden'"); + updatePstmt.setBytes(1, encryptedValue.getBytes("UTF-8")); + updatePstmt.executeUpdate(); + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to upgrade max ram size of router in config.", e); + } catch (UnsupportedEncodingException e) { + throw new CloudRuntimeException("Unable encrypt configuration values ", e); + } finally { + try { + if (updatePstmt != null) { + updatePstmt.close(); + } + } catch (SQLException e) { + } + } + s_logger.debug("Done updating router.ram.size config to 256"); + } + private void upgradeMemoryOfVirtualRoutervmOffering(Connection conn) { PreparedStatement updatePstmt = null; PreparedStatement selectPstmt = null; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6321a29e/setup/db/db/schema-442to450.sql ---------------------------------------------------------------------- diff --git a/setup/db/db/schema-442to450.sql b/setup/db/db/schema-442to450.sql index 3981415..c51bd00 100644 --- a/setup/db/db/schema-442to450.sql +++ b/setup/db/db/schema-442to450.sql @@ -448,8 +448,6 @@ UPDATE configuration SET value='KVM,XenServer,VMware,BareMetal,Ovm,LXC,Hyperv' W UPDATE `cloud`.`configuration` SET description="If set to true, will set guest VM's name as it appears on the hypervisor, to its hostname. The flag is supported for VMware hypervisor only" WHERE name='vm.instancename.flag'; INSERT IGNORE INTO `cloud`.`configuration`(category, instance, component, name, value, description, default_value) VALUES ('Advanced', 'DEFAULT', 'management-server', 'implicit.host.tags', 'GPU', 'Tag hosts at the time of host disovery based on the host properties/capabilities ', 'GPU'); -UPDATE `cloud`.`configuration` SET value='256' WHERE name='router.ram.size'; - DROP VIEW IF EXISTS `cloud`.`domain_router_view`; CREATE VIEW `cloud`.`domain_router_view` AS select