Merge pull request #1124 from rafaelweingartner/CID-1338387

CID-1338387: Deletion of method endPointSelector.selectHypervisorHostFollowing the discussions and analysis presented on PR #1056 create by @DaanHoogland
This PR is intended to push those changes that were discussed there regarding the of endPointSelector.selectHypervisorHost method.

* pr/1124:
  Deletion of method endPointSelector.selectHypervisorHost

Signed-off-by: Will Stevens <williamstevens@gmail.com>
This commit is contained in:
Will Stevens 2016-05-10 23:47:49 -04:00
commit 8a3fd10615
5 changed files with 26 additions and 134 deletions

View File

@ -35,7 +35,5 @@ public interface EndPointSelector {
EndPoint select(Scope scope, Long storeId);
EndPoint selectHypervisorHost(Scope scope);
EndPoint select(DataStore store, String downloadUrl);
}

View File

@ -29,9 +29,6 @@ import java.util.List;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
@ -43,6 +40,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.storage.LocalHostEndpoint;
import org.apache.cloudstack.storage.RemoteHostEndPoint;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.capacity.CapacityManager;
import com.cloud.host.Host;
@ -64,7 +63,7 @@ import com.cloud.vm.VirtualMachine;
public class DefaultEndPointSelector implements EndPointSelector {
private static final Logger s_logger = Logger.getLogger(DefaultEndPointSelector.class);
@Inject
HostDao hostDao;
private HostDao hostDao;
private final String findOneHostOnPrimaryStorage = "select t.id from "
+ "(select h.id, cd.value "
+ "from host h join storage_pool_host_ref s on h.id = s.host_id "
@ -72,8 +71,6 @@ public class DefaultEndPointSelector implements EndPointSelector {
+ "left join cluster_details cd on c.id=cd.cluster_id and cd.name='" + CapacityManager.StorageOperationsExcludeCluster.key() + "' "
+ "where h.status = 'Up' and h.type = 'Routing' and h.resource_state = 'Enabled' and s.pool_id = ? ";
private String findOneHypervisorHostInScope = "select h.id from host h where h.status = 'Up' and h.hypervisor_type is not null ";
protected boolean moveBetweenPrimaryImage(DataStore srcStore, DataStore destStore) {
DataStoreRole srcRole = srcStore.getRole();
DataStoreRole destRole = destStore.getRole();
@ -266,8 +263,9 @@ public class DefaultEndPointSelector implements EndPointSelector {
public EndPoint select(DataObject object) {
DataStore store = object.getDataStore();
EndPoint ep = select(store);
if (ep != null)
if (ep != null) {
return ep;
}
if (object instanceof TemplateInfo) {
TemplateInfo tmplInfo = (TemplateInfo)object;
if (store.getScope().getScopeType() == ScopeType.ZONE && store.getScope().getScopeId() == null && tmplInfo.getTemplateType() == TemplateType.SYSTEM) {
@ -386,40 +384,4 @@ public class DefaultEndPointSelector implements EndPointSelector {
}
return endPoints;
}
@Override
public EndPoint selectHypervisorHost(Scope scope) {
StringBuilder sbuilder = new StringBuilder();
sbuilder.append(findOneHypervisorHostInScope);
if (scope.getScopeType() == ScopeType.ZONE) {
sbuilder.append(" and h.data_center_id = ");
sbuilder.append(scope.getScopeId());
} else if (scope.getScopeType() == ScopeType.CLUSTER) {
sbuilder.append(" and h.cluster_id = ");
sbuilder.append(scope.getScopeId());
}
sbuilder.append(" ORDER by rand() limit 1");
String sql = sbuilder.toString();
HostVO host = null;
TransactionLegacy txn = TransactionLegacy.currentTxn();
try (
PreparedStatement pstmt = txn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
) {
while (rs.next()) {
long id = rs.getLong(1);
host = hostDao.findById(id);
}
} catch (SQLException e) {
s_logger.warn("can't find endpoint", e);
}
if (host == null) {
return null;
}
return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
}
}

View File

@ -19,21 +19,11 @@ package com.cloud.hypervisor.ovm3.resources;
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.ZoneScope;
import org.apache.cloudstack.storage.command.CopyCommand;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataObjectType;
import com.cloud.agent.api.to.DataStoreTO;
import com.cloud.agent.api.to.DataTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.HypervisorGuru;
import com.cloud.hypervisor.HypervisorGuruBase;
@ -45,15 +35,7 @@ import com.cloud.vm.VirtualMachineProfile;
public class Ovm3HypervisorGuru extends HypervisorGuruBase implements HypervisorGuru {
private final Logger LOGGER = Logger.getLogger(Ovm3HypervisorGuru.class);
@Inject
GuestOSDao guestOsDao;
@Inject
EndPointSelector endPointSelector;
@Inject
HostDao hostDao;
protected Ovm3HypervisorGuru() {
super();
}
private GuestOSDao guestOsDao;
@Override
public HypervisorType getHypervisorType() {
@ -65,7 +47,6 @@ public class Ovm3HypervisorGuru extends HypervisorGuruBase implements Hypervisor
VirtualMachineTO to = toVirtualMachineTO(vm);
to.setBootloader(vm.getBootLoaderType());
// Determine the VM's OS description
GuestOSVO guestOS = guestOsDao.findById(vm.getVirtualMachine()
.getGuestOSId());
to.setOs(guestOS.getDisplayName());
@ -78,35 +59,13 @@ public class Ovm3HypervisorGuru extends HypervisorGuruBase implements Hypervisor
return true;
}
/* I dislike the notion of having to place this here, and not being able to just override
*
* (non-Javadoc)
* @see com.cloud.hypervisor.HypervisorGuruBase#getCommandHostDelegation(long, com.cloud.agent.api.Command)
*/
@Override
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
LOGGER.debug("getCommandHostDelegation: " + cmd.getClass());
if (cmd instanceof StorageSubSystemCommand) {
StorageSubSystemCommand c = (StorageSubSystemCommand)cmd;
c.setExecuteInSequence(true);
}
if (cmd instanceof CopyCommand) {
CopyCommand cpyCommand = (CopyCommand)cmd;
DataTO srcData = cpyCommand.getSrcTO();
DataTO destData = cpyCommand.getDestTO();
if (HypervisorType.Ovm3.equals(srcData.getHypervisorType()) && srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE) {
LOGGER.debug("Snapshot to Template: " + cmd);
DataStoreTO srcStore = srcData.getDataStore();
DataStoreTO destStore = destData.getDataStore();
if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
HostVO host = hostDao.findById(hostId);
EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
if (ep != null) {
return new Pair<Boolean, Long>(Boolean.TRUE, Long.valueOf(ep.getId()));
}
}
}
}
return new Pair<Boolean, Long>(Boolean.FALSE, Long.valueOf(hostId));
}
}

View File

@ -18,14 +18,11 @@ package com.cloud.hypervisor;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
import org.apache.cloudstack.storage.command.CopyCommand;
@ -33,7 +30,7 @@ import org.apache.cloudstack.storage.command.DettachCommand;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.log4j.Logger;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataObjectType;
@ -57,34 +54,27 @@ import com.cloud.vm.UserVmVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.UserVmDao;
import org.apache.log4j.Logger;
public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable {
private final Logger LOGGER = Logger.getLogger(XenServerGuru.class);
@Inject
GuestOSDao _guestOsDao;
private GuestOSDao _guestOsDao;
@Inject
GuestOSHypervisorDao _guestOsHypervisorDao;
private GuestOSHypervisorDao _guestOsHypervisorDao;
@Inject
EndPointSelector endPointSelector;
private HostDao hostDao;
@Inject
HostDao hostDao;
private VolumeDao _volumeDao;
@Inject
VolumeDao _volumeDao;
private PrimaryDataStoreDao _storagePoolDao;
@Inject
PrimaryDataStoreDao _storagePoolDao;
private VolumeDataFactory _volFactory;
@Inject
VolumeDataFactory _volFactory;
@Inject
UserVmDao _userVmDao;
private UserVmDao _userVmDao;
static final ConfigKey<Integer> MaxNumberOfVCPUSPerVM = new ConfigKey<Integer>("Advanced", Integer.class, "xen.vm.vcpu.max", "16",
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);
protected XenServerGuru() {
super();
}
@Override
public HypervisorType getHypervisorType() {
return HypervisorType.XenServer;
@ -129,11 +119,6 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru,
return true;
}
@Override
public Map<String, String> getClusterSettings(long vmId) {
return null;
}
@Override
public List<Command> finalizeExpungeVolumes(VirtualMachine vm) {
List<Command> commands = new ArrayList<Command>();
@ -189,15 +174,13 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru,
DataStoreTO destStore = destData.getDataStore();
if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
HostVO host = hostDao.findById(hostId);
EndPoint ep = endPointSelector.selectHypervisorHost(new ZoneScope(host.getDataCenterId()));
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(ep.getId()));
return new Pair<Boolean, Long>(Boolean.TRUE, new Long(host.getId()));
}
}
}

View File

@ -33,11 +33,9 @@ import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.offering.ServiceOffering;
import com.cloud.resource.ResourceManager;
import com.cloud.server.ConfigurationServer;
import com.cloud.service.ServiceOfferingDetailsVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.service.dao.ServiceOfferingDetailsDao;
import com.cloud.storage.dao.VMTemplateDetailsDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.AdapterBase;
import com.cloud.vm.NicProfile;
@ -55,29 +53,21 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
public static final Logger s_logger = Logger.getLogger(HypervisorGuruBase.class);
@Inject
VMTemplateDetailsDao _templateDetailsDao;
private NicDao _nicDao;
@Inject
NicDao _nicDao;
private NetworkDao _networkDao;
@Inject
NetworkDao _networkDao;
private VMInstanceDao _virtualMachineDao;
@Inject
VMInstanceDao _virtualMachineDao;
private UserVmDetailsDao _userVmDetailsDao;
@Inject
UserVmDetailsDao _userVmDetailsDao;
private NicSecondaryIpDao _nicSecIpDao;
@Inject
NicSecondaryIpDao _nicSecIpDao;
private ResourceManager _resourceMgr;
@Inject
ConfigurationServer _configServer;
private ServiceOfferingDetailsDao _serviceOfferingDetailsDao;
@Inject
ResourceManager _resourceMgr;
@Inject
ServiceOfferingDetailsDao _serviceOfferingDetailsDao;
@Inject
ServiceOfferingDao _serviceOfferingDao;
protected HypervisorGuruBase() {
super();
}
private ServiceOfferingDao _serviceOfferingDao;
@Override
public NicTO toNicTO(NicProfile profile) {