@Override
public DiscoveredResourceDetails discoverResource(Configuration pluginConfig,
ResourceDiscoveryContext discoveryContext) throws InvalidPluginConfigurationException {
DiscoveredResourceDetails details;
DetectionMechanism detectionMechanism = getDetectionMechanism(pluginConfig);
log.debug("resource will have detection mechanism of [" + detectionMechanism + "]");
switch (detectionMechanism) {
case INTERNAL:
if (SystemInfoFactory.isNativeSystemInfoDisabled()) {
throw new InvalidPluginConfigurationException(
"The native system is disabled - cannot use the internal detection mechanism");
}
if (!SystemInfoFactory.isNativeSystemInfoAvailable()) {
throw new InvalidPluginConfigurationException(
"The native system is not available - cannot use the internal detection mechanism");
}
String version = LsofComponent.VERSION;
details = new DiscoveredResourceDetails(discoveryContext.getResourceType(), "*lsof-internal*",
DEFAULT_NAME, version, DEFAULT_DESCRIPTION, pluginConfig, null);
break;
case EXTERNAL:
// do all that we can to make sure we have a valid full path to the executable
PropertySimple executable = pluginConfig.getSimple(LsofComponent.PLUGINCONFIG_EXECUTABLE);
executable.setStringValue(findExecutable(executable.getStringValue()));
details = super.discoverResource(pluginConfig, discoveryContext);
details.setResourceName(DEFAULT_NAME);
break;
default:
throw new InvalidPluginConfigurationException("Unknown detection mechanism: " + detectionMechanism);
}