cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] DaanHoogland closed pull request #2709: check volumes for state when retrieving pool for configDrive creation
Date Wed, 18 Jul 2018 11:13:43 GMT
DaanHoogland closed pull request #2709: check volumes for state when retrieving pool for configDrive
creation
URL: https://github.com/apache/cloudstack/pull/2709
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
index 919d7bd9d18..4d2452d45ce 100644
--- a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
+++ b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
@@ -23,6 +23,7 @@
 
 import javax.inject.Inject;
 
+import com.cloud.storage.StoragePool;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@@ -30,6 +31,8 @@
 import org.apache.cloudstack.storage.configdrive.ConfigDrive;
 import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder;
 import org.apache.cloudstack.storage.to.TemplateObjectTO;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
@@ -56,7 +59,6 @@
 import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.Storage;
-import com.cloud.storage.StoragePool;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.GuestOSCategoryDao;
@@ -322,20 +324,11 @@ public void commitMigration(NicProfile nic, Network network, VirtualMachineProfi
     private DataStore findDataStore(VirtualMachineProfile profile, DeployDestination dest)
{
         DataStore dataStore = null;
         if (VirtualMachineManager.VmConfigDriveOnPrimaryPool.value()) {
-            if (dest.getStorageForDisks() != null) {
-                for (final Volume volume : dest.getStorageForDisks().keySet()) {
-                    if (volume.getVolumeType() == Volume.Type.ROOT) {
-                        final StoragePool primaryPool = dest.getStorageForDisks().get(volume);
-                        dataStore = _dataStoreMgr.getDataStore(primaryPool.getId(), DataStoreRole.Primary);
-                        break;
-                    }
-                }
+            if(MapUtils.isNotEmpty(dest.getStorageForDisks())) {
+                dataStore = getPlannedDataStore(dest, dataStore);
             }
             if (dataStore == null) {
-                final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(profile.getVirtualMachine().getId(),
Volume.Type.ROOT);
-                if (volumes != null && volumes.size() > 0) {
-                    dataStore = _dataStoreMgr.getDataStore(volumes.get(0).getPoolId(), DataStoreRole.Primary);
-                }
+                dataStore = pickExistingRootVolumeFromDataStore(profile, dataStore);
             }
         } else {
             dataStore = _dataStoreMgr.getImageStore(dest.getDataCenter().getId());
@@ -343,6 +336,66 @@ private DataStore findDataStore(VirtualMachineProfile profile, DeployDestination
         return dataStore;
     }
 
+    private DataStore getPlannedDataStore(DeployDestination dest, DataStore dataStore) {
+        for (final Volume volume : dest.getStorageForDisks().keySet()) {
+            if (volume.getVolumeType() == Volume.Type.ROOT) {
+                final StoragePool primaryPool = dest.getStorageForDisks().get(volume);
+                dataStore = _dataStoreMgr.getDataStore(primaryPool.getId(), DataStoreRole.Primary);
+                break;
+            }
+        }
+        return dataStore;
+    }
+
+    private DataStore pickExistingRootVolumeFromDataStore(VirtualMachineProfile profile,
DataStore dataStore) {
+        final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(profile.getVirtualMachine().getId(),
Volume.Type.ROOT);
+        if (CollectionUtils.isNotEmpty(volumes)) {
+            dataStore = pickDataStoreFromVolumes(volumes);
+        }
+        return dataStore;
+    }
+
+    private DataStore pickDataStoreFromVolumes(List<VolumeVO> volumes) {
+        DataStore dataStore = null;
+        for (Volume vol : volumes) {
+            if (doesVolumeStateCheckout(vol)) {
+                dataStore = _dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
+                if (dataStore != null) {
+                    return dataStore;
+                }
+            }
+        }
+        return dataStore;
+    }
+
+    private boolean doesVolumeStateCheckout(Volume vol) {
+        switch (vol.getState()) {
+        case Allocated:
+        case Creating:
+        case Ready:
+        case Snapshotting:
+        case RevertSnapshotting:
+        case Resizing:
+        case Copying:
+        case Attaching:
+            return true;
+        case Migrating:
+        case Expunging:
+        case Expunged:
+        case Destroy:
+        case Destroying:
+        case UploadOp:
+        case Uploaded:
+        case NotUploaded:
+        case UploadInProgress:
+        case UploadError:
+        case UploadAbandoned:
+            return false;
+        default:
+            throw new IllegalArgumentException("volume has a state that does not compute:
" +vol.getState());
+        }
+    }
+
     private Long findAgentIdForImageStore(final DataStore dataStore) throws ResourceUnavailableException
{
         EndPoint endpoint = _ep.select(dataStore);
         if (endpoint == null) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message