Skip to content

Commit

Permalink
Merge pull request #135 from swisspost/develop
Browse files Browse the repository at this point in the history
PR for new release
  • Loading branch information
mcweba authored Aug 29, 2023
2 parents 683880e + 07df564 commit 159a6fc
Show file tree
Hide file tree
Showing 41 changed files with 2,334 additions and 1,237 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,30 +188,31 @@ The data compression feature is not compatible with all vertx-rest-storage featu

The following configuration values are available:

| Property | Type | Default value | Description |
|:----------------------------------------|:-------|:-------------------------|:--------------------------------------------------------------------------------------------------------------------------------------|
| root | common | . | The prefix for the directory or redis key |
| storageType | common | filesystem | The storage implementation to use. Choose between filesystem or redis |
| port | common | 8989 | The port the mod listens to when HTTP API is enabled. |
| httpRequestHandlerEnabled | common | true | When set to _false_, the storage is accessible throught the event bus only. |
| httpRequestHandlerAuthenticationEnabled | common | false | Enable / disable authentication for the HTTP API |
| httpRequestHandlerUsername | common | | The username for the HTTP API authentication |
| httpRequestHandlerPassword | common | | The password for the HTTP API authentication |
| prefix | common | / | The part of the URL path before this handler (aka "context path" in JEE terminology) |
| storageAddress | common | resource-storage | The eventbus address the mod listens to. |
| editorConfig | common | | Additional configuration values for the editor |
| confirmCollectionDelete | common | false | When set to _true_, an additional _recursive=true_ url parameter has to be set to delete collections |
| redisHost | redis | localhost | The host where redis is running on |
| redisPort | redis | 6379 | The port where redis is running on |
| expirablePrefix | redis | rest-storage:expirable | The prefix for expirable data redis keys |
| resourcesPrefix | redis | rest-storage:resources | The prefix for resources redis keys |
| collectionsPrefix | redis | rest-storage:collections | The prefix for collections redis keys |
| deltaResourcesPrefix | redis | delta:resources | The prefix for delta resources redis keys |
| deltaEtagsPrefix | redis | delta:etags | The prefix for delta etags redis keys |
| lockPrefix | redis | rest-storage:locks | The prefix for lock redis keys |
| resourceCleanupAmount | redis | 100000 | The maximum amount of resources to clean in a single cleanup run |
| rejectStorageWriteOnLowMemory | redis | false | When set to _true_, PUT requests with the x-importance-level header can be rejected when memory gets low |
| freeMemoryCheckIntervalMs | redis | 60000 | The interval in milliseconds to calculate the actual memory usage |
| Property | Type | Default value | Description |
|:----------------------------------------|:-------|:-------------------------|:------------------------------------------------------------------------------------------------------------------------------|
| root | common | . | The prefix for the directory or redis key |
| storageType | common | filesystem | The storage implementation to use. Choose between filesystem or redis |
| port | common | 8989 | The port the mod listens to when HTTP API is enabled. |
| httpRequestHandlerEnabled | common | true | When set to _false_, the storage is accessible throught the event bus only. |
| httpRequestHandlerAuthenticationEnabled | common | false | Enable / disable authentication for the HTTP API |
| httpRequestHandlerUsername | common | | The username for the HTTP API authentication |
| httpRequestHandlerPassword | common | | The password for the HTTP API authentication |
| prefix | common | / | The part of the URL path before this handler (aka "context path" in JEE terminology) |
| storageAddress | common | resource-storage | The eventbus address the mod listens to. |
| editorConfig | common | | Additional configuration values for the editor |
| confirmCollectionDelete | common | false | When set to _true_, an additional _recursive=true_ url parameter has to be set to delete collections |
| redisHost | redis | localhost | The host where redis is running on |
| redisPort | redis | 6379 | The port where redis is running on |
| expirablePrefix | redis | rest-storage:expirable | The prefix for expirable data redis keys |
| resourcesPrefix | redis | rest-storage:resources | The prefix for resources redis keys |
| collectionsPrefix | redis | rest-storage:collections | The prefix for collections redis keys |
| deltaResourcesPrefix | redis | delta:resources | The prefix for delta resources redis keys |
| deltaEtagsPrefix | redis | delta:etags | The prefix for delta etags redis keys |
| lockPrefix | redis | rest-storage:locks | The prefix for lock redis keys |
| resourceCleanupAmount | redis | 100000 | The maximum amount of resources to clean in a single cleanup run |
| resourceCleanupIntervalSec | redis | | The interval (in seconds) how often to peform the storage cleanup. When set to _null_ no periodic storage cleanup is peformed |
| rejectStorageWriteOnLowMemory | redis | false | When set to _true_, PUT requests with the x-importance-level header can be rejected when memory gets low |
| freeMemoryCheckIntervalMs | redis | 60000 | The interval in milliseconds to calculate the actual memory usage |

### Configuration util

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.swisspush</groupId>
<artifactId>rest-storage</artifactId>
<version>3.0.15-SNAPSHOT</version>
<version>3.0.16-SNAPSHOT</version>
<name>rest-storage</name>
<description>
Persistence for REST resources in the filesystem or a redis database
Expand Down Expand Up @@ -415,7 +415,7 @@
<mockito.version>1.10.19</mockito.version>
<rest-assured.version>4.3.0</rest-assured.version>
<awaitility.version>1.6.5</awaitility.version>
<jedis.version>2.9.0</jedis.version>
<jedis.version>3.7.0</jedis.version>
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
<sonatypeOssDistMgmtSnapshotsUrl>
https://oss.sonatype.org/content/repositories/snapshots/
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/swisspush/reststorage/DefaultRedisProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.RedisAPI;
import io.vertx.redis.client.RedisOptions;
import org.apache.commons.lang.StringUtils;
import org.swisspush.reststorage.redis.RedisProvider;
import org.swisspush.reststorage.util.ModuleConfiguration;

import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -19,7 +21,7 @@ public class DefaultRedisProvider implements RedisProvider {

private final Vertx vertx;

private ModuleConfiguration configuration;
private final ModuleConfiguration configuration;

private RedisAPI redisAPI;

Expand Down Expand Up @@ -62,9 +64,8 @@ private Future<RedisAPI> setupRedisClient(){

private Future<RedisAPI> connectToRedis() {
Promise<RedisAPI> promise = Promise.promise();
String protocol = configuration.isRedisEnableTls() ? "rediss://" : "redis://";
Redis.createClient(vertx, new RedisOptions()
.setConnectionString(protocol + configuration.getRedisHost() + ":" + configuration.getRedisPort())
.setConnectionString(createConnectString())
.setPassword((configuration.getRedisAuth() == null ? "" : configuration.getRedisAuth()))
.setMaxPoolSize(configuration.getMaxRedisConnectionPoolSize())
.setMaxPoolWaiting(configuration.getMaxQueueWaiting())
Expand All @@ -79,4 +80,16 @@ private Future<RedisAPI> connectToRedis() {

return promise.future();
}

private String createConnectString() {
StringBuilder connectionStringBuilder = new StringBuilder();
connectionStringBuilder.append(configuration.isRedisEnableTls() ? "rediss://" : "redis://");
String redisUser = configuration.getRedisUser();
String redisPassword = configuration.getRedisPassword();
if (StringUtils.isNotEmpty(redisUser) && StringUtils.isNotEmpty(redisPassword)) {
connectionStringBuilder.append(configuration.getRedisUser()).append(":").append(redisPassword).append("@");
}
connectionStringBuilder.append(configuration.getRedisHost()).append(":").append(configuration.getRedisPort());
return connectionStringBuilder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FileSystemStorage implements Storage {
private final int rootLen;
private final FileSystemDirLister fileSystemDirLister;

private Logger log = LoggerFactory.getLogger(FileSystemStorage.class);
private final Logger log = LoggerFactory.getLogger(FileSystemStorage.class);

public FileSystemStorage(Vertx vertx, String root) {
this.vertx = vertx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class MimeTypeResolver {

private Map<String, String> mimeTypes = new HashMap<>();

private String defaultMimeType;
private final String defaultMimeType;

public MimeTypeResolver(String defaultMimeType) {
this.defaultMimeType = defaultMimeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private User(String name, String password) {
}
}

private User user;
private final User user;

public ModuleConfigurationAuthentication(ModuleConfiguration configuration) {
Objects.requireNonNull(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class RedisRestStorageRunner {

public static void main(String[] args) {
ModuleConfiguration modConfig = new ModuleConfiguration()
.storageType(ModuleConfiguration.StorageType.redis);
.storageType(ModuleConfiguration.StorageType.redis)
.resourceCleanupIntervalSec(10);

Vertx.vertx().deployVerticle(new RestStorageMod(), new DeploymentOptions().setConfig(modConfig.asJsonObject()), event ->
LoggerFactory.getLogger(RedisRestStorageRunner.class).info("rest-storage started"));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/swisspush/reststorage/RestStorageMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import io.vertx.core.http.HttpServerRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swisspush.reststorage.redis.RedisProvider;
import org.swisspush.reststorage.redis.RedisStorage;
import org.swisspush.reststorage.util.ModuleConfiguration;

public class RestStorageMod extends AbstractVerticle {

private Logger log = LoggerFactory.getLogger(RestStorageMod.class);
private final Logger log = LoggerFactory.getLogger(RestStorageMod.class);

private RedisProvider redisProvider;

Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/swisspush/reststorage/lock/Lock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.swisspush.reststorage.lock;

import io.vertx.core.Future;

/**
* Cluster wide locks allow you to obtain exclusive locks across the cluster.
* This is useful when you want to do something or access a resource on only one node of a cluster at any one time.
*
* @author https://github.com/mcweba [Marc-Andre Weber]
*/
public interface Lock {
/**
* Try to acquire a lock.
* The <code>token</code> parameter value must be unique across all clients and all lock requests. The <code>lockExpiryMs</code>
* parameter defines the expiry of the lock.
* When not manually released, the lock will be released automatically when expired.
*
* @param lock The name of the lock to acquire
* @param token A unique token to define the owner of the lock
* @param lockExpiryMs The lock expiry in milliseconds
* @return Returns a Future holding a Boolean value whether the lock could be successfully acquired or not
*/
Future<Boolean> acquireLock(String lock, String token, long lockExpiryMs);

/**
* Try to release a lock.
* The <code>token</code> parameter value is used to verify that only the owner of the lock can release it.
* The <code>token</code> parameter value also prevents the original owner of an already expired lock to release a lock
* which has been acquired by another client.
*
* @param lock The name of the lock to release
* @param token A unique token to verify if the owner of the lock tries to release the lock
* @return Returns a Promise holding a Boolean value whether the lock could be successfully released or not
*/
Future<Boolean> releaseLock(String lock, String token);
}
Loading

0 comments on commit 159a6fc

Please sign in to comment.