Merge pull request #2060 from apache/4.9

Merge release branch 4.9 to master
This commit is contained in:
Rajani Karuturi 2017-04-23 09:34:54 +05:30 committed by GitHub
commit fc8ed22abe
7 changed files with 166 additions and 31 deletions

View File

@ -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 { 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. // FIXME: We should do this better.
final Step previousStep = work.getStep(); Step previousStep = null;
if (work != null) {
previousStep = work.getStep();
_workDao.updateStep(work, step); _workDao.updateStep(work, step);
}
boolean result = false; boolean result = false;
try { try {
result = stateTransitTo(vm, event, hostId); result = stateTransitTo(vm, event, hostId);
return result; return result;
} finally { } finally {
if (!result) { if (!result && work != null) {
_workDao.updateStep(work, previousStep); _workDao.updateStep(work, previousStep);
} }
} }
@ -1517,12 +1520,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
if (doCleanup) { if (doCleanup) {
if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, cleanUpEvenIfUnableToStop)) { if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, cleanUpEvenIfUnableToStop)) {
try { try {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled() && work != null) {
s_logger.debug("Updating work item to Done, id:" + work.getId()); s_logger.debug("Updating work item to Done, id:" + work.getId());
} }
if (!changeState(vm, Event.AgentReportStopped, null, work, Step.Done)) { if (!changeState(vm, Event.AgentReportStopped, null, work, Step.Done)) {
throw new CloudRuntimeException("Unable to stop " + vm); throw new CloudRuntimeException("Unable to stop " + vm);
} }
} catch (final NoTransitionException e) { } catch (final NoTransitionException e) {
s_logger.warn("Unable to cleanup " + vm); s_logger.warn("Unable to cleanup " + vm);
throw new CloudRuntimeException("Unable to stop " + vm, e); throw new CloudRuntimeException("Unable to stop " + vm, e);

View File

@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import javax.inject.Inject; import javax.inject.Inject;
@ -356,11 +355,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
switch (level) { switch (level) {
case 1: // List all the capacities grouped by zone, capacity Type 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; break;
case 2: // List all the capacities grouped by pod, capacity Type 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; break;
case 3: // List all the capacities grouped by cluster, capacity Type 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); results.add(summedCapacity);
} }
HashMap<Integer, SummedCapacity> capacityMap = new HashMap<Integer, SummedCapacity>(); return results;
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;
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + finalQuery, e); throw new CloudRuntimeException("DB Exception on: " + finalQuery, e);
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -29,7 +29,6 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.vmware.vim25.ClusterDasConfigInfo;
import com.vmware.vim25.ManagedObjectReference; import com.vmware.vim25.ManagedObjectReference;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
@ -344,8 +343,7 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
return null; return null;
} else { } else {
ClusterMO clusterMo = new ClusterMO(context, morCluster); ClusterMO clusterMo = new ClusterMO(context, morCluster);
ClusterDasConfigInfo dasConfig = clusterMo.getDasConfig(); if (clusterMo.isHAEnabled()) {
if (dasConfig != null && dasConfig.isEnabled() != null && dasConfig.isEnabled().booleanValue()) {
clusterDetails.put("NativeHA", "true"); clusterDetails.put("NativeHA", "true");
_clusterDetailsDao.persist(clusterId, clusterDetails); _clusterDetailsDao.persist(clusterId, clusterDetails);
} }

View File

@ -49,9 +49,9 @@ import org.apache.log4j.NDC;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.vmware.vim25.AboutInfo; import com.vmware.vim25.AboutInfo;
import com.vmware.vim25.BoolPolicy; import com.vmware.vim25.BoolPolicy;
import com.vmware.vim25.ClusterDasConfigInfo;
import com.vmware.vim25.ComputeResourceSummary; import com.vmware.vim25.ComputeResourceSummary;
import com.vmware.vim25.CustomFieldStringValue; import com.vmware.vim25.CustomFieldStringValue;
import com.vmware.vim25.DasVmPriority;
import com.vmware.vim25.DVPortConfigInfo; import com.vmware.vim25.DVPortConfigInfo;
import com.vmware.vim25.DVPortConfigSpec; import com.vmware.vim25.DVPortConfigSpec;
import com.vmware.vim25.DatastoreSummary; 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. if (vmFolderExists && vmxFileFullPath != null) { // VM can be registered only if .vmx is present.
registerVm(vmNameOnVcenter, dsRootVolumeIsOn); registerVm(vmNameOnVcenter, dsRootVolumeIsOn);
vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName); vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
if (vmMo != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found registered vm " + vmInternalCSName + " at host " + hyperHost.getHyperHostName());
}
}
tearDownVm(vmMo); tearDownVm(vmMo);
}else if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(), }else if (!hyperHost.createBlankVm(vmNameOnVcenter, vmInternalCSName, vmSpec.getCpus(), vmSpec.getMaxSpeed().intValue(),
getReservedCpuMHZ(vmSpec), vmSpec.getLimitCpuUse(), (int)(vmSpec.getMaxRam() / (1024 * 1024)), getReservedMemoryMb(vmSpec), 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); 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 // Post Configuration
// //
@ -4830,8 +4839,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
private void fillHostDetailsInfo(VmwareContext serviceContext, Map<String, String> details) throws Exception { private void fillHostDetailsInfo(VmwareContext serviceContext, Map<String, String> details) throws Exception {
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
ClusterDasConfigInfo dasConfig = hyperHost.getDasConfig(); if (hyperHost.isHAEnabled()) {
if (dasConfig != null && dasConfig.isEnabled() != null && dasConfig.isEnabled().booleanValue()) {
details.put("NativeHA", "true"); details.put("NativeHA", "true");
} }
} }

View File

@ -22,16 +22,20 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.vmware.vim25.ArrayOfHostIpRouteEntry; import com.vmware.vim25.ArrayOfHostIpRouteEntry;
import com.vmware.vim25.ArrayUpdateOperation;
import com.vmware.vim25.ClusterComputeResourceSummary; import com.vmware.vim25.ClusterComputeResourceSummary;
import com.vmware.vim25.ClusterConfigInfoEx; import com.vmware.vim25.ClusterConfigInfoEx;
import com.vmware.vim25.ClusterDasConfigInfo; import com.vmware.vim25.ClusterDasConfigInfo;
import com.vmware.vim25.ClusterDasVmSettingsRestartPriority;
import com.vmware.vim25.ClusterHostRecommendation; import com.vmware.vim25.ClusterHostRecommendation;
import com.vmware.vim25.ComputeResourceSummary; import com.vmware.vim25.ComputeResourceSummary;
import com.vmware.vim25.CustomFieldStringValue; import com.vmware.vim25.CustomFieldStringValue;
import com.vmware.vim25.DasVmPriority;
import com.vmware.vim25.DatastoreInfo; import com.vmware.vim25.DatastoreInfo;
import com.vmware.vim25.DynamicProperty; import com.vmware.vim25.DynamicProperty;
import com.vmware.vim25.GuestOsDescriptor; import com.vmware.vim25.GuestOsDescriptor;
@ -49,6 +53,10 @@ import com.vmware.vim25.PropertySpec;
import com.vmware.vim25.TraversalSpec; import com.vmware.vim25.TraversalSpec;
import com.vmware.vim25.VirtualMachineConfigOption; import com.vmware.vim25.VirtualMachineConfigOption;
import com.vmware.vim25.VirtualMachineConfigSpec; 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.VmwareContext;
import com.cloud.hypervisor.vmware.util.VmwareHelper; import com.cloud.hypervisor.vmware.util.VmwareHelper;
@ -77,11 +85,120 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
@Override @Override
public ClusterDasConfigInfo getDasConfig() throws Exception { public ClusterDasConfigInfo getDasConfig() throws Exception {
ClusterConfigInfoEx configInfo = getClusterConfigInfo();
if (configInfo != null) {
// Note getDynamicProperty() with "configurationEx.dasConfig" does not work here because of that dasConfig is a property in subclass // Note getDynamicProperty() with "configurationEx.dasConfig" does not work here because of that dasConfig is a property in subclass
ClusterConfigInfoEx configInfo = (ClusterConfigInfoEx)_context.getVimClient().getDynamicProperty(_mor, "configurationEx");
return configInfo.getDasConfig(); return configInfo.getDasConfig();
} }
return null;
}
private ClusterConfigInfoEx getClusterConfigInfo() throws Exception {
ClusterConfigInfoEx configInfo = (ClusterConfigInfoEx)_context.getVimClient().getDynamicProperty(_mor, "configurationEx");
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 @Override
public ManagedObjectReference getHyperHostDatacenter() throws Exception { public ManagedObjectReference getHyperHostDatacenter() throws Exception {
Pair<DatacenterMO, String> dcPair = DatacenterMO.getOwnerDatacenter(getContext(), getMor()); Pair<DatacenterMO, String> dcPair = DatacenterMO.getOwnerDatacenter(getContext(), getMor());

View File

@ -143,6 +143,26 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
return null; 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 @Override
public String getHyperHostDefaultGateway() throws Exception { public String getHyperHostDefaultGateway() throws Exception {
List<HostIpRouteEntry> entries = getHostIpRouteEntries(); List<HostIpRouteEntry> entries = getHostIpRouteEntries();

View File

@ -37,6 +37,10 @@ public interface VmwareHypervisorHost {
ClusterDasConfigInfo getDasConfig() throws Exception; ClusterDasConfigInfo getDasConfig() throws Exception;
boolean isHAEnabled() throws Exception;
void setRestartPriorityForVM(VirtualMachineMO vmMo, String priority) throws Exception;
ManagedObjectReference getHyperHostDatacenter() throws Exception; ManagedObjectReference getHyperHostDatacenter() throws Exception;
ManagedObjectReference getHyperHostOwnerResourcePool() throws Exception; ManagedObjectReference getHyperHostOwnerResourcePool() throws Exception;