nvazquez commented on a change in pull request #5382:
URL: https://github.com/apache/cloudstack/pull/5382#discussion_r697808315
##########
File path: server/src/main/java/com/cloud/storage/StorageManagerImpl.java
##########
@@ -1834,6 +1836,42 @@ public void syncDatastoreClusterStoragePool(long
datastoreClusterPoolId, List<Mo
handleRemoveChildStoragePoolFromDatastoreCluster(childDatastoreUUIDs);
}
+ /**
+ * fixed mismatching between db uuids and and custom
+ * attribute uuids
+ *
+ * To different formats of uuids exists
+ * 1. xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+ * 2. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ * @param uuid of existing pool
+ * @return existing pull or null otherwise
+ */
+ private StoragePoolVO getExistingPoolByUuid(String uuid){
+ StoragePoolVO storagePool = _storagePoolDao.findByUuid(uuid);
+ if(storagePool != null){
+ return storagePool;
+ }
+
+ //this case is unlikely (DB uuid without separators), but safety first
+ if(uuid.contains("-")){
+ uuid = uuid.replaceAll("-", "");
+ storagePool = _storagePoolDao.findByUuid(uuid);
+ if(storagePool != null){
+ return storagePool;
+ }
+ }
+
+ //transform uuid in the valid format with separators
+ UUID poolUuid;
+ poolUuid = new UUID(
+ new BigInteger(uuid.substring(0, 16), 16).longValue(),
+ new BigInteger(uuid.substring(16), 16).longValue()
+ );
+
+ return _storagePoolDao.findByUuid(poolUuid.toString());
+ }
Review comment:
```suggestion
private StoragePoolVO getExistingPoolByUuid(String uuid){
String removedSepators = uuid.contains("-") ? uuid.replaceAll("-",
"") : null;
String formatted = new UUID(
new BigInteger(uuid.substring(0, 16), 16).longValue(),
new BigInteger(uuid.substring(16),
16).longValue()).toString();
List<String> options = Arrays.asList(uuid, removedSepators,
formatted);
return getFirstValidStoragePoolFromUuidOptions(options);
}
private StoragePoolVO
getFirstValidStoragePoolFromUuidOptions(List<String> uuids) {
for (String uuid : uuids) {
if (StringUtils.isBlank(uuid)) {
continue;
}
StoragePoolVO pool = _storagePoolDao.findByUuid(uuid);
if (pool != null) {
return pool;
}
}
return null;
}
```
I think something like this could help readability. Can also add unit tests
for the new method passing different options as a parameter
--
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]