mirror of https://github.com/apache/cloudstack.git
bug 9422: added rows in op_networks table to correspond to the rows in networks table
This commit is contained in:
parent
256517f1c3
commit
7b0f95a466
|
|
@ -443,8 +443,7 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||
}
|
||||
|
||||
protected void upgradeVirtualUserVms(Connection conn, long domainRouterId, long networkId, String gateway, String vnet) throws SQLException {
|
||||
PreparedStatement pstmt = conn
|
||||
.prepareStatement("SELECT vm_instance.id, vm_instance.private_mac_address, vm_instance.private_ip_address, vm_instance.private_netmask, vm_instance.state, vm_instance.type FROM vm_instance INNER JOIN user_vm ON vm_instance.id=user_vm.id WHERE user_vm.domain_router_id=? and vm_instance.removed IS NULL");
|
||||
PreparedStatement pstmt = conn.prepareStatement("SELECT vm_instance.id, vm_instance.private_mac_address, vm_instance.private_ip_address, vm_instance.private_netmask, vm_instance.state, vm_instance.type FROM vm_instance INNER JOIN user_vm ON vm_instance.id=user_vm.id WHERE user_vm.domain_router_id=? and vm_instance.removed IS NULL");
|
||||
pstmt.setLong(1, domainRouterId);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
List<Object[]> vms = new ArrayList<Object[]>();
|
||||
|
|
@ -462,16 +461,41 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||
|
||||
s_logger.debug("Upgrading " + vms.size() + " vms for router " + domainRouterId);
|
||||
|
||||
int count = 0;
|
||||
|
||||
for (Object[] vm : vms) {
|
||||
String state = (String) vm[4];
|
||||
|
||||
boolean running = false;
|
||||
if (state.equals("Running") || state.equals("Starting") || state.equals("Stopping")) {
|
||||
running = true;
|
||||
count++;
|
||||
}
|
||||
|
||||
insertNic(conn, networkId, (Long) vm[0], running, (String) vm[1], (String) vm[2], (String) vm[3], "Start", gateway, vnet, "ExternalGuestNetworkGuru", true, 0, "Dhcp", null);
|
||||
}
|
||||
|
||||
pstmt = conn.prepareStatement("SELECT state FROm vm_instance WHERE id=?");
|
||||
pstmt.setLong(1, domainRouterId);
|
||||
rs = pstmt.executeQuery();
|
||||
rs.next();
|
||||
String state = rs.getString(1);
|
||||
if (state.equals("Running") || state.equals("Starting") || state.equals("Stopping")) {
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
pstmt = conn.prepareStatement("UPDATE op_networks SET nics_count=?, check_for_gc=? WHERE id=?");
|
||||
pstmt.setLong(1, count);
|
||||
if (count == 0) {
|
||||
pstmt.setBoolean(2, false);
|
||||
} else {
|
||||
pstmt.setBoolean(2, true);
|
||||
}
|
||||
pstmt.setLong(3, networkId);
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
protected void upgradeBasicUserVms(Connection conn, long domainRouterId, long networkId, String gateway, String vnet) throws SQLException {
|
||||
|
|
@ -495,16 +519,39 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||
|
||||
s_logger.debug("Upgrading " + vms.size() + " vms for router " + domainRouterId);
|
||||
|
||||
int count = 0;
|
||||
for (Object[] vm : vms) {
|
||||
String state = (String) vm[4];
|
||||
|
||||
boolean running = false;
|
||||
if (state.equals("Running") || state.equals("Starting") || state.equals("Stopping")) {
|
||||
running = true;
|
||||
count++;
|
||||
}
|
||||
insertNic(conn, networkId, (Long) vm[0], running, (String) vm[1], (String) vm[2], (String) vm[3], "Start", gateway, vnet, "DirectPodBasedNetworkGuru", true, 0, "Dhcp", null);
|
||||
|
||||
}
|
||||
|
||||
pstmt = conn.prepareStatement("SELECT state FROM vm_instance WHERE id=?");
|
||||
pstmt.setLong(1, domainRouterId);
|
||||
rs = pstmt.executeQuery();
|
||||
rs.next();
|
||||
String state = rs.getString(1);
|
||||
if (state.equals("Running") || state.equals("Starting") || state.equals("Stopping")) {
|
||||
count++;
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
|
||||
pstmt = conn.prepareStatement("UPDATE op_networks SET nics_count=?, check_for_gc=? WHERE id=?");
|
||||
pstmt.setLong(1, count);
|
||||
if (count == 0) {
|
||||
pstmt.setBoolean(2, false);
|
||||
} else {
|
||||
pstmt.setBoolean(2, true);
|
||||
}
|
||||
pstmt.setLong(3, networkId);
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
protected long insertNetwork(Connection conn, String name, String displayText, String trafficType, String broadcastDomainType, String broadcastUri, String gateway, String cidr, String mode,
|
||||
|
|
@ -556,10 +603,14 @@ public class Upgrade218to22 implements DbUpgrade {
|
|||
pstmt = conn.prepareStatement("INSERT INTO op_networks(id, mac_address_seq, nics_count, gc, check_for_gc) VALUES(?, ?, ?, ?, ?)");
|
||||
pstmt.setLong(1, seq);
|
||||
pstmt.setLong(2, 0);
|
||||
pstmt.setLong(3, 1);
|
||||
pstmt.setLong(4, 0);
|
||||
pstmt.setBoolean(5, true);
|
||||
pstmt.executeUpdate();
|
||||
pstmt.setLong(3, 0);
|
||||
if (trafficType.equals("Guest")) {
|
||||
pstmt.setBoolean(4, true);
|
||||
} else {
|
||||
pstmt.setBoolean(4, false);
|
||||
}
|
||||
pstmt.setBoolean(5, false);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
pstmt = conn.prepareStatement("INSERT INTO account_network_ref (account_id, network_id, is_owner) VALUES (?, ?, 1)");
|
||||
pstmt.setLong(1, accountId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue