Hi guys, this is my situation:
in dynprop there is a Managed Object Reference to a datastoreBrowser Object
then I create a new HostDatastoreBrowserSearchSpec
then I retrieve the Managed Object Reference to a task with the command searchDatastore_Task
then I retrieve the "info" property of this task and obtain the TaskInfo Data Object (info.result doesn't work)
All is good until now. Yes because in the TaskInfo Data Object I can't found the
object "result" that should be an HostDatastoreBrowserSearch Object
And this happen even if the "state" of the task is running and if the "error" field
in the TaskInfo is null.
I suppose it is not a problem of permissions (I'm the only administrator).
Maybe I wrong datastore path? Should I put the path of a virtual machine? Is there a mistake in the code?
thnk you
for (int pci = 0; pci < pcary.length; pci++)
{
dynprop=pcary\[pci];
ManagedObjectReference mor= (ManagedObjectReference)dynprop.getVal();
HostDatastoreBrowserSearchSpec hdbss = new HostDatastoreBrowserSearchSpec();
hdbss.setSearchCaseInsensitive(true);
FileQueryFlags fqa=new FileQueryFlags();
fqa.setFileSize(true);
fqa.setFileType(true);
fqa.setModification(true);
hdbss.setDetails(fqa);
ManagedObjectReference task = service.searchDatastoreTask(mor, "\[storage1] /",hdbss);
PropertySpec prtask = new PropertySpec();
prtask.setPathSet(new String[] \{"info"});
prtask.setType("Task");
PropertyFilterSpec spectask = new PropertyFilterSpec();
spectask.setPropSet(new PropertySpec[] \{prtask});
spectask.setObjectSet(new ObjectSpec[] \{ new ObjectSpec() });
spectask.getObjectSet(0).setObj(task);
spectask.getObjectSet(0).setSkip(new Boolean(false));
spectask.getObjectSet(0).setSelectSet(new SelectionSpec[] \{ folderTraversalSpec });
ObjectContent\[] ocarytask = service.retrieveProperties(propCol, new PropertyFilterSpec[] \{ spectask });
ObjectContent octask = null;
ManagedObjectReference mortask = null;
DynamicProperty[] pcarytask = null;
for (int ocitask = 0; ocitask < ocarytask.length; ocitask++)
{
octask = ocarytask\[ocitask];
mortask = octask.getObj();
pcarytask = octask.getPropSet();
}
}
the SearchDatastore_Task returns a mor to task you need to monitor (wait till its done), then you retrieve the properties of the taskMor: Set type = "Task" and pathSet = "info.result".
In place of 'Task' set the type of PropertySpec to 'TaskInfo'
info property is of 'TaskInfo' type and not 'Task'
prtask.setType("TaskInfo");
Hi SaranshG, I'm sorry for the late, I was on Holiday
I tried your suggestion but it gives me an error on the
Retrieveproperties
AxisFault
faultCode: ServerFaultCode
faultSubcode:
faultString: The request refers to an unexpected or unknown type.
faultActor:
faultNode:
faultDetail:
\{urn:vim2}InvalidTypeFault:
ecc. ecc.
Is it normal?
the SearchDatastore_Task returns a mor to task you need to monitor (wait till its done), then you retrieve the properties of the taskMor: Set type = "Task" and pathSet = "info.result".
Ehm...yes, in fact it's this that I did (I think),
but the problem is that the info.result in each case is empty
Try this running this code
package com.vmware.samples.version;
import com.vmware.apputils.*;
public class FilterVMDisk {
private void getDataStore(String [] args) throws Exception{
com.vmware.apputils.ClientBase cb = ClientBase.initialize("FilterVMDisk",args);
cb.connect();
com.vmware.vim.ManagedObjectReference dsmor = null;
String dsName = null;
com.vmware.vim.ManagedObjectReference vmmor = cb.getServiceUtil().getDecendentMoRef(null,"VirtualMachine","First");
if(vmmor != null) {
com.vmware.vim.ManagedObjectReference \[] dsArray = (com.vmware.vim.ManagedObjectReference [])cb.getServiceUtil().getDynamicProperty(vmmor,"datastore");
for(int i=0; i<dsArray.length; i++) {
com.vmware.vim.DatastoreSummary dsSummary = (com.vmware.vim.DatastoreSummary)cb.getServiceUtil().getDynamicProperty(dsArray[i],"summary");
if(dsSummary.getName().equalsIgnoreCase("storage1")) {
dsmor = dsArray[i];
dsName = dsSummary.getName();
}
}
if(dsmor != null) {
com.vmware.vim.ManagedObjectReference dsBrowser = (com.vmware.vim.ManagedObjectReference)cb.getServiceUtil().getDynamicProperty(dsmor,"browser");
com.vmware.vim.HostDatastoreBrowserSearchSpec searchSpec = new com.vmware.vim.HostDatastoreBrowserSearchSpec();
com.vmware.vim.VmDiskFileQuery fQuery = new com.vmware.vim.VmDiskFileQuery();
com.vmware.vim.FileQuery [] arr = \{fQuery};
searchSpec.setQuery(arr);
com.vmware.vim.ManagedObjectReference taskmor = cb.getConnection().getService().searchDatastore_Task(dsBrowser,"\["\+dsName+"]",null);
String res = cb.getServiceUtil().waitForTask(taskmor);
System.out.println("Result " + res);
com.vmware.vim.TaskInfo tInfo = (com.vmware.vim.TaskInfo)cb.getServiceUtil().getDynamicProperty(taskmor,"info");
System.out.println(tInfo.getResult().getClass().getCanonicalName());
com.vmware.vim.HostDatastoreBrowserSearchResults searchResult = (com.vmware.vim.HostDatastoreBrowserSearchResults)tInfo.getResult();
com.vmware.vim.FileInfo \[] fInfos = (com.vmware.vim.FileInfo [])searchResult.getFile();
for(int j=0 ; j<fInfos.length; j++) {
System.out.println("File Name " + fInfos[j].getPath());
}
}
else {
System.out.println("No datastore found");
}
}
else {
System.out.println("No Host Found");
}
}
public static void main(String[] args) throws Exception {
FilterVMDisk obj = new FilterVMDisk();
obj.getDataStore(args);
}
}
Hi
I discovered which was the problem: I didn't wait the end of task, and if I want the results of the search I have to wait until the SUCCESS state
I just added this line after the searchtask line
Thread.sleep(1000);
and now it works!
tnk you for all guys. you sent me on the right direction
byez
Message was edited by:
uehguaglio