use of com.vmware.vim25.PropertyFilterSpec in project cloudstack by apache.
the class VMwareUtil method waitForValues.
private static Object[] waitForValues(VMwareConnection connection, ManagedObjectReference morObj, String[] filterProps, String[] endWaitProps, Object[][] expectedVals) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg {
String version = "";
Object[] endVals = new Object[endWaitProps.length];
Object[] filterVals = new Object[filterProps.length];
PropertyFilterSpec spec = new PropertyFilterSpec();
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(morObj);
oSpec.setSkip(Boolean.FALSE);
spec.getObjectSet().add(oSpec);
PropertySpec pSpec = new PropertySpec();
pSpec.getPathSet().addAll(Arrays.asList(filterProps));
pSpec.setType(morObj.getType());
spec.getPropSet().add(pSpec);
ManagedObjectReference propertyCollector = connection.getServiceContent().getPropertyCollector();
ManagedObjectReference filterSpecRef = connection.getVimPortType().createFilter(propertyCollector, spec, true);
boolean reached = false;
UpdateSet updateSet;
List<PropertyFilterUpdate> lstPropertyFilterUpdates;
List<ObjectUpdate> lstObjectUpdates;
List<PropertyChange> lstPropertyChanges;
while (!reached) {
updateSet = connection.getVimPortType().waitForUpdates(propertyCollector, version);
if (updateSet == null || updateSet.getFilterSet() == null) {
continue;
}
version = updateSet.getVersion();
lstPropertyFilterUpdates = updateSet.getFilterSet();
for (PropertyFilterUpdate propertyFilterUpdate : lstPropertyFilterUpdates) {
lstObjectUpdates = propertyFilterUpdate.getObjectSet();
for (ObjectUpdate objUpdate : lstObjectUpdates) {
if (objUpdate.getKind() == ObjectUpdateKind.MODIFY || objUpdate.getKind() == ObjectUpdateKind.ENTER || objUpdate.getKind() == ObjectUpdateKind.LEAVE) {
lstPropertyChanges = objUpdate.getChangeSet();
for (PropertyChange propchg : lstPropertyChanges) {
updateValues(endWaitProps, endVals, propchg);
updateValues(filterProps, filterVals, propchg);
}
}
}
}
Object expectedValue;
// Also, exit the WaitForUpdates loop if this is the case.
for (int chgi = 0; chgi < endVals.length && !reached; chgi++) {
for (int vali = 0; vali < expectedVals[chgi].length && !reached; vali++) {
expectedValue = expectedVals[chgi][vali];
reached = expectedValue.equals(endVals[chgi]) || reached;
}
}
}
// Destroy the filter when we are done.
connection.getVimPortType().destroyPropertyFilter(filterSpecRef);
return filterVals;
}
Aggregations