Skip to content

Commit 84a8eb6

Browse files
CLOUDSTACK-9025: Fixed Unable to deploy VM instance from template if template spin from linked clone snapshot
Re-introduce the code to send CopyCommand to hypervisor host instead of SSVM which was changed due to code cleanup in PR apache#1124.
1 parent 4af82bb commit 84a8eb6

File tree

5 files changed

+64
-10
lines changed

5 files changed

+64
-10
lines changed

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.cloudstack.engine.subsystem.api.storage;
2020

21+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2122
import java.util.List;
2223

2324
public interface EndPointSelector {
@@ -36,4 +37,6 @@ public interface EndPointSelector {
3637
EndPoint select(Scope scope, Long storeId);
3738

3839
EndPoint select(DataStore store, String downloadUrl);
40+
41+
EndPoint selectOneHypervisorHostByZone(long zoneId, HypervisorType hypervisorType);
3942
}

engine/schema/src/com/cloud/host/dao/HostDao.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cloud.host.HostVO;
2525
import com.cloud.host.Status;
2626
import com.cloud.hypervisor.Hypervisor;
27+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2728
import com.cloud.info.RunningHostCountInfo;
2829
import com.cloud.resource.ResourceState;
2930
import com.cloud.utils.db.GenericDao;
@@ -70,6 +71,10 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
7071

7172
HostVO findByTypeNameAndZoneId(long zoneId, String name, Host.Type type);
7273

74+
HostVO findOneByZoneAndHypervisor(long zoneId, HypervisorType hypervisorType);
75+
76+
HostVO findOneDisabledByZoneAndHypervisor(long zoneId, HypervisorType hypervisorType);
77+
7378
List<HostVO> findHypervisorHostInCluster(long clusterId);
7479

7580
/**

engine/schema/src/com/cloud/host/dao/HostDaoImpl.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.cloud.host.Status;
5151
import com.cloud.host.Status.Event;
5252
import com.cloud.hypervisor.Hypervisor;
53+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
5354
import com.cloud.info.RunningHostCountInfo;
5455
import com.cloud.org.Grouping;
5556
import com.cloud.org.Managed;
@@ -85,7 +86,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
8586

8687
protected SearchBuilder<HostVO> IdStatusSearch;
8788
protected SearchBuilder<HostVO> TypeDcSearch;
88-
protected SearchBuilder<HostVO> TypeDcStatusSearch;
8989
protected SearchBuilder<HostVO> TypeClusterStatusSearch;
9090
protected SearchBuilder<HostVO> MsStatusSearch;
9191
protected SearchBuilder<HostVO> DcPrivateIpAddressSearch;
@@ -128,6 +128,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
128128
protected GenericSearchBuilder<HostVO, Long> ClustersForHostsNotOwnedByAnyMSSearch;
129129
protected GenericSearchBuilder<ClusterVO, Long> AllClustersSearch;
130130
protected SearchBuilder<HostVO> HostsInClusterSearch;
131+
protected SearchBuilder<HostVO> HostByHypervisor;
131132

132133
protected Attribute _statusAttr;
133134
protected Attribute _resourceStateAttr;
@@ -188,13 +189,6 @@ public void init() {
188189
SecondaryStorageVMSearch.and("status", SecondaryStorageVMSearch.entity().getStatus(), SearchCriteria.Op.EQ);
189190
SecondaryStorageVMSearch.done();
190191

191-
TypeDcStatusSearch = createSearchBuilder();
192-
TypeDcStatusSearch.and("type", TypeDcStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
193-
TypeDcStatusSearch.and("dc", TypeDcStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
194-
TypeDcStatusSearch.and("status", TypeDcStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ);
195-
TypeDcStatusSearch.and("resourceState", TypeDcStatusSearch.entity().getResourceState(), SearchCriteria.Op.EQ);
196-
TypeDcStatusSearch.done();
197-
198192
TypeClusterStatusSearch = createSearchBuilder();
199193
TypeClusterStatusSearch.and("type", TypeClusterStatusSearch.entity().getType(), SearchCriteria.Op.EQ);
200194
TypeClusterStatusSearch.and("cluster", TypeClusterStatusSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
@@ -410,6 +404,14 @@ public void init() {
410404
HostIdSearch.and("dataCenterId", HostIdSearch.entity().getDataCenterId(), Op.EQ);
411405
HostIdSearch.done();
412406

407+
HostByHypervisor = createSearchBuilder();
408+
HostByHypervisor.and("hypervisorType", HostByHypervisor.entity().getHypervisorType(), Op.EQ);
409+
HostByHypervisor.and("status", HostByHypervisor.entity().getStatus(), Op.EQ);
410+
HostByHypervisor.and("zoneId", HostByHypervisor.entity().getDataCenterId(), Op.EQ);
411+
HostByHypervisor.and("resourceState", HostByHypervisor.entity().getResourceState(), Op.EQ);
412+
HostByHypervisor.and("type", HostByHypervisor.entity().getType(), Op.EQ);
413+
HostByHypervisor.done();
414+
413415
_statusAttr = _allAttributes.get("status");
414416
_msIdAttr = _allAttributes.get("managementServerId");
415417
_pingTimeAttr = _allAttributes.get("lastPinged");
@@ -695,6 +697,32 @@ public void markHostsAsDisconnected(long msId, long lastPing) {
695697
update(ub, sc, null);
696698
}
697699

700+
@Override
701+
public HostVO findOneByZoneAndHypervisor(long zoneId, HypervisorType hypervisorType) {
702+
return findOneByZoneAndHypervisorAndResourceState(zoneId, hypervisorType, ResourceState.Enabled);
703+
}
704+
705+
private HostVO findOneByZoneAndHypervisorAndResourceState(long zoneId, HypervisorType hypervisorType, ResourceState enabled) {
706+
SearchCriteria<HostVO> sc = HostByHypervisor.create();
707+
sc.setParameters("hypervisorType", hypervisorType);
708+
sc.setParameters("zoneId", zoneId);
709+
sc.setParameters("status", Status.Up);
710+
sc.setParameters("resourceState", enabled);
711+
sc.setParameters("type", Type.Routing);
712+
713+
Filter filter = new Filter(1);
714+
List<HostVO> hostVOList = listBy(sc, filter);
715+
if (hostVOList.isEmpty()) {
716+
return null;
717+
}
718+
return hostVOList.get(0);
719+
}
720+
721+
@Override
722+
public HostVO findOneDisabledByZoneAndHypervisor(long zoneId, HypervisorType hypervisorType) {
723+
return findOneByZoneAndHypervisorAndResourceState(zoneId, hypervisorType, ResourceState.Disabled);
724+
}
725+
698726
@Override
699727
public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) {
700728

engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,18 @@ public EndPoint select(Scope scope, Long storeId) {
363363
return findEndPointInScope(scope, findOneHostOnPrimaryStorage, storeId);
364364
}
365365

366+
@Override
367+
public EndPoint selectOneHypervisorHostByZone(long zoneId, Hypervisor.HypervisorType hypervisorType) {
368+
Host host = hostDao.findOneByZoneAndHypervisor(zoneId, hypervisorType);
369+
if (host == null) {
370+
host = hostDao.findOneDisabledByZoneAndHypervisor(zoneId, hypervisorType);
371+
}
372+
if (host == null) {
373+
throw new CloudRuntimeException("There is no host available in Up status in zone: " + zoneId + " for hypervisor: " + hypervisorType);
374+
}
375+
return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
376+
}
377+
366378
@Override
367379
public List<EndPoint> selectAll(DataStore store) {
368380
List<EndPoint> endPoints = new ArrayList<EndPoint>();

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/XenServerGuru.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import javax.inject.Inject;
2424

25+
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
26+
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
2527
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
2628
import org.apache.cloudstack.framework.config.ConfigKey;
2729
import org.apache.cloudstack.framework.config.Configurable;
@@ -75,6 +77,8 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru,
7577
private UserVmDao _userVmDao;
7678
@Inject
7779
GuestOsDetailsDao _guestOsDetailsDao;
80+
@Inject
81+
EndPointSelector endPointSelector;
7882

7983
private static final ConfigKey<Integer> MaxNumberOfVCPUSPerVM = new ConfigKey<Integer>("Advanced", Integer.class, "xen.vm.vcpu.max", "16",
8084
"Maximum number of VCPUs that VM can get in XenServer.", true, ConfigKey.Scope.Cluster);
@@ -183,19 +187,21 @@ public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
183187
DataStoreTO destStore = destData.getDataStore();
184188
if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
185189
HostVO host = hostDao.findById(hostId);
190+
EndPoint ep = endPointSelector.selectOneHypervisorHostByZone(host.getDataCenterId(), HypervisorType.XenServer);
191+
host = hostDao.findById(ep.getId());
186192
hostDao.loadDetails(host);
187193
String hypervisorVersion = host.getHypervisorVersion();
188194
String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix);
189195
if (hypervisorVersion != null && !hypervisorVersion.equalsIgnoreCase("6.1.0")) {
190196
if (!(hypervisorVersion.equalsIgnoreCase("6.2.0") &&
191197
!(snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004)))) {
192-
return new Pair<Boolean, Long>(Boolean.TRUE, new Long(host.getId()));
198+
return new Pair<>(Boolean.TRUE, ep.getId());
193199
}
194200
}
195201
}
196202
}
197203
}
198-
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
204+
return new Pair<>(Boolean.FALSE, hostId);
199205
}
200206

201207
@Override

0 commit comments

Comments
 (0)