Skip to content

Commit

Permalink
refactor(core)!: Added H2Db provider bundle (#5343)
Browse files Browse the repository at this point in the history
* Added db.h2db.provider bundle

Signed-off-by: pierantoniomerlino <[email protected]>

* Removed H2Db code from core bundle

Signed-off-by: pierantoniomerlino <[email protected]>

* Added new bundle in distrib

Signed-off-by: pierantoniomerlino <[email protected]>

* Updated names in component definitions

Signed-off-by: pierantoniomerlino <[email protected]>

* Fixed tests

Signed-off-by: pierantoniomerlino <[email protected]>

* Removed core.db test

Signed-off-by: pierantoniomerlino <[email protected]>

* Fixed some sonar issues

Signed-off-by: pierantoniomerlino <[email protected]>

* Tried to fix sonar complain

Signed-off-by: pierantoniomerlino <[email protected]>

* Fixed copyright; fixed import order

Signed-off-by: pierantoniomerlino <[email protected]>

* Fixed copyright

Signed-off-by: pierantoniomerlino <[email protected]>

---------

Signed-off-by: pierantoniomerlino <[email protected]>
  • Loading branch information
pierantoniomerlino authored Sep 5, 2024
1 parent e7727f8 commit b231173
Show file tree
Hide file tree
Showing 36 changed files with 569 additions and 387 deletions.
1 change: 1 addition & 0 deletions kura/distrib/config/kura.build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ org.eclipse.kura.container.provider.version=2.0.0-SNAPSHOT
org.eclipse.kura.configuration.change.manager.version=2.0.0-SNAPSHOT
org.eclipse.kura.event.publisher.version=2.0.0-SNAPSHOT
org.eclipse.kura.db.sqlite.provider.version=2.0.0-SNAPSHOT
org.eclipse.kura.db.h2db.provider.version=1.0.0-SNAPSHOT
org.eclipse.kura.rest.network.status.provider.version=2.0.0-SNAPSHOT
org.eclipse.kura.wire.script.tools.version=2.0.0-SNAPSHOT
org.eclipse.kura.cloudconnection.sparkplug.mqtt.provider.version=2.0.0-SNAPSHOT
Expand Down
7 changes: 7 additions & 0 deletions kura/distrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,11 @@
<artifactId>org.eclipse.kura.rest.network.status.provider</artifactId>
<version>${org.eclipse.kura.rest.network.status.provider.version}</version>
</artifactItem>
<artifactItem>
<groupId>org.eclipse.kura</groupId>
<artifactId>org.eclipse.kura.db.h2db.provider</artifactId>
<version>${org.eclipse.kura.db.h2db.provider.version}</version>
</artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
<outputDirectory>${project.basedir}/target/plugins</outputDirectory>
Expand Down Expand Up @@ -837,6 +842,7 @@
<move file="target/plugins/org.eclipse.kura.configuration.change.manager.jar" tofile="target/plugins/org.eclipse.kura.configuration.change.manager_${org.eclipse.kura.configuration.change.manager.version}.jar" />
<move file="target/plugins/org.eclipse.kura.event.publisher.jar" tofile="target/plugins/org.eclipse.kura.event.publisher_${org.eclipse.kura.event.publisher.version}.jar" />
<move file="target/plugins/org.eclipse.kura.rest.network.status.provider.jar" tofile="target/plugins/org.eclipse.kura.rest.network.status.provider_${org.eclipse.kura.rest.network.status.provider.version}.jar" />
<move file="target/plugins/org.eclipse.kura.db.h2db.provider.jar" tofile="target/plugins/org.eclipse.kura.db.h2db.provider_${org.eclipse.kura.db.h2db.provider.version}.jar" />
</target>
</configuration>
</execution>
Expand Down Expand Up @@ -2086,6 +2092,7 @@
<copy file="${project.build.directory}/plugins/org.eclipse.kura.container.provider_${org.eclipse.kura.container.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.configuration.change.manager_${org.eclipse.kura.configuration.change.manager.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.event.publisher_${org.eclipse.kura.event.publisher.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.db.h2db.provider_${org.eclipse.kura.db.h2db.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
</target>
</configuration>
</execution>
Expand Down
19 changes: 19 additions & 0 deletions kura/distrib/src/main/ant/build_equinox_distrib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<antcall target="linux.usb-config" />
<antcall target="bluetooth-config" />
<antcall target="linux.watchdog-config" />
<antcall target="h2db-config" />

<!-- Added Camel bundles configs -->
<antcall target="camel-config" />
Expand Down Expand Up @@ -701,6 +702,7 @@ fi]]>
<antcall target="emulator-gpio-jar" />
<antcall target="emulator-jars" />
<antcall target="linux-network-jars" />
<antcall target="h2db-jars" />

<echo message="Building Kura Distribution for ${build.name}-jars..." />

Expand Down Expand Up @@ -1281,6 +1283,14 @@ fi]]>
</propertyfile>
</target>

<target name="h2db-config">
<propertyfile
file="${project.build.directory}/${build.output.name}/config.ini">
<entry key="osgi.bundles" operation="+"
value=", reference:file:${kura.install.dir}/${kura.symlink}/${plugins.folder}/org.eclipse.kura.db.h2db.provider_${org.eclipse.kura.db.h2db.provider.version}.jar@4" />
</propertyfile>
</target>

<target name="asset-jar">
<zip destfile="${project.build.directory}/${build.output.name}.zip"
update="true">
Expand Down Expand Up @@ -1754,6 +1764,15 @@ fi]]>
todir="${build.install.dir.kura}/kura/plugins" />
</target>

<target name="h2db-jars">
<zip destfile="${project.build.directory}/${build.output.name}.zip"
update="true">
<zipfileset
file="${project.build.directory}/plugins/org.eclipse.kura.db.h2db.provider_${org.eclipse.kura.db.h2db.provider.version}.jar"
prefix="${build.output.name}/${plugins.folder}" />
</zip>
</target>

<target name="misc-config">
<propertyfile
file="${project.build.directory}/${build.output.name}/config.ini">
Expand Down
9 changes: 0 additions & 9 deletions kura/org.eclipse.kura.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,7 @@ Import-Package: javax.crypto,
org.eclipse.kura.type;version="[1.1,2.0)",
org.eclipse.kura.util.configuration;version="[1.0,2.0)",
org.eclipse.kura.util.jdbc;version="[1.0,2.0)",
org.eclipse.kura.util.message.store;version="[1.0,1.1)",
org.eclipse.kura.util.store.listener;version="[1.0,2.0)",
org.eclipse.kura.util.wire.store;version="[1.0,1.1)",
org.eclipse.kura.watchdog;version="[1.0,2.0)",
org.eclipse.kura.wire;version="[2.0,3.0)",
org.eclipse.kura.wire.store.provider;version="[1.0,1.1)",
org.h2;version="2.1.214",
org.h2.api;version="2.1.214",
org.h2.jdbcx;version="2.1.214",
org.h2.tools;version="2.1.214",
org.osgi.framework;version="1.5.0",
org.osgi.service.component;version="1.2.0",
org.osgi.service.event;version="1.4.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2023 Eurotech and/or its affiliates and others
* Copyright (c) 2011, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,8 +13,6 @@
package org.eclipse.kura.core.data;

import java.security.SecureRandom;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -45,7 +43,6 @@
import org.eclipse.kura.configuration.ConfigurationService;
import org.eclipse.kura.connection.listener.ConnectionListener;
import org.eclipse.kura.core.data.store.MessageStoreState;
import org.eclipse.kura.core.db.H2DbMessageStoreImpl;
import org.eclipse.kura.core.internal.data.TokenBucket;
import org.eclipse.kura.data.DataService;
import org.eclipse.kura.data.DataTransportService;
Expand All @@ -59,8 +56,6 @@
import org.eclipse.kura.status.CloudConnectionStatusComponent;
import org.eclipse.kura.status.CloudConnectionStatusEnum;
import org.eclipse.kura.status.CloudConnectionStatusService;
import org.eclipse.kura.util.jdbc.ConnectionProvider;
import org.eclipse.kura.util.jdbc.SQLFunction;
import org.eclipse.kura.watchdog.CriticalComponent;
import org.eclipse.kura.watchdog.WatchdogService;
import org.eclipse.paho.client.mqttv3.MqttException;
Expand Down Expand Up @@ -178,8 +173,6 @@ public Object addingService(ServiceReference<Object> reference) {

if (service instanceof MessageStoreProvider) {
setMessageStoreProvider((MessageStoreProvider) service);
} else if (service instanceof H2DbService) {
setH2DbService((H2DbService) service);
} else {
DataServiceImpl.this.componentContext.getBundleContext().ungetService(reference);
return null;
Expand Down Expand Up @@ -346,36 +339,6 @@ public synchronized void unsetMessageStoreProvider() {

}

public synchronized void setH2DbService(H2DbService dbService) {
setMessageStoreProvider(new MessageStoreProvider() {

@SuppressWarnings("restriction")
@Override
public MessageStore openMessageStore(String name) throws KuraStoreException {
return new H2DbMessageStoreImpl(new ConnectionProvider() {

@Override
public <T> T withConnection(final SQLFunction<Connection, T> task) throws SQLException {
return dbService.withConnection(task::call);
}
}, name);
}

@Override
public void addListener(ConnectionListener listener) {
// Do nothing

}

@Override
public void removeListener(ConnectionListener listener) {
// Do nothin

}
});

}

public synchronized void unsetH2DbService(H2DbService dbService) {
unsetMessageStoreProvider();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2023 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,19 +12,18 @@
*******************************************************************************/
package org.eclipse.kura.core.data;

import static java.util.Objects.requireNonNull;

import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import org.eclipse.kura.configuration.ConfigurationService;
import org.eclipse.kura.db.H2DbService;
import org.quartz.CronExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

public class DataServiceOptions {

private static final Logger logger = LoggerFactory.getLogger(DataServiceOptions.class);
Expand Down Expand Up @@ -55,7 +54,7 @@ public class DataServiceOptions {
private static final boolean AUTOCONNECT_PROP_DEFAULT = false;
private static final int CONNECT_DELAY_DEFAULT = 60;
private static final int DISCONNECT_DELAY_DEFAULT = 10;
private static final String DB_SERVICE_INSTANCE_DEFAULT = H2DbService.DEFAULT_INSTANCE_PID;
private static final String DB_SERVICE_INSTANCE_DEFAULT = "org.eclipse.kura.db.H2DbService";
private static final int STORE_HOUSEKEEPER_INTERVAL_DEFAULT = 900;
private static final int STORE_PURGE_AGE_DEFAULT = 60;
private static final int STORE_CAPACITY_DEFAULT = 10000;
Expand Down Expand Up @@ -181,11 +180,11 @@ public boolean isConnectionScheduleEnabled() {
}

public Optional<CronExpression> getConnectionScheduleExpression() {

if (!this.isConnectionScheduleEnabled()) {
return Optional.empty();
}

try {
return Optional.of(new CronExpression((String) this.properties.get(CONNECTION_SCHECULE_EXPRESSION)));
} catch (final Exception e) {
Expand Down
1 change: 1 addition & 0 deletions kura/org.eclipse.kura.db.h2db.provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/
33 changes: 33 additions & 0 deletions kura/org.eclipse.kura.db.h2db.provider/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.eclipse.kura.db.h2db.provider
Bundle-SymbolicName: org.eclipse.kura.db.h2db.provider;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Eclipse Kura
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Service-Component: OSGI-INF/*.xml
Bundle-ClassPath: .
Bundle-ActivationPolicy: lazy
Import-Package: org.eclipse.kura;version="[1.7,2.0)",
org.eclipse.kura.configuration;version="[1.2,2.0)",
org.eclipse.kura.connection.listener;version="1.0.0",
org.eclipse.kura.crypto;version="1.3.0",
org.eclipse.kura.data;version="[1.1,2.0)",
org.eclipse.kura.db;version="[2.0,2.1)",
org.eclipse.kura.message.store;version="[1.0,2.0)",
org.eclipse.kura.message.store.provider;version="[1.0,1.1)",
org.eclipse.kura.type;version="[1.1,2.0)",
org.eclipse.kura.util.configuration;version="[1.0,1.1)",
org.eclipse.kura.util.jdbc;version="[1.0,2.0)",
org.eclipse.kura.util.message.store;version="[1.0,2.0)",
org.eclipse.kura.util.store.listener;version="[1.0,2.0)",
org.eclipse.kura.util.wire.store;version="[1.0,1.1)",
org.eclipse.kura.wire;version="[2.0,3.0)",
org.eclipse.kura.wire.store.provider;version="[1.0,1.1)",
org.h2;version="2.1.214",
org.h2.api;version="2.1.214",
org.h2.jdbcx;version="2.1.214",
org.h2.tools;version="2.1.214",
org.osgi.framework;version="1.10.0",
org.osgi.service.component;version="1.4.0",
org.slf4j;version="1.7.32"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017, 2023 Eurotech and/or its affiliates and others
Copyright (c) 2017, 2024 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,7 +14,7 @@
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" enabled="true" activate="activate" configuration-policy="require" deactivate="deactivate" modified="updated" name="org.eclipse.kura.core.db.H2DbService">
<implementation class="org.eclipse.kura.core.db.H2DbServiceImpl"/>
<implementation class="org.eclipse.kura.internal.db.h2db.provider.H2DbServiceImpl"/>
<service>
<provide interface="org.eclipse.kura.configuration.ConfigurableComponent"/>
<provide interface="org.eclipse.kura.db.BaseDbService"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
Copyright (c) 2017, 2024 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,6 +14,6 @@
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" immediate="true" name="org.eclipse.kura.core.db.H2DbHelper">
<implementation class="org.eclipse.kura.core.db.H2DbHelper"/>
<implementation class="org.eclipse.kura.internal.db.h2db.provider.H2DbHelper"/>
<reference bind="setConfigurationService" cardinality="1..1" interface="org.eclipse.kura.configuration.ConfigurationService" name="ConfigurationService" policy="static" unbind="unsetConfigurationService"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
Copyright (c) 2017, 2024 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,7 +14,7 @@
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="activate" configuration-policy="require" deactivate="deactivate" immediate="true" modified="updated" name="org.eclipse.kura.core.db.H2DbServer">
<implementation class="org.eclipse.kura.core.db.H2DbServer"/>
<implementation class="org.eclipse.kura.internal.db.h2db.provider.H2DbServer"/>
<property name="service.pid" type="String" value="org.eclipse.kura.core.db.H2DbServer"/>
<service>
<provide interface="org.eclipse.kura.configuration.ConfigurableComponent"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
Copyright (c) 2017, 2024 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
Copyright (c) 2017, 2024 Eurotech and/or its affiliates and others
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
Expand Down
Loading

0 comments on commit b231173

Please sign in to comment.