DaanHoogland closed pull request #2512: Only use the host if its Resource State 
is Enabled.
URL: https://github.com/apache/cloudstack/pull/2512
 
 
   

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/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
 
b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
index 30cff850c88..45e951b59a1 100644
--- 
a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
+++ 
b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
@@ -43,6 +43,7 @@
 import com.cloud.host.dao.HostDao;
 import com.cloud.host.dao.HostDetailsDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.resource.ResourceState;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.DiskOfferingVO;
 import com.cloud.storage.Snapshot;
@@ -1933,7 +1934,11 @@ private HostVO getHostInCluster(long clusterId) {
         if (hosts != null && hosts.size() > 0) {
             Collections.shuffle(hosts, RANDOM);
 
-            return hosts.get(0);
+            for (HostVO host : hosts) {
+                if (ResourceState.Enabled.equals(host.getResourceState())) {
+                    return host;
+                }
+            }
         }
 
         throw new CloudRuntimeException("Unable to locate a host");
@@ -1954,6 +1959,10 @@ private HostVO getHost(Long zoneId, HypervisorType 
hypervisorType, boolean compu
         Collections.shuffle(hosts, RANDOM);
 
         for (HostVO host : hosts) {
+            if (!ResourceState.Enabled.equals(host.getResourceState())) {
+                continue;
+            }
+
             if (computeClusterMustSupportResign) {
                 long clusterId = host.getClusterId();
 
diff --git 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
index 88c385b4e61..a6fe50e2581 100644
--- 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
+++ 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java
@@ -25,7 +25,6 @@
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventUtils;
 import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -56,7 +55,6 @@
 import com.cloud.vm.snapshot.VMSnapshotService;
 import com.cloud.vm.snapshot.VMSnapshotVO;
 import com.cloud.vm.snapshot.dao.VMSnapshotDao;
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
@@ -86,6 +84,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Random;
 import java.util.UUID;
 
@@ -102,14 +101,14 @@
     @Inject private SnapshotDao snapshotDao;
     @Inject private SnapshotDataFactory snapshotDataFactory;
     @Inject private SnapshotDetailsDao snapshotDetailsDao;
-    @Inject SnapshotDataStoreDao snapshotStoreDao;
+    @Inject private SnapshotDataStoreDao snapshotStoreDao;
     @Inject private VolumeDetailsDao volumeDetailsDao;
     @Inject private VMInstanceDao vmInstanceDao;
     @Inject private VMSnapshotDao vmSnapshotDao;
     @Inject private VMSnapshotService vmSnapshotService;
     @Inject private VolumeDao volumeDao;
     @Inject private VolumeService volService;
-    @Inject private VolumeDetailsDao _volumeDetailsDaoImpl;
+    @Inject private VolumeDetailsDao volumeDetailsDaoImpl;
 
     @Override
     public SnapshotInfo backupSnapshot(SnapshotInfo snapshotInfo) {
@@ -200,7 +199,7 @@ private boolean cleanupSnapshotOnPrimaryStore(long 
snapshotId) {
         try {
             snapshotObj.processEvent(Snapshot.Event.DestroyRequested);
 
-            List<VolumeDetailVO> volumesFromSnapshot = 
_volumeDetailsDaoImpl.findDetails("SNAPSHOT_ID", String.valueOf(snapshotId), 
null);
+            List<VolumeDetailVO> volumesFromSnapshot = 
volumeDetailsDaoImpl.findDetails("SNAPSHOT_ID", String.valueOf(snapshotId), 
null);
 
             if (volumesFromSnapshot.size() > 0) {
                 try {
@@ -471,20 +470,11 @@ else if (volumeInfo.getFormat() == ImageFormat.OVA || 
volumeInfo.getFormat() ==
         if (ImageFormat.OVA.equals(volumeInfo.getFormat())) {
             setVmdk(snapshotInfo, volumeInfo);
 
-            try {
-                vmSnapshot = takeHypervisorSnapshot(volumeInfo);
-            }
-            catch (ResourceAllocationException ex) {
-                String errMsg = "Unable to allocate VM snapshot";
-
-                s_logger.error(errMsg, ex);
-
-                throw new CloudRuntimeException(errMsg, ex);
-            }
+            vmSnapshot = takeHypervisorSnapshot(volumeInfo);
         }
 
         SnapshotResult result = null;
-        SnapshotInfo snapshotOnPrimary = null;
+        SnapshotInfo snapshotOnPrimary;
 
         try {
             volumeInfo.stateTransit(Volume.Event.SnapshotRequested);
@@ -549,7 +539,7 @@ public void postSnapshotCreation(SnapshotInfo snapshot) {
 
     }
 
-    private VMSnapshot takeHypervisorSnapshot(VolumeInfo volumeInfo) throws 
ResourceAllocationException {
+    private VMSnapshot takeHypervisorSnapshot(VolumeInfo volumeInfo) {
         VirtualMachine virtualMachine = volumeInfo.getAttachedVM();
 
         if (virtualMachine != null && 
VirtualMachine.State.Running.equals(virtualMachine.getState())) {
@@ -678,7 +668,8 @@ private void performSnapshotAndCopyOnHostSide(VolumeInfo 
volumeInfo, SnapshotInf
         if (hostId != null) {
             hostVO = hostDao.findById(hostId);
         }
-        else {
+
+        if (hostVO == null || 
!ResourceState.Enabled.equals(hostVO.getResourceState())) {
             Optional<HostVO> optHostVO = getHost(volumeInfo.getDataCenterId(), 
false);
 
             if (optHostVO.isPresent()) {
@@ -836,7 +827,7 @@ private HostVO getHost(long zoneId, Long hostId) {
 
         HostVO hostVO = hostDao.findById(hostId);
 
-        if (hostVO != null) {
+        if (hostVO != null && 
ResourceState.Enabled.equals(hostVO.getResourceState())) {
             return hostVO;
         }
 
@@ -867,7 +858,7 @@ private HostVO getHost(long zoneId, Long hostId) {
                     Collections.shuffle(hosts, new Random(System.nanoTime()));
 
                     for (HostVO host : hosts) {
-                        if (host.getResourceState() == ResourceState.Enabled) {
+                        if 
(ResourceState.Enabled.equals(host.getResourceState())) {
                             if (computeClusterMustSupportResign) {
                                 if 
(clusterDao.getSupportsResigning(cluster.getId())) {
                                     return Optional.of(host);
@@ -886,7 +877,7 @@ private HostVO getHost(long zoneId, Long hostId) {
             }
         }
 
-        return Optional.absent();
+        return Optional.empty();
     }
 
     private void markAsBackedUp(SnapshotObject snapshotObj) {


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to