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/03/12 14:59:12 UTC

[2/2] incubator-quarks git commit: QUARKS-10 Initial application service

QUARKS-10 Initial application service


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

Branch: refs/heads/master
Commit: 1bfd1613382c9f4830474515de914166efed3988
Parents: 344f5bf
Author: Dan Debrunner <dj...@apache.org>
Authored: Wed Mar 9 15:58:44 2016 -0800
Committer: Dan Debrunner <dj...@apache.org>
Committed: Sat Mar 12 05:36:42 2016 -0800

----------------------------------------------------------------------
 .../java/quarks/execution/mbeans/JobMXBean.java |  2 +-
 .../mbeans/ApplicationServiceMXBean.java        | 36 +++++++++
 .../topology/services/ApplicationService.java   | 60 ++++++++++++++
 build.xml                                       |  2 +
 runtime/.classpath                              |  1 +
 runtime/appservice/build.xml                    | 28 +++++++
 .../quarks/runtime/appservice/AppService.java   | 82 ++++++++++++++++++++
 .../runtime/appservice/AppServiceControl.java   | 61 +++++++++++++++
 test/.classpath                                 |  1 +
 test/fvtiot/build.xml                           | 27 +++++++
 .../java/quarks/test/fvt/iot/IotAppService.java | 27 +++++++
 11 files changed, 326 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java
----------------------------------------------------------------------
diff --git a/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java b/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java
index cc98813..63795a6 100644
--- a/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java
+++ b/api/execution/src/main/java/quarks/execution/mbeans/JobMXBean.java
@@ -12,7 +12,7 @@ public interface JobMXBean {
      * TYPE is used to identify this bean as a job bean when building the bean's {@code ObjectName}.
      * The value is {@value} 
      */
-    public static final String TYPE = "job";
+    String TYPE = "job";
 
     /**
      * Returns the identifier of the job.

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/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
new file mode 100644
index 0000000..d09e3b8
--- /dev/null
+++ b/api/topology/src/main/java/quarks/topology/mbeans/ApplicationServiceMXBean.java
@@ -0,0 +1,36 @@
+/*
+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 quarks.topology.mbeans;
+
+import quarks.topology.services.ApplicationService;
+
+public interface ApplicationServiceMXBean {
+    
+    String TYPE = "appService";
+    
+    /**
+     * Submit an application registered with the application service.
+     * 
+     * @param applicationName Name of the application.
+     * @param jsonConfig JSON configuration serialized as a String.
+     * 
+     * @see ApplicationService
+     */
+    void submit(String applicationName, String jsonConfig);
+}

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/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
new file mode 100644
index 0000000..79dcb48
--- /dev/null
+++ b/api/topology/src/main/java/quarks/topology/services/ApplicationService.java
@@ -0,0 +1,60 @@
+/*
+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 quarks.topology.services;
+
+import com.google.gson.JsonObject;
+
+import quarks.execution.Submitter;
+import quarks.function.BiConsumer;
+import quarks.topology.Topology;
+import quarks.topology.mbeans.ApplicationServiceMXBean;
+
+/**
+ * Application registration service.
+ *
+ * @see ApplicationServiceMXBean
+ */
+public interface ApplicationService {
+    
+    String ALIAS = "quarksApplication";
+    
+    /**
+     * Add a topology that can be started though a control mbean.
+     * <BR>
+     * When a {@link ApplicationServiceMXBean#submit(String, String) submit}
+     * is invoked {@code builder.accept(topology, config)} is called passing:
+     * <UL>
+     * <LI>
+     * {@code topology} - An empty topology with the name {@code applicationName}.
+     * </LI>
+     * <LI>
+     * {@code config} - JSON submission configuration from
+     * {@link ApplicationServiceMXBean#submit(String, String) submit}.
+     * </LI>
+     * </UL>
+     * Once {@code builder.accept(topology, config)} returns it is submitted
+     * to the {@link Submitter} associated with the implementation of this service.
+     * 
+     * @param applicationName Application name to register.
+     * @param builder How to build the topology for this application.
+     * 
+     * @see ApplicationServiceMXBean
+     */
+    void registerTopology(String applicationName, BiConsumer<Topology, JsonObject> builder);
+}

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index 4ebb7d2..f311b40 100644
--- a/build.xml
+++ b/build.xml
@@ -90,6 +90,7 @@
         <ant dir="api/topology" target="@{target}" useNativeBasedir="true"/>
         <ant dir="spi/graph" target="@{target}" useNativeBasedir="true"/>
         <ant dir="spi/topology" target="@{target}" useNativeBasedir="true"/>
+        <ant dir="runtime/appservice" target="@{target}" useNativeBasedir="true"/>
         <ant dir="runtime/etiao" target="@{target}" useNativeBasedir="true"/>
         <ant dir="runtime/jmxcontrol" target="@{target}" useNativeBasedir="true"/>
         <ant dir="runtime/jsoncontrol" target="@{target}" useNativeBasedir="true"/>
@@ -124,6 +125,7 @@
         <ant dir="samples/console" target="@{target}" useNativeBasedir="true" />
         <ant dir="android/topology" target="@{target}" useNativeBasedir="true" />
         <ant dir="android/hardware" target="@{target}" useNativeBasedir="true" />
+        <ant dir="test/fvtiot" target="@{target}" useNativeBasedir="true" />
         <ant dir="test/svt" target="@{target}" useNativeBasedir="true" />
       </sequential>
   </macrodef>

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/runtime/.classpath
----------------------------------------------------------------------
diff --git a/runtime/.classpath b/runtime/.classpath
index f05fc67..6f9b13e 100644
--- a/runtime/.classpath
+++ b/runtime/.classpath
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+	<classpathentry kind="src" path="appservice/src/main/java"/>
 	<classpathentry kind="src" path="etiao/src/main/java"/>
 	<classpathentry kind="src" path="etiao/src/test/java"/>
 	<classpathentry kind="src" path="jmxcontrol/src/main/java"/>

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/runtime/appservice/build.xml
----------------------------------------------------------------------
diff --git a/runtime/appservice/build.xml b/runtime/appservice/build.xml
new file mode 100644
index 0000000..c6db1a5
--- /dev/null
+++ b/runtime/appservice/build.xml
@@ -0,0 +1,28 @@
+<project name="quarks.runtime.appservice" default="all" 
+    xmlns:jacoco="antlib:org.jacoco.ant"
+    >
+    <description>
+        Build the runtime Application service library.
+    </description>
+
+  <import file="../../common-build.xml"/>
+
+  <path id="compile.classpath">
+    <pathelement location="${lib}/quarks.api.execution.jar" />
+    <pathelement location="${lib}/quarks.api.topology.jar" />
+    <path refid="quarks.ext.classpath" />
+    <path refid="test.common.classpath"/>
+  </path>
+
+  <path id="test.compile.classpath">
+    <pathelement location="${jar}" />
+    <path refid="compile.classpath"/>
+  </path>
+
+  <path id="test.classpath">
+    <pathelement location="${test.classes}" />
+    <path refid="test.compile.classpath"/>
+  </path>
+
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/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
new file mode 100644
index 0000000..b749850
--- /dev/null
+++ b/runtime/appservice/src/main/java/quarks/runtime/appservice/AppService.java
@@ -0,0 +1,82 @@
+/*
+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 quarks.runtime.appservice;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.gson.JsonObject;
+
+import quarks.execution.DirectSubmitter;
+import quarks.execution.services.ControlService;
+import quarks.function.BiConsumer;
+import quarks.topology.Topology;
+import quarks.topology.TopologyProvider;
+import quarks.topology.mbeans.ApplicationServiceMXBean;
+import quarks.topology.services.ApplicationService;
+
+public class AppService implements ApplicationService {
+    
+    public static ApplicationService createAndRegister(TopologyProvider provider, DirectSubmitter submitter) {
+        
+        AppService service = new AppService(provider, submitter, ALIAS);
+        
+        submitter.getServices().addService(ApplicationService.class, service);
+        
+        return service;
+        
+    }
+    
+    private final Map<String,BiConsumer<Topology, JsonObject>> applications =
+            Collections.synchronizedMap(new HashMap<>());
+    
+    private final TopologyProvider provider;
+    private final DirectSubmitter submitter;
+    
+    public AppService(TopologyProvider provider, DirectSubmitter submitter, String alias) {
+        this.provider = provider;
+        this.submitter = submitter;
+        
+        ControlService cs = submitter.getServices().getService(ControlService.class);
+        if (cs != null)
+            cs.registerControl(ApplicationServiceMXBean.TYPE,
+                    ALIAS+System.currentTimeMillis(), alias,
+                    ApplicationServiceMXBean.class,
+                    new AppServiceControl(this));
+    }
+
+    @Override
+    public void registerTopology(String applicationName, BiConsumer<Topology, JsonObject> builder) {
+        applications.put(applicationName, builder);
+    }
+    
+    BiConsumer<Topology, JsonObject> getBuilder(String applicationName) {
+        return applications.get(applicationName);
+    }
+    
+    TopologyProvider getProvider() {
+        return provider;
+    }
+    
+    
+    DirectSubmitter getSubmitter() {
+        return submitter;
+    }   
+}

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/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
new file mode 100644
index 0000000..26e688b
--- /dev/null
+++ b/runtime/appservice/src/main/java/quarks/runtime/appservice/AppServiceControl.java
@@ -0,0 +1,61 @@
+/*
+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 quarks.runtime.appservice;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+import quarks.execution.Configs;
+import quarks.function.BiConsumer;
+import quarks.topology.Topology;
+import quarks.topology.mbeans.ApplicationServiceMXBean;
+
+public class AppServiceControl implements ApplicationServiceMXBean {
+    
+    private final AppService service;
+    
+    AppServiceControl(AppService service) {
+        this.service = service;
+    }
+
+    @Override
+    public void submit(String applicationName, String jsonConfig) {
+        
+        BiConsumer<Topology, JsonObject> builder = service.getBuilder(applicationName);
+        if (builder == null)
+            return;
+        
+        JsonObject config;
+        
+        if (jsonConfig != null)
+            config = (JsonObject) new JsonParser().parse(jsonConfig);
+        else
+            config = new JsonObject();
+        
+        Topology topology = service.getProvider().newTopology(applicationName);
+        
+        // Fill in the topology
+        builder.accept(topology, config);
+        
+        if (!config.has(Configs.JOB_NAME))
+            config.addProperty(Configs.JOB_NAME, applicationName);
+        
+        service.getSubmitter().submit(topology, config);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/test/.classpath
----------------------------------------------------------------------
diff --git a/test/.classpath b/test/.classpath
index 550db4d..efc056e 100644
--- a/test/.classpath
+++ b/test/.classpath
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+	<classpathentry kind="src" path="fvtiot/src/main/java"/>
 	<classpathentry kind="src" path="svt/src/main/java"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/analytics"/>

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/test/fvtiot/build.xml
----------------------------------------------------------------------
diff --git a/test/fvtiot/build.xml b/test/fvtiot/build.xml
new file mode 100644
index 0000000..a38ac29
--- /dev/null
+++ b/test/fvtiot/build.xml
@@ -0,0 +1,27 @@
+<project name="quarks.test.fvtiot" default="all" xmlns:jacoco="antlib:org.jacoco.ant">
+    <description>
+        FVT for iot scenario
+    </description>
+
+  <property name="component.path" value="test/fvtiot"/>
+  <import file="../../common-build.xml"/>
+
+  <path id="compile.classpath">
+    <pathelement location="${quarks.lib}/quarks.providers.direct.jar"/>
+    <pathelement location="${quarks.lib}/quarks.runtime.appservice.jar"/>
+    <pathelement location="${quarks.lib}/quarks.runtime.jsoncontrol.jar"/>
+    <path refid="quarks.ext.classpath"/>
+  </path>
+
+  <path id="test.compile.classpath">
+    <pathelement location="${jar}" />
+    <path refid="compile.classpath"/>
+  </path>
+
+  <path id="test.classpath">
+    <pathelement location="${test.classes}" />
+    <path refid="test.compile.classpath"/>
+    <path refid="test.common.classpath" />
+  </path>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/1bfd1613/test/fvtiot/src/main/java/quarks/test/fvt/iot/IotAppService.java
----------------------------------------------------------------------
diff --git a/test/fvtiot/src/main/java/quarks/test/fvt/iot/IotAppService.java b/test/fvtiot/src/main/java/quarks/test/fvt/iot/IotAppService.java
new file mode 100644
index 0000000..aeeb323
--- /dev/null
+++ b/test/fvtiot/src/main/java/quarks/test/fvt/iot/IotAppService.java
@@ -0,0 +1,27 @@
+/*
+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 quarks.test.fvt.iot;
+
+public class IotAppService {
+    
+    public void testAppService() {
+        
+    }
+    
+}