Hi all,

After more digging I was able to figure out the issue. In my first jar (
cputemptopology-1.0.0.jar) which contains the TopologyBuilder
implementation, I haven't registered the service provider and hence the
ServiceLoader was unable to pick up the service. After fixing this I was
able to get it running.

So my current cputemptopology-1.0.0.jar has the following structure.

├── META-INF
│   ├── MANIFEST.MF
│   ├── maven
│   │   └── org.amrsnghe.test.topology
│   │       └── cputemptopology
│   │           ├── pom.properties
│   │           └── pom.xml
│   └── services
│       └── org.apache.edgent.topology.services.TopologyBuilder
└── org
    └── amrsnghe
        └── test
            └── topology
                ├── CPUTempSensor.class
                └── MyTopology.class

And
the META-INF/services/org.apache.edgent.topology.services.TopologyBuilder
has the following line:
org.amrsnghe.test.topology.MyTopology

Let me know if I am doing something wrong here. But this seems to work, and
the topology loaded from the jar is submitted to the direct provider and
executed without an issue.

Thank you.

/Gayashan

On Wed, May 31, 2017 at 1:11 PM, Gayashan Amarasinghe <
gayashan.amarasin...@gmail.com> wrote:

> Hi Edgent community,
>
> I am a PhD student from University of Melbourne and I am interested in the
> Apache Edgent project. I need some help to implement a scenario to submit a
> topology externally to a provider. Unfortunately apart from some test cases
> in the source code and [1], I couldn't find any documentation on this. So
> here's what I have done so far,
>
>    - I have implemented the TopologyBuilder interface and created a
>    separate jar. This is the code in the class.
>
> public class MyTopology implements TopologyBuilder {
>
>     @Override
>
>     public String getName() {
>
>         return "MyCPUTempApp";
>
>     }
>
>
>     @Override
>
>     public BiConsumer<Topology, JsonObject> getBuilder() {
>
>         CPUTempSensor cpuTempSensor = new CPUTempSensor();
>
>         return (t, c) -> t.poll(cpuTempSensor, 2, TimeUnit.SECONDS)
>
>                 .filter(readings -> readings >
> 35).sink(System.out::println);
>
>     }
>
> }
>
>
>    - In a separate project, I have created another class to instantiate a
>    DirectProvider and to load the previous jar using an AppService similar to
>    the IotAppServiceTest. Here's the code,
>
> public class DynamicAppLoader {
>     public static void main(String[] args) {
>         DirectProvider directProvider = new DirectProvider();
>         JsonControlService jsonControlService = new JsonControlService();
>         directProvider.getServices().addService(ControlService.class,
> jsonControlService);
>         ApplicationService service = 
> AppService.createAndRegister(directProvider,
> directProvider);
>         File cpuTempAppJar =
>                 new File("/home/gayashan/projects/
> research/cputemptopology/target/cputemptopology-1.0.0.jar");
>         try {
>             URL cpuTempAppJarUrl = cpuTempAppJar.toURI().toURL();
>             JsonObject registerJar = newRegisterJarRequest(
> cpuTempAppJarUrl.toExternalForm());
>             jsonControlService.controlRequest(registerJar);
>             JsonObject submitCpuTempApp = newSubmitRequest("
> MyCPUTempApp");
>             jsonControlService.controlRequest(submitCpuTempApp);
>             System.out.println(service.getApplicationNames());
>         } catch (Exception e) {
>             System.err.println("Error: " + e.getLocalizedMessage());
>         }
>     }
>
> ...
> // newRegisterJarRequest and newSubmitRequest methods are as same as in
> the IotAppServiceTest class.
> }
>
> But unfortunately I don't understand how to get this to work. Can someone
> help me with this and point where I am making a mistake? Apologies in
> advance if this seems like a trivial question.
>
> Thank you.
>
> [1] https://edgent.apache.org/recipes/recipe_dynamic_
> analytic_control.html#loosely-coupled-edgent-applications
>
> Best regards,
> Gayashan
>

Reply via email to