I found an older post on these forums containing example code for filtering extensions that isn't working for me in 6.7.u2 for my HTML5 plug-in. The plug-in is never visible even when customProperty returns true. Could you tell me where the mistake is?
<extension id="com.violin.violinplugin.datastore.configureView">
<extendedPoint>vsphere.core.datastore.manageViews</extendedPoint>
<object>
<name>Violin Storage</name>
<contentSpec>
<url>/ui/violinplugin/resources/datastore-edit.html</url>
</contentSpec>
</object>
<metadata>
<objectType>Datastore</objectType>
<propertyConditions>
<com.vmware.data.query.CompositeConstraint>
<nestedConstraints>
<com.vmware.data.query.PropertyConstraint>
<propertyName>customProperty</propertyName>
<comparator>EQUALS</comparator>
<comparableValue>
<Boolean>true</Boolean>
</comparableValue>
</com.vmware.data.query.PropertyConstraint>
</nestedConstraints>
<conjoiner>AND</conjoiner>
</com.vmware.data.query.CompositeConstraint>
</propertyConditions>
</metadata>
</extension>
PropertyProviderAdapter code (with a slightly modified constructor signature) copied off these forums:
public class ViolinPropertyAdapter implements PropertyProviderAdapter {
private Log _logger = LogFactory.getLog(ViolinPropertyAdapter.class);
private static final String CUSTOMPROPERTY = "customProperty";
public ViolinPropertyAdapter(DataService dataService,
ObjectReferenceService objectReferenceService,
DataServiceExtensionRegistry extensionRegistry,
UserSessionService userSessionService) {
TypeInfo vmTypeInfo = new TypeInfo();
vmTypeInfo.type = "Datastore";
vmTypeInfo.properties = new String[]{CUSTOMPROPERTY};
TypeInfo[] providerTypes = new TypeInfo[]{vmTypeInfo};
extensionRegistry.registerDataAdapter(this, providerTypes);
}
@Override
public ResultSet getProperties(PropertyRequestSpec propertyRequest) {
_logger = LogFactory.getLog(ViolinPropertyAdapter.class);
_logger.info("getProperties()");
ResultSet result = new ResultSet();
try {
List<ResultItem> resultItems = new ArrayList<ResultItem>();
if(propertyRequest.properties != null && propertyRequest.properties.length > 0) {
String[] listPropertyNames = propertyRequest.properties[0].propertyNames;
for(String propertyName : listPropertyNames) {
for(Object dsRef : propertyRequest.objects) {
ResultItem resultItem = getDsProperties(dsRef, propertyName);
if(resultItem != null) {
resultItems.add(resultItem);
}
}
}
} else
result.items = resultItems.toArray(new ResultItem[]{});
} catch(Exception e) {
// Passing the exception in the result allows to display an error
// notification
// in the client UI.
result.error = e;
}
return result;
}
private ResultItem getDsProperties(Object dsRef, String propertyName) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ResultItem ri = new ResultItem();
ri.resourceObject = dsRef;
PropertyValue pvCustomProperty = new PropertyValue();
pvCustomProperty.resourceObject = dsRef;
pvCustomProperty.propertyName = CUSTOMPROPERTY;
boolean val = new Random().nextBoolean();
_logger.info(CUSTOMPROPERTY + "=" + val);
pvCustomProperty.value = val;// here taken the random boolean value which will load in
// plugin.xml. On true return you can filter the extension
// point using property
ri.properties = new PropertyValue[]{pvCustomProperty};
return ri;
}
}
And finally, the entries in my log file, that shows the PropertyProviderAdapter being called:
[2020-04-08 23:02:58] [INFO] com.violin.violinplugin.adapters.ViolinPropertyAdapter:44 - getProperties()
[2020-04-08 23:02:58] [INFO] com.violin.violinplugin.adapters.ViolinPropertyAdapter:76 - customProperty=false
[2020-04-08 23:03:14] [INFO] com.violin.violinplugin.adapters.ViolinPropertyAdapter:44 - getProperties()
[2020-04-08 23:03:14] [INFO] com.violin.violinplugin.adapters.ViolinPropertyAdapter:76 - customProperty=false
[2020-04-08 23:03:15] [INFO] com.violin.violinplugin.adapters.ViolinPropertyAdapter:44 - getProperties()
[2020-04-08 23:03:15] [INFO] com.violin.violinplugin.adapters.ViolinPropertyAdapter:76 - customProperty=true
[2020-04-08 23:03:17] [INFO] com.violin.violinplugin.adapters.ViolinPropertyAdapter:44 - getProperties()
[2020-04-08 23:03:17] [INFO] com.violin.violinplugin.adapters.ViolinPropertyAdapter:76 - customProperty=true
If you could give me a working code example of filtering based of a datastore property for 6.7, or tell me what needs to be fixed in the simple example I've included, that'd really help me out. Thanks!