Remove some of the field injections (Sonar recomendtion) (#2218)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -104,6 +104,9 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
|
|||||||
protected abstract AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes,
|
protected abstract AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes,
|
||||||
final String contentType, final String tempFile) throws IOException;
|
final String contentType, final String tempFile) throws IOException;
|
||||||
|
|
||||||
|
// java:S1066 - more readable with separate "if" statements
|
||||||
|
// java:S4042 - delete reason is not needed
|
||||||
|
@SuppressWarnings({ "java:S1066", "java:S4042" })
|
||||||
static File createTempFile(final boolean directory) {
|
static File createTempFile(final boolean directory) {
|
||||||
try {
|
try {
|
||||||
final File file = (directory
|
final File file = (directory
|
||||||
|
|||||||
@@ -130,13 +130,13 @@ public abstract class AbstractDDiApiIntegrationTest extends AbstractRestIntegrat
|
|||||||
|
|
||||||
protected ResultActions postDeploymentFeedback(final String controllerId, final Long actionId, final String content,
|
protected ResultActions postDeploymentFeedback(final String controllerId, final Long actionId, final String content,
|
||||||
final ResultMatcher statusMatcher) throws Exception {
|
final ResultMatcher statusMatcher) throws Exception {
|
||||||
return postDeploymentFeedback(MediaType.APPLICATION_JSON_UTF8, controllerId, actionId, content.getBytes(), statusMatcher);
|
return postDeploymentFeedback(MediaType.APPLICATION_JSON, controllerId, actionId, content.getBytes(), statusMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ResultActions putInstalledBase(final String controllerId, final String content, final ResultMatcher statusMatcher)
|
protected ResultActions putInstalledBase(final String controllerId, final String content, final ResultMatcher statusMatcher)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
return mvc.perform(put(INSTALLED_BASE_ROOT, tenantAware.getCurrentTenant(), controllerId)
|
return mvc.perform(put(INSTALLED_BASE_ROOT, tenantAware.getCurrentTenant(), controllerId)
|
||||||
.content(content.getBytes()).contentType(MediaType.APPLICATION_JSON_UTF8))
|
.content(content.getBytes()).contentType(MediaType.APPLICATION_JSON))
|
||||||
.andDo(MockMvcResultPrinter.print())
|
.andDo(MockMvcResultPrinter.print())
|
||||||
.andExpect(statusMatcher);
|
.andExpect(statusMatcher);
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ public abstract class AbstractDDiApiIntegrationTest extends AbstractRestIntegrat
|
|||||||
protected ResultActions postCancelFeedback(
|
protected ResultActions postCancelFeedback(
|
||||||
final String controllerId, final Long actionId, final String content,
|
final String controllerId, final Long actionId, final String content,
|
||||||
final ResultMatcher statusMatcher) throws Exception {
|
final ResultMatcher statusMatcher) throws Exception {
|
||||||
return postCancelFeedback(MediaType.APPLICATION_JSON_UTF8, controllerId, actionId, content.getBytes(), statusMatcher);
|
return postCancelFeedback(MediaType.APPLICATION_JSON, controllerId, actionId, content.getBytes(), statusMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ResultActions postCancelFeedback(
|
protected ResultActions postCancelFeedback(
|
||||||
|
|||||||
@@ -60,15 +60,22 @@ import org.springframework.util.ErrorHandler;
|
|||||||
@PropertySource("classpath:/hawkbit-dmf-defaults.properties")
|
@PropertySource("classpath:/hawkbit-dmf-defaults.properties")
|
||||||
public class AmqpConfiguration {
|
public class AmqpConfiguration {
|
||||||
|
|
||||||
@Autowired
|
private final AmqpProperties amqpProperties;
|
||||||
private AmqpProperties amqpProperties;
|
private final AmqpDeadletterProperties amqpDeadletterProperties;
|
||||||
@Autowired
|
private final ConnectionFactory rabbitConnectionFactory;
|
||||||
private AmqpDeadletterProperties amqpDeadletterProperties;
|
|
||||||
@Autowired
|
|
||||||
private ConnectionFactory rabbitConnectionFactory;
|
|
||||||
@Autowired(required = false)
|
|
||||||
private ServiceMatcher serviceMatcher;
|
private ServiceMatcher serviceMatcher;
|
||||||
|
|
||||||
|
public AmqpConfiguration(final AmqpProperties amqpProperties, final AmqpDeadletterProperties amqpDeadletterProperties, final ConnectionFactory rabbitConnectionFactory) {
|
||||||
|
this.amqpProperties = amqpProperties;
|
||||||
|
this.amqpDeadletterProperties = amqpDeadletterProperties;
|
||||||
|
this.rabbitConnectionFactory = rabbitConnectionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired(required = false) // spring setter injection
|
||||||
|
public void setServiceMatcher(final ServiceMatcher serviceMatcher) {
|
||||||
|
this.serviceMatcher = serviceMatcher;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a custom error handler bean.
|
* Creates a custom error handler bean.
|
||||||
*
|
*
|
||||||
@@ -262,8 +269,7 @@ public class AmqpConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create RabbitListenerContainerFactory bean if no listenerContainerFactory
|
* Create RabbitListenerContainerFactory bean if no listenerContainerFactory bean found
|
||||||
* bean found
|
|
||||||
*
|
*
|
||||||
* @return RabbitListenerContainerFactory bean
|
* @return RabbitListenerContainerFactory bean
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -215,8 +215,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
return StringUtils.hasLength(message.getMessageProperties().getCorrelationId());
|
return StringUtils.hasLength(message.getMessageProperties().getCorrelationId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exception squid:MethodCyclomaticComplexity - false positive, is a simple mapping
|
@SuppressWarnings("java:S2637" ) // java:S2637 - logAndThrowMessageError throws exception, i.e. doesn't return null
|
||||||
@SuppressWarnings("squid:MethodCyclomaticComplexity")
|
|
||||||
private static @NotNull Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus, final Action action) {
|
private static @NotNull Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus, final Action action) {
|
||||||
Status status = null;
|
Status status = null;
|
||||||
switch (actionUpdateStatus.getActionStatus()) {
|
switch (actionUpdateStatus.getActionStatus()) {
|
||||||
@@ -261,7 +260,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
logAndThrowMessageError(message, "Status for action does not exisit.");
|
logAndThrowMessageError(message, "Status for action does not exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,12 +53,9 @@ class BaseAmqpServiceTest {
|
|||||||
final DmfActionUpdateStatus actionUpdateStatus = createActionStatus();
|
final DmfActionUpdateStatus actionUpdateStatus = createActionStatus();
|
||||||
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
||||||
|
|
||||||
final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus,
|
final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus, createJsonProperties());
|
||||||
createJsonProperties());
|
final DmfActionUpdateStatus convertedActionUpdateStatus = baseAmqpService.convertMessage(message, DmfActionUpdateStatus.class);
|
||||||
final DmfActionUpdateStatus convertedActionUpdateStatus = baseAmqpService.convertMessage(message,
|
assertThat(convertedActionUpdateStatus).usingRecursiveComparison().isEqualTo(actionUpdateStatus);
|
||||||
DmfActionUpdateStatus.class);
|
|
||||||
|
|
||||||
assertThat(convertedActionUpdateStatus).isEqualToComparingFieldByField(actionUpdateStatus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -398,15 +398,14 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Step
|
@Step
|
||||||
protected DistributionSet createTargetAndDistributionSetAndAssign(final String controllerId,
|
protected DistributionSet createTargetAndDistributionSetAndAssign(final String controllerId, final Action.ActionType actionType) {
|
||||||
final Action.ActionType actionType) {
|
|
||||||
registerAndAssertTargetWithExistingTenant(controllerId);
|
registerAndAssertTargetWithExistingTenant(controllerId);
|
||||||
|
|
||||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
|
final DistributionSet distributionSetLocal = testdataFactory.createDistributionSet(UUID.randomUUID().toString());
|
||||||
testdataFactory.addSoftwareModuleMetadata(distributionSet);
|
testdataFactory.addSoftwareModuleMetadata(distributionSetLocal);
|
||||||
|
|
||||||
assignDistributionSet(distributionSet.getId(), controllerId, actionType);
|
assignDistributionSet(distributionSetLocal.getId(), controllerId, actionType);
|
||||||
return distributionSet;
|
return distributionSetLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertSoftwareModules(final Set<SoftwareModule> expectedSoftwareModules,
|
protected void assertSoftwareModules(final Set<SoftwareModule> expectedSoftwareModules,
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
@Import(TestChannelBinderConfiguration.class)
|
@Import(TestChannelBinderConfiguration.class)
|
||||||
// Dirty context is necessary to create a new vhost and recreate all necessary beans after every test class.
|
// Dirty context is necessary to create a new vhost and recreate all necessary beans after every test class.
|
||||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||||
|
@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes
|
||||||
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
|
public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
private static final Duration TIMEOUT = Duration.ofSeconds(5);
|
||||||
|
|||||||
@@ -15,25 +15,23 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.eclipse.hawkbit.repository.exception.ArtifactEncryptionUnsupportedException;
|
import org.eclipse.hawkbit.repository.exception.ArtifactEncryptionUnsupportedException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service responsible for encryption operations.
|
* 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 {
|
public final class ArtifactEncryptionService {
|
||||||
|
|
||||||
private static final ArtifactEncryptionService SINGLETON = new ArtifactEncryptionService();
|
private static final ArtifactEncryptionService SINGLETON = new ArtifactEncryptionService();
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private ArtifactEncryption artifactEncryption;
|
private ArtifactEncryption artifactEncryption;
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private ArtifactEncryptionSecretsStore artifactEncryptionSecretsStore;
|
private ArtifactEncryptionSecretsStore artifactEncryptionSecretsStore;
|
||||||
|
|
||||||
private ArtifactEncryptionService() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the artifact encryption service singleton instance
|
* @return the artifact encryption service singleton instance
|
||||||
*/
|
*/
|
||||||
@@ -41,6 +39,16 @@ public final class ArtifactEncryptionService {
|
|||||||
return SINGLETON;
|
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.
|
* 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
|
* Generates encryption secrets and saves them in secret store by software module id reference.
|
||||||
* module id reference.
|
|
||||||
*
|
*
|
||||||
* @param smId software module id
|
* @param smId software module id
|
||||||
*/
|
*/
|
||||||
@@ -116,7 +123,6 @@ public final class ArtifactEncryptionService {
|
|||||||
requiredSecretsKey);
|
requiredSecretsKey);
|
||||||
requiredSecretsValue.ifPresent(secretValue -> requiredSecrets.put(requiredSecretsKey, secretValue));
|
requiredSecretsValue.ifPresent(secretValue -> requiredSecrets.put(requiredSecretsKey, secretValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
return requiredSecrets;
|
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.
|
* A singleton bean which holds the event entity manager to have autowiring in the events.
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||||
public final class EventEntityManagerHolder {
|
public final class EventEntityManagerHolder {
|
||||||
|
|
||||||
private static final EventEntityManagerHolder SINGLETON = new EventEntityManagerHolder();
|
private static final EventEntityManagerHolder SINGLETON = new EventEntityManagerHolder();
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EventEntityManager eventEntityManager;
|
private EventEntityManager eventEntityManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +31,11 @@ public final class EventEntityManagerHolder {
|
|||||||
return SINGLETON;
|
return SINGLETON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired // spring setter injection
|
||||||
|
public void setEventEntityManager(final EventEntityManager eventEntityManager) {
|
||||||
|
this.eventEntityManager = eventEntityManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the eventEntityManager
|
* @return the eventEntityManager
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
|
||||||
@Getter
|
@Getter
|
||||||
|
@SuppressWarnings("java:S6548") // singleton holder ensures static access to spring resources in some places
|
||||||
public final class RsqlConfigHolder {
|
public final class RsqlConfigHolder {
|
||||||
|
|
||||||
private static final RsqlConfigHolder SINGLETON = new RsqlConfigHolder();
|
private static final RsqlConfigHolder SINGLETON = new RsqlConfigHolder();
|
||||||
|
|||||||
@@ -18,21 +18,18 @@ import org.springframework.cloud.bus.ServiceMatcher;
|
|||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton bean which holds the event publisher and service origin Id in
|
* A singleton bean which holds the event publisher and service origin id in order to publish remote application events.
|
||||||
* order to publish remote application events. It can be used in beans not
|
* It can be used in beans not instantiated by spring e.g. JPA entities which cannot be auto-wired.
|
||||||
* instantiated by spring e.g. JPA entities which cannot be auto-wired.
|
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||||
public final class EventPublisherHolder {
|
public final class EventPublisherHolder {
|
||||||
|
|
||||||
private static final EventPublisherHolder SINGLETON = new EventPublisherHolder();
|
private static final EventPublisherHolder SINGLETON = new EventPublisherHolder();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Autowired
|
|
||||||
private ApplicationEventPublisher eventPublisher;
|
private ApplicationEventPublisher eventPublisher;
|
||||||
@Autowired(required = false)
|
|
||||||
private ServiceMatcher serviceMatcher;
|
private ServiceMatcher serviceMatcher;
|
||||||
@Autowired
|
|
||||||
private BusProperties bus;
|
private BusProperties bus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,9 +39,24 @@ public final class EventPublisherHolder {
|
|||||||
return SINGLETON;
|
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}
|
* @return the service origin Id coming either from {@link ServiceMatcher} when available or {@link BusProperties}
|
||||||
* when available or {@link BusProperties} otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
public String getApplicationId() {
|
public String getApplicationId() {
|
||||||
String id = null;
|
String id = null;
|
||||||
|
|||||||
@@ -16,22 +16,27 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton bean which holds {@link SystemSecurityContext} service and makes
|
* A singleton bean which holds {@link SystemSecurityContext} service and makes it accessible to beans which are not
|
||||||
* it accessible to beans which are not managed by spring, e.g. JPA entities.
|
* managed by spring, e.g. JPA entities.
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||||
public final class SystemSecurityContextHolder {
|
public final class SystemSecurityContextHolder {
|
||||||
|
|
||||||
private static final SystemSecurityContextHolder INSTANCE = new SystemSecurityContextHolder();
|
private static final SystemSecurityContextHolder SINGLETON = new SystemSecurityContextHolder();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Autowired
|
|
||||||
private SystemSecurityContext systemSecurityContext;
|
private SystemSecurityContext systemSecurityContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the singleton {@link SystemSecurityContextHolder} instance
|
* @return the singleton {@link SystemSecurityContextHolder} instance
|
||||||
*/
|
*/
|
||||||
public static SystemSecurityContextHolder getInstance() {
|
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;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton bean which holds {@link TenantConfigurationManagement} service
|
* A singleton bean which holds {@link TenantConfigurationManagement} service and makes it accessible to beans which are
|
||||||
* and makes it accessible to beans which are not managed by spring, e.g. JPA
|
* not managed by spring, e.g. JPA entities.
|
||||||
* entities.
|
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||||
public final class TenantConfigurationManagementHolder {
|
public final class TenantConfigurationManagementHolder {
|
||||||
|
|
||||||
private static final TenantConfigurationManagementHolder INSTANCE = new TenantConfigurationManagementHolder();
|
private static final TenantConfigurationManagementHolder SINGLETON = new TenantConfigurationManagementHolder();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Autowired
|
|
||||||
private TenantConfigurationManagement tenantConfigurationManagement;
|
private TenantConfigurationManagement tenantConfigurationManagement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the singleton {@link TenantConfigurationManagementHolder} instance
|
* @return the singleton {@link TenantConfigurationManagementHolder} instance
|
||||||
*/
|
*/
|
||||||
public static TenantConfigurationManagementHolder getInstance() {
|
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;
|
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -19,11 +20,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
* entities which cannot be autowired.
|
* entities which cannot be autowired.
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||||
public final class AfterTransactionCommitExecutorHolder {
|
public final class AfterTransactionCommitExecutorHolder {
|
||||||
|
|
||||||
private static final AfterTransactionCommitExecutorHolder SINGLETON = new AfterTransactionCommitExecutorHolder();
|
private static final AfterTransactionCommitExecutorHolder SINGLETON = new AfterTransactionCommitExecutorHolder();
|
||||||
|
|
||||||
@Autowired
|
@Getter
|
||||||
private AfterTransactionCommitExecutor afterCommit;
|
private AfterTransactionCommitExecutor afterCommit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,17 +35,8 @@ public final class AfterTransactionCommitExecutorHolder {
|
|||||||
return SINGLETON;
|
return SINGLETON;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Autowired // spring setter injection
|
||||||
* @return the afterCommit
|
public void setAfterTransactionCommitExecutor(final AfterTransactionCommitExecutor afterCommit) {
|
||||||
*/
|
|
||||||
public AfterTransactionCommitExecutor getAfterCommit() {
|
|
||||||
return afterCommit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param afterCommit the afterCommit to set
|
|
||||||
*/
|
|
||||||
public void setAfterCommit(final AfterTransactionCommitExecutor afterCommit) {
|
|
||||||
this.afterCommit = afterCommit;
|
this.afterCommit = afterCommit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,13 +12,16 @@ package org.eclipse.hawkbit.repository.jpa.model.helper;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.eclipse.hawkbit.repository.jpa.EntityInterceptor;
|
import org.eclipse.hawkbit.repository.jpa.EntityInterceptor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton bean which holds the {@link EntityInterceptor} to have all
|
* A singleton bean which holds the {@link EntityInterceptor} to have all interceptors in spring beans.
|
||||||
* 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 {
|
public final class EntityInterceptorHolder {
|
||||||
|
|
||||||
private static final EntityInterceptorHolder SINGLETON = new EntityInterceptorHolder();
|
private static final EntityInterceptorHolder SINGLETON = new EntityInterceptorHolder();
|
||||||
@@ -26,10 +29,6 @@ public final class EntityInterceptorHolder {
|
|||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private final List<EntityInterceptor> entityInterceptors = new ArrayList<>();
|
private final List<EntityInterceptor> entityInterceptors = new ArrayList<>();
|
||||||
|
|
||||||
private EntityInterceptorHolder() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the entity intreceptor holder singleton instance
|
* @return the entity intreceptor holder singleton instance
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
|
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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
|
* A singleton bean which holds the {@link SecurityTokenGenerator} and make it
|
||||||
* accessible to beans which are not managed by spring, e.g. JPA entities.
|
* 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 {
|
public final class SecurityTokenGeneratorHolder {
|
||||||
|
|
||||||
private static final SecurityTokenGeneratorHolder INSTANCE = new SecurityTokenGeneratorHolder();
|
private static final SecurityTokenGeneratorHolder SINGLETON = new SecurityTokenGeneratorHolder();
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SecurityTokenGenerator securityTokenGenerator;
|
private SecurityTokenGenerator securityTokenGenerator;
|
||||||
|
|
||||||
/**
|
|
||||||
* private constructor.
|
|
||||||
*/
|
|
||||||
private SecurityTokenGeneratorHolder() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a singleton instance of the security token generator holder.
|
* @return a singleton instance of the security token generator holder.
|
||||||
*/
|
*/
|
||||||
public static SecurityTokenGeneratorHolder getInstance() {
|
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() {
|
public String generateToken() {
|
||||||
return securityTokenGenerator.generateToken();
|
return securityTokenGenerator.generateToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
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.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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
|
* A singleton bean which holds {@link TenantAware} service and makes it
|
||||||
* accessible to beans which are not managed by spring, e.g. JPA entities.
|
* 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 {
|
public final class TenantAwareHolder {
|
||||||
|
|
||||||
private static final TenantAwareHolder INSTANCE = new TenantAwareHolder();
|
private static final TenantAwareHolder SINGLETON = new TenantAwareHolder();
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TenantAware tenantAware;
|
private TenantAware tenantAware;
|
||||||
|
|
||||||
private TenantAwareHolder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the singleton {@link TenantAwareHolder} instance
|
* @return the singleton {@link TenantAwareHolder} instance
|
||||||
*/
|
*/
|
||||||
public static TenantAwareHolder getInstance() {
|
public static TenantAwareHolder getInstance() {
|
||||||
return INSTANCE;
|
return SINGLETON;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Autowired // spring setter injection
|
||||||
|
public void setTenantAware(final TenantAware tenantAware) {
|
||||||
|
this.tenantAware = tenantAware;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ import jakarta.persistence.EntityManagerFactory;
|
|||||||
import io.micrometer.core.instrument.Counter;
|
import io.micrometer.core.instrument.Counter;
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
import io.micrometer.core.instrument.MeterRegistry;
|
||||||
import io.micrometer.core.instrument.Timer;
|
import io.micrometer.core.instrument.Timer;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.eclipse.persistence.sessions.Session;
|
import org.eclipse.persistence.sessions.Session;
|
||||||
import org.eclipse.persistence.tools.profiler.PerformanceMonitor;
|
import org.eclipse.persistence.tools.profiler.PerformanceMonitor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.
|
* 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 class Statistics {
|
||||||
|
|
||||||
public static final String METER_PREFIX = "eclipselink.";
|
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 Pattern PATTERN = Pattern.compile("(?<type>(Counter|Timer)+):(?<key>[^ -]+)");
|
||||||
private static final Map<String, Long> REPORTED_TIMER_VALUES = new HashMap<>();
|
private static final Map<String, Long> REPORTED_TIMER_VALUES = new HashMap<>();
|
||||||
@@ -68,7 +72,7 @@ public class Statistics {
|
|||||||
* @return the singleton {@link Statistics} instance
|
* @return the singleton {@link Statistics} instance
|
||||||
*/
|
*/
|
||||||
public static Statistics getInstance() {
|
public static Statistics getInstance() {
|
||||||
return INSTANCE;
|
return SINGLETON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -80,36 +84,36 @@ public class Statistics {
|
|||||||
getPerformanceMonitor(entityManagerFactory).setDumpTime(dumpPeriod);
|
getPerformanceMonitor(entityManagerFactory).setDumpTime(dumpPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired // spring setter injection
|
||||||
public void setMeterRegistry(final MeterRegistry meterRegistry) {
|
public void setMeterRegistry(final MeterRegistry meterRegistry) {
|
||||||
this.meterRegistry = meterRegistry;
|
this.meterRegistry = meterRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
// flushes the statistics to the meter registry (if needed)
|
// flushes the statistics to the meter registry (if needed)
|
||||||
public static void flush() {
|
public static void flush() {
|
||||||
final MeterRegistry meterRegistry = INSTANCE.meterRegistry;
|
final MeterRegistry meterRegistry = SINGLETON.meterRegistry;
|
||||||
if (meterRegistry == null) {
|
if (meterRegistry == null) {
|
||||||
// not a bean (i.e. no performance monitoring) is enabled or no meter registry available
|
// not a bean (i.e. no performance monitoring) is enabled or no meter registry available
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (INSTANCE) {
|
synchronized (SINGLETON) {
|
||||||
if (INSTANCE.flushing) {
|
if (SINGLETON.flushing) {
|
||||||
// wait for flushing
|
// wait for flushing
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
INSTANCE.wait(1000);
|
SINGLETON.wait(1000);
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
} while (INSTANCE.flushing);
|
} while (SINGLETON.flushing);
|
||||||
// flushed
|
// flushed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// flush
|
// 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}")
|
@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;
|
package org.eclipse.hawkbit.repository.jpa;
|
||||||
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
import io.micrometer.core.instrument.MeterRegistry;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
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>
|
* <li>(?) When using in test the metrics MAYBE shall be enabled with @AutoConfigureObservability(tracing = false)</li>
|
||||||
* </ol>
|
* </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 class Statistics {
|
||||||
|
|
||||||
public static final String METER_PREFIX = "hibernate.";
|
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
|
// if meter registry is unavailable, the statistics will not send to metrics
|
||||||
@Getter
|
@Getter
|
||||||
@@ -45,17 +50,7 @@ public class Statistics {
|
|||||||
* @return the singleton {@link Statistics} instance
|
* @return the singleton {@link Statistics} instance
|
||||||
*/
|
*/
|
||||||
public static Statistics getInstance() {
|
public static Statistics getInstance() {
|
||||||
return INSTANCE;
|
return SINGLETON;
|
||||||
}
|
|
||||||
|
|
||||||
@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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// autoconfigure after CompositeMeterRegistryAutoConfiguration, so when the autoconfiguration is being processed the MeterRegistry
|
// autoconfigure after CompositeMeterRegistryAutoConfiguration, so when the autoconfiguration is being processed the MeterRegistry
|
||||||
@@ -74,4 +69,14 @@ public class Statistics {
|
|||||||
return Statistics.getInstance();
|
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;
|
this.rsqlQueryFieldType = rsqlQueryFieldType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("java:S1066") // java:S1066 - more readable with separate "if" statements
|
||||||
protected QuertPath getQuertPath(final ComparisonNode node) {
|
protected QuertPath getQuertPath(final ComparisonNode node) {
|
||||||
final int firstSeparatorIndex = node.getSelector().indexOf(RsqlQueryField.SUB_ATTRIBUTE_SEPARATOR);
|
final int firstSeparatorIndex = node.getSelector().indexOf(RsqlQueryField.SUB_ATTRIBUTE_SEPARATOR);
|
||||||
final String enumName = (firstSeparatorIndex == -1
|
final String enumName = (firstSeparatorIndex == -1
|
||||||
|
|||||||
@@ -9,12 +9,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.jpa.specifications;
|
package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import jakarta.persistence.criteria.Join;
|
import jakarta.persistence.criteria.Join;
|
||||||
import jakarta.persistence.criteria.ListJoin;
|
import jakarta.persistence.criteria.ListJoin;
|
||||||
import jakarta.persistence.criteria.SetJoin;
|
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.JpaAction_;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
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;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for {@link Action}s {@link Specification}s. The class provides
|
* Utility class for {@link Action}s {@link Specification}s. The class provides Spring Data JPQL Specifications.
|
||||||
* Spring Data JPQL Specifications.
|
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public final class ActionSpecifications {
|
public final class ActionSpecifications {
|
||||||
|
|
||||||
private ActionSpecifications() {
|
|
||||||
// utility class
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Specification<JpaAction> byTargetIdAndIsActive(final Long targetId) {
|
public static Specification<JpaAction> byTargetIdAndIsActive(final Long targetId) {
|
||||||
return (root, query, cb) -> cb.and(
|
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_.active), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +46,7 @@ public final class ActionSpecifications {
|
|||||||
|
|
||||||
public static Specification<JpaAction> byTargetIdAndIsActiveAndStatus(final Long targetId, final Action.Status status) {
|
public static Specification<JpaAction> byTargetIdAndIsActiveAndStatus(final Long targetId, final Action.Status status) {
|
||||||
return (root, query, cb) -> cb.and(
|
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_.active), true),
|
||||||
cb.equal(root.get(JpaAction_.status), status));
|
cb.equal(root.get(JpaAction_.status), status));
|
||||||
}
|
}
|
||||||
@@ -67,15 +64,6 @@ public final class ActionSpecifications {
|
|||||||
cb.equal(root.get(JpaAction_.status), status));
|
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.
|
* 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.
|
* @return the matching action s.
|
||||||
*/
|
*/
|
||||||
public static Specification<JpaAction> byTargetControllerIdAndActiveAndWeightIsNull(final String controllerId, final boolean isNull) {
|
public static Specification<JpaAction> byTargetControllerIdAndActiveAndWeightIsNull(final String controllerId, final boolean isNull) {
|
||||||
return (root, query, cb) ->
|
return (root, query, cb) -> cb.and(
|
||||||
cb.and(
|
|
||||||
cb.equal(root.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId),
|
cb.equal(root.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId),
|
||||||
cb.equal(root.get(JpaAction_.active), true),
|
cb.equal(root.get(JpaAction_.active), true),
|
||||||
isNull ? cb.isNull(root.get(JpaAction_.weight)) : cb.isNotNull(root.get(JpaAction_.weight)));
|
isNull ? cb.isNull(root.get(JpaAction_.weight)) : cb.isNotNull(root.get(JpaAction_.weight)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Specification<JpaAction> byDistributionSetId(final Long distributionSetId) {
|
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) {
|
public static Specification<JpaAction> byDistributionSetIdAndActive(final Long distributionSetId) {
|
||||||
return (root, query, cb) -> cb.and(
|
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.equal(root.get(JpaAction_.active), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Specification<JpaAction> byDistributionSetIdAndActiveAndStatusIsNot(
|
public static Specification<JpaAction> byDistributionSetIdAndActiveAndStatusIsNot(final Long distributionSetId, final Action.Status status) {
|
||||||
final Long distributionSetId, final Action.Status status) {
|
|
||||||
return (root, query, cb) -> cb.and(
|
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.equal(root.get(JpaAction_.active), true),
|
||||||
cb.notEqual(root.get(JpaAction_.status), status));
|
cb.notEqual(root.get(JpaAction_.status), status));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specification which joins all necessary tables to retrieve the dependency
|
* Specification which joins all necessary tables to retrieve the dependency between a target and a local file assignment through the
|
||||||
* between a target and a local file assignment through the assigned action
|
* assigned action of the target. All actions are included, not only active actions.
|
||||||
* of the target. All actions are included, not only active actions.
|
|
||||||
*
|
*
|
||||||
* @param controllerId the target to verify if the given artifact is currently
|
* @param controllerId the target to verify if the given artifact is currently assigned or had been assigned
|
||||||
* assigned or had been assigned
|
* @param sha1Hash of the local artifact to check wherever the target had ever 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
|
* @return a specification to use with spring JPA
|
||||||
*/
|
*/
|
||||||
public static Specification<JpaAction> hasTargetAssignedArtifact(final String controllerId, final String sha1Hash) {
|
public static Specification<JpaAction> hasTargetAssignedArtifact(final String controllerId, final String sha1Hash) {
|
||||||
return (actionRoot, query, criteriaBuilder) -> {
|
return (actionRoot, query, criteriaBuilder) -> {
|
||||||
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
|
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
|
||||||
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
|
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
|
||||||
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
|
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin.join(JpaSoftwareModule_.artifacts);
|
||||||
.join(JpaSoftwareModule_.artifacts);
|
return criteriaBuilder.and(
|
||||||
return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
|
criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
|
||||||
criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId),
|
criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId));
|
||||||
controllerId));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specification which joins all necessary tables to retrieve the dependency
|
* Specification which joins all necessary tables to retrieve the dependency between a target and a local file assignment through the
|
||||||
* between a target and a local file assignment through the assigned action
|
* assigned action of the target. All actions are included, not only active actions.
|
||||||
* of the target. All actions are included, not only active actions.
|
|
||||||
*
|
*
|
||||||
* @param targetId the target to verify if the given artifact is currently
|
* @param targetId the target to verify if the given artifact is currently assigned or had been assigned
|
||||||
* assigned or had been assigned
|
* @param sha1Hash of the local artifact to check wherever the target had ever 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
|
* @return a specification to use with spring JPA
|
||||||
*/
|
*/
|
||||||
public static Specification<JpaAction> hasTargetAssignedArtifact(final Long targetId, final String sha1Hash) {
|
public static Specification<JpaAction> hasTargetAssignedArtifact(final Long targetId, final String sha1Hash) {
|
||||||
return (actionRoot, query, criteriaBuilder) -> {
|
return (actionRoot, query, criteriaBuilder) -> {
|
||||||
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
|
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
|
||||||
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
|
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
|
||||||
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
|
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin.join(JpaSoftwareModule_.artifacts);
|
||||||
.join(JpaSoftwareModule_.artifacts);
|
return criteriaBuilder.and(
|
||||||
return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
|
criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash),
|
||||||
criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.id), targetId));
|
criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id), targetId));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,23 +9,21 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.jpa.specifications;
|
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.JpaArtifact_;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact_;
|
||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for {@link JpaArtifact}s {@link Specification}s. The class provides
|
* Utility class for {@link JpaArtifact}s {@link Specification}s. The class provides Spring Data JPQL Specifications.
|
||||||
* Spring Data JPQL Specifications.
|
|
||||||
*/
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public final class ArtifactSpecifications {
|
public final class ArtifactSpecifications {
|
||||||
|
|
||||||
private ArtifactSpecifications() {
|
|
||||||
// utility class
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Specification<JpaArtifact> bySoftwareModuleId(final Long softwareModuleId) {
|
public static Specification<JpaArtifact> bySoftwareModuleId(final Long softwareModuleId) {
|
||||||
return (targetRoot, query, cb) -> cb.equal(
|
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.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
|
||||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.
|
* accessible to beans which are not managed by spring, e.g. JPA entities.
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||||
public final class SystemManagementHolder {
|
public final class SystemManagementHolder {
|
||||||
|
|
||||||
private static final SystemManagementHolder INSTANCE = new SystemManagementHolder();
|
private static final SystemManagementHolder INSTANCE = new SystemManagementHolder();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
@Autowired
|
|
||||||
private SystemManagement systemManagement;
|
private SystemManagement systemManagement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,4 +34,9 @@ public final class SystemManagementHolder {
|
|||||||
public static SystemManagementHolder getInstance() {
|
public static SystemManagementHolder getInstance() {
|
||||||
return INSTANCE;
|
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}.
|
* {@link #SM_TYPE_RT} , {@link #SM_TYPE_APP}.
|
||||||
*/
|
*/
|
||||||
public DistributionSetType findOrCreateDefaultTestDsType() {
|
public DistributionSetType findOrCreateDefaultTestDsType() {
|
||||||
final List<SoftwareModuleType> mand = new ArrayList<>();
|
final List<SoftwareModuleType> swt = new ArrayList<>();
|
||||||
mand.add(findOrCreateSoftwareModuleType(SM_TYPE_OS));
|
swt.add(findOrCreateSoftwareModuleType(SM_TYPE_OS));
|
||||||
|
|
||||||
final List<SoftwareModuleType> opt = new ArrayList<>();
|
final List<SoftwareModuleType> opt = new ArrayList<>();
|
||||||
opt.add(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE));
|
opt.add(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE));
|
||||||
opt.add(findOrCreateSoftwareModuleType(SM_TYPE_RT));
|
opt.add(findOrCreateSoftwareModuleType(SM_TYPE_RT));
|
||||||
|
|
||||||
return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional",
|
return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional", swt, opt);
|
||||||
mand, opt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -651,15 +650,18 @@ public class TestdataFactory {
|
|||||||
public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName,
|
public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName,
|
||||||
final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) {
|
final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) {
|
||||||
return distributionSetTypeManagement.findByKey(dsTypeKey)
|
return distributionSetTypeManagement.findByKey(dsTypeKey)
|
||||||
.orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create()
|
.orElseGet(() -> distributionSetTypeManagement.create(
|
||||||
.key(dsTypeKey).name(dsTypeName).description(randomDescriptionShort()).colour("black")
|
entityFactory.distributionSetType().create()
|
||||||
.optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()))
|
.key(dsTypeKey)
|
||||||
.mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()))));
|
.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
|
* Finds {@link SoftwareModuleType} in repository with given {@link SoftwareModuleType#getKey()} or creates if it does not exist yet with
|
||||||
* {@link SoftwareModuleType#getKey()} or creates if it does not exist yet with
|
|
||||||
* {@link SoftwareModuleType#getMaxAssignments()} = 1.
|
* {@link SoftwareModuleType#getMaxAssignments()} = 1.
|
||||||
*
|
*
|
||||||
* @param key {@link SoftwareModuleType#getKey()}
|
* @param key {@link SoftwareModuleType#getKey()}
|
||||||
@@ -670,8 +672,7 @@ public class TestdataFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds {@link SoftwareModuleType} in repository with given
|
* Finds {@link SoftwareModuleType} in repository with given {@link SoftwareModuleType#getKey()} or creates if it does not exist yet.
|
||||||
* {@link SoftwareModuleType#getKey()} or creates if it does not exist yet.
|
|
||||||
*
|
*
|
||||||
* @param key {@link SoftwareModuleType#getKey()}
|
* @param key {@link SoftwareModuleType#getKey()}
|
||||||
* @param maxAssignments {@link SoftwareModuleType#getMaxAssignments()}
|
* @param maxAssignments {@link SoftwareModuleType#getMaxAssignments()}
|
||||||
@@ -680,7 +681,9 @@ public class TestdataFactory {
|
|||||||
public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) {
|
public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) {
|
||||||
return softwareModuleTypeManagement.findByKey(key)
|
return softwareModuleTypeManagement.findByKey(key)
|
||||||
.orElseGet(() -> softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create()
|
.orElseGet(() -> softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create()
|
||||||
.key(key).name(key).description(randomDescriptionShort()).colour("#ffffff")
|
.key(key)
|
||||||
|
.name(key)
|
||||||
|
.description(randomDescriptionShort()).colour("#ffffff")
|
||||||
.maxAssignments(maxAssignments)));
|
.maxAssignments(maxAssignments)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -693,11 +696,14 @@ public class TestdataFactory {
|
|||||||
* @param modules {@link DistributionSet#getModules()}
|
* @param modules {@link DistributionSet#getModules()}
|
||||||
* @return the created {@link DistributionSet}
|
* @return the created {@link DistributionSet}
|
||||||
*/
|
*/
|
||||||
public DistributionSet createDistributionSet(final String name, final String version,
|
public DistributionSet createDistributionSet(
|
||||||
final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
final String name, final String version, final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
||||||
return distributionSetManagement.create(entityFactory.distributionSet().create().name(name).version(version)
|
return distributionSetManagement.create(entityFactory.distributionSet().create()
|
||||||
.description(randomDescriptionShort()).type(type)
|
.type(type)
|
||||||
.modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList())));
|
.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()}
|
* @param requiredMigrationStep {@link DistributionSet#isRequiredMigrationStep()}
|
||||||
* @return the created {@link DistributionSet}
|
* @return the created {@link DistributionSet}
|
||||||
*/
|
*/
|
||||||
public DistributionSet generateDistributionSet(final String name, final String version,
|
public DistributionSet generateDistributionSet(
|
||||||
final DistributionSetType type, final Collection<SoftwareModule> modules,
|
final String name, final String version, final DistributionSetType type, final Collection<SoftwareModule> modules,
|
||||||
final boolean requiredMigrationStep) {
|
final boolean requiredMigrationStep) {
|
||||||
return entityFactory.distributionSet().create().name(name).version(version)
|
return entityFactory.distributionSet().create()
|
||||||
.description(randomDescriptionShort()).type(type)
|
.type(type)
|
||||||
.modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList()))
|
.name(name)
|
||||||
.requiredMigrationStep(requiredMigrationStep).build();
|
.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()}
|
* @param modules {@link DistributionSet#getModules()}
|
||||||
* @return the created {@link DistributionSet}
|
* @return the created {@link DistributionSet}
|
||||||
*/
|
*/
|
||||||
public DistributionSet generateDistributionSet(final String name, final String version,
|
public DistributionSet generateDistributionSet(
|
||||||
final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
final String name, final String version, final DistributionSetType type, final Collection<SoftwareModule> modules) {
|
||||||
return generateDistributionSet(name, version, type, modules, false);
|
return generateDistributionSet(name, version, type, modules, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -740,13 +750,11 @@ public class TestdataFactory {
|
|||||||
* @return the generated {@link DistributionSet}
|
* @return the generated {@link DistributionSet}
|
||||||
*/
|
*/
|
||||||
public DistributionSet generateDistributionSet(final String name) {
|
public DistributionSet generateDistributionSet(final String name) {
|
||||||
return generateDistributionSet(name, DEFAULT_VERSION, findOrCreateDefaultTestDsType(), Collections.emptyList(),
|
return generateDistributionSet(name, DEFAULT_VERSION, findOrCreateDefaultTestDsType(), Collections.emptyList(), false);
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link Target}s in repository and with {@link #DEFAULT_CONTROLLER_ID}
|
* Creates {@link Target}s in repository and with {@link #DEFAULT_CONTROLLER_ID} as prefix for {@link Target#getControllerId()}.
|
||||||
* as prefix for {@link Target#getControllerId()}.
|
|
||||||
*
|
*
|
||||||
* @param number of {@link Target}s to create
|
* @param number of {@link Target}s to create
|
||||||
* @return {@link List} of {@link Target} entities
|
* @return {@link List} of {@link Target} entities
|
||||||
@@ -764,7 +772,6 @@ public class TestdataFactory {
|
|||||||
for (int i = 0; i < number; i++) {
|
for (int i = 0; i < number; i++) {
|
||||||
targets.add(entityFactory.target().create().controllerId(prefix + (offset + i)));
|
targets.add(entityFactory.target().create().controllerId(prefix + (offset + i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return createTargets(targets);
|
return createTargets(targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,15 +783,11 @@ public class TestdataFactory {
|
|||||||
* @param targetType targetType of targets to create
|
* @param targetType targetType of targets to create
|
||||||
* @return {@link List} of {@link Target} entities
|
* @return {@link List} of {@link Target} entities
|
||||||
*/
|
*/
|
||||||
public List<Target> createTargetsWithType(final int number, final String controllerIdPrefix,
|
public List<Target> createTargetsWithType(final int number, final String controllerIdPrefix, final TargetType targetType) {
|
||||||
final TargetType targetType) {
|
|
||||||
|
|
||||||
final List<TargetCreate> targets = new ArrayList<>(number);
|
final List<TargetCreate> targets = new ArrayList<>(number);
|
||||||
for (int i = 0; i < number; i++) {
|
for (int i = 0; i < number; i++) {
|
||||||
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i)
|
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).targetType(targetType.getId()));
|
||||||
.targetType(targetType.getId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return createTargets(targets);
|
return createTargets(targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -795,12 +798,10 @@ public class TestdataFactory {
|
|||||||
* @return {@link List} of {@link Target} entities
|
* @return {@link List} of {@link Target} entities
|
||||||
*/
|
*/
|
||||||
public List<Target> createTargets(final String... targetIds) {
|
public List<Target> createTargets(final String... targetIds) {
|
||||||
|
|
||||||
final List<TargetCreate> targets = new ArrayList<>();
|
final List<TargetCreate> targets = new ArrayList<>();
|
||||||
for (final String targetId : targetIds) {
|
for (final String targetId : targetIds) {
|
||||||
targets.add(entityFactory.target().create().controllerId(targetId));
|
targets.add(entityFactory.target().create().controllerId(targetId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return createTargets(targets);
|
return createTargets(targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -835,14 +836,12 @@ public class TestdataFactory {
|
|||||||
* @param descriptionPrefix prefix used for the description
|
* @param descriptionPrefix prefix used for the description
|
||||||
* @return set of {@link Target}
|
* @return set of {@link Target}
|
||||||
*/
|
*/
|
||||||
public List<Target> createTargets(final int numberOfTargets, final String controllerIdPrefix,
|
public List<Target> createTargets(final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix) {
|
||||||
final String descriptionPrefix) {
|
|
||||||
|
|
||||||
final List<TargetCreate> targets = IntStream.range(0, numberOfTargets)
|
final List<TargetCreate> targets = IntStream.range(0, numberOfTargets)
|
||||||
.mapToObj(i -> entityFactory.target().create()
|
.mapToObj(i -> entityFactory.target().create()
|
||||||
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
||||||
.description(descriptionPrefix + i))
|
.description(descriptionPrefix + i))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
return createTargets(targets);
|
return createTargets(targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -855,14 +854,13 @@ public class TestdataFactory {
|
|||||||
* @param lastTargetQuery last time the target polled
|
* @param lastTargetQuery last time the target polled
|
||||||
* @return set of {@link Target}
|
* @return set of {@link Target}
|
||||||
*/
|
*/
|
||||||
public List<Target> createTargets(final int numberOfTargets, final String controllerIdPrefix,
|
public List<Target> createTargets(
|
||||||
final String descriptionPrefix, final Long lastTargetQuery) {
|
final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix, final Long lastTargetQuery) {
|
||||||
|
|
||||||
final List<TargetCreate> targets = IntStream.range(0, numberOfTargets)
|
final List<TargetCreate> targets = IntStream.range(0, numberOfTargets)
|
||||||
.mapToObj(i -> entityFactory.target().create()
|
.mapToObj(i -> entityFactory.target().create()
|
||||||
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
||||||
.description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery))
|
.description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
return createTargets(targets);
|
return createTargets(targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -875,12 +873,9 @@ public class TestdataFactory {
|
|||||||
*/
|
*/
|
||||||
public List<TargetTag> createTargetTags(final int number, final String tagPrefix) {
|
public List<TargetTag> createTargetTags(final int number, final String tagPrefix) {
|
||||||
final List<TagCreate> result = new ArrayList<>(number);
|
final List<TagCreate> result = new ArrayList<>(number);
|
||||||
|
|
||||||
for (int i = 0; i < number; i++) {
|
for (int i = 0; i < number; i++) {
|
||||||
result.add(entityFactory.tag().create().name(tagPrefix + i).description(tagPrefix + i)
|
result.add(entityFactory.tag().create().name(tagPrefix + i).description(tagPrefix + i).colour(String.valueOf(i)));
|
||||||
.colour(String.valueOf(i)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return targetTagManagement.create(result);
|
return targetTagManagement.create(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -892,12 +887,9 @@ public class TestdataFactory {
|
|||||||
*/
|
*/
|
||||||
public List<DistributionSetTag> createDistributionSetTags(final int number) {
|
public List<DistributionSetTag> createDistributionSetTags(final int number) {
|
||||||
final List<TagCreate> result = new ArrayList<>(number);
|
final List<TagCreate> result = new ArrayList<>(number);
|
||||||
|
|
||||||
for (int i = 0; i < number; i++) {
|
for (int i = 0; i < number; i++) {
|
||||||
result.add(
|
result.add(entityFactory.tag().create().name("tag" + i).description("tagdesc" + i).colour(String.valueOf(i)));
|
||||||
entityFactory.tag().create().name("tag" + i).description("tagdesc" + i).colour(String.valueOf(i)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return distributionSetTagManagement.create(result);
|
return distributionSetTagManagement.create(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -909,8 +901,7 @@ public class TestdataFactory {
|
|||||||
* @param message to add
|
* @param message to add
|
||||||
* @return updated {@link Action}.
|
* @return updated {@link Action}.
|
||||||
*/
|
*/
|
||||||
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status,
|
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status, final String message) {
|
||||||
final String message) {
|
|
||||||
return sendUpdateActionStatusToTargets(targets, status, Arrays.asList(message));
|
return sendUpdateActionStatusToTargets(targets, status, Arrays.asList(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -922,15 +913,11 @@ public class TestdataFactory {
|
|||||||
* @param msgs to add
|
* @param msgs to add
|
||||||
* @return updated {@link Action}.
|
* @return updated {@link Action}.
|
||||||
*/
|
*/
|
||||||
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status,
|
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status, final Collection<String> msgs) {
|
||||||
final Collection<String> msgs) {
|
|
||||||
final List<Action> result = new ArrayList<>();
|
final List<Action> result = new ArrayList<>();
|
||||||
for (final Target target : targets) {
|
for (final Target target : targets) {
|
||||||
final List<Action> findByTarget = deploymentManagement
|
deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 400)).getContent()
|
||||||
.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 400)).getContent();
|
.forEach(action -> result.add(sendUpdateActionStatusToTarget(status, action, msgs)));
|
||||||
for (final Action action : findByTarget) {
|
|
||||||
result.add(sendUpdateActionStatusToTarget(status, action, msgs));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -939,7 +926,6 @@ public class TestdataFactory {
|
|||||||
createTargets(quotaManagement.getMaxTargetsPerAutoAssignment());
|
createTargets(quotaManagement.getMaxTargetsPerAutoAssignment());
|
||||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||||
.create(entityFactory.targetFilterQuery().create().name("testName").query("id==*"));
|
.create(entityFactory.targetFilterQuery().create().name("testName").query("id==*"));
|
||||||
|
|
||||||
return targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery()
|
return targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery()
|
||||||
.updateAutoAssign(targetFilterQuery.getId()).ds(createDistributionSet().getId()));
|
.updateAutoAssign(targetFilterQuery.getId()).ds(createDistributionSet().getId()));
|
||||||
}
|
}
|
||||||
@@ -998,8 +984,7 @@ public class TestdataFactory {
|
|||||||
* @param errorCondition to switch to next group
|
* @param errorCondition to switch to next group
|
||||||
* @param actionType the type of the Rollout
|
* @param actionType the type of the Rollout
|
||||||
* @param weight weight of the Rollout
|
* @param weight weight of the Rollout
|
||||||
* @param confirmationRequired if the confirmation is required (considered with confirmation flow
|
* @param confirmationRequired if the confirmation is required (considered with confirmation flow active)
|
||||||
* active)
|
|
||||||
* @param dynamic is dynamic
|
* @param dynamic is dynamic
|
||||||
* @return created {@link Rollout}
|
* @return created {@link Rollout}
|
||||||
*/
|
*/
|
||||||
@@ -1039,39 +1024,33 @@ public class TestdataFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create {@link Rollout} with a new {@link DistributionSet} and
|
* Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||||
* {@link Target}s.
|
|
||||||
*
|
*
|
||||||
* @param prefix for rollouts name, description, {@link Target#getControllerId()}
|
* @param prefix for rollouts name, description, {@link Target#getControllerId()} filter
|
||||||
* filter
|
|
||||||
* @return created {@link Rollout}
|
* @return created {@link Rollout}
|
||||||
*/
|
*/
|
||||||
public Rollout createRollout(final String prefix) {
|
public Rollout createRollout(final String prefix) {
|
||||||
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(),
|
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(), prefix);
|
||||||
prefix);
|
|
||||||
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
|
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
|
||||||
quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*",
|
quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*",
|
||||||
createDistributionSet(prefix), "50", "5");
|
createDistributionSet(prefix), "50", "5");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create {@link Rollout} with a new {@link DistributionSet} and
|
* Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||||
* {@link Target}s.
|
|
||||||
*
|
*
|
||||||
* @return created {@link Rollout}
|
* @return created {@link Rollout}
|
||||||
*/
|
*/
|
||||||
public Rollout createRollout() {
|
public Rollout createRollout() {
|
||||||
final String prefix = randomString(5);
|
final String prefix = randomString(5);
|
||||||
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(),
|
createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(), prefix);
|
||||||
prefix);
|
|
||||||
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
|
return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION,
|
||||||
quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*",
|
quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*",
|
||||||
createDistributionSet(prefix), "50", "5");
|
createDistributionSet(prefix), "50", "5");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create {@link Rollout} with a new {@link DistributionSet} and
|
* Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||||
* {@link Target}s.
|
|
||||||
*
|
*
|
||||||
* @return created {@link Rollout}
|
* @return created {@link Rollout}
|
||||||
*/
|
*/
|
||||||
@@ -1089,11 +1068,11 @@ public class TestdataFactory {
|
|||||||
* @param errorCondition error condition
|
* @param errorCondition error condition
|
||||||
* @return the created {@link Rollout}
|
* @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 int amountGroups, final String successCondition, final String errorCondition) {
|
||||||
|
final Rollout createdRollout = createSimpleTestRolloutWithTargetsAndDistributionSet(
|
||||||
final Rollout createdRollout = createSimpleTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout,
|
amountTargetsForRollout, amountOtherTargets, amountGroups, successCondition, errorCondition);
|
||||||
amountOtherTargets, amountGroups, successCondition, errorCondition);
|
|
||||||
return startAndReloadRollout(createdRollout);
|
return startAndReloadRollout(createdRollout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1107,11 +1086,12 @@ public class TestdataFactory {
|
|||||||
* @param errorCondition error condition
|
* @param errorCondition error condition
|
||||||
* @return the created {@link Rollout}
|
* @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 int amountOtherTargets, final int amountOfGroups, final String successCondition,
|
||||||
final String errorCondition) {
|
final String errorCondition) {
|
||||||
return createSimpleTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountOtherTargets,
|
return createSimpleTestRolloutWithTargetsAndDistributionSet(
|
||||||
amountOfGroups, successCondition, errorCondition, ActionType.FORCED, null);
|
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}
|
* Create the soft deleted {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||||
* and {@link Target}s.
|
|
||||||
*
|
*
|
||||||
* @param prefix for rollouts name, description, {@link Target#getControllerId()}
|
* @param prefix for rollouts name, description, {@link Target#getControllerId()} filter
|
||||||
* filter
|
|
||||||
* @return created {@link Rollout}
|
* @return created {@link Rollout}
|
||||||
*/
|
*/
|
||||||
public Rollout createSoftDeletedRollout(final String prefix) {
|
public Rollout createSoftDeletedRollout(final String prefix) {
|
||||||
@@ -1156,8 +1134,7 @@ public class TestdataFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds {@link TargetType} in repository with given
|
* Finds {@link TargetType} in repository with given {@link TargetType#getName()} or creates if it does not exist yet. No ds types
|
||||||
* {@link TargetType#getName()} or creates if it does not exist yet. No ds types
|
|
||||||
* are assigned on creation.
|
* are assigned on creation.
|
||||||
*
|
*
|
||||||
* @param targetTypeName {@link TargetType#getName()}
|
* @param targetTypeName {@link TargetType#getName()}
|
||||||
@@ -1171,8 +1148,7 @@ public class TestdataFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link TargetType} in repository with given
|
* Creates {@link TargetType} in repository with given {@link TargetType#getName()}. Compatible distribution set types are assigned
|
||||||
* {@link TargetType#getName()}. Compatible distribution set types are assigned
|
|
||||||
* on creation
|
* on creation
|
||||||
*
|
*
|
||||||
* @param targetTypeName {@link TargetType#getName()}
|
* @param targetTypeName {@link TargetType#getName()}
|
||||||
@@ -1185,8 +1161,7 @@ public class TestdataFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link TargetType} in repository with given
|
* Creates {@link TargetType} in repository with given {@link TargetType#getName()}. No ds types are assigned on creation.
|
||||||
* {@link TargetType#getName()}. No ds types are assigned on creation.
|
|
||||||
*
|
*
|
||||||
* @param targetTypePrefix {@link TargetType#getName()}
|
* @param targetTypePrefix {@link TargetType#getName()}
|
||||||
* @return persisted {@link TargetType}
|
* @return persisted {@link TargetType}
|
||||||
@@ -1202,15 +1177,15 @@ public class TestdataFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a distribution set and directly invalidates it. No actions will be
|
* Creates a distribution set and directly invalidates it. No actions will be canceled and no rollouts will be stopped with this
|
||||||
* canceled and no rollouts will be stopped with this invalidation.
|
* invalidation.
|
||||||
*
|
*
|
||||||
* @return created invalidated {@link DistributionSet}
|
* @return created invalidated {@link DistributionSet}
|
||||||
*/
|
*/
|
||||||
public DistributionSet createAndInvalidateDistributionSet() {
|
public DistributionSet createAndInvalidateDistributionSet() {
|
||||||
final DistributionSet distributionSet = createDistributionSet();
|
final DistributionSet distributionSet = createDistributionSet();
|
||||||
distributionSetInvalidationManagement.invalidateDistributionSet(
|
distributionSetInvalidationManagement.invalidateDistributionSet(
|
||||||
new DistributionSetInvalidation(Arrays.asList(distributionSet.getId()), CancelationType.NONE, false));
|
new DistributionSetInvalidation(List.of(distributionSet.getId()), CancelationType.NONE, false));
|
||||||
return distributionSet;
|
return distributionSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1239,7 +1214,6 @@ public class TestdataFactory {
|
|||||||
.key(VISIBLE_SM_MD_KEY).value(VISIBLE_SM_MD_VALUE).targetVisible(true));
|
.key(VISIBLE_SM_MD_KEY).value(VISIBLE_SM_MD_VALUE).targetVisible(true));
|
||||||
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
|
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
|
||||||
.key(INVISIBLE_SM_MD_KEY).value(INVISIBLE_SM_MD_VALUE).targetVisible(false));
|
.key(INVISIBLE_SM_MD_KEY).value(INVISIBLE_SM_MD_VALUE).targetVisible(false));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertTargetProperlyCreated(final Target target) {
|
private void assertTargetProperlyCreated(final Target target) {
|
||||||
@@ -1252,8 +1226,7 @@ public class TestdataFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds {@link Target} objects with given prefix for
|
* Builds {@link Target} objects with given prefix for {@link Target#getControllerId()} followed by a number suffix.
|
||||||
* {@link Target#getControllerId()} followed by a number suffix.
|
|
||||||
*
|
*
|
||||||
* @param start value for the controllerId suffix
|
* @param start value for the controllerId suffix
|
||||||
* @param numberOfTargets of {@link Target}s to generate
|
* @param numberOfTargets of {@link Target}s to generate
|
||||||
@@ -1265,36 +1238,27 @@ public class TestdataFactory {
|
|||||||
for (int i = start; i < start + numberOfTargets; i++) {
|
for (int i = start; i < start + numberOfTargets; i++) {
|
||||||
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).build());
|
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
return targets;
|
return targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Target> createTargets(final Collection<TargetCreate> targetCreates) {
|
private List<Target> createTargets(final Collection<TargetCreate> targetCreates) {
|
||||||
// init new instance of array list since the TargetManagement#create
|
// init new instance of array list since the TargetManagement#create will provide a unmodifiable list
|
||||||
// will
|
return new ArrayList<>(targetManagement.create(targetCreates));
|
||||||
// provide a unmodifiable list
|
|
||||||
final List<Target> createdTargets = targetManagement.create(targetCreates);
|
|
||||||
return new ArrayList<>(createdTargets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA,
|
private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Collection<String> msgs) {
|
||||||
final Collection<String> msgs) {
|
|
||||||
|
|
||||||
return controllerManagement.addUpdateActionStatus(
|
return controllerManagement.addUpdateActionStatus(
|
||||||
entityFactory.actionStatus().create(updActA.getId()).status(status).messages(msgs));
|
entityFactory.actionStatus().create(updActA.getId()).status(status).messages(msgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rollout startAndReloadRollout(final Rollout rollout) {
|
private Rollout startAndReloadRollout(final Rollout rollout) {
|
||||||
rolloutManagement.start(rollout.getId());
|
rolloutManagement.start(rollout.getId());
|
||||||
|
|
||||||
// Run here, because scheduler is disabled during tests
|
// Run here, because scheduler is disabled during tests
|
||||||
rolloutHandler.handleAll();
|
rolloutHandler.handleAll();
|
||||||
|
|
||||||
return reloadRollout(rollout);
|
return reloadRollout(rollout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Rollout reloadRollout(final Rollout rollout) {
|
private Rollout reloadRollout(final Rollout rollout) {
|
||||||
return rolloutManagement.get(rollout.getId()).orElseThrow(NoSuchElementException::new);
|
return rolloutManagement.get(rollout.getId()).orElseThrow(NoSuchElementException::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,7 @@ public class Amqp {
|
|||||||
vHosts.values().forEach(VHost::stop);
|
vHosts.values().forEach(VHost::stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("java:S3358") // java:S3358
|
||||||
public VHost getVhost(final DMF dmf, final boolean initVHost) {
|
public VHost getVhost(final DMF dmf, final boolean initVHost) {
|
||||||
final String vHost = dmf == null || ObjectUtils.isEmpty(dmf.getVirtualHost()) ?
|
final String vHost = dmf == null || ObjectUtils.isEmpty(dmf.getVirtualHost()) ?
|
||||||
(rabbitProperties.getVirtualHost() == null ? "/" : rabbitProperties.getVirtualHost()) :
|
(rabbitProperties.getVirtualHost() == null ? "/" : rabbitProperties.getVirtualHost()) :
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.springframework.security.web.access.intercept.AuthorizationFilter;
|
|||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
|
||||||
public class MdcHandler {
|
public class MdcHandler {
|
||||||
|
|
||||||
public static final String MDC_KEY_TENANT = "tenant";
|
public static final String MDC_KEY_TENANT = "tenant";
|
||||||
@@ -40,7 +41,6 @@ public class MdcHandler {
|
|||||||
|
|
||||||
@Value("${hawkbit.logging.mdchandler.enabled:true}")
|
@Value("${hawkbit.logging.mdchandler.enabled:true}")
|
||||||
private boolean mdcEnabled;
|
private boolean mdcEnabled;
|
||||||
@Autowired(required = false)
|
|
||||||
private SpringSecurityAuditorAware springSecurityAuditorAware = new SpringSecurityAuditorAware();
|
private SpringSecurityAuditorAware springSecurityAuditorAware = new SpringSecurityAuditorAware();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,6 +50,11 @@ public class MdcHandler {
|
|||||||
return SINGLETON;
|
return SINGLETON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired(required = false) // spring setter injection
|
||||||
|
public void setSpringSecurityAuditorAware(final SpringSecurityAuditorAware springSecurityAuditorAware) {
|
||||||
|
this.springSecurityAuditorAware = springSecurityAuditorAware;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes callable and returns the result. If MDC is enabled, it sets the tenant and / or user from the authentication in the MDC context.
|
* Executes callable and returns the result. If MDC is enabled, it sets the tenant and / or user from the authentication in the MDC context.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user