I thought using CheckForUpdates would only return changes since the last call. The version is incremented during each call and passed to subsequent calls. I only want to see properties that are different. Any ideas?
Hi,
The CheckForUpdates will only return the properties that have changed from the last call. But when you call the method for the first time it would return you the complete list of properties with their current values.
I am not sure of which script you are running and the properties that you are tracking using the CheckForUpdates, So I would not be able to comment on the exact problem that you are facing.
Suppose If you are tracking config.extraConfig property of the Virtual Machine then even when you change the value of any one of the properties defined you will still receive the complete array of the OptionValue as you are tracking the config.extraConfig property which is an array of OptionValue.
I hope the above information helps.
~ Sidharth
I found the problem. There were two things going on here.
1) I was creating a new Property Filter Spec each time. This was causing an accumulation of new Property Collector filters. My bad!
2) The UpdateSet return from checkForUpdates will never be null, but if there are no changes, then the PropertyFilterUpdate set will be null.
UpdateSet changeData = conn.getService().checkForUpdates(pcRef, _version);
PropertyFilterUpdate[] pfUpdate = null;
if (changeData != null)
pfUpdate = changeData.getFilterSet();
Thanks for your response. You described the behavior that I was
expecting, but it is not behaving that way. Every call returns a
complete update set of all properties. The properties are for the
VirtualMachine managed object.
I tried setting partialUpdates to TRUE with no effect. I also tried
using retrieveProperties before checkForUpdates, still with no effect.
None of the properties in the pathSet have changed between calls.
The code is below.
public void updateProperties () throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("VirtualMachine");
pSpec.setAll(new Boolean(false));
pSpec.setPathSet(new String[]
{"name" ,
"config.annotation",
"runtime.powerState",
"runtime.bootTime",
"runtime.host",
"runtime.connectionState",
"runtime.maxCpuUsage",
"runtime.maxMemoryUsage",
"runtime.memoryOverhead",
"runtime.suspendTime"});
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(vm);
oSpec.setSkip(Boolean.FALSE);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setObjectSet(new ObjectSpec[] );
pfSpec.setPropSet(new PropertySpec[] );
ManagedObjectReference pcRef = conn.getPropCol();
ManagedObjectReference pFilter =
conn.getService().createFilter(pcRef, pfSpec, Boolean.TRUE);
UpdateSet changeData = conn.getService().checkForUpdates(pcRef,
_version);
// IF NOTHING HAS CHANGED, EXPECT changeData TO BE null
if(changeData != null) {
// Update the version
_version = changeData.getVersion();
PropertyFilterUpdate[] pfUpdate =
changeData.getFilterSet();
for(int a=0; a<pfUpdate.length; ++a) {
// Only interested in our filter
if(pFilter.get_value().equals(pfUpdate[a].getFilter().get_value())) {
ObjectUpdate[] objUpdate =
pfUpdate[a].getObjectSet();
for(int b=0; b<objUpdate.length; ++b) {
ObjectUpdate obj = objUpdate[b];
PropertyChange[] cProps =
obj.getChangeSet();
// For each property collected
from the VirtualMachine
for(int ps=0; ps <
cProps.length; ++ps) {
PropertyChange pc =
cProps[ps];
if
(pc.getName().equals("name"))
name = (String)
pc.getVal();
ETC.