eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject [1/2] incubator-eagle git commit: [EAGLE-442] Support ApplicationProvider to extend extensible guice modules
Date Thu, 11 Aug 2016 04:14:33 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/develop c65138b8b -> 6d5907daa


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6d5907da/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 43f5c10..6299e28 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,10 +16,7 @@
  */
 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,30 +25,15 @@ import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.jaxrs.listing.ApiListingResource;
 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 org.apache.eagle.server.module.GuideBundleLoader;
 
 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> {
-    private GuiceBundle<ServerConfig> guiceBundle;
-
     @Override
     public void initialize(Bootstrap<ServerConfig> bootstrap) {
-        guiceBundle = GuiceBundle.<ServerConfig>newBuilder()
-                .addModule(new CommonGuiceModule())
-                .addModule(MetadataStore.getInstance())
-                .addModule(new ApplicationGuiceModule())
-                .setConfigClass(ServerConfig.class)
-                .build();
-        bootstrap.addBundle(guiceBundle);
+        bootstrap.addBundle(GuideBundleLoader.load());
         bootstrap.addBundle(new AssetsBundle("/assets","/","index.html","/"));
     }
 
@@ -66,18 +48,6 @@ 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);
 

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6d5907da/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java b/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java
index 55c5c5d..3bbe335 100644
--- a/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java
+++ b/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java
@@ -20,7 +20,7 @@ import com.typesafe.config.Config;
 import com.typesafe.config.ConfigFactory;
 import io.dropwizard.Configuration;
 
-class ServerConfig extends Configuration {
+public class ServerConfig extends Configuration {
     private final static String SERVER_NAME = "Apache Eagle";
     private final static String SERVER_VERSION = "0.5.0-incubating";
     private final static String API_BASE_PATH = "/rest/*";

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6d5907da/eagle-server/src/main/java/org/apache/eagle/server/module/GuideBundleLoader.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/module/GuideBundleLoader.java
b/eagle-server/src/main/java/org/apache/eagle/server/module/GuideBundleLoader.java
new file mode 100644
index 0000000..3dc3eec
--- /dev/null
+++ b/eagle-server/src/main/java/org/apache/eagle/server/module/GuideBundleLoader.java
@@ -0,0 +1,64 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.server.module;
+
+import com.google.inject.Module;
+import com.hubspot.dropwizard.guice.GuiceBundle;
+import org.apache.eagle.app.module.ApplicationExtensionLoader;
+import org.apache.eagle.common.module.GlobalScope;
+import org.apache.eagle.common.module.ModuleRegistry;
+import org.apache.eagle.metadata.persistence.MetadataStore;
+import org.apache.eagle.metadata.persistence.MetadataStoreFactory;
+import org.apache.eagle.server.ServerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class GuideBundleLoader {
+    private final static Logger LOGGER = LoggerFactory.getLogger(GuideBundleLoader.class);
+    public static GuiceBundle<ServerConfig> load(List<Module> modules){
+        MetadataStore metadataStoreModule = MetadataStoreFactory.getInstance();
+        ServeModule serveBaseModule = new ServeModule();
+        GuiceBundle.Builder<ServerConfig> builder = GuiceBundle.newBuilder();
+        ModuleRegistry registry = ApplicationExtensionLoader.load(serveBaseModule);
+        List<Module> metadataExtensions = metadataStoreModule.getModules(registry);
+        int extensionNum = 0;
+        if(metadataExtensions!=null){
+            extensionNum = metadataExtensions.size();
+            metadataExtensions.forEach(builder::addModule);
+        }
+        LOGGER.info("Loaded {} modules (scope: metadata)",extensionNum,metadataStoreModule);
+
+        List<Module> globalExtensions = registry.getModules(GlobalScope.class);
+        extensionNum = 0;
+        if(globalExtensions!=null){
+            extensionNum = globalExtensions.size();
+            globalExtensions.forEach(builder::addModule);
+        }
+        LOGGER.info("Loaded {} modules (scope: global)",extensionNum,metadataStoreModule);
+
+        if(modules!=null) modules.forEach(builder::addModule);
+        return builder.addModule(serveBaseModule)
+                .setConfigClass(ServerConfig.class)
+                .build();
+    }
+
+    public static GuiceBundle<ServerConfig> load(){
+        return load(null);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6d5907da/eagle-server/src/main/java/org/apache/eagle/server/module/ServeModule.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/module/ServeModule.java b/eagle-server/src/main/java/org/apache/eagle/server/module/ServeModule.java
new file mode 100644
index 0000000..3b7d7f9
--- /dev/null
+++ b/eagle-server/src/main/java/org/apache/eagle/server/module/ServeModule.java
@@ -0,0 +1,31 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.server.module;
+
+import com.google.inject.AbstractModule;
+import org.apache.eagle.app.module.ApplicationGuiceModule;
+import org.apache.eagle.common.module.CommonGuiceModule;
+import org.apache.eagle.metadata.persistence.MetadataStoreFactory;
+
+public class ServeModule extends AbstractModule {
+    @Override
+    protected void configure() {
+        install(new CommonGuiceModule());
+        install(new ApplicationGuiceModule());
+        install(MetadataStoreFactory.getInstance());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6d5907da/eagle-server/src/test/java/org/apache/eagle/server/GuideBundleLoaderTest.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/test/java/org/apache/eagle/server/GuideBundleLoaderTest.java
b/eagle-server/src/test/java/org/apache/eagle/server/GuideBundleLoaderTest.java
new file mode 100644
index 0000000..4316dfd
--- /dev/null
+++ b/eagle-server/src/test/java/org/apache/eagle/server/GuideBundleLoaderTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.server;
+
+import com.hubspot.dropwizard.guice.GuiceBundle;
+import org.apache.eagle.server.module.GuideBundleLoader;
+import org.junit.Test;
+
+public class GuideBundleLoaderTest {
+    @Test
+    public void testLoad(){
+        GuiceBundle<ServerConfig> bundle = GuideBundleLoader.load();
+    }
+}


Mime
View raw message