ResourceContainer parentResourceContainer = getResourceContainer(parentResourceId);
ResourceComponent parentResourceComponent = parentResourceContainer.getResourceComponent();
// Get the discovery component responsible for discovering resources of the specified resource type.
PluginComponentFactory pluginComponentFactory = PluginContainer.getInstance().getPluginComponentFactory();
ResourceDiscoveryComponent discoveryComponent = pluginComponentFactory.getDiscoveryComponent(resourceType,
parentResourceContainer);
DiscoveredResourceDetails discoveredResourceDetails;
if (discoveryComponent instanceof ManualAddFacet) {
// The plugin is using the new manual add API.
ResourceDiscoveryContext<ResourceComponent<?>> discoveryContext = new ResourceDiscoveryContext<ResourceComponent<?>>(
resourceType, parentResourceComponent, parentResourceContainer.getResourceContext(),
SystemInfoFactory.createSystemInfo(), new ArrayList<ProcessScanResult>(0),
new ArrayList<Configuration>(0), this.configuration.getContainerName(),
this.configuration.getPluginContainerDeployment());
// Ask the plugin's discovery component to find the new resource, throwing exceptions if it cannot be
// found at all.
discoveredResourceDetails = discoverResource(discoveryComponent, pluginConfiguration, discoveryContext,
parentResourceContainer);
if (discoveredResourceDetails == null) {
log.info("Plugin Error: During manual add, discovery component method ["
+ discoveryComponent.getClass().getName() + ".discoverResource()] returned null "
+ "(either the Resource type was blacklisted or the plugin developer "
+ "did not implement support for manually discovered Resources correctly).");
throw new PluginContainerException("The [" + resourceType.getPlugin()
+ "] plugin does not properly support manual addition of [" + resourceType.getName()
+ "] Resources.");
}
} else {
// The plugin is using the old manual add API, which we must continue to support to maintain
// backward compatibility.
log.info("Plugin Warning: Resource type '" + resourceType.getName() + "' from '"
+ resourceType.getPlugin() + "' is still using the deprecated manual Resource add API, "
+ "rather than the new ManualAddFacet interface.");
List<Configuration> pluginConfigurations = new ArrayList<Configuration>(1);
pluginConfigurations.add(pluginConfiguration);
ResourceDiscoveryContext<ResourceComponent<?>> discoveryContext = new ResourceDiscoveryContext<ResourceComponent<?>>(
resourceType, parentResourceComponent, parentResourceContainer.getResourceContext(),
SystemInfoFactory.createSystemInfo(), new ArrayList<ProcessScanResult>(0), pluginConfigurations,
this.configuration.getContainerName(), this.configuration.getPluginContainerDeployment());
// Ask the plugin's discovery component to find the new resource, throwing exceptions if it cannot be
// found at all.
try {
Set<DiscoveredResourceDetails> discoveredResources = invokeDiscoveryComponent(
parentResourceContainer, discoveryComponent, discoveryContext);
if ((discoveredResources == null) || discoveredResources.isEmpty()) {
log.info("Plugin Error: During manual add, discovery component method ["
+ discoveryComponent.getClass().getName() + ".discoverResources()] returned "
+ discoveredResources + " when passed a single plugin configuration "
+ "(either the resource type was blacklisted or the plugin developer "
+ "did not implement support for manually discovered resources correctly).");
throw new PluginContainerException("The [" + resourceType.getPlugin()
+ "] plugin does not properly support manual addition of [" + resourceType.getName()
+ "] resources.");
}
discoveredResourceDetails = discoveredResources.iterator().next();
} catch (DiscoverySuspendedException e) {
String message = "The discovery class ["
+ discoveryComponent.getClass().getName()
+ "]"
+ " uses a legacy implementation of \"manual add\" functionality. Some of the child resources"
+ " with the resource type ["
+ resourceType
+ "] under the parent resource ["