mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge pull request #2060 from apache/4.9
Merge release branch 4.9 to master
This commit is contained in:
commit
fc8ed22abe
@ -747,14 +747,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
|
||||
protected <T extends VMInstanceVO> boolean changeState(final T vm, final Event event, final Long hostId, final ItWorkVO work, final Step step) throws NoTransitionException {
|
||||
// FIXME: We should do this better.
|
||||
final Step previousStep = work.getStep();
|
||||
_workDao.updateStep(work, step);
|
||||
Step previousStep = null;
|
||||
if (work != null) {
|
||||
previousStep = work.getStep();
|
||||
_workDao.updateStep(work, step);
|
||||
}
|
||||
boolean result = false;
|
||||
try {
|
||||
result = stateTransitTo(vm, event, hostId);
|
||||
return result;
|
||||
} finally {
|
||||
if (!result) {
|
||||
if (!result && work != null) {
|
||||
_workDao.updateStep(work, previousStep);
|
||||
}
|
||||
}
|
||||
@ -1517,12 +1520,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
if (doCleanup) {
|
||||
if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, cleanUpEvenIfUnableToStop)) {
|
||||
try {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
if (s_logger.isDebugEnabled() && work != null) {
|
||||
s_logger.debug("Updating work item to Done, id:" + work.getId());
|
||||
}
|
||||
if (!changeState(vm, Event.AgentReportStopped, null, work, Step.Done)) {
|
||||
throw new CloudRuntimeException("Unable to stop " + vm);
|
||||
}
|
||||
|
||||
} catch (final NoTransitionException e) {
|
||||
s_logger.warn("Unable to cleanup " + vm);
|
||||
throw new CloudRuntimeException("Unable to stop " + vm, e);
|
||||
|
||||
@ -23,7 +23,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -356,11 +355,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
||||
|
||||
switch (level) {
|
||||
case 1: // List all the capacities grouped by zone, capacity Type
|
||||
finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2);
|
||||
finalQuery.append(LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2);
|
||||
break;
|
||||
|
||||
case 2: // List all the capacities grouped by pod, capacity Type
|
||||
finalQuery.append(LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART2);
|
||||
finalQuery.append(LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2);
|
||||
break;
|
||||
|
||||
case 3: // List all the capacities grouped by cluster, capacity Type
|
||||
@ -392,22 +391,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
||||
results.add(summedCapacity);
|
||||
}
|
||||
|
||||
HashMap<Integer, SummedCapacity> capacityMap = new HashMap<Integer, SummedCapacity>();
|
||||
for (SummedCapacity result: results) {
|
||||
if (capacityMap.containsKey(result.getCapacityType().intValue())) {
|
||||
SummedCapacity tempCapacity = capacityMap.get(result.getCapacityType().intValue());
|
||||
tempCapacity.setUsedCapacity(tempCapacity.getUsedCapacity()+result.getUsedCapacity());
|
||||
tempCapacity.setReservedCapacity(tempCapacity.getReservedCapacity()+result.getReservedCapacity());
|
||||
tempCapacity.setSumTotal(tempCapacity.getTotalCapacity()+result.getTotalCapacity());
|
||||
}else {
|
||||
capacityMap.put(result.getCapacityType().intValue(),result);
|
||||
}
|
||||
}
|
||||
List<SummedCapacity> summedCapacityList = new ArrayList<SummedCapacity>();
|
||||
for (Entry<Integer, SummedCapacity> entry : capacityMap.entrySet()) {
|
||||
summedCapacityList.add(entry.getValue());
|
||||
}
|
||||
return summedCapacityList;
|
||||
return results;
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("DB Exception on: " + finalQuery, e);
|
||||
} catch (Throwable e) {
|
||||
|
||||
@ -29,7 +29,6 @@ import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.vmware.vim25.ClusterDasConfigInfo;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -344,8 +343,7 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
|
||||
return null;
|
||||
} else {
|
||||
ClusterMO clusterMo = new ClusterMO(context, morCluster);
|
||||
ClusterDasConfigInfo dasConfig = clusterMo.getDasConfig();
|
||||
if (dasConfig != null && dasConfig.isEnabled() != null && dasConfig.isEnabled().booleanValue()) {
|
||||
if (clusterMo.isHAEnabled()) {
|
||||
clusterDetails.put("NativeHA", "true");
|
||||
_clusterDetailsDao.persist(clusterId, clusterDetails);
|
||||
}
|
||||
|
||||
@ -49,9 +49,9 @@ import org.apache.log4j.NDC;
|
||||
import com.google.gson.Gson;
|
||||
import com.vmware.vim25.AboutInfo;
|
||||
import com.vmware.vim25.BoolPolicy;
|
||||
import com.vmware.vim25.ClusterDasConfigInfo;
|
||||
import com.vmware.vim25.ComputeResourceSummary;
|
||||
import com.vmware.vim25.CustomFieldStringValue;
|
||||
import com.vmware.vim25.DasVmPriority;
|
||||
import com.vmware.vim25.DVPortConfigInfo;
|
||||
import com.vmware.vim25.DVPortConfigSpec;
|
||||
import com.vmware.vim25.DatastoreSummary;
|
||||
@ -1663,6 +1663,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
if (vmFolderExists && vmxFileFullPath != null) { // VM can be registered only if .vmx is present.
|
||||
registerVm(vmNameOnVcenter, dsRootVolumeIsOn);
|
||||
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
|
||||
if (vmMo != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Found registered vm " + vmInternalCSName + " at host " + hyperHost.getHyperHostName());
|
||||
}
|
||||
}
|
||||
tearDownVm(vmMo);
|
||||
}else if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
|
||||
getReservedCpuMHZ(vmSpec), vmSpec.getLimitCpuUse(), (int)(vmSpec.getMaxRam() / (1024 * 1024)), getReservedMemoryMb(vmSpec),
|
||||
@ -2013,6 +2018,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
throw new Exception("Failed to configure VM before start. vmName: " + vmInternalCSName);
|
||||
}
|
||||
|
||||
if (vmSpec.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
hyperHost.setRestartPriorityForVM(vmMo, DasVmPriority.HIGH.value());
|
||||
}
|
||||
|
||||
//
|
||||
// Post Configuration
|
||||
//
|
||||
@ -4830,8 +4839,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
||||
private void fillHostDetailsInfo(VmwareContext serviceContext, Map<String, String> details) throws Exception {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
|
||||
ClusterDasConfigInfo dasConfig = hyperHost.getDasConfig();
|
||||
if (dasConfig != null && dasConfig.isEnabled() != null && dasConfig.isEnabled().booleanValue()) {
|
||||
if (hyperHost.isHAEnabled()) {
|
||||
details.put("NativeHA", "true");
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,16 +22,20 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.vmware.vim25.ArrayOfHostIpRouteEntry;
|
||||
import com.vmware.vim25.ArrayUpdateOperation;
|
||||
import com.vmware.vim25.ClusterComputeResourceSummary;
|
||||
import com.vmware.vim25.ClusterConfigInfoEx;
|
||||
import com.vmware.vim25.ClusterDasConfigInfo;
|
||||
import com.vmware.vim25.ClusterDasVmSettingsRestartPriority;
|
||||
import com.vmware.vim25.ClusterHostRecommendation;
|
||||
import com.vmware.vim25.ComputeResourceSummary;
|
||||
import com.vmware.vim25.CustomFieldStringValue;
|
||||
import com.vmware.vim25.DasVmPriority;
|
||||
import com.vmware.vim25.DatastoreInfo;
|
||||
import com.vmware.vim25.DynamicProperty;
|
||||
import com.vmware.vim25.GuestOsDescriptor;
|
||||
@ -49,6 +53,10 @@ import com.vmware.vim25.PropertySpec;
|
||||
import com.vmware.vim25.TraversalSpec;
|
||||
import com.vmware.vim25.VirtualMachineConfigOption;
|
||||
import com.vmware.vim25.VirtualMachineConfigSpec;
|
||||
import com.vmware.vim25.ClusterDasVmConfigInfo;
|
||||
import com.vmware.vim25.ClusterDasVmConfigSpec;
|
||||
import com.vmware.vim25.ClusterDasVmSettings;
|
||||
import com.vmware.vim25.ClusterConfigSpecEx;
|
||||
|
||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||
import com.cloud.hypervisor.vmware.util.VmwareHelper;
|
||||
@ -77,9 +85,118 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
||||
|
||||
@Override
|
||||
public ClusterDasConfigInfo getDasConfig() throws Exception {
|
||||
// Note getDynamicProperty() with "configurationEx.dasConfig" does not work here because of that dasConfig is a property in subclass
|
||||
ClusterConfigInfoEx configInfo = getClusterConfigInfo();
|
||||
if (configInfo != null) {
|
||||
// Note getDynamicProperty() with "configurationEx.dasConfig" does not work here because of that dasConfig is a property in subclass
|
||||
return configInfo.getDasConfig();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ClusterConfigInfoEx getClusterConfigInfo() throws Exception {
|
||||
ClusterConfigInfoEx configInfo = (ClusterConfigInfoEx)_context.getVimClient().getDynamicProperty(_mor, "configurationEx");
|
||||
return configInfo.getDasConfig();
|
||||
return configInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHAEnabled() throws Exception {
|
||||
ClusterDasConfigInfo dasConfig = getDasConfig();
|
||||
if (dasConfig != null && dasConfig.isEnabled() != null && dasConfig.isEnabled().booleanValue()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getRestartPriorityForVM(VirtualMachineMO vmMo) throws Exception {
|
||||
if (vmMo == null) {
|
||||
s_logger.debug("Failed to get restart priority for VM, invalid VM object reference");
|
||||
return null;
|
||||
}
|
||||
|
||||
ManagedObjectReference vmMor = vmMo.getMor();
|
||||
if (vmMor == null || !vmMor.getType().equals("VirtualMachine")) {
|
||||
s_logger.debug("Failed to get restart priority for VM: " + vmMo.getName() + ", invalid VM object reference");
|
||||
return null;
|
||||
}
|
||||
|
||||
ClusterConfigInfoEx configInfo = getClusterConfigInfo();
|
||||
if (configInfo == null) {
|
||||
s_logger.debug("Failed to get restart priority for VM: " + vmMo.getName() + ", no cluster config information");
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ClusterDasVmConfigInfo> dasVmConfig = configInfo.getDasVmConfig();
|
||||
for (int dasVmConfigIndex = 0; dasVmConfigIndex < dasVmConfig.size(); dasVmConfigIndex++) {
|
||||
ClusterDasVmConfigInfo dasVmConfigInfo = dasVmConfig.get(dasVmConfigIndex);
|
||||
if (dasVmConfigInfo != null && dasVmConfigInfo.getKey().getValue().equals(vmMor.getValue())) {
|
||||
DasVmPriority dasVmPriority = dasVmConfigInfo.getRestartPriority();
|
||||
if (dasVmPriority != null) {
|
||||
return dasVmPriority.value();
|
||||
} else {
|
||||
//VM uses cluster restart priority when DasVmPriority for the VM is null.
|
||||
return ClusterDasVmSettingsRestartPriority.CLUSTER_RESTART_PRIORITY.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_logger.debug("VM: " + vmMo.getName() + " uses default restart priority in the cluster: " + getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRestartPriorityForVM(VirtualMachineMO vmMo, String priority) throws Exception {
|
||||
if (vmMo == null || StringUtils.isBlank(priority)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isHAEnabled()) {
|
||||
s_logger.debug("Couldn't set restart priority for VM: " + vmMo.getName() + ", HA disabled in the cluster");
|
||||
return;
|
||||
}
|
||||
|
||||
ManagedObjectReference vmMor = vmMo.getMor();
|
||||
if (vmMor == null || !vmMor.getType().equals("VirtualMachine")) {
|
||||
s_logger.debug("Failed to set restart priority for VM: " + vmMo.getName() + ", invalid VM object reference");
|
||||
return;
|
||||
}
|
||||
|
||||
String currentVmRestartPriority = getRestartPriorityForVM(vmMo);
|
||||
if (StringUtils.isNotBlank(currentVmRestartPriority) && currentVmRestartPriority.equalsIgnoreCase(priority)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClusterDasVmSettings clusterDasVmSettings = new ClusterDasVmSettings();
|
||||
clusterDasVmSettings.setRestartPriority(priority);
|
||||
|
||||
ClusterDasVmConfigInfo clusterDasVmConfigInfo = new ClusterDasVmConfigInfo();
|
||||
clusterDasVmConfigInfo.setKey(vmMor);
|
||||
clusterDasVmConfigInfo.setDasSettings(clusterDasVmSettings);
|
||||
|
||||
ClusterDasVmConfigSpec clusterDasVmConfigSpec = new ClusterDasVmConfigSpec();
|
||||
clusterDasVmConfigSpec.setOperation((StringUtils.isNotBlank(currentVmRestartPriority)) ? ArrayUpdateOperation.EDIT : ArrayUpdateOperation.ADD);
|
||||
clusterDasVmConfigSpec.setInfo(clusterDasVmConfigInfo);
|
||||
|
||||
ClusterConfigSpecEx clusterConfigSpecEx = new ClusterConfigSpecEx();
|
||||
ClusterDasConfigInfo clusterDasConfigInfo = new ClusterDasConfigInfo();
|
||||
clusterConfigSpecEx.setDasConfig(clusterDasConfigInfo);
|
||||
clusterConfigSpecEx.getDasVmConfigSpec().add(clusterDasVmConfigSpec);
|
||||
|
||||
ManagedObjectReference morTask = _context.getService().reconfigureComputeResourceTask(_mor, clusterConfigSpecEx, true);
|
||||
|
||||
boolean result = _context.getVimClient().waitForTask(morTask);
|
||||
|
||||
if (result) {
|
||||
_context.waitForTaskProgressDone(morTask);
|
||||
|
||||
if (s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - setRestartPriority done(successfully)");
|
||||
} else {
|
||||
if (s_logger.isTraceEnabled())
|
||||
s_logger.trace("vCenter API trace - setRestartPriority done(failed)");
|
||||
s_logger.error("Set restart priority failed for VM: " + vmMo.getName() + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -143,6 +143,26 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHAEnabled() throws Exception {
|
||||
ManagedObjectReference morParent = getParentMor();
|
||||
if (morParent.getType().equals("ClusterComputeResource")) {
|
||||
ClusterMO clusterMo = new ClusterMO(_context, morParent);
|
||||
return clusterMo.isHAEnabled();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRestartPriorityForVM(VirtualMachineMO vmMo, String priority) throws Exception {
|
||||
ManagedObjectReference morParent = getParentMor();
|
||||
if (morParent.getType().equals("ClusterComputeResource")) {
|
||||
ClusterMO clusterMo = new ClusterMO(_context, morParent);
|
||||
clusterMo.setRestartPriorityForVM(vmMo, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHyperHostDefaultGateway() throws Exception {
|
||||
List<HostIpRouteEntry> entries = getHostIpRouteEntries();
|
||||
|
||||
@ -37,6 +37,10 @@ public interface VmwareHypervisorHost {
|
||||
|
||||
ClusterDasConfigInfo getDasConfig() throws Exception;
|
||||
|
||||
boolean isHAEnabled() throws Exception;
|
||||
|
||||
void setRestartPriorityForVM(VirtualMachineMO vmMo, String priority) throws Exception;
|
||||
|
||||
ManagedObjectReference getHyperHostDatacenter() throws Exception;
|
||||
|
||||
ManagedObjectReference getHyperHostOwnerResourcePool() throws Exception;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user