Merge branch '4.18' into 4.19

This commit is contained in:
Vishesh 2024-06-28 20:14:21 +05:30
commit bcbf152a05
No known key found for this signature in database
GPG Key ID: 4E395186CBFA790B
11 changed files with 66 additions and 19 deletions

View File

@ -192,6 +192,10 @@ public interface VirtualMachineProfile {
Map<Param, Object> getParameters(); Map<Param, Object> getParameters();
void setCpuOvercommitRatio(Float cpuOvercommitRatio);
void setMemoryOvercommitRatio(Float memoryOvercommitRatio);
Float getCpuOvercommitRatio(); Float getCpuOvercommitRatio();
Float getMemoryOvercommitRatio(); Float getMemoryOvercommitRatio();

View File

@ -126,6 +126,8 @@ public interface ResourceManager extends ResourceService, Configurable {
public List<HostVO> listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType type, long dcId); public List<HostVO> listAllUpAndEnabledHostsInOneZoneByHypervisor(HypervisorType type, long dcId);
public List<HostVO> listAllUpHostsInOneZoneByHypervisor(HypervisorType type, long dcId);
public List<HostVO> listAllUpAndEnabledHostsInOneZone(long dcId); public List<HostVO> listAllUpAndEnabledHostsInOneZone(long dcId);
public List<HostVO> listAllHostsInOneZoneByType(Host.Type type, long dcId); public List<HostVO> listAllHostsInOneZoneByType(Host.Type type, long dcId);

View File

@ -264,11 +264,13 @@ public class VirtualMachineProfileImpl implements VirtualMachineProfile {
_offering = offering; _offering = offering;
} }
@Override
public void setCpuOvercommitRatio(Float cpuOvercommitRatio) { public void setCpuOvercommitRatio(Float cpuOvercommitRatio) {
this.cpuOvercommitRatio = cpuOvercommitRatio; this.cpuOvercommitRatio = cpuOvercommitRatio;
} }
@Override
public void setMemoryOvercommitRatio(Float memoryOvercommitRatio) { public void setMemoryOvercommitRatio(Float memoryOvercommitRatio) {
this.memoryOvercommitRatio = memoryOvercommitRatio; this.memoryOvercommitRatio = memoryOvercommitRatio;

View File

@ -44,6 +44,8 @@ import com.cloud.agent.api.CheckOnHostCommand;
import com.cloud.agent.api.CheckVirtualMachineCommand; import com.cloud.agent.api.CheckVirtualMachineCommand;
import com.cloud.agent.api.CleanupNetworkRulesCmd; import com.cloud.agent.api.CleanupNetworkRulesCmd;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
import com.cloud.agent.api.CreateStoragePoolCommand;
import com.cloud.agent.api.DeleteStoragePoolCommand;
import com.cloud.agent.api.MaintainCommand; import com.cloud.agent.api.MaintainCommand;
import com.cloud.agent.api.MigrateCommand; import com.cloud.agent.api.MigrateCommand;
import com.cloud.agent.api.ModifySshKeysCommand; import com.cloud.agent.api.ModifySshKeysCommand;
@ -119,8 +121,9 @@ public abstract class AgentAttache {
StopCommand.class.toString(), CheckVirtualMachineCommand.class.toString(), PingTestCommand.class.toString(), CheckHealthCommand.class.toString(), StopCommand.class.toString(), CheckVirtualMachineCommand.class.toString(), PingTestCommand.class.toString(), CheckHealthCommand.class.toString(),
ReadyCommand.class.toString(), ShutdownCommand.class.toString(), SetupCommand.class.toString(), ReadyCommand.class.toString(), ShutdownCommand.class.toString(), SetupCommand.class.toString(),
CleanupNetworkRulesCmd.class.toString(), CheckNetworkCommand.class.toString(), PvlanSetupCommand.class.toString(), CheckOnHostCommand.class.toString(), CleanupNetworkRulesCmd.class.toString(), CheckNetworkCommand.class.toString(), PvlanSetupCommand.class.toString(), CheckOnHostCommand.class.toString(),
ModifyTargetsCommand.class.toString(), ModifySshKeysCommand.class.toString(), ModifyStoragePoolCommand.class.toString(), SetupMSListCommand.class.toString(), RollingMaintenanceCommand.class.toString(), ModifyTargetsCommand.class.toString(), ModifySshKeysCommand.class.toString(),
CleanupPersistentNetworkResourceCommand.class.toString()}; CreateStoragePoolCommand.class.toString(), DeleteStoragePoolCommand.class.toString(), ModifyStoragePoolCommand.class.toString(),
SetupMSListCommand.class.toString(), RollingMaintenanceCommand.class.toString(), CleanupPersistentNetworkResourceCommand.class.toString()};
protected final static String[] s_commandsNotAllowedInConnectingMode = new String[] { StartCommand.class.toString(), CreateCommand.class.toString() }; protected final static String[] s_commandsNotAllowedInConnectingMode = new String[] { StartCommand.class.toString(), CreateCommand.class.toString() };
static { static {
Arrays.sort(s_commandsAllowedInMaintenanceMode); Arrays.sort(s_commandsAllowedInMaintenanceMode);

View File

@ -1235,21 +1235,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
long destHostId = dest.getHost().getId(); long destHostId = dest.getHost().getId();
vm.setPodIdToDeployIn(dest.getPod().getId()); vm.setPodIdToDeployIn(dest.getPod().getId());
final Long cluster_id = dest.getCluster().getId(); final Long clusterId = dest.getCluster().getId();
final ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id, VmDetailConstants.CPU_OVER_COMMIT_RATIO); updateOverCommitRatioForVmProfile(vmProfile, clusterId);
final ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id, VmDetailConstants.MEMORY_OVER_COMMIT_RATIO);
if (userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO) == null &&
(Float.parseFloat(cluster_detail_cpu.getValue()) > 1f || Float.parseFloat(cluster_detail_ram.getValue()) > 1f)) {
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO, cluster_detail_cpu.getValue(), true);
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO, cluster_detail_ram.getValue(), true);
} else if (userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO) != null) {
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO, cluster_detail_cpu.getValue(), true);
userVmDetailsDao.addDetail(vm.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO, cluster_detail_ram.getValue(), true);
}
vmProfile.setCpuOvercommitRatio(Float.parseFloat(cluster_detail_cpu.getValue()));
vmProfile.setMemoryOvercommitRatio(Float.parseFloat(cluster_detail_ram.getValue()));
StartAnswer startAnswer = null; StartAnswer startAnswer = null;
try { try {
@ -1264,7 +1252,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
resetVmNicsDeviceId(vm.getId()); resetVmNicsDeviceId(vm.getId());
_networkMgr.prepare(vmProfile, dest, ctx); _networkMgr.prepare(vmProfile, dest, ctx);
if (vm.getHypervisorType() != HypervisorType.BareMetal) { if (vm.getHypervisorType() != HypervisorType.BareMetal) {
checkAndAttemptMigrateVmAcrossCluster(vm, cluster_id, dest.getStorageForDisks()); checkAndAttemptMigrateVmAcrossCluster(vm, clusterId, dest.getStorageForDisks());
volumeMgr.prepare(vmProfile, dest); volumeMgr.prepare(vmProfile, dest);
} }
@ -1462,6 +1450,27 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} }
} }
private void updateOverCommitRatioForVmProfile(VirtualMachineProfile vmProfile, long clusterId) {
final ClusterDetailsVO clusterDetailCpu = _clusterDetailsDao.findDetail(clusterId, VmDetailConstants.CPU_OVER_COMMIT_RATIO);
final ClusterDetailsVO clusterDetailRam = _clusterDetailsDao.findDetail(clusterId, VmDetailConstants.MEMORY_OVER_COMMIT_RATIO);
final float parsedClusterCpuDetailCpu = Float.parseFloat(clusterDetailCpu.getValue());
final float parsedClusterDetailRam = Float.parseFloat(clusterDetailRam.getValue());
UserVmDetailVO vmDetailCpu = userVmDetailsDao.findDetail(vmProfile.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO);
UserVmDetailVO vmDetailRam = userVmDetailsDao.findDetail(vmProfile.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO);
if ((vmDetailCpu == null && parsedClusterCpuDetailCpu > 1f) ||
(vmDetailCpu != null && Float.parseFloat(vmDetailCpu.getValue()) != parsedClusterCpuDetailCpu)) {
userVmDetailsDao.addDetail(vmProfile.getId(), VmDetailConstants.CPU_OVER_COMMIT_RATIO, clusterDetailCpu.getValue(), true);
}
if ((vmDetailRam == null && parsedClusterDetailRam > 1f) ||
(vmDetailRam != null && Float.parseFloat(vmDetailRam.getValue()) != parsedClusterDetailRam)) {
userVmDetailsDao.addDetail(vmProfile.getId(), VmDetailConstants.MEMORY_OVER_COMMIT_RATIO, clusterDetailRam.getValue(), true);
}
vmProfile.setCpuOvercommitRatio(Float.parseFloat(clusterDetailCpu.getValue()));
vmProfile.setMemoryOvercommitRatio(Float.parseFloat(clusterDetailRam.getValue()));
}
/** /**
* Setting pod id to null can result in migration of Volumes across pods. This is not desirable for VMs which * Setting pod id to null can result in migration of Volumes across pods. This is not desirable for VMs which
* have a volume in Ready state (happens when a VM is shutdown and started again). * have a volume in Ready state (happens when a VM is shutdown and started again).
@ -2736,6 +2745,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
_networkMgr.prepareNicForMigration(profile, dest); _networkMgr.prepareNicForMigration(profile, dest);
volumeMgr.prepareForMigration(profile, dest); volumeMgr.prepareForMigration(profile, dest);
profile.setConfigDriveLabel(VmConfigDriveLabel.value()); profile.setConfigDriveLabel(VmConfigDriveLabel.value());
updateOverCommitRatioForVmProfile(profile, dest.getHost().getClusterId());
final VirtualMachineTO to = toVmTO(profile); final VirtualMachineTO to = toVmTO(profile);
final PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand(to); final PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand(to);

View File

@ -99,6 +99,9 @@ public class TemplateDataFactoryImpl implements TemplateDataFactory {
@Override @Override
public TemplateInfo getTemplate(long templateId, DataStore store) { public TemplateInfo getTemplate(long templateId, DataStore store) {
VMTemplateVO templ = imageDataDao.findById(templateId); VMTemplateVO templ = imageDataDao.findById(templateId);
if (templ == null) {
return null;
}
if (store == null && !templ.isDirectDownload()) { if (store == null && !templ.isDirectDownload()) {
TemplateObject tmpl = TemplateObject.getTemplate(templ, null, null); TemplateObject tmpl = TemplateObject.getTemplate(templ, null, null);
return tmpl; return tmpl;

View File

@ -81,6 +81,10 @@ public class TemplateObject implements TemplateInfo {
} }
protected void configure(VMTemplateVO template, DataStore dataStore) { protected void configure(VMTemplateVO template, DataStore dataStore) {
if (template == null) {
String msg = String.format("Template Object is not properly initialised %s", this.toString());
s_logger.warn(msg);
}
imageVO = template; imageVO = template;
this.dataStore = dataStore; this.dataStore = dataStore;
} }
@ -97,6 +101,10 @@ public class TemplateObject implements TemplateInfo {
} }
public VMTemplateVO getImage() { public VMTemplateVO getImage() {
if (imageVO == null) {
String msg = String.format("Template Object is not properly initialised %s", this.toString());
s_logger.error(msg);
} // somehow the nullpointer is needed : refacter needed!?!
return imageVO; return imageVO;
} }

View File

@ -430,7 +430,7 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
@Override @Override
public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) { public boolean attachZone(DataStore dataStore, ZoneScope scope, HypervisorType hypervisorType) {
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId()); List<HostVO> hosts = _resourceMgr.listAllUpHostsInOneZoneByHypervisor(hypervisorType, scope.getScopeId());
s_logger.debug("In createPool. Attaching the pool to each of the hosts."); s_logger.debug("In createPool. Attaching the pool to each of the hosts.");
List<HostVO> poolHosts = new ArrayList<HostVO>(); List<HostVO> poolHosts = new ArrayList<HostVO>();
for (HostVO host : hosts) { for (HostVO host : hosts) {

View File

@ -1191,7 +1191,7 @@ public class ScaleIOPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
@Override @Override
public boolean canCopy(DataObject srcData, DataObject destData) { public boolean canCopy(DataObject srcData, DataObject destData) {
DataStore srcStore = destData.getDataStore(); DataStore srcStore = srcData.getDataStore();
DataStore destStore = destData.getDataStore(); DataStore destStore = destData.getDataStore();
if ((srcStore.getRole() == DataStoreRole.Primary && (srcData.getType() == DataObjectType.TEMPLATE || srcData.getType() == DataObjectType.VOLUME)) if ((srcStore.getRole() == DataStoreRole.Primary && (srcData.getType() == DataObjectType.TEMPLATE || srcData.getType() == DataObjectType.VOLUME))
&& (destStore.getRole() == DataStoreRole.Primary && destData.getType() == DataObjectType.VOLUME)) { && (destStore.getRole() == DataStoreRole.Primary && destData.getType() == DataObjectType.VOLUME)) {

View File

@ -3388,6 +3388,15 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
return sc.list(); return sc.list();
} }
@Override
public List<HostVO> listAllUpHostsInOneZoneByHypervisor(final HypervisorType type, final long dcId) {
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getHypervisorType(), Op.EQ, type);
sc.and(sc.entity().getDataCenterId(), Op.EQ, dcId);
sc.and(sc.entity().getStatus(), Op.EQ, Status.Up);
return sc.list();
}
@Override @Override
public List<HostVO> listAllUpAndEnabledHostsInOneZone(final long dcId) { public List<HostVO> listAllUpAndEnabledHostsInOneZone(final long dcId) {
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class); final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);

View File

@ -590,6 +590,12 @@ public class MockResourceManagerImpl extends ManagerBase implements ResourceMana
return null; return null;
} }
@Override
public List<HostVO> listAllUpHostsInOneZoneByHypervisor(final HypervisorType type, final long dcId) {
// TODO Auto-generated method stub
return null;
}
@Override @Override
public List<HostVO> listAllUpAndEnabledHostsInOneZone(final long dcId) { public List<HostVO> listAllUpAndEnabledHostsInOneZone(final long dcId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub