GutoVeronezi commented on a change in pull request #5382:
URL: https://github.com/apache/cloudstack/pull/5382#discussion_r714184186



##########
File path: 
engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41600.java
##########
@@ -64,6 +67,30 @@ public boolean supportsRollingUpgrade() {
 
     @Override
     public void performDataMigration(Connection conn) {
+        fixWrongPoolUuid(conn);
+    }
+
+    public void fixWrongPoolUuid(Connection conn) {
+        LOG.debug("Replacement of faulty pool uuids");
+        try (PreparedStatement pstmt = conn.prepareStatement("SELECT id,uuid 
FROM storage_pool "
+                + "WHERE removed IS NULL;"); ResultSet rs = 
pstmt.executeQuery()) {
+            PreparedStatement updateStmt = conn.prepareStatement("update 
storage_pool set uuid = ? where id = ?");
+            while (rs.next()) {
+                if (!rs.getString(2).contains("-")) {
+                    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) {
+            LOG.error("fixWrongPoolUuid:Exception while updating faulty pool 
uuids" + ex.getMessage());

Review comment:
       We could pass the exception as parameter of `LOG.error(...)`.

##########
File path: server/src/main/java/com/cloud/storage/StorageManagerImpl.java
##########
@@ -1834,6 +1836,17 @@ public void syncDatastoreClusterStoragePool(long 
datastoreClusterPoolId, List<Mo
         handleRemoveChildStoragePoolFromDatastoreCluster(childDatastoreUUIDs);
     }
 
+    private StoragePoolVO getExistingPoolByUuid(String uuid){
+        if(!uuid.contains("-")){

Review comment:
       We could invert this `if` to reduce indentation.

##########
File path: 
engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41600.java
##########
@@ -64,6 +67,30 @@ public boolean supportsRollingUpgrade() {
 
     @Override
     public void performDataMigration(Connection conn) {
+        fixWrongPoolUuid(conn);
+    }
+
+    public void fixWrongPoolUuid(Connection conn) {
+        LOG.debug("Replacement of faulty pool uuids");
+        try (PreparedStatement pstmt = conn.prepareStatement("SELECT id,uuid 
FROM storage_pool "
+                + "WHERE removed IS NULL;"); ResultSet rs = 
pstmt.executeQuery()) {
+            PreparedStatement updateStmt = conn.prepareStatement("update 
storage_pool set uuid = ? where id = ?");
+            while (rs.next()) {
+                if (!rs.getString(2).contains("-")) {
+                    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) {
+            LOG.error("fixWrongPoolUuid:Exception while updating faulty pool 
uuids" + ex.getMessage());
+            throw new CloudRuntimeException("fixWrongPoolUuid:Exception while 
updating faulty pool uuids", ex);

Review comment:
       We could extract this message to a variable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to