Skip to content

Commit

Permalink
🚚 moving ServiceConfigurationManager into isolable modules in order t…
Browse files Browse the repository at this point in the history
…o allow them to be ignored (overriding not supported)

Signed-off-by: dseurotech <[email protected]>
  • Loading branch information
dseurotech committed Jul 10, 2024
1 parent de386ff commit 72c8f63
Show file tree
Hide file tree
Showing 16 changed files with 672 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@
import javax.inject.Singleton;

import org.eclipse.kapua.commons.configuration.AccountRelativeFinder;
import org.eclipse.kapua.commons.configuration.CachingServiceConfigRepository;
import org.eclipse.kapua.commons.configuration.ResourceLimitedServiceConfigurationManagerImpl;
import org.eclipse.kapua.commons.configuration.RootUserTester;
import org.eclipse.kapua.commons.configuration.ServiceConfigImplJpaRepository;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManager;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManagerCachingWrapper;
import org.eclipse.kapua.commons.configuration.UsedEntitiesCounterImpl;
import org.eclipse.kapua.commons.core.AbstractKapuaModule;
import org.eclipse.kapua.commons.core.ServiceModule;
import org.eclipse.kapua.commons.event.ServiceEventHouseKeeperFactoryImpl;
import org.eclipse.kapua.commons.jpa.EntityCacheFactory;
import org.eclipse.kapua.commons.jpa.EventStorer;
import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration;
import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory;
Expand All @@ -38,7 +31,6 @@
import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordRepository;
import org.eclipse.kapua.commons.service.event.store.internal.EventStoreServiceImpl;
import org.eclipse.kapua.commons.service.internal.cache.NamedEntityCache;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.event.ServiceEventBus;
import org.eclipse.kapua.event.ServiceEventBusException;
import org.eclipse.kapua.model.domain.Actions;
Expand All @@ -53,8 +45,6 @@

import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.multibindings.ClassMapKey;
import com.google.inject.multibindings.ProvidesIntoMap;
import com.google.inject.multibindings.ProvidesIntoSet;

/**
Expand Down Expand Up @@ -136,34 +126,6 @@ AccountService accountService(AccountRepository accountRepository,
accountMapper);
}

@ProvidesIntoMap
@ClassMapKey(AccountService.class)
@Singleton
ServiceConfigurationManager accountServiceConfigurationManager(
AccountFactory factory,
RootUserTester rootUserTester,
AccountRelativeFinder accountRelativeFinder,
AccountRepository accountRepository,
KapuaJpaRepositoryConfiguration jpaRepoConfig,
EntityCacheFactory entityCacheFactory,
XmlUtil xmlUtil
) {
return new ServiceConfigurationManagerCachingWrapper(
new ResourceLimitedServiceConfigurationManagerImpl(
AccountService.class.getName(),
new CachingServiceConfigRepository(
new ServiceConfigImplJpaRepository(jpaRepoConfig),
entityCacheFactory.createCache("AbstractKapuaConfigurableServiceCacheId")
),
rootUserTester,
accountRelativeFinder,
new UsedEntitiesCounterImpl(
factory,
accountRepository),
xmlUtil
));
}

@Provides
@Singleton
AccountRepository accountRepository(NamedCacheFactory namedCacheFactory, KapuaJpaRepositoryConfiguration jpaRepoConfig) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 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.service.account.internal;

import javax.inject.Singleton;

import org.eclipse.kapua.commons.configuration.AccountRelativeFinder;
import org.eclipse.kapua.commons.configuration.CachingServiceConfigRepository;
import org.eclipse.kapua.commons.configuration.ResourceLimitedServiceConfigurationManagerImpl;
import org.eclipse.kapua.commons.configuration.RootUserTester;
import org.eclipse.kapua.commons.configuration.ServiceConfigImplJpaRepository;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManager;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManagerCachingWrapper;
import org.eclipse.kapua.commons.configuration.UsedEntitiesCounterImpl;
import org.eclipse.kapua.commons.core.AbstractKapuaModule;
import org.eclipse.kapua.commons.jpa.EntityCacheFactory;
import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.service.account.AccountFactory;
import org.eclipse.kapua.service.account.AccountRepository;
import org.eclipse.kapua.service.account.AccountService;

import com.google.inject.Module;
import com.google.inject.multibindings.ClassMapKey;
import com.google.inject.multibindings.ProvidesIntoMap;

/**
* This module provides the ServiceConfigurationManager for the AccountService.
* <br><br>
* Unfortunately Guice does not support overriding for Map binder entries, therefore if you need to change the behaviour of this ServiceConfigurationManager, just skip this module and define the new
* instance in a separate one
*/
public class AccountServiceConfigurationManagerModule extends AbstractKapuaModule implements Module {

@Override
protected void configureModule() {
}

@ProvidesIntoMap
@ClassMapKey(AccountService.class)
@Singleton
ServiceConfigurationManager accountServiceConfigurationManager(
AccountFactory factory,
RootUserTester rootUserTester,
AccountRelativeFinder accountRelativeFinder,
AccountRepository accountRepository,
KapuaJpaRepositoryConfiguration jpaRepoConfig,
EntityCacheFactory entityCacheFactory,
XmlUtil xmlUtil
) {
return new ServiceConfigurationManagerCachingWrapper(
new ResourceLimitedServiceConfigurationManagerImpl(
AccountService.class.getName(),
new CachingServiceConfigRepository(
new ServiceConfigImplJpaRepository(jpaRepoConfig),
entityCacheFactory.createCache("AbstractKapuaConfigurableServiceCacheId")
),
rootUserTester,
accountRelativeFinder,
new UsedEntitiesCounterImpl(
factory,
accountRepository),
xmlUtil
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,13 @@

import javax.inject.Singleton;

import org.eclipse.kapua.commons.configuration.CachingServiceConfigRepository;
import org.eclipse.kapua.commons.configuration.RootUserTester;
import org.eclipse.kapua.commons.configuration.ServiceConfigImplJpaRepository;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManager;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManagerCachingWrapper;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManagerImpl;
import org.eclipse.kapua.commons.core.AbstractKapuaModule;
import org.eclipse.kapua.commons.jpa.EntityCacheFactory;
import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration;
import org.eclipse.kapua.commons.jpa.KapuaJpaTxManagerFactory;
import org.eclipse.kapua.commons.model.domains.Domains;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.model.domain.Actions;
import org.eclipse.kapua.model.domain.Domain;
import org.eclipse.kapua.model.domain.DomainEntry;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.account.AccountService;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
Expand All @@ -48,17 +39,13 @@
import org.eclipse.kapua.service.datastore.internal.converter.QueryConverterImpl;
import org.eclipse.kapua.service.datastore.internal.mediator.DatastoreUtils;
import org.eclipse.kapua.service.datastore.internal.setting.DatastoreSettings;
import org.eclipse.kapua.service.datastore.internal.setting.DatastoreSettingsKey;
import org.eclipse.kapua.service.elasticsearch.client.ElasticsearchClientProvider;
import org.eclipse.kapua.service.elasticsearch.client.configuration.ElasticsearchClientConfiguration;
import org.eclipse.kapua.service.elasticsearch.client.rest.MetricsEsClient;
import org.eclipse.kapua.service.elasticsearch.client.rest.RestElasticsearchClientProvider;
import org.eclipse.kapua.service.storable.model.id.StorableIdFactory;
import org.eclipse.kapua.storage.TxContext;

import com.google.inject.Provides;
import com.google.inject.multibindings.ClassMapKey;
import com.google.inject.multibindings.ProvidesIntoMap;
import com.google.inject.multibindings.ProvidesIntoSet;

public class DatastoreModule extends AbstractKapuaModule {
Expand Down Expand Up @@ -136,31 +123,4 @@ MessageStoreService messageStoreService(
metricsDatastore,
datastoreSettings);
}

@ProvidesIntoMap
@ClassMapKey(MessageStoreService.class)
@Singleton
ServiceConfigurationManager messageStoreServiceConfigurationManager(
RootUserTester rootUserTester,
KapuaJpaRepositoryConfiguration jpaRepoConfig,
DatastoreSettings datastoreSettings,
EntityCacheFactory entityCacheFactory,
XmlUtil xmlUtil
) {
return new ServiceConfigurationManagerCachingWrapper(new ServiceConfigurationManagerImpl(
MessageStoreService.class.getName(),
new CachingServiceConfigRepository(
new ServiceConfigImplJpaRepository(jpaRepoConfig),
entityCacheFactory.createCache("AbstractKapuaConfigurableServiceCacheId")
),
rootUserTester,
xmlUtil
) {

@Override
public boolean isServiceEnabled(TxContext txContext, KapuaId scopeId) {
return !datastoreSettings.getBoolean(DatastoreSettingsKey.DISABLE_DATASTORE, false);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 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.service.datastore.internal;

import javax.inject.Singleton;

import org.eclipse.kapua.commons.configuration.CachingServiceConfigRepository;
import org.eclipse.kapua.commons.configuration.RootUserTester;
import org.eclipse.kapua.commons.configuration.ServiceConfigImplJpaRepository;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManager;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManagerCachingWrapper;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManagerImpl;
import org.eclipse.kapua.commons.core.AbstractKapuaModule;
import org.eclipse.kapua.commons.jpa.EntityCacheFactory;
import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.datastore.MessageStoreService;
import org.eclipse.kapua.service.datastore.internal.setting.DatastoreSettings;
import org.eclipse.kapua.service.datastore.internal.setting.DatastoreSettingsKey;
import org.eclipse.kapua.storage.TxContext;

import com.google.inject.Module;
import com.google.inject.multibindings.ClassMapKey;
import com.google.inject.multibindings.ProvidesIntoMap;

/**
* This module provides the ServiceConfigurationManager for the MessageStoreService.
* <br><br>
* Unfortunately Guice does not support overriding for Map binder entries, therefore if you need to change the behaviour of this ServiceConfigurationManager, just skip this module and define the new
* instance in a separate one
*/
public class MessageStoreServiceConfigurationManagerModule extends AbstractKapuaModule implements Module {

@Override
protected void configureModule() {
}

@ProvidesIntoMap
@ClassMapKey(MessageStoreService.class)
@Singleton
ServiceConfigurationManager messageStoreServiceConfigurationManager(
RootUserTester rootUserTester,
KapuaJpaRepositoryConfiguration jpaRepoConfig,
DatastoreSettings datastoreSettings,
EntityCacheFactory entityCacheFactory,
XmlUtil xmlUtil
) {
return new ServiceConfigurationManagerCachingWrapper(new ServiceConfigurationManagerImpl(
MessageStoreService.class.getName(),
new CachingServiceConfigRepository(
new ServiceConfigImplJpaRepository(jpaRepoConfig),
entityCacheFactory.createCache("AbstractKapuaConfigurableServiceCacheId")
),
rootUserTester,
xmlUtil
) {

@Override
public boolean isServiceEnabled(TxContext txContext, KapuaId scopeId) {
return !datastoreSettings.getBoolean(DatastoreSettingsKey.DISABLE_DATASTORE, false);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 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.service.device.registry;

import java.util.Map;

import javax.inject.Singleton;

import org.eclipse.kapua.commons.configuration.CachingServiceConfigRepository;
import org.eclipse.kapua.commons.configuration.RootUserTester;
import org.eclipse.kapua.commons.configuration.ServiceConfigImplJpaRepository;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManager;
import org.eclipse.kapua.commons.configuration.ServiceConfigurationManagerCachingWrapper;
import org.eclipse.kapua.commons.core.AbstractKapuaModule;
import org.eclipse.kapua.commons.jpa.EntityCacheFactory;
import org.eclipse.kapua.commons.jpa.KapuaJpaRepositoryConfiguration;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.service.device.authentication.api.DeviceConnectionCredentialAdapter;
import org.eclipse.kapua.service.device.registry.connection.DeviceConnectionService;
import org.eclipse.kapua.service.device.registry.connection.internal.DeviceConnectionServiceConfigurationManager;

import com.google.inject.Module;
import com.google.inject.multibindings.ClassMapKey;
import com.google.inject.multibindings.ProvidesIntoMap;

/**
* This module provides the ServiceConfigurationManager for the DeviceRegistryService.
* <br><br>
* Unfortunately Guice does not support overriding for Map binder entries, therefore if you need to change the behaviour of this ServiceConfigurationManager, just skip this module and define the new
* instance in a separate one
*/
public class DeviceConnectionServiceConfigurationManagerModule extends AbstractKapuaModule implements Module {

@Override
protected void configureModule() {
}

@ProvidesIntoMap
@ClassMapKey(DeviceConnectionService.class)
@Singleton
ServiceConfigurationManager deviceConnectionServiceConfigurationManager(
RootUserTester rootUserTester,
KapuaJpaRepositoryConfiguration jpaRepoConfig,
Map<String, DeviceConnectionCredentialAdapter> availableDeviceConnectionAdapters,
EntityCacheFactory entityCacheFactory,
KapuaDeviceRegistrySettings kapuaDeviceRegistrySettings,
XmlUtil xmlUtil) {
return new ServiceConfigurationManagerCachingWrapper(
new DeviceConnectionServiceConfigurationManager(
new CachingServiceConfigRepository(
new ServiceConfigImplJpaRepository(jpaRepoConfig),
entityCacheFactory.createCache("AbstractKapuaConfigurableServiceCacheId")
),
rootUserTester,
availableDeviceConnectionAdapters,
kapuaDeviceRegistrySettings,
xmlUtil)
);
}
}
Loading

0 comments on commit 72c8f63

Please sign in to comment.