eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject incubator-eagle git commit: Load app web classes and app topology classes using configured lib dir
Date Mon, 08 Aug 2016 09:15:15 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/develop 660bfbd3f -> 5c0db6aff


Load app web classes and app topology classes using configured lib dir

https://issues.apache.org/jira/browse/EAGLE-426

Author: yonzhang <yonzhang2012@gmail.com>

Closes #310 from yonzhang/develop.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/5c0db6af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/5c0db6af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/5c0db6af

Branch: refs/heads/develop
Commit: 5c0db6aff007defee467878a820845edcb70f9d9
Parents: 660bfbd
Author: yonzhang <yonzhang2012@gmail.com>
Authored: Mon Aug 8 17:14:56 2016 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Mon Aug 8 17:14:56 2016 +0800

----------------------------------------------------------------------
 .../config/ApplicationProviderDescConfig.java   |  6 ++-
 .../impl/ApplicationProviderServiceImpl.java    | 12 +++---
 .../app/spi/AbstractApplicationProvider.java    |  5 ++-
 .../app/ApplicationProviderDescConfigTest.java  |  4 +-
 ...org.apache.eagle.app.spi.ApplicationProvider |  2 +-
 eagle-server/pom.xml                            | 41 ++++++++++----------
 .../apache/eagle/server/ServerApplication.java  | 21 +++++++++-
 .../src/main/resources/application.conf         |  3 ++
 8 files changed, 59 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5c0db6af/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/config/ApplicationProviderDescConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/config/ApplicationProviderDescConfig.java
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/config/ApplicationProviderDescConfig.java
index 1fbae16..824d81a 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/config/ApplicationProviderDescConfig.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/config/ApplicationProviderDescConfig.java
@@ -18,6 +18,7 @@ package org.apache.eagle.app.config;
 
 
 import org.apache.eagle.alert.engine.coordinator.StreamDefinition;
+import org.apache.eagle.app.spi.AbstractApplicationProvider;
 import org.apache.eagle.metadata.model.ApplicationDocs;
 import org.apache.eagle.metadata.model.Configuration;
 import org.slf4j.Logger;
@@ -110,11 +111,12 @@ public class ApplicationProviderDescConfig {
 
     private final static Logger LOG = LoggerFactory.getLogger(ApplicationProviderDescConfig.class);
 
-    public static ApplicationProviderDescConfig loadFromXML(String configXmlFile){
+    public static ApplicationProviderDescConfig loadFromXML(AbstractApplicationProvider provider,
String configXmlFile){
         try {
             JAXBContext jc = JAXBContext.newInstance(ApplicationProviderDescConfig.class);
             Unmarshaller unmarshaller = jc.createUnmarshaller();
-            InputStream is = ApplicationProviderDescConfig.class.getResourceAsStream(configXmlFile);
+//            InputStream is = ApplicationProviderDescConfig.class.getResourceAsStream(configXmlFile);
+            InputStream is = provider.getClass().getResourceAsStream(configXmlFile);
             if(is == null){
                 is = ApplicationProviderDescConfig.class.getResourceAsStream("/"+configXmlFile);
             }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5c0db6af/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderServiceImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderServiceImpl.java
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderServiceImpl.java
index 2297ea5..ec2ad6c 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderServiceImpl.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderServiceImpl.java
@@ -44,13 +44,13 @@ public class ApplicationProviderServiceImpl implements ApplicationProviderServic
 
     @Inject
     public ApplicationProviderServiceImpl(Config config){
-        LOG.info("Initializing {}",this.getClass().getCanonicalName());
+        LOG.warn("Initializing {}",this.getClass().getCanonicalName());
         this.config = config;
         String appProviderLoaderClass = this.config.hasPath(APP_PROVIDER_LOADER_CLASS_KEY)?
                 this.config.getString(APP_PROVIDER_LOADER_CLASS_KEY):ApplicationProviderLoader.getDefaultAppProviderLoader();
-        LOG.info("Initializing {} = {}",APP_PROVIDER_LOADER_CLASS_KEY,appProviderLoaderClass);
+        LOG.warn("Initializing {} = {}",APP_PROVIDER_LOADER_CLASS_KEY,appProviderLoaderClass);
         appProviderLoader = initializeAppProviderLoader(appProviderLoaderClass);
-        LOG.info("Initialized {}",appProviderLoader);
+        LOG.warn("Initialized {}",appProviderLoader);
         reload();
     }
 
@@ -65,9 +65,9 @@ public class ApplicationProviderServiceImpl implements ApplicationProviderServic
 
     public synchronized void reload(){
         appProviderLoader.reset();
-        LOG.info("Loading application providers ...");
+        LOG.warn("Loading application providers ...");
         appProviderLoader.load();
-        LOG.info("Loaded {} application providers",appProviderLoader.getProviders().size());
+        LOG.warn("Loaded {} application providers",appProviderLoader.getProviders().size());
     }
 
     public Collection<ApplicationProvider> getProviders(){
@@ -86,4 +86,4 @@ public class ApplicationProviderServiceImpl implements ApplicationProviderServic
     public ApplicationDesc getApplicationDescByType(String appType) {
         return appProviderLoader.getApplicationProviderByType(appType).getApplicationDesc();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5c0db6af/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
index bf1e587..2299eca 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/AbstractApplicationProvider.java
@@ -48,14 +48,15 @@ public abstract class AbstractApplicationProvider<T extends Application>
impleme
 
     protected AbstractApplicationProvider(String applicationDescConfig) {
         this();
-        ApplicationProviderDescConfig descWrapperConfig = ApplicationProviderDescConfig.loadFromXML(applicationDescConfig);
+        ApplicationProviderDescConfig descWrapperConfig = ApplicationProviderDescConfig.loadFromXML(this,
applicationDescConfig);
         setType(descWrapperConfig.getType());
         setVersion(descWrapperConfig.getVersion());
         setName(descWrapperConfig.getName());
         setDocs(descWrapperConfig.getDocs());
         try {
             if (descWrapperConfig.getAppClass() != null) {
-                setAppClass((Class<T>) Class.forName(descWrapperConfig.getAppClass()));
+//                setAppClass((Class<T>) Class.forName(descWrapperConfig.getAppClass()));
+                setAppClass((Class<T>) Class.forName(descWrapperConfig.getAppClass(),
true, this.getClass().getClassLoader()));
                 if (!Application.class.isAssignableFrom(applicationDesc.getAppClass())) {
                     throw new IllegalStateException(descWrapperConfig.getAppClass() + " is
not sub-class of " + Application.class.getCanonicalName());
                 }

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5c0db6af/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/ApplicationProviderDescConfigTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/ApplicationProviderDescConfigTest.java
b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/ApplicationProviderDescConfigTest.java
index 5a6980c..cd28d86 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/ApplicationProviderDescConfigTest.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/ApplicationProviderDescConfigTest.java
@@ -27,7 +27,7 @@ import java.io.InputStream;
 public class ApplicationProviderDescConfigTest {
     @Test
     public void testApplicationDescWrapperConfigLoadFromXML(){
-        ApplicationProviderDescConfig config = ApplicationProviderDescConfig.loadFromXML("TestApplicationMetadata.xml");
+        ApplicationProviderDescConfig config = ApplicationProviderDescConfig.loadFromXML(null,
"TestApplicationMetadata.xml");
         Assert.assertNotNull(config);
     }
 
@@ -50,4 +50,4 @@ public class ApplicationProviderDescConfigTest {
             throw new RuntimeException("Failed to load application descriptor configuration:
"+configXmlFile,ex);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5c0db6af/eagle-examples/eagle-app-example/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
----------------------------------------------------------------------
diff --git a/eagle-examples/eagle-app-example/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
b/eagle-examples/eagle-app-example/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
index 808e4ab..f42e30f 100644
--- a/eagle-examples/eagle-app-example/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
+++ b/eagle-examples/eagle-app-example/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
@@ -14,4 +14,4 @@
 # limitations under the License.
 
 org.apache.eagle.app.example.ExampleApplicationProvider
-org.apache.eagle.app.example.ExampleApplicationProvider2
\ No newline at end of file
+##org.apache.eagle.app.example.ExampleApplicationProvider2

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5c0db6af/eagle-server/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-server/pom.xml b/eagle-server/pom.xml
index 6083616..e8264a2 100644
--- a/eagle-server/pom.xml
+++ b/eagle-server/pom.xml
@@ -127,27 +127,26 @@
             <artifactId>eagle-common</artifactId>
             <version>${project.version}</version>
         </dependency>
-
-        <dependency>
-            <groupId>org.apache.eagle</groupId>
-            <artifactId>eagle-app-example</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.eagle</groupId>
-            <artifactId>eagle-jpm-app</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.eagle</groupId>
-            <artifactId>eagle-security-hbase-auditlog</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.eagle</groupId>
-            <artifactId>eagle-security-hbase-web</artifactId>
-            <version>${project.version}</version>
-        </dependency>
+        <!--<dependency>-->
+            <!--<groupId>org.apache.eagle</groupId>-->
+            <!--<artifactId>eagle-app-example</artifactId>-->
+            <!--<version>${project.version}</version>-->
+        <!--</dependency>-->
+        <!--<dependency>-->
+            <!--<groupId>org.apache.eagle</groupId>-->
+            <!--<artifactId>eagle-jpm-app</artifactId>-->
+            <!--<version>${project.version}</version>-->
+        <!--</dependency>-->
+        <!--<dependency>-->
+            <!--<groupId>org.apache.eagle</groupId>-->
+            <!--<artifactId>eagle-security-hbase-auditlog</artifactId>-->
+            <!--<version>${project.version}</version>-->
+        <!--</dependency>-->
+        <!--<dependency>-->
+            <!--<groupId>org.apache.eagle</groupId>-->
+            <!--<artifactId>eagle-security-hbase-web</artifactId>-->
+            <!--<version>${project.version}</version>-->
+        <!--</dependency>-->
     </dependencies>
     <build>
         <resources>

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5c0db6af/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java b/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java
index d7bd14a..43f5c10 100644
--- a/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java
+++ b/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java
@@ -16,8 +16,10 @@
  */
 package org.apache.eagle.server;
 
+import com.google.inject.Binding;
 import com.hubspot.dropwizard.guice.GuiceBundle;
 import com.sun.jersey.api.core.PackagesResourceConfig;
+import com.typesafe.config.Config;
 import io.dropwizard.Application;
 import io.dropwizard.assets.AssetsBundle;
 import io.dropwizard.setup.Bootstrap;
@@ -28,9 +30,14 @@ import org.apache.eagle.alert.coordinator.CoordinatorListener;
 import org.apache.eagle.alert.resource.SimpleCORSFiler;
 import org.apache.eagle.app.ApplicationGuiceModule;
 import org.apache.eagle.common.module.CommonGuiceModule;
+import org.apache.eagle.common.module.ConfigServiceProvider;
 import org.apache.eagle.metadata.persistence.MetadataStore;
 
 import javax.servlet.DispatcherType;
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Arrays;
 import java.util.EnumSet;
 
 class ServerApplication extends Application<ServerConfig> {
@@ -59,6 +66,18 @@ class ServerApplication extends Application<ServerConfig> {
         environment.jersey().register(RESTExceptionMapper.class);
         environment.jersey().setUrlPattern(ServerConfig.getApiBasePath());
 
+        Binding<Config> b = guiceBundle.getInjector().getBinding(Config.class);
+        Config conf = b.getProvider().get();
+        if(conf.hasPath("application.provider.dir")) {
+            File loc = new File(conf.getString("application.provider.dir"));
+            File[] jarFiles = loc.listFiles(file -> file.getPath().toLowerCase().endsWith(".jar"));
+            URL[] urls = new URL[jarFiles.length];
+            for (int i = 0; i < jarFiles.length; i++) {
+                urls[i] = jarFiles[i].toURI().toURL();
+            }
+            URLClassLoader jarFileClassLoader = new URLClassLoader(urls);
+            Thread.currentThread().setContextClassLoader(jarFileClassLoader);
+        }
         // Automatically scan all REST resources
         new PackagesResourceConfig(ServerConfig.getResourcePackage()).getClasses().forEach(environment.jersey()::register);
 
@@ -81,4 +100,4 @@ class ServerApplication extends Application<ServerConfig> {
         // context listener
         environment.servlets().addServletListeners(new CoordinatorListener());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/5c0db6af/eagle-server/src/main/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/resources/application.conf b/eagle-server/src/main/resources/application.conf
index ce75909..9860245 100644
--- a/eagle-server/src/main/resources/application.conf
+++ b/eagle-server/src/main/resources/application.conf
@@ -49,6 +49,9 @@
 		"storm": {
 			"nimbusHost": "localhost"
 			"nimbusThriftPort": 6627
+		},
+		"provider" : {
+//			"dir" : "/tmp/eagle"
 		}
 	}
 }


Mime
View raw message