コード例 #1
0
  private void assertIsNOTDisabledType(ResourceType type) {
    try {
      metadataManager.getDiscoveryClass(type);
    } catch (ResourceTypeNotEnabledException ok) {
      assert false : "Discovery: should not have been disabled: " + type;
    }

    try {
      metadataManager.getComponentClass(type);
    } catch (ResourceTypeNotEnabledException ok) {
      assert false : "Component: should not have been disabled: " + type;
    }
  }
コード例 #2
0
 private void outputTypes() {
   Set<ResourceType> allTypes = metadataManager.getRootTypes();
   for (ResourceType type : allTypes) {
     outputType(type, 0);
   }
   System.out.flush();
 }
コード例 #3
0
 private ResourceType getResourceType(ResourceType typeToGet) {
   for (ResourceType type : metadataManager.getAllTypes()) {
     if (type.equals(typeToGet)) {
       return type;
     }
   }
   return null;
 }
コード例 #4
0
  /**
   * Finds all plugins using the plugin finder defined in the <code>pluginContainerConfiguration
   * </code> and {@link #loadPlugin(java.net.URL, ClassLoader,
   * org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor) loads} each plugin found.
   */
  public PluginManager(
      PluginContainerConfiguration pluginContainerConfiguration,
      PluginLifecycleListenerManager pluginLifecycleListenerManager) {

    if (pluginContainerConfiguration == null) {
      throw new NullPointerException("pluginContainerConfiguration is null");
    }
    if (pluginLifecycleListenerManager == null) {
      throw new NullPointerException("pluginLifecycleListenerManager is null");
    }

    this.pluginContainerConfiguration = pluginContainerConfiguration;
    this.pluginLifecycleListenerMgr = pluginLifecycleListenerManager;
    loadedPluginEnvironments = new HashMap<String, PluginEnvironment>();
    loadedPlugins = new ArrayList<Plugin>();
    metadataManager = new PluginMetadataManager();

    metadataManager.setDisabledResourceTypes(
        pluginContainerConfiguration.getDisabledResourceTypes());
    updateLoadedPlugins =
        new UpdateLoadedPlugins() {
          PluginTransformer transformer = new PluginTransformer();

          public void execute(PluginDescriptor pluginDescriptor, URL pluginURL) {
            Plugin plugin = transformer.toPlugin(pluginDescriptor, pluginURL);
            loadedPlugins.add(plugin);
          }
        };

    PluginFinder finder = pluginContainerConfiguration.getPluginFinder();
    File tmpDir = pluginContainerConfiguration.getTemporaryDirectory();
    List<String> disabledPlugins = pluginContainerConfiguration.getDisabledPlugins();

    // The root classloader for all plugins will have all classes hidden except for those configured
    // in the regex.
    // Notice this root classloader has no jar URLs - it will provide no classes except for what it
    // will allow
    // the parent to expose as dictated by the regex.
    ClassLoader thisClassLoader = this.getClass().getClassLoader();
    String rootPluginClassLoaderRegex =
        pluginContainerConfiguration.getRootPluginClassLoaderRegex();
    ClassLoader rootCL =
        new RootPluginClassLoader(new URL[] {}, thisClassLoader, rootPluginClassLoaderRegex);

    // build our empty class loader manager - we use it to create and manage our plugin's
    // classloaders
    Map<String, URL> pluginNamesUrls = new HashMap<String, URL>();
    // Save descriptors for later use, so we don't need to parse them twice.
    Map<URL, PluginDescriptor> descriptors = new HashMap<URL, PluginDescriptor>();
    PluginDependencyGraph graph = new PluginDependencyGraph();
    boolean createResourceCL = pluginContainerConfiguration.isCreateResourceClassloaders();
    this.classLoaderManager =
        new ClassLoaderManager(pluginNamesUrls, graph, rootCL, tmpDir, createResourceCL);

    if (finder == null) {
      log.warn(
          "No plugin finder was specified in the plugin container configuration - this should only occur within test environments.");
      return;
    }

    try {
      Collection<URL> pluginUrls = finder.findPlugins();

      // first, we need to parse all descriptors so we can build the dependency graph
      for (URL url : pluginUrls) {
        log.debug("Plugin found at: " + url);
        try {
          PluginDescriptor descriptor = AgentPluginDescriptorUtil.loadPluginDescriptorFromUrl(url);
          if (!disabledPlugins.contains(descriptor.getName())) {
            AgentPluginDescriptorUtil.addPluginToDependencyGraph(graph, descriptor);
            pluginNamesUrls.put(descriptor.getName(), url);
            descriptors.put(url, descriptor);
          } else {
            log.info("Not loading disabled plugin: " + url);
          }
        } catch (Throwable t) {
          // probably due to invalid XML syntax in the deployment descriptor - the plugin will be
          // ignored
          log.error(
              "Plugin at [" + url + "] could not be loaded and will therefore not be deployed.", t);
          continue;
        }
      }

      // our graph is complete, get the order that we have to deploy the plugins
      List<String> deploymentOrder = graph.getDeploymentOrder();

      // now deploy the plugins in the proper order, making sure we build the proper classloaders
      for (String nextPlugin : deploymentOrder) {
        URL pluginUrl = pluginNamesUrls.get(nextPlugin);

        try {
          ClassLoader pluginClassLoader =
              this.classLoaderManager.obtainPluginClassLoader(nextPlugin);
          PluginDescriptor descriptor = descriptors.get(pluginUrl);
          loadPlugin(pluginUrl, pluginClassLoader, descriptor);
        } catch (Throwable t) {
          // for some reason, the plugin failed to load - it will be ignored, and its depending
          // plugins will also fail later
          log.error(
              "Plugin ["
                  + nextPlugin
                  + "] at ["
                  + pluginUrl
                  + "] could not be loaded and will therefore not be deployed.",
              t);
          continue;
        }
      }
      log.info("Deployed plugins: " + this.loadedPlugins);
      metadataManager.cleanupDescriptors();
    } catch (Exception e) {
      shutdown(); // have to clean up the environments (e.g. unpacked jars) we might have already
      // created
      log.error("Error initializing plugin container", e);
      throw new RuntimeException("Cannot initialize the plugin container", e);
    }
  }