Solved Basic Module Development Questions
-
Hi, I have some questions about how to build a module. So far, I've downloaded Eclipse for Java EE Developers and JDK. I've also cloned the git repositories from https://github.com/infiniteautomation/ma-modules-public and https://github.com/infiniteautomation/ma-core-public. I've been going into the Virtual Data Source folder and right clicking on the pox.xml file, and running it as Maven build. From what I understand, I'm supposed to configure the settings by linking the settings.xml file, but I don't see the file in the Virtual Data Source folder. There's also errors in the other folders that I've cloned. I'm a little confused on where to go from here.
-
-
@Jared-Wiltshire Hey Jared, thanks for sharing the link. I think I got my settings.xml file in order now! Do you know how would I go about modifying the pom.xml file? So far I've copied the folder for the Virtual Data Source to use as a base, so what parts of the pom file would I have to modify? What are my next steps here?
-
@jwang I have been working on getting some examples setup to help build a data source that might be of help.
Here is a repository that I'll be adding to in the coming weeks but for now it has one example polling data source that works with Mango 3.6.0 its a vanilla module that can be used as a starting point:
https://github.com/infiniteautomation/ma-modules-contrib
Here is another one I recently completed as a user module that is not part of the Mango codebase:
https://github.com/terrypacker/mango-modules/tree/master/acurite-ds
There is one thing that both of these pom.xml files don't have that would allow you to develop and build them without any of the Mango code checked out locally, which would be to reference the IAS Maven repositories. You can add them into the pom like this:
<repositories> <repository> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> <id>ias-snapshots</id> <name>Mango Dependencies</name> <url>https://maven.mangoautomation.net/repository/ias-snapshot/</url> </repository> <repository> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>ias-releases</id> <name>Mango Dependencies</name> <url>https://maven.mangoautomation.net/repository/ias-release/</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> <id>ias-snapshots</id> <name>Mango Dependencies</name> <url>https://maven.mangoautomation.net/repository/ias-snapshot/</url> </pluginRepository> <pluginRepository> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>ias-releases</id> <name>Mango Dependencies</name> <url>https://maven.mangoautomation.net/repository/ias-release/</url> </pluginRepository> </pluginRepositories>
-
@terrypacker It seems like both of these pom.xml files have the same issue where I'm getting an error that says "Could not find artifact com.infiniteautomation.mango:mango-api:jar:3.6.0-SNAPSHOT in ias-snapshots (https://maven.mangoautomation.net/repository/ias-snapshot/)."
I've added in the snippet of code into the project and ran it as a Maven build. Is there something else I should be doing to fix this? -
Sorry, our maven repository only holds the latest snapshot versions and lets the older ones roll off. The latest version is
3.6.1-SNAPSHOT
for the api module. Since that version will also eventually drop off of the repository I would suggest you use the release version of the api module as that will always be available. So change the dependency from3.6.0-SNAPSHOT
to3.6.0
and you should be good to go. -
@terrypacker Thanks, that fixed it for me!
Also, from what I understand so far, modules are defined by the features in this folder: https://github.com/infiniteautomation/ma-core-public/tree/main/Core/src/com/serotonin/m2m2/module. How can I add these features to that vanilla module? Is there a package I have to put them in, or are there dependencies I need to change in the pom file, ect? For example, say I wanted to use the Script Source Definition (I believe this gives the black scripting box like in the scripting data source, but correct me if I'm wrong!). How would I add that particular element to the vanilla module?
To add some context, the end goal of this module I'm building is essentially a more refined version of the HTTP Retriever data source, dedicated to only a specific site with a specific API protocol. I want to be able to add/select certain parameters for an HTTP GET request (likely as a drop down box of some sort), and then automatically parse the resulting JSON file.
-
Hi jwang,
Classes which extend ModuleElementDefinition classes are reflected out of modules when loading them in startup. So, no, you do not need to place them in any particular package. REST controllers are not unconditionally reflected out of modules, though, so currently you would need to place rest controllers in
com.serotonin.mango.rest.v1
orcom.serotonin.mango.rest.v2
-
@phildunlap In that case, could you elaborate a bit more on what I do have to add to the vanilla module in order to get a drop down box or a text field and such?
-
@jwang said in Basic Module Development Questions:
@phildunlap In that case, could you elaborate a bit more on what I do have to add to the vanilla module in order to get a drop down box or a text field and such?
Are you talking about in the new UI? e.g. on a dashboard designer page? You will need to have an AngularJSModuleDefinition and a REST API class (annotated with
@RestController
and in thecom.infiniteautomation.mango.rest.v2
package).I might add a new simpler example to the https://github.com/infiniteautomation/ma-modules-contrib repo.
-
I would start by having a look in the web-src directory of some of the public modules. They're also examples! https://github.com/infiniteautomation/ma-modules-public
To add some context, the end goal of this module I'm building is essentially a more refined version of the HTTP Retriever data source, dedicated to only a specific site with a specific API protocol. I want to be able to add/select certain parameters for an HTTP GET request (likely as a drop down box of some sort), and then automatically parse the resulting JSON file.
I personally would be hesitant to create a whole module for this. You can probably achieve this ambition using the HttpBuilder in a script. You would just have to set values to points to change how the script behaves instead of configure it as a data source.
-
I guess I have more questions about what you are trying to achieve -
- Do you require the information retrieved from your external HTTP API to be available as data points / point values? (e.g. you want to store history for them in the Mango time series database, or you want the values to be available on the watch list etc)
- Is the external HTTP API available on the internet / accessible from the client web browser? If so you may be able to request the data directly from the web browser via a XHR request.