Search in sources :

Example 1 with InvalidCollectorVersionFaultMsg

use of com.vmware.vim25.InvalidCollectorVersionFaultMsg in project photon-model by vmware.

the class EnumerationClient method queryDisksAvailabilityinVSphere.

/**
 * Utility method that crosschecks the availability of independent disks in vSphere.
 */
public List<String> queryDisksAvailabilityinVSphere(Map<String, Object> diskInfoInLocalIndex) {
    final List<String> unAvailableDisks = new ArrayList<>();
    diskInfoInLocalIndex.entrySet().stream().forEach(entry -> {
        DiskService.DiskState diskState = Utils.fromJson(entry.getValue(), DiskService.DiskState.class);
        String diskDirectoryPath = diskState.customProperties.get(CustomProperties.DISK_PARENT_DIRECTORY);
        String datastoreName = diskState.customProperties.get(CustomProperties.DISK_DATASTORE_NAME);
        HostDatastoreBrowserSearchSpec searchSpec = createHostDatastoreBrowserSearchSpecForDisk(diskState.id);
        try {
            this.getMoRef.entityProps(this.finder.datastore(datastoreName).object, "browser").entrySet().stream().forEach(item -> {
                try {
                    ManagedObjectReference hostBrowser = (ManagedObjectReference) item.getValue();
                    ManagedObjectReference task = connection.getVimPort().searchDatastoreSubFoldersTask(hostBrowser, diskDirectoryPath, searchSpec);
                    TaskInfo info = VimUtils.waitTaskEnd(connection, task);
                    ArrayOfHostDatastoreBrowserSearchResults searchResult = (ArrayOfHostDatastoreBrowserSearchResults) info.getResult();
                    if (searchResult == null) {
                        // Folder is deleted.
                        unAvailableDisks.add(entry.getKey());
                    } else {
                        searchResult.getHostDatastoreBrowserSearchResults().stream().forEach(result -> {
                            // Folder is present but the vmdk file is deleted.
                            if (CollectionUtils.isEmpty(result.getFile())) {
                                unAvailableDisks.add(entry.getKey());
                            }
                        });
                    }
                } catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg | InvalidCollectorVersionFaultMsg | FileFaultFaultMsg | InvalidDatastoreFaultMsg ex) {
                    logger.info("Unable to get the availability status for " + entry.getKey());
                }
            });
        } catch (InvalidPropertyFaultMsg | RuntimeFaultFaultMsg | FinderException ex) {
            logger.info("Unable to find the datastore : " + datastoreName);
        }
    });
    return unAvailableDisks;
}
Also used : InvalidCollectorVersionFaultMsg(com.vmware.vim25.InvalidCollectorVersionFaultMsg) ArrayList(java.util.ArrayList) HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) DiskService(com.vmware.photon.controller.model.resources.DiskService) TaskInfo(com.vmware.vim25.TaskInfo) InvalidDatastoreFaultMsg(com.vmware.vim25.InvalidDatastoreFaultMsg) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) FileFaultFaultMsg(com.vmware.vim25.FileFaultFaultMsg) ArrayOfHostDatastoreBrowserSearchResults(com.vmware.vim25.ArrayOfHostDatastoreBrowserSearchResults) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with InvalidCollectorVersionFaultMsg

use of com.vmware.vim25.InvalidCollectorVersionFaultMsg in project photon-model by vmware.

the class VimUtils method waitTaskEnd.

public static TaskInfo waitTaskEnd(Connection connection, ManagedObjectReference task) throws InvalidCollectorVersionFaultMsg, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    WaitForValues waitForValues = new WaitForValues(connection);
    Object[] info = waitForValues.wait(task, new String[] { VimPath.task_info }, new String[] { VimPath.task_info_state }, new Object[][] { new Object[] { TaskInfoState.SUCCESS, TaskInfoState.ERROR } });
    return (TaskInfo) info[0];
}
Also used : TaskInfo(com.vmware.vim25.TaskInfo) WaitForValues(com.vmware.photon.controller.model.adapters.vsphere.util.connection.WaitForValues)

Example 3 with InvalidCollectorVersionFaultMsg

use of com.vmware.vim25.InvalidCollectorVersionFaultMsg 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)

Example 4 with InvalidCollectorVersionFaultMsg

use of com.vmware.vim25.InvalidCollectorVersionFaultMsg in project photon-model by vmware.

the class WaitForValues method wait.

/**
 * Handle Updates for a single object. waits till expected values of
 * properties to check are reached Destroys the ObjectFilter when done.
 * The matching properties will be added to the list of properties to fetch.
 *
 * @param moRef       MOR of the Object to wait for
 * @param fetchProps  Properties list to filter
 * @param propsToMatch Properties list to check for expected values these be properties
 *                     of a property in the filter properties list
 * @param propsMatchValues values for properties to end the wait
 * @param maxWaitSeconds how long to wait for the condition to be met, use null to wait forever
 * @return the requested properties or null if expected values not reached within timeout
 * @throws RuntimeFaultFaultMsg
 * @throws InvalidPropertyFaultMsg
 * @throws InvalidCollectorVersionFaultMsg
 */
public Object[] wait(ManagedObjectReference moRef, String[] fetchProps, String[] propsToMatch, Object[][] propsMatchValues, Integer maxWaitSeconds) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvalidCollectorVersionFaultMsg {
    VimPortType vimPort;
    ManagedObjectReference filterSpecRef = null;
    ServiceContent serviceContent;
    try {
        vimPort = this.connection.getVimPort();
        serviceContent = this.connection.getServiceContent();
    } catch (Throwable cause) {
        throw new BaseHelper.HelperException(cause);
    }
    // version string is initially null
    String version = "";
    Object[] endVals = new Object[propsToMatch.length];
    String stateVal = null;
    PropertyFilterSpec spec = propertyFilterSpec(moRef, fetchProps, propsToMatch);
    filterSpecRef = vimPort.createFilter(serviceContent.getPropertyCollector(), spec, true);
    boolean reached = false;
    UpdateSet updateset;
    List<PropertyFilterUpdate> filtupary;
    List<ObjectUpdate> objupary;
    List<PropertyChange> propchgary;
    // override maxWaitSeconds to give the timeout a chance to be hit earlier
    WaitOptions waitOptions = new WaitOptions();
    waitOptions.setMaxWaitSeconds(DEFAULT_MAX_WAIT_SECONDS);
    long timeout = -1;
    if (maxWaitSeconds != null) {
        timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(maxWaitSeconds);
    }
    while (!reached && shouldContinue(timeout)) {
        updateset = vimPort.waitForUpdatesEx(serviceContent.getPropertyCollector(), version, waitOptions);
        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) {
                propchgary = objup.getChangeSet();
                for (PropertyChange propchg : propchgary) {
                    updateValues(propsToMatch, endVals, propchg);
                }
            }
        }
        // Also exit the WaitForUpdates loop if this is the case.
        for (int chgi = 0; chgi < endVals.length && !reached; chgi++) {
            for (int vali = 0; vali < propsMatchValues[chgi].length && !reached; vali++) {
                Object expectedValue = propsMatchValues[chgi][vali];
                Object endVal = endVals[chgi];
                if (endVal == null) {
                // Do Nothing
                } else if (endVal.toString().contains("val: null")) {
                    // Due to some issue in JAX-WS De-serialization getting the information from
                    // the nodes
                    Element stateElement = (Element) endVal;
                    if (stateElement.getFirstChild() != null) {
                        stateVal = stateElement.getFirstChild().getTextContent();
                        reached = expectedValue.toString().equalsIgnoreCase(stateVal) || reached;
                    }
                } else {
                    expectedValue = propsMatchValues[chgi][vali];
                    reached = expectedValue.equals(endVal) || reached;
                    stateVal = "filtervals";
                }
            }
        }
    }
    if (!reached) {
        // got here but condition not reached; timeout
        return null;
    }
    Object[] retVal = null;
    // Destroy the filter when we are done.
    try {
        vimPort.destroyPropertyFilter(filterSpecRef);
    } catch (RuntimeFaultFaultMsg e) {
        e.printStackTrace();
    }
    if (stateVal != null) {
        if (stateVal.equalsIgnoreCase("ready")) {
            retVal = new Object[] { HttpNfcLeaseState.READY };
        }
        if (stateVal.equalsIgnoreCase("error")) {
            retVal = new Object[] { HttpNfcLeaseState.ERROR };
        }
        if (stateVal.equals("filtervals")) {
            retVal = fetchFinalValues(moRef, fetchProps);
        }
    } else {
        retVal = new Object[] { HttpNfcLeaseState.ERROR };
    }
    return retVal;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) PropertyFilterUpdate(com.vmware.vim25.PropertyFilterUpdate) PropertyChange(com.vmware.vim25.PropertyChange) Element(org.w3c.dom.Element) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) WaitOptions(com.vmware.vim25.WaitOptions) VimPortType(com.vmware.vim25.VimPortType) ServiceContent(com.vmware.vim25.ServiceContent) UpdateSet(com.vmware.vim25.UpdateSet) ObjectUpdate(com.vmware.vim25.ObjectUpdate) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)3 ObjectUpdate (com.vmware.vim25.ObjectUpdate)2 PropertyChange (com.vmware.vim25.PropertyChange)2 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)2 PropertyFilterUpdate (com.vmware.vim25.PropertyFilterUpdate)2 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)2 TaskInfo (com.vmware.vim25.TaskInfo)2 UpdateSet (com.vmware.vim25.UpdateSet)2 WaitForValues (com.vmware.photon.controller.model.adapters.vsphere.util.connection.WaitForValues)1 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)1 DiskService (com.vmware.photon.controller.model.resources.DiskService)1 ArrayOfHostDatastoreBrowserSearchResults (com.vmware.vim25.ArrayOfHostDatastoreBrowserSearchResults)1 FileFaultFaultMsg (com.vmware.vim25.FileFaultFaultMsg)1 HostDatastoreBrowserSearchSpec (com.vmware.vim25.HostDatastoreBrowserSearchSpec)1 InvalidCollectorVersionFaultMsg (com.vmware.vim25.InvalidCollectorVersionFaultMsg)1 InvalidDatastoreFaultMsg (com.vmware.vim25.InvalidDatastoreFaultMsg)1 InvalidPropertyFaultMsg (com.vmware.vim25.InvalidPropertyFaultMsg)1 ObjectSpec (com.vmware.vim25.ObjectSpec)1 PropertySpec (com.vmware.vim25.PropertySpec)1 ServiceContent (com.vmware.vim25.ServiceContent)1