Code format hawkbit-repository-core (#1927)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-05 09:46:55 +02:00
committed by GitHub
parent 67eb170f7c
commit da7fa9e022
27 changed files with 182 additions and 233 deletions

View File

@@ -9,56 +9,57 @@
SPDX-License-Identifier: EPL-2.0 SPDX-License-Identifier: EPL-2.0
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.hawkbit</groupId> <parent>
<artifactId>hawkbit-repository</artifactId> <groupId>org.eclipse.hawkbit</groupId>
<version>${revision}</version> <artifactId>hawkbit-repository</artifactId>
</parent> <version>${revision}</version>
<artifactId>hawkbit-repository-core</artifactId> </parent>
<name>hawkBit :: Repository :: Core Implementation Support</name> <artifactId>hawkbit-repository-core</artifactId>
<name>hawkBit :: Repository :: Core Implementation Support</name>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.eclipse.hawkbit</groupId> <groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-api</artifactId> <artifactId>hawkbit-repository-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.ben-manes.caffeine</groupId> <groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId> <artifactId>caffeine</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId> <artifactId>spring-context-support</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.protostuff</groupId> <groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId> <artifactId>protostuff-core</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.protostuff</groupId> <groupId>io.protostuff</groupId>
<artifactId>protostuff-runtime</artifactId> <artifactId>protostuff-runtime</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- TEST --> <!-- TEST -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.qameta.allure</groupId> <groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId> <artifactId>allure-junit5</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -9,6 +9,10 @@
*/ */
package org.eclipse.hawkbit.event; package org.eclipse.hawkbit.event;
import io.protostuff.LinkedBuffer;
import io.protostuff.ProtobufIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.bus.event.RemoteApplicationEvent; import org.springframework.cloud.bus.event.RemoteApplicationEvent;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
@@ -17,15 +21,10 @@ import org.springframework.messaging.converter.AbstractMessageConverter;
import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConversionException;
import org.springframework.util.MimeType; import org.springframework.util.MimeType;
import io.protostuff.LinkedBuffer;
import io.protostuff.ProtobufIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
/** /**
* A customize message converter for the spring cloud events. The converter is * A customize message converter for the spring cloud events. The converter is
* registered for the application/binary+protostuff type. * registered for the application/binary+protostuff type.
* *
* The clazz-type-information is encoded into the message payload infront with a * The clazz-type-information is encoded into the message payload infront with a
* length of {@link #EVENT_TYPE_LENGTH}. This is necessary due in case of * length of {@link #EVENT_TYPE_LENGTH}. This is necessary due in case of
* rabbitMQ batching the message headers will be merged together and custom * rabbitMQ batching the message headers will be merged together and custom
@@ -85,8 +84,7 @@ public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
log.error("Cannot read clazz header for given EventType value {}, missing mapping", eventType.getValue()); log.error("Cannot read clazz header for given EventType value {}, missing mapping", eventType.getValue());
throw new MessageConversionException("Missing mapping of EventType for value " + eventType.getValue()); throw new MessageConversionException("Missing mapping of EventType for value " + eventType.getValue());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked") final Schema<Object> schema = (Schema<Object>) RuntimeSchema.getSchema(targetClass);
final Schema<Object> schema = (Schema<Object>) RuntimeSchema.getSchema(targetClass);
final Object deserializeEvent = schema.newMessage(); final Object deserializeEvent = schema.newMessage();
ProtobufIOUtil.mergeFrom(content, deserializeEvent, schema); ProtobufIOUtil.mergeFrom(content, deserializeEvent, schema);
return deserializeEvent; return deserializeEvent;
@@ -120,8 +118,7 @@ public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
private static byte[] writeContent(final Object payload) { private static byte[] writeContent(final Object payload) {
final Class<?> serializeClass = payload.getClass(); final Class<?> serializeClass = payload.getClass();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked") final Schema<Object> schema = (Schema<Object>) RuntimeSchema.getSchema(serializeClass);
final Schema<Object> schema = (Schema<Object>) RuntimeSchema.getSchema(serializeClass);
final LinkedBuffer buffer = LinkedBuffer.allocate(); final LinkedBuffer buffer = LinkedBuffer.allocate();
return ProtobufIOUtil.toByteArray(payload, schema, buffer); return ProtobufIOUtil.toByteArray(payload, schema, buffer);
} }
@@ -132,8 +129,7 @@ public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
log.error("There is no mapping to EventType for the given class {}", clazz); log.error("There is no mapping to EventType for the given class {}", clazz);
throw new MessageConversionException("Missing EventType for given class : " + clazz); throw new MessageConversionException("Missing EventType for given class : " + clazz);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked") final Schema<Object> schema = (Schema<Object>) RuntimeSchema
final Schema<Object> schema = (Schema<Object>) RuntimeSchema
.getSchema((Class<?>) EventType.class); .getSchema((Class<?>) EventType.class);
final LinkedBuffer buffer = LinkedBuffer.allocate(); final LinkedBuffer buffer = LinkedBuffer.allocate();
return ProtobufIOUtil.toByteArray(clazzEventType, schema, buffer); return ProtobufIOUtil.toByteArray(clazzEventType, schema, buffer);

View File

@@ -19,6 +19,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
import org.eclipse.hawkbit.repository.event.remote.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.DistributionSetTypeDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.DistributionSetTypeDeletedEvent;
@@ -40,7 +41,6 @@ import org.eclipse.hawkbit.repository.event.remote.TargetTypeDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.TenantConfigurationDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.TenantConfigurationDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent;
import org.eclipse.hawkbit.repository.event.remote.CancelTargetAssignmentEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent;
@@ -83,6 +83,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.TenantConfigurationUpd
public class EventType { public class EventType {
private static final Map<Integer, Class<?>> TYPES = new HashMap<>(); private static final Map<Integer, Class<?>> TYPES = new HashMap<>();
private int value;
/** /**
* The associated event-type-value must remain the same as initially * The associated event-type-value must remain the same as initially
@@ -170,28 +171,20 @@ public class EventType {
TYPES.put(46, TargetTypeDeletedEvent.class); TYPES.put(46, TargetTypeDeletedEvent.class);
} }
private int value;
/** /**
* Constructor. * Constructor.
* *
* @param value * @param value the value to initialize
* the value to initialize
*/ */
public EventType(final int value) { public EventType(final int value) {
this.value = value; this.value = value;
} }
public Class<?> getTargetClass() {
return TYPES.get(value);
}
/** /**
* Returns a {@link EventType} based on the given class type. * Returns a {@link EventType} based on the given class type.
* *
* @param clazz * @param clazz the clazz type to retrieve the corresponding {@link EventType}
* the clazz type to retrieve the corresponding {@link EventType} * .
* .
* @return the corresponding {@link EventType} or {@code null} if the clazz * @return the corresponding {@link EventType} or {@code null} if the clazz
* does not have a {@link EventType}. * does not have a {@link EventType}.
*/ */
@@ -201,4 +194,8 @@ public class EventType {
return foundEventType.map(EventType::new).orElse(null); return foundEventType.map(EventType::new).orElse(null);
} }
public Class<?> getTargetClass() {
return TYPES.get(value);
}
} }

View File

@@ -15,15 +15,13 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
* {@link QuotaManagement} implementation based on spring boot * {@link QuotaManagement} implementation based on spring boot
* {@link ConfigurationProperties}. * {@link ConfigurationProperties}.
*
*/ */
public class PropertiesQuotaManagement implements QuotaManagement { public class PropertiesQuotaManagement implements QuotaManagement {
private final HawkbitSecurityProperties securityProperties; private final HawkbitSecurityProperties securityProperties;
/** /**
* @param securityProperties * @param securityProperties that holds the quota definitions
* that holds the quota definitions
*/ */
public PropertiesQuotaManagement(final HawkbitSecurityProperties securityProperties) { public PropertiesQuotaManagement(final HawkbitSecurityProperties securityProperties) {
this.securityProperties = securityProperties; this.securityProperties = securityProperties;
@@ -84,11 +82,6 @@ public class PropertiesQuotaManagement implements QuotaManagement {
return securityProperties.getDos().getMaxTargetsPerRolloutGroup(); return securityProperties.getDos().getMaxTargetsPerRolloutGroup();
} }
@Override
public int getMaxActionsPerTarget() {
return securityProperties.getDos().getMaxActionsPerTarget();
}
@Override @Override
public int getMaxTargetDistributionSetAssignmentsPerManualAssignment() { public int getMaxTargetDistributionSetAssignmentsPerManualAssignment() {
return securityProperties.getDos().getMaxTargetDistributionSetAssignmentsPerManualAssignment(); return securityProperties.getDos().getMaxTargetDistributionSetAssignmentsPerManualAssignment();
@@ -99,6 +92,11 @@ public class PropertiesQuotaManagement implements QuotaManagement {
return securityProperties.getDos().getMaxTargetsPerAutoAssignment(); return securityProperties.getDos().getMaxTargetsPerAutoAssignment();
} }
@Override
public int getMaxActionsPerTarget() {
return securityProperties.getDos().getMaxActionsPerTarget();
}
@Override @Override
public long getMaxArtifactSize() { public long getMaxArtifactSize() {
return securityProperties.getDos().getMaxArtifactSize(); return securityProperties.getDos().getMaxArtifactSize();

View File

@@ -17,7 +17,6 @@ import org.springframework.context.annotation.PropertySource;
/** /**
* Default configuration that is common to all repository implementations. * Default configuration that is common to all repository implementations.
*
*/ */
@Configuration @Configuration
@EnableConfigurationProperties({ RepositoryProperties.class, ControllerPollProperties.class, @EnableConfigurationProperties({ RepositoryProperties.class, ControllerPollProperties.class,

View File

@@ -22,8 +22,7 @@ public interface RolloutApprovalStrategy {
* important according to the implementation, e.g. user roles of the rollout * important according to the implementation, e.g. user roles of the rollout
* creator, state of the system, .... * creator, state of the system, ....
* *
* @param rollout * @param rollout rollout to decide for whether approval is needed.
* rollout to decide for whether approval is needed.
* @return true if the rollout according to this strategy needs approval. * @return true if the rollout according to this strategy needs approval.
*/ */
boolean isApprovalNeeded(Rollout rollout); boolean isApprovalNeeded(Rollout rollout);
@@ -34,8 +33,7 @@ public interface RolloutApprovalStrategy {
* Implementations may also decide to provide an empty implementation for this * Implementations may also decide to provide an empty implementation for this
* method. * method.
* *
* @param rollout * @param rollout rollout to create approval task for.
* rollout to create approval task for.
*/ */
void onApprovalRequired(Rollout rollout); void onApprovalRequired(Rollout rollout);
@@ -43,9 +41,8 @@ public interface RolloutApprovalStrategy {
* Returns the user that made a decision to approve or deny the given rollout. * Returns the user that made a decision to approve or deny the given rollout.
* Depending on the implementation this may be different to the current user eg. * Depending on the implementation this may be different to the current user eg.
* when the decision is made in an external system. * when the decision is made in an external system.
* *
* @param rollout * @param rollout target rollout
* target rollout
* @return identifier of the user that decided on approval * @return identifier of the user that decided on approval
*/ */
String getApprovalUser(Rollout rollout); String getApprovalUser(Rollout rollout);

View File

@@ -33,7 +33,7 @@ public final class RolloutHelper {
/** /**
* Verifies that the required success condition and action are actually set. * Verifies that the required success condition and action are actually set.
* *
* @param conditions input conditions and actions * @param conditions input conditions and actions
*/ */
public static void verifyRolloutGroupConditions(final RolloutGroupConditions conditions) { public static void verifyRolloutGroupConditions(final RolloutGroupConditions conditions) {
@@ -48,7 +48,7 @@ public final class RolloutHelper {
/** /**
* Verifies that the group has the required success condition and action and a * Verifies that the group has the required success condition and action and a
* valid target percentage. * valid target percentage.
* *
* @param group the input group * @param group the input group
* @return the verified group * @return the verified group
*/ */
@@ -68,7 +68,7 @@ public final class RolloutHelper {
/** /**
* Verify if the supplied amount of groups is in range * Verify if the supplied amount of groups is in range
* *
* @param amountGroup amount of groups * @param amountGroup amount of groups
* @param quotaManagement to retrieve maximum number of groups allowed * @param quotaManagement to retrieve maximum number of groups allowed
*/ */
@@ -81,7 +81,7 @@ public final class RolloutHelper {
/** /**
* Verify that the supplied percentage is in range * Verify that the supplied percentage is in range
* *
* @param percentage the percentage * @param percentage the percentage
*/ */
public static void verifyRolloutGroupTargetPercentage(final float percentage) { public static void verifyRolloutGroupTargetPercentage(final float percentage) {
@@ -95,7 +95,7 @@ public final class RolloutHelper {
/** /**
* Modifies the target filter query to only match targets that were created * Modifies the target filter query to only match targets that were created
* after the Rollout. * after the Rollout.
* *
* @param rollout Rollout to derive the filter from * @param rollout Rollout to derive the filter from
* @return resulting target filter query * @return resulting target filter query
*/ */
@@ -117,7 +117,7 @@ public final class RolloutHelper {
/** /**
* Verifies that the Rollout is in the required status. * Verifies that the Rollout is in the required status.
* *
* @param rollout the Rollout * @param rollout the Rollout
* @param status the Status * @param status the Status
*/ */
@@ -130,7 +130,7 @@ public final class RolloutHelper {
/** /**
* Filters the groups of a Rollout to match a specific status and adds a group * Filters the groups of a Rollout to match a specific status and adds a group
* to the result. * to the result.
* *
* @param status the required status for the groups * @param status the required status for the groups
* @param group the group to add * @param group the group to add
* @return list of groups * @return list of groups
@@ -187,16 +187,6 @@ public final class RolloutHelper {
return baseFilter; return baseFilter;
} }
private static boolean isTargetFilterInGroups(final String groupFilter, final List<RolloutGroup> groups) {
return !StringUtils.isEmpty(groupFilter)
&& groups.stream().anyMatch(prevGroup -> !StringUtils.isEmpty(prevGroup.getTargetFilterQuery())
&& prevGroup.getTargetFilterQuery().equals(groupFilter));
}
private static String concatAndTargetFilters(final String... filters) {
return "(" + Arrays.stream(filters).collect(Collectors.joining(");(")) + ")";
}
/** /**
* @param baseFilter the base filter from the rollout * @param baseFilter the base filter from the rollout
* @param group group for which the filter string should be created * @param group group for which the filter string should be created
@@ -211,7 +201,7 @@ public final class RolloutHelper {
/** /**
* Verifies that no targets are left * Verifies that no targets are left
* *
* @param targetCount the count of left targets * @param targetCount the count of left targets
*/ */
public static void verifyRemainingTargets(final long targetCount) { public static void verifyRemainingTargets(final long targetCount) {
@@ -254,4 +244,14 @@ public final class RolloutHelper {
public static String getIdFromRetriedTargetFilter(final String targetFilter) { public static String getIdFromRetriedTargetFilter(final String targetFilter) {
return targetFilter.substring("failedrollout==".length()); return targetFilter.substring("failedrollout==".length());
} }
private static boolean isTargetFilterInGroups(final String groupFilter, final List<RolloutGroup> groups) {
return !StringUtils.isEmpty(groupFilter)
&& groups.stream().anyMatch(prevGroup -> !StringUtils.isEmpty(prevGroup.getTargetFilterQuery())
&& prevGroup.getTargetFilterQuery().equals(groupFilter));
}
private static String concatAndTargetFilters(final String... filters) {
return "(" + Arrays.stream(filters).collect(Collectors.joining(");(")) + ")";
}
} }

View File

@@ -17,6 +17,7 @@ import java.util.stream.Collectors;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenancyCacheManager;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent;
@@ -31,26 +32,21 @@ import org.springframework.cache.Cache;
import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import com.github.benmanes.caffeine.cache.Caffeine;
/** /**
* Internal cache for Rollout status. * Internal cache for Rollout status.
*
*/ */
public class RolloutStatusCache { public class RolloutStatusCache {
private static final String CACHE_RO_NAME = "RolloutStatus"; private static final String CACHE_RO_NAME = "RolloutStatus";
private static final String CACHE_GR_NAME = "RolloutGroupStatus"; private static final String CACHE_GR_NAME = "RolloutGroupStatus";
private static final long DEFAULT_SIZE = 50_000; private static final long DEFAULT_SIZE = 50_000;
private final TenancyCacheManager cacheManager; private final TenancyCacheManager cacheManager;
private final TenantAware tenantAware; private final TenantAware tenantAware;
/** /**
* @param tenantAware * @param tenantAware to get current tenant
* to get current tenant * @param size the maximum size of the cache
* @param size
* the maximum size of the cache
*/ */
public RolloutStatusCache(final TenantAware tenantAware, final long size) { public RolloutStatusCache(final TenantAware tenantAware, final long size) {
this.tenantAware = tenantAware; this.tenantAware = tenantAware;
@@ -63,8 +59,7 @@ public class RolloutStatusCache {
} }
/** /**
* @param tenantAware * @param tenantAware to get current tenant
* to get current tenant
*/ */
public RolloutStatusCache(final TenantAware tenantAware) { public RolloutStatusCache(final TenantAware tenantAware) {
this(tenantAware, DEFAULT_SIZE); this(tenantAware, DEFAULT_SIZE);
@@ -74,8 +69,7 @@ public class RolloutStatusCache {
* Retrieves cached list of {@link TotalTargetCountActionStatus} of * Retrieves cached list of {@link TotalTargetCountActionStatus} of
* {@link Rollout}s. * {@link Rollout}s.
* *
* @param rollouts * @param rollouts rolloutIds to retrieve cache entries for
* rolloutIds to retrieve cache entries for
* @return map of cached entries * @return map of cached entries
*/ */
public Map<Long, List<TotalTargetCountActionStatus>> getRolloutStatus(final List<Long> rollouts) { public Map<Long, List<TotalTargetCountActionStatus>> getRolloutStatus(final List<Long> rollouts) {
@@ -86,8 +80,7 @@ public class RolloutStatusCache {
* Retrieves cached list of {@link TotalTargetCountActionStatus} of * Retrieves cached list of {@link TotalTargetCountActionStatus} of
* {@link Rollout}s. * {@link Rollout}s.
* *
* @param rolloutId * @param rolloutId to retrieve cache entries for
* to retrieve cache entries for
* @return map of cached entries * @return map of cached entries
*/ */
public List<TotalTargetCountActionStatus> getRolloutStatus(final Long rolloutId) { public List<TotalTargetCountActionStatus> getRolloutStatus(final Long rolloutId) {
@@ -98,8 +91,7 @@ public class RolloutStatusCache {
* Retrieves cached list of {@link TotalTargetCountActionStatus} of * Retrieves cached list of {@link TotalTargetCountActionStatus} of
* {@link RolloutGroup}s. * {@link RolloutGroup}s.
* *
* @param rolloutGroups * @param rolloutGroups rolloutGroupsIds to retrieve cache entries for
* rolloutGroupsIds to retrieve cache entries for
* @return map of cached entries * @return map of cached entries
*/ */
public Map<Long, List<TotalTargetCountActionStatus>> getRolloutGroupStatus(final List<Long> rolloutGroups) { public Map<Long, List<TotalTargetCountActionStatus>> getRolloutGroupStatus(final List<Long> rolloutGroups) {
@@ -110,8 +102,7 @@ public class RolloutStatusCache {
* Retrieves cached list of {@link TotalTargetCountActionStatus} of * Retrieves cached list of {@link TotalTargetCountActionStatus} of
* {@link RolloutGroup}. * {@link RolloutGroup}.
* *
* @param groupId * @param groupId to retrieve cache entries for
* to retrieve cache entries for
* @return map of cached entries * @return map of cached entries
*/ */
public List<TotalTargetCountActionStatus> getRolloutGroupStatus(final Long groupId) { public List<TotalTargetCountActionStatus> getRolloutGroupStatus(final Long groupId) {
@@ -122,8 +113,7 @@ public class RolloutStatusCache {
* Put map of {@link TotalTargetCountActionStatus} for multiple * Put map of {@link TotalTargetCountActionStatus} for multiple
* {@link Rollout}s into cache. * {@link Rollout}s into cache.
* *
* @param put * @param put map of cached entries
* map of cached entries
*/ */
public void putRolloutStatus(final Map<Long, List<TotalTargetCountActionStatus>> put) { public void putRolloutStatus(final Map<Long, List<TotalTargetCountActionStatus>> put) {
putIntoCache(put, getRolloutStatusCache()); putIntoCache(put, getRolloutStatusCache());
@@ -133,23 +123,18 @@ public class RolloutStatusCache {
* Put {@link TotalTargetCountActionStatus} for one {@link Rollout}s into * Put {@link TotalTargetCountActionStatus} for one {@link Rollout}s into
* cache. * cache.
* *
* @param rolloutId * @param rolloutId the cache entries belong to
* the cache entries belong to * @param status list to cache
* @param status
* list to cache
*
*/ */
public void putRolloutStatus(final Long rolloutId, final List<TotalTargetCountActionStatus> status) { public void putRolloutStatus(final Long rolloutId, final List<TotalTargetCountActionStatus> status) {
putIntoCache(rolloutId, status, getRolloutStatusCache()); putIntoCache(rolloutId, status, getRolloutStatusCache());
} }
/** /**
* Put {@link TotalTargetCountActionStatus} for multiple * Put {@link TotalTargetCountActionStatus} for multiple
* {@link RolloutGroup}s into cache. * {@link RolloutGroup}s into cache.
* *
* @param put * @param put map of cached entries
* map of cached entries
*/ */
public void putRolloutGroupStatus(final Map<Long, List<TotalTargetCountActionStatus>> put) { public void putRolloutGroupStatus(final Map<Long, List<TotalTargetCountActionStatus>> put) {
putIntoCache(put, getGroupStatusCache()); putIntoCache(put, getGroupStatusCache());
@@ -159,41 +144,13 @@ public class RolloutStatusCache {
* Put {@link TotalTargetCountActionStatus} for multiple * Put {@link TotalTargetCountActionStatus} for multiple
* {@link RolloutGroup}s into cache. * {@link RolloutGroup}s into cache.
* *
* @param groupId * @param groupId the cache entries belong to
* the cache entries belong to * @param status list to cache
* @param status
* list to cache
*/ */
public void putRolloutGroupStatus(final Long groupId, final List<TotalTargetCountActionStatus> status) { public void putRolloutGroupStatus(final Long groupId, final List<TotalTargetCountActionStatus> status) {
putIntoCache(groupId, status, getGroupStatusCache()); putIntoCache(groupId, status, getGroupStatusCache());
} }
private Map<Long, List<TotalTargetCountActionStatus>> retrieveFromCache(final List<Long> ids,
@NotNull final Cache cache) {
return ids.stream().map(id -> cache.get(id, CachedTotalTargetCountActionStatus.class)).filter(Objects::nonNull)
.collect(Collectors.toMap(CachedTotalTargetCountActionStatus::getId,
CachedTotalTargetCountActionStatus::getStatus));
}
private List<TotalTargetCountActionStatus> retrieveFromCache(final Long id, @NotNull final Cache cache) {
final CachedTotalTargetCountActionStatus cacheItem = cache.get(id, CachedTotalTargetCountActionStatus.class);
if (cacheItem == null) {
return Collections.emptyList();
}
return cacheItem.getStatus();
}
private void putIntoCache(final Long id, final List<TotalTargetCountActionStatus> status,
@NotNull final Cache cache) {
cache.put(id, new CachedTotalTargetCountActionStatus(id, status));
}
private void putIntoCache(final Map<Long, List<TotalTargetCountActionStatus>> put, @NotNull final Cache cache) {
put.forEach((k, v) -> cache.put(k, new CachedTotalTargetCountActionStatus(k, v)));
}
@EventListener(classes = AbstractActionEvent.class) @EventListener(classes = AbstractActionEvent.class)
public void invalidateCachedTotalTargetCountActionStatus(final AbstractActionEvent event) { public void invalidateCachedTotalTargetCountActionStatus(final AbstractActionEvent event) {
if (event.getRolloutId() != null) { if (event.getRolloutId() != null) {
@@ -235,13 +192,38 @@ public class RolloutStatusCache {
* Evicts all caches for a given tenant. All caches under a certain tenant * Evicts all caches for a given tenant. All caches under a certain tenant
* gets evicted. * gets evicted.
* *
* @param tenant * @param tenant the tenant to evict caches
* the tenant to evict caches
*/ */
public void evictCaches(final String tenant) { public void evictCaches(final String tenant) {
cacheManager.evictCaches(tenant); cacheManager.evictCaches(tenant);
} }
private Map<Long, List<TotalTargetCountActionStatus>> retrieveFromCache(final List<Long> ids,
@NotNull final Cache cache) {
return ids.stream().map(id -> cache.get(id, CachedTotalTargetCountActionStatus.class)).filter(Objects::nonNull)
.collect(Collectors.toMap(CachedTotalTargetCountActionStatus::getId,
CachedTotalTargetCountActionStatus::getStatus));
}
private List<TotalTargetCountActionStatus> retrieveFromCache(final Long id, @NotNull final Cache cache) {
final CachedTotalTargetCountActionStatus cacheItem = cache.get(id, CachedTotalTargetCountActionStatus.class);
if (cacheItem == null) {
return Collections.emptyList();
}
return cacheItem.getStatus();
}
private void putIntoCache(final Long id, final List<TotalTargetCountActionStatus> status,
@NotNull final Cache cache) {
cache.put(id, new CachedTotalTargetCountActionStatus(id, status));
}
private void putIntoCache(final Map<Long, List<TotalTargetCountActionStatus>> put, @NotNull final Cache cache) {
put.forEach((k, v) -> cache.put(k, new CachedTotalTargetCountActionStatus(k, v)));
}
private @NotNull Cache getRolloutStatusCache() { private @NotNull Cache getRolloutStatusCache() {
return Objects.requireNonNull(cacheManager.getCache(CACHE_RO_NAME), "Cache '" + CACHE_RO_NAME + "' is null!"); return Objects.requireNonNull(cacheManager.getCache(CACHE_RO_NAME), "Cache '" + CACHE_RO_NAME + "' is null!");
} }
@@ -251,6 +233,7 @@ public class RolloutStatusCache {
} }
private static final class CachedTotalTargetCountActionStatus { private static final class CachedTotalTargetCountActionStatus {
private final long id; private final long id;
private final List<TotalTargetCountActionStatus> status; private final List<TotalTargetCountActionStatus> status;

View File

@@ -22,8 +22,7 @@ import org.springframework.util.StringUtils;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractActionStatusCreate<T> { public abstract class AbstractActionStatusCreate<T> {

View File

@@ -12,14 +12,10 @@ package org.eclipse.hawkbit.repository.builder;
import java.util.Collection; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
import org.eclipse.hawkbit.repository.ValidString;
import org.springframework.util.StringUtils;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractDistributionSetTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> { public abstract class AbstractDistributionSetTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> {

View File

@@ -17,10 +17,10 @@ import org.springframework.util.StringUtils;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractMetadataUpdateCreate<T> { public abstract class AbstractMetadataUpdateCreate<T> {
@ValidString @ValidString
protected String key; protected String key;

View File

@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.repository.builder;
import java.util.Optional; import java.util.Optional;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.Null;
import org.eclipse.hawkbit.repository.ValidString; import org.eclipse.hawkbit.repository.ValidString;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;

View File

@@ -16,10 +16,10 @@ import org.springframework.util.StringUtils;
/** /**
* Create builder DTO. * Create builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractRolloutGroupCreate<T> extends AbstractNamedEntityBuilder<T> { public abstract class AbstractRolloutGroupCreate<T> extends AbstractNamedEntityBuilder<T> {
@ValidString @ValidString
protected String targetFilterQuery; protected String targetFilterQuery;
protected Float targetPercentage; protected Float targetPercentage;

View File

@@ -14,10 +14,10 @@ import java.util.Optional;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractSoftwareModuleMetadataUpdateCreate<T> extends AbstractMetadataUpdateCreate<T> { public abstract class AbstractSoftwareModuleMetadataUpdateCreate<T> extends AbstractMetadataUpdateCreate<T> {
protected Boolean targetVisible; protected Boolean targetVisible;
protected long softwareModuleId; protected long softwareModuleId;

View File

@@ -12,8 +12,7 @@ package org.eclipse.hawkbit.repository.builder;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractSoftwareModuleTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> { public abstract class AbstractSoftwareModuleTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> {

View File

@@ -17,10 +17,10 @@ import org.springframework.util.StringUtils;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractSoftwareModuleUpdateCreate<T> extends AbstractNamedEntityBuilder<T> { public abstract class AbstractSoftwareModuleUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
@ValidString @ValidString
protected String version; protected String version;

View File

@@ -17,10 +17,10 @@ import org.springframework.util.StringUtils;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public class AbstractTagUpdateCreate<T> extends AbstractNamedEntityBuilder<T> { public class AbstractTagUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
@ValidString @ValidString
protected String colour; protected String colour;

View File

@@ -23,10 +23,10 @@ import org.springframework.util.StringUtils;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractBaseEntityBuilder { public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractBaseEntityBuilder {
@ValidString @ValidString
protected String name; protected String name;
@@ -40,14 +40,13 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
@Min(Action.WEIGHT_MIN) @Min(Action.WEIGHT_MIN)
@Max(Action.WEIGHT_MAX) @Max(Action.WEIGHT_MAX)
protected Integer weight; protected Integer weight;
protected Boolean confirmationRequired; protected Boolean confirmationRequired;
/** /**
* Set DS ID of the {@link Action} created during auto assignment * Set DS ID of the {@link Action} created during auto assignment
* *
* @param distributionSetId * @param distributionSetId of the {@link TargetFilterQuery}
* of the {@link TargetFilterQuery}
* @return this builder * @return this builder
*/ */
public T autoAssignDistributionSet(final Long distributionSetId) { public T autoAssignDistributionSet(final Long distributionSetId) {
@@ -62,9 +61,8 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
/** /**
* Set {@link ActionType} of the {@link Action} created during auto * Set {@link ActionType} of the {@link Action} created during auto
* assignment * assignment
* *
* @param actionType * @param actionType of the {@link TargetFilterQuery}
* of the {@link TargetFilterQuery}
* @return this builder * @return this builder
*/ */
public T autoAssignActionType(final ActionType actionType) { public T autoAssignActionType(final ActionType actionType) {
@@ -74,9 +72,8 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
/** /**
* Set weight of the {@link Action} created during auto assignment * Set weight of the {@link Action} created during auto assignment
* *
* @param weight * @param weight of the {@link TargetFilterQuery}
* of the {@link TargetFilterQuery}
* @return this builder * @return this builder
*/ */
public T autoAssignWeight(final Integer weight) { public T autoAssignWeight(final Integer weight) {
@@ -94,9 +91,8 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
/** /**
* Set name of the filter * Set name of the filter
* *
* @param name * @param name of the {@link TargetFilterQuery}
* of the {@link TargetFilterQuery}
* @return this builder * @return this builder
*/ */
public T name(final String name) { public T name(final String name) {
@@ -110,9 +106,8 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
/** /**
* Set query used by the filter * Set query used by the filter
* *
* @param query * @param query of the {@link TargetFilterQuery}
* of the {@link TargetFilterQuery}
* @return this builder * @return this builder
*/ */
public T query(final String query) { public T query(final String query) {
@@ -125,9 +120,8 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
} }
/** /**
* @param confirmationRequired * @param confirmationRequired if confirmation is required for configured auto assignment
* if confirmation is required for configured auto assignment * (considered with confirmation flow active)
* (considered with confirmation flow active)
* @return updated builder instance * @return updated builder instance
*/ */
public T confirmationRequired(final boolean confirmationRequired) { public T confirmationRequired(final boolean confirmationRequired) {

View File

@@ -9,25 +9,20 @@
*/ */
package org.eclipse.hawkbit.repository.builder; package org.eclipse.hawkbit.repository.builder;
import org.eclipse.hawkbit.repository.ValidString;
import org.springframework.util.StringUtils;
import java.util.Collection; import java.util.Collection;
import java.util.Optional; import java.util.Optional;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractTargetTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> { public abstract class AbstractTargetTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> {
protected Collection<Long> compatible; protected Collection<Long> compatible;
/** /**
* @param compatible * @param compatible list of ID
* list of ID
* @return generic type * @return generic type
*/ */
public T compatible(final Collection<Long> compatible) { public T compatible(final Collection<Long> compatible) {
@@ -36,7 +31,7 @@ public abstract class AbstractTargetTypeUpdateCreate<T> extends AbstractTypeUpda
} }
/** /**
* @return List of ID * @return List of ID
*/ */
public Optional<Collection<Long>> getCompatible() { public Optional<Collection<Long>> getCompatible() {
return Optional.ofNullable(compatible); return Optional.ofNullable(compatible);

View File

@@ -21,10 +21,10 @@ import org.springframework.util.StringUtils;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T> { public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
@ValidString @ValidString
protected String controllerId; protected String controllerId;
@@ -37,7 +37,7 @@ public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T>
protected Long lastTargetQuery; protected Long lastTargetQuery;
protected TargetUpdateStatus status; protected TargetUpdateStatus status;
protected Boolean requestAttributes; protected Boolean requestAttributes;
protected Long targetTypeId; protected Long targetTypeId;

View File

@@ -9,16 +9,15 @@
*/ */
package org.eclipse.hawkbit.repository.builder; package org.eclipse.hawkbit.repository.builder;
import java.util.Optional;
import org.eclipse.hawkbit.repository.ValidString; import org.eclipse.hawkbit.repository.ValidString;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.Optional;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
* *
* @param <T> * @param <T> update or create builder interface
* update or create builder interface
*/ */
public abstract class AbstractTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> { public abstract class AbstractTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {

View File

@@ -10,13 +10,12 @@
package org.eclipse.hawkbit.repository.builder; package org.eclipse.hawkbit.repository.builder;
import jakarta.annotation.Nullable; import jakarta.annotation.Nullable;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.util.Optional;
/** /**
* Update implementation. * Update implementation.
*/ */

View File

@@ -10,13 +10,12 @@
package org.eclipse.hawkbit.repository.builder; package org.eclipse.hawkbit.repository.builder;
import jakarta.annotation.Nullable; import jakarta.annotation.Nullable;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.util.Optional;
/** /**
* Update implementation. * Update implementation.
*/ */

View File

@@ -13,6 +13,7 @@ package org.eclipse.hawkbit.repository.builder;
* Update implementation. * Update implementation.
*/ */
public class GenericTagUpdate extends AbstractTagUpdateCreate<TagUpdate> implements TagUpdate { public class GenericTagUpdate extends AbstractTagUpdateCreate<TagUpdate> implements TagUpdate {
public GenericTagUpdate(final Long id) { public GenericTagUpdate(final Long id) {
super.id = id; super.id = id;
} }

View File

@@ -16,8 +16,7 @@ public class GenericTargetTypeUpdate extends AbstractTargetTypeUpdateCreate<Targ
implements TargetTypeUpdate { implements TargetTypeUpdate {
/** /**
* @param id * @param id Target type ID
* Target type ID
*/ */
public GenericTargetTypeUpdate(final Long id) { public GenericTargetTypeUpdate(final Long id) {
super.id = id; super.id = id;

View File

@@ -25,7 +25,8 @@ public final class SystemManagementHolder {
private static final SystemManagementHolder INSTANCE = new SystemManagementHolder(); private static final SystemManagementHolder INSTANCE = new SystemManagementHolder();
@Getter @Setter @Getter
@Setter
@Autowired @Autowired
private SystemManagement systemManagement; private SystemManagement systemManagement;

View File

@@ -15,6 +15,7 @@ import static org.mockito.Mockito.when;
import java.util.HashMap; import java.util.HashMap;
import io.qameta.allure.Description;
import org.eclipse.hawkbit.repository.event.remote.entity.RemoteEntityEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RemoteEntityEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
@@ -28,8 +29,6 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConversionException;
import io.qameta.allure.Description;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class BusProtoStuffMessageConverterTest { public class BusProtoStuffMessageConverterTest {