Search in sources :

Example 1 with PropertyFilterUpdate

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;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) PropertyFilterUpdate(com.vmware.vim25.PropertyFilterUpdate) PropertyChange(com.vmware.vim25.PropertyChange) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) UpdateSet(com.vmware.vim25.UpdateSet) ObjectUpdate(com.vmware.vim25.ObjectUpdate) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 ObjectSpec (com.vmware.vim25.ObjectSpec)1 ObjectUpdate (com.vmware.vim25.ObjectUpdate)1 PropertyChange (com.vmware.vim25.PropertyChange)1 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)1 PropertyFilterUpdate (com.vmware.vim25.PropertyFilterUpdate)1 PropertySpec (com.vmware.vim25.PropertySpec)1 UpdateSet (com.vmware.vim25.UpdateSet)1