|
28 | 28 | import java.util.Map; |
29 | 29 | import java.util.Set; |
30 | 30 |
|
| 31 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 32 | + |
31 | 33 | import org.apache.log4j.Logger; |
32 | 34 |
|
33 | 35 | public class Upgrade431to432 implements DbUpgrade { |
@@ -55,6 +57,112 @@ public File[] getPrepareScripts() { |
55 | 57 |
|
56 | 58 | @Override |
57 | 59 | public void performDataMigration(Connection conn) { |
| 60 | + updateMaxRouterSizeConfig(conn); |
| 61 | + upgradeMemoryOfVirtualRoutervmOffering(conn); |
| 62 | + upgradeMemoryOfInternalLoadBalancervmOffering(conn); |
| 63 | + } |
| 64 | + |
| 65 | + private void updateMaxRouterSizeConfig(Connection conn) { |
| 66 | + PreparedStatement updatePstmt = null; |
| 67 | + try { |
| 68 | + updatePstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value='256' WHERE name='router.ram.size'"); |
| 69 | + updatePstmt.executeUpdate(); |
| 70 | + } catch (SQLException e) { |
| 71 | + throw new CloudRuntimeException("Unable to upgrade max ram size of router in config.", e); |
| 72 | + } finally { |
| 73 | + try { |
| 74 | + if (updatePstmt != null) { |
| 75 | + updatePstmt.close(); |
| 76 | + } |
| 77 | + } catch (SQLException e) { |
| 78 | + } |
| 79 | + } |
| 80 | + s_logger.debug("Done updating router.ram.size config to 256"); |
| 81 | + } |
| 82 | + |
| 83 | + private void upgradeMemoryOfInternalLoadBalancervmOffering(Connection conn) { |
| 84 | + PreparedStatement updatePstmt = null; |
| 85 | + PreparedStatement selectPstmt = null; |
| 86 | + ResultSet selectResultSet = null; |
| 87 | + int newRamSize = 256; //256MB |
| 88 | + long serviceOfferingId = 0; |
| 89 | + |
| 90 | + /** |
| 91 | + * Pick first row in service_offering table which has system vm type as internalloadbalancervm. User added offerings would start from 2nd row onwards. |
| 92 | + * We should not update/modify any user-defined offering. |
| 93 | + */ |
| 94 | + |
| 95 | + try { |
| 96 | + selectPstmt = conn.prepareStatement("SELECT id FROM `cloud`.`service_offering` WHERE vm_type='internalloadbalancervm'"); |
| 97 | + updatePstmt = conn.prepareStatement("UPDATE `cloud`.`service_offering` SET ram_size=? WHERE id=?"); |
| 98 | + selectResultSet = selectPstmt.executeQuery(); |
| 99 | + if(selectResultSet.next()) { |
| 100 | + serviceOfferingId = selectResultSet.getLong("id"); |
| 101 | + } |
| 102 | + |
| 103 | + updatePstmt.setInt(1, newRamSize); |
| 104 | + updatePstmt.setLong(2, serviceOfferingId); |
| 105 | + updatePstmt.executeUpdate(); |
| 106 | + } catch (SQLException e) { |
| 107 | + throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for internal loadbalancer vm. ", e); |
| 108 | + } finally { |
| 109 | + try { |
| 110 | + if (selectPstmt != null) { |
| 111 | + selectPstmt.close(); |
| 112 | + } |
| 113 | + if (selectResultSet != null) { |
| 114 | + selectResultSet.close(); |
| 115 | + } |
| 116 | + if (updatePstmt != null) { |
| 117 | + updatePstmt.close(); |
| 118 | + } |
| 119 | + } catch (SQLException e) { |
| 120 | + } |
| 121 | + } |
| 122 | + s_logger.debug("Done upgrading RAM for service offering of internal loadbalancer vm to " + newRamSize); |
| 123 | + } |
| 124 | + |
| 125 | + |
| 126 | + private void upgradeMemoryOfVirtualRoutervmOffering(Connection conn) { |
| 127 | + PreparedStatement updatePstmt = null; |
| 128 | + PreparedStatement selectPstmt = null; |
| 129 | + ResultSet selectResultSet = null; |
| 130 | + int newRamSize = 256; //256MB |
| 131 | + long serviceOfferingId = 0; |
| 132 | + |
| 133 | + /** |
| 134 | + * Pick first row in service_offering table which has system vm type as domainrouter. User added offerings would start from 2nd row onwards. |
| 135 | + * We should not update/modify any user-defined offering. |
| 136 | + */ |
| 137 | + |
| 138 | + try { |
| 139 | + selectPstmt = conn.prepareStatement("SELECT id FROM `cloud`.`service_offering` WHERE vm_type='domainrouter'"); |
| 140 | + updatePstmt = conn.prepareStatement("UPDATE `cloud`.`service_offering` SET ram_size=? WHERE id=?"); |
| 141 | + selectResultSet = selectPstmt.executeQuery(); |
| 142 | + if(selectResultSet.next()) { |
| 143 | + serviceOfferingId = selectResultSet.getLong("id"); |
| 144 | + } |
| 145 | + |
| 146 | + updatePstmt.setInt(1, newRamSize); |
| 147 | + updatePstmt.setLong(2, serviceOfferingId); |
| 148 | + updatePstmt.executeUpdate(); |
| 149 | + } catch (SQLException e) { |
| 150 | + throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for domain router. ", e); |
| 151 | + } finally { |
| 152 | + try { |
| 153 | + if (selectPstmt != null) { |
| 154 | + selectPstmt.close(); |
| 155 | + } |
| 156 | + if (selectResultSet != null) { |
| 157 | + selectResultSet.close(); |
| 158 | + } |
| 159 | + if (updatePstmt != null) { |
| 160 | + updatePstmt.close(); |
| 161 | + } |
| 162 | + } catch (SQLException e) { |
| 163 | + } |
| 164 | + } |
| 165 | + s_logger.debug("Done upgrading RAM for service offering of domain router to " + newRamSize); |
58 | 166 | } |
59 | 167 |
|
60 | 168 | @Override |
|
0 commit comments