mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
bug 12843: initialize uuid column for tables that have default data content
This commit is contained in:
parent
b0dd607e29
commit
74c2506f42
@ -161,5 +161,6 @@
|
||||
<dao name="UserDao" class="com.cloud.user.dao.UserDaoImpl" singleton="false"/>
|
||||
<dao name="NetworkOfferingServiceDao" class="com.cloud.offerings.dao.NetworkOfferingServiceMapDaoImpl" singleton="false"/>
|
||||
<dao name="VirtualRouterProviderDao" class="com.cloud.network.dao.VirtualRouterProviderDaoImpl" singleton="false"/>
|
||||
<dao name="IdentityDao" class="com.cloud.uuididentity.dao.IdentityDaoImpl" singleton="false"/>
|
||||
</configuration-server>
|
||||
</components.xml>
|
||||
|
||||
@ -103,6 +103,7 @@ import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.uuididentity.dao.IdentityDao;
|
||||
|
||||
public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
public static final Logger s_logger = Logger.getLogger(ConfigurationServerImpl.class.getName());
|
||||
@ -121,6 +122,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
private final AccountDao _accountDao;
|
||||
private final ResourceCountDao _resourceCountDao;
|
||||
private final NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao;
|
||||
private final IdentityDao _identityDao;
|
||||
|
||||
public ConfigurationServerImpl() {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(Name);
|
||||
@ -137,6 +139,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
_accountDao = locator.getDao(AccountDao.class);
|
||||
_resourceCountDao = locator.getDao(ResourceCountDao.class);
|
||||
_ntwkOfferingServiceMapDao = locator.getDao(NetworkOfferingServiceMapDao.class);
|
||||
_identityDao = locator.getDao(IdentityDao.class);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@ -266,10 +269,33 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
// Update the cloud identifier
|
||||
updateCloudIdentifier();
|
||||
|
||||
updateUuids();
|
||||
|
||||
|
||||
// Set init to true
|
||||
_configDao.update("init", "Hidden", "true");
|
||||
}
|
||||
|
||||
|
||||
private void updateUuids() {
|
||||
_identityDao.initializeDefaultUuid("disk_offering");
|
||||
_identityDao.initializeDefaultUuid("network_offerings");
|
||||
_identityDao.initializeDefaultUuid("vm_template");
|
||||
_identityDao.initializeDefaultUuid("user");
|
||||
_identityDao.initializeDefaultUuid("domain");
|
||||
_identityDao.initializeDefaultUuid("account");
|
||||
_identityDao.initializeDefaultUuid("guest_os");
|
||||
_identityDao.initializeDefaultUuid("guest_os_category");
|
||||
_identityDao.initializeDefaultUuid("hypervisor_capabilities");
|
||||
_identityDao.initializeDefaultUuid("snapshot_policy");
|
||||
_identityDao.initializeDefaultUuid("security_group");
|
||||
_identityDao.initializeDefaultUuid("security_group_rule");
|
||||
_identityDao.initializeDefaultUuid("physical_network");
|
||||
_identityDao.initializeDefaultUuid("physical_network_traffic_types");
|
||||
_identityDao.initializeDefaultUuid("physical_network_service_providers");
|
||||
_identityDao.initializeDefaultUuid("virtual_router_providers");
|
||||
_identityDao.initializeDefaultUuid("networks");
|
||||
_identityDao.initializeDefaultUuid("user_ip_address");
|
||||
}
|
||||
|
||||
private String getMountParent() {
|
||||
return getEnvironmentProperty("mount.parent");
|
||||
|
||||
@ -25,4 +25,5 @@ public interface IdentityDao extends GenericDao<IdentityVO, Long> {
|
||||
Long getIdentityId(IdentityMapper mapper, String identityString);
|
||||
Long getIdentityId(String tableName, String identityString);
|
||||
String getIdentityUuid(String tableName, String identityString);
|
||||
void initializeDefaultUuid(String tableName);
|
||||
}
|
||||
|
||||
@ -20,6 +20,9 @@ package com.cloud.uuididentity.dao;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
@ -99,7 +102,7 @@ public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements
|
||||
try {
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(
|
||||
String.format("SELECT uuid FROM %s WHERE id=? OR uuid=?", tableName)
|
||||
String.format("SELECT uuid FROM `%s` WHERE id=? OR uuid=?", tableName)
|
||||
// String.format("SELECT uuid FROM %s WHERE (id=? AND uuid IS NULL) OR uuid=?", tableName)
|
||||
);
|
||||
|
||||
@ -130,4 +133,65 @@ public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements
|
||||
|
||||
return identityString;
|
||||
}
|
||||
|
||||
@DB
|
||||
public void initializeDefaultUuid(String tableName) {
|
||||
assert(tableName != null);
|
||||
List<Long> l = getNullUuidRecords(tableName);
|
||||
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
try {
|
||||
txn.start();
|
||||
for(Long id : l) {
|
||||
setInitialUuid(tableName, id);
|
||||
}
|
||||
txn.commit();
|
||||
} catch (SQLException e) {
|
||||
txn.rollback();
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
}
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
@DB
|
||||
List<Long> getNullUuidRecords(String tableName) {
|
||||
List<Long> l = new ArrayList<Long>();
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(
|
||||
String.format("SELECT id FROM `%s` WHERE uuid IS NULL", tableName)
|
||||
);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while(rs.next()) {
|
||||
l.add(rs.getLong(1));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
}
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
@DB
|
||||
void setInitialUuid(String tableName, long id) throws SQLException {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
PreparedStatement pstmtUpdate = null;
|
||||
pstmtUpdate = txn.prepareAutoCloseStatement(
|
||||
String.format("UPDATE `%s` SET uuid=? WHERE id=?", tableName)
|
||||
);
|
||||
|
||||
pstmtUpdate.setString(1, UUID.randomUUID().toString());
|
||||
pstmtUpdate.setLong(2, id);
|
||||
pstmtUpdate.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user