Help on creating .bnd and wrapper API files/entries for using Cassandra

Hello Everybody,

Greetings !

We would like to customize OpenEMS to store device data to Cassandra (similar to OpenEMS’s TimeData InfluxDB implementation).

We have taken the latest OpenEMS develop branch. Following DataStax’s Java drivers for Cassandra (available as an OSGi bundle) will be used.

  • java-driver-core-4.13.0.jar
  • java-driver-query-builder-4.13.0.jar
  • java-driver-mapper-runtime-4.13.0.jar

Following entries have been added to openems/cnf/pom.xml:

<dependency>
	<groupId>com.datastax.oss</groupId>
	<artifactId>java-driver-core</artifactId>
	<version>4.13.0</version>
</dependency>
       <!-- added similar entries for -->
	<artifactId>java-driver-query-builder</artifactId>
	<artifactId>java-driver-mapper</artifactId>

Added cassandra.bnd in the newly created directory openems/io.openems.edge.timedata.cassandra.

To add API specifications, we used OpenEMS’s InfluxDB io.openems.wrapper/influxdb-java.bnd as reference and added openems/io.openems.wrapper/cassandra-java.bnd.

Project build shows the following error:
® ‘io.openems.wrapper.cassandra-java: Can not find JAR file java-driver-core-4.13.0.jar, java-driver-query-builder-4.13.0.jar and java-driver-mapper-runtime-4,13.0.jar

There are issues with the above mentioned procedure.

I kindly request to guide on creating the bnd file and the addition of dependency entries (for API specification).

Thank you very much,
Regards,
Uma Maheswaran

Hi Uma Maheswaran,

Thanks for getting in touch. What you did sounds ok. To find the problem, I would have to do the same steps again and try it on my machine.

Can you publish your developments in a Branch on Github to save me some time?

Thanks & Regards,
Stefan

Hi Stefan,

My apologies for the late response. I was not able to respond earlier.

We have created the following public repository containing the changes for Cassandra:

CassandraSample class in EdgeApp.java has been added for verifying the successful connectivity from OpenEMS.

The jar has been built successfully. ErrorLog-Cassandra.log - Contains the error log when the generated openems_edge.jar is run.

I Kindly request to guide us to resolve the missing requirement error.

Changes in openems-community with respect to OpenEMS:

  1. cnf/pom.xml - Contains the changes for including the dependencies for Cassandra

  2. io.openems.edge.application/EdgeApp.bndrun - Change in “-runproperties” for entries felix.cm.dir and openems.data.dir

  3. io.openems.edge.application/bnd.bnd - Added “com.datastax.oss.driver.core” in “-buildpath”

  4. io.openems.edge.application/src/io/openems/edge/application/EdgeApp.java - Added class CassandraSample and changes in activate() to call CassandraSample.doCRUDOperations()

  5. io.openems.wrapper/*.jar files - Added the DataStax Java driver jar files for Cassandra

  6. io.openems.edge.application/EdgeApp.bndrun - Added entry (line 336) for Cassandra in “runbundles”

  7. ErrorLog-Cassandra.log - Contains the error log when the generated openems_edge.jar is run

Thank you very much,
Regards,
Uma Maheswaran

Hi,

I checked out your branch and tried to fix and build it on my machine.

Could you please grant me (sfeilmeier (Stefan Feilmeier) · GitHub) write permissions on your repository, so that I can push some fixes on your branch?

Things were a bit complicated, because you did not use the Github “Fork” feature, but instead created a completely new repository and as such lost the entire git history. This will make merging future improvements from OpenEMS to your branch complicated; and will also make it complicated to contribute back to OpenEMS - which would be very welcomed for such an improvement. See Fork a repo - GitHub Docs for more information.

Regards,
Stefan

Hi Stefan,
Thank you very much for your response. We have added your id to the repository.
I am sorry. I am not aware about GitHub’s Fork feature. The repository which we have provided has port number changes also for Edge server and Backend server. We will create a new repository by using GitHub Fork feature to create fork of OpenEMS and apply changes for integrating Cassandra by tomorrow. I will inform once the repository is created.

Thank you very much,
Regards,
Uma Maheswaran

Hi,

no worries. Just wanted to make you aware of it. Knowing some basic git commands will help you down the line and simplify things.

I pushed two commits. The first (Reset files to closest develop version I could find · umamaheswaran-j/openems-community@811468c · GitHub) resets some files back to OpenEMS defaults, which I assume you touched unintentionally.

The second (Successfully starts now. · umamaheswaran-j/openems-community@598fb08 · GitHub) fixes the build and should be able to connect to a Cassandra server. Some background info on that commit:

  1. The datastax library comes with full OSGi support, i.e. the MANIFEST file inside the jar library file provides all the information needed for OSGi. Because of this it is not required to create a wrapper inside io.openems.wrapper.

  2. Many of the dependencies listed in https://mvnrepository.com/artifact/com.datastax.oss/java-driver-core/4.13.0, are compile time dependencies and not required during running. I removed them from the pom.xml file.

  3. What I typically do to solve the dependencies problem is to strip down my workspace by closing all unnecessary projects in Eclipse IDE and remove everything from the EdgeApp.bndrun, that I do not need. This speeds up the build in Eclipse IDE and makes the Resolve feature faster. Then I start adding the first dependency, check if it has the required OSGi headers in the MANIFEST and try to Resolve EdgeApp.bndrun. If this points me to a missing runtime dependency, I add that one as well, and so on.

  4. The current state still throws a ‘Unable to load JNR native implementation’ exception on startup, but that is ok according to DataStax Java Driver - Frequently Asked Questions - OSGi

Regards,
Stefan

Hi Stefan,

It is great that with your changes, connecting to Cassandra server from OpenEMS environment has been done successfully. Thank you very much for your commits. It is a great help for our team.

Regarding Point 3 - This information will be useful for us. We have kept all the projects open all the time.

Following is the summary of changes:
(This may be useful for anyone who wants to use Cassandra from OpenEMS)

  1. Addition of DataStax Java driver entries to cnf/pom.xml
<dependency>
    <groupId>com.datastax.oss</groupId>
    <artifactId>java-driver-core</artifactId>
    <version>4.13.0</version>
</dependency><!-- https://mvnrepository.com/artifact/com.datastax.oss/native-protocol -->
<dependency>
    <groupId>com.datastax.oss</groupId>
    <artifactId>native-protocol</artifactId>
    <version>1.5.0</version>
</dependency><!-- https://mvnrepository.com/artifact/com.datastax.oss/java-driver-shaded-guava -->
<dependency>
    <groupId>com.datastax.oss</groupId>
    <artifactId>java-driver-shaded-guava</artifactId>
    <version>25.1-jre</version>
</dependency>
  1. In the project configuration where Cassandra needs to be used (version number may change):

a) Addition of the following entry in -buildpath in bnd.bnd:
com.datastax.oss.driver.core;version=‘4.13’,\

b) Addition of “-runbundles” entries in .bndrun:

-runbundles:
com.datastax.oss.driver.core;version=’[4.13.0,4.13.1)’,
com.datastax.oss.driver.shaded.guava;version=’[25.1.0,25.1.1)’,
com.datastax.oss.protocol;version=’[1.5.0,1.5.1)’,\

(In openems-community, we have added the code to io/openems/edge/application/EdgeApp.java to test the connectivity to Cassandra)

Thank you very much,
Regards,
Uma Maheswaran

1 Like

Hi Stefan,

When we use the OpenEMS from GitHub - OpenEMS/openems: OpenEMS - Open Source Energy Management System, modify to include Cassandra code, we are getting some more dependency errors during ‘Resolve’.

We referred Point #3 (quoted below) from your response.

Are there any other guidelines/help available to resolve the dependency errors so that time/effort can be reduced?

Thanks and Regards,
Uma Maheswaran

Hi,

dependency and resolve problems in OSGi are unforunately very often difficult to solve.

The best and most specific guide on the topic is this one, but it is also complicated to understand. In rest, usually the existing wrappers in OpenEMS provide good examples.

Regarding the usage of Cassandra in OpenEMS. Instead of asking everybody who would like to see this feature in OpenEMS to follow your steps, the Open-Source way would be to create a Pull-Request and have this feature natively available in OpenEMS.

Could you start such a Pull-Request from a Fork (see documentation on Github) so that the community and I can review it and eventually merge it to OpenEMS?

Regards,
Stefan

Thank you Stefan. I will refer the bnd guide that you have mentioned. After resolving the dependency problems, I will create Pull-Request for integrating the changes done for Cassandra to OpenEMS.

Thanks and Regards,
Uma Maheswaran