Search in sources :

Example 1 with ArrayOfHostDatastoreBrowserSearchResults

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

Aggregations

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 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 RuntimeFaultFaultMsg (com.vmware.vim25.RuntimeFaultFaultMsg)1 TaskInfo (com.vmware.vim25.TaskInfo)1 ArrayList (java.util.ArrayList)1