From a772395a4fa1fe5170ebe60c4ef1e47bae8c4a4a Mon Sep 17 00:00:00 2001 From: Stefan Freyr Stefansson Date: Tue, 2 Apr 2024 14:00:12 +0000 Subject: [PATCH 1/2] Split services/command-router module into three modules (base, infinispan and redis). The infinispan and redis modules produce two separate command-router images. --- bom/pom.xml | 22 +- client-device-connection-infinispan/pom.xml | 15 +- .../infinispan/client/BasicCache.java | 1 + .../infinispan/client/HotrodCache.java | 2 +- ...emoteCacheQuarkusPropertyBindingTest.java} | 18 +- client-device-connection-redis/pom.xml | 122 ++++++++++ .../redis/client/RedisCache.java | 217 ++++++++++++++++++ .../native-image.properties | 15 ++ .../resources-config.json | 37 +++ .../src/main/resources/application.properties | 11 + .../src/test/resources/logback-test.xml | 37 +++ .../test/resources/remote-cache-options.yaml | 34 +++ client-device-connection/pom.xml | 164 +++++++++++++ .../AdapterInstanceStatusProvider.java | 2 +- .../hono/deviceconnection/common}/Cache.java | 2 +- .../CacheBasedDeviceConnectionInfo.java | 2 +- .../common}/CommonCacheConfig.java | 2 +- .../common}/CommonCacheOptions.java | 2 +- .../common}/DeviceConnectionInfo.java | 2 +- .../DeviceToAdapterMappingErrorListener.java | 2 +- .../common}/UnknownStatusProvider.java | 2 +- .../CacheBasedDeviceConnectionInfoTest.java | 2 +- ...CommonCacheQuarkusPropertyBindingTest.java | 38 +++ .../test/resources/common-cache-options.yaml | 0 .../src/test/resources/logback-test.xml | 36 +++ pom.xml | 2 + .../pom.xml | 63 +---- .../AdapterInstanceStatusService.java | 2 +- .../commandrouter/CommandConsumerFactory.java | 0 .../CommandRouterAmqpServer.java | 0 .../commandrouter/CommandRouterMetrics.java | 0 .../commandrouter/CommandRouterResult.java | 0 .../commandrouter/CommandRouterService.java | 0 .../CommandRouterServiceConfigProperties.java | 0 .../CommandRouterServiceOptions.java | 0 .../commandrouter/CommandTargetMapper.java | 2 +- .../MicrometerBasedCommandRouterMetrics.java | 0 .../app/AbstractApplication.java} | 22 +- .../commandrouter/app/MetricsFactory.java | 0 .../impl/AbstractCommandProcessingQueue.java | 0 ...actMappingAndDelegatingCommandHandler.java | 0 .../impl/CommandProcessingQueue.java | 0 .../impl/CommandRouterServiceImpl.java | 2 +- .../impl/CommandTargetMapperImpl.java | 2 +- .../DelegatingCommandRouterAmqpEndpoint.java | 0 ...etesBasedAdapterInstanceStatusService.java | 0 .../impl/UnknownStatusProvidingService.java | 0 ...ProtonBasedCommandConsumerFactoryImpl.java | 0 .../ProtonBasedCommandProcessingQueue.java | 0 ...sedMappingAndDelegatingCommandHandler.java | 0 .../InternalKafkaTopicCleanupService.java | 0 .../KafkaBasedCommandConsumerFactoryImpl.java | 0 ...sedMappingAndDelegatingCommandHandler.java | 0 .../kafka/KafkaCommandProcessingQueue.java | 0 ...PubSubBasedCommandConsumerFactoryImpl.java | 0 .../PubSubBasedCommandProcessingQueue.java | 0 ...sedMappingAndDelegatingCommandHandler.java | 0 .../native-image.properties | 0 .../main/resources/application-dev.properties | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/default_banner.txt | 0 .../impl/CommandRouterServiceImplTest.java | 2 +- ...legatingCommandRouterAmqpEndpointTest.java | 0 ...BasedAdapterInstanceStatusServiceTest.java | 0 ...appingAndDelegatingCommandHandlerTest.java | 0 .../InternalKafkaTopicCleanupServiceTest.java | 0 ...appingAndDelegatingCommandHandlerTest.java | 0 .../KafkaCommandProcessingQueueTest.java | 0 ...appingAndDelegatingCommandHandlerTest.java | 0 .../src/test/resources/application.yml | 0 services/command-router-infinispan/pom.xml | 93 ++++++++ .../infinispan/app/Application.java | 34 +++ ...finispanDeviceConnectionInfoProducer.java} | 38 +-- .../native-image.properties | 12 + .../main/resources/application-dev.properties | 29 +++ .../src/main/resources/application.properties | 2 + .../src/main/resources/default_banner.txt | 14 ++ .../src/test/resources/application.yml | 23 ++ services/command-router-redis/pom.xml | 100 ++++++++ .../commandrouter/redis/app/Application.java | 34 +++ .../RedisDeviceConnectionInfoProducer.java | 73 ++++++ .../redis/config/RedisConfigInterceptor.java | 23 ++ .../native-image.properties | 12 + ...io.smallrye.config.ConfigSourceInterceptor | 1 + .../main/resources/application-dev.properties | 29 +++ .../src/main/resources/application.properties | 2 + .../src/main/resources/default_banner.txt | 14 ++ .../src/test/resources/application.yml | 23 ++ services/pom.xml | 4 +- tests/pom.xml | 55 ++++- .../commandrouter/redis-cache/application.yml | 92 ++++++++ 91 files changed, 1469 insertions(+), 122 deletions(-) rename client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/{QuarkusPropertyBindingTest.java => RemoteCacheQuarkusPropertyBindingTest.java} (85%) create mode 100644 client-device-connection-redis/pom.xml create mode 100644 client-device-connection-redis/src/main/java/org/eclipse/hono/deviceconnection/redis/client/RedisCache.java create mode 100644 client-device-connection-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/client-device-connection-infinispan/native-image.properties create mode 100644 client-device-connection-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/client-device-connection-infinispan/resources-config.json create mode 100644 client-device-connection-redis/src/main/resources/application.properties create mode 100644 client-device-connection-redis/src/test/resources/logback-test.xml create mode 100644 client-device-connection-redis/src/test/resources/remote-cache-options.yaml create mode 100644 client-device-connection/pom.xml rename {client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common}/AdapterInstanceStatusProvider.java (97%) rename {client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common}/Cache.java (98%) rename {client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common}/CacheBasedDeviceConnectionInfo.java (99%) rename {client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common}/CommonCacheConfig.java (97%) rename {client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common}/CommonCacheOptions.java (95%) rename {client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common}/DeviceConnectionInfo.java (99%) rename {client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common}/DeviceToAdapterMappingErrorListener.java (95%) rename {client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common}/UnknownStatusProvider.java (94%) rename {client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client => client-device-connection/src/test/java/org/eclipse/hono/deviceconnection/common}/CacheBasedDeviceConnectionInfoTest.java (99%) create mode 100644 client-device-connection/src/test/java/org/eclipse/hono/deviceconnection/common/CommonCacheQuarkusPropertyBindingTest.java rename {client-device-connection-infinispan => client-device-connection}/src/test/resources/common-cache-options.yaml (100%) create mode 100644 client-device-connection/src/test/resources/logback-test.xml rename services/{command-router => command-router-base}/pom.xml (67%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/AdapterInstanceStatusService.java (90%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/CommandConsumerFactory.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/CommandRouterAmqpServer.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/CommandRouterMetrics.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/CommandRouterResult.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/CommandRouterService.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceConfigProperties.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceOptions.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/CommandTargetMapper.java (98%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/MicrometerBasedCommandRouterMetrics.java (100%) rename services/{command-router/src/main/java/org/eclipse/hono/commandrouter/app/Application.java => command-router-base/src/main/java/org/eclipse/hono/commandrouter/app/AbstractApplication.java} (97%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/app/MetricsFactory.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractCommandProcessingQueue.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractMappingAndDelegatingCommandHandler.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/CommandProcessingQueue.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImpl.java (99%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/CommandTargetMapperImpl.java (99%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpoint.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusService.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/UnknownStatusProvidingService.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandConsumerFactoryImpl.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandProcessingQueue.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandler.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupService.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedCommandConsumerFactoryImpl.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandler.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueue.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandConsumerFactoryImpl.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandProcessingQueue.java (100%) rename services/{command-router => command-router-base}/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandler.java (100%) rename services/{command-router => command-router-base}/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties (100%) rename services/{command-router => command-router-base}/src/main/resources/application-dev.properties (100%) rename services/{command-router => command-router-base}/src/main/resources/application.properties (100%) rename services/{command-router => command-router-base}/src/main/resources/default_banner.txt (100%) rename services/{command-router => command-router-base}/src/test/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImplTest.java (99%) rename services/{command-router => command-router-base}/src/test/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpointTest.java (100%) rename services/{command-router => command-router-base}/src/test/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusServiceTest.java (100%) rename services/{command-router => command-router-base}/src/test/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandlerTest.java (100%) rename services/{command-router => command-router-base}/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupServiceTest.java (100%) rename services/{command-router => command-router-base}/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandlerTest.java (100%) rename services/{command-router => command-router-base}/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueueTest.java (100%) rename services/{command-router => command-router-base}/src/test/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandlerTest.java (100%) rename services/{command-router => command-router-base}/src/test/resources/application.yml (100%) create mode 100644 services/command-router-infinispan/pom.xml create mode 100644 services/command-router-infinispan/src/main/java/org/eclipse/hono/commandrouter/infinispan/app/Application.java rename services/{command-router/src/main/java/org/eclipse/hono/commandrouter/app/DeviceConnectionInfoProducer.java => command-router-infinispan/src/main/java/org/eclipse/hono/commandrouter/infinispan/app/InfinispanDeviceConnectionInfoProducer.java} (82%) create mode 100644 services/command-router-infinispan/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties create mode 100644 services/command-router-infinispan/src/main/resources/application-dev.properties create mode 100644 services/command-router-infinispan/src/main/resources/application.properties create mode 100644 services/command-router-infinispan/src/main/resources/default_banner.txt create mode 100644 services/command-router-infinispan/src/test/resources/application.yml create mode 100644 services/command-router-redis/pom.xml create mode 100644 services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/app/Application.java create mode 100644 services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/app/RedisDeviceConnectionInfoProducer.java create mode 100644 services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/config/RedisConfigInterceptor.java create mode 100644 services/command-router-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties create mode 100644 services/command-router-redis/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor create mode 100644 services/command-router-redis/src/main/resources/application-dev.properties create mode 100644 services/command-router-redis/src/main/resources/application.properties create mode 100644 services/command-router-redis/src/main/resources/default_banner.txt create mode 100644 services/command-router-redis/src/test/resources/application.yml create mode 100644 tests/src/test/resources/commandrouter/redis-cache/application.yml diff --git a/bom/pom.xml b/bom/pom.xml index 919647b523..9f49595e41 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -427,7 +427,22 @@ quarkus.vertx.max-event-loop-execute-time=${max.event-loop.execute-time:20000} org.eclipse.hono - hono-service-command-router + hono-service-command-router-base + ${project.version} + + + org.eclipse.hono + hono-service-command-router-infinispan + ${project.version} + + + org.eclipse.hono + hono-service-command-router-redis + ${project.version} + + + org.eclipse.hono + client-device-connection ${project.version} @@ -435,6 +450,11 @@ quarkus.vertx.max-event-loop-execute-time=${max.event-loop.execute-time:20000} client-device-connection-infinispan ${project.version} + + org.eclipse.hono + client-device-connection-redis + ${project.version} + org.eclipse.hono hono-client-application diff --git a/client-device-connection-infinispan/pom.xml b/client-device-connection-infinispan/pom.xml index b24f28db0b..6b0c0a4582 100644 --- a/client-device-connection-infinispan/pom.xml +++ b/client-device-connection-infinispan/pom.xml @@ -34,6 +34,7 @@ org.slf4j slf4j-api + org.infinispan infinispan-core-jakarta @@ -59,18 +60,30 @@ + + + org.eclipse.hono + hono-core + + + org.eclipse.hono + client-device-connection + org.eclipse.hono hono-client-common + io.vertx - vertx-web + vertx-core + com.google.guava guava + io.quarkus quarkus-core diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/BasicCache.java b/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/BasicCache.java index 9373aae86f..3fdaa5ce77 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/BasicCache.java +++ b/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/BasicCache.java @@ -24,6 +24,7 @@ import java.util.function.Function; import org.eclipse.hono.client.ServerErrorException; +import org.eclipse.hono.deviceconnection.common.Cache; import org.eclipse.hono.util.Futures; import org.eclipse.hono.util.Lifecycle; import org.infinispan.commons.api.BasicCacheContainer; diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/HotrodCache.java b/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/HotrodCache.java index 4e3b3ea9b1..693a5e7904 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/HotrodCache.java +++ b/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/HotrodCache.java @@ -18,6 +18,7 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; +import org.eclipse.hono.deviceconnection.common.CommonCacheConfig; import org.infinispan.client.hotrod.RemoteCache; import org.infinispan.client.hotrod.RemoteCacheContainer; import org.infinispan.client.hotrod.RemoteCacheManager; @@ -174,7 +175,6 @@ protected void postCacheAccess(final AsyncResult cacheOperationResult) { */ @Override public Future checkForCacheAvailability() { - if (isStarted()) { final ConnectionCheckResult lastResult = lastConnectionCheckResult; if (lastResult != null && !lastResult.isOlderThan(CACHED_CONNECTION_CHECK_RESULT_MAX_AGE)) { diff --git a/client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/QuarkusPropertyBindingTest.java b/client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/RemoteCacheQuarkusPropertyBindingTest.java similarity index 85% rename from client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/QuarkusPropertyBindingTest.java rename to client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/RemoteCacheQuarkusPropertyBindingTest.java index 53fe74cf6a..fe52d57ff5 100644 --- a/client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/QuarkusPropertyBindingTest.java +++ b/client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/RemoteCacheQuarkusPropertyBindingTest.java @@ -25,24 +25,10 @@ import org.junit.jupiter.api.Test; /** - * Tests verifying binding of configuration properties to {@link CommonCacheConfig} and - * {@link InfinispanRemoteConfigurationProperties}. + * Tests verifying binding of configuration properties to {@link InfinispanRemoteConfigurationProperties}. * */ -public class QuarkusPropertyBindingTest { - - @Test - void testCommonCacheConfigurationPropertiesArePickedUp() { - - final var commonCacheConfig = new CommonCacheConfig( - ConfigMappingSupport.getConfigMapping( - CommonCacheOptions.class, - this.getClass().getResource("/common-cache-options.yaml"))); - - assertThat(commonCacheConfig.getCacheName()).isEqualTo("the-cache"); - assertThat(commonCacheConfig.getCheckKey()).isEqualTo("the-key"); - assertThat(commonCacheConfig.getCheckValue()).isEqualTo("the-value"); - } +public class RemoteCacheQuarkusPropertyBindingTest { @SuppressWarnings("deprecation") @Test diff --git a/client-device-connection-redis/pom.xml b/client-device-connection-redis/pom.xml new file mode 100644 index 0000000000..8f9f22aa69 --- /dev/null +++ b/client-device-connection-redis/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + + org.eclipse.hono + hono-bom + 2.6.0-SNAPSHOT + ../bom + + client-device-connection-redis + + Redis Device Connection client + A Redis based client for accessing device connection information in a Redis cluster. + + + + org.eclipse.hono + client-device-connection + + + + io.quarkus + quarkus-redis-client + + + + org.eclipse.hono + hono-legal + + + org.eclipse.hono + hono-core + + + + org.slf4j + slf4j-api + + + + + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + com.google.truth + truth + test + + + ch.qos.logback + logback-classic + test + + + org.mockito + mockito-core + test + + + io.vertx + vertx-junit5 + test + + + org.eclipse.hono + core-test-utils + test + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + org.jboss.jandex + jandex-maven-plugin + + + org.jacoco + jacoco-maven-plugin + + + + diff --git a/client-device-connection-redis/src/main/java/org/eclipse/hono/deviceconnection/redis/client/RedisCache.java b/client-device-connection-redis/src/main/java/org/eclipse/hono/deviceconnection/redis/client/RedisCache.java new file mode 100644 index 0000000000..4346f6825f --- /dev/null +++ b/client-device-connection-redis/src/main/java/org/eclipse/hono/deviceconnection/redis/client/RedisCache.java @@ -0,0 +1,217 @@ +/** + * Copyright (c) 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package org.eclipse.hono.deviceconnection.redis.client; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.eclipse.hono.deviceconnection.common.Cache; +import org.eclipse.hono.util.Lifecycle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.vertx.core.Future; +import io.vertx.core.json.JsonObject; +import io.vertx.redis.client.Redis; +import io.vertx.redis.client.RedisAPI; +import io.vertx.redis.client.Response; + +/** + * TODO. + */ +public class RedisCache implements Cache, Lifecycle { + + private static final Logger LOG = LoggerFactory.getLogger(RedisCache.class); + + private final RedisAPI api; + + /** + * TODO. + * + * @param redis TODO. + */ + private RedisCache(final Redis redis) { + Objects.requireNonNull(redis); + this.api = RedisAPI.api(redis); + } + + /** + * TODO. + * + * @param api TODO. + */ + private RedisCache(final RedisAPI api) { + Objects.requireNonNull(api); + this.api = api; + } + + /** + * TODO. + * + * @param api TODO. + * @return TODO. + */ + public static RedisCache from(final RedisAPI api) { + Objects.requireNonNull(api); + return new RedisCache(api); + } + + @Override + public Future start() { + LOG.info("VREDIS: start()"); + return checkForCacheAvailability().mapEmpty(); + } + + @Override + public Future stop() { + LOG.info("VREDIS: stop()"); + api.close(); + return Future.succeededFuture(); + } + + @Override + public Future checkForCacheAvailability() { + LOG.info("VREDIS: checkForCacheAvailability()"); + Objects.requireNonNull(api); + + return api.ping(List.of()) + .map(new JsonObject()); + } + + @Override + public Future put(final String key, final String value) { + LOG.info("VREDIS: put {}={}", key, value); + Objects.requireNonNull(api); + + return api.set(List.of(String.valueOf(key), String.valueOf(value))) + .mapEmpty(); + } + + @Override + public Future put(final String key, final String value, final long lifespan, final TimeUnit lifespanUnit) { + LOG.info("VREDIS: put {}={} ({} {})", key, value, lifespan, lifespanUnit); + Objects.requireNonNull(api); + + final List params = new ArrayList<>(List.of(key, value)); + final long millis = lifespanUnit.toMillis(lifespan); + if (millis > 0) { + params.addAll(List.of("PX", String.valueOf(millis))); + } + return api.set(params) + .mapEmpty(); + } + + @Override + public Future putAll(final Map data) { + LOG.info("VREDIS: putAll ({})", data.size()); + Objects.requireNonNull(api); + + final List keyValues = new ArrayList<>(data.size() * 2); + data.forEach((k, v) -> { + keyValues.add(k); + keyValues.add(v); + }); + return api.mset(keyValues) + .mapEmpty(); + } + + @Override + public Future putAll(final Map data, final long lifespan, + final TimeUnit lifespanUnit) { + LOG.info("VREDIS: putAll ({}) ({} {})", data.size(), lifespan, lifespanUnit); + Objects.requireNonNull(api); + + final long millis = lifespanUnit.toMillis(lifespan); + return api.multi() + .compose(ignored -> { + final List> futures = new ArrayList<>(data.size()); + data.forEach((k, v) -> { + final List params = new ArrayList<>(List.of(String.valueOf(k), String.valueOf(v))); + if (millis > 0) { + params.addAll(List.of("PX", String.valueOf(millis))); + } + futures.add(api.set(params)); + }); + return Future.all(Collections.unmodifiableList(futures)); + }) + .compose(ignored -> api.exec()) + // null reply means transaction aborted + .map(Objects::nonNull) + .mapEmpty(); + } + + @Override + public Future get(final String key) { + LOG.info("VREDIS: get {}", key); + Objects.requireNonNull(api); + + return api.get(String.valueOf(key)) + .compose(value -> Future.succeededFuture(String.valueOf(value))); + } + + @Override + public Future remove(final String key, final String value) { + LOG.info("VREDIS: remove {}={}", key, value); + Objects.requireNonNull(api); + + return api.watch(List.of(String.valueOf(key))) + .compose(ignored -> api.get(String.valueOf(key))) + .compose(response -> { + if (response == null) { + // key does not exist + return Future.succeededFuture(false); + } + if (String.valueOf(response).equals(value)) { + return api.multi() + .compose(ignored -> api.del(List.of(String.valueOf(key)))) + .compose(ignored -> api.exec()) + // null reply means transaction aborted + .map(Objects::nonNull); + } else { + return Future.succeededFuture(false); + } + }); + } + + @Override + public Future> getAll(final Set keys) { + LOG.info("VREDIS: getAll ({})", keys.size()); + Objects.requireNonNull(api); + + final LinkedList keyList = new LinkedList<>(keys.stream().map(String::valueOf).toList()); + final Map result = new HashMap<>(keyList.size()); + return api.mget(keyList) + .compose(values -> { + values.forEach(i -> { + try { + if (i != null) { // TODO: this is kinda strange but some results are null and the BasicCache does not include those in the returned result. Ask about/investigate. + result.put(keyList.removeFirst(), i.toString()); + } else { + keyList.removeFirst(); + } + } catch (Exception e) { + LOG.info(" - got exception {}", e.getMessage()); + } + }); + return Future.succeededFuture(result); + }); + } +} diff --git a/client-device-connection-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/client-device-connection-infinispan/native-image.properties b/client-device-connection-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/client-device-connection-infinispan/native-image.properties new file mode 100644 index 0000000000..2879f33e15 --- /dev/null +++ b/client-device-connection-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/client-device-connection-infinispan/native-image.properties @@ -0,0 +1,15 @@ +# Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0 +# +# SPDX-License-Identifier: EPL-2.0 +Args = -H:ResourceConfigurationResources=${.}/resources-config.json \ + -H:AdditionalSecurityProviders=org.wildfly.security.sasl.digest.WildFlyElytronSaslDigestProvider \ + -H:AdditionalSecurityProviders=org.wildfly.security.sasl.external.WildFlyElytronSaslExternalProvider \ + -H:AdditionalSecurityProviders=org.wildfly.security.sasl.plain.WildFlyElytronSaslPlainProvider \ + -H:AdditionalSecurityProviders=org.wildfly.security.sasl.scram.WildFlyElytronSaslScramProvider diff --git a/client-device-connection-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/client-device-connection-infinispan/resources-config.json b/client-device-connection-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/client-device-connection-infinispan/resources-config.json new file mode 100644 index 0000000000..ef9f0db4ab --- /dev/null +++ b/client-device-connection-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/client-device-connection-infinispan/resources-config.json @@ -0,0 +1,37 @@ +{ + "resources": { + "includes": [ + { + "pattern": ".*\\.properties$" + }, + { + "pattern": ".*\\.proto$" + }, + { + "pattern": "default-configs\\/.*$" + }, + { + "pattern": "META-INF\\/services\\/java\\.security\\.Provider" + }, + { + "pattern": "META-INF\\/services\\/javax\\.security\\.sasl\\.SaslClientFactory" + }, + { + "pattern": "META-INF\\/services\\/org\\.infinispan\\.configuration\\.parsing\\.ConfigurationParser" + }, + { + "pattern": "META-INF\\/services\\/org\\.infinispan\\.factories\\.impl\\..*$" + }, + { + "pattern": "META-INF\\/services\\/org\\.infinispan\\.protostream\\..*$" + } + ], + "excludes": [ + { + "pattern": "META-INF\\/maven\\/.*$" + },{ + "pattern": "META-INF\\/native-image\\/.*$" + } + ] + } +} diff --git a/client-device-connection-redis/src/main/resources/application.properties b/client-device-connection-redis/src/main/resources/application.properties new file mode 100644 index 0000000000..7fce6fc1be --- /dev/null +++ b/client-device-connection-redis/src/main/resources/application.properties @@ -0,0 +1,11 @@ +# Create a Jandex index of beans contained in Google Guava +# This prevents warnings when building downstream modules that use for example +# the com.google.common.base.MoreObjects$ToStringHelper method. +quarkus.index-dependency.guava.group-id=com.google.guava +quarkus.index-dependency.guava.artifact-id=guava +# Create a Jandex index of beans contained in the Infinispan Hotrod client +# This is necessary in order to be able to configure the Hotrod client by +# means of the org.eclipse.hono.deviceconnection.infinispan.client.InfinispanRemoteConfigurationOptions +# class. +quarkus.index-dependency.infinispan.group-id=org.infinispan +quarkus.index-dependency.infinispan.artifact-id=infinispan-client-hotrod diff --git a/client-device-connection-redis/src/test/resources/logback-test.xml b/client-device-connection-redis/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..fb0c54d42d --- /dev/null +++ b/client-device-connection-redis/src/test/resources/logback-test.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + diff --git a/client-device-connection-redis/src/test/resources/remote-cache-options.yaml b/client-device-connection-redis/src/test/resources/remote-cache-options.yaml new file mode 100644 index 0000000000..19b061cf42 --- /dev/null +++ b/client-device-connection-redis/src/test/resources/remote-cache-options.yaml @@ -0,0 +1,34 @@ +hono: + cache: + infinispan: + serverList: "data-grid:11222" + authServerName: "data-grid" + authUsername: "user" + authPassword: "secret" + authRealm: "ApplicationRealm" + cluster: + siteA: "hostA1:11222; hostA2:11223" + siteB: "hostB1:11222; hostB2:11223" + connectionPool: + minIdle: 10 + maxActive: 10 + maxPendingRequests: 400 + maxWait: 500 + defaultExecutorFactory: + poolSize: 200 + saslMechanism: "DIGEST-MD5" + saslProperties: + "javax.security.sasl.qop": "auth" + socketTimeout: 5000 + connectTimeout: 5000 + keyStoreFileName: "/etc/hono/key-store.p12" + keyStoreType: "PKCS12" + keyStorePassword: "key-store-secret" + keyAlias: "infinispan" + keyStoreCertificatePassword: "cert-secret" + trustStorePath: "/etc/hono/trust-store.p12" + trustStoreFileName: "/etc/hono/trust-store-file.p12" + trustStoreType: "PKCS12" + trustStorePassword: "trust-store-secret" + useSsl: true + sslCiphers: "TLS_AES_128_GCM_SHA256 TLS_AES_256_GCM_SHA384 TLS_CHACHA20_POLY1305_SHA256" diff --git a/client-device-connection/pom.xml b/client-device-connection/pom.xml new file mode 100644 index 0000000000..6a3848e74f --- /dev/null +++ b/client-device-connection/pom.xml @@ -0,0 +1,164 @@ + + + + 4.0.0 + + org.eclipse.hono + hono-bom + 2.6.0-SNAPSHOT + ../bom + + client-device-connection + + Device Connection client + Base classes for client for accessing device connection information in a remote cache / data grid. + + + + org.eclipse.hono + hono-legal + + + org.eclipse.hono + hono-core + + + org.eclipse.hono + hono-client-common + + + + org.slf4j + slf4j-api + + + io.opentracing + opentracing-api + + + + io.smallrye.config + smallrye-config-core + + + + io.vertx + vertx-core + + + + io.vertx + vertx-health-check + + + + com.google.guava + guava + + + io.quarkus + quarkus-core + true + + + org.jboss.logmanager + jboss-logmanager-embedded + + + org.jboss.logging + jboss-logging-annotations + + + io.quarkus + quarkus-development-mode-spi + + + io.quarkus + quarkus-bootstrap-runner + + + org.jboss.slf4j + slf4j-jboss-logmanager + + + org.graalvm.sdk + graal-sdk + + + io.quarkus + quarkus-fs-util + + + + + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + com.google.truth + truth + test + + + ch.qos.logback + logback-classic + test + + + org.mockito + mockito-core + test + + + io.vertx + vertx-junit5 + test + + + org.eclipse.hono + core-test-utils + test + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + org.jboss.jandex + jandex-maven-plugin + + + org.jacoco + jacoco-maven-plugin + + + + diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/AdapterInstanceStatusProvider.java b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/AdapterInstanceStatusProvider.java similarity index 97% rename from client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/AdapterInstanceStatusProvider.java rename to client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/AdapterInstanceStatusProvider.java index 2c98c8a2c0..64a18cf0f6 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/AdapterInstanceStatusProvider.java +++ b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/AdapterInstanceStatusProvider.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import java.util.Collection; import java.util.Set; diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/Cache.java b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/Cache.java similarity index 98% rename from client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/Cache.java rename to client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/Cache.java index eec68f8f7c..42d28a015c 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/Cache.java +++ b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/Cache.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import java.util.Map; import java.util.Set; diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CacheBasedDeviceConnectionInfo.java b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CacheBasedDeviceConnectionInfo.java similarity index 99% rename from client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CacheBasedDeviceConnectionInfo.java rename to client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CacheBasedDeviceConnectionInfo.java index 21f3bd28a7..caa3e24172 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CacheBasedDeviceConnectionInfo.java +++ b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CacheBasedDeviceConnectionInfo.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import java.net.HttpURLConnection; import java.time.Duration; diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CommonCacheConfig.java b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CommonCacheConfig.java similarity index 97% rename from client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CommonCacheConfig.java rename to client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CommonCacheConfig.java index ec4109424c..c969ab3c49 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CommonCacheConfig.java +++ b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CommonCacheConfig.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import com.google.common.base.MoreObjects; diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CommonCacheOptions.java b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CommonCacheOptions.java similarity index 95% rename from client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CommonCacheOptions.java rename to client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CommonCacheOptions.java index 8118a198f5..bbd69c036d 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/CommonCacheOptions.java +++ b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/CommonCacheOptions.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import org.eclipse.hono.util.CommandRouterConstants; diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/DeviceConnectionInfo.java b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/DeviceConnectionInfo.java similarity index 99% rename from client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/DeviceConnectionInfo.java rename to client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/DeviceConnectionInfo.java index 4b7e800298..f3c2d2a35c 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/DeviceConnectionInfo.java +++ b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/DeviceConnectionInfo.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import java.time.Duration; import java.util.Map; diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/DeviceToAdapterMappingErrorListener.java b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/DeviceToAdapterMappingErrorListener.java similarity index 95% rename from client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/DeviceToAdapterMappingErrorListener.java rename to client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/DeviceToAdapterMappingErrorListener.java index bdb45e069b..0fa4d7fb95 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/DeviceToAdapterMappingErrorListener.java +++ b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/DeviceToAdapterMappingErrorListener.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import io.opentracing.Span; import io.vertx.core.Future; diff --git a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/UnknownStatusProvider.java b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/UnknownStatusProvider.java similarity index 94% rename from client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/UnknownStatusProvider.java rename to client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/UnknownStatusProvider.java index d52468ce44..861ecfda79 100644 --- a/client-device-connection-infinispan/src/main/java/org/eclipse/hono/deviceconnection/infinispan/client/UnknownStatusProvider.java +++ b/client-device-connection/src/main/java/org/eclipse/hono/deviceconnection/common/UnknownStatusProvider.java @@ -12,7 +12,7 @@ */ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import java.util.Collection; import java.util.Set; diff --git a/client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/CacheBasedDeviceConnectionInfoTest.java b/client-device-connection/src/test/java/org/eclipse/hono/deviceconnection/common/CacheBasedDeviceConnectionInfoTest.java similarity index 99% rename from client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/CacheBasedDeviceConnectionInfoTest.java rename to client-device-connection/src/test/java/org/eclipse/hono/deviceconnection/common/CacheBasedDeviceConnectionInfoTest.java index 744858a2be..a6efb9126d 100644 --- a/client-device-connection-infinispan/src/test/java/org/eclipse/hono/deviceconnection/infinispan/client/CacheBasedDeviceConnectionInfoTest.java +++ b/client-device-connection/src/test/java/org/eclipse/hono/deviceconnection/common/CacheBasedDeviceConnectionInfoTest.java @@ -11,7 +11,7 @@ * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hono.deviceconnection.infinispan.client; +package org.eclipse.hono.deviceconnection.common; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/client-device-connection/src/test/java/org/eclipse/hono/deviceconnection/common/CommonCacheQuarkusPropertyBindingTest.java b/client-device-connection/src/test/java/org/eclipse/hono/deviceconnection/common/CommonCacheQuarkusPropertyBindingTest.java new file mode 100644 index 0000000000..753711f531 --- /dev/null +++ b/client-device-connection/src/test/java/org/eclipse/hono/deviceconnection/common/CommonCacheQuarkusPropertyBindingTest.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ + +package org.eclipse.hono.deviceconnection.common; + +import static com.google.common.truth.Truth.assertThat; + +import org.eclipse.hono.test.ConfigMappingSupport; +import org.junit.jupiter.api.Test; + +/** + * Tests verifying binding of configuration properties to {@link CommonCacheConfig}. + * + */ +public class CommonCacheQuarkusPropertyBindingTest { + + @Test + void testCommonCacheConfigurationPropertiesArePickedUp() { + final var commonCacheConfig = new CommonCacheConfig( + ConfigMappingSupport.getConfigMapping( + CommonCacheOptions.class, + this.getClass().getResource("/common-cache-options.yaml"))); + + assertThat(commonCacheConfig.getCacheName()).isEqualTo("the-cache"); + assertThat(commonCacheConfig.getCheckKey()).isEqualTo("the-key"); + assertThat(commonCacheConfig.getCheckValue()).isEqualTo("the-value"); + } +} diff --git a/client-device-connection-infinispan/src/test/resources/common-cache-options.yaml b/client-device-connection/src/test/resources/common-cache-options.yaml similarity index 100% rename from client-device-connection-infinispan/src/test/resources/common-cache-options.yaml rename to client-device-connection/src/test/resources/common-cache-options.yaml diff --git a/client-device-connection/src/test/resources/logback-test.xml b/client-device-connection/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..42747dae3b --- /dev/null +++ b/client-device-connection/src/test/resources/logback-test.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index fdcafbacd4..56facc63da 100644 --- a/pom.xml +++ b/pom.xml @@ -178,7 +178,9 @@ bom core cli + client-device-connection client-device-connection-infinispan + client-device-connection-redis clients demo-certs examples diff --git a/services/command-router/pom.xml b/services/command-router-base/pom.xml similarity index 67% rename from services/command-router/pom.xml rename to services/command-router-base/pom.xml index aeaa5a4738..17e8cba98b 100644 --- a/services/command-router/pom.xml +++ b/services/command-router-base/pom.xml @@ -19,15 +19,16 @@ 2.6.0-SNAPSHOT ../parent - hono-service-command-router - Hono Command Router - A Quarkus based implementation of Hono's Command Router API that is using Infinispan for storing data. + hono-service-command-router-base + Hono Service Command Router Base + Base classes for implementing a Hono Command Router org.eclipse.hono - client-device-connection-infinispan + client-device-connection + org.eclipse.hono hono-client-command-amqp @@ -104,58 +105,4 @@ - - - - - io.fabric8 - docker-maven-plugin - - - - - - Command Router - - - 5671 - 5672 - ${health.check.port} - - - - - - - - - - - - - - build-docker-image - - - - io.fabric8 - docker-maven-plugin - - - - - - - build-native-image - - - - io.fabric8 - docker-maven-plugin - - - - - - diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/AdapterInstanceStatusService.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/AdapterInstanceStatusService.java similarity index 90% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/AdapterInstanceStatusService.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/AdapterInstanceStatusService.java index bf3dec738a..16eb5653df 100644 --- a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/AdapterInstanceStatusService.java +++ b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/AdapterInstanceStatusService.java @@ -13,7 +13,7 @@ package org.eclipse.hono.commandrouter; -import org.eclipse.hono.deviceconnection.infinispan.client.AdapterInstanceStatusProvider; +import org.eclipse.hono.deviceconnection.common.AdapterInstanceStatusProvider; import org.eclipse.hono.util.Lifecycle; /** diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandConsumerFactory.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandConsumerFactory.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandConsumerFactory.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandConsumerFactory.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterAmqpServer.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterAmqpServer.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterAmqpServer.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterAmqpServer.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterMetrics.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterMetrics.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterMetrics.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterMetrics.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterResult.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterResult.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterResult.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterResult.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterService.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterService.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterService.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterService.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceConfigProperties.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceConfigProperties.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceConfigProperties.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceConfigProperties.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceOptions.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceOptions.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceOptions.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandRouterServiceOptions.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandTargetMapper.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandTargetMapper.java similarity index 98% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandTargetMapper.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandTargetMapper.java index d39fc6eb45..482efeb4da 100644 --- a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/CommandTargetMapper.java +++ b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/CommandTargetMapper.java @@ -15,7 +15,7 @@ import org.eclipse.hono.client.registry.DeviceRegistrationClient; import org.eclipse.hono.commandrouter.impl.CommandTargetMapperImpl; -import org.eclipse.hono.deviceconnection.infinispan.client.DeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; import io.opentracing.SpanContext; import io.opentracing.Tracer; diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/MicrometerBasedCommandRouterMetrics.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/MicrometerBasedCommandRouterMetrics.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/MicrometerBasedCommandRouterMetrics.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/MicrometerBasedCommandRouterMetrics.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/app/Application.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/app/AbstractApplication.java similarity index 97% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/app/Application.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/app/AbstractApplication.java index 81c1309fb8..c60be69e52 100644 --- a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/app/Application.java +++ b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/app/AbstractApplication.java @@ -61,7 +61,7 @@ import org.eclipse.hono.commandrouter.impl.pubsub.PubSubBasedCommandConsumerFactoryImpl; import org.eclipse.hono.config.ServiceConfigProperties; import org.eclipse.hono.config.ServiceOptions; -import org.eclipse.hono.deviceconnection.infinispan.client.DeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; import org.eclipse.hono.service.HealthCheckProvider; import org.eclipse.hono.service.NotificationSupportingServiceApplication; import org.eclipse.hono.service.amqp.AmqpEndpoint; @@ -86,20 +86,18 @@ import io.vertx.core.buffer.Buffer; import io.vertx.ext.healthchecks.HealthCheckHandler; import io.vertx.proton.sasl.ProtonSaslAuthenticatorFactory; -import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; /** * The Quarkus based Command Router main application class. */ -@ApplicationScoped -public class Application extends NotificationSupportingServiceApplication { +public abstract class AbstractApplication extends NotificationSupportingServiceApplication { private static final String COMPONENT_NAME = "Hono Command Router"; - private static final Logger LOG = LoggerFactory.getLogger(Application.class); + private static final Logger LOG = LoggerFactory.getLogger(AbstractApplication.class); - @Inject - DeviceConnectionInfo deviceConnectionInfo; + //@Inject + //DeviceConnectionInfo deviceConnectionInfo; @Inject ProtonSaslAuthenticatorFactory saslAuthenticatorFactory; @@ -349,16 +347,22 @@ public void registerReadinessChecks(final HealthCheckHandler handler) { return endpoint; } + /** + * TODO. + * @return TODO. + */ + protected abstract DeviceConnectionInfo getDeviceConnectionInfo(); + private CommandRouterService commandRouterService() { final DeviceRegistrationClient registrationClient = registrationClient(); final TenantClient tenantClient = tenantClient(); - final var commandTargetMapper = CommandTargetMapper.create(registrationClient, deviceConnectionInfo, tracer); + final var commandTargetMapper = CommandTargetMapper.create(registrationClient, getDeviceConnectionInfo(), tracer); return new CommandRouterServiceImpl( amqpServerProperties, registrationClient, tenantClient, - deviceConnectionInfo, + getDeviceConnectionInfo(), commandConsumerFactoryProvider(tenantClient, commandTargetMapper), eventSenderProvider(), adapterInstanceStatusService, diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/app/MetricsFactory.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/app/MetricsFactory.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/app/MetricsFactory.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/app/MetricsFactory.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractCommandProcessingQueue.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractCommandProcessingQueue.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractCommandProcessingQueue.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractCommandProcessingQueue.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractMappingAndDelegatingCommandHandler.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractMappingAndDelegatingCommandHandler.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractMappingAndDelegatingCommandHandler.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/AbstractMappingAndDelegatingCommandHandler.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/CommandProcessingQueue.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/CommandProcessingQueue.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/CommandProcessingQueue.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/CommandProcessingQueue.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImpl.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImpl.java similarity index 99% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImpl.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImpl.java index 6d53adac9f..713ff373d6 100644 --- a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImpl.java +++ b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImpl.java @@ -38,7 +38,7 @@ import org.eclipse.hono.commandrouter.CommandRouterResult; import org.eclipse.hono.commandrouter.CommandRouterService; import org.eclipse.hono.config.ServiceConfigProperties; -import org.eclipse.hono.deviceconnection.infinispan.client.DeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; import org.eclipse.hono.service.HealthCheckProvider; import org.eclipse.hono.tracing.TracingHelper; import org.eclipse.hono.util.CommandConstants; diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/CommandTargetMapperImpl.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/CommandTargetMapperImpl.java similarity index 99% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/CommandTargetMapperImpl.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/CommandTargetMapperImpl.java index 17e60de2a5..1f4a863fc6 100644 --- a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/CommandTargetMapperImpl.java +++ b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/CommandTargetMapperImpl.java @@ -23,7 +23,7 @@ import org.eclipse.hono.client.registry.DeviceDisabledOrNotRegisteredException; import org.eclipse.hono.client.registry.DeviceRegistrationClient; import org.eclipse.hono.commandrouter.CommandTargetMapper; -import org.eclipse.hono.deviceconnection.infinispan.client.DeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; import org.eclipse.hono.tracing.TracingHelper; import org.eclipse.hono.util.DeviceConnectionConstants; import org.eclipse.hono.util.MessageHelper; diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpoint.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpoint.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpoint.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpoint.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusService.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusService.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusService.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusService.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/UnknownStatusProvidingService.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/UnknownStatusProvidingService.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/UnknownStatusProvidingService.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/UnknownStatusProvidingService.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandConsumerFactoryImpl.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandConsumerFactoryImpl.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandConsumerFactoryImpl.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandConsumerFactoryImpl.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandProcessingQueue.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandProcessingQueue.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandProcessingQueue.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedCommandProcessingQueue.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandler.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandler.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandler.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandler.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupService.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupService.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupService.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupService.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedCommandConsumerFactoryImpl.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedCommandConsumerFactoryImpl.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedCommandConsumerFactoryImpl.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedCommandConsumerFactoryImpl.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandler.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandler.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandler.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandler.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueue.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueue.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueue.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueue.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandConsumerFactoryImpl.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandConsumerFactoryImpl.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandConsumerFactoryImpl.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandConsumerFactoryImpl.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandProcessingQueue.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandProcessingQueue.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandProcessingQueue.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedCommandProcessingQueue.java diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandler.java b/services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandler.java similarity index 100% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandler.java rename to services/command-router-base/src/main/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandler.java diff --git a/services/command-router/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties b/services/command-router-base/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties similarity index 100% rename from services/command-router/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties rename to services/command-router-base/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties diff --git a/services/command-router/src/main/resources/application-dev.properties b/services/command-router-base/src/main/resources/application-dev.properties similarity index 100% rename from services/command-router/src/main/resources/application-dev.properties rename to services/command-router-base/src/main/resources/application-dev.properties diff --git a/services/command-router/src/main/resources/application.properties b/services/command-router-base/src/main/resources/application.properties similarity index 100% rename from services/command-router/src/main/resources/application.properties rename to services/command-router-base/src/main/resources/application.properties diff --git a/services/command-router/src/main/resources/default_banner.txt b/services/command-router-base/src/main/resources/default_banner.txt similarity index 100% rename from services/command-router/src/main/resources/default_banner.txt rename to services/command-router-base/src/main/resources/default_banner.txt diff --git a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImplTest.java b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImplTest.java similarity index 99% rename from services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImplTest.java rename to services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImplTest.java index 929d2bf701..5fa82469be 100644 --- a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImplTest.java +++ b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/CommandRouterServiceImplTest.java @@ -41,7 +41,7 @@ import org.eclipse.hono.client.util.MessagingClientProvider; import org.eclipse.hono.commandrouter.CommandConsumerFactory; import org.eclipse.hono.config.ServiceConfigProperties; -import org.eclipse.hono.deviceconnection.infinispan.client.DeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; import org.eclipse.hono.test.VertxMockSupport; import org.eclipse.hono.util.CommandConstants; import org.eclipse.hono.util.EventConstants; diff --git a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpointTest.java b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpointTest.java similarity index 100% rename from services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpointTest.java rename to services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/DelegatingCommandRouterAmqpEndpointTest.java diff --git a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusServiceTest.java b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusServiceTest.java similarity index 100% rename from services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusServiceTest.java rename to services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/KubernetesBasedAdapterInstanceStatusServiceTest.java diff --git a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandlerTest.java b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandlerTest.java similarity index 100% rename from services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandlerTest.java rename to services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/amqp/ProtonBasedMappingAndDelegatingCommandHandlerTest.java diff --git a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupServiceTest.java b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupServiceTest.java similarity index 100% rename from services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupServiceTest.java rename to services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/InternalKafkaTopicCleanupServiceTest.java diff --git a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandlerTest.java b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandlerTest.java similarity index 100% rename from services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandlerTest.java rename to services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaBasedMappingAndDelegatingCommandHandlerTest.java diff --git a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueueTest.java b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueueTest.java similarity index 100% rename from services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueueTest.java rename to services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/kafka/KafkaCommandProcessingQueueTest.java diff --git a/services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandlerTest.java b/services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandlerTest.java similarity index 100% rename from services/command-router/src/test/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandlerTest.java rename to services/command-router-base/src/test/java/org/eclipse/hono/commandrouter/impl/pubsub/PubSubBasedMappingAndDelegatingCommandHandlerTest.java diff --git a/services/command-router/src/test/resources/application.yml b/services/command-router-base/src/test/resources/application.yml similarity index 100% rename from services/command-router/src/test/resources/application.yml rename to services/command-router-base/src/test/resources/application.yml diff --git a/services/command-router-infinispan/pom.xml b/services/command-router-infinispan/pom.xml new file mode 100644 index 0000000000..1122afe232 --- /dev/null +++ b/services/command-router-infinispan/pom.xml @@ -0,0 +1,93 @@ + + + 4.0.0 + + org.eclipse.hono + hono-services-parent + 2.6.0-SNAPSHOT + ../parent + + hono-service-command-router-infinispan + Hono Command Router Infinispan + A Quarkus based implementation of Hono's Command Router API that is using Infinispan for storing data. + + + + org.eclipse.hono + hono-service-command-router-base + + + + org.eclipse.hono + client-device-connection-infinispan + + + + + + + + + io.fabric8 + docker-maven-plugin + + + + + + Command Router + + + 5671 + 5672 + ${health.check.port} + + + + + + + + + + + + + + build-docker-image + + + + io.fabric8 + docker-maven-plugin + + + + + + + build-native-image + + + + io.fabric8 + docker-maven-plugin + + + + + + + diff --git a/services/command-router-infinispan/src/main/java/org/eclipse/hono/commandrouter/infinispan/app/Application.java b/services/command-router-infinispan/src/main/java/org/eclipse/hono/commandrouter/infinispan/app/Application.java new file mode 100644 index 0000000000..c62cc3c59f --- /dev/null +++ b/services/command-router-infinispan/src/main/java/org/eclipse/hono/commandrouter/infinispan/app/Application.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.hono.commandrouter.infinispan.app; + +import org.eclipse.hono.commandrouter.app.AbstractApplication; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +/** + * The Quarkus based Command Router main application class (Infinispan variant). + */ +@ApplicationScoped +public class Application extends AbstractApplication { + + @Inject + DeviceConnectionInfo deviceConnectionInfo; + + @Override + protected DeviceConnectionInfo getDeviceConnectionInfo() { + return deviceConnectionInfo; + } +} diff --git a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/app/DeviceConnectionInfoProducer.java b/services/command-router-infinispan/src/main/java/org/eclipse/hono/commandrouter/infinispan/app/InfinispanDeviceConnectionInfoProducer.java similarity index 82% rename from services/command-router/src/main/java/org/eclipse/hono/commandrouter/app/DeviceConnectionInfoProducer.java rename to services/command-router-infinispan/src/main/java/org/eclipse/hono/commandrouter/infinispan/app/InfinispanDeviceConnectionInfoProducer.java index 07b1482bbb..caf066d095 100644 --- a/services/command-router/src/main/java/org/eclipse/hono/commandrouter/app/DeviceConnectionInfoProducer.java +++ b/services/command-router-infinispan/src/main/java/org/eclipse/hono/commandrouter/infinispan/app/InfinispanDeviceConnectionInfoProducer.java @@ -12,7 +12,7 @@ */ -package org.eclipse.hono.commandrouter.app; +package org.eclipse.hono.commandrouter.infinispan.app; import java.io.IOException; import java.nio.file.Files; @@ -23,11 +23,11 @@ import org.eclipse.hono.commandrouter.CommandRouterServiceOptions; import org.eclipse.hono.commandrouter.impl.KubernetesBasedAdapterInstanceStatusService; import org.eclipse.hono.commandrouter.impl.UnknownStatusProvidingService; -import org.eclipse.hono.deviceconnection.infinispan.client.BasicCache; -import org.eclipse.hono.deviceconnection.infinispan.client.CacheBasedDeviceConnectionInfo; -import org.eclipse.hono.deviceconnection.infinispan.client.CommonCacheConfig; -import org.eclipse.hono.deviceconnection.infinispan.client.CommonCacheOptions; -import org.eclipse.hono.deviceconnection.infinispan.client.DeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.common.Cache; +import org.eclipse.hono.deviceconnection.common.CacheBasedDeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.common.CommonCacheConfig; +import org.eclipse.hono.deviceconnection.common.CommonCacheOptions; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; import org.eclipse.hono.deviceconnection.infinispan.client.EmbeddedCache; import org.eclipse.hono.deviceconnection.infinispan.client.HotrodCache; import org.eclipse.hono.deviceconnection.infinispan.client.InfinispanRemoteConfigurationOptions; @@ -55,44 +55,46 @@ * on whether a remote cache config with a non-empty server list is used or not. */ @ApplicationScoped -public class DeviceConnectionInfoProducer { +public class InfinispanDeviceConnectionInfoProducer { - private static final Logger LOG = LoggerFactory.getLogger(DeviceConnectionInfoProducer.class); + private static final Logger LOG = LoggerFactory.getLogger(InfinispanDeviceConnectionInfoProducer.class); @ConfigProperty(name = "hono.commandRouter.cache.embedded.configurationFile", defaultValue = "/etc/hono/cache-config.xml") String configFile; @Produces DeviceConnectionInfo deviceConnectionInfo( - final BasicCache cache, + final Cache cache, final Tracer tracer, final AdapterInstanceStatusService adapterInstanceStatusService) { return new CacheBasedDeviceConnectionInfo(cache, tracer, adapterInstanceStatusService); } @Produces - BasicCache cache( + Cache cache( final Vertx vertx, @ConfigMapping(prefix = "hono.commandRouter.cache.common") final CommonCacheOptions commonCacheOptions, @ConfigMapping(prefix = "hono.commandRouter.cache.remote") - final InfinispanRemoteConfigurationOptions remoteCacheConfigurationOptions) { + final InfinispanRemoteConfigurationOptions remoteCacheConfigurationOptions + ) { final var commonCacheConfig = new CommonCacheConfig(commonCacheOptions); final var infinispanCacheConfig = new InfinispanRemoteConfigurationProperties(remoteCacheConfigurationOptions); - if (Strings.isNullOrEmpty(infinispanCacheConfig.getServerList())) { - LOG.info("configuring embedded cache"); - return new EmbeddedCache<>( - vertx, - embeddedCacheManager(commonCacheConfig), - commonCacheConfig.getCacheName()); - } else { + + if (!Strings.isNullOrEmpty(infinispanCacheConfig.getServerList())) { LOG.info("configuring remote cache"); return HotrodCache.from( vertx, infinispanCacheConfig, commonCacheConfig); } + + LOG.info("configuring embedded cache"); + return new EmbeddedCache<>( + vertx, + embeddedCacheManager(commonCacheConfig), + commonCacheConfig.getCacheName()); } private EmbeddedCacheManager embeddedCacheManager(final CommonCacheConfig cacheConfig) { diff --git a/services/command-router-infinispan/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties b/services/command-router-infinispan/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties new file mode 100644 index 0000000000..7887b76e12 --- /dev/null +++ b/services/command-router-infinispan/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties @@ -0,0 +1,12 @@ +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0 +# +# SPDX-License-Identifier: EPL-2.0 + +Args = -H:+RunReachabilityHandlersConcurrently diff --git a/services/command-router-infinispan/src/main/resources/application-dev.properties b/services/command-router-infinispan/src/main/resources/application-dev.properties new file mode 100644 index 0000000000..0ef606f163 --- /dev/null +++ b/services/command-router-infinispan/src/main/resources/application-dev.properties @@ -0,0 +1,29 @@ +### Used when starting quarkus app in development mode, e.g. mvn quarkus:dev + +app.id=command-router +short.name=cmd-router + +hono.commandRouter.amqp.insecurePortEnabled=true +hono.commandRouter.amqp.insecurePortBindAddress=0.0.0.0 +hono.commandRouter.amqp.insecurePort=${fixed.commandrouter.amqp.port} + +hono.commandRouter.cache.remote.serverList=${docker.host.address:localhost}:${hono.infinispan.port} +hono.commandRouter.cache.remote.authServerName=${hono.infinispan.host:localhost} +hono.commandRouter.cache.remote.authRealm=ApplicationRealm +hono.commandRouter.cache.remote.authUsername=${hono.infinispan.username} +hono.commandRouter.cache.remote.authPassword=${hono.infinispan.password} +hono.commandRouter.cache.remote.saslMechanism=SCRAM-SHA-512 +hono.commandRouter.cache.remote.socketTimeout=5000 +hono.commandRouter.cache.remote.connectTimeout=5000 + +quarkus.http.port=${fixed.commandrouter.quarkus.http.port:3088} + +${quarkus.application-dev.properties} +hono.kafka.commandInternal.producerConfig."max.block.ms"=${kafka-client.producer.max-block-ms} +hono.kafka.commandInternal.producerConfig."request.timeout.ms"=${kafka-client.producer.request-timeout-ms} +hono.kafka.commandResponse.producerConfig."max.block.ms"=${kafka-client.producer.max-block-ms} +hono.kafka.commandResponse.producerConfig."request.timeout.ms"=${kafka-client.producer.request-timeout-ms} +hono.kafka.event.producerConfig."max.block.ms"=${kafka-client.producer.max-block-ms} +hono.kafka.event.producerConfig."request.timeout.ms"=${kafka-client.producer.request-timeout-ms} +hono.kafka.notification.producerConfig."max.block.ms"=${kafka-client.producer.max-block-ms} +hono.kafka.notification.producerConfig."request.timeout.ms"=${kafka-client.producer.request-timeout-ms} diff --git a/services/command-router-infinispan/src/main/resources/application.properties b/services/command-router-infinispan/src/main/resources/application.properties new file mode 100644 index 0000000000..6eb2ef7767 --- /dev/null +++ b/services/command-router-infinispan/src/main/resources/application.properties @@ -0,0 +1,2 @@ +${quarkus.application.properties} + diff --git a/services/command-router-infinispan/src/main/resources/default_banner.txt b/services/command-router-infinispan/src/main/resources/default_banner.txt new file mode 100644 index 0000000000..6ff38647e3 --- /dev/null +++ b/services/command-router-infinispan/src/main/resources/default_banner.txt @@ -0,0 +1,14 @@ + + ______ _ _ _ _ + | ____| | (_) | | | | + | |__ ___| |_ _ __ ___ ___ | |__| | ___ _ __ ___ + | __| / __| | | '_ \/ __|/ _ \ | __ |/ _ \| '_ \ / _ \ + | |___| (__| | | |_) \__ \ __/ | | | | (_) | | | | (_) | + |______\___|_|_| .__/|___/\___| |_| |_|\___/|_| |_|\___/ + | | + |_| + +Eclipse Hono Infinispan Based Command Router + +Go to https://www.eclipse.org/hono for more information. + diff --git a/services/command-router-infinispan/src/test/resources/application.yml b/services/command-router-infinispan/src/test/resources/application.yml new file mode 100644 index 0000000000..ab4f7d2c7b --- /dev/null +++ b/services/command-router-infinispan/src/test/resources/application.yml @@ -0,0 +1,23 @@ +# +# Copyright (c) 2022 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0 +# +# SPDX-License-Identifier: EPL-2.0 +# +quarkus: + console: + color: true + log: + level: INFO + min-level: TRACE + category: + "org.eclipse.hono.commandrouter": + level: INFO + "org.eclipse.hono.util": + level: INFO diff --git a/services/command-router-redis/pom.xml b/services/command-router-redis/pom.xml new file mode 100644 index 0000000000..8741ce0a15 --- /dev/null +++ b/services/command-router-redis/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + org.eclipse.hono + hono-services-parent + 2.6.0-SNAPSHOT + ../parent + + hono-service-command-router-redis + Hono Command Router Redis + A Quarkus based implementation of Hono's Command Router API that is using Redis for storing data. + + + + org.eclipse.hono + hono-service-command-router-base + + + + org.eclipse.hono + client-device-connection-redis + + + + + + + + + + + io.fabric8 + docker-maven-plugin + + + + + + Command Router + + + 5671 + 5672 + ${health.check.port} + + + + + + + + + + + + + + build-docker-image + + + + io.fabric8 + docker-maven-plugin + + + + + + + build-native-image + + + + io.fabric8 + docker-maven-plugin + + + + + + + diff --git a/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/app/Application.java b/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/app/Application.java new file mode 100644 index 0000000000..9335e63ae5 --- /dev/null +++ b/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/app/Application.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.hono.commandrouter.redis.app; + +import org.eclipse.hono.commandrouter.app.AbstractApplication; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +/** + * The Quarkus based Command Router main application class (Redis variant). + */ +@ApplicationScoped +public class Application extends AbstractApplication { + + @Inject + DeviceConnectionInfo deviceConnectionInfo; + + @Override + protected DeviceConnectionInfo getDeviceConnectionInfo() { + return deviceConnectionInfo; + } +} diff --git a/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/app/RedisDeviceConnectionInfoProducer.java b/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/app/RedisDeviceConnectionInfoProducer.java new file mode 100644 index 0000000000..2b17836c81 --- /dev/null +++ b/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/app/RedisDeviceConnectionInfoProducer.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ + + +package org.eclipse.hono.commandrouter.redis.app; + +import java.util.Optional; + +import org.eclipse.hono.commandrouter.AdapterInstanceStatusService; +import org.eclipse.hono.commandrouter.CommandRouterServiceOptions; +import org.eclipse.hono.commandrouter.impl.KubernetesBasedAdapterInstanceStatusService; +import org.eclipse.hono.commandrouter.impl.UnknownStatusProvidingService; +import org.eclipse.hono.deviceconnection.common.Cache; +import org.eclipse.hono.deviceconnection.common.CacheBasedDeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.common.DeviceConnectionInfo; +import org.eclipse.hono.deviceconnection.redis.client.RedisCache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.opentracing.Tracer; +import io.vertx.redis.client.RedisAPI; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Singleton; + + +/** + * A producer of an application scoped {@link DeviceConnectionInfo} instance. + *

+ * The underlying cache implementation will store data in-memory or in a remote cache, depending + * on whether a remote cache config with a non-empty server list is used or not. + */ +@ApplicationScoped +public class RedisDeviceConnectionInfoProducer { + + private static final Logger LOG = LoggerFactory.getLogger(RedisDeviceConnectionInfoProducer.class); + + @Produces + DeviceConnectionInfo deviceConnectionInfo( + final Cache cache, + final Tracer tracer, + final AdapterInstanceStatusService adapterInstanceStatusService) { + return new CacheBasedDeviceConnectionInfo(cache, tracer, adapterInstanceStatusService); + } + + @Produces + Cache cache(final RedisAPI redis) { + LOG.info("configuring redis cache"); + return RedisCache.from(redis); + } + + @Produces + @Singleton + AdapterInstanceStatusService adapterInstanceStatusService( + final CommandRouterServiceOptions commandRouterServiceOptions) { + final AdapterInstanceStatusService service = commandRouterServiceOptions + .kubernetesBasedAdapterInstanceStatusServiceEnabled() + ? KubernetesBasedAdapterInstanceStatusService.create() + : null; + return Optional.ofNullable(service) + .orElseGet(UnknownStatusProvidingService::new); + } +} diff --git a/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/config/RedisConfigInterceptor.java b/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/config/RedisConfigInterceptor.java new file mode 100644 index 0000000000..43fd612463 --- /dev/null +++ b/services/command-router-redis/src/main/java/org/eclipse/hono/commandrouter/redis/config/RedisConfigInterceptor.java @@ -0,0 +1,23 @@ +/* +TODO + */ +package org.eclipse.hono.commandrouter.redis.config; + +import io.smallrye.config.RelocateConfigSourceInterceptor; + +/** + * TODO. + */ +public class RedisConfigInterceptor extends RelocateConfigSourceInterceptor { + + /** + * TODO. + */ + public RedisConfigInterceptor() { + super(name -> { + + return name.startsWith("quarkus.redis") ? + name.replaceAll("quarkus\\.redis", "hono.commandRouter.cache.redis") : name; + }); + } +} diff --git a/services/command-router-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties b/services/command-router-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties new file mode 100644 index 0000000000..7887b76e12 --- /dev/null +++ b/services/command-router-redis/src/main/resources/META-INF/native-image/org.eclipse.hono/hono-service-command-router/native-image.properties @@ -0,0 +1,12 @@ +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0 +# +# SPDX-License-Identifier: EPL-2.0 + +Args = -H:+RunReachabilityHandlersConcurrently diff --git a/services/command-router-redis/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor b/services/command-router-redis/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor new file mode 100644 index 0000000000..35ffcb26e7 --- /dev/null +++ b/services/command-router-redis/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor @@ -0,0 +1 @@ +org.eclipse.hono.commandrouter.redis.config.RedisConfigInterceptor diff --git a/services/command-router-redis/src/main/resources/application-dev.properties b/services/command-router-redis/src/main/resources/application-dev.properties new file mode 100644 index 0000000000..0ef606f163 --- /dev/null +++ b/services/command-router-redis/src/main/resources/application-dev.properties @@ -0,0 +1,29 @@ +### Used when starting quarkus app in development mode, e.g. mvn quarkus:dev + +app.id=command-router +short.name=cmd-router + +hono.commandRouter.amqp.insecurePortEnabled=true +hono.commandRouter.amqp.insecurePortBindAddress=0.0.0.0 +hono.commandRouter.amqp.insecurePort=${fixed.commandrouter.amqp.port} + +hono.commandRouter.cache.remote.serverList=${docker.host.address:localhost}:${hono.infinispan.port} +hono.commandRouter.cache.remote.authServerName=${hono.infinispan.host:localhost} +hono.commandRouter.cache.remote.authRealm=ApplicationRealm +hono.commandRouter.cache.remote.authUsername=${hono.infinispan.username} +hono.commandRouter.cache.remote.authPassword=${hono.infinispan.password} +hono.commandRouter.cache.remote.saslMechanism=SCRAM-SHA-512 +hono.commandRouter.cache.remote.socketTimeout=5000 +hono.commandRouter.cache.remote.connectTimeout=5000 + +quarkus.http.port=${fixed.commandrouter.quarkus.http.port:3088} + +${quarkus.application-dev.properties} +hono.kafka.commandInternal.producerConfig."max.block.ms"=${kafka-client.producer.max-block-ms} +hono.kafka.commandInternal.producerConfig."request.timeout.ms"=${kafka-client.producer.request-timeout-ms} +hono.kafka.commandResponse.producerConfig."max.block.ms"=${kafka-client.producer.max-block-ms} +hono.kafka.commandResponse.producerConfig."request.timeout.ms"=${kafka-client.producer.request-timeout-ms} +hono.kafka.event.producerConfig."max.block.ms"=${kafka-client.producer.max-block-ms} +hono.kafka.event.producerConfig."request.timeout.ms"=${kafka-client.producer.request-timeout-ms} +hono.kafka.notification.producerConfig."max.block.ms"=${kafka-client.producer.max-block-ms} +hono.kafka.notification.producerConfig."request.timeout.ms"=${kafka-client.producer.request-timeout-ms} diff --git a/services/command-router-redis/src/main/resources/application.properties b/services/command-router-redis/src/main/resources/application.properties new file mode 100644 index 0000000000..6eb2ef7767 --- /dev/null +++ b/services/command-router-redis/src/main/resources/application.properties @@ -0,0 +1,2 @@ +${quarkus.application.properties} + diff --git a/services/command-router-redis/src/main/resources/default_banner.txt b/services/command-router-redis/src/main/resources/default_banner.txt new file mode 100644 index 0000000000..b002effac8 --- /dev/null +++ b/services/command-router-redis/src/main/resources/default_banner.txt @@ -0,0 +1,14 @@ + + ______ _ _ _ _ + | ____| | (_) | | | | + | |__ ___| |_ _ __ ___ ___ | |__| | ___ _ __ ___ + | __| / __| | | '_ \/ __|/ _ \ | __ |/ _ \| '_ \ / _ \ + | |___| (__| | | |_) \__ \ __/ | | | | (_) | | | | (_) | + |______\___|_|_| .__/|___/\___| |_| |_|\___/|_| |_|\___/ + | | + |_| + +Eclipse Hono Redis Based Command Router + +Go to https://www.eclipse.org/hono for more information. + diff --git a/services/command-router-redis/src/test/resources/application.yml b/services/command-router-redis/src/test/resources/application.yml new file mode 100644 index 0000000000..ab4f7d2c7b --- /dev/null +++ b/services/command-router-redis/src/test/resources/application.yml @@ -0,0 +1,23 @@ +# +# Copyright (c) 2022 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0 +# +# SPDX-License-Identifier: EPL-2.0 +# +quarkus: + console: + color: true + log: + level: INFO + min-level: TRACE + category: + "org.eclipse.hono.commandrouter": + level: INFO + "org.eclipse.hono.util": + level: INFO diff --git a/services/pom.xml b/services/pom.xml index 416fc18f64..ea151fae11 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -30,7 +30,9 @@ auth auth-base base-jdbc - command-router + command-router-base + command-router-infinispan + command-router-redis device-registry-base device-registry-jdbc device-registry-mongodb diff --git a/tests/pom.xml b/tests/pom.xml index b7466c33bc..4f4f5ceed6 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -85,7 +85,7 @@ Command Router related properties. --> clustered-cache - hono-service-command-router + hono-service-command-router-infinispan 300000000 ${default.java-options} @@ -93,6 +93,7 @@ false false + true + + bitnami/redis + hono-redis-test + + ${hono.redis.disabled} + + 6379:6379 + + + custom + ${custom.network.name} + redis + + 1500000000 + 1500000000 + + Redis + ${log.color.extra-services} + + + + .*(Ready to accept connections).* + + + yes + + + ${docker.repository}/hono-jaeger-test:${project.version} @@ -2227,7 +2276,7 @@ true **/hono-*-test:* - hono-*-test-*,all-in-one-*,cp-*,postgres-* + hono-*-test-*,all-in-one-*,cp-*,postgres-*,redis-* diff --git a/tests/src/test/resources/commandrouter/redis-cache/application.yml b/tests/src/test/resources/commandrouter/redis-cache/application.yml new file mode 100644 index 0000000000..7c5eada006 --- /dev/null +++ b/tests/src/test/resources/commandrouter/redis-cache/application.yml @@ -0,0 +1,92 @@ +hono: + app: + maxInstances: 1 + amqpMessagingDisabled: ${hono.amqp-messaging.disabled} + kafkaMessagingDisabled: ${hono.kafka-messaging.disabled} + auth: + host: "${hono.auth.host}" + port: 5671 + name: "command-router" + trustStorePath: "/opt/hono/config/certs/trusted-certs.pem" + jwksPollingInterval: "PT20S" + commandRouter: + amqp: + insecurePortEnabled: true + insecurePortBindAddress: "0.0.0.0" + cache: + redis: + hosts: "redis://redis:6379" + messaging: + name: 'Hono Command Router' + host: "${hono.amqp-network.host}" + port: 5673 + amqpHostname: "hono-internal" + keyPath: "/opt/hono/config/certs/command-router-key.pem" + certPath: "/opt/hono/config/certs/command-router-cert.pem" + trustStorePath: "/opt/hono/config/certs/trusted-certs.pem" + linkEstablishmentTimeout: ${link.establishment.timeout} + flowLatency: ${flow.latency} + requestTimeout: ${request.timeout} + registration: + name: 'Hono Command Router' + host: "${hono.registration.host}" + port: 5672 + username: "command-router@HONO" + password: "cmd-router-secret" + linkEstablishmentTimeout: ${link.establishment.timeout} + flowLatency: ${flow.latency} + requestTimeout: ${request.timeout} + tenant: + name: 'Hono Command Router' + host: "${hono.registration.host}" + port: 5672 + username: "command-router@HONO" + password: "cmd-router-secret" + linkEstablishmentTimeout: ${link.establishment.timeout} + flowLatency: ${flow.latency} + requestTimeout: ${request.timeout} + command: + name: 'Hono Command Router' + host: "${hono.amqp-network.host}" + port: 5673 + amqpHostname: "hono-internal" + keyPath: "/opt/hono/config/certs/command-router-key.pem" + certPath: "/opt/hono/config/certs/command-router-cert.pem" + trustStorePath: "/opt/hono/config/certs/trusted-certs.pem" + linkEstablishmentTimeout: ${link.establishment.timeout} + flowLatency: ${flow.latency} + requestTimeout: ${request.timeout} + kafka: + commonClientConfig: + bootstrap.servers: "${hono.kafka.bootstrap.servers}" + commandInternal: + producerConfig: + max.block.ms: ${kafka-client.producer.max-block-ms} + request.timeout.ms: ${kafka-client.producer.request-timeout-ms} + delivery.timeout.ms: ${kafka-client.producer.delivery-timeout-ms} + commandResponse: + producerConfig: + max.block.ms: ${kafka-client.producer.max-block-ms} + request.timeout.ms: ${kafka-client.producer.request-timeout-ms} + delivery.timeout.ms: ${kafka-client.producer.delivery-timeout-ms} + event: + producerConfig: + max.block.ms: ${kafka-client.producer.max-block-ms} + request.timeout.ms: ${kafka-client.producer.request-timeout-ms} + delivery.timeout.ms: ${kafka-client.producer.delivery-timeout-ms} + +quarkus: + otel: + exporter: + otlp: + endpoint: "${otel-collector.endpoint}" + console: + color: true + log: + level: INFO + min-level: TRACE + category: + "io.quarkus.vertx.core.runtime": + level: DEBUG + vertx: + max-event-loop-execute-time: ${max.event-loop.execute-time} From b3485f42a39d4647c8f8a625453ec95707a2df1c Mon Sep 17 00:00:00 2001 From: Stefan Freyr Stefansson Date: Tue, 2 Apr 2024 17:28:29 +0000 Subject: [PATCH 2/2] Remove commented out dependencies --- client-device-connection-redis/pom.xml | 11 ----------- services/command-router-redis/pom.xml | 8 -------- 2 files changed, 19 deletions(-) diff --git a/client-device-connection-redis/pom.xml b/client-device-connection-redis/pom.xml index 8f9f22aa69..b0fbdce95e 100644 --- a/client-device-connection-redis/pom.xml +++ b/client-device-connection-redis/pom.xml @@ -50,17 +50,6 @@ slf4j-api - - org.junit.jupiter diff --git a/services/command-router-redis/pom.xml b/services/command-router-redis/pom.xml index 8741ce0a15..9e55c0f62b 100644 --- a/services/command-router-redis/pom.xml +++ b/services/command-router-redis/pom.xml @@ -33,14 +33,6 @@ org.eclipse.hono client-device-connection-redis - - -