[ https://issues.apache.org/jira/browse/METRON-777?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16124295#comment-16124295 ]
ASF GitHub Bot commented on METRON-777: --------------------------------------- Github user mattf-horton commented on a diff in the pull request: https://github.com/apache/metron/pull/530#discussion_r132801955 --- Diff: bundles-lib/src/main/java/org/apache/metron/bundles/VFSBundleClassLoader.java --- @@ -0,0 +1,515 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.metron.bundles; + +import java.io.IOException; +import java.net.URL; +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.security.SecureClassLoader; +import java.security.cert.Certificate; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; +import java.util.jar.Attributes; +import java.util.jar.Attributes.Name; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemManager; +import org.apache.commons.vfs2.NameScope; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * <p> + * A <tt>ClassLoader</tt> for loading BUNDLES (plugin archives). BUNDLEs are designed to + * allow isolating bundles of code (comprising one-or-more + * plugin classes and their + * dependencies) from other such bundles; this allows for dependencies and + * processors that require conflicting, incompatible versions of the same + * dependency to run in a single instance of a given process.</p> + * + * <p> + * <tt>BundleClassLoader</tt> follows the delegation model described in + * {@link ClassLoader#findClass(java.lang.String) ClassLoader.findClass(...)}; + * classes are first loaded from the parent <tt>ClassLoader</tt>, and only if + * they cannot be found there does the <tt>BundleClassLoader</tt> provide a + * definition. Specifically, this means that resources are loaded from the application's + * <tt>conf</tt> + * and <tt>lib</tt> directories first, and if they cannot be found there, are + * loaded from the BUNDLE.</p> + * + * <p> + * The packaging of a BUNDLE is such that it is a ZIP file with the following + * directory structure: + * + * <pre> + * +META-INF/ + * +-- bundled-dependencies/ + * +-- <JAR files> + * +-- MANIFEST.MF + * </pre> + * </p> + * + * <p> + * The MANIFEST.MF file contains the same information as a typical JAR file but + * also includes two additional bundle properties: {@code Bundle-Id} and + * {@code Bundle-Dependency-Id}. + * </p> + * + * <p> + * The {@code Bundle-Id} provides a unique identifier for this BUNDLE. + * </p> + * + * <p> + * The {@code Bundle-Dependency-Id} is optional. If provided, it indicates that + * this BUNDLE should inherit all of the dependencies of the BUNDLE with the provided + * ID. Often times, the BUNDLE that is depended upon is referred to as the Parent. + * This is because its ClassLoader will be the parent ClassLoader of the + * dependent BUNDLE. + * </p> + * + * <p> + * If a BUNDLE is built using the Bundles Maven Plugin, the {@code Bundle-Id} property + * will be set to the artifactId of the BUNDLE. The {@code Bundle-Dependency-Id} will + * be set to the artifactId of the BUNDLE that is depended upon. For example, if + * BUNDLE A is defined as such: + * + * <pre> + * ... + * <artifactId>bundle-a</artifactId> + * <packaging>bundle</packaging> + * ... + * <dependencies> + * <dependency> + * <groupId>group</groupId> + * <artifactId>bundle-z</artifactId> + * <b><type>bundle</type></b> + * </dependency> + * </dependencies> + * </pre> + * </p> + * + * + * <p> + * Then the MANIFEST.MF file that is created for Bundle A will have the following + * properties set: + * <ul> + * <li>{@code {Foo}-Id: bundle-a}</li> + * <li>{@code {Foo}-Dependency-Id: bundle-z}</li> + * </ul> + * Where is configurable by BundleProperty META_ID_PREFIX [ default Bundle ] + * </p> + * + * <p> + * Note, above, that the {@code type} of the dependency is set to {@code foo}. + * </p> + * + * <p> + * If the Bundle has more than one dependency of {@code type} {@code Foo}, then the + * Maven Bundle plugin will fail to build the Bundle. + * </p> + * + * This classloader is Metron Bundle aware, in that it understands that the passed in root + * FileObjects may be Bundles, + * This class is adapted from Apache Commons VFS + * VFSClassLoader class v.2.1 + * And the Apache Nifi NarClassLoader v. 1.2 + * + * @see FileSystemManager#createFileSystem + */ +public class VFSBundleClassLoader extends SecureClassLoader { --- End diff -- Nice job on the below. > Create a plugin system for Metron based on 'NAR' > ------------------------------------------------ > > Key: METRON-777 > URL: https://issues.apache.org/jira/browse/METRON-777 > Project: Metron > Issue Type: New Feature > Reporter: Otto Fowler > Assignee: Otto Fowler > > The success of the Metron project will be greatly dependent on community > participation, and with that the ability to adapt and extend Metron without > having to maintain a fork of the project. > As organizations and individuals look to extend the Metron system with custom > parsers, enrichments, and stellar functions that may be proprietary in > nature, the ability to develop and deploy these extensions outside the Metron > code base is critically important. > To that end, and after community discussion and proposal we create or > formalize the 'plugin' development story in Metron. > The proposal is to adapt the Apache Nifi NAR system for use in Metron. This > will provide the system with: > * archetype(s) for developer projects and independent development > * defined packaging and metadata for 'plugin' products > * loading and instantiation with classloader isolation capabilities > * removing the necessity for shading plugin jars > These capabilities will also enable other features, such as plugin lifecycle, > plugin configuration+redeployment, and other things. > The plugin archetypes and their installation will be a followon -- This message was sent by Atlassian JIRA (v6.4.14#64029)