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.yadav@shapeblue.com>
(cherry picked from commit 6321a29e4336de9ffe96e27968f896ec5a8bf37d)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2014-12-13 00:15:40 +05:30
parent dd145a397a
commit 1a66b3b5c6
2 changed files with 25 additions and 2 deletions

View File

@ -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;

View File

@ -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