diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java index b498de7e7c65..05eb2c7df556 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java @@ -34,6 +34,7 @@ import com.cloud.utils.exception.CloudRuntimeException; + public class Upgrade41520to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate { final static Logger LOG = Logger.getLogger(Upgrade41520to41600.class); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java index 7d65b432ed33..dd22c2b743d9 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java @@ -21,7 +21,12 @@ 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 InputStream[] getPrepareScripts() { @Override public void performDataMigration(Connection conn) { + fixWrongPoolUuid(conn); } @Override @@ -83,4 +89,26 @@ public void updateSystemVmTemplates(Connection conn) { 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); + } + } } diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java index db24b17bbe18..78a438a54c2a 100644 --- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java @@ -230,6 +230,8 @@ 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 { @@ -1798,7 +1800,7 @@ public void syncDatastoreClusterStoragePool(long datastoreClusterPoolId, List nfsStoragePools = _storagePoolDao.findPoolsByStorageType(StoragePoolType.NetworkFilesystem.toString()); for (StoragePoolVO storagePool : nfsStoragePools) { @@ -1844,6 +1846,17 @@ public void syncDatastoreClusterStoragePool(long datastoreClusterPoolId, List childDatastoreAnswerList) { for (ModifyStoragePoolAnswer childDataStoreAnswer : childDatastoreAnswerList) { StoragePoolInfo childStoragePoolInfo = childDataStoreAnswer.getPoolInfo();