Skip to content

Commit

Permalink
Added option to automatically run the liquibase database upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Aug 24, 2018
1 parent 44d54b7 commit 3dbc52d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 53 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -5,7 +5,8 @@ Version 1.8 is not released yet.
**New Features**
* Upgraded moquette to v0.11.
* Allow setting of the moquette persistent store path and storage class.
* Enabling the tomcat CorsFilter to enable cross-site-scripting can be done from environment variables.
* Enabling the tomcat CorsFilter to allow cross-site-scripting can be done from environment variables.
* Added option to automatically run the liquibase database upgrade.

**Bugfixes**
* Fixed #59, incorrect nextLink when filtering on unitOfMeasurement/name.
Expand Down
Expand Up @@ -17,6 +17,7 @@
package de.fraunhofer.iosb.ilt.sta.persistence;

import de.fraunhofer.iosb.ilt.sta.settings.CoreSettings;
import de.fraunhofer.iosb.ilt.sta.settings.PersistenceSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -34,6 +35,7 @@ public class PersistenceManagerFactory {
public static synchronized void init(CoreSettings settings) {
if (instance == null) {
instance = new PersistenceManagerFactory(settings);
maybeUpdateDatabase(settings, instance);
}
}

Expand Down Expand Up @@ -73,4 +75,13 @@ public PersistenceManager create() {
}
return persistenceManager;
}

private static void maybeUpdateDatabase(CoreSettings coreSettings, PersistenceManagerFactory instance) {
PersistenceSettings persistenceSettings = coreSettings.getPersistenceSettings();
if (persistenceSettings.isAutoUpdateDatabase()) {
String updateLog = instance.create().doUpgrades();
LOGGER.info("Database-update-log:\n{}", updateLog);
}
}

}
Expand Up @@ -33,6 +33,8 @@ public class PersistenceSettings {
private static final String DEFAULT_IMPLEMENTATION_CLASS = "de.fraunhofer.iosb.ilt.sta.persistence.postgres.longid.PostgresPersistenceManagerLong";
private static final String TAG_ALWAYS_ORDERBY_ID = "alwaysOrderbyId";
private static final String TAG_ID_GENERATION_MODE = "idGenerationMode";
private static final String TAG_AUTO_UPDATE_DATABASE = "autoUpdateDatabase";
private static final boolean DEFAULT_AUTO_UPDATE_DATABASE = false;

private static final List<String> ALL_PROPERTIES = Arrays.asList(
TAG_IMPLEMENTATION_CLASS,
Expand All @@ -46,6 +48,7 @@ public class PersistenceSettings {
private String persistenceManagerImplementationClass;
private boolean alwaysOrderbyId = true;
private String idGenerationMode = "ServerGeneratedOnly";
private boolean autoUpdateDatabase;
/**
* Extension point for implementation specific settings
*/
Expand All @@ -62,6 +65,7 @@ private void init(Settings settings) {
persistenceManagerImplementationClass = settings.get(TAG_IMPLEMENTATION_CLASS, DEFAULT_IMPLEMENTATION_CLASS);
alwaysOrderbyId = settings.getBoolean(TAG_ALWAYS_ORDERBY_ID, alwaysOrderbyId);
idGenerationMode = settings.get(TAG_ID_GENERATION_MODE, idGenerationMode);
autoUpdateDatabase = settings.getBoolean(TAG_AUTO_UPDATE_DATABASE, DEFAULT_AUTO_UPDATE_DATABASE);
customSettings = settings;
}

Expand All @@ -73,10 +77,14 @@ public boolean getAlwaysOrderbyId() {
return alwaysOrderbyId;
}

public boolean isAutoUpdateDatabase() {
return autoUpdateDatabase;
}

public Settings getCustomSettings() {
return customSettings;
}

public String getIdGenerationMode() {
return idGenerationMode;
}
Expand Down
1 change: 1 addition & 0 deletions FROST-Server.HTTP/src/main/webapp/META-INF/context.xml
Expand Up @@ -29,6 +29,7 @@
"ServerAndClientGenerated" = Both, server and client generated ids, are allowed.
"ClientGeneratedOnly" = Client has to provide @iot.id to create entities.
-->
<Parameter override="false" name="persistence.autoUpdateDatabase" value="false" description="Automatically apply database updates."/>
<Parameter override="false" name="persistence.alwaysOrderbyId" value="false" description="Always add an 'orderby=id asc' to queries to ensure consistent paging."/>
<!-- JNDO Database connection. Does suppport connection pooling. -->
<Parameter override="false" name="persistence.db_jndi_datasource" value="jdbc/sensorThings" description="JNDI data source name"/>
Expand Down
56 changes: 5 additions & 51 deletions FROST-Server.HTTP/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -77,57 +77,6 @@
<param-name>mqtt.mqttServerImplementationClass</param-name>
<param-value>de.fraunhofer.iosb.ilt.sensorthingsserver.mqtt.moquette.MoquetteMqttServer</param-value>
</context-param>
<context-param>
<description>Specifies wether MQTT support will be enabled or not.</description>
<param-name>mqtt.Enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>The port the MQTT server runs on.</description>
<param-name>mqtt.Port</param-name>
<param-value>1883</param-value>
</context-param>
<context-param>
<description>Quality of Service Level for MQTT messages.</description>
<param-name>mqtt.QoS</param-name>
<param-value>0</param-value>
</context-param>
<context-param>
<description>Queue size for messages to be pubslihed via MQTT.</description>
<param-name>mqtt.SubscribeMessageQueueSize</param-name>
<param-value>100</param-value>
</context-param>
<context-param>
<description>Number of threads use to dispatch MQTT notifications.</description>
<param-name>mqtt.SubscribeThreadPoolSize</param-name>
<param-value>20</param-value>
</context-param>
<context-param>
<description>Queue size for create observation requests via MQTT.</description>
<param-name>mqtt.CreateMessageQueueSize</param-name>
<param-value>100</param-value>
</context-param>
<context-param>
<description>Number of threads use to dispatch observation creation requests.</description>
<param-name>mqtt.CreateThreadPoolSize</param-name>
<param-value>10</param-value>
</context-param>
<context-param>
<description>The external IP address or host name the MQTT server should listen on. Set to 0.0.0.0 to listen on all interfaces.</description>
<param-name>mqtt.Host</param-name>
<param-value>0.0.0.0</param-value>
</context-param>
<context-param>
<description>The internal host name of the MQTT server.</description>
<param-name>mqtt.internalHost</param-name>
<param-value>localhost</param-value>
</context-param>
<!-- MQTT setting -->
<context-param>
<description>The port the MQTT server is reachable via WebSocket.</description>
<param-name>mqtt.WebsocketPort</param-name>
<param-value>9876</param-value>
</context-param>
<!-- persistence setting -->
<context-param>
<description>The java class used for persistence (must implement PersistenceManaher interface)</description>
Expand All @@ -139,6 +88,11 @@
de.fraunhofer.iosb.ilt.sta.persistence.postgres.uuidid.PostgresPersistenceManagerUuid
-->
</context-param>
<context-param>
<description>Automatically apply database updates.</description>
<param-name>persistence.autoUpdateDatabase</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>Always add an 'orderby=id asc' to queries to ensure consistent paging.</description>
<param-name>persistence.alwaysOrderbyId</param-name>
Expand Down
1 change: 1 addition & 0 deletions FROST-Server.MQTTP/src/main/webapp/META-INF/context.xml
Expand Up @@ -40,6 +40,7 @@
"ServerAndClientGenerated" = Both, server and client generated ids, are allowed.
"ClientGeneratedOnly" = Client has to provide @iot.id to create entities.
-->
<Parameter override="false" name="persistence.autoUpdateDatabase" value="false" description="Automatically apply database updates."/>
<Parameter override="false" name="persistence.alwaysOrderbyId" value="false" description="Always add an 'orderby=id asc' to queries to ensure consistent paging."/>
<!-- JNDO Database connection. Does suppport connection pooling. -->
<Parameter override="false" name="persistence.db_jndi_datasource" value="jdbc/sensorThings" description="JNDI data source name"/>
Expand Down
5 changes: 5 additions & 0 deletions FROST-Server.MQTTP/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -137,6 +137,11 @@
de.fraunhofer.iosb.ilt.sta.persistence.postgres.uuidid.PostgresPersistenceManagerUuid
-->
</context-param>
<context-param>
<description>Automatically apply database updates.</description>
<param-name>persistence.autoUpdateDatabase</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>Always add an 'orderby=id asc' to queries to ensure consistent paging.</description>
<param-name>persistence.alwaysOrderbyId</param-name>
Expand Down
1 change: 1 addition & 0 deletions docker-compose-separated.yaml
Expand Up @@ -17,6 +17,7 @@ services:
- persistence_db_url=jdbc:postgresql://database:5432/sensorthings
- persistence_db_username=sensorthings
- persistence_db_password=ChangeMe
- persistence_autoUpdateDatabase=true

mqtt:
image: fraunhoferiosb/frost-server-mqtt:latest
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Expand Up @@ -11,6 +11,7 @@ services:
- persistence_db_url=jdbc:postgresql://database:5432/sensorthings
- persistence_db_username=sensorthings
- persistence_db_password=ChangeMe
- persistence_autoUpdateDatabase=true
ports:
- 8080:8080
- 1883:1883
Expand Down

0 comments on commit 3dbc52d

Please sign in to comment.