mirror of https://github.com/apache/cloudstack.git
bug 14407: update network count for account/domain as a part of 3.0 to 3.0.1 upgrade
status 14407: resolved fixed
This commit is contained in:
parent
37a7c897bd
commit
da2be577a2
|
|
@ -31,7 +31,6 @@ import java.util.UUID;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
|
@ -89,10 +88,7 @@ public class Upgrade2214to30 implements DbUpgrade {
|
|||
migrateUserConcentratedPlannerChoice(conn);
|
||||
// update domain router table for element it;
|
||||
updateRouters(conn);
|
||||
// update network account resource count
|
||||
udpateAccountNetworkResourceCount(conn);
|
||||
// update network domain resource count
|
||||
udpateDomainNetworkResourceCount(conn);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1095,56 +1091,4 @@ public class Upgrade2214to30 implements DbUpgrade {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void udpateAccountNetworkResourceCount(Connection conn) {
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rs1 = null;
|
||||
long accountId = 0;
|
||||
try {
|
||||
pstmt = conn.prepareStatement("select id from `cloud`.`account` where removed is null");
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
accountId = rs.getLong(1);
|
||||
|
||||
//get networks count for the account
|
||||
pstmt = conn.prepareStatement("select count(*) from `cloud`.`networks` n, `cloud`.`account_network_ref` a, `cloud`.`network_offerings` no" +
|
||||
" WHERE n.acl_type='Account' and n.id=a.network_id and a.account_id=? and a.is_owner=1 and no.specify_vlan=false and no.traffic_type='Guest'");
|
||||
pstmt.setLong(1, accountId);
|
||||
rs1 = pstmt.executeQuery();
|
||||
long count = 0;
|
||||
while (rs1.next()) {
|
||||
count = rs1.getLong(1);
|
||||
}
|
||||
|
||||
pstmt = conn.prepareStatement("insert into `cloud`.`resource_count` (account_id, domain_id, type, count) VALUES (?, null, 'network', ?)");
|
||||
pstmt.setLong(1, accountId);
|
||||
pstmt.setLong(2, count);
|
||||
pstmt.executeUpdate();
|
||||
s_logger.debug("Updated network resource count for account id=" + accountId + " to be " + count);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to update network resource count for account id=" + accountId, e);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
|
||||
if (rs1 != null) {
|
||||
rs1.close();
|
||||
}
|
||||
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void udpateDomainNetworkResourceCount(Connection conn) {
|
||||
Upgrade218to22.upgradeDomainResourceCounts(conn, ResourceType.network);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,13 @@ package com.cloud.upgrade.dao;
|
|||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
|
|
@ -55,12 +59,67 @@ public class Upgrade30to301 implements DbUpgrade {
|
|||
|
||||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
|
||||
// update network account resource count
|
||||
udpateAccountNetworkResourceCount(conn);
|
||||
// update network domain resource count
|
||||
udpateDomainNetworkResourceCount(conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getCleanupScripts() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected void udpateAccountNetworkResourceCount(Connection conn) {
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rs1 = null;
|
||||
long accountId = 0;
|
||||
try {
|
||||
pstmt = conn.prepareStatement("select id from `cloud`.`account` where removed is null");
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
accountId = rs.getLong(1);
|
||||
|
||||
//get networks count for the account
|
||||
pstmt = conn.prepareStatement("select count(*) from `cloud`.`networks` n, `cloud`.`account_network_ref` a, `cloud`.`network_offerings` no" +
|
||||
" WHERE n.acl_type='Account' and n.id=a.network_id and a.account_id=? and a.is_owner=1 and no.specify_vlan=false and no.traffic_type='Guest'");
|
||||
pstmt.setLong(1, accountId);
|
||||
rs1 = pstmt.executeQuery();
|
||||
long count = 0;
|
||||
while (rs1.next()) {
|
||||
count = rs1.getLong(1);
|
||||
}
|
||||
|
||||
pstmt = conn.prepareStatement("insert into `cloud`.`resource_count` (account_id, domain_id, type, count) VALUES (?, null, 'network', ?)");
|
||||
pstmt.setLong(1, accountId);
|
||||
pstmt.setLong(2, count);
|
||||
pstmt.executeUpdate();
|
||||
s_logger.debug("Updated network resource count for account id=" + accountId + " to be " + count);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to update network resource count for account id=" + accountId, e);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
|
||||
if (rs1 != null) {
|
||||
rs1.close();
|
||||
}
|
||||
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void udpateDomainNetworkResourceCount(Connection conn) {
|
||||
Upgrade218to22.upgradeDomainResourceCounts(conn, ResourceType.network);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,6 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT'
|
|||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.templates', '20', 'The default maximum number of templates that can be deployed for a project');
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.snapshots', '20', 'The default maximum number of snapshots that can be created for a project');
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.volumes', '20', 'The default maximum number of volumes that can be created for a project');
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.networks', '20', 'The default maximum number of networks that can be created for a project');
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'project.invite.required', 'false', 'If invitation confirmation is required when add account to project. Default value is false');
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'project.invite.timeout', '86400', 'Invitation expiration time (in seconds). Default is 1 day - 86400 seconds');
|
||||
|
|
@ -720,7 +719,6 @@ UPDATE `cloud`.`network_offerings` SET display_text='Offering for Shared Securit
|
|||
|
||||
UPDATE `cloud`.`configuration` SET category = 'Secure' where name in ('alert.smtp.password', 'network.loadbalancer.haproxy.stats.auth', 'security.singlesignon.key', 'project.smtp.password');
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Account Defaults', 'DEFAULT', 'management-server', 'max.account.networks', '20', 'The default maximum number of networks that can be created for an account');
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (143, 1, 'CentOS 6.0 (32-bit)');
|
||||
INSERT IGNORE INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (144, 1, 'CentOS 6.0 (64-bit)');
|
||||
|
|
|
|||
|
|
@ -17,3 +17,6 @@
|
|||
|
||||
#Schema upgrade from 3.0 to 3.0.1;
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Project Defaults', 'DEFAULT', 'management-server', 'max.project.networks', '20', 'The default maximum number of networks that can be created for a project');
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Account Defaults', 'DEFAULT', 'management-server', 'max.account.networks', '20', 'The default maximum number of networks that can be created for an account');
|
||||
Loading…
Reference in New Issue