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