Feature horizontal scalability (#305)
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
committed by
Kai Zimmermann
parent
07cb62a3dd
commit
866bc72114
@@ -13,36 +13,44 @@ import java.util.concurrent.Executors;
|
||||
|
||||
import org.eclipse.hawkbit.api.ArtifactUrlHandlerProperties;
|
||||
import org.eclipse.hawkbit.api.PropertyBasedArtifactUrlHandler;
|
||||
import org.eclipse.hawkbit.cache.CacheConstants;
|
||||
import org.eclipse.hawkbit.cache.TenancyCacheManager;
|
||||
import org.eclipse.hawkbit.cache.DefaultDownloadIdCache;
|
||||
import org.eclipse.hawkbit.cache.DownloadIdCache;
|
||||
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyResolver;
|
||||
import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.eclipse.hawkbit.repository.test.util.JpaTestRepositoryManagement;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestRepositoryManagement;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.eclipse.hawkbit.security.DdiSecurityProperties;
|
||||
import org.eclipse.hawkbit.security.SecurityContextTenantAware;
|
||||
import org.eclipse.hawkbit.security.SpringSecurityAuditorAware;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.guava.GuavaCacheManager;
|
||||
import org.springframework.cloud.bus.ConditionalOnBusEnabled;
|
||||
import org.springframework.cloud.bus.ServiceMatcher;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AdviceMode;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.context.event.SimpleApplicationEventMulticaster;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.messaging.converter.MessageConverter;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import com.google.common.eventbus.AsyncEventBus;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.mongodb.MongoClientOptions;
|
||||
|
||||
/**
|
||||
@@ -59,8 +67,9 @@ import com.mongodb.MongoClientOptions;
|
||||
@EnableAutoConfiguration
|
||||
public class TestConfiguration implements AsyncConfigurer {
|
||||
@Bean
|
||||
public TestRepositoryManagement testRepositoryManagement() {
|
||||
return new JpaTestRepositoryManagement();
|
||||
public TestRepositoryManagement testRepositoryManagement(final SystemSecurityContext systemSecurityContext,
|
||||
final SystemManagement systemManagement) {
|
||||
return new JpaTestRepositoryManagement(cacheManager(), systemSecurityContext, systemManagement);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -87,7 +96,7 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TenancyCacheManager cacheManager() {
|
||||
public TenantAwareCacheManager cacheManager() {
|
||||
return new TenantAwareCacheManager(new GuavaCacheManager(), tenantAware());
|
||||
}
|
||||
|
||||
@@ -96,19 +105,21 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
*
|
||||
* @return the cache
|
||||
*/
|
||||
@Bean(name = CacheConstants.DOWNLOAD_ID_CACHE)
|
||||
public Cache downloadIdCache() {
|
||||
return cacheManager().getDirectCache(CacheConstants.DOWNLOAD_ID_CACHE);
|
||||
@Bean
|
||||
public DownloadIdCache downloadIdCache() {
|
||||
return new DefaultDownloadIdCache(cacheManager());
|
||||
}
|
||||
|
||||
@Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
|
||||
public SimpleApplicationEventMulticaster applicationEventMulticaster() {
|
||||
final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new SimpleApplicationEventMulticaster();
|
||||
simpleApplicationEventMulticaster.setTaskExecutor(asyncExecutor());
|
||||
return simpleApplicationEventMulticaster;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EventBus eventBus() {
|
||||
return new AsyncEventBus(asyncExecutor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EventBusHolder eventBusHolder() {
|
||||
return EventBusHolder.getInstance();
|
||||
public EventPublisherHolder eventBusHolder() {
|
||||
return EventPublisherHolder.getInstance();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -140,4 +151,23 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
return new VirtualPropertyResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ServiceMatcher serviceMatcher(final ApplicationContext applicationContext) {
|
||||
final ServiceMatcher serviceMatcher = new ServiceMatcher();
|
||||
serviceMatcher.setMatcher(new AntPathMatcher(":"));
|
||||
serviceMatcher.setApplicationContext(applicationContext);
|
||||
return serviceMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the protostuff io message converter
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnBusEnabled
|
||||
public MessageConverter busProtoBufConverter() {
|
||||
return new BusProtoStuffMessageConverter();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.junit.runners.model.FrameworkMethod;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.bus.ServiceMatcher;
|
||||
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.auditing.AuditingHandler;
|
||||
@@ -51,6 +53,7 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.gridfs.GridFsOperations;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
@@ -68,7 +71,7 @@ import de.flapdoodle.embed.mongo.MongodExecutable;
|
||||
@WebAppConfiguration
|
||||
@ActiveProfiles({ "test" })
|
||||
@WithUser(principal = "bumlux", allSpPermissions = true, authorities = { CONTROLLER_ROLE, SYSTEM_ROLE })
|
||||
@SpringApplicationConfiguration(classes = { TestConfiguration.class })
|
||||
@SpringApplicationConfiguration(classes = { TestConfiguration.class, TestSupportBinderAutoConfiguration.class })
|
||||
// destroy the context after each test class because otherwise we get problem
|
||||
// when context is
|
||||
// refreshed we e.g. get two instances of CacheManager which leads to very
|
||||
@@ -80,6 +83,12 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
|
||||
protected static final Pageable pageReq = new PageRequest(0, 400);
|
||||
|
||||
/**
|
||||
* Constant for MediaType HAL with encoding UTF-8. Necessary since Spring
|
||||
* version 4.3.2 @see https://jira.spring.io/browse/SPR-14577
|
||||
*/
|
||||
protected static final String APPLICATION_JSON_HAL_UTF = MediaTypes.HAL_JSON + ";charset=UTF-8";
|
||||
|
||||
/**
|
||||
* Number of {@link DistributionSetType}s that exist in every test case. One
|
||||
* generated by using
|
||||
@@ -162,6 +171,9 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
||||
@Autowired
|
||||
protected MongodExecutable mongodExecutable;
|
||||
|
||||
@Autowired
|
||||
protected ServiceMatcher serviceMatcher;
|
||||
|
||||
@Rule
|
||||
public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule();
|
||||
|
||||
|
||||
@@ -15,20 +15,34 @@ import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class JpaTestRepositoryManagement implements TestRepositoryManagement {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JpaTestRepositoryManagement.class);
|
||||
@Autowired
|
||||
private TenantAwareCacheManager cacheManager;
|
||||
|
||||
@Autowired
|
||||
private SystemSecurityContext systemSecurityContext;
|
||||
private final TenantAwareCacheManager cacheManager;
|
||||
|
||||
@Autowired
|
||||
private SystemManagement systemManagement;
|
||||
private final SystemSecurityContext systemSecurityContext;
|
||||
|
||||
private final SystemManagement systemManagement;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param cacheManager
|
||||
* the cachemanager
|
||||
* @param systemSecurityContext
|
||||
* the systemSecurityContext
|
||||
* @param systemManagement
|
||||
* the systemManagement
|
||||
*/
|
||||
public JpaTestRepositoryManagement(final TenantAwareCacheManager cacheManager,
|
||||
final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement) {
|
||||
this.cacheManager = cacheManager;
|
||||
this.systemSecurityContext = systemSecurityContext;
|
||||
this.systemManagement = systemManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.concurrent.Callable;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
|
||||
import org.eclipse.hawkbit.im.authentication.UserPrincipal;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder;
|
||||
import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
Reference in New Issue
Block a user