This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 0c13024329e refactor: remove duplicate inject (#7548)
0c13024329e is described below

commit 0c13024329e5119136efdbed52a205e5b0592461
Author: Abhishek Kumar <[email protected]>
AuthorDate: Fri May 26 07:19:54 2023 +0530

    refactor: remove duplicate inject (#7548)
    
    VolumeDao has been injected twice. This PR removes and refactors injection.
    
    Signed-off-by: Abhishek Kumar <[email protected]>
---
 .../java/com/cloud/storage/StorageManagerImpl.java | 48 +++++++++++-----------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java 
b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
index c1d17cc8f70..471aa6e2524 100644
--- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
@@ -19,6 +19,7 @@ package com.cloud.storage;
 import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
@@ -37,6 +38,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Random;
 import java.util.Set;
+import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -45,8 +47,6 @@ import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
-import com.google.common.collect.Sets;
-import com.cloud.vm.UserVmManager;
 import org.apache.cloudstack.annotation.AnnotationService;
 import org.apache.cloudstack.annotation.dao.AnnotationDao;
 import org.apache.cloudstack.api.ApiConstants;
@@ -229,11 +229,11 @@ import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.DiskProfile;
+import com.cloud.vm.UserVmManager;
 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;
+import com.google.common.collect.Sets;
 
 @Component
 public class StorageManagerImpl extends ManagerBase implements StorageManager, 
ClusterManagerListener, Configurable {
@@ -249,8 +249,6 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
     @Inject
     protected ConfigurationManager _configMgr;
     @Inject
-    protected VolumeDao _volsDao;
-    @Inject
     private VolumeDataStoreDao _volumeDataStoreDao;
     @Inject
     protected HostDao _hostDao;
@@ -299,7 +297,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
     @Inject
     protected HypervisorGuruManager _hvGuruMgr;
     @Inject
-    protected VolumeDao _volumeDao;
+    protected VolumeDao volumeDao;
     @Inject
     ConfigurationDao _configDao;
     @Inject
@@ -372,7 +370,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
     public boolean share(VMInstanceVO vm, List<VolumeVO> vols, HostVO host, 
boolean cancelPreviousShare) throws StorageUnavailableException {
 
         // if pool is in maintenance and it is the ONLY pool available; reject
-        List<VolumeVO> rootVolForGivenVm = 
_volsDao.findByInstanceAndType(vm.getId(), Type.ROOT);
+        List<VolumeVO> rootVolForGivenVm = 
volumeDao.findByInstanceAndType(vm.getId(), Type.ROOT);
         if (rootVolForGivenVm != null && rootVolForGivenVm.size() > 0) {
             boolean isPoolAvailable = 
isPoolAvailable(rootVolForGivenVm.get(0).getPoolId());
             if (!isPoolAvailable) {
@@ -436,7 +434,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
         for (StoragePoolHostVO storagePoolHostRef : storagePoolHostRefs) {
             StoragePoolVO PrimaryDataStoreVO = 
_storagePoolDao.findById(storagePoolHostRef.getPoolId());
             if (PrimaryDataStoreVO.getPoolType() == StoragePoolType.LVM || 
PrimaryDataStoreVO.getPoolType() == StoragePoolType.EXT) {
-                SearchBuilder<VolumeVO> volumeSB = 
_volsDao.createSearchBuilder();
+                SearchBuilder<VolumeVO> volumeSB = 
volumeDao.createSearchBuilder();
                 volumeSB.and("poolId", volumeSB.entity().getPoolId(), 
SearchCriteria.Op.EQ);
                 volumeSB.and("removed", volumeSB.entity().getRemoved(), 
SearchCriteria.Op.NULL);
                 volumeSB.and("state", volumeSB.entity().getState(), 
SearchCriteria.Op.NIN);
@@ -450,7 +448,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
                 volumeSC.setParameters("state", Volume.State.Expunging, 
Volume.State.Destroy);
                 volumeSC.setJoinParameters("activeVmSB", "state", 
State.Starting, State.Running, State.Stopping, State.Migrating);
 
-                List<VolumeVO> volumes = _volsDao.search(volumeSC, null);
+                List<VolumeVO> volumes = volumeDao.search(volumeSC, null);
                 if (volumes.size() > 0) {
                     return true;
                 }
@@ -598,7 +596,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
 
         StoragePoolSearch = _vmInstanceDao.createSearchBuilder();
 
-        SearchBuilder<VolumeVO> volumeSearch = 
_volumeDao.createSearchBuilder();
+        SearchBuilder<VolumeVO> volumeSearch = volumeDao.createSearchBuilder();
         volumeSearch.and("volumeType", volumeSearch.entity().getVolumeType(), 
SearchCriteria.Op.EQ);
         volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), 
SearchCriteria.Op.EQ);
         volumeSearch.and("state", volumeSearch.entity().getState(), 
SearchCriteria.Op.EQ);
@@ -1035,10 +1033,10 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
         List<StoragePoolVO> childStoragePools = 
_storagePoolDao.listChildStoragePoolsInDatastoreCluster(sPool.getId());
         boolean canDelete = true;
         for (StoragePoolVO childPool : childStoragePools) {
-            Pair<Long, Long> vlms = 
_volsDao.getCountAndTotalByPool(childPool.getId());
+            Pair<Long, Long> vlms = 
volumeDao.getCountAndTotalByPool(childPool.getId());
             if (forced) {
                 if (vlms.first() > 0) {
-                    Pair<Long, Long> nonDstrdVlms = 
_volsDao.getNonDestroyedCountAndTotalByPool(childPool.getId());
+                    Pair<Long, Long> nonDstrdVlms = 
volumeDao.getNonDestroyedCountAndTotalByPool(childPool.getId());
                     if (nonDstrdVlms.first() > 0) {
                         canDelete = false;
                         break;
@@ -1055,15 +1053,15 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
     }
 
     private boolean deleteDataStoreInternal(StoragePoolVO sPool, boolean 
forced) {
-        Pair<Long, Long> vlms = _volsDao.getCountAndTotalByPool(sPool.getId());
+        Pair<Long, Long> vlms = 
volumeDao.getCountAndTotalByPool(sPool.getId());
         if (forced) {
             if (vlms.first() > 0) {
-                Pair<Long, Long> nonDstrdVlms = 
_volsDao.getNonDestroyedCountAndTotalByPool(sPool.getId());
+                Pair<Long, Long> nonDstrdVlms = 
volumeDao.getNonDestroyedCountAndTotalByPool(sPool.getId());
                 if (nonDstrdVlms.first() > 0) {
                     throw new CloudRuntimeException("Cannot delete pool " + 
sPool.getName() + " as there are associated " + "non-destroyed vols for this 
pool");
                 }
                 // force expunge non-destroyed volumes
-                List<VolumeVO> vols = _volsDao.listVolumesToBeDestroyed();
+                List<VolumeVO> vols = volumeDao.listVolumesToBeDestroyed();
                 for (VolumeVO vol : vols) {
                     AsyncCallFuture<VolumeApiResult> future = 
volService.expungeVolumeAsync(volFactory.getVolume(vol.getId()));
                     try {
@@ -1326,7 +1324,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
                     }
                     cleanupSecondaryStorage(recurring);
 
-                    List<VolumeVO> vols = 
_volsDao.listVolumesToBeDestroyed(new Date(System.currentTimeMillis() - 
((long)StorageCleanupDelay.value() << 10)));
+                    List<VolumeVO> vols = 
volumeDao.listVolumesToBeDestroyed(new Date(System.currentTimeMillis() - 
((long)StorageCleanupDelay.value() << 10)));
                     for (VolumeVO vol : vols) {
                         if (Type.ROOT.equals(vol.getVolumeType())) {
                              VMInstanceVO vmInstanceVO = 
_vmInstanceDao.findById(vol.getInstanceId());
@@ -1375,7 +1373,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
                     // destroy uploaded volumes in abandoned/error state
                     List<VolumeDataStoreVO> volumeDataStores = 
_volumeDataStoreDao.listByVolumeState(Volume.State.UploadError, 
Volume.State.UploadAbandoned);
                     for (VolumeDataStoreVO volumeDataStore : volumeDataStores) 
{
-                        VolumeVO volume = 
_volumeDao.findById(volumeDataStore.getVolumeId());
+                        VolumeVO volume = 
volumeDao.findById(volumeDataStore.getVolumeId());
                         if (volume == null) {
                             s_logger.warn("Uploaded volume with id " + 
volumeDataStore.getVolumeId() + " not found, so cannot be destroyed");
                             continue;
@@ -1948,7 +1946,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
 
         for (String childDatastoreUUID : childDatastoreUUIDs) {
             StoragePoolVO dataStoreVO = 
_storagePoolDao.findPoolByUUID(childDatastoreUUID);
-            List<VolumeVO> allVolumes = 
_volumeDao.findByPoolId(dataStoreVO.getId());
+            List<VolumeVO> allVolumes = 
volumeDao.findByPoolId(dataStoreVO.getId());
             allVolumes.removeIf(volumeVO -> volumeVO.getInstanceId() == null);
             allVolumes.removeIf(volumeVO -> volumeVO.getState() != 
Volume.State.Ready);
             for (VolumeVO volume : allVolumes) {
@@ -1984,7 +1982,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
                         volume.getUuid() + "Host=" + hostId;
 
                 // check for the changed details of volume and update database
-                VolumeVO volumeVO = _volumeDao.findById(volumeId);
+                VolumeVO volumeVO = volumeDao.findById(volumeId);
                 String datastoreName = answer.getContextParam("datastoreName");
                 if (datastoreName != null) {
                     StoragePoolVO storagePoolVO = 
_storagePoolDao.findByUuid(datastoreName);
@@ -2005,7 +2003,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
                     volumeVO.setChainInfo(chainInfo);
                 }
 
-                _volumeDao.update(volumeVO.getId(), volumeVO);
+                volumeDao.update(volumeVO.getId(), volumeVO);
             }
             dataStoreVO.setParent(0L);
             _storagePoolDao.update(dataStoreVO.getId(), dataStoreVO);
@@ -2426,14 +2424,14 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
             // might be clearer that this "volume" in "volumeDiskProfilesList" 
still might have an old value for hv_ss_reverse.
             Volume volume = volumeDiskProfilePair.first();
             DiskProfile diskProfile = volumeDiskProfilePair.second();
-            VolumeVO volumeVO = _volumeDao.findById(volume.getId());
+            VolumeVO volumeVO = volumeDao.findById(volume.getId());
 
             if (volumeVO.getHypervisorSnapshotReserve() == null) {
                 // update the volume's hv_ss_reserve (hypervisor snapshot 
reserve) from a disk offering (used for managed storage)
                 
volService.updateHypervisorSnapshotReserveForVolume(getDiskOfferingVO(volumeVO),
 volumeVO.getId(), getHypervisorType(volumeVO));
 
                 // hv_ss_reserve field might have been updated; refresh from 
DB to make use of it in getDataObjectSizeIncludingHypervisorSnapshotReserve
-                volumeVO = _volumeDao.findById(volume.getId());
+                volumeVO = volumeDao.findById(volume.getId());
             }
 
             // this if statement should resolve to true at most once per 
execution of the for loop its contained within (for a root disk that is
@@ -3271,9 +3269,9 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
             if (activeVolumeIds.contains(volumeId)) {
                 continue;
             }
-            Volume volume = _volumeDao.findById(volumeId);
+            Volume volume = volumeDao.findById(volumeId);
             if (volume != null && volume.getState() == Volume.State.Expunged) {
-                _volumeDao.remove(volumeId);
+                volumeDao.remove(volumeId);
             }
         }
 

Reply via email to