mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
fix mismatching between db uuids and custom attributes uuids (#5382)
* fix mismatching between db uuids and custom attributes uuids during the datastore cluster creation, cloudstack could not recognize the existing primary storage and create a new one because uuid format not equal * remove method call setUuid * add upgrade step to fix faulty pool uuids * adapt method to transform uuid each time * extract error msg * rm unused import * add exception to log error as parameter * adapt sql to fetch wrong uuids * rm spaces * move upgrade code to Upgrade41610to41700 Co-authored-by: DK101010 <dirk.klahre@itelligence.de>
This commit is contained in:
parent
5cf8064467
commit
18d9c6dfc6
@ -34,6 +34,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
|
||||
public class Upgrade41520to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate {
|
||||
|
||||
final static Logger LOG = Logger.getLogger(Upgrade41520to41600.class);
|
||||
|
||||
@ -21,7 +21,12 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Upgrade41610to41700 implements DbUpgrade, DbUpgradeSystemVmTemplate {
|
||||
|
||||
@ -56,6 +61,7 @@ public class Upgrade41610to41700 implements DbUpgrade, DbUpgradeSystemVmTemplate
|
||||
|
||||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
fixWrongPoolUuid(conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,4 +89,26 @@ public class Upgrade41610to41700 implements DbUpgrade, DbUpgradeSystemVmTemplate
|
||||
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
|
||||
}
|
||||
}
|
||||
|
||||
public void fixWrongPoolUuid(Connection conn) {
|
||||
LOG.debug("Replacement of faulty pool uuids");
|
||||
try (PreparedStatement pstmt = conn.prepareStatement("SELECT id,uuid FROM storage_pool "
|
||||
+ "WHERE uuid NOT LIKE \"%-%-%-%\" AND removed IS NULL;"); ResultSet rs = pstmt.executeQuery()) {
|
||||
PreparedStatement updateStmt = conn.prepareStatement("update storage_pool set uuid = ? where id = ?");
|
||||
while (rs.next()) {
|
||||
UUID poolUuid = new UUID(
|
||||
new BigInteger(rs.getString(2).substring(0, 16), 16).longValue(),
|
||||
new BigInteger(rs.getString(2).substring(16), 16).longValue()
|
||||
);
|
||||
updateStmt.setLong(2, rs.getLong(1));
|
||||
updateStmt.setString(1, poolUuid.toString());
|
||||
updateStmt.addBatch();
|
||||
}
|
||||
updateStmt.executeBatch();
|
||||
} catch (SQLException ex) {
|
||||
String errorMsg = "fixWrongPoolUuid:Exception while updating faulty pool uuids";
|
||||
LOG.error(errorMsg,ex);
|
||||
throw new CloudRuntimeException(errorMsg, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,6 +231,8 @@ import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import java.math.BigInteger;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class StorageManagerImpl extends ManagerBase implements StorageManager, ClusterManagerListener, Configurable {
|
||||
@ -1818,7 +1820,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
|
||||
for (ModifyStoragePoolAnswer childDataStoreAnswer : childDatastoreAnswerList) {
|
||||
StoragePoolInfo childStoragePoolInfo = childDataStoreAnswer.getPoolInfo();
|
||||
StoragePoolVO dataStoreVO = _storagePoolDao.findPoolByUUID(childStoragePoolInfo.getUuid());
|
||||
StoragePoolVO dataStoreVO = getExistingPoolByUuid(childStoragePoolInfo.getUuid());
|
||||
if (dataStoreVO == null && childDataStoreAnswer.getPoolType().equalsIgnoreCase("NFS")) {
|
||||
List<StoragePoolVO> nfsStoragePools = _storagePoolDao.findPoolsByStorageType(StoragePoolType.NetworkFilesystem.toString());
|
||||
for (StoragePoolVO storagePool : nfsStoragePools) {
|
||||
@ -1864,6 +1866,17 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
||||
handleRemoveChildStoragePoolFromDatastoreCluster(childDatastoreUUIDs);
|
||||
}
|
||||
|
||||
private StoragePoolVO getExistingPoolByUuid(String uuid){
|
||||
if(!uuid.contains("-")){
|
||||
UUID poolUuid = new UUID(
|
||||
new BigInteger(uuid.substring(0, 16), 16).longValue(),
|
||||
new BigInteger(uuid.substring(16), 16).longValue()
|
||||
);
|
||||
uuid = poolUuid.toString();
|
||||
}
|
||||
return _storagePoolDao.findByUuid(uuid);
|
||||
}
|
||||
|
||||
private void validateChildDatastoresToBeAddedInUpState(StoragePoolVO datastoreClusterPool, List<ModifyStoragePoolAnswer> childDatastoreAnswerList) {
|
||||
for (ModifyStoragePoolAnswer childDataStoreAnswer : childDatastoreAnswerList) {
|
||||
StoragePoolInfo childStoragePoolInfo = childDataStoreAnswer.getPoolInfo();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user