You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@edgent.apache.org by Susan Cline <ho...@pacbell.net> on 2016/09/14 00:06:45 UTC

Trying register an application via the registerJar command

Hi, 

I’m trying to come up with fairly complete example that allows me to do the following:

Send a registerJar command to a raspberry pi to register an Edgent application
Send a ‘submit’ command to start the Edgent application
Close/stop the Edgent application

Here is what I have done so far and have not been successful:

1) “manually” start an application on a raspberry pi that creates an IotProvider, and uses the AppService to creates and register this provider:

public class RunningApp {

	public static void main(String[] args) throws Exception {
		//DirectProvider provider = new DirectProvider();
		File configFile = new File("./device_config.txt");
		IotProvider provider = new IotProvider(topology -> new IotfDevice(topology, configFile));
		JsonControlService control = new JsonControlService();
		provider.getServices().addService(ControlService.class, control);
		AppService.createAndRegister(provider, provider);
		
		provider.start();
	}

}
2) Put a jar file called SensorApp.jar on the pi in the same directory where the ‘RunningApp’ is running.

3) Send a registerJar command that looks like the following:
command
:
"edgentControl"
date
:
1473800605520
payload
:
{args: ["/home/pi/slcQuarks/edgent/SensorApp.jar", ""], op: "registerJar", alias: "edgent",…}
alias
:
"edgent"
args
:
["/home/pi/slcQuarks/edgent/SensorApp.jar", ""]
0
:
"/home/pi/slcQuarks/edgent/SensorApp.jar"
1
:
""
op
:
"registerJar"
type
:
“appService"


I get no errors coming from the RunningApp console, and just see this:

pi@raspberrypi:~/slcQuarks/edgent $ java -jar runningApp.jar
Sep 13, 2016 8:43:23 PM com.ibm.iotf.client.AbstractClient createClient
INFO: pool-1-thread-22-edgentIotDevicePubSub: Org ID    = ni6dcf
         Client ID    = d:ni6dcf:raspberryPi3:Pi-SLC-Oakland
Sep 13, 2016 8:43:23 PM com.ibm.iotf.client.AbstractClient connect
INFO: pool-1-thread-22-edgentIotDevicePubSub: Connecting client d:ni6dcf:raspberryPi3:Pi-SLC-Oakland to ssl://ni6dcf.messaging.internetofthings.ibmcloud.com:8883 (attempt #1)...
Sep 13, 2016 8:43:25 PM com.ibm.iotf.client.AbstractClient connect
INFO: pool-1-thread-22-edgentIotDevicePubSub: Successfully connected to the IBM Watson IoT Platform


Does anyone know what I am doing wrong?

I looked at the IotAppServiceTest and it appears to me that my jar file to be loaded is correct.
Here is the code for the SensorApp:

import java.util.Date;
import java.util.concurrent.TimeUnit;
import com.google.gson.JsonObject;
import com.pi4j.system.SystemInfo;
import org.apache.edgent.connectors.iot.QoS;
import org.apache.edgent.connectors.iot.IotDevice;
import org.apache.edgent.function.BiConsumer;
import org.apache.edgent.topology.TStream;
import org.apache.edgent.topology.Topology;
import org.apache.edgent.topology.services.TopologyBuilder;

public class SensorApplications {


   private static abstract class SensorApp implements TopologyBuilder {
	   
        @Override
        public BiConsumer<Topology, JsonObject> getBuilder() {
            return (t,c) -> t.strings(getName()).print();
        }     
    }
    
    public static class CpuSensorApp extends SensorApp {
    	
        @Override
        public String getName() {
            return "CpuSensorApp";
        }
        
        public void accept(IotDevice device, JsonObject config) {
            TStream<Date> readingTime = device.topology().poll(() -> new Date(), 1, TimeUnit.SECONDS);

    		TStream<JsonObject> cpuReading = readingTime.map(rt ->
    			{
    				JsonObject cpuInfo = new JsonObject();
    				cpuInfo.addProperty("ts", System.currentTimeMillis());
    	
    				try {
    					cpuInfo.addProperty("cpuTemperature", SystemInfo.getCpuTemperature());
    					cpuInfo.addProperty("cpuVoltage", SystemInfo.getCpuVoltage());
    				} catch(Exception e) {
    					throw new RuntimeException(e);
    				}
    	            return cpuInfo;
    			});
    		cpuReading.print();
    		device.events(cpuReading,  "cpuReading", QoS.FIRE_AND_FORGET);		
        }
  
    }
    
    public static class MemorySensorApp extends SensorApp {
        @Override
        public String getName() {
            return "MemorySensorApp";
        }
    }
}


Thanks,

Susan

Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
Okay, thanks.  I don’t have connectivity to the raspberry pi this is running on right now, but will later today and will try it.

I think the problem lies with my accept method still, but I don’t understand how to fix it.

Thanks,

Susan

> On Sep 16, 2016, at 10:32 AM, Dale LaBossiere <dm...@gmail.com> wrote:
> 
> I haven’t digested the complete email message yet, but try removing those three lines before provider.start() and try again.
> IotProvider already create/registers those services (described in its javadoc).  I guess I wouldn’t be surprised if these extra additions might much things up.
> 
> — Dale
> 
>> On Sep 16, 2016, at 1:17 PM, Susan Cline <ho...@pacbell.net> wrote:
>> 
>> I’ve gotten a step further, but I am still having problems.
>> ...
>> 
>> public class RegisterJarExample {
>> 		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
>> 		/*
>> 		 * Not sure if I need the next few lines or not ...
>> 		 */
>> 		JsonControlService control = new JsonControlService();
>> 		provider.getServices().addService(ControlService.class, control); 
>> 		ApplicationService appService = AppService.createAndRegister(provider, provider);
>> 		provider.start();
>> 		
>> 		logger.info("Here is some info");
>> 	}
>> 	
>> }
> 


Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
Thanks Dale.  I will give this a try later this week.

Cheers,

Susan

> On Sep 26, 2016, at 8:24 AM, Dale LaBossiere <dm...@gmail.com> wrote:
> 
> I think I understand the confusion / issue now...
> 
> Your app created the IotpDevice (with its config) when it started up, as a param to the IotProvider.  You only create one.
> 
> ….
> 
> — Dale
> 


Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
Your table looks good Dale, many thanks!

Susan

> On Mar 31, 2017, at 10:23 AM, Dale LaBossiere <dm...@gmail.com> wrote:
> 
>> On Mar 30, 2017, at 8:53 PM, Susan Cline <home4slc@pacbell.net <ma...@pacbell.net>> wrote:
>> 
>> Yay!  I got it to work.
> 
> Woo hoo!  Happy Friday indeed!
> 
> BTW, I just improved doc on registerJar and IotProvider.  Take look and see if you agree / that’s enough.  I had previously improved the IotProvider package-info.java and it’s info on JSON for cmds, now including registerJar.
> 
> All post 1.1.0 I’m afraid.
> 
> https://issues.apache.org/jira/browse/EDGENT-405 <https://issues.apache.org/jira/browse/EDGENT-405>
> https://issues.apache.org/jira/browse/EDGENT-406 <https://issues.apache.org/jira/browse/EDGENT-406>
> 
> <PastedGraphic-1.png>
> 
> — Dale


Re: Trying register an application via the registerJar command

Posted by Dale LaBossiere <dm...@gmail.com>.
> On Mar 30, 2017, at 8:53 PM, Susan Cline <ho...@pacbell.net> wrote:
> 
> Yay!  I got it to work.

Woo hoo!  Happy Friday indeed!

BTW, I just improved doc on registerJar and IotProvider.  Take look and see if you agree / that’s enough.  I had previously improved the IotProvider package-info.java and it’s info on JSON for cmds, now including registerJar.

All post 1.1.0 I’m afraid.

https://issues.apache.org/jira/browse/EDGENT-405 <https://issues.apache.org/jira/browse/EDGENT-405>
https://issues.apache.org/jira/browse/EDGENT-406 <https://issues.apache.org/jira/browse/EDGENT-406>



— Dale

Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
Yay!  I got it to work.

Here is what I did:

1) On the pi start an application called RegisterJarExample that was made into a runnable jar file.

package pi;

...

public class RegisterJarExample {
	public static void main(String args[]) throws Exception {

		String s = null;
		for (String str: args) {
			s = str;
		}
		/* a device configuration file ties a specific device
		 * to a device type and an organization
		 * each device needs an authentication token
		 * devices must be registered at IOT prior to running this application
		 */
		File configFile;
		if (s != null) {
			s = "./" + s;
			configFile = new File(s);
		} else {
			configFile = new File("./device_config.txt");
		}
		
		IotProvider provider = new IotProvider(topology -> new IotfDevice(topology, configFile));
		provider.start();
	}
	
}

java -jar RegisterJar.jar

2) I placed the jar file that will be registered via the Edgent registerJar command on the pi (note this could be some external URL, but for my example I just uploaded it to the pi).
I called the jar file pi.sensors.jar.

To build the jar file, my build file looked like this:

<project name="pi.sensors" default="registerJar">
<target name="registerJar">
    <jar destfile="bin/pi.sensors.jar">
      <service type="org.apache.edgent.topology.services.TopologyBuilder">
        <provider classname="pi.sensors.SpeedSensorTopologyBuilder$SpeedSensor" />
      </service>
     <fileset dir="./bin" includes="**/SpeedSensorTopologyBuilder*"/>
    </jar>
  </target>
</project>

The SpeedSensorTopologyBuilder class looks like this:

public class SpeedSensorTopologyBuilder {
	private static abstract class Sensor implements TopologyBuilder {
       @Override
       public BiConsumer<Topology, JsonObject> getBuilder() {
    	   
       		return (topology,config) -> SpeedSensor.myIotDeviceBasedBuilder(IotDevicePubSub.addIotDevice(topology), config);
       }   
	}
	
	public static class SpeedSensor extends Sensor {
       @Override
       public String getName() {
           return "SpeedJarApp";
       }

       public static void myIotDeviceBasedBuilder(IotDevice iotDevice, JsonObject config) {
	        TStream<Date> readingTime = iotDevice.topology().poll(() -> new Date(), 3, TimeUnit.SECONDS);
	    	
			TStream<JsonObject> speedReading = readingTime.map(rt ->
				{
					JsonObject speedInfo = new JsonObject();
					long curTime = System.currentTimeMillis();
					SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss");
					Date dateObj = new Date(curTime);
					speedInfo.addProperty("time:", sdf.format(dateObj));
		
					try {
						double speed = SystemInfo.getMemoryUsed() * 0.0000000752;
					    Random randomGenerator = new Random();
					    int randomInt = randomGenerator.nextInt(20);
					    
						double randSpeed = speed + randomInt;
						DecimalFormat df = new DecimalFormat("#.##");
						speedInfo.addProperty("Speed", df.format(randSpeed));
					} catch(Exception e) {
						throw new RuntimeException(e);
					}
		            return speedInfo;
				});
			speedReading.print();
			iotDevice.events(speedReading,  "speedReading", QoS.FIRE_AND_FORGET);
       }
	}
}

3. I issued this registerJar command to the pi:

{"args":["file:/home/pi/slcEdgent/pi.sensors.jar",""],"op":"registerJar","alias":"edgent","type":"appService”}

4. I issued the ‘submit’ command:
{"args":["SpeedJarApp",{}],"op":"submit","alias":"edgent","type":"appService”}

In the running application on the pi, I saw this line:
Mar 31, 2017 12:34:58 AM pi.sensors.SpeedSensorTopologyBuilder$SpeedSensor myIotDeviceBasedBuilder


and then these lines:

{"time:":"Mar 31,2017 00:36:49","Speed":"15.12"}
{"time:":"Mar 31,2017 00:36:52","Speed":"23.13”}

5. Finally, I stopped the running application by issuing the ‘CLOSE’ command:

{"args":["CLOSE"],"op":"stateChange","alias":"SpeedJarApp","type":"job”}

The output on the pi stopped.


Thanks a bunch for your help Dale!

Cheers,

Susan

> On Mar 30, 2017, at 7:19 AM, Dale LaBossiere <dm...@gmail.com> wrote:
> 
>> On Mar 28, 2017, at 12:40 PM, Susan Cline <ho...@pacbell.net> wrote:
>> ...
>> I have not gotten back to this since Dale posted this a long time ago, but I’d like to get this working.  
> 
> I’ve reread all of this thread - whew :-).  I think you’re very close.  Your jar is OK. The registerJar cmd worked.  The submit cmd worked (with your getBuilder() that returned a fn that just created a top that printed the app name).
> 
> I’ll stick with the assertion in my last msg of 9/26 11:24.  I think all that's left to fix is:
> 
> - change your TopologyBuilder.getBuilder() impl
>  from
> 	(t, c) -> buildTopology(t, c)
>  to
> 	(t, c) -> buildTopology( IotDevicePubSub.addIotDevice(t), c))
> 	Notice that’s exactly what IotProvider.registerTopology() does - how the IotDevice will get created for and passed to your builder/top
> 
> - change your buildTopology(Topology t, JsonConfig c) to
> 	buildTopology(IotDevice iotDevice, JsonConfig c)  <== just a rename of the accept() in your 9/16/1:17 mail
> 
> I’m going to add a JIRA and improve the doc in IotProvider to make this clear.
> — Dale


Re: Trying register an application via the registerJar command

Posted by Dale LaBossiere <dm...@gmail.com>.
> On Mar 28, 2017, at 12:40 PM, Susan Cline <ho...@pacbell.net> wrote:
> ...
> I have not gotten back to this since Dale posted this a long time ago, but I’d like to get this working.  

I’ve reread all of this thread - whew :-).  I think you’re very close.  Your jar is OK. The registerJar cmd worked.  The submit cmd worked (with your getBuilder() that returned a fn that just created a top that printed the app name).

I’ll stick with the assertion in my last msg of 9/26 11:24.  I think all that's left to fix is:

- change your TopologyBuilder.getBuilder() impl
  from
	(t, c) -> buildTopology(t, c)
  to
	(t, c) -> buildTopology( IotDevicePubSub.addIotDevice(t), c))
	Notice that’s exactly what IotProvider.registerTopology() does - how the IotDevice will get created for and passed to your builder/top

- change your buildTopology(Topology t, JsonConfig c) to
	buildTopology(IotDevice iotDevice, JsonConfig c)  <== just a rename of the accept() in your 9/16/1:17 mail

I’m going to add a JIRA and improve the doc in IotProvider to make this clear.
— Dale

Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
Hi,

I have not gotten back to this since Dale posted this a long time ago, but I’d like to get this working.  Has anyone gotten the registerJar command to work
successfully?  If so, it would be great if someone could respond with their code that works.

Thanks!

Susan


> On Sep 26, 2016, at 8:24 AM, Dale LaBossiere <dm...@gmail.com> wrote:
> 
> I think I understand the confusion / issue now...
> 
> Your app created the IotpDevice (with its config) when it started up, as a param to the IotProvider.  You only create one.
> 
> I’m think your registered-jar’s embedded TopologyBuilder builder’s accept<Topology,JsonObject> needs to call IotDevicePubSub.addIotDevice(topology) to get a “virtual" IotDevice (linked to the original IotpDevice you created) for the topology it’s building.  This is alluded to in the IotProvider class javadoc.  (the IotProvider.registerTopology() impl does that automatically for you when using the non-registerJar based flow)
> 
> e.g., something along the lines of:
>    class MyRegisterJarBasedBuilder implements TopologyBuilder {  // registered as Java service provider in the jar’s manifest
> 	...
>        BiConsumer<Topology,JsonObject> getBuilder {	   
>            return (topology,config) -> MyApp.myIotDeviceBasedBuilder( IotDevicePubSub.addIotDevice(topology), config) )
>        }
>    }
> 
>    class MyApp {
>      ...
>      static void myIotDeviceBasedBuilder(IotDevice iotDevice, JsonObject config) {
> 	Topology t = iotDevice.getTopology();
> 	  … build your topology on “t” using iotDevice as needed
>      }
>    }
> 
> — Dale
> 
>> On Sep 19, 2016, at 10:30 PM, Susan Cline <ho...@pacbell.net> wrote:
>> 
>> Many thanks, Dale.
>> 
>> Still trying to figure this out …
>> 
>> Cheers,
>> 
>> Susan
>>> On Sep 19, 2016, at 8:30 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>>> 
>>> FYI I just created https://issues.apache.org/jira/browse/EDGENT-250 <https://issues.apache.org/jira/browse/EDGENT-250> to update IotProvider doc related to registerJar().  You should consider adding commentary there as part of your experiences — and/or consider tacking that jira and maybe even enhancing the doc further in this space :-)
>>> 
>>> — Dale
>>> 
>>> 
>>>> On Sep 19, 2016, at 11:07 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>>>> 
>>>> The TopologyBuilder.getBuilder() impl is bogus.  Looks like it’s copied from TestApplication().  All it does is return a builder (BiConsumer) that creates a topology consisting of a TStream<String> containing one tuple with the app’s name and prints that stream.
>>>> 
>>>> Your getBuilder() impl needs to return a BiConsumer that builds your app’s topology.  Looks like that’s what your accept() is trying to do.  Seems like you want something like (though I’d rename that accept() to something like “buildTopology()” for clarity).
>>>> 
>>>>    public BiConsumer<Topology, JsonObject> getBuilder() {
>>>>    		return (t,c) -> accept(t,c);
>>>>    }   
>>>> 
>>>> Fix that and then see what happens regarding handling of the submit request.  You might also consider adding a println to your getBuilder() and accept() to verify they’re getting called.
>>>> 
>>>> — Dale
>>>> 
>>>>> On Sep 16, 2016, at 5:44 PM, Susan Cline <ho...@pacbell.net> wrote:
>>>>> 
>>>>> Thanks Dale.  It did not work however, the results are the same after removing the 3 lines before provider.start().
>>>>> When I submit the SpeedJarApp I can see this in the pi terminal (this is the full output from when I started the registerJarExample application to when I submitted the command):
>>>>> 
>>>>> pi@raspberrypi:~/devConf $ java -jar registerJarExample.jar speed_sensor_config1.txt
>>>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>>>> INFO: Register application name: edgentIotDevicePubSub
>>>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>>>> INFO: Register application name: edgentIotCommandsToControl
>>>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>>>> INFO: Register application name: edgentJobMonitorApp
>>>>> false
>>>>> Sep 16, 2016 9:39:09 PM pi.RegisterJarExample main
>>>>> INFO: Here is some info
>>>>> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient createClient
>>>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Org ID    = ni6dcf
>>>>>     Client ID    = d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1
>>>>> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient connect
>>>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Connecting client d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1 to ssl://ni6dcf.messaging.internetofthings.ibmcloud.com:8883 (attempt #1)...
>>>>> Sep 16, 2016 9:39:10 PM com.ibm.iotf.client.AbstractClient connect
>>>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Successfully connected to the IBM Watson IoT Platform
>>>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
>>>>> INFO: Register jar: file:///home/pi/devConf/pi.sensors.jar
>>>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
>>>>> INFO: about to call registerTopology
>>>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>>>> INFO: Register application name: SpeedJarApp
>>>>> SpeedJarApp
>>>>> Sep 16, 2016 9:40:11 PM org.apache.edgent.runtime.etiao.Executable$1 accept
>>>>> INFO: No more active user tasks
>>>>> 
>>>>> Thanks,
>>>>> 
>>>>> Susan
>>>>> 
>>>>> 
>>>>> 
>>>>>> On Sep 16, 2016, at 10:32 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>>>>>> 
>>>>>> I haven’t digested the complete email message yet, but try removing those three lines before provider.start() and try again.
>>>>>> IotProvider already create/registers those services (described in its javadoc).  I guess I wouldn’t be surprised if these extra additions might much things up.
>>>>>> 
>>>>>> — Dale
>>>>>> 
>>>>>>> On Sep 16, 2016, at 1:17 PM, Susan Cline <ho...@pacbell.net> wrote:
>>>>>>> 
>>>>>>> I’ve gotten a step further, but I am still having problems.
>>>>>>> ...
>>>>>>> 
>>>>>>> public class RegisterJarExample {
>>>>>>> 		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
>>>>>>> 		/*
>>>>>>> 		 * Not sure if I need the next few lines or not ...
>>>>>>> 		 */
>>>>>>> 		JsonControlService control = new JsonControlService();
>>>>>>> 		provider.getServices().addService(ControlService.class, control); 
>>>>>>> 		ApplicationService appService = AppService.createAndRegister(provider, provider);
>>>>>>> 		provider.start();
>>>>>>> 		
>>>>>>> 		logger.info("Here is some info");
>>>>>>> 	}
>>>>>>> 	
>>>>>>> }
>>>>>> 
>>>>> 
>>>> 
>>> 
>> 
> 


Re: Trying register an application via the registerJar command

Posted by Dale LaBossiere <dm...@gmail.com>.
I think I understand the confusion / issue now...

Your app created the IotpDevice (with its config) when it started up, as a param to the IotProvider.  You only create one.

I’m think your registered-jar’s embedded TopologyBuilder builder’s accept<Topology,JsonObject> needs to call IotDevicePubSub.addIotDevice(topology) to get a “virtual" IotDevice (linked to the original IotpDevice you created) for the topology it’s building.  This is alluded to in the IotProvider class javadoc.  (the IotProvider.registerTopology() impl does that automatically for you when using the non-registerJar based flow)

e.g., something along the lines of:
    class MyRegisterJarBasedBuilder implements TopologyBuilder {  // registered as Java service provider in the jar’s manifest
	...
        BiConsumer<Topology,JsonObject> getBuilder {	   
            return (topology,config) -> MyApp.myIotDeviceBasedBuilder( IotDevicePubSub.addIotDevice(topology), config) )
        }
    }

    class MyApp {
      ...
      static void myIotDeviceBasedBuilder(IotDevice iotDevice, JsonObject config) {
	Topology t = iotDevice.getTopology();
	  … build your topology on “t” using iotDevice as needed
      }
    }

— Dale

> On Sep 19, 2016, at 10:30 PM, Susan Cline <ho...@pacbell.net> wrote:
> 
> Many thanks, Dale.
> 
> Still trying to figure this out …
> 
> Cheers,
> 
> Susan
>> On Sep 19, 2016, at 8:30 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>> 
>> FYI I just created https://issues.apache.org/jira/browse/EDGENT-250 <https://issues.apache.org/jira/browse/EDGENT-250> to update IotProvider doc related to registerJar().  You should consider adding commentary there as part of your experiences — and/or consider tacking that jira and maybe even enhancing the doc further in this space :-)
>> 
>> — Dale
>> 
>> 
>>> On Sep 19, 2016, at 11:07 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>>> 
>>> The TopologyBuilder.getBuilder() impl is bogus.  Looks like it’s copied from TestApplication().  All it does is return a builder (BiConsumer) that creates a topology consisting of a TStream<String> containing one tuple with the app’s name and prints that stream.
>>> 
>>> Your getBuilder() impl needs to return a BiConsumer that builds your app’s topology.  Looks like that’s what your accept() is trying to do.  Seems like you want something like (though I’d rename that accept() to something like “buildTopology()” for clarity).
>>> 
>>>     public BiConsumer<Topology, JsonObject> getBuilder() {
>>>     		return (t,c) -> accept(t,c);
>>>     }   
>>> 
>>> Fix that and then see what happens regarding handling of the submit request.  You might also consider adding a println to your getBuilder() and accept() to verify they’re getting called.
>>> 
>>> — Dale
>>> 
>>>> On Sep 16, 2016, at 5:44 PM, Susan Cline <ho...@pacbell.net> wrote:
>>>> 
>>>> Thanks Dale.  It did not work however, the results are the same after removing the 3 lines before provider.start().
>>>> When I submit the SpeedJarApp I can see this in the pi terminal (this is the full output from when I started the registerJarExample application to when I submitted the command):
>>>> 
>>>> pi@raspberrypi:~/devConf $ java -jar registerJarExample.jar speed_sensor_config1.txt
>>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>>> INFO: Register application name: edgentIotDevicePubSub
>>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>>> INFO: Register application name: edgentIotCommandsToControl
>>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>>> INFO: Register application name: edgentJobMonitorApp
>>>> false
>>>> Sep 16, 2016 9:39:09 PM pi.RegisterJarExample main
>>>> INFO: Here is some info
>>>> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient createClient
>>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Org ID    = ni6dcf
>>>>      Client ID    = d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1
>>>> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient connect
>>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Connecting client d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1 to ssl://ni6dcf.messaging.internetofthings.ibmcloud.com:8883 (attempt #1)...
>>>> Sep 16, 2016 9:39:10 PM com.ibm.iotf.client.AbstractClient connect
>>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Successfully connected to the IBM Watson IoT Platform
>>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
>>>> INFO: Register jar: file:///home/pi/devConf/pi.sensors.jar
>>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
>>>> INFO: about to call registerTopology
>>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>>> INFO: Register application name: SpeedJarApp
>>>> SpeedJarApp
>>>> Sep 16, 2016 9:40:11 PM org.apache.edgent.runtime.etiao.Executable$1 accept
>>>> INFO: No more active user tasks
>>>> 
>>>> Thanks,
>>>> 
>>>> Susan
>>>> 
>>>> 
>>>> 
>>>>> On Sep 16, 2016, at 10:32 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>>>>> 
>>>>> I haven’t digested the complete email message yet, but try removing those three lines before provider.start() and try again.
>>>>> IotProvider already create/registers those services (described in its javadoc).  I guess I wouldn’t be surprised if these extra additions might much things up.
>>>>> 
>>>>> — Dale
>>>>> 
>>>>>> On Sep 16, 2016, at 1:17 PM, Susan Cline <ho...@pacbell.net> wrote:
>>>>>> 
>>>>>> I’ve gotten a step further, but I am still having problems.
>>>>>> ...
>>>>>> 
>>>>>> public class RegisterJarExample {
>>>>>> 		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
>>>>>> 		/*
>>>>>> 		 * Not sure if I need the next few lines or not ...
>>>>>> 		 */
>>>>>> 		JsonControlService control = new JsonControlService();
>>>>>> 		provider.getServices().addService(ControlService.class, control); 
>>>>>> 		ApplicationService appService = AppService.createAndRegister(provider, provider);
>>>>>> 		provider.start();
>>>>>> 		
>>>>>> 		logger.info("Here is some info");
>>>>>> 	}
>>>>>> 	
>>>>>> }
>>>>> 
>>>> 
>>> 
>> 
> 


Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
Many thanks, Dale.

Still trying to figure this out …

Cheers,

Susan
> On Sep 19, 2016, at 8:30 AM, Dale LaBossiere <dm...@gmail.com> wrote:
> 
> FYI I just created https://issues.apache.org/jira/browse/EDGENT-250 <https://issues.apache.org/jira/browse/EDGENT-250> to update IotProvider doc related to registerJar().  You should consider adding commentary there as part of your experiences — and/or consider tacking that jira and maybe even enhancing the doc further in this space :-)
> 
> — Dale
> 
> 
>> On Sep 19, 2016, at 11:07 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>> 
>> The TopologyBuilder.getBuilder() impl is bogus.  Looks like it’s copied from TestApplication().  All it does is return a builder (BiConsumer) that creates a topology consisting of a TStream<String> containing one tuple with the app’s name and prints that stream.
>> 
>> Your getBuilder() impl needs to return a BiConsumer that builds your app’s topology.  Looks like that’s what your accept() is trying to do.  Seems like you want something like (though I’d rename that accept() to something like “buildTopology()” for clarity).
>> 
>>      public BiConsumer<Topology, JsonObject> getBuilder() {
>>      		return (t,c) -> accept(t,c);
>>      }   
>> 
>> Fix that and then see what happens regarding handling of the submit request.  You might also consider adding a println to your getBuilder() and accept() to verify they’re getting called.
>> 
>> — Dale
>> 
>>> On Sep 16, 2016, at 5:44 PM, Susan Cline <ho...@pacbell.net> wrote:
>>> 
>>> Thanks Dale.  It did not work however, the results are the same after removing the 3 lines before provider.start().
>>> When I submit the SpeedJarApp I can see this in the pi terminal (this is the full output from when I started the registerJarExample application to when I submitted the command):
>>> 
>>> pi@raspberrypi:~/devConf $ java -jar registerJarExample.jar speed_sensor_config1.txt
>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>> INFO: Register application name: edgentIotDevicePubSub
>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>> INFO: Register application name: edgentIotCommandsToControl
>>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>> INFO: Register application name: edgentJobMonitorApp
>>> false
>>> Sep 16, 2016 9:39:09 PM pi.RegisterJarExample main
>>> INFO: Here is some info
>>> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient createClient
>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Org ID    = ni6dcf
>>>       Client ID    = d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1
>>> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient connect
>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Connecting client d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1 to ssl://ni6dcf.messaging.internetofthings.ibmcloud.com:8883 (attempt #1)...
>>> Sep 16, 2016 9:39:10 PM com.ibm.iotf.client.AbstractClient connect
>>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Successfully connected to the IBM Watson IoT Platform
>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
>>> INFO: Register jar: file:///home/pi/devConf/pi.sensors.jar
>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
>>> INFO: about to call registerTopology
>>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>>> INFO: Register application name: SpeedJarApp
>>> SpeedJarApp
>>> Sep 16, 2016 9:40:11 PM org.apache.edgent.runtime.etiao.Executable$1 accept
>>> INFO: No more active user tasks
>>> 
>>> Thanks,
>>> 
>>> Susan
>>> 
>>> 
>>> 
>>>> On Sep 16, 2016, at 10:32 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>>>> 
>>>> I haven’t digested the complete email message yet, but try removing those three lines before provider.start() and try again.
>>>> IotProvider already create/registers those services (described in its javadoc).  I guess I wouldn’t be surprised if these extra additions might much things up.
>>>> 
>>>> — Dale
>>>> 
>>>>> On Sep 16, 2016, at 1:17 PM, Susan Cline <ho...@pacbell.net> wrote:
>>>>> 
>>>>> I’ve gotten a step further, but I am still having problems.
>>>>> ...
>>>>> 
>>>>> public class RegisterJarExample {
>>>>> 		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
>>>>> 		/*
>>>>> 		 * Not sure if I need the next few lines or not ...
>>>>> 		 */
>>>>> 		JsonControlService control = new JsonControlService();
>>>>> 		provider.getServices().addService(ControlService.class, control); 
>>>>> 		ApplicationService appService = AppService.createAndRegister(provider, provider);
>>>>> 		provider.start();
>>>>> 		
>>>>> 		logger.info("Here is some info");
>>>>> 	}
>>>>> 	
>>>>> }
>>>> 
>>> 
>> 
> 


Re: Trying register an application via the registerJar command

Posted by Dale LaBossiere <dm...@gmail.com>.
FYI I just created https://issues.apache.org/jira/browse/EDGENT-250 <https://issues.apache.org/jira/browse/EDGENT-250> to update IotProvider doc related to registerJar().  You should consider adding commentary there as part of your experiences — and/or consider tacking that jira and maybe even enhancing the doc further in this space :-)

— Dale


> On Sep 19, 2016, at 11:07 AM, Dale LaBossiere <dm...@gmail.com> wrote:
> 
> The TopologyBuilder.getBuilder() impl is bogus.  Looks like it’s copied from TestApplication().  All it does is return a builder (BiConsumer) that creates a topology consisting of a TStream<String> containing one tuple with the app’s name and prints that stream.
> 
> Your getBuilder() impl needs to return a BiConsumer that builds your app’s topology.  Looks like that’s what your accept() is trying to do.  Seems like you want something like (though I’d rename that accept() to something like “buildTopology()” for clarity).
> 
>       public BiConsumer<Topology, JsonObject> getBuilder() {
>       		return (t,c) -> accept(t,c);
>       }   
> 
> Fix that and then see what happens regarding handling of the submit request.  You might also consider adding a println to your getBuilder() and accept() to verify they’re getting called.
> 
> — Dale
> 
>> On Sep 16, 2016, at 5:44 PM, Susan Cline <ho...@pacbell.net> wrote:
>> 
>> Thanks Dale.  It did not work however, the results are the same after removing the 3 lines before provider.start().
>> When I submit the SpeedJarApp I can see this in the pi terminal (this is the full output from when I started the registerJarExample application to when I submitted the command):
>> 
>> pi@raspberrypi:~/devConf $ java -jar registerJarExample.jar speed_sensor_config1.txt
>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>> INFO: Register application name: edgentIotDevicePubSub
>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>> INFO: Register application name: edgentIotCommandsToControl
>> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>> INFO: Register application name: edgentJobMonitorApp
>> false
>> Sep 16, 2016 9:39:09 PM pi.RegisterJarExample main
>> INFO: Here is some info
>> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient createClient
>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Org ID    = ni6dcf
>>        Client ID    = d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1
>> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient connect
>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Connecting client d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1 to ssl://ni6dcf.messaging.internetofthings.ibmcloud.com:8883 (attempt #1)...
>> Sep 16, 2016 9:39:10 PM com.ibm.iotf.client.AbstractClient connect
>> INFO: pool-1-thread-22-edgentIotDevicePubSub: Successfully connected to the IBM Watson IoT Platform
>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
>> INFO: Register jar: file:///home/pi/devConf/pi.sensors.jar
>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
>> INFO: about to call registerTopology
>> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerTopology
>> INFO: Register application name: SpeedJarApp
>> SpeedJarApp
>> Sep 16, 2016 9:40:11 PM org.apache.edgent.runtime.etiao.Executable$1 accept
>> INFO: No more active user tasks
>> 
>> Thanks,
>> 
>> Susan
>> 
>> 
>> 
>>> On Sep 16, 2016, at 10:32 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>>> 
>>> I haven’t digested the complete email message yet, but try removing those three lines before provider.start() and try again.
>>> IotProvider already create/registers those services (described in its javadoc).  I guess I wouldn’t be surprised if these extra additions might much things up.
>>> 
>>> — Dale
>>> 
>>>> On Sep 16, 2016, at 1:17 PM, Susan Cline <ho...@pacbell.net> wrote:
>>>> 
>>>> I’ve gotten a step further, but I am still having problems.
>>>> ...
>>>> 
>>>> public class RegisterJarExample {
>>>> 		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
>>>> 		/*
>>>> 		 * Not sure if I need the next few lines or not ...
>>>> 		 */
>>>> 		JsonControlService control = new JsonControlService();
>>>> 		provider.getServices().addService(ControlService.class, control); 
>>>> 		ApplicationService appService = AppService.createAndRegister(provider, provider);
>>>> 		provider.start();
>>>> 		
>>>> 		logger.info("Here is some info");
>>>> 	}
>>>> 	
>>>> }
>>> 
>> 
> 


Re: Trying register an application via the registerJar command

Posted by Dale LaBossiere <dm...@gmail.com>.
The TopologyBuilder.getBuilder() impl is bogus.  Looks like it’s copied from TestApplication().  All it does is return a builder (BiConsumer) that creates a topology consisting of a TStream<String> containing one tuple with the app’s name and prints that stream.

Your getBuilder() impl needs to return a BiConsumer that builds your app’s topology.  Looks like that’s what your accept() is trying to do.  Seems like you want something like (though I’d rename that accept() to something like “buildTopology()” for clarity).

       public BiConsumer<Topology, JsonObject> getBuilder() {
       		return (t,c) -> accept(t,c);
       }   

Fix that and then see what happens regarding handling of the submit request.  You might also consider adding a println to your getBuilder() and accept() to verify they’re getting called.

— Dale

> On Sep 16, 2016, at 5:44 PM, Susan Cline <ho...@pacbell.net> wrote:
> 
> Thanks Dale.  It did not work however, the results are the same after removing the 3 lines before provider.start().
> When I submit the SpeedJarApp I can see this in the pi terminal (this is the full output from when I started the registerJarExample application to when I submitted the command):
> 
> pi@raspberrypi:~/devConf $ java -jar registerJarExample.jar speed_sensor_config1.txt
> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
> INFO: Register application name: edgentIotDevicePubSub
> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
> INFO: Register application name: edgentIotCommandsToControl
> Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
> INFO: Register application name: edgentJobMonitorApp
> false
> Sep 16, 2016 9:39:09 PM pi.RegisterJarExample main
> INFO: Here is some info
> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient createClient
> INFO: pool-1-thread-22-edgentIotDevicePubSub: Org ID    = ni6dcf
>         Client ID    = d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1
> Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient connect
> INFO: pool-1-thread-22-edgentIotDevicePubSub: Connecting client d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1 to ssl://ni6dcf.messaging.internetofthings.ibmcloud.com:8883 (attempt #1)...
> Sep 16, 2016 9:39:10 PM com.ibm.iotf.client.AbstractClient connect
> INFO: pool-1-thread-22-edgentIotDevicePubSub: Successfully connected to the IBM Watson IoT Platform
> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
> INFO: Register jar: file:///home/pi/devConf/pi.sensors.jar
> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
> INFO: about to call registerTopology
> Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerTopology
> INFO: Register application name: SpeedJarApp
> SpeedJarApp
> Sep 16, 2016 9:40:11 PM org.apache.edgent.runtime.etiao.Executable$1 accept
> INFO: No more active user tasks
> 
> Thanks,
> 
> Susan
> 
> 
> 
>> On Sep 16, 2016, at 10:32 AM, Dale LaBossiere <dm...@gmail.com> wrote:
>> 
>> I haven’t digested the complete email message yet, but try removing those three lines before provider.start() and try again.
>> IotProvider already create/registers those services (described in its javadoc).  I guess I wouldn’t be surprised if these extra additions might much things up.
>> 
>> — Dale
>> 
>>> On Sep 16, 2016, at 1:17 PM, Susan Cline <ho...@pacbell.net> wrote:
>>> 
>>> I’ve gotten a step further, but I am still having problems.
>>> ...
>>> 
>>> public class RegisterJarExample {
>>> 		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
>>> 		/*
>>> 		 * Not sure if I need the next few lines or not ...
>>> 		 */
>>> 		JsonControlService control = new JsonControlService();
>>> 		provider.getServices().addService(ControlService.class, control); 
>>> 		ApplicationService appService = AppService.createAndRegister(provider, provider);
>>> 		provider.start();
>>> 		
>>> 		logger.info("Here is some info");
>>> 	}
>>> 	
>>> }
>> 
> 


Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
Thanks Dale.  It did not work however, the results are the same after removing the 3 lines before provider.start().
When I submit the SpeedJarApp I can see this in the pi terminal (this is the full output from when I started the registerJarExample application to when I submitted the command):

pi@raspberrypi:~/devConf $ java -jar registerJarExample.jar speed_sensor_config1.txt
Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
INFO: Register application name: edgentIotDevicePubSub
Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
INFO: Register application name: edgentIotCommandsToControl
Sep 16, 2016 9:39:08 PM org.apache.edgent.runtime.appservice.AppService registerTopology
INFO: Register application name: edgentJobMonitorApp
false
Sep 16, 2016 9:39:09 PM pi.RegisterJarExample main
INFO: Here is some info
Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient createClient
INFO: pool-1-thread-22-edgentIotDevicePubSub: Org ID    = ni6dcf
         Client ID    = d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1
Sep 16, 2016 9:39:09 PM com.ibm.iotf.client.AbstractClient connect
INFO: pool-1-thread-22-edgentIotDevicePubSub: Connecting client d:ni6dcf:SpeedSensor:Pi3_SpeedSensor_1 to ssl://ni6dcf.messaging.internetofthings.ibmcloud.com:8883 (attempt #1)...
Sep 16, 2016 9:39:10 PM com.ibm.iotf.client.AbstractClient connect
INFO: pool-1-thread-22-edgentIotDevicePubSub: Successfully connected to the IBM Watson IoT Platform
Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
INFO: Register jar: file:///home/pi/devConf/pi.sensors.jar
Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerJar
INFO: about to call registerTopology
Sep 16, 2016 9:39:49 PM org.apache.edgent.runtime.appservice.AppService registerTopology
INFO: Register application name: SpeedJarApp
SpeedJarApp
Sep 16, 2016 9:40:11 PM org.apache.edgent.runtime.etiao.Executable$1 accept
INFO: No more active user tasks

Thanks,

Susan



> On Sep 16, 2016, at 10:32 AM, Dale LaBossiere <dm...@gmail.com> wrote:
> 
> I haven’t digested the complete email message yet, but try removing those three lines before provider.start() and try again.
> IotProvider already create/registers those services (described in its javadoc).  I guess I wouldn’t be surprised if these extra additions might much things up.
> 
> — Dale
> 
>> On Sep 16, 2016, at 1:17 PM, Susan Cline <ho...@pacbell.net> wrote:
>> 
>> I’ve gotten a step further, but I am still having problems.
>> ...
>> 
>> public class RegisterJarExample {
>> 		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
>> 		/*
>> 		 * Not sure if I need the next few lines or not ...
>> 		 */
>> 		JsonControlService control = new JsonControlService();
>> 		provider.getServices().addService(ControlService.class, control); 
>> 		ApplicationService appService = AppService.createAndRegister(provider, provider);
>> 		provider.start();
>> 		
>> 		logger.info("Here is some info");
>> 	}
>> 	
>> }
> 


Re: Trying register an application via the registerJar command

Posted by Dale LaBossiere <dm...@gmail.com>.
I haven’t digested the complete email message yet, but try removing those three lines before provider.start() and try again.
IotProvider already create/registers those services (described in its javadoc).  I guess I wouldn’t be surprised if these extra additions might much things up.

— Dale

> On Sep 16, 2016, at 1:17 PM, Susan Cline <ho...@pacbell.net> wrote:
> 
> I’ve gotten a step further, but I am still having problems.
> ...
> 
> public class RegisterJarExample {
> 		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
> 		/*
> 		 * Not sure if I need the next few lines or not ...
> 		 */
> 		JsonControlService control = new JsonControlService();
> 		provider.getServices().addService(ControlService.class, control); 
> 		ApplicationService appService = AppService.createAndRegister(provider, provider);
> 		provider.start();
> 		
> 		logger.info("Here is some info");
> 	}
> 	
> }


Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
HI,

I’ve gotten a step further, but I am still having problems.

My jar file that I start up first, called registerJarExample.jar now contains the correct service entries in the jar file.
This application looks like this:

package pi;

...

public class RegisterJarExample {
	private static final Logger logger = LoggerFactory.getLogger(RegisterJarExample.class); 
	public static void main(String args[]) throws Exception {

		File configFile = new File("./device_config.txt");
		IotProvider provider = new IotProvider(topology -> new IotpDevice(topology, configFile));
		/*
		 * Not sure if I need the next few lines or not ...
		 */
		JsonControlService control = new JsonControlService();
		provider.getServices().addService(ControlService.class, control); 
		ApplicationService appService = AppService.createAndRegister(provider, provider);
		provider.start();
		
		logger.info("Here is some info");
	}
	
}

Then, the jar file that contains the application that I want to run when I issue the registerJar command looks like this:

package pi.sensors;

...

public class SpeedSensorTopologyBuilder {
	
	private static abstract class Sensor implements TopologyBuilder {
        @Override
        public BiConsumer<Topology, JsonObject> getBuilder() {
        		return (t,c) -> t.strings(getName()).print();
        }   
	}
	
	public static class SpeedSensor extends Sensor {
        @Override
        public String getName() {
            return "SpeedJarApp";
        }
		
        public void accept(IotDevice device, JsonObject config) {
	        TStream<Date> readingTime = device.topology().poll(() -> new Date(), 3, TimeUnit.SECONDS);
	
			TStream<JsonObject> speedReading = readingTime.map(rt ->
				{
					JsonObject speedInfo = new JsonObject();
					long curTime = System.currentTimeMillis();
					SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss");
					Date dateObj = new Date(curTime);
					speedInfo.addProperty("time:", sdf.format(dateObj));
		
					try {
						double speed = SystemInfo.getMemoryUsed() * 0.0000000752;
					    Random randomGenerator = new Random();
					    int randomInt = randomGenerator.nextInt(20);
					    
						double randSpeed = speed + randomInt;
						DecimalFormat df = new DecimalFormat("#.##");
						speedInfo.addProperty("Speed", df.format(randSpeed));
					} catch(Exception e) {
						throw new RuntimeException(e);
					}
		            return speedInfo;
				});
			speedReading.print();
			device.events(speedReading,  "speedReading", QoS.FIRE_AND_FORGET);
			
        }
	}
}

I can tell that the application “SpeedJarApp” is being loaded because I put a logger statement in AppService.java here:

    @Override
    public void registerTopology(String applicationName, BiConsumer<Topology, JsonObject> builder) {
        logger.info("Register application name: {}", applicationName);
        applications.put(applicationName, builder);
    }

and I can see the line “Register application name SpeedJarApp”.

However, when I try to “submit’ the SpeedJarApp using this command:

edgentControl:

{"args":["SpeedJarApp",{}],"op":"submit","alias":"edgent","type":"appService”}

Nothing happens.  Looking at my code above I know something is wrong because in the ‘accept’ method, which I had used before and worked when I registered the topology through the api instead of via the registerJar command, I’m not passing the IotDevice and I’m not sure how to…

Does anyone know how I need to code the method (and if there is a particular method I need to override) to allow me to submit a command that will allow me to start sending events?  To clarify, this is the code that is in the jar file that is loaded via the registerJar command.

Thanks,

Susan


> On Sep 15, 2016, at 10:11 AM, Dan Debrunner <dj...@debrunners.com> wrote:
> 
> On 9/14/2016 10:48 AM, Susan Cline wrote:
> 
>> Are you saying there is an entry in the jar file that I need to make?
>> I.e, put something in the META-INF directory of the jar file?
> 
> Yes, it's documented (with the assumption that the reader knows Jar files) in the TopologyBuilder class and ApplicationServiceMXBean.registerJar method. Basically each application is registered as a TopologyBuilder service provider.
> 
> You can see the ant mechanism to build the jar file here:
> 
> https://github.com/apache/incubator-edgent/blob/b86179228c51bb81b85f5e0d0b588f211595d8d2/api/topology/build.xml#L45
> 
> 
> Dan.
> 


Re: Trying register an application via the registerJar command

Posted by Dan Debrunner <dj...@debrunners.com>.
On 9/14/2016 10:48 AM, Susan Cline wrote:

> Are you saying there is an entry in the jar file that I need to make?
>  I.e, put something in the META-INF directory of the jar file?

Yes, it's documented (with the assumption that the reader knows Jar 
files) in the TopologyBuilder class and 
ApplicationServiceMXBean.registerJar method. Basically each application 
is registered as a TopologyBuilder service provider.

You can see the ant mechanism to build the jar file here:

https://github.com/apache/incubator-edgent/blob/b86179228c51bb81b85f5e0d0b588f211595d8d2/api/topology/build.xml#L45

and the gradle mechanism here:

https://github.com/apache/incubator-edgent/blob/3118af66956c55b5d3b54477751372fe6398a46d/api/topology/build.gradle#L21

Dan.


Re: Trying register an application via the registerJar command

Posted by Susan Cline <ho...@pacbell.net>.
I’m not sure what you mean by that.  In IotAppServiceTest.java I see that the registerJar command adds these properties, that I may not have added:

submitApp.addProperty(JsonControlService.TYPE_KEY, ApplicationServiceMXBean.TYPE);
submitApp.addProperty(JsonControlService.ALIAS_KEY, ApplicationService.ALIAS);

… but I don’t think that is what you mean.

Are you saying there is an entry in the jar file that I need to make?  I.e, put something in the META-INF directory of the jar file?

If so, can you please tell me where this is documented, or what I need to do?

Also, when you say ‘the correct service’ is it the JsonControlService?
Is the jar that needs an entry the one that is already running, or the one that is loaded via the registerJar command?

Thanks,

Susan

> On Sep 14, 2016, at 8:47 AM, Dan Debrunner <dj...@debrunners.com> wrote:
> 
> On 9/13/2016 5:06 PM, Susan Cline wrote:
>> Hi,
>> 
>> I’m trying to come up with fairly complete example that allows me to do the following:
>> 
>> Send a registerJar command to a raspberry pi to register an Edgent application
>> Send a ‘submit’ command to start the Edgent application
>> Close/stop the Edgent application
> 
> Did you build the jar with the correct service registry entries?
> 
> Dan.
> 


Re: Trying register an application via the registerJar command

Posted by Dan Debrunner <dj...@debrunners.com>.
On 9/13/2016 5:06 PM, Susan Cline wrote:
> Hi,
>
> I\u2019m trying to come up with fairly complete example that allows me to do the following:
>
> Send a registerJar command to a raspberry pi to register an Edgent application
> Send a \u2018submit\u2019 command to start the Edgent application
> Close/stop the Edgent application

Did you build the jar with the correct service registry entries?

Dan.