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