use of com.vmware.vim25.PropertyFilterUpdate in project cloudstack by apache.
the class VmwareClient method waitForValues.
/**
* Handle Updates for a single object. waits till expected values of
* properties to check are reached Destroys the ObjectFilter when done.
*
* @param objmor
* MOR of the Object to wait for
* @param filterProps
* Properties list to filter
* @param endWaitProps
* Properties list to check for expected values these be
* properties of a property in the filter properties list
* @param expectedVals
* values for properties to end the wait
* @return true indicating expected values were met, and false otherwise
* @throws RuntimeFaultFaultMsg
* @throws InvalidPropertyFaultMsg
* @throws InvalidCollectorVersionFaultMsg
*/
private Object[] waitForValues(ManagedObjectReference objmor, String[] filterProps, String[] endWaitProps, Object[][] expectedVals) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg {
// version string is initially null
String version = "";
Object[] endVals = new Object[endWaitProps.length];
Object[] filterVals = new Object[filterProps.length];
PropertyFilterSpec spec = new PropertyFilterSpec();
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(objmor);
oSpec.setSkip(Boolean.FALSE);
spec.getObjectSet().add(oSpec);
PropertySpec pSpec = new PropertySpec();
pSpec.getPathSet().addAll(Arrays.asList(filterProps));
pSpec.setType(objmor.getType());
spec.getPropSet().add(pSpec);
ManagedObjectReference propertyCollector = getPropCol();
ManagedObjectReference filterSpecRef = vimPort.createFilter(propertyCollector, spec, true);
boolean reached = false;
UpdateSet updateset = null;
List<PropertyFilterUpdate> filtupary = null;
List<ObjectUpdate> objupary = null;
List<PropertyChange> propchgary = null;
while (!reached) {
updateset = vimPort.waitForUpdates(propertyCollector, version);
if (updateset == null || updateset.getFilterSet() == null) {
continue;
}
version = updateset.getVersion();
// Make this code more general purpose when PropCol changes later.
filtupary = updateset.getFilterSet();
for (PropertyFilterUpdate filtup : filtupary) {
objupary = filtup.getObjectSet();
for (ObjectUpdate objup : objupary) {
// TODO: Handle all "kind"s of updates.
if (objup.getKind() == ObjectUpdateKind.MODIFY || objup.getKind() == ObjectUpdateKind.ENTER || objup.getKind() == ObjectUpdateKind.LEAVE) {
propchgary = objup.getChangeSet();
for (PropertyChange propchg : propchgary) {
updateValues(endWaitProps, endVals, propchg);
updateValues(filterProps, filterVals, propchg);
}
}
}
}
Object expctdval = null;
// 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++) {
expctdval = expectedVals[chgi][vali];
reached = expctdval.equals(endVals[chgi]) || reached;
}
}
}
// Destroy the filter when we are done.
vimPort.destroyPropertyFilter(filterSpecRef);
return filterVals;
}
Aggregations