mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-4464,CLOUDSTACK-4529: use property collector to collect all information in one round, we have a few other places that need to do it the same way
This commit is contained in:
parent
d6bac1465a
commit
a4762b0904
|
|
@ -54,6 +54,7 @@ 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.DVPortConfigInfo;
|
||||
import com.vmware.vim25.DVPortConfigSpec;
|
||||
import com.vmware.vim25.DatastoreSummary;
|
||||
|
|
@ -5740,10 +5741,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
if(_recycleHungWorker) {
|
||||
s_logger.info("Scan hung worker VM to recycle");
|
||||
|
||||
int key = ((HostMO)hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
if(key == 0) {
|
||||
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
|
||||
}
|
||||
String instanceNameCustomField = "value[" + key + "]";
|
||||
|
||||
// GC worker that has been running for too long
|
||||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(
|
||||
new String[] {"name", "config.template", "runtime.powerState", "runtime.bootTime"});
|
||||
new String[] {"name", "config.template", "runtime.powerState", "runtime.bootTime", instanceNameCustomField });
|
||||
if(ocs != null) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
|
|
@ -5757,6 +5764,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
for(DynamicProperty prop : props) {
|
||||
if (prop.getName().equals("name"))
|
||||
vmName = prop.getVal().toString();
|
||||
else if(prop.getName().startsWith("value[")) {
|
||||
if(prop.getVal() != null)
|
||||
internalName = ((CustomFieldStringValue)prop.getVal()).getValue();
|
||||
}
|
||||
else if(prop.getName().equals("config.template"))
|
||||
template = (Boolean)prop.getVal();
|
||||
else if(prop.getName().equals("runtime.powerState"))
|
||||
|
|
@ -5766,15 +5777,13 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
internalName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
|
||||
String name = null;
|
||||
if (internalName != null) {
|
||||
name = internalName;
|
||||
} else {
|
||||
name = vmName;
|
||||
}
|
||||
|
||||
if(!template && name.matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")) {
|
||||
boolean recycle = false;
|
||||
|
||||
|
|
@ -6215,9 +6224,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
private HashMap<String, State> getVmStates() throws Exception {
|
||||
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
|
||||
|
||||
int key = ((HostMO)hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
if(key == 0) {
|
||||
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
|
||||
}
|
||||
String instanceNameCustomField = "value[" + key + "]";
|
||||
|
||||
// CLOUD_VM_INTERNAL_NAME stores the internal CS generated vm name. This was earlier stored in name. Now, name can be either the hostname or
|
||||
// the internal CS name, but the custom field CLOUD_VM_INTERNAL_NAME always stores the internal CS name.
|
||||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "runtime.powerState", "config.template" });
|
||||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "runtime.powerState", "config.template", instanceNameCustomField });
|
||||
|
||||
HashMap<String, State> newStates = new HashMap<String, State>();
|
||||
if (ocs != null && ocs.length > 0) {
|
||||
|
|
@ -6238,13 +6254,15 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
powerState = (VirtualMachinePowerState) objProp.getVal();
|
||||
} else if (objProp.getName().equals("name")) {
|
||||
name = (String) objProp.getVal();
|
||||
} else {
|
||||
} else if(objProp.getName().contains(instanceNameCustomField)) {
|
||||
if(objProp.getVal() != null)
|
||||
VMInternalCSName = ((CustomFieldStringValue)objProp.getVal()).getValue();
|
||||
}
|
||||
else {
|
||||
assert (false);
|
||||
}
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
VMInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
|
||||
if (VMInternalCSName != null)
|
||||
name = VMInternalCSName;
|
||||
|
||||
|
|
@ -6276,8 +6294,14 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
int key = ((HostMO)hyperHost).getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
if(key == 0) {
|
||||
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
|
||||
}
|
||||
String instanceNameCustomField = "value[" + key + "]";
|
||||
|
||||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] {"name", "summary.config.numCpu", "summary.quickStats.overallCpuUsage"});
|
||||
ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] {"name", "summary.config.numCpu", "summary.quickStats.overallCpuUsage", instanceNameCustomField});
|
||||
if (ocs != null && ocs.length > 0) {
|
||||
for (ObjectContent oc : ocs) {
|
||||
List<DynamicProperty> objProps = oc.getPropSet();
|
||||
|
|
@ -6290,16 +6314,17 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
for (DynamicProperty objProp : objProps) {
|
||||
if (objProp.getName().equals("name")) {
|
||||
vmNameOnVcenter = objProp.getVal().toString();
|
||||
} else if (objProp.getName().equals("summary.config.numCpu")) {
|
||||
} else if(objProp.getName().contains(instanceNameCustomField)) {
|
||||
if(objProp.getVal() != null)
|
||||
vmInternalCSName = ((CustomFieldStringValue)objProp.getVal()).getValue();
|
||||
}
|
||||
else if (objProp.getName().equals("summary.config.numCpu")) {
|
||||
numberCPUs = objProp.getVal().toString();
|
||||
} else if (objProp.getName().equals("summary.quickStats.overallCpuUsage")) {
|
||||
maxCpuUsage = objProp.getVal().toString();
|
||||
}
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(hyperHost.getContext(), oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
vmInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
|
||||
if (vmInternalCSName != null) {
|
||||
name = vmInternalCSName;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -98,25 +98,28 @@ public class ClusterMO extends BaseMO implements VmwareHypervisorHost {
|
|||
|
||||
@Override
|
||||
public VirtualMachineMO findVmOnHyperHost(String name) throws Exception {
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name" });
|
||||
return HypervisorHostHelper.findVmFromObjectContent(_context, ocs, name);
|
||||
|
||||
int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
if(key == 0) {
|
||||
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
|
||||
}
|
||||
|
||||
String instanceNameCustomField = "value[" + key + "]";
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name", instanceNameCustomField });
|
||||
return HypervisorHostHelper.findVmFromObjectContent(_context, ocs, name, instanceNameCustomField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualMachineMO findVmOnPeerHyperHost(String name) throws Exception {
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name" });
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
if(props != null) {
|
||||
for(DynamicProperty prop : props) {
|
||||
if(prop.getVal().toString().equals(name))
|
||||
return new VirtualMachineMO(_context, oc.getObj());
|
||||
}
|
||||
}
|
||||
}
|
||||
int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
if(key == 0) {
|
||||
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
|
||||
}
|
||||
return null;
|
||||
|
||||
String instanceNameCustomField = "value[" + key + "]";
|
||||
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name", instanceNameCustomField });
|
||||
return HypervisorHostHelper.findVmFromObjectContent(_context, ocs, name, instanceNameCustomField);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -510,9 +510,14 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
|||
|
||||
_vmCache.clear();
|
||||
|
||||
int key = getCustomFieldKey("VirtualMachine", CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
if(key == 0) {
|
||||
s_logger.warn("Custom field " + CustomFieldConstants.CLOUD_VM_INTERNAL_NAME + " is not registered ?!");
|
||||
}
|
||||
|
||||
// name is the name of the VM as it appears in vCenter. The CLOUD_VM_INTERNAL_NAME custom
|
||||
// field value contains the name of the VM as it is maintained internally by cloudstack (i-x-y).
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name" });
|
||||
ObjectContent[] ocs = getVmPropertiesOnHyperHost(new String[] { "name", "value[" + key + "]" });
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
List<DynamicProperty> props = oc.getPropSet();
|
||||
|
|
@ -522,11 +527,11 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
|||
for (DynamicProperty prop : props) {
|
||||
if (prop.getName().equals("name")) {
|
||||
vmVcenterName = prop.getVal().toString();
|
||||
}
|
||||
} else if(prop.getName().startsWith("value[")) {
|
||||
if(prop.getVal() != null)
|
||||
vmInternalCSName = ((CustomFieldStringValue)prop.getVal()).getValue();
|
||||
}
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(_context, oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
vmInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
String vmName = null;
|
||||
if (vmInternalCSName != null && isUserVMInternalCSName(vmInternalCSName)) {
|
||||
vmName = vmInternalCSName;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import com.vmware.vim25.AlreadyExistsFaultMsg;
|
||||
import com.vmware.vim25.BoolPolicy;
|
||||
import com.vmware.vim25.CustomFieldStringValue;
|
||||
import com.vmware.vim25.DVPortSetting;
|
||||
import com.vmware.vim25.DVPortgroupConfigInfo;
|
||||
import com.vmware.vim25.DVPortgroupConfigSpec;
|
||||
|
|
@ -46,7 +47,6 @@ import com.vmware.vim25.HttpNfcLeaseState;
|
|||
import com.vmware.vim25.LongPolicy;
|
||||
import com.vmware.vim25.ManagedObjectReference;
|
||||
import com.vmware.vim25.ObjectContent;
|
||||
import com.vmware.vim25.OptionValue;
|
||||
import com.vmware.vim25.OvfCreateImportSpecParams;
|
||||
import com.vmware.vim25.OvfCreateImportSpecResult;
|
||||
import com.vmware.vim25.OvfFileItem;
|
||||
|
|
@ -91,8 +91,8 @@ public class HypervisorHostHelper {
|
|||
private static final String UNTAGGED_VLAN_NAME = "untagged";
|
||||
|
||||
public static VirtualMachineMO findVmFromObjectContent(VmwareContext context,
|
||||
ObjectContent[] ocs, String name) {
|
||||
|
||||
ObjectContent[] ocs, String name, String instanceNameCustomField) {
|
||||
|
||||
if(ocs != null && ocs.length > 0) {
|
||||
for(ObjectContent oc : ocs) {
|
||||
String vmNameInvCenter = null;
|
||||
|
|
@ -102,16 +102,14 @@ public class HypervisorHostHelper {
|
|||
for(DynamicProperty objProp : objProps) {
|
||||
if(objProp.getName().equals("name")) {
|
||||
vmNameInvCenter = (String)objProp.getVal();
|
||||
} else if(objProp.getName().contains(instanceNameCustomField)) {
|
||||
if(objProp.getVal() != null)
|
||||
vmInternalCSName = ((CustomFieldStringValue)objProp.getVal()).getValue();
|
||||
}
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(context, oc.getObj());
|
||||
// Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
|
||||
try {
|
||||
vmInternalCSName = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_VM_INTERNAL_NAME);
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unable to retrieve custom field value for internal VM name");
|
||||
}
|
||||
|
||||
if ( (vmNameInvCenter != null && name.equalsIgnoreCase(vmNameInvCenter))
|
||||
|| (vmInternalCSName != null && name.equalsIgnoreCase(vmInternalCSName)) ) {
|
||||
VirtualMachineMO vmMo = new VirtualMachineMO(context, oc.getObj());
|
||||
return vmMo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue