You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2017/01/23 18:34:59 UTC

[1/3] incubator-edgent git commit: [Edgent-367] Add autoSubmit to IotProvider

Repository: incubator-edgent
Updated Branches:
  refs/heads/master f8a15989c -> 66b6861f5


[Edgent-367] Add autoSubmit to IotProvider

Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/7e7b302a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/7e7b302a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/7e7b302a

Branch: refs/heads/master
Commit: 7e7b302a8fc5920efa0524ae9845e7f5dc5a5d9b
Parents: a6090c8
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Mon Jan 16 17:25:30 2017 -0500
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Mon Jan 16 17:25:30 2017 -0500

----------------------------------------------------------------------
 .../edgent/providers/iot/IotProvider.java       | 55 ++++++++++++++++++--
 1 file changed, 52 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/7e7b302a/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java
----------------------------------------------------------------------
diff --git a/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java b/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java
index 945d721..84d5600 100644
--- a/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java
+++ b/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java
@@ -21,7 +21,10 @@ package org.apache.edgent.providers.iot;
 import static org.apache.edgent.topology.services.ApplicationService.SYSTEM_APP_PREFIX;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.concurrent.Future;
 import java.util.prefs.BackingStoreException;
 import java.util.prefs.Preferences;
@@ -105,6 +108,8 @@ public class IotProvider implements TopologyProvider,
      */
     private final List<String> systemApps = new ArrayList<>();
 
+    private final Map<String,JsonObject> autoSubmitApps = new HashMap<>();  // <appName,config>
+
     private JsonControlService controlService = new JsonControlService();
     
     /**
@@ -313,7 +318,8 @@ public class IotProvider implements TopologyProvider,
     }
     
     /**
-     * Start this provider by starting its system applications.
+     * Start this provider by starting its system applications 
+     * and any autoSubmit-enabled registered applications.
      * 
      * @throws Exception on failure starting applications.
      */
@@ -324,6 +330,10 @@ public class IotProvider implements TopologyProvider,
         for (String systemAppName : systemApps) {
             bean.submit(systemAppName, null /* no config */);
         }
+        
+        for (Entry<String,JsonObject> e : autoSubmitApps.entrySet()) {
+          submitApplication(e.getKey(), e.getValue());
+        }
     }
 
     /**
@@ -354,6 +364,18 @@ public class IotProvider implements TopologyProvider,
     /**
      * Register an application that uses an {@code IotDevice}.
      * <BR>
+     * Same as {@link #registerTopology(String, BiConsumer, boolean, JsonObject) registerTopology(appName, builder, false, null)}.
+     * 
+     * @param applicationName Application name
+     * @param builder Function that builds the topology.
+     */
+    public void registerTopology(String applicationName, BiConsumer<IotDevice, JsonObject> builder) {
+      registerTopology(applicationName, builder, false, null);
+    }
+    
+    /**
+     * Register an application that uses an {@code IotDevice}.
+     * <BR>
      * Wrapper around {@link ApplicationService#registerTopology(String, BiConsumer)}
      * that passes in an {@link IotDevice} and configuration to the supplied
      * function {@code builder} that builds the application. The passed
@@ -366,12 +388,39 @@ public class IotProvider implements TopologyProvider,
      * {@link org.apache.edgent.topology.mbeans.ApplicationServiceMXBean#submit(String, String) submitted} {@code builder.accept(iotDevice, config)}
      * is called to build the application's graph.
      * </P>
+     * <P>
+     * Specify {@code autoSubmit==true}, to have the provider submit the application
+     * when {@link #start} is called.
+     * </P>
      * 
      * @param applicationName Application name
      * @param builder Function that builds the topology.
+     * @param autoSubmit auto submit the application when {@link #start()} is called.
+     * @param config config for auto-submitted application.
+     *        See {@link #submit(Topology, JsonObject) submit}. May be null.
      */
-    public void registerTopology(String applicationName, BiConsumer<IotDevice, JsonObject> builder) {
+    public void registerTopology(String applicationName, BiConsumer<IotDevice, JsonObject> builder, boolean autoSubmit, JsonObject config) {
         getApplicationService().registerTopology(applicationName,
-                (topology,config) -> builder.accept(IotDevicePubSub.addIotDevice(topology), config));
+                (topology,cfg) -> builder.accept(IotDevicePubSub.addIotDevice(topology), cfg));
+        if (autoSubmit) {
+          autoSubmitApps.put(applicationName, config);
+        }
+    }
+
+    /**
+     * Submit the specified application previously registered
+     * via {@link #registerTopology(String, BiConsumer) registerTopology}.
+     * @param appName name of registered application
+     * @param config See {@link #submit(Topology, JsonObject) submit}. May be null.
+     * 
+     * @throws Exception on failure starting applications.
+     */
+    public void submitApplication(String appName, JsonObject config) throws Exception {
+      if (systemApps.contains(appName)) {
+        throw new IllegalArgumentException("appName");
+      }
+      ApplicationServiceMXBean bean = getControlService().getControl(ApplicationServiceMXBean.TYPE,
+          ApplicationService.ALIAS, ApplicationServiceMXBean.class);
+      bean.submit(appName, config==null ? null : config.toString());
     }
 }


[3/3] incubator-edgent git commit: Merge pull request #276

Posted by dl...@apache.org.
Merge pull request #276

This closes #276


Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/66b6861f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/66b6861f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/66b6861f

Branch: refs/heads/master
Commit: 66b6861f5b995f070c0a2cdf8cb496314241cd67
Parents: f8a1598 88e026c
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Mon Jan 23 13:34:52 2017 -0500
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Mon Jan 23 13:34:52 2017 -0500

----------------------------------------------------------------------
 .../edgent/providers/iot/IotProvider.java       | 55 ++++++++++++++++++--
 1 file changed, 52 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



[2/3] incubator-edgent git commit: make new IotProvider.submitApplication private

Posted by dl...@apache.org.
make new IotProvider.submitApplication private

make public once there's a demonstrated need

Project: http://git-wip-us.apache.org/repos/asf/incubator-edgent/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-edgent/commit/88e026c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-edgent/tree/88e026c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-edgent/diff/88e026c8

Branch: refs/heads/master
Commit: 88e026c868b4a13179c8005d265ab796db12c03a
Parents: 7e7b302
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Mon Jan 23 09:38:51 2017 -0500
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Mon Jan 23 09:38:51 2017 -0500

----------------------------------------------------------------------
 .../src/main/java/org/apache/edgent/providers/iot/IotProvider.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-edgent/blob/88e026c8/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java
----------------------------------------------------------------------
diff --git a/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java b/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java
index 84d5600..764bc7d 100644
--- a/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java
+++ b/providers/iot/src/main/java/org/apache/edgent/providers/iot/IotProvider.java
@@ -415,7 +415,7 @@ public class IotProvider implements TopologyProvider,
      * 
      * @throws Exception on failure starting applications.
      */
-    public void submitApplication(String appName, JsonObject config) throws Exception {
+    private void submitApplication(String appName, JsonObject config) throws Exception {
       if (systemApps.contains(appName)) {
         throw new IllegalArgumentException("appName");
       }