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;
}
Aggregations