Skip to content

Commit 9363be3

Browse files
committed
Merge pull request apache#934 from karuturi/CLOUDSTACK-8923
[4.6][BLOCKER] CLOUDSTACK-8923: Create storage network IP range failedThis is a regression from commit 0cd8c06 try-with-resource used at https://github.com/apache/cloudstack/blob/master/server/src/com/cloud/network/StorageNetworkManagerImpl.java#L107 is closing the transaction. At later point when the transaction is actually committed, it doesn't find the transaction and hence the exception. testing: manually tested that create storage network api succeeds. ``` cloudmonkey > create storagenetworkiprange gateway=192.168.200.67 netmask=255.255.255.0 startip=192.168.200.200 endip=192.168.200.202 podid=544e3be0-9bc6-428f-9237-bf777053ab2e \ accountid = 120b521c-725c-11e5-9244-7278fd1d2943 cmd = org.apache.cloudstack.api.command.admin.network.CreateStorageNetworkIpRangeCmd created = 2015-10-15T09:31:22+0000 jobid = c86c4968-bc6e-4255-aa11-39221eb2277f jobprocstatus = 0 jobresult: storagenetworkiprange: id = df491e87-7a00-4b5e-9bfe-e811fe78c9cd endip = 192.168.200.202 gateway = 192.168.200.67 netmask = 255.255.255.0 startip = 192.168.200.200 jobresultcode = 0 jobresulttype = object jobstatus = 1 userid = 120b6414-725c-11e5-9244-7278fd1d2943 ``` ``` cloudmonkey > list storagenetworkiprange count = 1 storagenetworkiprange: id = df491e87-7a00-4b5e-9bfe-e811fe78c9cd endip = 192.168.200.202 gateway = 192.168.200.67 netmask = 255.255.255.0 networkid = a0f7faf9-83a1-4af5-b420-d8a78f2f59d8 podid = 544e3be0-9bc6-428f-9237-bf777053ab2e startip = 192.168.200.200 zoneid = 34b9a0a1-758c-442b-9bc6-7bce03157d4c ``` * pr/934: CLOUDSTACK-8923: Create storage network IP range failed Signed-off-by: Rajani Karuturi <rajani.karuturi@citrix.com>
2 parents 2ce5a0c + 79b7391 commit 9363be3

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

‎server/src/com/cloud/network/StorageNetworkManagerImpl.java‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,19 @@ private void createStorageIpEntires(TransactionLegacy txn, long rangeId, String
104104
String insertSql =
105105
"INSERT INTO `cloud`.`op_dc_storage_network_ip_address` (range_id, ip_address, mac_address, taken) VALUES (?, ?, (select mac_address from `cloud`.`data_center` where id=?), ?)";
106106
String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
107-
try (Connection conn = txn.getConnection();) {
108-
while (startIPLong <= endIPLong) {
109-
try (PreparedStatement stmt_insert = conn.prepareStatement(insertSql); ) {
110-
stmt_insert.setLong(1, rangeId);
111-
stmt_insert.setString(2, NetUtils.long2Ip(startIPLong++));
112-
stmt_insert.setLong(3, zoneId);
113-
stmt_insert.setNull(4, java.sql.Types.DATE);
114-
stmt_insert.executeUpdate();
115-
}
107+
Connection conn = txn.getConnection();
108+
while (startIPLong <= endIPLong) {
109+
try (PreparedStatement stmt_insert = conn.prepareStatement(insertSql);) {
110+
stmt_insert.setLong(1, rangeId);
111+
stmt_insert.setString(2, NetUtils.long2Ip(startIPLong++));
112+
stmt_insert.setLong(3, zoneId);
113+
stmt_insert.setNull(4, java.sql.Types.DATE);
114+
stmt_insert.executeUpdate();
115+
}
116116

117-
try (PreparedStatement stmt_update = txn.prepareStatement(updateSql);) {
118-
stmt_update.setLong(1, zoneId);
119-
stmt_update.executeUpdate();
120-
}
117+
try (PreparedStatement stmt_update = txn.prepareStatement(updateSql);) {
118+
stmt_update.setLong(1, zoneId);
119+
stmt_update.executeUpdate();
121120
}
122121
}
123122
}

0 commit comments

Comments
 (0)