Remove some of the field injections (Sonar recomendtion) (#2218)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -15,25 +15,23 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactEncryptionUnsupportedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Service responsible for encryption operations.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // singleton holder ensures static access to spring resources in some places
|
||||
public final class ArtifactEncryptionService {
|
||||
|
||||
private static final ArtifactEncryptionService SINGLETON = new ArtifactEncryptionService();
|
||||
|
||||
@Autowired(required = false)
|
||||
private ArtifactEncryption artifactEncryption;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ArtifactEncryptionSecretsStore artifactEncryptionSecretsStore;
|
||||
|
||||
private ArtifactEncryptionService() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the artifact encryption service singleton instance
|
||||
*/
|
||||
@@ -41,6 +39,16 @@ public final class ArtifactEncryptionService {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired(required = false) // spring setter injection
|
||||
public void setArtifactEncryption(final ArtifactEncryption artifactEncryption) {
|
||||
this.artifactEncryption = artifactEncryption;
|
||||
}
|
||||
|
||||
@Autowired(required = false) // spring setter injection
|
||||
public void setArtifactEncryptionSecretsStore(final ArtifactEncryptionSecretsStore artifactEncryptionSecretsStore) {
|
||||
this.artifactEncryptionSecretsStore = artifactEncryptionSecretsStore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if required encryption and secrets store beans are present.
|
||||
*
|
||||
@@ -51,8 +59,7 @@ public final class ArtifactEncryptionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates encryption secrets and saves them in secret store by software
|
||||
* module id reference.
|
||||
* Generates encryption secrets and saves them in secret store by software module id reference.
|
||||
*
|
||||
* @param smId software module id
|
||||
*/
|
||||
@@ -116,7 +123,6 @@ public final class ArtifactEncryptionService {
|
||||
requiredSecretsKey);
|
||||
requiredSecretsValue.ifPresent(secretValue -> requiredSecrets.put(requiredSecretsKey, secretValue));
|
||||
}
|
||||
|
||||
return requiredSecrets;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* A singleton bean which holds the event entity manager to have autowiring in the events.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class EventEntityManagerHolder {
|
||||
|
||||
private static final EventEntityManagerHolder SINGLETON = new EventEntityManagerHolder();
|
||||
|
||||
@Autowired
|
||||
private EventEntityManager eventEntityManager;
|
||||
|
||||
/**
|
||||
@@ -31,6 +31,11 @@ public final class EventEntityManagerHolder {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setEventEntityManager(final EventEntityManager eventEntityManager) {
|
||||
this.eventEntityManager = eventEntityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the eventEntityManager
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
*/
|
||||
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
|
||||
@Getter
|
||||
@SuppressWarnings("java:S6548") // singleton holder ensures static access to spring resources in some places
|
||||
public final class RsqlConfigHolder {
|
||||
|
||||
private static final RsqlConfigHolder SINGLETON = new RsqlConfigHolder();
|
||||
|
||||
@@ -18,21 +18,18 @@ import org.springframework.cloud.bus.ServiceMatcher;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
/**
|
||||
* A singleton bean which holds the event publisher and service origin Id in
|
||||
* order to publish remote application events. It can be used in beans not
|
||||
* instantiated by spring e.g. JPA entities which cannot be auto-wired.
|
||||
* A singleton bean which holds the event publisher and service origin id in order to publish remote application events.
|
||||
* It can be used in beans not instantiated by spring e.g. JPA entities which cannot be auto-wired.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class EventPublisherHolder {
|
||||
|
||||
private static final EventPublisherHolder SINGLETON = new EventPublisherHolder();
|
||||
|
||||
@Getter
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
@Autowired(required = false)
|
||||
private ServiceMatcher serviceMatcher;
|
||||
@Autowired
|
||||
private BusProperties bus;
|
||||
|
||||
/**
|
||||
@@ -42,9 +39,24 @@ public final class EventPublisherHolder {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setApplicationEventPublisher(final ApplicationEventPublisher eventPublisher) {
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
@Autowired(required = false) // spring setter injection
|
||||
public void setServiceMatcher(final ServiceMatcher serviceMatcher) {
|
||||
this.serviceMatcher = serviceMatcher;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setBusProperties(final BusProperties bus) {
|
||||
this.bus = bus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the service origin Id coming either from {@link ServiceMatcher}
|
||||
* when available or {@link BusProperties} otherwise.
|
||||
* @return the service origin Id coming either from {@link ServiceMatcher} when available or {@link BusProperties}
|
||||
* otherwise.
|
||||
*/
|
||||
public String getApplicationId() {
|
||||
String id = null;
|
||||
|
||||
@@ -16,22 +16,27 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* A singleton bean which holds {@link SystemSecurityContext} service and makes
|
||||
* it accessible to beans which are not managed by spring, e.g. JPA entities.
|
||||
* A singleton bean which holds {@link SystemSecurityContext} service and makes it accessible to beans which are not
|
||||
* managed by spring, e.g. JPA entities.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class SystemSecurityContextHolder {
|
||||
|
||||
private static final SystemSecurityContextHolder INSTANCE = new SystemSecurityContextHolder();
|
||||
private static final SystemSecurityContextHolder SINGLETON = new SystemSecurityContextHolder();
|
||||
|
||||
@Getter
|
||||
@Autowired
|
||||
private SystemSecurityContext systemSecurityContext;
|
||||
|
||||
/**
|
||||
* @return the singleton {@link SystemSecurityContextHolder} instance
|
||||
*/
|
||||
public static SystemSecurityContextHolder getInstance() {
|
||||
return INSTANCE;
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setSystemSecurityContext(final SystemSecurityContext systemSecurityContext) {
|
||||
this.systemSecurityContext = systemSecurityContext;
|
||||
}
|
||||
}
|
||||
@@ -16,23 +16,27 @@ import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* A singleton bean which holds {@link TenantConfigurationManagement} service
|
||||
* and makes it accessible to beans which are not managed by spring, e.g. JPA
|
||||
* entities.
|
||||
* A singleton bean which holds {@link TenantConfigurationManagement} service and makes it accessible to beans which are
|
||||
* not managed by spring, e.g. JPA entities.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class TenantConfigurationManagementHolder {
|
||||
|
||||
private static final TenantConfigurationManagementHolder INSTANCE = new TenantConfigurationManagementHolder();
|
||||
private static final TenantConfigurationManagementHolder SINGLETON = new TenantConfigurationManagementHolder();
|
||||
|
||||
@Getter
|
||||
@Autowired
|
||||
private TenantConfigurationManagement tenantConfigurationManagement;
|
||||
|
||||
/**
|
||||
* @return the singleton {@link TenantConfigurationManagementHolder} instance
|
||||
*/
|
||||
public static TenantConfigurationManagementHolder getInstance() {
|
||||
return INSTANCE;
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setTenantConfigurationManagement(final TenantConfigurationManagement tenantConfigurationManagement) {
|
||||
this.tenantConfigurationManagement = tenantConfigurationManagement;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -19,11 +20,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* entities which cannot be autowired.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class AfterTransactionCommitExecutorHolder {
|
||||
|
||||
private static final AfterTransactionCommitExecutorHolder SINGLETON = new AfterTransactionCommitExecutorHolder();
|
||||
|
||||
@Autowired
|
||||
@Getter
|
||||
private AfterTransactionCommitExecutor afterCommit;
|
||||
|
||||
/**
|
||||
@@ -33,17 +35,8 @@ public final class AfterTransactionCommitExecutorHolder {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the afterCommit
|
||||
*/
|
||||
public AfterTransactionCommitExecutor getAfterCommit() {
|
||||
return afterCommit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param afterCommit the afterCommit to set
|
||||
*/
|
||||
public void setAfterCommit(final AfterTransactionCommitExecutor afterCommit) {
|
||||
@Autowired // spring setter injection
|
||||
public void setAfterTransactionCommitExecutor(final AfterTransactionCommitExecutor afterCommit) {
|
||||
this.afterCommit = afterCommit;
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,16 @@ package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.jpa.EntityInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* A singleton bean which holds the {@link EntityInterceptor} to have all
|
||||
* interceptors in spring beans.
|
||||
* A singleton bean which holds the {@link EntityInterceptor} to have all interceptors in spring beans.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class EntityInterceptorHolder {
|
||||
|
||||
private static final EntityInterceptorHolder SINGLETON = new EntityInterceptorHolder();
|
||||
@@ -26,10 +29,6 @@ public final class EntityInterceptorHolder {
|
||||
@Autowired(required = false)
|
||||
private final List<EntityInterceptor> entityInterceptors = new ArrayList<>();
|
||||
|
||||
private EntityInterceptorHolder() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entity intreceptor holder singleton instance
|
||||
*/
|
||||
@@ -40,4 +39,4 @@ public final class EntityInterceptorHolder {
|
||||
public List<EntityInterceptor> getEntityInterceptors() {
|
||||
return entityInterceptors;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -16,25 +18,24 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* A singleton bean which holds the {@link SecurityTokenGenerator} and make it
|
||||
* accessible to beans which are not managed by spring, e.g. JPA entities.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class SecurityTokenGeneratorHolder {
|
||||
|
||||
private static final SecurityTokenGeneratorHolder INSTANCE = new SecurityTokenGeneratorHolder();
|
||||
private static final SecurityTokenGeneratorHolder SINGLETON = new SecurityTokenGeneratorHolder();
|
||||
|
||||
@Autowired
|
||||
private SecurityTokenGenerator securityTokenGenerator;
|
||||
|
||||
/**
|
||||
* private constructor.
|
||||
*/
|
||||
private SecurityTokenGeneratorHolder() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a singleton instance of the security token generator holder.
|
||||
*/
|
||||
public static SecurityTokenGeneratorHolder getInstance() {
|
||||
return INSTANCE;
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setSecurityTokenGenerator(final SecurityTokenGenerator securityTokenGenerator) {
|
||||
this.securityTokenGenerator = securityTokenGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,5 +46,4 @@ public final class SecurityTokenGeneratorHolder {
|
||||
public String generateToken() {
|
||||
return securityTokenGenerator.generateToken();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -16,21 +20,24 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* A singleton bean which holds {@link TenantAware} service and makes it
|
||||
* accessible to beans which are not managed by spring, e.g. JPA entities.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class TenantAwareHolder {
|
||||
|
||||
private static final TenantAwareHolder INSTANCE = new TenantAwareHolder();
|
||||
private static final TenantAwareHolder SINGLETON = new TenantAwareHolder();
|
||||
|
||||
@Autowired
|
||||
private TenantAware tenantAware;
|
||||
|
||||
private TenantAwareHolder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the singleton {@link TenantAwareHolder} instance
|
||||
*/
|
||||
public static TenantAwareHolder getInstance() {
|
||||
return INSTANCE;
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setTenantAware(final TenantAware tenantAware) {
|
||||
this.tenantAware = tenantAware;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,4 +46,4 @@ public final class TenantAwareHolder {
|
||||
public TenantAware getTenantAware() {
|
||||
return tenantAware;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@ import jakarta.persistence.EntityManagerFactory;
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.persistence.sessions.Session;
|
||||
import org.eclipse.persistence.tools.profiler.PerformanceMonitor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -48,11 +50,13 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
*
|
||||
* It encapsulates reporting the Eclipselink {@link PerformanceMonitor} statistics to the {@link MeterRegistry} and the Spring autoconfiguration.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public class Statistics {
|
||||
|
||||
public static final String METER_PREFIX = "eclipselink.";
|
||||
|
||||
private static final Statistics INSTANCE = new Statistics();
|
||||
private static final Statistics SINGLETON = new Statistics();
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile("(?<type>(Counter|Timer)+):(?<key>[^ -]+)");
|
||||
private static final Map<String, Long> REPORTED_TIMER_VALUES = new HashMap<>();
|
||||
@@ -68,7 +72,7 @@ public class Statistics {
|
||||
* @return the singleton {@link Statistics} instance
|
||||
*/
|
||||
public static Statistics getInstance() {
|
||||
return INSTANCE;
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -80,36 +84,36 @@ public class Statistics {
|
||||
getPerformanceMonitor(entityManagerFactory).setDumpTime(dumpPeriod);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Autowired // spring setter injection
|
||||
public void setMeterRegistry(final MeterRegistry meterRegistry) {
|
||||
this.meterRegistry = meterRegistry;
|
||||
}
|
||||
|
||||
// flushes the statistics to the meter registry (if needed)
|
||||
public static void flush() {
|
||||
final MeterRegistry meterRegistry = INSTANCE.meterRegistry;
|
||||
final MeterRegistry meterRegistry = SINGLETON.meterRegistry;
|
||||
if (meterRegistry == null) {
|
||||
// not a bean (i.e. no performance monitoring) is enabled or no meter registry available
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (INSTANCE) {
|
||||
if (INSTANCE.flushing) {
|
||||
synchronized (SINGLETON) {
|
||||
if (SINGLETON.flushing) {
|
||||
// wait for flushing
|
||||
do {
|
||||
try {
|
||||
INSTANCE.wait(1000);
|
||||
SINGLETON.wait(1000);
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
} while (INSTANCE.flushing);
|
||||
} while (SINGLETON.flushing);
|
||||
// flushed
|
||||
return;
|
||||
}
|
||||
// flush
|
||||
INSTANCE.flushing = true;
|
||||
SINGLETON.flushing = true;
|
||||
}
|
||||
INSTANCE.flush0();
|
||||
SINGLETON.flush0();
|
||||
}
|
||||
|
||||
@Scheduled(initialDelayString = "${hawkbit.jpa.statistics.flush.fixedDelay:60000}", fixedDelayString = "${hawkbit.jpa.statistics.flush.fixedDelay:60000}")
|
||||
|
||||
@@ -10,7 +10,10 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
@@ -31,11 +34,13 @@ import org.springframework.context.annotation.Configuration;
|
||||
* <li>(?) When using in test the metrics MAYBE shall be enabled with @AutoConfigureObservability(tracing = false)</li>
|
||||
* </ol>
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public class Statistics {
|
||||
|
||||
public static final String METER_PREFIX = "hibernate.";
|
||||
|
||||
private static final Statistics INSTANCE = new Statistics();
|
||||
private static final Statistics SINGLETON = new Statistics();
|
||||
|
||||
// if meter registry is unavailable, the statistics will not send to metrics
|
||||
@Getter
|
||||
@@ -45,17 +50,7 @@ public class Statistics {
|
||||
* @return the singleton {@link Statistics} instance
|
||||
*/
|
||||
public static Statistics getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setMeterRegistry(final MeterRegistry meterRegistry) {
|
||||
this.meterRegistry = meterRegistry;
|
||||
}
|
||||
|
||||
// flushes the statistics to the meter registry (if needed)
|
||||
public static void flush() {
|
||||
// nothing to do for Hibernate
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
// autoconfigure after CompositeMeterRegistryAutoConfiguration, so when the autoconfiguration is being processed the MeterRegistry
|
||||
@@ -74,4 +69,14 @@ public class Statistics {
|
||||
return Statistics.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setMeterRegistry(final MeterRegistry meterRegistry) {
|
||||
this.meterRegistry = meterRegistry;
|
||||
}
|
||||
|
||||
// flushes the statistics to the meter registry (if needed)
|
||||
public static void flush() {
|
||||
// nothing to do for Hibernate
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public abstract class AbstractRSQLVisitor<A extends Enum<A> & RsqlQueryField> {
|
||||
this.rsqlQueryFieldType = rsqlQueryFieldType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("java:S1066") // java:S1066 - more readable with separate "if" statements
|
||||
protected QuertPath getQuertPath(final ComparisonNode node) {
|
||||
final int firstSeparatorIndex = node.getSelector().indexOf(RsqlQueryField.SUB_ATTRIBUTE_SEPARATOR);
|
||||
final String enumName = (firstSeparatorIndex == -1
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.criteria.Join;
|
||||
import jakarta.persistence.criteria.ListJoin;
|
||||
import jakarta.persistence.criteria.SetJoin;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
@@ -28,18 +29,14 @@ import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
/**
|
||||
* Utility class for {@link Action}s {@link Specification}s. The class provides
|
||||
* Spring Data JPQL Specifications.
|
||||
* Utility class for {@link Action}s {@link Specification}s. The class provides Spring Data JPQL Specifications.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class ActionSpecifications {
|
||||
|
||||
private ActionSpecifications() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
public static Specification<JpaAction> byTargetIdAndIsActive(final Long targetId) {
|
||||
return (root, query, cb) -> cb.and(
|
||||
cb.equal(root.get(JpaAction_.target).get(JpaTarget_.id), targetId),
|
||||
cb.equal(root.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id), targetId),
|
||||
cb.equal(root.get(JpaAction_.active), true));
|
||||
}
|
||||
|
||||
@@ -49,7 +46,7 @@ public final class ActionSpecifications {
|
||||
|
||||
public static Specification<JpaAction> byTargetIdAndIsActiveAndStatus(final Long targetId, final Action.Status status) {
|
||||
return (root, query, cb) -> cb.and(
|
||||
cb.equal(root.get(JpaAction_.target).get(JpaTarget_.id), targetId),
|
||||
cb.equal(root.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id), targetId),
|
||||
cb.equal(root.get(JpaAction_.active), true),
|
||||
cb.equal(root.get(JpaAction_.status), status));
|
||||
}
|
||||
@@ -67,15 +64,6 @@ public final class ActionSpecifications {
|
||||
cb.equal(root.get(JpaAction_.status), status));
|
||||
}
|
||||
|
||||
public static Specification<JpaAction> byTargetIdsAndActiveAndStatusAndDSNotRequiredMigrationStep(
|
||||
final List<Long> targetIds, final boolean active, final Action.Status status) {
|
||||
return (root, query, cb) -> cb.and(
|
||||
root.get(JpaAction_.target).in(targetIds),
|
||||
cb.equal(root.get(JpaAction_.active), active),
|
||||
cb.equal(root.get(JpaAction_.status), status),
|
||||
cb.equal(root.get(JpaAction_.distributionSet).get(JpaDistributionSet_.requiredMigrationStep), false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns active actions by target controller that has null or non-null depending on <code>isNull</code> value.
|
||||
*
|
||||
@@ -84,73 +72,64 @@ public final class ActionSpecifications {
|
||||
* @return the matching action s.
|
||||
*/
|
||||
public static Specification<JpaAction> byTargetControllerIdAndActiveAndWeightIsNull(final String controllerId, final boolean isNull) {
|
||||
return (root, query, cb) ->
|
||||
cb.and(
|
||||
cb.equal(root.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId),
|
||||
cb.equal(root.get(JpaAction_.active), true),
|
||||
isNull ? cb.isNull(root.get(JpaAction_.weight)) : cb.isNotNull(root.get(JpaAction_.weight)));
|
||||
return (root, query, cb) -> cb.and(
|
||||
cb.equal(root.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId),
|
||||
cb.equal(root.get(JpaAction_.active), true),
|
||||
isNull ? cb.isNull(root.get(JpaAction_.weight)) : cb.isNotNull(root.get(JpaAction_.weight)));
|
||||
}
|
||||
|
||||
public static Specification<JpaAction> byDistributionSetId(final Long distributionSetId) {
|
||||
return (root, query, cb) -> cb.equal(root.get(JpaAction_.distributionSet).get(JpaTarget_.id), distributionSetId);
|
||||
return (root, query, cb) -> cb.equal(root.get(JpaAction_.distributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId);
|
||||
}
|
||||
|
||||
public static Specification<JpaAction> byDistributionSetIdAndActive(final Long distributionSetId) {
|
||||
return (root, query, cb) -> cb.and(
|
||||
cb.equal(root.get(JpaAction_.distributionSet).get(JpaTarget_.id), distributionSetId),
|
||||
cb.equal(root.get(JpaAction_.distributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId),
|
||||
cb.equal(root.get(JpaAction_.active), true));
|
||||
}
|
||||
|
||||
public static Specification<JpaAction> byDistributionSetIdAndActiveAndStatusIsNot(
|
||||
final Long distributionSetId, final Action.Status status) {
|
||||
public static Specification<JpaAction> byDistributionSetIdAndActiveAndStatusIsNot(final Long distributionSetId, final Action.Status status) {
|
||||
return (root, query, cb) -> cb.and(
|
||||
cb.equal(root.get(JpaAction_.distributionSet).get(JpaTarget_.id), distributionSetId),
|
||||
cb.equal(root.get(JpaAction_.distributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId),
|
||||
cb.equal(root.get(JpaAction_.active), true),
|
||||
cb.notEqual(root.get(JpaAction_.status), status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Specification which joins all necessary tables to retrieve the dependency
|
||||
* between a target and a local file assignment through the assigned action
|
||||
* of the target. All actions are included, not only active actions.
|
||||
* Specification which joins all necessary tables to retrieve the dependency between a target and a local file assignment through the
|
||||
* assigned action of the target. All actions are included, not only active actions.
|
||||
*
|
||||
* @param controllerId the target to verify if the given artifact is currently
|
||||
* assigned or had been assigned
|
||||
* @param sha1Hash of the local artifact to check wherever the target had ever
|
||||
* been assigned
|
||||
* @param controllerId the target to verify if the given artifact is currently assigned or had been assigned
|
||||
* @param sha1Hash of the local artifact to check wherever the target had ever been assigned
|
||||
* @return a specification to use with spring JPA
|
||||
*/
|
||||
public static Specification<JpaAction> hasTargetAssignedArtifact(final String controllerId, final String sha1Hash) {
|
||||
return (actionRoot, query, criteriaBuilder) -> {
|
||||
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
|
||||
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
|
||||
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
|
||||
.join(JpaSoftwareModule_.artifacts);
|
||||
return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
|
||||
criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId),
|
||||
controllerId));
|
||||
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin.join(JpaSoftwareModule_.artifacts);
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
|
||||
criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Specification which joins all necessary tables to retrieve the dependency
|
||||
* between a target and a local file assignment through the assigned action
|
||||
* of the target. All actions are included, not only active actions.
|
||||
* Specification which joins all necessary tables to retrieve the dependency between a target and a local file assignment through the
|
||||
* assigned action of the target. All actions are included, not only active actions.
|
||||
*
|
||||
* @param targetId the target to verify if the given artifact is currently
|
||||
* assigned or had been assigned
|
||||
* @param sha1Hash of the local artifact to check wherever the target had ever
|
||||
* been assigned
|
||||
* @param targetId the target to verify if the given artifact is currently assigned or had been assigned
|
||||
* @param sha1Hash of the local artifact to check wherever the target had ever been assigned
|
||||
* @return a specification to use with spring JPA
|
||||
*/
|
||||
public static Specification<JpaAction> hasTargetAssignedArtifact(final Long targetId, final String sha1Hash) {
|
||||
return (actionRoot, query, criteriaBuilder) -> {
|
||||
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
|
||||
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
|
||||
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
|
||||
.join(JpaSoftwareModule_.artifacts);
|
||||
return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
|
||||
criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.id), targetId));
|
||||
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin.join(JpaSoftwareModule_.artifacts);
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
|
||||
criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id), targetId));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -9,23 +9,21 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
/**
|
||||
* Utility class for {@link JpaArtifact}s {@link Specification}s. The class provides
|
||||
* Spring Data JPQL Specifications.
|
||||
* Utility class for {@link JpaArtifact}s {@link Specification}s. The class provides Spring Data JPQL Specifications.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class ArtifactSpecifications {
|
||||
|
||||
private ArtifactSpecifications() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
public static Specification<JpaArtifact> bySoftwareModuleId(final Long softwareModuleId) {
|
||||
return (targetRoot, query, cb) -> cb.equal(
|
||||
targetRoot.get(JpaArtifact_.softwareModule).get(JpaSoftwareModule_.id), softwareModuleId);
|
||||
targetRoot.get(JpaArtifact_.softwareModule).get(AbstractJpaBaseEntity_.id), softwareModuleId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.test.util;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -21,13 +20,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* accessible to beans which are not managed by spring, e.g. JPA entities.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||
public final class SystemManagementHolder {
|
||||
|
||||
private static final SystemManagementHolder INSTANCE = new SystemManagementHolder();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Autowired
|
||||
private SystemManagement systemManagement;
|
||||
|
||||
/**
|
||||
@@ -36,4 +34,9 @@ public final class SystemManagementHolder {
|
||||
public static SystemManagementHolder getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Autowired // spring setter injection
|
||||
public void setSystemManagement(final SystemManagement systemManagement) {
|
||||
this.systemManagement = systemManagement;
|
||||
}
|
||||
}
|
||||
@@ -614,15 +614,14 @@ public class TestdataFactory {
|
||||
* {@link #SM_TYPE_RT} , {@link #SM_TYPE_APP}.
|
||||
*/
|
||||
public DistributionSetType findOrCreateDefaultTestDsType() {
|
||||
final List<SoftwareModuleType> mand = new ArrayList<>();
|
||||
mand.add(findOrCreateSoftwareModuleType(SM_TYPE_OS));
|
||||
final List<SoftwareModuleType> swt = new ArrayList<>();
|
||||
swt.add(findOrCreateSoftwareModuleType(SM_TYPE_OS));
|
||||
|
||||
final List<SoftwareModuleType> opt = new ArrayList<>();
|
||||
opt.add(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE));
|
||||
opt.add(findOrCreateSoftwareModuleType(SM_TYPE_RT));
|
||||
|
||||
return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional",
|
||||
mand, opt);
|
||||
return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional", swt, opt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -651,15 +650,18 @@ public class TestdataFactory {
|
||||
public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName,
|
||||
final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) {
|
||||
return distributionSetTypeManagement.findByKey(dsTypeKey)
|
||||
.orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
|
||||
.key(dsTypeKey).name(dsTypeName).description(randomDescriptionShort()).colour("black")
|
||||
.optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()))
|
||||
.mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()))));
|
||||
.orElseGet(() -> distributionSetTypeManagement.create(
|
||||
entityFactory.distributionSetType().create()
|
||||
.key(dsTypeKey)
|
||||
.name(dsTypeName)
|
||||
.description(randomDescriptionShort())
|
||||
.colour("black")
|
||||
.optional(optional.stream().map(SoftwareModuleType::getId).toList())
|
||||
.mandatory(mandatory.stream().map(SoftwareModuleType::getId).toList())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds {@link SoftwareModuleType} in repository with given
|
||||
* {@link SoftwareModuleType#getKey()} or creates if it does not exist yet with
|
||||
* Finds {@link SoftwareModuleType} in repository with given {@link SoftwareModuleType#getKey()} or creates if it does not exist yet with
|
||||
* {@link SoftwareModuleType#getMaxAssignments()} = 1.
|
||||
*
|
||||
* @param key {@link SoftwareModuleType#getKey()}
|
||||
@@ -670,8 +672,7 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds {@link SoftwareModuleType} in repository with given
|
||||
* {@link SoftwareModuleType#getKey()} or creates if it does not exist yet.
|
||||
* Finds {@link SoftwareModuleType} in repository with given {@link SoftwareModuleType#getKey()} or creates if it does not exist yet.
|
||||
*
|
||||
* @param key {@link SoftwareModuleType#getKey()}
|
||||
* @param maxAssignments {@link SoftwareModuleType#getMaxAssignments()}
|
||||
@@ -680,7 +681,9 @@ public class TestdataFactory {
|
||||
public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) {
|
||||
return softwareModuleTypeManagement.findByKey(key)
|
||||
.orElseGet(() -> softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create()
|
||||
.key(key).name(key).description(randomDescriptionShort()).colour("#ffffff")
|
||||
.key(key)
|
||||
.name(key)
|
||||
.description(randomDescriptionShort()).colour("#ffffff")
|
||||
.maxAssignments(maxAssignments)));
|
||||
}
|
||||
|
||||
@@ -693,11 +696,14 @@ public class TestdataFactory {
|
||||
* @param modules {@link DistributionSet#getModules()}
|
||||
* @return the created {@link DistributionSet}
|
||||
*/
|
||||
public DistributionSet createDistributionSet(final String name, final String version,
|
||||
final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
||||
return distributionSetManagement.create(entityFactory.distributionSet().create().name(name).version(version)
|
||||
.description(randomDescriptionShort()).type(type)
|
||||
.modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList())));
|
||||
public DistributionSet createDistributionSet(
|
||||
final String name, final String version, final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
||||
return distributionSetManagement.create(entityFactory.distributionSet().create()
|
||||
.type(type)
|
||||
.name(name)
|
||||
.version(version)
|
||||
.description(randomDescriptionShort())
|
||||
.modules(modules.stream().map(SoftwareModule::getId).toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -710,13 +716,17 @@ public class TestdataFactory {
|
||||
* @param requiredMigrationStep {@link DistributionSet#isRequiredMigrationStep()}
|
||||
* @return the created {@link DistributionSet}
|
||||
*/
|
||||
public DistributionSet generateDistributionSet(final String name, final String version,
|
||||
final DistributionSetType type, final Collection<SoftwareModule> modules,
|
||||
public DistributionSet generateDistributionSet(
|
||||
final String name, final String version, final DistributionSetType type, final Collection<SoftwareModule> modules,
|
||||
final boolean requiredMigrationStep) {
|
||||
return entityFactory.distributionSet().create().name(name).version(version)
|
||||
.description(randomDescriptionShort()).type(type)
|
||||
.modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList()))
|
||||
.requiredMigrationStep(requiredMigrationStep).build();
|
||||
return entityFactory.distributionSet().create()
|
||||
.type(type)
|
||||
.name(name)
|
||||
.version(version)
|
||||
.description(randomDescriptionShort())
|
||||
.modules(modules.stream().map(SoftwareModule::getId).toList())
|
||||
.requiredMigrationStep(requiredMigrationStep)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -728,8 +738,8 @@ public class TestdataFactory {
|
||||
* @param modules {@link DistributionSet#getModules()}
|
||||
* @return the created {@link DistributionSet}
|
||||
*/
|
||||
public DistributionSet generateDistributionSet(final String name, final String version,
|
||||
final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
||||
public DistributionSet generateDistributionSet(
|
||||
final String name, final String version, final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
||||
return generateDistributionSet(name, version, type, modules, false);
|
||||
}
|
||||
|
||||
@@ -740,13 +750,11 @@ public class TestdataFactory {
|
||||
* @return the generated {@link DistributionSet}
|
||||
*/
|
||||
public DistributionSet generateDistributionSet(final String name) {
|
||||
return generateDistributionSet(name, DEFAULT_VERSION, findOrCreateDefaultTestDsType(), Collections.emptyList(),
|
||||
false);
|
||||
return generateDistributionSet(name, DEFAULT_VERSION, findOrCreateDefaultTestDsType(), Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link Target}s in repository and with {@link #DEFAULT_CONTROLLER_ID}
|
||||
* as prefix for {@link Target#getControllerId()}.
|
||||
* Creates {@link Target}s in repository and with {@link #DEFAULT_CONTROLLER_ID} as prefix for {@link Target#getControllerId()}.
|
||||
*
|
||||
* @param number of {@link Target}s to create
|
||||
* @return {@link List} of {@link Target} entities
|
||||
@@ -764,7 +772,6 @@ public class TestdataFactory {
|
||||
for (int i = 0; i < number; i++) {
|
||||
targets.add(entityFactory.target().create().controllerId(prefix + (offset + i)));
|
||||
}
|
||||
|
||||
return createTargets(targets);
|
||||
}
|
||||
|
||||
@@ -776,15 +783,11 @@ public class TestdataFactory {
|
||||
* @param targetType targetType of targets to create
|
||||
* @return {@link List} of {@link Target} entities
|
||||
*/
|
||||
public List<Target> createTargetsWithType(final int number, final String controllerIdPrefix,
|
||||
final TargetType targetType) {
|
||||
|
||||
public List<Target> createTargetsWithType(final int number, final String controllerIdPrefix, final TargetType targetType) {
|
||||
final List<TargetCreate> targets = new ArrayList<>(number);
|
||||
for (int i = 0; i < number; i++) {
|
||||
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i)
|
||||
.targetType(targetType.getId()));
|
||||
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).targetType(targetType.getId()));
|
||||
}
|
||||
|
||||
return createTargets(targets);
|
||||
}
|
||||
|
||||
@@ -795,12 +798,10 @@ public class TestdataFactory {
|
||||
* @return {@link List} of {@link Target} entities
|
||||
*/
|
||||
public List<Target> createTargets(final String... targetIds) {
|
||||
|
||||
final List<TargetCreate> targets = new ArrayList<>();
|
||||
for (final String targetId : targetIds) {
|
||||
targets.add(entityFactory.target().create().controllerId(targetId));
|
||||
}
|
||||
|
||||
return createTargets(targets);
|
||||
}
|
||||
|
||||
@@ -835,14 +836,12 @@ public class TestdataFactory {
|
||||
* @param descriptionPrefix prefix used for the description
|
||||
* @return set of {@link Target}
|
||||
*/
|
||||
public List<Target> createTargets(final int numberOfTargets, final String controllerIdPrefix,
|
||||
final String descriptionPrefix) {
|
||||
|
||||
public List<Target> createTargets(final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix) {
|
||||
final List<TargetCreate> targets = IntStream.range(0, numberOfTargets)
|
||||
.mapToObj(i -> entityFactory.target().create()
|
||||
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
||||
.description(descriptionPrefix + i))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
return createTargets(targets);
|
||||
}
|
||||
|
||||
@@ -855,14 +854,13 @@ public class TestdataFactory {
|
||||
* @param lastTargetQuery last time the target polled
|
||||
* @return set of {@link Target}
|
||||
*/
|
||||
public List<Target> createTargets(final int numberOfTargets, final String controllerIdPrefix,
|
||||
final String descriptionPrefix, final Long lastTargetQuery) {
|
||||
|
||||
public List<Target> createTargets(
|
||||
final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix, final Long lastTargetQuery) {
|
||||
final List<TargetCreate> targets = IntStream.range(0, numberOfTargets)
|
||||
.mapToObj(i -> entityFactory.target().create()
|
||||
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
||||
.description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
return createTargets(targets);
|
||||
}
|
||||
|
||||
@@ -875,12 +873,9 @@ public class TestdataFactory {
|
||||
*/
|
||||
public List<TargetTag> createTargetTags(final int number, final String tagPrefix) {
|
||||
final List<TagCreate> result = new ArrayList<>(number);
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.add(entityFactory.tag().create().name(tagPrefix + i).description(tagPrefix + i)
|
||||
.colour(String.valueOf(i)));
|
||||
result.add(entityFactory.tag().create().name(tagPrefix + i).description(tagPrefix + i).colour(String.valueOf(i)));
|
||||
}
|
||||
|
||||
return targetTagManagement.create(result);
|
||||
}
|
||||
|
||||
@@ -892,12 +887,9 @@ public class TestdataFactory {
|
||||
*/
|
||||
public List<DistributionSetTag> createDistributionSetTags(final int number) {
|
||||
final List<TagCreate> result = new ArrayList<>(number);
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.add(
|
||||
entityFactory.tag().create().name("tag" + i).description("tagdesc" + i).colour(String.valueOf(i)));
|
||||
result.add(entityFactory.tag().create().name("tag" + i).description("tagdesc" + i).colour(String.valueOf(i)));
|
||||
}
|
||||
|
||||
return distributionSetTagManagement.create(result);
|
||||
}
|
||||
|
||||
@@ -909,8 +901,7 @@ public class TestdataFactory {
|
||||
* @param message to add
|
||||
* @return updated {@link Action}.
|
||||
*/
|
||||
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status,
|
||||
final String message) {
|
||||
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status, final String message) {
|
||||
return sendUpdateActionStatusToTargets(targets, status, Arrays.asList(message));
|
||||
}
|
||||
|
||||
@@ -922,15 +913,11 @@ public class TestdataFactory {
|
||||
* @param msgs to add
|
||||
* @return updated {@link Action}.
|
||||
*/
|
||||
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status,
|
||||
final Collection<String> msgs) {
|
||||
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status, final Collection<String> msgs) {
|
||||
final List<Action> result = new ArrayList<>();
|
||||
for (final Target target : targets) {
|
||||
final List<Action> findByTarget = deploymentManagement
|
||||
.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 400)).getContent();
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, msgs));
|
||||
}
|
||||
deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 400)).getContent()
|
||||
.forEach(action -> result.add(sendUpdateActionStatusToTarget(status, action, msgs)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -939,7 +926,6 @@ public class TestdataFactory {
|
||||
createTargets(quotaManagement.getMaxTargetsPerAutoAssignment());
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.create(entityFactory.targetFilterQuery().create().name("testName").query("id==*"));
|
||||
|
||||
return targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery()
|
||||
.updateAutoAssign(targetFilterQuery.getId()).ds(createDistributionSet().getId()));
|
||||
}
|
||||
@@ -998,8 +984,7 @@ public class TestdataFactory {
|
||||
* @param errorCondition to switch to next group
|
||||
* @param actionType the type of the Rollout
|
||||
* @param weight weight of the Rollout
|
||||
* @param confirmationRequired if the confirmation is required (considered with confirmation flow
|
||||
* active)
|
||||
* @param confirmationRequired if the confirmation is required (considered with confirmation flow active)
|
||||
* @param dynamic is dynamic
|
||||
* @return created {@link Rollout}
|
||||
*/
|
||||
@@ -1039,39 +1024,33 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link Rollout} with a new {@link DistributionSet} and
|
||||
* {@link Target}s.
|
||||
* Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||
*
|
||||
* @param prefix for rollouts name, description, {@link Target#getControllerId()}
|
||||
* filter
|
||||
* @param prefix for rollouts name, description, {@link Target#getControllerId()} filter
|
||||
* @return created {@link Rollout}
|
||||
*/
|
||||
public Rollout createRollout(final String prefix) {
|
||||
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(),
|
||||
prefix);
|
||||
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(), prefix);
|
||||
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
|
||||
quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*",
|
||||
createDistributionSet(prefix), "50", "5");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link Rollout} with a new {@link DistributionSet} and
|
||||
* {@link Target}s.
|
||||
* Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||
*
|
||||
* @return created {@link Rollout}
|
||||
*/
|
||||
public Rollout createRollout() {
|
||||
final String prefix = randomString(5);
|
||||
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(),
|
||||
prefix);
|
||||
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(), prefix);
|
||||
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
|
||||
quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*",
|
||||
createDistributionSet(prefix), "50", "5");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link Rollout} with a new {@link DistributionSet} and
|
||||
* {@link Target}s.
|
||||
* Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||
*
|
||||
* @return created {@link Rollout}
|
||||
*/
|
||||
@@ -1089,11 +1068,11 @@ public class TestdataFactory {
|
||||
* @param errorCondition error condition
|
||||
* @return the created {@link Rollout}
|
||||
*/
|
||||
public Rollout createAndStartRollout(final int amountTargetsForRollout, final int amountOtherTargets,
|
||||
public Rollout createAndStartRollout(
|
||||
final int amountTargetsForRollout, final int amountOtherTargets,
|
||||
final int amountGroups, final String successCondition, final String errorCondition) {
|
||||
|
||||
final Rollout createdRollout = createSimpleTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout,
|
||||
amountOtherTargets, amountGroups, successCondition, errorCondition);
|
||||
final Rollout createdRollout = createSimpleTestRolloutWithTargetsAndDistributionSet(
|
||||
amountTargetsForRollout, amountOtherTargets, amountGroups, successCondition, errorCondition);
|
||||
return startAndReloadRollout(createdRollout);
|
||||
}
|
||||
|
||||
@@ -1107,11 +1086,12 @@ public class TestdataFactory {
|
||||
* @param errorCondition error condition
|
||||
* @return the created {@link Rollout}
|
||||
*/
|
||||
public Rollout createSimpleTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout,
|
||||
public Rollout createSimpleTestRolloutWithTargetsAndDistributionSet(
|
||||
final int amountTargetsForRollout,
|
||||
final int amountOtherTargets, final int amountOfGroups, final String successCondition,
|
||||
final String errorCondition) {
|
||||
return createSimpleTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountOtherTargets,
|
||||
amountOfGroups, successCondition, errorCondition, ActionType.FORCED, null);
|
||||
return createSimpleTestRolloutWithTargetsAndDistributionSet(
|
||||
amountTargetsForRollout, amountOtherTargets, amountOfGroups, successCondition, errorCondition, ActionType.FORCED, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1139,11 +1119,9 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the soft deleted {@link Rollout} with a new {@link DistributionSet}
|
||||
* and {@link Target}s.
|
||||
* Create the soft deleted {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||
*
|
||||
* @param prefix for rollouts name, description, {@link Target#getControllerId()}
|
||||
* filter
|
||||
* @param prefix for rollouts name, description, {@link Target#getControllerId()} filter
|
||||
* @return created {@link Rollout}
|
||||
*/
|
||||
public Rollout createSoftDeletedRollout(final String prefix) {
|
||||
@@ -1156,8 +1134,7 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds {@link TargetType} in repository with given
|
||||
* {@link TargetType#getName()} or creates if it does not exist yet. No ds types
|
||||
* Finds {@link TargetType} in repository with given {@link TargetType#getName()} or creates if it does not exist yet. No ds types
|
||||
* are assigned on creation.
|
||||
*
|
||||
* @param targetTypeName {@link TargetType#getName()}
|
||||
@@ -1171,8 +1148,7 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link TargetType} in repository with given
|
||||
* {@link TargetType#getName()}. Compatible distribution set types are assigned
|
||||
* Creates {@link TargetType} in repository with given {@link TargetType#getName()}. Compatible distribution set types are assigned
|
||||
* on creation
|
||||
*
|
||||
* @param targetTypeName {@link TargetType#getName()}
|
||||
@@ -1185,8 +1161,7 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link TargetType} in repository with given
|
||||
* {@link TargetType#getName()}. No ds types are assigned on creation.
|
||||
* Creates {@link TargetType} in repository with given {@link TargetType#getName()}. No ds types are assigned on creation.
|
||||
*
|
||||
* @param targetTypePrefix {@link TargetType#getName()}
|
||||
* @return persisted {@link TargetType}
|
||||
@@ -1202,15 +1177,15 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a distribution set and directly invalidates it. No actions will be
|
||||
* canceled and no rollouts will be stopped with this invalidation.
|
||||
* Creates a distribution set and directly invalidates it. No actions will be canceled and no rollouts will be stopped with this
|
||||
* invalidation.
|
||||
*
|
||||
* @return created invalidated {@link DistributionSet}
|
||||
*/
|
||||
public DistributionSet createAndInvalidateDistributionSet() {
|
||||
final DistributionSet distributionSet = createDistributionSet();
|
||||
distributionSetInvalidationManagement.invalidateDistributionSet(
|
||||
new DistributionSetInvalidation(Arrays.asList(distributionSet.getId()), CancelationType.NONE, false));
|
||||
new DistributionSetInvalidation(List.of(distributionSet.getId()), CancelationType.NONE, false));
|
||||
return distributionSet;
|
||||
}
|
||||
|
||||
@@ -1239,7 +1214,6 @@ public class TestdataFactory {
|
||||
.key(VISIBLE_SM_MD_KEY).value(VISIBLE_SM_MD_VALUE).targetVisible(true));
|
||||
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
|
||||
.key(INVISIBLE_SM_MD_KEY).value(INVISIBLE_SM_MD_VALUE).targetVisible(false));
|
||||
|
||||
}
|
||||
|
||||
private void assertTargetProperlyCreated(final Target target) {
|
||||
@@ -1252,8 +1226,7 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds {@link Target} objects with given prefix for
|
||||
* {@link Target#getControllerId()} followed by a number suffix.
|
||||
* Builds {@link Target} objects with given prefix for {@link Target#getControllerId()} followed by a number suffix.
|
||||
*
|
||||
* @param start value for the controllerId suffix
|
||||
* @param numberOfTargets of {@link Target}s to generate
|
||||
@@ -1265,36 +1238,27 @@ public class TestdataFactory {
|
||||
for (int i = start; i < start + numberOfTargets; i++) {
|
||||
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).build());
|
||||
}
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
private List<Target> createTargets(final Collection<TargetCreate> targetCreates) {
|
||||
// init new instance of array list since the TargetManagement#create
|
||||
// will
|
||||
// provide a unmodifiable list
|
||||
final List<Target> createdTargets = targetManagement.create(targetCreates);
|
||||
return new ArrayList<>(createdTargets);
|
||||
// init new instance of array list since the TargetManagement#create will provide a unmodifiable list
|
||||
return new ArrayList<>(targetManagement.create(targetCreates));
|
||||
}
|
||||
|
||||
private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA,
|
||||
final Collection<String> msgs) {
|
||||
|
||||
private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Collection<String> msgs) {
|
||||
return controllerManagement.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(updActA.getId()).status(status).messages(msgs));
|
||||
}
|
||||
|
||||
private Rollout startAndReloadRollout(final Rollout rollout) {
|
||||
rolloutManagement.start(rollout.getId());
|
||||
|
||||
// Run here, because scheduler is disabled during tests
|
||||
rolloutHandler.handleAll();
|
||||
|
||||
return reloadRollout(rollout);
|
||||
}
|
||||
|
||||
private Rollout reloadRollout(final Rollout rollout) {
|
||||
return rolloutManagement.get(rollout.getId()).orElseThrow(NoSuchElementException::new);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user