Skip to content
Merged
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 @@ -35,7 +35,5 @@ public interface EndPointSelector {

EndPoint select(Scope scope, Long storeId);

EndPoint selectHypervisorHost(Scope scope);

EndPoint select(DataStore store, String downloadUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

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;
Expand All @@ -43,6 +40,8 @@
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;
Expand All @@ -64,16 +63,14 @@
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 "
+ "join cluster c on c.id=h.cluster_id "
+ "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();
Expand Down Expand Up @@ -266,8 +263,9 @@ private List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId) {
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) {
Expand Down Expand Up @@ -386,40 +384,4 @@ public List<EndPoint> selectAll(DataStore store) {
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,11 @@

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;
Expand All @@ -45,15 +35,7 @@
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() {
Expand All @@ -65,7 +47,6 @@ public VirtualMachineTO implement(VirtualMachineProfile vm) {
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());
Expand All @@ -78,35 +59,13 @@ public boolean trackVmHostChange() {
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@

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;
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;
Expand All @@ -57,34 +54,27 @@
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;
@Inject
GuestOSHypervisorDao _guestOsHypervisorDao;
private GuestOSDao _guestOsDao;
@Inject
EndPointSelector endPointSelector;
private GuestOSHypervisorDao _guestOsHypervisorDao;
@Inject
HostDao hostDao;
private HostDao hostDao;
@Inject
VolumeDao _volumeDao;
private VolumeDao _volumeDao;
@Inject
PrimaryDataStoreDao _storagePoolDao;
private PrimaryDataStoreDao _storagePoolDao;
@Inject
VolumeDataFactory _volFactory;
private 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;
Expand Down Expand Up @@ -129,11 +119,6 @@ public boolean trackVmHostChange() {
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>();
Expand Down Expand Up @@ -189,15 +174,13 @@ 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.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()));
}
}
}
Expand Down
26 changes: 8 additions & 18 deletions server/src/com/cloud/hypervisor/HypervisorGuruBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
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;
Expand All @@ -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) {
Expand Down