diff --git a/broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/AppModule.java b/broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/AppModule.java index 44c53d3a79b..19833e2f274 100644 --- a/broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/AppModule.java +++ b/broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/AppModule.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others + * Copyright (c) 2016, 2024 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -17,12 +17,13 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.broker.artemis.plugin.security.setting.BrokerSetting; -import org.eclipse.kapua.broker.artemis.plugin.security.setting.BrokerSettingKey; import org.eclipse.kapua.broker.artemis.plugin.utils.BrokerHostResolver; import org.eclipse.kapua.broker.artemis.plugin.utils.BrokerIdResolver; import org.eclipse.kapua.broker.artemis.plugin.utils.BrokerIdentity; import org.eclipse.kapua.broker.artemis.plugin.utils.DefaultBrokerHostResolver; import org.eclipse.kapua.broker.artemis.plugin.utils.DefaultBrokerIdResolver; +import org.eclipse.kapua.commons.ContainerIdResolver; +import org.eclipse.kapua.commons.DefaultContainerIdResolver; import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.core.JaxbClassProvider; import org.eclipse.kapua.commons.liquibase.DatabaseCheckUpdate; @@ -67,12 +68,6 @@ String metricModuleName() { return "broker-telemetry"; } - @Provides - @Named("eventsModuleName") - String eventModuleName() { - return "telemetry"; - } - @Provides @Singleton @Named("brokerHost") @@ -88,7 +83,49 @@ BrokerIdResolver brokerIdResolver(BrokerSetting brokerSettings) throws KapuaExce @Singleton @Provides - BrokerHostResolver brokerHostResolver(BrokerSetting brokerSettings) throws KapuaException { - return new DefaultBrokerHostResolver(brokerSettings.getString(BrokerSettingKey.BROKER_HOST)); + ContainerIdResolver containerIdResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultContainerIdResolver(systemSetting.getString(SystemSettingKey.CONTAINER_ID)); + } + + @Singleton + @Provides + BrokerHostResolver brokerHostResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultBrokerHostResolver(systemSetting.getString(SystemSettingKey.BROKER_HOST)); + } + + @Provides + @Named("accountEvtSubscriptionGroupId") + String accountEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authenticationEvtSubscriptionGroupId") + String authenticationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authorizationEvtSubscriptionGroupId") + String authorizationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceConnectionEvtSubscriptionGroupId") + String deviceConnectionEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceRegistryEvtSubscriptionGroupId") + String deviceRegistryEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("userEvtSubscriptionGroupId") + String userEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); } } diff --git a/broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ArtemisSecurityModuleClient.java b/broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ArtemisSecurityModuleClient.java index 78cf2d98243..d1e53750337 100644 --- a/broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ArtemisSecurityModuleClient.java +++ b/broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ArtemisSecurityModuleClient.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019, 2022 Eurotech and/or its affiliates and others + * Copyright (c) 2019, 2024 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -90,4 +90,5 @@ ServiceClient authServiceClient( public String authServiceRequestAddress() { return "$SYS/SVC/auth/request"; } + } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/ContainerIdResolver.java b/commons/src/main/java/org/eclipse/kapua/commons/ContainerIdResolver.java new file mode 100644 index 00000000000..d651003286b --- /dev/null +++ b/commons/src/main/java/org/eclipse/kapua/commons/ContainerIdResolver.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2024 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.commons; + +/** + * Resolves the container id + */ +public interface ContainerIdResolver { + + String getContainerId(); + +} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/DefaultContainerIdResolver.java b/commons/src/main/java/org/eclipse/kapua/commons/DefaultContainerIdResolver.java new file mode 100644 index 00000000000..f4d6b9e8ca0 --- /dev/null +++ b/commons/src/main/java/org/eclipse/kapua/commons/DefaultContainerIdResolver.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2017, 2024 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.commons; + +import com.google.inject.Inject; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.kapua.KapuaErrorCodes; +import org.eclipse.kapua.KapuaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Lookup from the configuration file + * + * @since 1.0 + */ +public class DefaultContainerIdResolver implements ContainerIdResolver { + + protected static final Logger logger = LoggerFactory.getLogger(DefaultContainerIdResolver.class); + + private static final String CANNOT_FIND_IP_ERROR_MSG = "Cannot resolve the container id. Please check the configuration!"; + private final String containerId; + + @Inject + public DefaultContainerIdResolver(String containerId) throws KapuaException { + this.containerId = containerId; + logger.info("Loaded container id: {}", this.containerId); + if (StringUtils.isEmpty(this.containerId)) { + throw new KapuaException(KapuaErrorCodes.INTERNAL_ERROR, CANNOT_FIND_IP_ERROR_MSG); + } + } + + @Override + public String getContainerId() { + return containerId; + } +} diff --git a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalModule.java b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalModule.java index 9f661eb7384..4d28e951567 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalModule.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/event/ServiceEventTransactionalModule.java @@ -56,11 +56,11 @@ private String getSubscriptionName(String address, String subscriber) { public ServiceEventTransactionalModule( ServiceEventClientConfiguration[] serviceEventClientConfigurations, String internalAddress, - String uniqueClientId, + String subscriptionGroupId, ServiceEventHouseKeeperFactory serviceEventTransactionalHousekeeperFactory, ServiceEventBus serviceEventBus) { this.serviceEventBus = serviceEventBus; - this.serviceEventClientConfigurations = appendClientId(uniqueClientId, serviceEventClientConfigurations); + this.serviceEventClientConfigurations = appendClientId(subscriptionGroupId, serviceEventClientConfigurations); this.internalAddress = internalAddress; this.houseKeeperFactory = serviceEventTransactionalHousekeeperFactory; } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/setting/system/SystemSettingKey.java b/commons/src/main/java/org/eclipse/kapua/commons/setting/system/SystemSettingKey.java index 2581ff8924c..5f42257c578 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/setting/system/SystemSettingKey.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/setting/system/SystemSettingKey.java @@ -23,6 +23,10 @@ */ public enum SystemSettingKey implements SettingKey { + /** + * Container id (used for example to set a unique identifier for event listeners so events could be received by all the instances of a certain type) + */ + CONTAINER_ID("container.id"), /** * Cluster name */ diff --git a/commons/src/main/resources/kapua-environment-setting.properties b/commons/src/main/resources/kapua-environment-setting.properties index f8c9ebbdeb7..073dfbd89eb 100644 --- a/commons/src/main/resources/kapua-environment-setting.properties +++ b/commons/src/main/resources/kapua-environment-setting.properties @@ -68,6 +68,8 @@ broker.connector.internal.amqp.name=amqp broker.connector.internal.username=internalUsername broker.connector.internal.password=internalPassword +container.id=default + character.encoding=UTF-8 # diff --git a/console/web/src/main/java/org/eclipse/kapua/app/console/AppModule.java b/console/web/src/main/java/org/eclipse/kapua/app/console/AppModule.java index 6709f539bef..9ef57ef3831 100644 --- a/console/web/src/main/java/org/eclipse/kapua/app/console/AppModule.java +++ b/console/web/src/main/java/org/eclipse/kapua/app/console/AppModule.java @@ -15,6 +15,7 @@ import javax.inject.Named; import javax.inject.Singleton; +import org.eclipse.kapua.commons.ContainerIdResolver; import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.util.xml.JAXBContextProvider; @@ -33,9 +34,46 @@ String metricModuleName() { return "web-console"; } + @Singleton @Provides - @Named("eventsModuleName") - String eventModuleName() { - return "console"; + ContainerIdResolver containerIdResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultContainerIdResolver(systemSetting.getString(SystemSettingKey.CONTAINER_ID)); } + + @Provides + @Named("accountEvtSubscriptionGroupId") + String accountEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "console-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authenticationEvtSubscriptionGroupId") + String authenticationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "console-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authorizationEvtSubscriptionGroupId") + String authorizationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "console-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceConnectionEvtSubscriptionGroupId") + String deviceConnectionEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceRegistryEvtSubscriptionGroupId") + String deviceRegistryEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "console-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("userEvtSubscriptionGroupId") + String userEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "console-" + containerIdResolver.getContainerId(); + } + } diff --git a/consumer/lifecycle-app/src/main/java/org/eclipse/kapua/consumer/lifecycle/AppModule.java b/consumer/lifecycle-app/src/main/java/org/eclipse/kapua/consumer/lifecycle/AppModule.java index 0bbfeb64e54..a3bbf507845 100644 --- a/consumer/lifecycle-app/src/main/java/org/eclipse/kapua/consumer/lifecycle/AppModule.java +++ b/consumer/lifecycle-app/src/main/java/org/eclipse/kapua/consumer/lifecycle/AppModule.java @@ -15,9 +15,14 @@ import javax.inject.Named; import javax.inject.Singleton; +import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.ContainerIdResolver; +import org.eclipse.kapua.commons.DefaultContainerIdResolver; import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.core.JaxbClassProvider; import org.eclipse.kapua.commons.liquibase.DatabaseCheckUpdate; +import org.eclipse.kapua.commons.setting.system.SystemSetting; +import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.xml.JAXBContextProvider; import org.eclipse.kapua.commons.util.xml.JAXBContextProviderImpl; import org.eclipse.kapua.commons.util.xml.XmlRootAnnotatedJaxbClassesScanner; @@ -48,9 +53,53 @@ String metricModuleName() { return MetricsLifecycle.CONSUMER_LIFECYCLE; } + @Singleton @Provides - @Named("eventsModuleName") - String eventModuleName() { - return "lifecycle"; + ContainerIdResolver containerIdResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultContainerIdResolver(systemSetting.getString(SystemSettingKey.CONTAINER_ID)); } + + @Provides + @Named("accountEvtSubscriptionGroupId") + String accountEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-lif-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authenticationEvtSubscriptionGroupId") + String authenticationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-lif-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authorizationEvtSubscriptionGroupId") + String authorizationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-lif-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceConnectionEvtSubscriptionGroupId") + String deviceConnectionEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceRegistryEvtSubscriptionGroupId") + String deviceRegistryEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-lif-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("userEvtSubscriptionGroupId") + String userEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-lif-" + containerIdResolver.getContainerId(); + } + + @Provides + @Singleton + @Named("clusterName") + String clusterName(SystemSetting systemSetting) { + return systemSetting.getString(SystemSettingKey.CLUSTER_NAME); + } + } diff --git a/consumer/telemetry-app/src/main/java/org/eclipse/kapua/consumer/telemetry/AppModule.java b/consumer/telemetry-app/src/main/java/org/eclipse/kapua/consumer/telemetry/AppModule.java index 3946ce0eb81..82d1642cb32 100644 --- a/consumer/telemetry-app/src/main/java/org/eclipse/kapua/consumer/telemetry/AppModule.java +++ b/consumer/telemetry-app/src/main/java/org/eclipse/kapua/consumer/telemetry/AppModule.java @@ -15,9 +15,14 @@ import javax.inject.Named; import javax.inject.Singleton; +import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.ContainerIdResolver; +import org.eclipse.kapua.commons.DefaultContainerIdResolver; import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.core.JaxbClassProvider; import org.eclipse.kapua.commons.liquibase.DatabaseCheckUpdate; +import org.eclipse.kapua.commons.setting.system.SystemSetting; +import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.xml.JAXBContextProvider; import org.eclipse.kapua.commons.util.xml.JAXBContextProviderImpl; import org.eclipse.kapua.commons.util.xml.XmlRootAnnotatedJaxbClassesScanner; @@ -48,9 +53,45 @@ String metricModuleName() { return MetricsTelemetry.CONSUMER_TELEMETRY; } + @Singleton @Provides - @Named("eventsModuleName") - String eventModuleName() { - return "telemetry"; + ContainerIdResolver containerIdResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultContainerIdResolver(systemSetting.getString(SystemSettingKey.CONTAINER_ID)); + } + + @Provides + @Named("accountEvtSubscriptionGroupId") + String accountEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authenticationEvtSubscriptionGroupId") + String authenticationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authorizationEvtSubscriptionGroupId") + String authorizationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceConnectionEvtSubscriptionGroupId") + String deviceConnectionEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceRegistryEvtSubscriptionGroupId") + String deviceRegistryEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("userEvtSubscriptionGroupId") + String userEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "con-tel-" + containerIdResolver.getContainerId(); } } diff --git a/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/AppModule.java b/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/AppModule.java index b4102a9b6b3..a608d9ec98e 100644 --- a/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/AppModule.java +++ b/job-engine/app/web/src/main/java/org/eclipse/kapua/job/engine/app/web/AppModule.java @@ -15,9 +15,14 @@ import javax.inject.Named; import javax.inject.Singleton; +import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.ContainerIdResolver; +import org.eclipse.kapua.commons.DefaultContainerIdResolver; import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.core.JaxbClassProvider; import org.eclipse.kapua.commons.liquibase.DatabaseCheckUpdate; +import org.eclipse.kapua.commons.setting.system.SystemSetting; +import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.xml.JAXBContextProvider; import org.eclipse.kapua.commons.util.xml.JAXBContextProviderImpl; import org.eclipse.kapua.commons.util.xml.XmlRootAnnotatedJaxbClassesScanner; @@ -49,9 +54,45 @@ String metricModuleName() { return "job-engine"; } + @Singleton @Provides - @Named("eventsModuleName") - String eventModuleName() { - return "job_engine"; + ContainerIdResolver containerIdResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultContainerIdResolver(systemSetting.getString(SystemSettingKey.CONTAINER_ID)); + } + + @Provides + @Named("accountEvtSubscriptionGroupId") + String accountEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "eng-job-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authenticationEvtSubscriptionGroupId") + String authenticationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "eng-job-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authorizationEvtSubscriptionGroupId") + String authorizationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "eng-job-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceConnectionEvtSubscriptionGroupId") + String deviceConnectionEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceRegistryEvtSubscriptionGroupId") + String deviceRegistryEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "eng-job-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("userEvtSubscriptionGroupId") + String userEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "eng-job-" + containerIdResolver.getContainerId(); } } diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/TestConfigModule.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/TestConfigModule.java index 0d8e5e32bcf..7725fa5cb34 100644 --- a/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/TestConfigModule.java +++ b/qa/integration/src/test/java/org/eclipse/kapua/integration/misc/TestConfigModule.java @@ -15,7 +15,12 @@ import javax.inject.Named; import javax.inject.Singleton; +import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.ContainerIdResolver; +import org.eclipse.kapua.commons.DefaultContainerIdResolver; import org.eclipse.kapua.commons.core.AbstractKapuaModule; +import org.eclipse.kapua.commons.setting.system.SystemSetting; +import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.xml.JAXBContextProvider; import org.eclipse.kapua.qa.common.TestJAXBContextProvider; @@ -39,4 +44,47 @@ String metricModuleName() { String eventModuleName() { return "qa_tests"; } + + @Singleton + @Provides + ContainerIdResolver containerIdResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultContainerIdResolver(systemSetting.getString(SystemSettingKey.CONTAINER_ID)); + } + + @Provides + @Named("accountEvtSubscriptionGroupId") + String accountEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "qa-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authenticationEvtSubscriptionGroupId") + String authenticationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "qa-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authorizationEvtSubscriptionGroupId") + String authorizationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "qa-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceConnectionEvtSubscriptionGroupId") + String deviceConnectionEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "qa-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceRegistryEvtSubscriptionGroupId") + String deviceRegistryEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "qa-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("userEvtSubscriptionGroupId") + String userEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "qa-" + containerIdResolver.getContainerId(); + } + } diff --git a/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/AppModule.java b/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/AppModule.java index 2590eb88367..792e3222c21 100644 --- a/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/AppModule.java +++ b/rest-api/web/src/main/java/org/eclipse/kapua/app/api/web/AppModule.java @@ -15,16 +15,21 @@ import javax.inject.Named; import javax.inject.Singleton; +import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.app.api.core.model.StorableEntityId; import org.eclipse.kapua.app.api.core.model.device.management.JsonGenericRequestMessage; import org.eclipse.kapua.app.api.core.model.device.management.JsonGenericResponseMessage; import org.eclipse.kapua.app.api.core.settings.KapuaApiCoreSetting; import org.eclipse.kapua.app.api.core.settings.KapuaApiCoreSettingKeys; import org.eclipse.kapua.app.api.resources.v1.resources.model.device.management.keystore.DeviceKeystoreCertificateInfo; +import org.eclipse.kapua.commons.ContainerIdResolver; +import org.eclipse.kapua.commons.DefaultContainerIdResolver; import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.core.JaxbClassProvider; import org.eclipse.kapua.commons.core.SimpleJaxbClassProvider; import org.eclipse.kapua.commons.liquibase.DatabaseCheckUpdate; +import org.eclipse.kapua.commons.setting.system.SystemSetting; +import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.xml.JAXBContextProvider; import org.eclipse.kapua.commons.util.xml.JAXBContextProviderImpl; import org.eclipse.kapua.commons.util.xml.XmlRootAnnotatedJaxbClassesScanner; @@ -75,10 +80,46 @@ String metricModuleName() { return "rest-api"; } + @Singleton @Provides - @Named("eventsModuleName") - String eventModuleName() { - return "rest_api"; + ContainerIdResolver containerIdResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultContainerIdResolver(systemSetting.getString(SystemSettingKey.CONTAINER_ID)); + } + + @Provides + @Named("accountEvtSubscriptionGroupId") + String accountEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "rest-api-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authenticationEvtSubscriptionGroupId") + String authenticationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "rest-api-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authorizationEvtSubscriptionGroupId") + String authorizationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "rest-api-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceConnectionEvtSubscriptionGroupId") + String deviceConnectionEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceRegistryEvtSubscriptionGroupId") + String deviceRegistryEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "rest-api-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("userEvtSubscriptionGroupId") + String userEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "rest-api-" + containerIdResolver.getContainerId(); } } diff --git a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountModule.java b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountModule.java index 60b6481a0fa..3b49177124a 100644 --- a/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountModule.java +++ b/service/account/internal/src/main/java/org/eclipse/kapua/service/account/internal/AccountModule.java @@ -92,7 +92,7 @@ ServiceModule accountServiceModule(AccountService accountService, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaAccountSetting kapuaAccountSetting, - @Named("eventsModuleName") String eventModuleName + @Named("accountEvtSubscriptionGroupId") String eventModuleName ) throws ServiceEventBusException { return new AccountServiceModule( accountService, diff --git a/service/authentication-app/src/main/java/org/eclipse/kapua/service/authentication/AppModule.java b/service/authentication-app/src/main/java/org/eclipse/kapua/service/authentication/AppModule.java index 765acc2d854..9e2cd28def5 100644 --- a/service/authentication-app/src/main/java/org/eclipse/kapua/service/authentication/AppModule.java +++ b/service/authentication-app/src/main/java/org/eclipse/kapua/service/authentication/AppModule.java @@ -15,9 +15,14 @@ import javax.inject.Named; import javax.inject.Singleton; +import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.commons.ContainerIdResolver; +import org.eclipse.kapua.commons.DefaultContainerIdResolver; import org.eclipse.kapua.commons.core.AbstractKapuaModule; import org.eclipse.kapua.commons.core.JaxbClassProvider; import org.eclipse.kapua.commons.liquibase.DatabaseCheckUpdate; +import org.eclipse.kapua.commons.setting.system.SystemSetting; +import org.eclipse.kapua.commons.setting.system.SystemSettingKey; import org.eclipse.kapua.commons.util.xml.JAXBContextProvider; import org.eclipse.kapua.commons.util.xml.JAXBContextProviderImpl; import org.eclipse.kapua.commons.util.xml.XmlRootAnnotatedJaxbClassesScanner; @@ -48,9 +53,45 @@ String metricModuleName() { return MetricsAuthentication.SERVICE_AUTHENTICATION; } + @Singleton @Provides - @Named("eventsModuleName") - String eventModuleName() { - return "authentication"; + ContainerIdResolver containerIdResolver(SystemSetting systemSetting) throws KapuaException { + return new DefaultContainerIdResolver(systemSetting.getString(SystemSettingKey.CONTAINER_ID)); + } + + @Provides + @Named("accountEvtSubscriptionGroupId") + String accountEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "svc-ath-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authenticationEvtSubscriptionGroupId") + String authenticationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "svc-ath-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("authorizationEvtSubscriptionGroupId") + String authorizationEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "svc-ath-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceConnectionEvtSubscriptionGroupId") + String deviceConnectionEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "brk-tel-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("deviceRegistryEvtSubscriptionGroupId") + String deviceRegistryEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "svc-ath-" + containerIdResolver.getContainerId(); + } + + @Provides + @Named("userEvtSubscriptionGroupId") + String userEvtSubscriptionGroupId(ContainerIdResolver containerIdResolver) { + return "svc-ath-" + containerIdResolver.getContainerId(); } } diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerModule.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerModule.java index 7709e703544..d65f9ee33a4 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerModule.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerModule.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others + * Copyright (c) 2023, 2024 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -52,7 +52,7 @@ protected ServiceModule deviceConnectionEventListenerServiceModule(DeviceConnect EventStoreFactory eventStoreFactory, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, - @Named("eventsModuleName") String eventModuleName + @Named("deviceConnectionEvtSubscriptionGroupId") String subscriptionGroupId ) throws ServiceEventBusException { String address = kapuaDeviceRegistrySettings.getString(KapuaDeviceRegistrySettingKeys.DEVICE_EVENT_ADDRESS); @@ -71,6 +71,6 @@ protected ServiceModule deviceConnectionEventListenerServiceModule(DeviceConnect serviceEventBus ), serviceEventBus, - eventModuleName); + subscriptionGroupId); } } diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerServiceImpl.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerServiceImpl.java index 290bddf3698..a28e3add174 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerServiceImpl.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerServiceImpl.java @@ -30,8 +30,6 @@ public class DeviceConnectionEventListenerServiceImpl implements DeviceConnectio private static final Logger LOGGER = LoggerFactory.getLogger(DeviceConnectionEventListenerServiceImpl.class); - protected static final String DISCONNECT = "disconnect"; - protected ArrayList receivers = new ArrayList<>(); @Inject diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerServiceModule.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerServiceModule.java index 2f49bf316c0..d1cda8aa230 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerServiceModule.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/connection/listener/internal/DeviceConnectionEventListenerServiceModule.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023, 2022 Eurotech and/or its affiliates and others + * Copyright (c) 2023, 2024 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -25,10 +25,10 @@ public class DeviceConnectionEventListenerServiceModule extends ServiceEventTran public DeviceConnectionEventListenerServiceModule(DeviceConnectionEventListenerService deviceConnectionEventListenerService, String eventAddress, ServiceEventHouseKeeperFactory serviceEventTransactionalHousekeeperFactory, ServiceEventBus serviceEventBus, - String eventModuleName) { + String subscriptionGroupId) { super(ServiceInspector.getEventBusClients(deviceConnectionEventListenerService, DeviceConnectionEventListenerService.class).toArray(new ServiceEventClientConfiguration[0]), eventAddress, - eventModuleName, + subscriptionGroupId, serviceEventTransactionalHousekeeperFactory, serviceEventBus); } diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java index bd018a85761..54476ad266a 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceRegistryModule.java @@ -138,7 +138,7 @@ ServiceModule deviceRegistryModule(DeviceConnectionService deviceConnectionServi ServiceEventBus serviceEventBus, KapuaDeviceRegistrySettings kapuaDeviceRegistrySettings, KapuaJpaTxManagerFactory jpaTxManagerFactory, - @Named("eventsModuleName") String eventModuleName + @Named("deviceRegistryEvtSubscriptionGroupId") String subscriptionGroupId ) throws ServiceEventBusException { return new DeviceServiceModule( deviceConnectionService, @@ -156,7 +156,7 @@ ServiceModule deviceRegistryModule(DeviceConnectionService deviceConnectionServi serviceEventBus ), serviceEventBus, - eventModuleName); + subscriptionGroupId); } @Provides diff --git a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceServiceModule.java b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceServiceModule.java index b5e6df5f822..477f24e13d3 100644 --- a/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceServiceModule.java +++ b/service/device/registry/internal/src/main/java/org/eclipse/kapua/service/device/registry/DeviceServiceModule.java @@ -29,7 +29,7 @@ public DeviceServiceModule(DeviceConnectionService deviceConnectionService, KapuaDeviceRegistrySettings deviceRegistrySettings, ServiceEventHouseKeeperFactory serviceEventTransactionalHousekeeperFactory, ServiceEventBus serviceEventBus, - String eventModuleName) { + String subscriptionGroupId) { super(Arrays.asList(ServiceInspector.getEventBusClients(deviceRegistryService, DeviceRegistryService.class), ServiceInspector.getEventBusClients(deviceConnectionService, DeviceConnectionService.class) ) @@ -38,7 +38,7 @@ public DeviceServiceModule(DeviceConnectionService deviceConnectionService, .collect(Collectors.toList()) .toArray(new ServiceEventClientConfiguration[0]), deviceRegistrySettings.getString(KapuaDeviceRegistrySettingKeys.DEVICE_EVENT_ADDRESS), - eventModuleName, + subscriptionGroupId, serviceEventTransactionalHousekeeperFactory, serviceEventBus); } diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationModule.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationModule.java index d3202f52d44..c1d29c29b27 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationModule.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authentication/shiro/AuthenticationModule.java @@ -152,7 +152,7 @@ public ServiceModule authenticationServiceModule(AccessTokenService accessTokenS EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaAuthenticationSetting kapuaAuthenticationSetting, - @Named("eventsModuleName") String eventModuleName + @Named("authenticationEvtSubscriptionGroupId") String subscriptionGroupId ) throws ServiceEventBusException { return new AuthenticationServiceModule( credentialService, @@ -170,7 +170,7 @@ public ServiceModule authenticationServiceModule(AccessTokenService accessTokenS serviceEventBus ), serviceEventBus, - eventModuleName); + subscriptionGroupId); } @ProvidesIntoSet diff --git a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/AuthorizationModule.java b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/AuthorizationModule.java index ab46f2fd679..c19c8cd20fb 100644 --- a/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/AuthorizationModule.java +++ b/service/security/shiro/src/main/java/org/eclipse/kapua/service/authorization/shiro/AuthorizationModule.java @@ -159,7 +159,7 @@ ServiceModule authorizationServiceModule(AccessInfoService accessInfoService, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaAuthorizationSetting kapuaAuthorizationSetting, - @Named("eventsModuleName") String eventModuleName + @Named("authorizationEvtSubscriptionGroupId") String subscriptionGroupId ) throws ServiceEventBusException { return new AuthorizationServiceModule( accessInfoService, @@ -178,7 +178,7 @@ ServiceModule authorizationServiceModule(AccessInfoService accessInfoService, txManagerFactory.create("kapua-authorization"), serviceEventBus ), serviceEventBus, - eventModuleName); + subscriptionGroupId); } @Provides diff --git a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserModule.java b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserModule.java index dff254c3bf4..3ab0e766987 100644 --- a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserModule.java +++ b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserModule.java @@ -102,7 +102,7 @@ public ServiceModule userServiceModule(UserService userService, EventStoreRecordRepository eventStoreRecordRepository, ServiceEventBus serviceEventBus, KapuaUserSetting kapuaUserSetting, - @Named("eventsModuleName") String eventModuleName + @Named("userEvtSubscriptionGroupId") String subscriptionGroupId ) throws ServiceEventBusException { return new UserServiceModule( userService, @@ -118,7 +118,7 @@ public ServiceModule userServiceModule(UserService userService, txManagerFactory.create("kapua-user"), serviceEventBus ), serviceEventBus, - eventModuleName); + subscriptionGroupId); } @Provides diff --git a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceModule.java b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceModule.java index e82038f9422..60fb1b1f7ba 100644 --- a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceModule.java +++ b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceModule.java @@ -25,10 +25,10 @@ public class UserServiceModule extends ServiceEventTransactionalModule { public UserServiceModule(UserService userService, KapuaUserSetting kapuaUserSetting, ServiceEventHouseKeeperFactory serviceEventTransactionalHousekeeperFactory, ServiceEventBus serviceEventBus, - String eventModuleName) { + String subscriptionGroupId) { super(ServiceInspector.getEventBusClients(userService, UserService.class).toArray(new ServiceEventClientConfiguration[0]), kapuaUserSetting.getString(KapuaUserSettingKeys.USER_EVENT_ADDRESS), - eventModuleName, + subscriptionGroupId, serviceEventTransactionalHousekeeperFactory, serviceEventBus); } }