[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-9025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16314470#comment-16314470
 ] 

ASF GitHub Bot commented on CLOUDSTACK-9025:
--------------------------------------------

DaanHoogland closed pull request #2317: CLOUDSTACK-9025: Fixed Unable to deploy 
VM instance from template if …
URL: https://github.com/apache/cloudstack/pull/2317
 
 
   

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/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
 
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
index 0613a11572f..20e143e4fb9 100644
--- 
a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
+++ 
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cloudstack.engine.subsystem.api.storage;
 
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import java.util.List;
 
 public interface EndPointSelector {
@@ -36,4 +37,6 @@
     EndPoint select(Scope scope, Long storeId);
 
     EndPoint select(DataStore store, String downloadUrl);
+
+    EndPoint selectOneHypervisorHostByZone(long zoneId, HypervisorType 
hypervisorType);
 }
diff --git a/engine/schema/src/com/cloud/host/dao/HostDao.java 
b/engine/schema/src/com/cloud/host/dao/HostDao.java
index f98e8c19eeb..419b8930517 100644
--- a/engine/schema/src/com/cloud/host/dao/HostDao.java
+++ b/engine/schema/src/com/cloud/host/dao/HostDao.java
@@ -24,6 +24,7 @@
 import com.cloud.host.HostVO;
 import com.cloud.host.Status;
 import com.cloud.hypervisor.Hypervisor;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.info.RunningHostCountInfo;
 import com.cloud.resource.ResourceState;
 import com.cloud.utils.db.GenericDao;
@@ -70,6 +71,10 @@
 
     HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type);
 
+    HostVO findOneByZoneAndHypervisor(long zoneId, HypervisorType 
hypervisorType);
+
+    HostVO findOneDisabledByZoneAndHypervisor(long zoneId, HypervisorType 
hypervisorType);
+
     List<HostVO> findHypervisorHostInCluster(long clusterId);
 
     /**
diff --git a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java 
b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
index d08b40281e6..a70d6e1612f 100644
--- a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
+++ b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
@@ -50,6 +50,7 @@
 import com.cloud.host.Status;
 import com.cloud.host.Status.Event;
 import com.cloud.hypervisor.Hypervisor;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.info.RunningHostCountInfo;
 import com.cloud.org.Grouping;
 import com.cloud.org.Managed;
@@ -85,7 +86,6 @@
 
     protected SearchBuilder<HostVO> IdStatusSearch;
     protected SearchBuilder<HostVO> TypeDcSearch;
-    protected SearchBuilder<HostVO> TypeDcStatusSearch;
     protected SearchBuilder<HostVO> TypeClusterStatusSearch;
     protected SearchBuilder<HostVO> MsStatusSearch;
     protected SearchBuilder<HostVO> DcPrivateIpAddressSearch;
@@ -128,6 +128,7 @@
     protected GenericSearchBuilder<HostVO, Long> 
ClustersForHostsNotOwnedByAnyMSSearch;
     protected GenericSearchBuilder<ClusterVO, Long> AllClustersSearch;
     protected SearchBuilder<HostVO> HostsInClusterSearch;
+    protected SearchBuilder<HostVO> HostByHypervisor;
 
     protected Attribute _statusAttr;
     protected Attribute _resourceStateAttr;
@@ -188,13 +189,6 @@ public void init() {
         SecondaryStorageVMSearch.and("status", 
SecondaryStorageVMSearch.entity().getStatus(), SearchCriteria.Op.EQ);
         SecondaryStorageVMSearch.done();
 
-        TypeDcStatusSearch = createSearchBuilder();
-        TypeDcStatusSearch.and("type", TypeDcStatusSearch.entity().getType(), 
SearchCriteria.Op.EQ);
-        TypeDcStatusSearch.and("dc", 
TypeDcStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
-        TypeDcStatusSearch.and("status", 
TypeDcStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
-        TypeDcStatusSearch.and("resourceState", 
TypeDcStatusSearch.entity().getResourceState(), SearchCriteria.Op.EQ);
-        TypeDcStatusSearch.done();
-
         TypeClusterStatusSearch = createSearchBuilder();
         TypeClusterStatusSearch.and("type", 
TypeClusterStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
         TypeClusterStatusSearch.and("cluster", 
TypeClusterStatusSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
@@ -410,6 +404,14 @@ public void init() {
         HostIdSearch.and("dataCenterId", 
HostIdSearch.entity().getDataCenterId(), Op.EQ);
         HostIdSearch.done();
 
+        HostByHypervisor = createSearchBuilder();
+        HostByHypervisor.and("hypervisorType", 
HostByHypervisor.entity().getHypervisorType(), Op.EQ);
+        HostByHypervisor.and("status", HostByHypervisor.entity().getStatus(), 
Op.EQ);
+        HostByHypervisor.and("zoneId", 
HostByHypervisor.entity().getDataCenterId(), Op.EQ);
+        HostByHypervisor.and("resourceState", 
HostByHypervisor.entity().getResourceState(), Op.EQ);
+        HostByHypervisor.and("type", HostByHypervisor.entity().getType(), 
Op.EQ);
+        HostByHypervisor.done();
+
         _statusAttr = _allAttributes.get("status");
         _msIdAttr = _allAttributes.get("managementServerId");
         _pingTimeAttr = _allAttributes.get("lastPinged");
@@ -695,6 +697,32 @@ public void markHostsAsDisconnected(long msId, long 
lastPing) {
         update(ub, sc, null);
     }
 
+    @Override
+    public HostVO findOneByZoneAndHypervisor(long zoneId, HypervisorType 
hypervisorType) {
+        return findOneByZoneAndHypervisorAndResourceState(zoneId, 
hypervisorType, ResourceState.Enabled);
+    }
+
+    private HostVO findOneByZoneAndHypervisorAndResourceState(long zoneId, 
HypervisorType hypervisorType, ResourceState enabled) {
+        SearchCriteria<HostVO> sc = HostByHypervisor.create();
+        sc.setParameters("hypervisorType", hypervisorType);
+        sc.setParameters("zoneId", zoneId);
+        sc.setParameters("status", Status.Up);
+        sc.setParameters("resourceState", enabled);
+        sc.setParameters("type", Type.Routing);
+
+        Filter filter = new Filter(1);
+        List<HostVO> hostVOList = listBy(sc, filter);
+        if (hostVOList.isEmpty()) {
+            return null;
+        }
+        return hostVOList.get(0);
+    }
+
+    @Override
+    public HostVO findOneDisabledByZoneAndHypervisor(long zoneId, 
HypervisorType hypervisorType) {
+        return findOneByZoneAndHypervisorAndResourceState(zoneId, 
hypervisorType, ResourceState.Disabled);
+    }
+
     @Override
     public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long 
podId, long dcId, String hostTag) {
 
diff --git 
a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
 
b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
index e414b6c4c35..625bb178a01 100644
--- 
a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
+++ 
b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
@@ -363,6 +363,18 @@ public EndPoint select(Scope scope, Long storeId) {
         return findEndPointInScope(scope, findOneHostOnPrimaryStorage, 
storeId);
     }
 
+    @Override
+    public EndPoint selectOneHypervisorHostByZone(long zoneId, 
Hypervisor.HypervisorType hypervisorType) {
+        Host host = hostDao.findOneByZoneAndHypervisor(zoneId, hypervisorType);
+        if (host == null) {
+            host = hostDao.findOneDisabledByZoneAndHypervisor(zoneId, 
hypervisorType);
+        }
+        if (host == null) {
+            throw new CloudRuntimeException("There is no host available in Up 
status in zone: " + zoneId + " for hypervisor: " + hypervisorType);
+        }
+        return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
+    }
+
     @Override
     public List<EndPoint> selectAll(DataStore store) {
         List<EndPoint> endPoints = new ArrayList<EndPoint>();
diff --git 
a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/XenServerGuru.java 
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/XenServerGuru.java
index 74f989bf0f2..1e766d2a0f1 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/XenServerGuru.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/XenServerGuru.java
@@ -22,6 +22,8 @@
 
 import javax.inject.Inject;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.Configurable;
@@ -75,6 +77,8 @@
     private UserVmDao _userVmDao;
     @Inject
     GuestOsDetailsDao _guestOsDetailsDao;
+    @Inject
+    EndPointSelector endPointSelector;
 
     private static final ConfigKey<Integer> MaxNumberOfVCPUSPerVM = new 
ConfigKey<Integer>("Advanced", Integer.class, "xen.vm.vcpu.max", "16",
             "Maximum number of VCPUs that VM can get in XenServer.", true, 
ConfigKey.Scope.Cluster);
@@ -183,19 +187,21 @@ public boolean trackVmHostChange() {
                 DataStoreTO destStore = destData.getDataStore();
                 if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
                     HostVO host = hostDao.findById(hostId);
+                    EndPoint ep = 
endPointSelector.selectOneHypervisorHostByZone(host.getDataCenterId(), 
HypervisorType.XenServer);
+                    host = hostDao.findById(ep.getId());
                     hostDao.loadDetails(host);
                     String hypervisorVersion = host.getHypervisorVersion();
                     String snapshotHotFixVersion = 
host.getDetail(XenserverConfigs.XS620HotFix);
                     if (hypervisorVersion != null && 
!hypervisorVersion.equalsIgnoreCase("6.1.0")) {
                         if (!(hypervisorVersion.equalsIgnoreCase("6.2.0") &&
                                 !(snapshotHotFixVersion != null && 
snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)))) {
-                            return new Pair<Boolean, Long>(Boolean.TRUE, new 
Long(host.getId()));
+                            return new Pair<>(Boolean.TRUE, ep.getId());
                         }
                     }
                 }
             }
         }
-        return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
+        return new Pair<>(Boolean.FALSE, hostId);
     }
 
     @Override


 

----------------------------------------------------------------
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:
us...@infra.apache.org


> Unable to deploy VM instance from template if template spin from linked clone 
> snapshot
> --------------------------------------------------------------------------------------
>
>                 Key: CLOUDSTACK-9025
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-9025
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: XenServer
>    Affects Versions: 4.5.2
>         Environment: XenServer 6.5
>            Reporter: Anshul Gangwar
>            Assignee: Anshul Gangwar
>            Priority: Critical
>             Fix For: 4.6.0
>
>
> As default, CloudStack create linked clone snapshot for VM instance . When we 
> take a snapshot for the VM, and create a template based on such snapshot, 
> CloudStack only download incremental VHD as template file, as a result, the 
> VM instance fail to deploy as it is incomplete.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to