Hi,
I am trying to use the DAM library to gather the list of VM's (and possibly other objects once I get this part for VM's working). In reading the documentation, it looked to me like the DataByQuerySpecRequest is what I need to use. Specifically, I was referencing the following document:
vSphere 5.5 Documentation Center
This document section talks about the DataByQuerySpecRequest, but doesn't give specific examples for it, so I have sort of modeled my code after the similar methods which do have examples {DataByConstraintRequest}.
One thing I thought was odd is that the example uses the "QuerySpecUtil" which is only a sample class and not part of the real API. At any rate, I reviewed the HostSampleSummarySectionViewMediator.as sample as well. I was also able to find this reference document which does give an example for DataByQuerySpecRequest, but the example is filled with errors (sample link below):
I tried to follow this documentation as best as I could, but there is quite a bit of ambiguity, and I have not done something correctly. I was hoping someone else can see what I might have missed or done incorrectly.
From my code, I have a primary mediator class. This mediator class is calling my Data Manager Access class, which would/could use my Data Model class (DAMModel)... but one big piece of the puzzle that I think I'm missing is, I don't know where to pass my Data Model. But perhaps I don't need it when using the DataByQuerySpecRequest? I just can't tell based on my interpretation of the docs. I think I am making the request correctly, but I am not getting any response. That is to say, nothing at all happens after I make the request... no success, no error, no exceptions, nothing.
Any help is appreciated, thanks in advance!
// DAMModel.as
package com.acme.models {
import com.vmware.core.model.DataObject;
[Model(type="VirtualMachine")]
public class DAMModel extends DataObject {
[Model(property="name")]
public var vmName:String;
[Model(property="summary.vm")]
public var vmMOR:String;
}
}
// DAMLibraryAccess.as
package com.acme.models {
import com.acme.models.DAMModel;
import com.vmware.data.Constraint;
import com.vmware.data.ResourceSpec;
import com.vmware.data.query.DataUpdateMode;
import com.vmware.data.query.DataUpdateSpec;
import com.vmware.data.query.QuerySpec;
import com.vmware.data.query.ResultSpec;
import com.vmware.data.query.events.DataByQuerySpecRequest;
import flash.events.EventDispatcher;
import mx.collections.ArrayCollection;
[Event(name="{com.vmware.data.query.events.DataByConstraintRequest.REQUEST_ID}",
type="com.vmware.data.query.events.DataByConstraintRequest")]
[Event(name="{com.vmware.data.query.events.DataByQuerySpecRequest.REQUEST_ID}",
type="com.vmware.data.query.events.DataByQuerySpecRequest")]
public class DAMLibraryAccess extends EventDispatcher {
public function GetAllVMObjects():void {
var constraint:Constraint = new Constraint();
constraint.targetType = "vm";
var resourceSpec:ResourceSpec = new ResourceSpec();
resourceSpec.constraint = constraint;
var resultSpec:ResultSpec = new ResultSpec();
resultSpec.maxResultCount = 1000;
resultSpec.offset = 0;
resultSpec.order = null;
var querySpec:QuerySpec = new QuerySpec();
querySpec.name = "damLibaryAccess";
querySpec.resourceSpec = resourceSpec;
querySpec.resultSpec = resultSpec;
var request:DataByQuerySpecRequest = DataByQuerySpecRequest.newInstance(querySpec,
new DataRequestInfo( new DataUpdateSpec( new DataUpdateMode( "IMPLICIT" ) ) ) );
dispatchEvent(request);
}
[ResponseHandler(name="{com.vmware.data.query.events.DataByQuerySpecRequest.RESPONSE_ID}")]
public function AllVMObjectsRetrieved(request:DataByQuerySpecRequest,
result:ArrayCollection,
error:Error):void {
var result1:Array = result[0] as Array;
var temp:String = "debug_breakpoint"; // dummy code just to set a breakpoint here... breakpoint never hits
}
}
}
// ActionViewMediator.as
package com.acme.views {
import com.acme.models.DAMLibraryAccess;
import flash.events.EventDispatcher;
[Event(name="{com.vmware.ui.events.NavigationRequest.NAVIGATION_REQUEST}",
type="com.vmware.ui.events.NavigationRequest")]
public class ActionViewMediator extends EventDispatcher {
// Settings view's extension id (defined in plugin.xml)
private var _view:ActionView;
/**
* set view
* The view associated with this mediator.
*
* @param value ActionView view
*
* @return void
*/
[View]
public function set view(value:ActionView):void {
// The view is injected here by the Framework when it is first created,
// and reset to null when it is no longer needed.
if ((value == null) && (_view != null)) {
// TODO: do something here
}
_view = value;
if (_view == null) {
return;
}
var dla:DAMLibraryAccess = new DAMLibraryAccess();
dla.GetAllVMObjects();
}
}
}