Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,4 +37,6 @@ public interface EndPointSelector {
EndPoint select(Scope scope, Long storeId);

EndPoint select(DataStore store, String downloadUrl);

EndPoint selectOneHypervisorHostByZone(long zoneId, HypervisorType hypervisorType);
}
5 changes: 5 additions & 0 deletions engine/schema/src/com/cloud/host/dao/HostDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,6 +71,10 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat

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);

/**
Expand Down
44 changes: 36 additions & 8 deletions engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +86,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao

protected SearchBuilder<HostVO> IdStatusSearch;
protected SearchBuilder<HostVO> TypeDcSearch;
protected SearchBuilder<HostVO> TypeDcStatusSearch;
protected SearchBuilder<HostVO> TypeClusterStatusSearch;
protected SearchBuilder<HostVO> MsStatusSearch;
protected SearchBuilder<HostVO> DcPrivateIpAddressSearch;
Expand Down Expand Up @@ -128,6 +128,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
protected GenericSearchBuilder<HostVO, Long> ClustersForHostsNotOwnedByAnyMSSearch;
protected GenericSearchBuilder<ClusterVO, Long> AllClustersSearch;
protected SearchBuilder<HostVO> HostsInClusterSearch;
protected SearchBuilder<HostVO> HostByHypervisor;

protected Attribute _statusAttr;
protected Attribute _resourceStateAttr;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,6 +77,8 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru,
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);
Expand Down Expand Up @@ -183,19 +187,21 @@ public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
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
Expand Down