You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/11/09 13:23:19 UTC

[GitHub] [cloudstack] DaanHoogland commented on a diff in pull request #6879: Check for null volume pool ID when tagging

DaanHoogland commented on code in PR #6879:
URL: https://github.com/apache/cloudstack/pull/6879#discussion_r1017929924


##########
server/src/main/java/com/cloud/tags/TaggedResourceManagerImpl.java:
##########
@@ -318,7 +318,11 @@ public Map<String, String> getTagsFromResource(ResourceObjectType type, long res
     private void informStoragePoolForVmTags(long vmId, String key, String value) {
         List<VolumeVO> volumeVos = volumeDao.findByInstance(vmId);
         for (VolumeVO volume : volumeVos) {
-            DataStore dataStore = dataStoreMgr.getDataStore(volume.getPoolId(), DataStoreRole.Primary);
+            Long poolId = volume.getPoolId();
+            if (poolId == null) {
+                continue;
+            }
+            DataStore dataStore = dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
             if (dataStore == null || !(dataStore.getDriver() instanceof PrimaryDataStoreDriver)) {
                 continue;
             }

Review Comment:
   can you combine these and put them in a separate method?
   something like 
   ```
   DataStore dataStore = null;
   try {
       DataStore dataStore = retrieveDatastore(poolId);
   } catch (<local>Exception e) {
      log.info(String.format("no data store found for vm %s with poolId %d", vm.getName(), poolId));
       continue;
   }
   ```
   and move the code to new method `DataStore retrieveDatastore(Long poolId) {..}`



-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org