You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dj...@apache.org on 2016/07/07 16:31:10 UTC

[3/7] incubator-quarks git commit: Add mbean support for register jar

Add mbean support for register jar


Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/6f2fe038
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/6f2fe038
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/6f2fe038

Branch: refs/heads/master
Commit: 6f2fe038dffa26097a0f82909bd28c70ab768d7e
Parents: ea2a478
Author: Daniel J. Debrunner <de...@us.ibm.com>
Authored: Thu Jun 30 09:50:50 2016 -0700
Committer: Daniel J. Debrunner <de...@us.ibm.com>
Committed: Thu Jun 30 09:50:50 2016 -0700

----------------------------------------------------------------------
 .../mbeans/ApplicationServiceMXBean.java        | 16 ++++++
 .../topology/services/ApplicationService.java   |  4 +-
 .../topology/services/TopologyBuilder.java      |  5 ++
 .../topology/services/TestApplications.java     |  2 +-
 common-build.xml                                |  2 +
 .../direct/appservice/AppServiceTest.java       | 12 +++--
 .../quarks/runtime/appservice/AppService.java   |  2 +-
 .../runtime/appservice/AppServiceControl.java   |  5 ++
 .../quarks/test/fvt/iot/IotAppServiceTest.java  | 54 +++++++++++++++++---
 9 files changed, 89 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/api/topology/src/main/java/quarks/topology/mbeans/ApplicationServiceMXBean.java
----------------------------------------------------------------------
diff --git a/api/topology/src/main/java/quarks/topology/mbeans/ApplicationServiceMXBean.java b/api/topology/src/main/java/quarks/topology/mbeans/ApplicationServiceMXBean.java
index 591e5f1..c027fd0 100644
--- a/api/topology/src/main/java/quarks/topology/mbeans/ApplicationServiceMXBean.java
+++ b/api/topology/src/main/java/quarks/topology/mbeans/ApplicationServiceMXBean.java
@@ -19,6 +19,7 @@ under the License.
 package quarks.topology.mbeans;
 
 import quarks.topology.services.ApplicationService;
+import quarks.topology.services.TopologyBuilder;
 
 /**
  * Control MBean for the application service.
@@ -40,4 +41,19 @@ public interface ApplicationServiceMXBean {
      * @see ApplicationService
      */
     void submit(String applicationName, String jsonConfig) throws Exception;
+    
+    /**
+     * Register a jar file containing applications with
+     * the application service. Any service providers
+     * in the jar of type {@link TopologyBuilder} will
+     * be registered as applications.
+     * 
+     * @param jarURL URL for the jar file.
+     * @param jsonConfig JSON configuration serialized as a String (currently unused).
+     * @throws Exception Error registering jar.
+     * 
+     * @see ApplicationService
+     * @see TopologyBuilder
+     */
+    void registerJar(String jarURL, String jsonConfig) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/api/topology/src/main/java/quarks/topology/services/ApplicationService.java
----------------------------------------------------------------------
diff --git a/api/topology/src/main/java/quarks/topology/services/ApplicationService.java b/api/topology/src/main/java/quarks/topology/services/ApplicationService.java
index 7bc2fe3..1859901 100644
--- a/api/topology/src/main/java/quarks/topology/services/ApplicationService.java
+++ b/api/topology/src/main/java/quarks/topology/services/ApplicationService.java
@@ -18,7 +18,6 @@ under the License.
 */
 package quarks.topology.services;
 
-import java.net.MalformedURLException;
 import java.util.Set;
 
 import com.google.gson.JsonObject;
@@ -87,8 +86,9 @@ public interface ApplicationService {
      * be the classpath of this service.
      * 
      * @param jarURL URL of Jar containing new applications.
+     * @param jsonConfig Configuration information, currently unused.
      */
-    void registerJar(String jarURL) throws MalformedURLException;
+    void registerJar(String jarURL, String jsonConfig) throws Exception;
     
     /**
      * Returns the names of applications registered with this service.

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/api/topology/src/main/java/quarks/topology/services/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/api/topology/src/main/java/quarks/topology/services/TopologyBuilder.java b/api/topology/src/main/java/quarks/topology/services/TopologyBuilder.java
index 2c47d23..e6659a8 100644
--- a/api/topology/src/main/java/quarks/topology/services/TopologyBuilder.java
+++ b/api/topology/src/main/java/quarks/topology/services/TopologyBuilder.java
@@ -25,6 +25,11 @@ import quarks.topology.Topology;
 
 /**
  * Represents an topology that can be built.
+ * 
+ * A class implementing {@code TopologyBuilder} can
+ * be registered as a service provider in a jar file for
+ * automatic application registration using
+ * {@link ApplicationService#registerJar(String, String)}.
  *
  */
 public interface TopologyBuilder {

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/api/topology/src/test/java/quarks/test/topology/services/TestApplications.java
----------------------------------------------------------------------
diff --git a/api/topology/src/test/java/quarks/test/topology/services/TestApplications.java b/api/topology/src/test/java/quarks/test/topology/services/TestApplications.java
index cff5cde..6b37b18 100644
--- a/api/topology/src/test/java/quarks/test/topology/services/TestApplications.java
+++ b/api/topology/src/test/java/quarks/test/topology/services/TestApplications.java
@@ -31,7 +31,7 @@ import quarks.topology.services.TopologyBuilder;
  *
  */
 public class TestApplications {
-    
+        
     private static abstract class App implements TopologyBuilder {
 
         @Override

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/common-build.xml
----------------------------------------------------------------------
diff --git a/common-build.xml b/common-build.xml
index 4d35364..1d28c6a 100644
--- a/common-build.xml
+++ b/common-build.xml
@@ -199,6 +199,8 @@
 	         <path refid="test.classpath"/>
 	       </classpath>
 	       <sysproperty key="quarks.build.ci" value="${quarks.build.ci}"/>
+	       <!-- Allow tests to know the root directory -->
+	       <sysproperty key="quarks.test.root.dir" value="${quarks.dir}"/>
 	       <assertions><enable/></assertions>
 	       <formatter type="xml"/>
 	       <!-- Only use the brief formatter for a continuous integration build" -->

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/providers/direct/src/test/java/quarks/test/providers/direct/appservice/AppServiceTest.java
----------------------------------------------------------------------
diff --git a/providers/direct/src/test/java/quarks/test/providers/direct/appservice/AppServiceTest.java b/providers/direct/src/test/java/quarks/test/providers/direct/appservice/AppServiceTest.java
index 1c27db2..1a891d7 100644
--- a/providers/direct/src/test/java/quarks/test/providers/direct/appservice/AppServiceTest.java
+++ b/providers/direct/src/test/java/quarks/test/providers/direct/appservice/AppServiceTest.java
@@ -19,8 +19,10 @@ under the License.
 package quarks.test.providers.direct.appservice;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
 import java.net.URL;
 
 import org.junit.Test;
@@ -31,7 +33,6 @@ import quarks.topology.services.ApplicationService;
 
 public class AppServiceTest {
     
-    private static final String JAR_NAME = "quarks.api.topology.APPS.TEST.jar";
     
     @Test
     public void testRegisterTopology() {
@@ -55,9 +56,14 @@ public class AppServiceTest {
         DirectProvider direct = new DirectProvider();
         ApplicationService appService = AppService.createAndRegister(direct, direct);
         
-        URL testAppsJar = getClass().getClassLoader().getResource(JAR_NAME);
+        String qd = System.getProperty("quarks.test.root.dir");
+        assertNotNull(qd);
+        File testAppsJar = new File(qd, "api/topology/test.classes/quarks.api.topology.APPS.TEST.jar");
+        assertTrue(testAppsJar.exists());
+        
+        URL testAppsJarURL = testAppsJar.toURI().toURL();
 
-        appService.registerJar(testAppsJar.toExternalForm());
+        appService.registerJar(testAppsJarURL.toExternalForm(), null);
         
         assertEquals(3, appService.getApplicationNames().size());
         assertTrue(appService.getApplicationNames().contains("FirstJarApp"));

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/runtime/appservice/src/main/java/quarks/runtime/appservice/AppService.java
----------------------------------------------------------------------
diff --git a/runtime/appservice/src/main/java/quarks/runtime/appservice/AppService.java b/runtime/appservice/src/main/java/quarks/runtime/appservice/AppService.java
index 58204af..673d442 100644
--- a/runtime/appservice/src/main/java/quarks/runtime/appservice/AppService.java
+++ b/runtime/appservice/src/main/java/quarks/runtime/appservice/AppService.java
@@ -111,7 +111,7 @@ public class AppService implements ApplicationService {
      * topology application that is registered as a service provider.
      */
     @Override
-    public void registerJar(String jarURL) throws MalformedURLException {
+    public void registerJar(String jarURL, String jsonConfig) throws MalformedURLException {
         
         // TODO copy the jar if it is not local rather than loading it
         // directly.

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/runtime/appservice/src/main/java/quarks/runtime/appservice/AppServiceControl.java
----------------------------------------------------------------------
diff --git a/runtime/appservice/src/main/java/quarks/runtime/appservice/AppServiceControl.java b/runtime/appservice/src/main/java/quarks/runtime/appservice/AppServiceControl.java
index 857cfec..d8f95f4 100644
--- a/runtime/appservice/src/main/java/quarks/runtime/appservice/AppServiceControl.java
+++ b/runtime/appservice/src/main/java/quarks/runtime/appservice/AppServiceControl.java
@@ -73,4 +73,9 @@ public class AppServiceControl implements ApplicationServiceMXBean {
             throw (Exception) t;
         }
     }
+    
+    @Override
+    public void registerJar(String jarURL, String jsonConfig) throws Exception {
+        service.registerJar(jarURL, jsonConfig);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/6f2fe038/test/fvtiot/src/test/java/quarks/test/fvt/iot/IotAppServiceTest.java
----------------------------------------------------------------------
diff --git a/test/fvtiot/src/test/java/quarks/test/fvt/iot/IotAppServiceTest.java b/test/fvtiot/src/test/java/quarks/test/fvt/iot/IotAppServiceTest.java
index b1b449e..f33941b 100644
--- a/test/fvtiot/src/test/java/quarks/test/fvt/iot/IotAppServiceTest.java
+++ b/test/fvtiot/src/test/java/quarks/test/fvt/iot/IotAppServiceTest.java
@@ -18,8 +18,12 @@ under the License.
 */
 package quarks.test.fvt.iot;
 
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
+import java.net.URL;
+
 import org.junit.Test;
 
 import com.google.gson.JsonArray;
@@ -42,17 +46,41 @@ public class IotAppServiceTest {
         DirectProvider provider = new DirectProvider();
         
         JsonControlService control = new JsonControlService();
-        provider.getServices().addService(ControlService.class, control);
-        
-        ApplicationService apps = AppService.createAndRegister(provider, provider);
-        provider.getServices().addService(ApplicationService.class, apps);
+        provider.getServices().addService(ControlService.class, control);        
+        AppService.createAndRegister(provider, provider);
         
         IotTestApps.registerApplications(provider);       
         
-        JsonObject submitAppOne = newSubmitRequest("AppOne");
+        JsonObject submitAppOne = newSubmitRequest("AppOne");        
+        JsonElement crr = control.controlRequest(submitAppOne);      
+        assertTrue(crr.getAsBoolean());
+    }
+    
+    @Test(expected=ClassNotFoundException.class)
+    public void testAppsNotInClasspath() throws ClassNotFoundException {
+        Class.forName("quarks.test.topology.services.TestApplications");
+    }
+    
+    @Test
+    public void testAppServiceJar() throws Exception {
+        
+        DirectProvider provider = new DirectProvider();
+        
+        JsonControlService control = new JsonControlService();
+        provider.getServices().addService(ControlService.class, control);        
+        AppService.createAndRegister(provider, provider);
+        String qd = System.getProperty("quarks.test.root.dir");
+        assertNotNull(qd);
+        File testAppsJar = new File(qd, "api/topology/test.classes/quarks.api.topology.APPS.TEST.jar");
+        assertTrue(testAppsJar.exists());
         
-        JsonElement crr = control.controlRequest(submitAppOne);
+        URL testAppsJarURL = testAppsJar.toURI().toURL();
+        JsonObject registerJar = newRegisterJarRequest(testAppsJarURL.toExternalForm());       
+        JsonElement crr = control.controlRequest(registerJar);    
+        assertTrue(crr.getAsBoolean());
         
+        JsonObject submitAppTwo = newSubmitRequest("SecondJarApp");        
+        crr = control.controlRequest(submitAppTwo);      
         assertTrue(crr.getAsBoolean());
     }
     
@@ -68,4 +96,18 @@ public class IotAppServiceTest {
         
         return submitApp;
     }
+    public static JsonObject newRegisterJarRequest(String jarURL) {
+        JsonObject submitApp = new JsonObject();   
+        submitApp.addProperty(JsonControlService.TYPE_KEY, ApplicationServiceMXBean.TYPE);
+        submitApp.addProperty(JsonControlService.ALIAS_KEY, ApplicationService.ALIAS);
+        JsonArray args = new JsonArray();
+        args.add(new JsonPrimitive(jarURL));
+        args.add(new JsonObject());
+        submitApp.addProperty(JsonControlService.OP_KEY, "registerJar");
+        submitApp.add(JsonControlService.ARGS_KEY, args); 
+        
+        return submitApp;
+    }
+    
+
 }