Code refactoring of hawkbit-repository (#2056)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-17 15:03:03 +02:00
committed by GitHub
parent 7cb617007a
commit f9bb48d697
118 changed files with 622 additions and 797 deletions

View File

@@ -65,4 +65,4 @@ public class ErrorController extends BasicErrorController {
} }
return body; return body;
} }
} }

View File

@@ -42,8 +42,7 @@ public class Start {
public static class RedirectController { public static class RedirectController {
@GetMapping("/") @GetMapping("/")
public RedirectView redirectToSwagger( public RedirectView redirectToSwagger(final RedirectAttributes attributes) {
RedirectAttributes attributes) {
attributes.addFlashAttribute("flashAttribute", "redirectWithRedirectView"); attributes.addFlashAttribute("flashAttribute", "redirectWithRedirectView");
attributes.addAttribute("attribute", "redirectWithRedirectView"); attributes.addAttribute("attribute", "redirectWithRedirectView");
return new RedirectView("swagger-ui/index.html"); return new RedirectView("swagger-ui/index.html");
@@ -52,7 +51,5 @@ public class Start {
@Configuration @Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, proxyTargetClass = true) @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, proxyTargetClass = true)
public static class MethodSecurityConfig { public static class MethodSecurityConfig {}
}
} }

View File

@@ -32,26 +32,29 @@ public class PreAuthorizeEnabledTest extends AbstractSecurityTest {
@Description("Tests whether request fail if a role is forbidden for the user") @Description("Tests whether request fail if a role is forbidden for the user")
@WithUser(authorities = { SpPermission.READ_TARGET }) @WithUser(authorities = { SpPermission.READ_TARGET })
public void failIfNoRole() throws Exception { public void failIfNoRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets")).andExpect(result -> mvc.perform(get("/rest/v1/distributionsets"))
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.FORBIDDEN.value())); .andExpect(result ->
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.FORBIDDEN.value()));
} }
@Test @Test
@Description("Tests whether request succeed if a role is granted for the user") @Description("Tests whether request succeed if a role is granted for the user")
@WithUser(authorities = { SpPermission.READ_REPOSITORY }) @WithUser(authorities = { SpPermission.READ_REPOSITORY })
public void successIfHasRole() throws Exception { public void successIfHasRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets")).andExpect(result -> { mvc.perform(get("/rest/v1/distributionsets"))
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()); .andExpect(result -> {
}); assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
});
} }
@Test @Test
@Description("Tests whether request succeed if a role is granted for the user") @Description("Tests whether request succeed if a role is granted for the user")
@WithUser(authorities = { SpRole.TENANT_ADMIN }) @WithUser(authorities = { SpRole.TENANT_ADMIN })
public void successIfHasTenantAdminRole() throws Exception { public void successIfHasTenantAdminRole() throws Exception {
mvc.perform(get("/rest/v1/distributionsets")).andExpect(result -> { mvc.perform(get("/rest/v1/distributionsets"))
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()); .andExpect(result -> {
}); assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
});
} }
@Test @Test
@@ -59,14 +62,15 @@ public class PreAuthorizeEnabledTest extends AbstractSecurityTest {
"granted for the user") "granted for the user")
@WithUser(authorities = { SpPermission.READ_TARGET }) @WithUser(authorities = { SpPermission.READ_TARGET })
public void onlyDSIfNoTenantConfig() throws Exception { public void onlyDSIfNoTenantConfig() throws Exception {
mvc.perform(get("/rest/v1/system/configs")).andExpect(result -> { mvc.perform(get("/rest/v1/system/configs"))
// returns default DS type because of READ_TARGET .andExpect(result -> {
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()); // returns default DS type because of READ_TARGET
assertThat( assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
new ObjectMapper().reader().readValue(result.getResponse().getContentAsString(), HashMap.class) assertThat(
.size()) new ObjectMapper().reader().readValue(result.getResponse().getContentAsString(), HashMap.class)
.isEqualTo(1); .size())
}); .isEqualTo(1);
});
} }
@Test @Test
@@ -74,7 +78,8 @@ public class PreAuthorizeEnabledTest extends AbstractSecurityTest {
"granted for the user") "granted for the user")
@WithUser(authorities = { SpPermission.TENANT_CONFIGURATION }) @WithUser(authorities = { SpPermission.TENANT_CONFIGURATION })
public void successIfHasTenantConfig() throws Exception { public void successIfHasTenantConfig() throws Exception {
mvc.perform(get("/rest/v1/system/configs")).andExpect(result -> mvc.perform(get("/rest/v1/system/configs"))
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value())); .andExpect(result ->
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value()));
} }
} }

View File

@@ -33,14 +33,6 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.hateoas</groupId> <groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId> <artifactId>spring-hateoas</artifactId>
@@ -71,6 +63,16 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.cronutils</groupId> <groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId> <artifactId>cron-utils</artifactId>

View File

@@ -9,6 +9,8 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import java.io.Serial;
import lombok.Data; import lombok.Data;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
@@ -23,6 +25,7 @@ import org.springframework.data.domain.Sort;
@Data @Data
public final class OffsetBasedPageRequest extends PageRequest { public final class OffsetBasedPageRequest extends PageRequest {
@Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final long offset; private final long offset;

View File

@@ -18,12 +18,12 @@ import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.PollStatus;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;

View File

@@ -54,4 +54,4 @@ public interface ActionStatusCreate {
* @return peek on current state of {@link ActionStatus} in the builder * @return peek on current state of {@link ActionStatus} in the builder
*/ */
ActionStatus build(); ActionStatus build();
} }

View File

@@ -26,13 +26,11 @@ import org.eclipse.hawkbit.repository.model.MetaData;
@Getter @Getter
public class EntityNotFoundException extends AbstractServerRtException { public class EntityNotFoundException extends AbstractServerRtException {
@Serial
private static final long serialVersionUID = 1L;
public static final String KEY = "key"; public static final String KEY = "key";
public static final String ENTITY_ID = "entityId"; public static final String ENTITY_ID = "entityId";
public static final String TYPE = "type"; public static final String TYPE = "type";
@Serial
private static final long serialVersionUID = 1L;
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_ENTITY_NOT_EXISTS; private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_ENTITY_NOT_EXISTS;
private static final int ENTITY_STRING_MAX_LENGTH = 100; private static final int ENTITY_STRING_MAX_LENGTH = 100;

View File

@@ -27,7 +27,7 @@ public class IncompatibleTargetTypeException extends AbstractServerRtException {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final Collection<String> targetTypeNames; private final Collection<String> targetTypeNames;
private final Collection<String> distributionSetTypeNames; private final Collection<String> distributionSetTypeNames;

View File

@@ -12,9 +12,9 @@ package org.eclipse.hawkbit.tenancy.configuration.validator;
import java.time.Duration; import java.time.Duration;
import java.time.format.DateTimeParseException; import java.time.format.DateTimeParseException;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.eclipse.hawkbit.tenancy.configuration.ControllerPollProperties; import org.eclipse.hawkbit.tenancy.configuration.ControllerPollProperties;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**

View File

@@ -36,14 +36,12 @@ import org.springframework.util.MimeType;
public class BusProtoStuffMessageConverter extends AbstractMessageConverter { public class BusProtoStuffMessageConverter extends AbstractMessageConverter {
public static final MimeType APPLICATION_BINARY_PROTOSTUFF = new MimeType("application", "binary+protostuff"); public static final MimeType APPLICATION_BINARY_PROTOSTUFF = new MimeType("application", "binary+protostuff");
/** /**
* The length of the class type length of the payload. * The length of the class type length of the payload.
*/ */
private static final byte EVENT_TYPE_LENGTH = 2; private static final byte EVENT_TYPE_LENGTH = 2;
/**
* Constructor.
*/
public BusProtoStuffMessageConverter() { public BusProtoStuffMessageConverter() {
super(APPLICATION_BINARY_PROTOSTUFF); super(APPLICATION_BINARY_PROTOSTUFF);
} }

View File

@@ -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; private int value;
/** /**

View File

@@ -111,4 +111,4 @@ public class PropertiesQuotaManagement implements QuotaManagement {
public int getMaxDistributionSetTypesPerTargetType() { public int getMaxDistributionSetTypesPerTargetType() {
return securityProperties.getDos().getMaxDistributionSetTypesPerTargetType(); return securityProperties.getDos().getMaxDistributionSetTypesPerTargetType();
} }
} }

View File

@@ -19,9 +19,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, TenantConfigurationProperties.class })
TenantConfigurationProperties.class })
@PropertySource("classpath:/hawkbit-repository-defaults.properties") @PropertySource("classpath:/hawkbit-repository-defaults.properties")
public class RepositoryDefaultConfiguration { public class RepositoryDefaultConfiguration {}
}

View File

@@ -46,4 +46,4 @@ public interface RolloutApprovalStrategy {
* @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

@@ -250,4 +250,4 @@ public class RolloutStatusCache {
return status; return status;
} }
} }
} }

View File

@@ -29,16 +29,12 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.T
public final class TimestampCalculator { public final class TimestampCalculator {
/** /**
* Calculates the overdue timestamp (<em>overdue_ts</em>) based on the * Calculates the overdue timestamp (<em>overdue_ts</em>) based on the current timestamp and the intervals for polling and poll-overdue:
* current timestamp and the intervals for polling and poll-overdue:
* <p> * <p>
* <em>overdue_ts = now_ts - pollingInterval - * <em>overdue_ts = now_ts - pollingInterval - pollingOverdueInterval</em>;<br>
* pollingOverdueInterval</em>;<br> * <em>pollingInterval</em> and <em>pollingOverdueInterval</em> are retrieved from tenant-specific system configuration.
* <em>pollingInterval</em> and <em>pollingOverdueInterval</em> are
* retrieved from tenant-specific system configuration.
* *
* @return <em>overdue_ts</em> in milliseconds since Unix epoch as long * @return <em>overdue_ts</em> in milliseconds since Unix epoch as long value
* value
*/ */
public static long calculateOverdueTimestamp() { public static long calculateOverdueTimestamp() {
return Instant.now().toEpochMilli() - getDurationForKey(TenantConfigurationKey.POLLING_TIME_INTERVAL).toMillis() return Instant.now().toEpochMilli() - getDurationForKey(TenantConfigurationKey.POLLING_TIME_INTERVAL).toMillis()

View File

@@ -18,7 +18,6 @@ import java.util.stream.Collectors;
import lombok.Getter; import lombok.Getter;
import org.eclipse.hawkbit.repository.ValidString; import org.eclipse.hawkbit.repository.ValidString;
import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Action.Status;
import org.springframework.util.StringUtils;
/** /**
* Create and update builder DTO. * Create and update builder DTO.
@@ -28,31 +27,24 @@ import org.springframework.util.StringUtils;
public abstract class AbstractActionStatusCreate<T> { public abstract class AbstractActionStatusCreate<T> {
protected Status status; protected Status status;
protected Long occurredAt; protected Long occurredAt;
protected Integer code; protected Integer code;
protected List<@ValidString String> messages; protected List<@ValidString String> messages;
@Getter @Getter
protected Long actionId; protected Long actionId;
public T status(final Status status) { public T status(final Status status) {
this.status = status; this.status = status;
return (T) this; return (T) this;
} }
public T occurredAt(final long occurredAt) { public T occurredAt(final long occurredAt) {
this.occurredAt = occurredAt; this.occurredAt = occurredAt;
return (T) this; return (T) this;
} }
public T code(final int code) { public T code(final int code) {
this.code = code; this.code = code;
return (T) this; return (T) this;
} }
@@ -63,7 +55,6 @@ public abstract class AbstractActionStatusCreate<T> {
} else { } else {
this.messages.addAll(messages.stream().map(String::strip).toList()); this.messages.addAll(messages.stream().map(String::strip).toList());
} }
return (T) this; return (T) this;
} }
@@ -72,7 +63,6 @@ public abstract class AbstractActionStatusCreate<T> {
this.messages = new ArrayList<>(); this.messages = new ArrayList<>();
} }
this.messages.add(message.strip()); this.messages.add(message.strip());
return (T) this; return (T) this;
} }

View File

@@ -19,5 +19,4 @@ public abstract class AbstractBaseEntityBuilder implements Identifiable<Long> {
public Long getId() { public Long getId() {
return id; return id;
} }
}
}

View File

@@ -39,4 +39,4 @@ public abstract class AbstractDistributionSetTypeUpdateCreate<T> extends Abstrac
public Optional<Collection<Long>> getOptional() { public Optional<Collection<Long>> getOptional() {
return Optional.ofNullable(optional); return Optional.ofNullable(optional);
} }
} }

View File

@@ -23,7 +23,6 @@ public abstract class AbstractMetadataUpdateCreate<T> {
@ValidString @ValidString
protected String key; protected String key;
@ValidString @ValidString
protected String value; protected String value;
@@ -44,5 +43,4 @@ public abstract class AbstractMetadataUpdateCreate<T> {
public Optional<String> getValue() { public Optional<String> getValue() {
return Optional.ofNullable(value); return Optional.ofNullable(value);
} }
}
}

View File

@@ -18,7 +18,6 @@ public abstract class AbstractNamedEntityBuilder<T> extends AbstractBaseEntityBu
@ValidString @ValidString
protected String name; protected String name;
@ValidString @ValidString
protected String description; protected String description;

View File

@@ -45,5 +45,4 @@ public abstract class AbstractRolloutGroupCreate<T> extends AbstractNamedEntityB
this.confirmationRequired = confirmationRequired; this.confirmationRequired = confirmationRequired;
return (T) this; return (T) this;
} }
}
}

View File

@@ -38,5 +38,4 @@ public abstract class AbstractSoftwareModuleMetadataUpdateCreate<T> extends Abst
this.targetVisible = targetVisible; this.targetVisible = targetVisible;
return (T) this; return (T) this;
} }
}
}

View File

@@ -23,10 +23,8 @@ public abstract class AbstractSoftwareModuleUpdateCreate<T> extends AbstractName
@ValidString @ValidString
protected String version; protected String version;
@ValidString @ValidString
protected String vendor; protected String vendor;
@ValidString @ValidString
protected String type; protected String type;
@@ -56,5 +54,4 @@ public abstract class AbstractSoftwareModuleUpdateCreate<T> extends AbstractName
public Optional<String> getVersion() { public Optional<String> getVersion() {
return Optional.ofNullable(version); return Optional.ofNullable(version);
} }
}
}

View File

@@ -32,5 +32,4 @@ public class AbstractTagUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
public Optional<String> getColour() { public Optional<String> getColour() {
return Optional.ofNullable(colour); return Optional.ofNullable(colour);
} }
}
}

View File

@@ -29,18 +29,13 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
@ValidString @ValidString
protected String name; protected String name;
@ValidString @ValidString
protected String query; protected String query;
protected Long distributionSetId; protected Long distributionSetId;
protected ActionType actionType; protected ActionType actionType;
@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;
/** /**
@@ -132,4 +127,4 @@ public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractB
public Optional<Boolean> getConfirmationRequired() { public Optional<Boolean> getConfirmationRequired() {
return Optional.ofNullable(confirmationRequired); return Optional.ofNullable(confirmationRequired);
} }
} }

View File

@@ -36,4 +36,4 @@ public abstract class AbstractTargetTypeUpdateCreate<T> extends AbstractTypeUpda
public Optional<Collection<Long>> getCompatible() { public Optional<Collection<Long>> getCompatible() {
return Optional.ofNullable(compatible); return Optional.ofNullable(compatible);
} }
} }

View File

@@ -27,18 +27,13 @@ public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T>
@ValidString @ValidString
protected String controllerId; protected String controllerId;
protected String address; protected String address;
@ToString.Exclude @ToString.Exclude
@ValidString @ValidString
protected String securityToken; protected String securityToken;
protected Long lastTargetQuery; protected Long lastTargetQuery;
protected TargetUpdateStatus status; protected TargetUpdateStatus status;
protected Boolean requestAttributes; protected Boolean requestAttributes;
protected Long targetTypeId; protected Long targetTypeId;
protected AbstractTargetUpdateCreate(final String controllerId) { protected AbstractTargetUpdateCreate(final String controllerId) {

View File

@@ -43,4 +43,4 @@ public abstract class AbstractTypeUpdateCreate<T> extends AbstractNamedEntityBui
public Optional<String> getKey() { public Optional<String> getKey() {
return Optional.ofNullable(key); return Optional.ofNullable(key);
} }
} }

View File

@@ -18,5 +18,4 @@ public class GenericDistributionSetTypeUpdate extends AbstractDistributionSetTyp
public GenericDistributionSetTypeUpdate(final Long id) { public GenericDistributionSetTypeUpdate(final Long id) {
super.id = id; super.id = id;
} }
}
}

View File

@@ -23,8 +23,7 @@ import lombok.experimental.Accessors;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)
@Accessors(fluent = true) @Accessors(fluent = true)
public class GenericDistributionSetUpdate extends AbstractDistributionSetUpdateCreate<DistributionSetUpdate> public class GenericDistributionSetUpdate extends AbstractDistributionSetUpdateCreate<DistributionSetUpdate> implements DistributionSetUpdate {
implements DistributionSetUpdate {
@Nullable @Nullable
protected Boolean locked; protected Boolean locked;

View File

@@ -17,4 +17,4 @@ public class GenericRolloutUpdate extends AbstractNamedEntityBuilder<RolloutUpda
public GenericRolloutUpdate(final Long id) { public GenericRolloutUpdate(final Long id) {
super.id = id; super.id = id;
} }
} }

View File

@@ -18,5 +18,4 @@ public class GenericSoftwareModuleTypeUpdate extends AbstractSoftwareModuleTypeU
public GenericSoftwareModuleTypeUpdate(final Long id) { public GenericSoftwareModuleTypeUpdate(final Long id) {
super.id = id; super.id = id;
} }
}
}

View File

@@ -17,4 +17,4 @@ public class GenericTagUpdate extends AbstractTagUpdateCreate<TagUpdate> impleme
public GenericTagUpdate(final Long id) { public GenericTagUpdate(final Long id) {
super.id = id; super.id = id;
} }
} }

View File

@@ -18,5 +18,4 @@ public class GenericTargetFilterQueryUpdate extends AbstractTargetFilterQueryUpd
public GenericTargetFilterQueryUpdate(final Long id) { public GenericTargetFilterQueryUpdate(final Long id) {
super.id = id; super.id = id;
} }
}
}

View File

@@ -21,5 +21,4 @@ public class GenericTargetTypeUpdate extends AbstractTargetTypeUpdateCreate<Targ
public GenericTargetTypeUpdate(final Long id) { public GenericTargetTypeUpdate(final Long id) {
super.id = id; super.id = id;
} }
}
}

View File

@@ -30,10 +30,8 @@ public final class EventPublisherHolder {
@Getter @Getter
@Autowired @Autowired
private ApplicationEventPublisher eventPublisher; private ApplicationEventPublisher eventPublisher;
@Autowired(required = false) @Autowired(required = false)
private ServiceMatcher serviceMatcher; private ServiceMatcher serviceMatcher;
@Autowired @Autowired
private BusProperties bus; private BusProperties bus;

View File

@@ -9,6 +9,7 @@
*/ */
package org.eclipse.hawkbit.repository.rsql; package org.eclipse.hawkbit.repository.rsql;
import java.io.Serial;
import java.time.Instant; import java.time.Instant;
import org.apache.commons.lang3.text.StrLookup; import org.apache.commons.lang3.text.StrLookup;
@@ -43,6 +44,7 @@ import org.eclipse.hawkbit.repository.TimestampCalculator;
*/ */
public class VirtualPropertyResolver extends StrLookup<String> implements VirtualPropertyReplacer { public class VirtualPropertyResolver extends StrLookup<String> implements VirtualPropertyReplacer {
@Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private transient StrSubstitutor substitutor; private transient StrSubstitutor substitutor;

View File

@@ -35,7 +35,6 @@ import org.eclipse.hawkbit.repository.RolloutGroupManagement;
import org.eclipse.hawkbit.repository.RolloutHelper; import org.eclipse.hawkbit.repository.RolloutHelper;
import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.event.remote.RolloutGroupDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.RolloutStoppedEvent; import org.eclipse.hawkbit.repository.event.remote.RolloutStoppedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException; import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
@@ -232,7 +231,8 @@ public class JpaRolloutExecutor implements RolloutExecutor {
if (readyGroups == rolloutGroups.size()) { if (readyGroups == rolloutGroups.size()) {
if (rollout.isDynamic() && !rolloutGroups.get(rolloutGroups.size() - 1).isDynamic()) { if (rollout.isDynamic() && !rolloutGroups.get(rolloutGroups.size() - 1).isDynamic()) {
// add first dynamic group one by using the last as a parent and as a pattern // add first dynamic group one by using the last as a parent and as a pattern
createDynamicGroup(rollout, (JpaRolloutGroup) rolloutGroups.get(rolloutGroups.size() - 1), rolloutGroups.size(), RolloutGroupStatus.READY); createDynamicGroup(rollout, (JpaRolloutGroup) rolloutGroups.get(rolloutGroups.size() - 1), rolloutGroups.size(),
RolloutGroupStatus.READY);
} }
if (!rolloutApprovalStrategy.isApprovalNeeded(rollout)) { if (!rolloutApprovalStrategy.isApprovalNeeded(rollout)) {

View File

@@ -174,7 +174,6 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.domain.EntityScan;
@@ -183,7 +182,6 @@ import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers; import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;

View File

@@ -32,16 +32,14 @@ public interface AccessController<T> {
/** /**
* Introduce a new specification to limit the access to a specific entity. * Introduce a new specification to limit the access to a specific entity.
* *
* @return a new specification limiting the access, if empty no access restrictions * @return a new specification limiting the access, if empty no access restrictions are to be applied
* are to be applied
*/ */
Optional<Specification<T>> getAccessRules(Operation operation); Optional<Specification<T>> getAccessRules(Operation operation);
/** /**
* Append the resource limitation on an already existing specification. * Append the resource limitation on an already existing specification.
* *
* @param specification is the root specification which needs to be appended by the * @param specification is the root specification which needs to be appended by the resource limitation
* resource limitation
* @return a new appended specification * @return a new appended specification
*/ */
@Nullable @Nullable
@@ -79,17 +77,14 @@ public interface AccessController<T> {
* Entity creation * Entity creation
*/ */
CREATE, CREATE,
/** /**
* Read entities * Read entities
*/ */
READ, READ,
/** /**
* Entity modification (e.g. name/description change, tag/type assignment, etc.) * Entity modification (e.g. name/description change, tag/type assignment, etc.)
*/ */
UPDATE, UPDATE,
/** /**
* Entity deletion * Entity deletion
*/ */

View File

@@ -49,24 +49,20 @@ public class ExceptionMappingAspectHandler implements Ordered {
private static final List<Class<?>> MAPPED_EXCEPTION_ORDER = new ArrayList<>(4); private static final List<Class<?>> MAPPED_EXCEPTION_ORDER = new ArrayList<>(4);
static { static {
MAPPED_EXCEPTION_ORDER.add(DuplicateKeyException.class); MAPPED_EXCEPTION_ORDER.add(DuplicateKeyException.class);
MAPPED_EXCEPTION_ORDER.add(DataIntegrityViolationException.class); MAPPED_EXCEPTION_ORDER.add(DataIntegrityViolationException.class);
MAPPED_EXCEPTION_ORDER.add(OptimisticLockingFailureException.class); MAPPED_EXCEPTION_ORDER.add(OptimisticLockingFailureException.class);
MAPPED_EXCEPTION_ORDER.add(AccessDeniedException.class); MAPPED_EXCEPTION_ORDER.add(AccessDeniedException.class);
EXCEPTION_MAPPING.put(DuplicateKeyException.class.getName(), EntityAlreadyExistsException.class.getName()); EXCEPTION_MAPPING.put(DuplicateKeyException.class.getName(), EntityAlreadyExistsException.class.getName());
EXCEPTION_MAPPING.put(DataIntegrityViolationException.class.getName(), EXCEPTION_MAPPING.put(DataIntegrityViolationException.class.getName(), EntityAlreadyExistsException.class.getName());
EntityAlreadyExistsException.class.getName());
EXCEPTION_MAPPING.put(OptimisticLockingFailureException.class.getName(), EXCEPTION_MAPPING.put(OptimisticLockingFailureException.class.getName(), ConcurrentModificationException.class.getName());
ConcurrentModificationException.class.getName());
EXCEPTION_MAPPING.put(AccessDeniedException.class.getName(), InsufficientPermissionException.class.getName()); EXCEPTION_MAPPING.put(AccessDeniedException.class.getName(), InsufficientPermissionException.class.getName());
} }
/** /**
* catch exceptions of the {@link TransactionManager} and wrap them to * catch exceptions of the {@link TransactionManager} and wrap them to custom exceptions.
* custom exceptions.
* *
* @param ex the thrown and catched exception * @param ex the thrown and catched exception
* @throws Throwable * @throws Throwable
@@ -119,4 +115,4 @@ public class ExceptionMappingAspectHandler implements Ordered {
return rex; return rex;
} }
} }

View File

@@ -47,11 +47,8 @@ public abstract class AbstractAutoAssignExecutor implements AutoAssignExecutor {
private static final int PAGE_SIZE = 1000; private static final int PAGE_SIZE = 1000;
private final TargetFilterQueryManagement targetFilterQueryManagement; private final TargetFilterQueryManagement targetFilterQueryManagement;
private final DeploymentManagement deploymentManagement; private final DeploymentManagement deploymentManagement;
private final PlatformTransactionManager transactionManager; private final PlatformTransactionManager transactionManager;
private final ContextAware contextAware; private final ContextAware contextAware;
/** /**
@@ -177,4 +174,4 @@ public abstract class AbstractAutoAssignExecutor implements AutoAssignExecutor {
.setConfirmationRequired(filterQuery.isConfirmationRequired()).build()) .setConfirmationRequired(filterQuery.isConfirmationRequired()).build())
.toList(); .toList();
} }
} }

View File

@@ -66,11 +66,9 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor {
@Override @Override
public void checkSingleTarget(String controllerId) { public void checkSingleTarget(String controllerId) {
log.debug("Auto assign check call for tenant {} and device {} started", getContextAware().getCurrentTenant(), log.debug("Auto assign check call for tenant {} and device {} started", getContextAware().getCurrentTenant(), controllerId);
controllerId);
forEachFilterWithAutoAssignDS(filter -> checkForDevice(controllerId, filter)); forEachFilterWithAutoAssignDS(filter -> checkForDevice(controllerId, filter));
log.debug("Auto assign check call for tenant {} and device {} finished", getContextAware().getCurrentTenant(), log.debug("Auto assign check call for tenant {} and device {} finished", getContextAware().getCurrentTenant(), controllerId);
controllerId);
} }
/** /**

View File

@@ -27,11 +27,8 @@ public class AutoAssignScheduler {
private static final String PROP_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.autoassign.scheduler.fixedDelay:2000}"; private static final String PROP_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.autoassign.scheduler.fixedDelay:2000}";
private final SystemManagement systemManagement; private final SystemManagement systemManagement;
private final SystemSecurityContext systemSecurityContext; private final SystemSecurityContext systemSecurityContext;
private final AutoAssignExecutor autoAssignExecutor; private final AutoAssignExecutor autoAssignExecutor;
private final LockRegistry lockRegistry; private final LockRegistry lockRegistry;
/** /**
@@ -52,10 +49,8 @@ public class AutoAssignScheduler {
} }
/** /**
* Scheduler method called by the spring-async mechanism. Retrieves all * Scheduler method called by the spring-async mechanism. Retrieves all tenants and runs for each
* tenants and runs for each * tenant the auto assignments defined in the target filter queries {@link SystemSecurityContext}.
* tenant the auto assignments defined in the target filter queries
* {@link SystemSecurityContext}.
*/ */
@Scheduled(initialDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER) @Scheduled(initialDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER)
public void autoAssignScheduler() { public void autoAssignScheduler() {
@@ -87,4 +82,4 @@ public class AutoAssignScheduler {
return null; return null;
} }
} }

View File

@@ -53,15 +53,13 @@ public class AutoActionCleanup implements CleanupTask {
* @param deploymentMgmt The {@link DeploymentManagement} to operate on. * @param deploymentMgmt The {@link DeploymentManagement} to operate on.
* @param configMgmt The {@link TenantConfigurationManagement} service. * @param configMgmt The {@link TenantConfigurationManagement} service.
*/ */
public AutoActionCleanup(final DeploymentManagement deploymentMgmt, public AutoActionCleanup(final DeploymentManagement deploymentMgmt, final TenantConfigurationManagement configMgmt) {
final TenantConfigurationManagement configMgmt) {
this.deploymentMgmt = deploymentMgmt; this.deploymentMgmt = deploymentMgmt;
this.config = configMgmt; this.config = configMgmt;
} }
@Override @Override
public void run() { public void run() {
if (!isEnabled()) { if (!isEnabled()) {
log.debug("Action cleanup is disabled for this tenant..."); log.debug("Action cleanup is disabled for this tenant...");
return; return;
@@ -104,5 +102,4 @@ public class AutoActionCleanup implements CleanupTask {
final Class<T> valueType) { final Class<T> valueType) {
return config.getConfigurationValue(key, valueType); return config.getConfigurationValue(key, valueType);
} }
}
}

View File

@@ -34,15 +34,15 @@ public class AutoCleanupScheduler {
private final List<CleanupTask> cleanupTasks; private final List<CleanupTask> cleanupTasks;
/** /**
* Constructs the cleanup schedulers and initializes it with a set of * Constructs the cleanup schedulers and initializes it with a set of cleanup handlers.
* cleanup handlers.
* *
* @param systemManagement Management APIs to invoke actions in a certain tenant context. * @param systemManagement Management APIs to invoke actions in a certain tenant context.
* @param systemSecurityContext The system security context. * @param systemSecurityContext The system security context.
* @param lockRegistry A registry for shared locks. * @param lockRegistry A registry for shared locks.
* @param cleanupTasks A list of cleanup tasks. * @param cleanupTasks A list of cleanup tasks.
*/ */
public AutoCleanupScheduler(final SystemManagement systemManagement, public AutoCleanupScheduler(
final SystemManagement systemManagement,
final SystemSecurityContext systemSecurityContext, final LockRegistry lockRegistry, final SystemSecurityContext systemSecurityContext, final LockRegistry lockRegistry,
final List<CleanupTask> cleanupTasks) { final List<CleanupTask> cleanupTasks) {
this.systemManagement = systemManagement; this.systemManagement = systemManagement;
@@ -88,5 +88,4 @@ public class AutoCleanupScheduler {
private Lock obtainLock(final CleanupTask task, final String tenant) { private Lock obtainLock(final CleanupTask task, final String tenant) {
return lockRegistry.obtain(AUTO_CLEANUP + SEP + task.getId() + SEP + tenant); return lockRegistry.obtain(AUTO_CLEANUP + SEP + task.getId() + SEP + tenant);
} }
}
}

View File

@@ -24,5 +24,4 @@ public interface CleanupTask extends Runnable {
* @return The identifier of this cleanup task. Never null. * @return The identifier of this cleanup task. Never null.
*/ */
String getId(); String getId();
}
}

View File

@@ -22,5 +22,4 @@ public class JpaActionStatusBuilder implements ActionStatusBuilder {
public ActionStatusCreate create(final long actionId) { public ActionStatusCreate create(final long actionId) {
return new JpaActionStatusCreate(actionId); return new JpaActionStatusCreate(actionId);
} }
}
}

View File

@@ -33,4 +33,4 @@ public class JpaActionStatusCreate extends AbstractActionStatusCreate<ActionStat
} }
return result; return result;
} }
} }

View File

@@ -40,5 +40,4 @@ public class JpaDistributionSetBuilder implements DistributionSetBuilder {
public DistributionSetCreate create() { public DistributionSetCreate create() {
return new JpaDistributionSetCreate(distributionSetTypeManagement, softwareModuleManagement); return new JpaDistributionSetCreate(distributionSetTypeManagement, softwareModuleManagement);
} }
}
}

View File

@@ -13,6 +13,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Optional; import java.util.Optional;
import lombok.Getter;
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
import org.eclipse.hawkbit.repository.ValidString; import org.eclipse.hawkbit.repository.ValidString;
@@ -28,11 +29,11 @@ import org.springframework.util.StringUtils;
/** /**
* Create/build implementation. * Create/build implementation.
*/ */
public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreate<DistributionSetCreate> public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreate<DistributionSetCreate> implements DistributionSetCreate {
implements DistributionSetCreate {
private final DistributionSetTypeManagement distributionSetTypeManagement; private final DistributionSetTypeManagement distributionSetTypeManagement;
private final SoftwareModuleManagement softwareModuleManagement; private final SoftwareModuleManagement softwareModuleManagement;
@Getter
@ValidString @ValidString
private String type; private String type;
@@ -56,10 +57,6 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat
Optional.ofNullable(requiredMigrationStep).orElse(Boolean.FALSE)); Optional.ofNullable(requiredMigrationStep).orElse(Boolean.FALSE));
} }
public String getType() {
return type;
}
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) { private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) {
return distributionSetTypeManagement.getByKey(distributionSetTypekey) return distributionSetTypeManagement.getByKey(distributionSetTypekey)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey)); .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey));
@@ -78,5 +75,4 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat
return module; return module;
} }
}
}

View File

@@ -36,5 +36,4 @@ public class JpaDistributionSetTypeBuilder implements DistributionSetTypeBuilder
public DistributionSetTypeCreate create() { public DistributionSetTypeCreate create() {
return new JpaDistributionSetTypeCreate(softwareModuleTypeManagement); return new JpaDistributionSetTypeCreate(softwareModuleTypeManagement);
} }
}
}

View File

@@ -55,5 +55,4 @@ public class JpaDistributionSetTypeCreate extends AbstractDistributionSetTypeUpd
return module; return module;
} }
}
}

View File

@@ -36,5 +36,4 @@ public class JpaRolloutBuilder implements RolloutBuilder {
public RolloutCreate create() { public RolloutCreate create() {
return new JpaRolloutCreate(distributionSetManagement); return new JpaRolloutCreate(distributionSetManagement);
} }
}
}

View File

@@ -22,5 +22,4 @@ public class JpaRolloutGroupBuilder implements RolloutGroupBuilder {
public RolloutGroupCreate create() { public RolloutGroupCreate create() {
return new JpaRolloutGroupCreate(); return new JpaRolloutGroupCreate();
} }
}
}

View File

@@ -15,8 +15,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
public class JpaRolloutGroupCreate extends AbstractRolloutGroupCreate<RolloutGroupCreate> public class JpaRolloutGroupCreate extends AbstractRolloutGroupCreate<RolloutGroupCreate> implements RolloutGroupCreate {
implements RolloutGroupCreate {
/** /**
* Set the Success And Error conditions for the rollout group * Set the Success And Error conditions for the rollout group
@@ -84,5 +83,4 @@ public class JpaRolloutGroupCreate extends AbstractRolloutGroupCreate<RolloutGro
return group; return group;
} }
}
}

View File

@@ -36,5 +36,4 @@ public class JpaSoftwareModuleBuilder implements SoftwareModuleBuilder {
public SoftwareModuleCreate create() { public SoftwareModuleCreate create() {
return new JpaSoftwareModuleCreate(softwareModuleTypeManagement); return new JpaSoftwareModuleCreate(softwareModuleTypeManagement);
} }
}
}

View File

@@ -21,11 +21,9 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
/** /**
* Create/build implementation. * Create/build implementation.
*/ */
public class JpaSoftwareModuleCreate extends AbstractSoftwareModuleUpdateCreate<SoftwareModuleCreate> public class JpaSoftwareModuleCreate extends AbstractSoftwareModuleUpdateCreate<SoftwareModuleCreate> implements SoftwareModuleCreate {
implements SoftwareModuleCreate {
private final SoftwareModuleTypeManagement softwareModuleTypeManagement; private final SoftwareModuleTypeManagement softwareModuleTypeManagement;
private boolean encrypted; private boolean encrypted;
JpaSoftwareModuleCreate(final SoftwareModuleTypeManagement softwareModuleTypeManagement) { JpaSoftwareModuleCreate(final SoftwareModuleTypeManagement softwareModuleTypeManagement) {
@@ -56,4 +54,4 @@ public class JpaSoftwareModuleCreate extends AbstractSoftwareModuleUpdateCreate<
return softwareModuleTypeManagement.getByKey(type.trim()) return softwareModuleTypeManagement.getByKey(type.trim())
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type.trim())); .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type.trim()));
} }
} }

View File

@@ -36,5 +36,4 @@ public class JpaSoftwareModuleMetadataBuilder implements SoftwareModuleMetadataB
public SoftwareModuleMetadataCreate create(final long softwareModuleId) { public SoftwareModuleMetadataCreate create(final long softwareModuleId) {
return new JpaSoftwareModuleMetadataCreate(softwareModuleId, softwareModuleManagement); return new JpaSoftwareModuleMetadataCreate(softwareModuleId, softwareModuleManagement);
} }
}
}

View File

@@ -25,8 +25,7 @@ public class JpaSoftwareModuleMetadataCreate
private final SoftwareModuleManagement softwareModuleManagement; private final SoftwareModuleManagement softwareModuleManagement;
JpaSoftwareModuleMetadataCreate(final long softwareModuleId, JpaSoftwareModuleMetadataCreate(final long softwareModuleId, final SoftwareModuleManagement softwareModuleManagement) {
final SoftwareModuleManagement softwareModuleManagement) {
this.softwareModuleManagement = softwareModuleManagement; this.softwareModuleManagement = softwareModuleManagement;
this.softwareModuleId = softwareModuleId; this.softwareModuleId = softwareModuleId;
} }
@@ -42,5 +41,4 @@ public class JpaSoftwareModuleMetadataCreate
return new JpaSoftwareModuleMetadata(key, module, value, isTargetVisible().orElse(false)); return new JpaSoftwareModuleMetadata(key, module, value, isTargetVisible().orElse(false));
} }
}
}

View File

@@ -29,5 +29,4 @@ public class JpaSoftwareModuleTypeBuilder implements SoftwareModuleTypeBuilder {
public SoftwareModuleTypeCreate create() { public SoftwareModuleTypeCreate create() {
return new JpaSoftwareModuleTypeCreate(); return new JpaSoftwareModuleTypeCreate();
} }
}
}

View File

@@ -9,6 +9,8 @@
*/ */
package org.eclipse.hawkbit.repository.jpa.builder; package org.eclipse.hawkbit.repository.jpa.builder;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.builder.AbstractSoftwareModuleTypeUpdateCreate; import org.eclipse.hawkbit.repository.builder.AbstractSoftwareModuleTypeUpdateCreate;
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate; import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
@@ -16,15 +18,12 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
/** /**
* Create/build implementation. * Create/build implementation.
*/ */
@NoArgsConstructor(access = AccessLevel.PACKAGE)
public class JpaSoftwareModuleTypeCreate extends AbstractSoftwareModuleTypeUpdateCreate<SoftwareModuleTypeCreate> public class JpaSoftwareModuleTypeCreate extends AbstractSoftwareModuleTypeUpdateCreate<SoftwareModuleTypeCreate>
implements SoftwareModuleTypeCreate { implements SoftwareModuleTypeCreate {
JpaSoftwareModuleTypeCreate() {
}
@Override @Override
public JpaSoftwareModuleType build() { public JpaSoftwareModuleType build() {
return new JpaSoftwareModuleType(key, name, description, maxAssignments, colour); return new JpaSoftwareModuleType(key, name, description, maxAssignments, colour);
} }
} }

View File

@@ -29,5 +29,4 @@ public class JpaTagBuilder implements TagBuilder {
public TagCreate create() { public TagCreate create() {
return new JpaTagCreate(); return new JpaTagCreate();
} }
}
}

View File

@@ -9,6 +9,8 @@
*/ */
package org.eclipse.hawkbit.repository.jpa.builder; package org.eclipse.hawkbit.repository.jpa.builder;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.builder.AbstractTagUpdateCreate; import org.eclipse.hawkbit.repository.builder.AbstractTagUpdateCreate;
import org.eclipse.hawkbit.repository.builder.TagCreate; import org.eclipse.hawkbit.repository.builder.TagCreate;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
@@ -19,12 +21,9 @@ import org.eclipse.hawkbit.repository.model.Tag;
/** /**
* Create/build implementation. * Create/build implementation.
*/ */
@NoArgsConstructor(access = AccessLevel.PACKAGE)
public class JpaTagCreate extends AbstractTagUpdateCreate<TagCreate> implements TagCreate { public class JpaTagCreate extends AbstractTagUpdateCreate<TagCreate> implements TagCreate {
JpaTagCreate() {
}
public JpaDistributionSetTag buildDistributionSetTag() { public JpaDistributionSetTag buildDistributionSetTag() {
return new JpaDistributionSetTag(name, description, colour); return new JpaDistributionSetTag(name, description, colour);
} }

View File

@@ -20,7 +20,7 @@ import org.eclipse.hawkbit.repository.model.Target;
*/ */
public class JpaTargetBuilder implements TargetBuilder { public class JpaTargetBuilder implements TargetBuilder {
final private TargetTypeManagement targetTypeManagement; private final TargetTypeManagement targetTypeManagement;
/** /**
* @param targetTypeManagement Target type management * @param targetTypeManagement Target type management
@@ -38,5 +38,4 @@ public class JpaTargetBuilder implements TargetBuilder {
public TargetCreate create() { public TargetCreate create() {
return new JpaTargetCreate(targetTypeManagement); return new JpaTargetCreate(targetTypeManagement);
} }
}
}

View File

@@ -16,7 +16,7 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.model.TargetType; import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.springframework.util.StringUtils; import org.springframework.util.ObjectUtils;
/** /**
* Create/build implementation. * Create/build implementation.
@@ -37,20 +37,19 @@ public class JpaTargetCreate extends AbstractTargetUpdateCreate<TargetCreate> im
@Override @Override
public JpaTarget build() { public JpaTarget build() {
JpaTarget target; final JpaTarget target;
if (ObjectUtils.isEmpty(securityToken)) {
if (StringUtils.isEmpty(securityToken)) {
target = new JpaTarget(controllerId); target = new JpaTarget(controllerId);
} else { } else {
target = new JpaTarget(controllerId, securityToken); target = new JpaTarget(controllerId, securityToken);
} }
if (!StringUtils.isEmpty(name)) { if (!ObjectUtils.isEmpty(name)) {
target.setName(name); target.setName(name);
} }
if (targetTypeId != null) { if (targetTypeId != null) {
TargetType targetType = targetTypeManagement.get(targetTypeId) final TargetType targetType = targetTypeManagement.get(targetTypeId)
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId)); .orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId));
target.setTargetType(targetType); target.setTargetType(targetType);
} }
@@ -62,5 +61,4 @@ public class JpaTargetCreate extends AbstractTargetUpdateCreate<TargetCreate> im
return target; return target;
} }
}
}

View File

@@ -42,5 +42,4 @@ public class JpaTargetFilterQueryBuilder implements TargetFilterQueryBuilder {
public TargetFilterQueryCreate create() { public TargetFilterQueryCreate create() {
return new JpaTargetFilterQueryCreate(distributionSetManagement); return new JpaTargetFilterQueryCreate(distributionSetManagement);
} }
}
}

View File

@@ -44,5 +44,4 @@ public class JpaTargetFilterQueryCreate extends AbstractTargetFilterQueryUpdateC
return true; return true;
} }
}
}

View File

@@ -41,4 +41,4 @@ public class JpaTargetTypeBuilder implements TargetTypeBuilder {
public TargetTypeCreate create() { public TargetTypeCreate create() {
return new JpaTargetTypeCreate(distributionSetTypeManagement); return new JpaTargetTypeCreate(distributionSetTypeManagement);
} }
} }

View File

@@ -25,8 +25,7 @@ import org.springframework.util.CollectionUtils;
/** /**
* Create/build implementation. * Create/build implementation.
*/ */
public class JpaTargetTypeCreate extends AbstractTargetTypeUpdateCreate<TargetTypeCreate> public class JpaTargetTypeCreate extends AbstractTargetTypeUpdateCreate<TargetTypeCreate> implements TargetTypeCreate {
implements TargetTypeCreate {
private final DistributionSetTypeManagement distributionSetTypeManagement; private final DistributionSetTypeManagement distributionSetTypeManagement;

View File

@@ -17,5 +17,4 @@ public class JpaTargetUpdate extends AbstractTargetUpdateCreate<TargetUpdate> im
JpaTargetUpdate(final String controllerId) { JpaTargetUpdate(final String controllerId) {
super(controllerId); super(controllerId);
} }
}
}

View File

@@ -36,4 +36,4 @@ public final class Constants {
* @see Backoff#delay() * @see Backoff#delay()
*/ */
public static final long TX_RT_DELAY = 100; public static final long TX_RT_DELAY = 100;
} }

View File

@@ -51,4 +51,4 @@ public class MultiTenantJpaTransactionManager extends JpaTransactionManager {
em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase()); em.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, currentTenant.toUpperCase());
} }
} }
} }

View File

@@ -21,8 +21,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
* successful spring transaction commit.The class is thread safe. * successful spring transaction commit.The class is thread safe.
*/ */
@Slf4j @Slf4j
public class AfterTransactionCommitDefaultServiceExecutor extends TransactionSynchronizationAdapter public class AfterTransactionCommitDefaultServiceExecutor extends TransactionSynchronizationAdapter implements AfterTransactionCommitExecutor {
implements AfterTransactionCommitExecutor {
private static final ThreadLocal<List<Runnable>> THREAD_LOCAL_RUNNABLES = new ThreadLocal<>(); private static final ThreadLocal<List<Runnable>> THREAD_LOCAL_RUNNABLES = new ThreadLocal<>();
@@ -69,5 +68,4 @@ public class AfterTransactionCommitDefaultServiceExecutor extends TransactionSyn
runnable.run(); runnable.run();
} }
}
}

View File

@@ -23,4 +23,4 @@ public interface AfterTransactionCommitExecutor {
* @param runnable the after commit runnable * @param runnable the after commit runnable
*/ */
void afterCommit(Runnable runnable); void afterCommit(Runnable runnable);
} }

View File

@@ -67,7 +67,8 @@ public abstract class AbstractDsAssignmentStrategy {
private final BooleanSupplier confirmationFlowConfig; private final BooleanSupplier confirmationFlowConfig;
private final RepositoryProperties repositoryProperties; private final RepositoryProperties repositoryProperties;
AbstractDsAssignmentStrategy(final TargetRepository targetRepository, AbstractDsAssignmentStrategy(
final TargetRepository targetRepository,
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder, final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository, final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
final QuotaManagement quotaManagement, final BooleanSupplier multiAssignmentsConfig, final QuotaManagement quotaManagement, final BooleanSupplier multiAssignmentsConfig,
@@ -83,7 +84,8 @@ public abstract class AbstractDsAssignmentStrategy {
this.repositoryProperties = repositoryProperties; this.repositoryProperties = repositoryProperties;
} }
public JpaAction createTargetAction(final String initiatedBy, final TargetWithActionType targetWithActionType, public JpaAction createTargetAction(
final String initiatedBy, final TargetWithActionType targetWithActionType,
final List<JpaTarget> targets, final JpaDistributionSet set) { final List<JpaTarget> targets, final JpaDistributionSet set) {
final Optional<JpaTarget> optTarget = targets.stream() final Optional<JpaTarget> optTarget = targets.stream()
.filter(t -> t.getControllerId().equals(targetWithActionType.getControllerId())).findFirst(); .filter(t -> t.getControllerId().equals(targetWithActionType.getControllerId())).findFirst();
@@ -95,8 +97,9 @@ public abstract class AbstractDsAssignmentStrategy {
actionForTarget.setActionType(targetWithActionType.getActionType()); actionForTarget.setActionType(targetWithActionType.getActionType());
actionForTarget.setForcedTime(targetWithActionType.getForceTime()); actionForTarget.setForcedTime(targetWithActionType.getForceTime());
actionForTarget.setWeight( actionForTarget.setWeight(
targetWithActionType.getWeight() == null ? targetWithActionType.getWeight() == null
repositoryProperties.getActionWeightIfAbsent() : targetWithActionType.getWeight()); ? repositoryProperties.getActionWeightIfAbsent()
: targetWithActionType.getWeight());
actionForTarget.setActive(true); actionForTarget.setActive(true);
actionForTarget.setTarget(target); actionForTarget.setTarget(target);
actionForTarget.setDistributionSet(set); actionForTarget.setDistributionSet(set);
@@ -294,7 +297,6 @@ public abstract class AbstractDsAssignmentStrategy {
private void assertActionsPerTargetQuota(final Target target, final int requested) { private void assertActionsPerTargetQuota(final Target target, final int requested) {
final int quota = quotaManagement.getMaxActionsPerTarget(); final int quota = quotaManagement.getMaxActionsPerTarget();
QuotaHelper.assertAssignmentQuota(target.getId(), requested, quota, Action.class, Target.class, QuotaHelper.assertAssignmentQuota(target.getId(), requested, quota, Action.class, Target.class, actionRepository::countByTargetId);
actionRepository::countByTargetId);
} }
} }

View File

@@ -47,7 +47,8 @@ public class JpaActionManagement {
protected final QuotaManagement quotaManagement; protected final QuotaManagement quotaManagement;
protected final RepositoryProperties repositoryProperties; protected final RepositoryProperties repositoryProperties;
public JpaActionManagement(final ActionRepository actionRepository, public JpaActionManagement(
final ActionRepository actionRepository,
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement, final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement,
final RepositoryProperties repositoryProperties) { final RepositoryProperties repositoryProperties) {
this.actionRepository = actionRepository; this.actionRepository = actionRepository;
@@ -172,4 +173,4 @@ public class JpaActionManagement {
action.setLastActionStatusCode(actionStatus.getCode().orElse(null)); action.setLastActionStatusCode(actionStatus.getCode().orElse(null));
return actionRepository.save(action); return actionRepository.save(action);
} }
} }

View File

@@ -70,19 +70,15 @@ import org.springframework.validation.annotation.Validated;
public class JpaArtifactManagement implements ArtifactManagement { public class JpaArtifactManagement implements ArtifactManagement {
private final EntityManager entityManager; private final EntityManager entityManager;
private final LocalArtifactRepository localArtifactRepository; private final LocalArtifactRepository localArtifactRepository;
private final SoftwareModuleRepository softwareModuleRepository; private final SoftwareModuleRepository softwareModuleRepository;
@Nullable @Nullable
private final ArtifactRepository artifactRepository; private final ArtifactRepository artifactRepository;
private final TenantAware tenantAware; private final TenantAware tenantAware;
private final QuotaManagement quotaManagement; private final QuotaManagement quotaManagement;
public JpaArtifactManagement(final EntityManager entityManager, public JpaArtifactManagement(
final EntityManager entityManager,
final LocalArtifactRepository localArtifactRepository, final LocalArtifactRepository localArtifactRepository,
final SoftwareModuleRepository softwareModuleRepository, @Nullable final ArtifactRepository artifactRepository, final SoftwareModuleRepository softwareModuleRepository, @Nullable final ArtifactRepository artifactRepository,
final QuotaManagement quotaManagement, final TenantAware tenantAware) { final QuotaManagement quotaManagement, final TenantAware tenantAware) {
@@ -101,8 +97,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Artifact create(final ArtifactUpload artifactUpload) { public Artifact create(final ArtifactUpload artifactUpload) {
assertArtifactRepositoryAvailable(); assertArtifactRepositoryAvailable();
@@ -138,8 +134,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long id) { public void delete(final long id) {
final JpaArtifact toDelete = (JpaArtifact) get(id) final JpaArtifact toDelete = (JpaArtifact) get(id)
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, id)); .orElseThrow(() -> new EntityNotFoundException(Artifact.class, id));

View File

@@ -61,10 +61,8 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
private final EntityFactory entityFactory; private final EntityFactory entityFactory;
private final TargetRepository targetRepository; private final TargetRepository targetRepository;
/** public JpaConfirmationManagement(
* Constructor final TargetRepository targetRepository,
*/
public JpaConfirmationManagement(final TargetRepository targetRepository,
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository, final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
final RepositoryProperties repositoryProperties, final QuotaManagement quotaManagement, final RepositoryProperties repositoryProperties, final QuotaManagement quotaManagement,
final EntityFactory entityFactory) { final EntityFactory entityFactory) {
@@ -80,14 +78,12 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
@Override @Override
@Transactional @Transactional
public AutoConfirmationStatus activateAutoConfirmation(final String controllerId, final String initiator, public AutoConfirmationStatus activateAutoConfirmation(final String controllerId, final String initiator, final String remark) {
final String remark) { log.trace(
log.trace("'activateAutoConfirmation' was called with values: controllerId={}; initiator={}; remark={}", "'activateAutoConfirmation' was called with values: controllerId={}; initiator={}; remark={}", controllerId, initiator, remark);
controllerId, initiator, remark);
final JpaTarget target = getTargetByControllerIdAndThrowIfNotFound(controllerId); final JpaTarget target = getTargetByControllerIdAndThrowIfNotFound(controllerId);
if (target.getAutoConfirmationStatus() != null) { if (target.getAutoConfirmationStatus() != null) {
log.debug("'activateAutoConfirmation' was called for an controller id {} with active auto confirmation.", log.debug("'activateAutoConfirmation' was called for an controller id {} with active auto confirmation.", controllerId);
controllerId);
throw new AutoConfirmationAlreadyActiveException(controllerId); throw new AutoConfirmationAlreadyActiveException(controllerId);
} }
final JpaAutoConfirmationStatus confirmationStatus = new JpaAutoConfirmationStatus(initiator, remark, target); final JpaAutoConfirmationStatus confirmationStatus = new JpaAutoConfirmationStatus(initiator, remark, target);
@@ -95,8 +91,9 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
final JpaTarget updatedTarget = targetRepository.save(target); final JpaTarget updatedTarget = targetRepository.save(target);
final AutoConfirmationStatus autoConfStatus = updatedTarget.getAutoConfirmationStatus(); final AutoConfirmationStatus autoConfStatus = updatedTarget.getAutoConfirmationStatus();
if (autoConfStatus == null) { if (autoConfStatus == null) {
final String message = String.format("Persisted auto confirmation status is null. " final String message = String.format(
+ "Cannot proceed with giving confirmations for active actions for device %s with initiator %s.", "Persisted auto confirmation status is null. " +
"Cannot proceed with giving confirmations for active actions for device %s with initiator %s.",
controllerId, initiator); controllerId, initiator);
log.error("message"); log.error("message");
throw new IllegalStateException(message); throw new IllegalStateException(message);
@@ -123,8 +120,8 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action confirmAction(final long actionId, final Integer code, final Collection<String> deviceMessages) { public Action confirmAction(final long actionId, final Integer code, final Collection<String> deviceMessages) {
log.trace("Action with id {} confirm request is triggered.", actionId); log.trace("Action with id {} confirm request is triggered.", actionId);
final Action action = getActionAndThrowExceptionIfNotFound(actionId); final Action action = getActionAndThrowExceptionIfNotFound(actionId);
@@ -142,8 +139,8 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action denyAction(final long actionId, final Integer code, final Collection<String> deviceMessages) { public Action denyAction(final long actionId, final Integer code, final Collection<String> deviceMessages) {
log.trace("Action with id {} deny request is triggered.", actionId); log.trace("Action with id {} deny request is triggered.", actionId);
final Action action = getActionAndThrowExceptionIfNotFound(actionId); final Action action = getActionAndThrowExceptionIfNotFound(actionId);
@@ -152,8 +149,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
if (deviceMessages != null) { if (deviceMessages != null) {
messages.addAll(deviceMessages); messages.addAll(deviceMessages);
} }
messages.add(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target rejected action." messages.add(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target rejected action. Action will stay in confirmation pending state.");
+ " Action will stay in confirmation pending state.");
final ActionStatusCreate statusCreate = createConfirmationActionStatus(action.getId(), code, messages) final ActionStatusCreate statusCreate = createConfirmationActionStatus(action.getId(), code, messages)
.status(Status.WAIT_FOR_CONFIRMATION); .status(Status.WAIT_FOR_CONFIRMATION);
return addActionStatus((JpaActionStatusCreate) statusCreate); return addActionStatus((JpaActionStatusCreate) statusCreate);
@@ -191,8 +187,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
} }
} }
private ActionStatusCreate createConfirmationActionStatus(final long actionId, final Integer code, private ActionStatusCreate createConfirmationActionStatus(final long actionId, final Integer code, final Collection<String> messages) {
final Collection<String> messages) {
final ActionStatusCreate statusCreate = entityFactory.actionStatus().create(actionId); final ActionStatusCreate statusCreate = entityFactory.actionStatus().create(actionId);
if (!CollectionUtils.isEmpty(messages)) { if (!CollectionUtils.isEmpty(messages)) {
statusCreate.messages(messages); statusCreate.messages(messages);
@@ -207,25 +202,27 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
private List<Action> giveConfirmationForActiveActions(final AutoConfirmationStatus autoConfirmationStatus) { private List<Action> giveConfirmationForActiveActions(final AutoConfirmationStatus autoConfirmationStatus) {
final Target target = autoConfirmationStatus.getTarget(); final Target target = autoConfirmationStatus.getTarget();
return findActiveActionsHavingStatus(target.getControllerId(), Status.WAIT_FOR_CONFIRMATION).stream() return findActiveActionsHavingStatus(target.getControllerId(), Status.WAIT_FOR_CONFIRMATION).stream()
.map(action -> autoConfirmAction(action, autoConfirmationStatus)).collect(Collectors.toList()); .map(action -> autoConfirmAction(action, autoConfirmationStatus))
.collect(Collectors.toList());
} }
private Action autoConfirmAction(final JpaAction action, final AutoConfirmationStatus autoConfirmationStatus) { private Action autoConfirmAction(final JpaAction action, final AutoConfirmationStatus autoConfirmationStatus) {
if (!action.isWaitingConfirmation()) { if (!action.isWaitingConfirmation()) {
log.debug("Auto-confirming action is not necessary, since action {} is in RUNNING state already.", log.debug("Auto-confirming action is not necessary, since action {} is in RUNNING state already.", action.getId());
action.getId());
return action; return action;
} }
final JpaActionStatus actionStatus = (JpaActionStatus) entityFactory.actionStatus().create(action.getId()) final JpaActionStatus actionStatus = (JpaActionStatus) entityFactory.actionStatus()
.create(action.getId())
.status(Status.RUNNING) .status(Status.RUNNING)
.messages(Collections.singletonList(autoConfirmationStatus.constructActionMessage())).build(); .messages(Collections.singletonList(autoConfirmationStatus.constructActionMessage()))
.build();
log.debug( log.debug(
"Automatically confirm actionId '{}' due to active auto-confirmation initiated by '{}' and rollouts system user '{}'", "Automatically confirm actionId '{}' due to active auto-confirmation initiated by '{}' and rollouts system user '{}'",
action.getId(), autoConfirmationStatus.getInitiator(), autoConfirmationStatus.getCreatedBy()); action.getId(), autoConfirmationStatus.getInitiator(), autoConfirmationStatus.getCreatedBy());
// do not make use of // do not make use of
// org.eclipse.hawkbit.repository.jpa.management.JpaActionManagement.handleAddUpdateActionStatus // org.eclipse.hawkbit.repository.jpa.management.JpaActionManagement.handleAddUpdateActionStatus
// to bypass the quota check. Otherwise the action will not be confirmed in case // to bypass the quota check. Otherwise, the action will not be confirmed in case
// of exceeded action status quota. // of exceeded action status quota.
action.setStatus(Status.RUNNING); action.setStatus(Status.RUNNING);
actionStatus.setAction(action); actionStatus.setAction(action);
@@ -238,4 +235,4 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
return targetRepository.findOne(TargetSpecifications.hasControllerId(controllerId)) return targetRepository.findOne(TargetSpecifications.hasControllerId(controllerId))
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId)); .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
} }
} }

View File

@@ -127,46 +127,32 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Autowired @Autowired
private EntityManager entityManager; private EntityManager entityManager;
@Autowired @Autowired
private TargetRepository targetRepository; private TargetRepository targetRepository;
@Autowired @Autowired
private SoftwareModuleRepository softwareModuleRepository; private SoftwareModuleRepository softwareModuleRepository;
@Autowired @Autowired
private TenantConfigurationManagement tenantConfigurationManagement; private TenantConfigurationManagement tenantConfigurationManagement;
@Autowired @Autowired
private SystemSecurityContext systemSecurityContext; private SystemSecurityContext systemSecurityContext;
@Autowired @Autowired
private EntityFactory entityFactory; private EntityFactory entityFactory;
@Autowired @Autowired
private EventPublisherHolder eventPublisherHolder; private EventPublisherHolder eventPublisherHolder;
@Autowired @Autowired
private AfterTransactionCommitExecutor afterCommit; private AfterTransactionCommitExecutor afterCommit;
@Autowired @Autowired
private SoftwareModuleMetadataRepository softwareModuleMetadataRepository; private SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
@Autowired @Autowired
private PlatformTransactionManager txManager; private PlatformTransactionManager txManager;
@Autowired @Autowired
private TenantAware tenantAware; private TenantAware tenantAware;
@Autowired @Autowired
private ConfirmationManagement confirmationManagement; private ConfirmationManagement confirmationManagement;
@Autowired @Autowired
private TargetTypeManagement targetTypeManagement; private TargetTypeManagement targetTypeManagement;
@Autowired @Autowired
private DeploymentManagement deploymentManagement; private DeploymentManagement deploymentManagement;
@Autowired @Autowired
private DistributionSetManagement distributionSetManagement; private DistributionSetManagement distributionSetManagement;
@@ -179,7 +165,6 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
executorService.scheduleWithFixedDelay(this::flushUpdateQueue, executorService.scheduleWithFixedDelay(this::flushUpdateQueue,
repositoryProperties.getPollPersistenceFlushTime(), repositoryProperties.getPollPersistenceFlushTime(),
repositoryProperties.getPollPersistenceFlushTime(), TimeUnit.MILLISECONDS); repositoryProperties.getPollPersistenceFlushTime(), TimeUnit.MILLISECONDS);
queue = new LinkedBlockingDeque<>(repositoryProperties.getPollPersistenceQueueSize()); queue = new LinkedBlockingDeque<>(repositoryProperties.getPollPersistenceQueueSize());
} else { } else {
queue = null; queue = null;
@@ -194,26 +179,30 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Override @Override
protected void onActionStatusUpdate(final Action.Status updatedActionStatus, final JpaAction action) { protected void onActionStatusUpdate(final Action.Status updatedActionStatus, final JpaAction action) {
switch (updatedActionStatus) { switch (updatedActionStatus) {
case ERROR: case ERROR: {
final JpaTarget target = (JpaTarget) action.getTarget(); final JpaTarget target = (JpaTarget) action.getTarget();
target.setUpdateStatus(TargetUpdateStatus.ERROR); target.setUpdateStatus(TargetUpdateStatus.ERROR);
handleErrorOnAction(action, target); handleErrorOnAction(action, target);
break; break;
case FINISHED: }
case FINISHED: {
handleFinishedAndStoreInTargetStatus(action).ifPresent(this::requestControllerAttributes); handleFinishedAndStoreInTargetStatus(action).ifPresent(this::requestControllerAttributes);
break; break;
case DOWNLOADED: }
case DOWNLOADED: {
handleDownloadedActionStatus(action).ifPresent(this::requestControllerAttributes); handleDownloadedActionStatus(action).ifPresent(this::requestControllerAttributes);
break; break;
default: }
default: {
break; break;
}
} }
} }
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action addCancelActionStatus(final ActionStatusCreate c) { public Action addCancelActionStatus(final ActionStatusCreate c) {
final JpaActionStatusCreate create = (JpaActionStatusCreate) c; final JpaActionStatusCreate create = (JpaActionStatusCreate) c;
@@ -227,19 +216,22 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
switch (actionStatus.getStatus()) { switch (actionStatus.getStatus()) {
case CANCELED: case CANCELED:
case FINISHED: case FINISHED: {
handleFinishedCancelation(actionStatus, action); handleFinishedCancelation(actionStatus, action);
break; break;
}
case ERROR: case ERROR:
case CANCEL_REJECTED: case CANCEL_REJECTED: {
// Cancellation rejected. Back to running. // Cancellation rejected. Back to running.
action.setStatus(Status.RUNNING); action.setStatus(Status.RUNNING);
break; break;
default: }
default: {
// information status entry - check for a potential DOS attack // information status entry - check for a potential DOS attack
assertActionStatusQuota(actionStatus, action); assertActionStatusQuota(actionStatus, action);
assertActionStatusMessageQuota(actionStatus); assertActionStatusMessageQuota(actionStatus);
break; break;
}
} }
actionStatus.setAction(actionRepository.save(action)); actionStatus.setAction(actionRepository.save(action));
@@ -250,24 +242,22 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Override @Override
public Optional<SoftwareModule> getSoftwareModule(final long id) { public Optional<SoftwareModule> getSoftwareModule(final long id) {
return softwareModuleRepository.findById(id).map(s -> (SoftwareModule) s); return softwareModuleRepository.findById(id).map(SoftwareModule.class::cast);
} }
@Override @Override
public Map<Long, List<SoftwareModuleMetadata>> findTargetVisibleMetaDataBySoftwareModuleId( public Map<Long, List<SoftwareModuleMetadata>> findTargetVisibleMetaDataBySoftwareModuleId(final Collection<Long> moduleId) {
final Collection<Long> moduleId) {
return softwareModuleMetadataRepository return softwareModuleMetadataRepository
.findBySoftwareModuleIdInAndTargetVisible(PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT), .findBySoftwareModuleIdInAndTargetVisible(
moduleId, true) PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT), moduleId, true)
.getContent().stream().collect(Collectors.groupingBy(o -> (Long) o[0], .getContent().stream()
Collectors.mapping(o -> (SoftwareModuleMetadata) o[1], Collectors.toList()))); .collect(Collectors.groupingBy(o -> (Long) o[0], Collectors.mapping(o -> (SoftwareModuleMetadata) o[1], Collectors.toList())));
} }
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public ActionStatus addInformationalActionStatus(final ActionStatusCreate c) { public ActionStatus addInformationalActionStatus(final ActionStatusCreate c) {
final JpaActionStatusCreate create = (JpaActionStatusCreate) c; final JpaActionStatusCreate create = (JpaActionStatusCreate) c;
final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId()); final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId());
@@ -282,8 +272,8 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action addUpdateActionStatus(final ActionStatusCreate statusCreate) { public Action addUpdateActionStatus(final ActionStatusCreate statusCreate) {
return addActionStatus((JpaActionStatusCreate) statusCreate); return addActionStatus((JpaActionStatusCreate) statusCreate);
} }
@@ -314,14 +304,14 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = ConcurrencyFailureException.class, exclude = EntityAlreadyExistsException.class, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) @Retryable(retryFor = ConcurrencyFailureException.class, exclude = EntityAlreadyExistsException.class, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target findOrRegisterTargetIfItDoesNotExist(final String controllerId, final URI address) { public Target findOrRegisterTargetIfItDoesNotExist(final String controllerId, final URI address) {
return findOrRegisterTargetIfItDoesNotExist(controllerId, address, null, null); return findOrRegisterTargetIfItDoesNotExist(controllerId, address, null, null);
} }
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = ConcurrencyFailureException.class, exclude = EntityAlreadyExistsException.class, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) @Retryable(retryFor = ConcurrencyFailureException.class, exclude = EntityAlreadyExistsException.class, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target findOrRegisterTargetIfItDoesNotExist(final String controllerId, final URI address, public Target findOrRegisterTargetIfItDoesNotExist(final String controllerId, final URI address,
final String name, final String type) { final String name, final String type) {
final Specification<JpaTarget> spec = final Specification<JpaTarget> spec =
@@ -332,8 +322,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
} }
@Override @Override
public Optional<Action> getActionForDownloadByTargetAndSoftwareModule(final String controllerId, public Optional<Action> getActionForDownloadByTargetAndSoftwareModule(final String controllerId, final long moduleId) {
final long moduleId) {
throwExceptionIfTargetDoesNotExist(controllerId); throwExceptionIfTargetDoesNotExist(controllerId);
throwExceptionIfSoftwareModuleDoesNotExist(moduleId); throwExceptionIfSoftwareModuleDoesNotExist(moduleId);
@@ -409,16 +398,16 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action registerRetrieved(final long actionId, final String message) { public Action registerRetrieved(final long actionId, final String message) {
return handleRegisterRetrieved(actionId, message); return handleRegisterRetrieved(actionId, message);
} }
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target updateControllerAttributes(final String controllerId, final Map<String, String> data, public Target updateControllerAttributes(final String controllerId, final Map<String, String> data,
final UpdateMode mode) { final UpdateMode mode) {

View File

@@ -122,11 +122,10 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
* Maximum amount of Actions that are started at once. * Maximum amount of Actions that are started at once.
*/ */
private static final int ACTION_PAGE_LIMIT = 1000; private static final int ACTION_PAGE_LIMIT = 1000;
private static final String QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED_DEFAULT =
private static final String QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED_DEFAULT = "DELETE FROM sp_action WHERE tenant=#tenant AND status IN (%s) AND last_modified_at<#last_modified_at LIMIT " "DELETE FROM sp_action WHERE tenant=#tenant AND status IN (%s) AND last_modified_at<#last_modified_at LIMIT " + ACTION_PAGE_LIMIT;
+ ACTION_PAGE_LIMIT;
private static final EnumMap<Database, String> QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED; private static final EnumMap<Database, String> QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED;
private final EntityManager entityManager; private final EntityManager entityManager;
private final DistributionSetManagement distributionSetManagement; private final DistributionSetManagement distributionSetManagement;
private final TargetRepository targetRepository; private final TargetRepository targetRepository;
@@ -144,14 +143,18 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
static { static {
QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED = new EnumMap<>(Database.class); QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED = new EnumMap<>(Database.class);
QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED.put(Database.SQL_SERVER, "DELETE TOP (" + ACTION_PAGE_LIMIT QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED.put(
+ ") FROM sp_action WHERE tenant=#tenant AND status IN (%s) AND last_modified_at<#last_modified_at "); Database.SQL_SERVER,
QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED.put(Database.POSTGRESQL, "DELETE TOP (" + ACTION_PAGE_LIMIT + ") FROM sp_action " +
"DELETE FROM sp_action WHERE id IN (SELECT id FROM sp_action WHERE tenant=#tenant AND status IN (%s) AND last_modified_at<#last_modified_at LIMIT " "WHERE tenant=#tenant AND status IN (%s) AND last_modified_at<#last_modified_at ");
+ ACTION_PAGE_LIMIT + ")"); QUERY_DELETE_ACTIONS_BY_STATE_AND_LAST_MODIFIED.put(
Database.POSTGRESQL,
"DELETE FROM sp_action " +
"WHERE id IN (SELECT id FROM sp_action WHERE tenant=#tenant AND status IN (%s) AND last_modified_at<#last_modified_at LIMIT " + ACTION_PAGE_LIMIT + ")");
} }
public JpaDeploymentManagement(final EntityManager entityManager, final ActionRepository actionRepository, public JpaDeploymentManagement(
final EntityManager entityManager, final ActionRepository actionRepository,
final DistributionSetManagement distributionSetManagement, final TargetRepository targetRepository, final DistributionSetManagement distributionSetManagement, final TargetRepository targetRepository,
final ActionStatusRepository actionStatusRepository, final AuditorAware<String> auditorProvider, final ActionStatusRepository actionStatusRepository, final AuditorAware<String> auditorProvider,
final EventPublisherHolder eventPublisherHolder, final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder, final AfterTransactionCommitExecutor afterCommit,
@@ -182,17 +185,15 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
public List<DistributionSetAssignmentResult> assignDistributionSets( public List<DistributionSetAssignmentResult> assignDistributionSets(final List<DeploymentRequest> deploymentRequests) {
final List<DeploymentRequest> deploymentRequests) {
return assignDistributionSets(tenantAware.getCurrentUsername(), deploymentRequests, null); return assignDistributionSets(tenantAware.getCurrentUsername(), deploymentRequests, null);
} }
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
public List<DistributionSetAssignmentResult> assignDistributionSets(final String initiatedBy, public List<DistributionSetAssignmentResult> assignDistributionSets(
final List<DeploymentRequest> deploymentRequests, final String actionMessage) { final String initiatedBy, final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
WeightValidationHelper.usingContext(systemSecurityContext, tenantConfigurationManagement) WeightValidationHelper.usingContext(systemSecurityContext, tenantConfigurationManagement).validate(deploymentRequests);
.validate(deploymentRequests);
return assignDistributionSets(initiatedBy, deploymentRequests, actionMessage, onlineDsAssignmentStrategy); return assignDistributionSets(initiatedBy, deploymentRequests, actionMessage, onlineDsAssignmentStrategy);
} }
@@ -213,15 +214,14 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
public List<DistributionSetAssignmentResult> offlineAssignedDistributionSets( public List<DistributionSetAssignmentResult> offlineAssignedDistributionSets(final Collection<Entry<String, Long>> assignments) {
final Collection<Entry<String, Long>> assignments) {
return offlineAssignedDistributionSets(assignments, tenantAware.getCurrentUsername()); return offlineAssignedDistributionSets(assignments, tenantAware.getCurrentUsername());
} }
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action cancelAction(final long actionId) { public Action cancelAction(final long actionId) {
log.debug("cancelAction({})", actionId); log.debug("cancelAction({})", actionId);
@@ -381,15 +381,14 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action forceQuitAction(final long actionId) { public Action forceQuitAction(final long actionId) {
final JpaAction action = actionRepository.findById(actionId) final JpaAction action = actionRepository.findById(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId)); .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
if (!action.isCancelingOrCanceled()) { if (!action.isCancelingOrCanceled()) {
throw new ForceQuitActionNotAllowedException( throw new ForceQuitActionNotAllowedException(action.getId() + " is not canceled yet and cannot be force quit");
action.getId() + " is not canceled yet and cannot be force quit");
} }
if (!action.isActive()) { if (!action.isActive()) {
@@ -411,8 +410,8 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action forceTargetAction(final long actionId) { public Action forceTargetAction(final long actionId) {
final JpaAction action = actionRepository.findById(actionId).map(this::assertTargetUpdateAllowed) final JpaAction action = actionRepository.findById(actionId).map(this::assertTargetUpdateAllowed)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId)); .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
@@ -426,13 +425,12 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
@Override @Override
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void cancelInactiveScheduledActionsForTargets(final List<Long> targetIds) { public void cancelInactiveScheduledActionsForTargets(final List<Long> targetIds) {
if (!isMultiAssignmentsEnabled()) { if (!isMultiAssignmentsEnabled()) {
targetRepository.getAccessController().ifPresent(v -> { targetRepository.getAccessController().ifPresent(v -> {
if (targetRepository.count(AccessController.Operation.UPDATE, if (targetRepository.count(AccessController.Operation.UPDATE, TargetSpecifications.hasIdIn(targetIds)) != targetIds.size()) {
TargetSpecifications.hasIdIn(targetIds)) != targetIds.size()) {
throw new EntityNotFoundException(Target.class, targetIds); throw new EntityNotFoundException(Target.class, targetIds);
} }
}); });
@@ -443,8 +441,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
} }
@Override @Override
public void startScheduledActionsByRolloutGroupParent(final long rolloutId, final long distributionSetId, public void startScheduledActionsByRolloutGroupParent(final long rolloutId, final long distributionSetId, final Long rolloutGroupParentId) {
final Long rolloutGroupParentId) {
while (DeploymentHelper.runInNewTransaction( while (DeploymentHelper.runInNewTransaction(
txManager, txManager,
"startScheduledActions-" + rolloutId, "startScheduledActions-" + rolloutId,
@@ -540,10 +537,8 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
@Override @Override
@Transactional @Transactional
public void cancelActionsForDistributionSet(final CancelationType cancelationType, public void cancelActionsForDistributionSet(final CancelationType cancelationType, final DistributionSet distributionSet) {
final DistributionSet distributionSet) { actionRepository.findAll(ActionSpecifications.byDistributionSetIdAndActiveAndStatusIsNot(distributionSet.getId(), Status.CANCELING))
actionRepository.findAll(ActionSpecifications
.byDistributionSetIdAndActiveAndStatusIsNot(distributionSet.getId(), Status.CANCELING))
.forEach(action -> { .forEach(action -> {
try { try {
assertTargetUpdateAllowed(action); assertTargetUpdateAllowed(action);
@@ -580,24 +575,24 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
return getConfigValue(REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED, Boolean.class); return getConfigValue(REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED, Boolean.class);
} }
private static Map<Long, List<TargetWithActionType>> convertRequest( private static Map<Long, List<TargetWithActionType>> convertRequest(final Collection<DeploymentRequest> deploymentRequests) {
final Collection<DeploymentRequest> deploymentRequests) { return deploymentRequests.stream().collect(
return deploymentRequests.stream().collect(Collectors.groupingBy(DeploymentRequest::getDistributionSetId, Collectors.groupingBy(DeploymentRequest::getDistributionSetId,
Collectors.mapping(DeploymentRequest::getTargetWithActionType, Collectors.toList()))); Collectors.mapping(DeploymentRequest::getTargetWithActionType, Collectors.toList())));
} }
/** /**
* split tIDs length into max entries in-statement because many database have * split tIDs length into max entries in-statement because many database have
* constraint of max entries in in-statements e.g. Oracle with maximum 1000 * a constraint of max entries in in-statements e.g. Oracle with maximum 1000
* elements, so we need to split the entries here and execute multiple * elements, so we need to split the entries here and execute multiple
* statements * statements
*/ */
private static List<List<Long>> getTargetEntitiesAsChunks(final List<JpaTarget> targetEntities) { private static List<List<Long>> getTargetEntitiesAsChunks(final List<JpaTarget> targetEntities) {
return ListUtils.partition(targetEntities.stream().map(Target::getId).collect(Collectors.toList()), return ListUtils.partition(targetEntities.stream().map(Target::getId).collect(Collectors.toList()), Constants.MAX_ENTRIES_IN_STATEMENT);
Constants.MAX_ENTRIES_IN_STATEMENT);
} }
private static DistributionSetAssignmentResult buildAssignmentResult(final JpaDistributionSet distributionSet, private static DistributionSetAssignmentResult buildAssignmentResult(
final JpaDistributionSet distributionSet,
final List<JpaAction> assignedActions, final int totalTargetsForAssignment) { final List<JpaAction> assignedActions, final int totalTargetsForAssignment) {
final int alreadyAssignedTargetsCount = totalTargetsForAssignment - assignedActions.size(); final int alreadyAssignedTargetsCount = totalTargetsForAssignment - assignedActions.size();
@@ -631,15 +626,16 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
return template; return template;
} }
private List<DistributionSetAssignmentResult> assignDistributionSets(final String initiatedBy, private List<DistributionSetAssignmentResult> assignDistributionSets(
final String initiatedBy,
final List<DeploymentRequest> deploymentRequests, final String actionMessage, final List<DeploymentRequest> deploymentRequests, final String actionMessage,
final AbstractDsAssignmentStrategy strategy) { final AbstractDsAssignmentStrategy strategy) {
final List<DeploymentRequest> validatedRequests = validateAndFilterRequestForAssignments(deploymentRequests); final List<DeploymentRequest> validatedRequests = validateAndFilterRequestForAssignments(deploymentRequests);
final Map<Long, List<TargetWithActionType>> assignmentsByDsIds = convertRequest(validatedRequests); final Map<Long, List<TargetWithActionType>> assignmentsByDsIds = convertRequest(validatedRequests);
final List<DistributionSetAssignmentResult> results = assignmentsByDsIds.entrySet().stream() final List<DistributionSetAssignmentResult> results = assignmentsByDsIds.entrySet().stream()
.map(entry -> assignDistributionSetToTargetsWithRetry(initiatedBy, entry.getKey(), entry.getValue(), .map(entry -> assignDistributionSetToTargetsWithRetry(
actionMessage, strategy)) initiatedBy, entry.getKey(), entry.getValue(), actionMessage, strategy))
.toList(); .toList();
strategy.sendDeploymentEvents(results); strategy.sendDeploymentEvents(results);
return results; return results;
@@ -663,7 +659,9 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
private void checkForMultiAssignment(final Collection<DeploymentRequest> deploymentRequests) { private void checkForMultiAssignment(final Collection<DeploymentRequest> deploymentRequests) {
if (!isMultiAssignmentsEnabled()) { if (!isMultiAssignmentsEnabled()) {
final long distinctTargetsInRequest = deploymentRequests.stream() final long distinctTargetsInRequest = deploymentRequests.stream()
.map(request -> request.getTargetWithActionType().getControllerId()).distinct().count(); .map(request -> request.getTargetWithActionType().getControllerId())
.distinct()
.count();
if (distinctTargetsInRequest < deploymentRequests.size()) { if (distinctTargetsInRequest < deploymentRequests.size()) {
throw new MultiAssignmentIsNotEnabledException(); throw new MultiAssignmentIsNotEnabledException();
} }
@@ -676,14 +674,16 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
} }
private void checkForTargetTypeCompatibility(final List<DeploymentRequest> deploymentRequests) { private void checkForTargetTypeCompatibility(final List<DeploymentRequest> deploymentRequests) {
final List<String> controllerIds = deploymentRequests.stream().map(DeploymentRequest::getControllerId) final List<String> controllerIds = deploymentRequests.stream()
.distinct().toList(); .map(DeploymentRequest::getControllerId)
.distinct()
.toList();
final List<Long> distSetIds = deploymentRequests.stream().map(DeploymentRequest::getDistributionSetId) final List<Long> distSetIds = deploymentRequests.stream().map(DeploymentRequest::getDistributionSetId)
.distinct().toList(); .distinct()
.toList();
if (controllerIds.size() > 1 && distSetIds.size() > 1) { if (controllerIds.size() > 1 && distSetIds.size() > 1) {
throw new IllegalStateException( throw new IllegalStateException("Assigning multiple Distribution Sets to multiple Targets simultaneously is not allowed!");
"Assigning multiple Distribution Sets to multiple Targets simultaneously is not allowed!");
} }
if (distSetIds.size() == 1) { if (distSetIds.size() == 1) {
@@ -699,7 +699,10 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
.stream() .stream()
.map(ids -> targetRepository.findAll(TargetSpecifications.hasControllerIdIn(ids) .map(ids -> targetRepository.findAll(TargetSpecifications.hasControllerIdIn(ids)
.and(TargetSpecifications.notCompatibleWithDistributionSetType(distSetType.getId())))) .and(TargetSpecifications.notCompatibleWithDistributionSetType(distSetType.getId()))))
.flatMap(List::stream).map(Target::getTargetType).map(TargetType::getName).collect(Collectors.toSet()); .flatMap(List::stream)
.map(Target::getTargetType)
.map(TargetType::getName)
.collect(Collectors.toSet());
if (!incompatibleTargetTypes.isEmpty()) { if (!incompatibleTargetTypes.isEmpty()) {
throw new IncompatibleTargetTypeException(incompatibleTargetTypes, distSetType.getName()); throw new IncompatibleTargetTypeException(incompatibleTargetTypes, distSetType.getName());
@@ -714,11 +717,13 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
// we assume that list of assigned DS is less than // we assume that list of assigned DS is less than
// MAX_ENTRIES_IN_STATEMENT // MAX_ENTRIES_IN_STATEMENT
final Set<DistributionSetType> incompatibleDistSetTypes = distributionSetManagement.get(distSetIds).stream() final Set<DistributionSetType> incompatibleDistSetTypes = distributionSetManagement.get(distSetIds).stream()
.map(DistributionSet::getType).collect(Collectors.toSet()); .map(DistributionSet::getType)
.collect(Collectors.toSet());
incompatibleDistSetTypes.removeAll(target.getTargetType().getCompatibleDistributionSetTypes()); incompatibleDistSetTypes.removeAll(target.getTargetType().getCompatibleDistributionSetTypes());
if (!incompatibleDistSetTypes.isEmpty()) { if (!incompatibleDistSetTypes.isEmpty()) {
final Set<String> distSetTypeNames = incompatibleDistSetTypes.stream().map(DistributionSetType::getName) final Set<String> distSetTypeNames = incompatibleDistSetTypes.stream()
.map(DistributionSetType::getName)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
throw new IncompatibleTargetTypeException(target.getTargetType().getName(), distSetTypeNames); throw new IncompatibleTargetTypeException(target.getTargetType().getName(), distSetTypeNames);
} }
@@ -726,8 +731,10 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
} }
private List<DeploymentRequest> filterByTargetUpdatable(final List<DeploymentRequest> deploymentRequests) { private List<DeploymentRequest> filterByTargetUpdatable(final List<DeploymentRequest> deploymentRequests) {
final List<String> controllerIds = deploymentRequests.stream().map(DeploymentRequest::getControllerId) final List<String> controllerIds = deploymentRequests.stream()
.distinct().toList(); .map(DeploymentRequest::getControllerId)
.distinct()
.toList();
final List<String> found = targetRepository final List<String> found = targetRepository
.findAll(AccessController.Operation.UPDATE, TargetSpecifications.hasControllerIdIn(controllerIds)) .findAll(AccessController.Operation.UPDATE, TargetSpecifications.hasControllerIdIn(controllerIds))
@@ -773,8 +780,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
private DistributionSetAssignmentResult assignDistributionSetToTargets(final String initiatedBy, final Long dsId, private DistributionSetAssignmentResult assignDistributionSetToTargets(final String initiatedBy, final Long dsId,
final Collection<TargetWithActionType> targetsWithActionType, final String actionMessage, final Collection<TargetWithActionType> targetsWithActionType, final String actionMessage,
final AbstractDsAssignmentStrategy assignmentStrategy) { final AbstractDsAssignmentStrategy assignmentStrategy) {
final JpaDistributionSet distributionSet = final JpaDistributionSet distributionSet = (JpaDistributionSet) distributionSetManagement.getValidAndComplete(dsId);
(JpaDistributionSet) distributionSetManagement.getValidAndComplete(dsId);
if (((JpaDistributionSetManagement) distributionSetManagement).isImplicitLockApplicable(distributionSet)) { if (((JpaDistributionSetManagement) distributionSetManagement).isImplicitLockApplicable(distributionSet)) {
// without new transaction DS changed event is not thrown // without new transaction DS changed event is not thrown

View File

@@ -183,4 +183,4 @@ public class JpaDistributionSetInvalidationManagement implements DistributionSet
.countByDistributionSetIdAndActiveIsTrueAndStatusIsNot(distributionSet, Status.CANCELING)) .countByDistributionSetIdAndActiveIsTrueAndStatusIsNot(distributionSet, Status.CANCELING))
.sum(); .sum();
} }
} }

View File

@@ -151,8 +151,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSet> create(final Collection<DistributionSetCreate> creates) { public List<DistributionSet> create(final Collection<DistributionSetCreate> creates) {
final List<JpaDistributionSet> toCreate = creates.stream().map(JpaDistributionSetCreate.class::cast) final List<JpaDistributionSet> toCreate = creates.stream().map(JpaDistributionSetCreate.class::cast)
.map(this::setDefaultTypeIfMissing).map(JpaDistributionSetCreate::build).toList(); .map(this::setDefaultTypeIfMissing).map(JpaDistributionSetCreate::build).toList();
@@ -162,8 +162,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet create(final DistributionSetCreate c) { public DistributionSet create(final DistributionSetCreate c) {
final JpaDistributionSetCreate create = (JpaDistributionSetCreate) c; final JpaDistributionSetCreate create = (JpaDistributionSetCreate) c;
setDefaultTypeIfMissing(create); setDefaultTypeIfMissing(create);
@@ -173,8 +173,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet update(final DistributionSetUpdate u) { public DistributionSet update(final DistributionSetUpdate u) {
final GenericDistributionSetUpdate update = (GenericDistributionSetUpdate) u; final GenericDistributionSetUpdate update = (GenericDistributionSetUpdate) u;
@@ -212,16 +212,16 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long id) { public void delete(final long id) {
delete(List.of(id)); delete(List.of(id));
} }
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> distributionSetIDs) { public void delete(final Collection<Long> distributionSetIDs) {
getDistributionSets(distributionSetIDs); // throws EntityNotFoundException if any of these do not exists getDistributionSets(distributionSetIDs); // throws EntityNotFoundException if any of these do not exists
final List<JpaDistributionSet> setsFound = distributionSetRepository.findAll( final List<JpaDistributionSet> setsFound = distributionSetRepository.findAll(
@@ -288,8 +288,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet assignSoftwareModules(final long id, final Collection<Long> softwareModuleId) { public DistributionSet assignSoftwareModules(final long id, final Collection<Long> softwareModuleId) {
final JpaDistributionSet set = (JpaDistributionSet) getValid(id); final JpaDistributionSet set = (JpaDistributionSet) getValid(id);
assertDistributionSetIsNotAssignedToTargets(id); assertDistributionSetIsNotAssignedToTargets(id);
@@ -308,8 +308,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSet> assignTag(final Collection<Long> ids, final long dsTagId) { public List<DistributionSet> assignTag(final Collection<Long> ids, final long dsTagId) {
return updateTag(ids, dsTagId, (tag, distributionSet) -> { return updateTag(ids, dsTagId, (tag, distributionSet) -> {
if (distributionSet.getTags().contains(tag)) { if (distributionSet.getTags().contains(tag)) {
@@ -323,8 +323,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSet> unassignTag(final Collection<Long> ids, final long dsTagId) { public List<DistributionSet> unassignTag(final Collection<Long> ids, final long dsTagId) {
return updateTag(ids, dsTagId, (tag, distributionSet) -> { return updateTag(ids, dsTagId, (tag, distributionSet) -> {
if (distributionSet.getTags().contains(tag)) { if (distributionSet.getTags().contains(tag)) {
@@ -338,8 +338,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetMetadata> createMetaData(final long id, final Collection<MetaData> md) { public List<DistributionSetMetadata> createMetaData(final long id, final Collection<MetaData> md) {
final JpaDistributionSet distributionSet = (JpaDistributionSet) getValid(id); final JpaDistributionSet distributionSet = (JpaDistributionSet) getValid(id);
assertMetaDataQuota(id, md.size()); assertMetaDataQuota(id, md.size());
@@ -357,8 +357,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteMetaData(final long id, final String key) { public void deleteMetaData(final long id, final String key) {
final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId( final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(
id, key) id, key)
@@ -373,8 +373,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void lock(final long id) { public void lock(final long id) {
final JpaDistributionSet distributionSet = getById(id); final JpaDistributionSet distributionSet = getById(id);
if (!distributionSet.isLocked()) { if (!distributionSet.isLocked()) {
@@ -386,8 +386,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void unlock(final long id) { public void unlock(final long id) {
final JpaDistributionSet distributionSet = getById(id); final JpaDistributionSet distributionSet = getById(id);
if (distributionSet.isLocked()) { if (distributionSet.isLocked()) {
@@ -570,8 +570,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet unassignSoftwareModule(final long id, final long moduleId) { public DistributionSet unassignSoftwareModule(final long id, final long moduleId) {
final JpaDistributionSet set = (JpaDistributionSet) getValid(id); final JpaDistributionSet set = (JpaDistributionSet) getValid(id);
assertDistributionSetIsNotAssignedToTargets(id); assertDistributionSetIsNotAssignedToTargets(id);
@@ -584,8 +584,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetMetadata updateMetaData(final long id, final MetaData md) { public DistributionSetMetadata updateMetaData(final long id, final MetaData md) {
// check if exists otherwise throw entity not found exception // check if exists otherwise throw entity not found exception
final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(id, final JpaDistributionSetMetadata toUpdate = (JpaDistributionSetMetadata) getMetaDataByDistributionSetId(id,
@@ -641,8 +641,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection<Long> ids, final String tagName) { public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection<Long> ids, final String tagName) {
return updateTag( return updateTag(
ids, ids,
@@ -678,8 +678,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSet unassignTag(final long id, final long dsTagId) { public DistributionSet unassignTag(final long id, final long dsTagId) {
final JpaDistributionSet set = (JpaDistributionSet) getWithDetails(id) final JpaDistributionSet set = (JpaDistributionSet) getWithDetails(id)
.orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, id)); .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, id));

View File

@@ -54,14 +54,12 @@ import org.springframework.validation.annotation.Validated;
public class JpaDistributionSetTagManagement implements DistributionSetTagManagement { public class JpaDistributionSetTagManagement implements DistributionSetTagManagement {
private final DistributionSetTagRepository distributionSetTagRepository; private final DistributionSetTagRepository distributionSetTagRepository;
private final DistributionSetRepository distributionSetRepository; private final DistributionSetRepository distributionSetRepository;
private final VirtualPropertyReplacer virtualPropertyReplacer; private final VirtualPropertyReplacer virtualPropertyReplacer;
private final Database database; private final Database database;
public JpaDistributionSetTagManagement(final DistributionSetTagRepository distributionSetTagRepository, public JpaDistributionSetTagManagement(
final DistributionSetTagRepository distributionSetTagRepository,
final DistributionSetRepository distributionSetRepository, final DistributionSetRepository distributionSetRepository,
final VirtualPropertyReplacer virtualPropertyReplacer, final Database database) { final VirtualPropertyReplacer virtualPropertyReplacer, final Database database) {
this.distributionSetTagRepository = distributionSetTagRepository; this.distributionSetTagRepository = distributionSetTagRepository;
@@ -72,8 +70,8 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetTag> create(final Collection<TagCreate> dst) { public List<DistributionSetTag> create(final Collection<TagCreate> dst) {
final List<JpaDistributionSetTag> toCreate = dst.stream().map(JpaTagCreate.class::cast) final List<JpaDistributionSetTag> toCreate = dst.stream().map(JpaTagCreate.class::cast)
.map(JpaTagCreate::buildDistributionSetTag).toList(); .map(JpaTagCreate::buildDistributionSetTag).toList();
@@ -83,8 +81,8 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetTag create(final TagCreate c) { public DistributionSetTag create(final TagCreate c) {
final JpaTagCreate create = (JpaTagCreate) c; final JpaTagCreate create = (JpaTagCreate) c;
return distributionSetTagRepository.save(AccessController.Operation.CREATE, create.buildDistributionSetTag()); return distributionSetTagRepository.save(AccessController.Operation.CREATE, create.buildDistributionSetTag());
@@ -92,8 +90,8 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetTag update(final TagUpdate u) { public DistributionSetTag update(final TagUpdate u) {
final GenericTagUpdate update = (GenericTagUpdate) u; final GenericTagUpdate update = (GenericTagUpdate) u;
@@ -114,16 +112,16 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long id) { public void delete(final long id) {
distributionSetTagRepository.deleteById(id); distributionSetTagRepository.deleteById(id);
} }
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) { public void delete(final Collection<Long> ids) {
final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAllById(ids); final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAllById(ids);
@@ -166,8 +164,8 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final String tagName) { public void delete(final String tagName) {
final JpaDistributionSetTag dsTag = distributionSetTagRepository final JpaDistributionSetTag dsTag = distributionSetTagRepository
.findOne(DistributionSetTagSpecifications.byName(tagName)) .findOne(DistributionSetTagSpecifications.byName(tagName))

View File

@@ -105,8 +105,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignOptionalSoftwareModuleTypes(final long id, public DistributionSetType assignOptionalSoftwareModuleTypes(final long id,
final Collection<Long> softwareModulesTypeIds) { final Collection<Long> softwareModulesTypeIds) {
return assignSoftwareModuleTypes(id, softwareModulesTypeIds, false); return assignSoftwareModuleTypes(id, softwareModulesTypeIds, false);
@@ -114,8 +114,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType assignMandatorySoftwareModuleTypes(final long id, public DistributionSetType assignMandatorySoftwareModuleTypes(final long id,
final Collection<Long> softwareModuleTypeIds) { final Collection<Long> softwareModuleTypeIds) {
return assignSoftwareModuleTypes(id, softwareModuleTypeIds, true); return assignSoftwareModuleTypes(id, softwareModuleTypeIds, true);
@@ -123,8 +123,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType unassignSoftwareModuleType(final long id, final long softwareModuleTypeId) { public DistributionSetType unassignSoftwareModuleType(final long id, final long softwareModuleTypeId) {
final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(id); final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(id);
@@ -137,8 +137,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<DistributionSetType> create(final Collection<DistributionSetTypeCreate> types) { public List<DistributionSetType> create(final Collection<DistributionSetTypeCreate> types) {
final List<JpaDistributionSetType> typesToCreate = types.stream().map(JpaDistributionSetTypeCreate.class::cast) final List<JpaDistributionSetType> typesToCreate = types.stream().map(JpaDistributionSetTypeCreate.class::cast)
.map(JpaDistributionSetTypeCreate::build).toList(); .map(JpaDistributionSetTypeCreate::build).toList();
@@ -149,8 +149,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType create(final DistributionSetTypeCreate c) { public DistributionSetType create(final DistributionSetTypeCreate c) {
final JpaDistributionSetType distributionSetType = ((JpaDistributionSetTypeCreate) c).build(); final JpaDistributionSetType distributionSetType = ((JpaDistributionSetTypeCreate) c).build();
@@ -159,8 +159,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public DistributionSetType update(final DistributionSetTypeUpdate u) { public DistributionSetType update(final DistributionSetTypeUpdate u) {
final GenericDistributionSetTypeUpdate update = (GenericDistributionSetTypeUpdate) u; final GenericDistributionSetTypeUpdate update = (GenericDistributionSetTypeUpdate) u;
@@ -202,8 +202,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long id) { public void delete(final long id) {
final JpaDistributionSetType toDelete = distributionSetTypeRepository.findById(id) final JpaDistributionSetType toDelete = distributionSetTypeRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, id)); .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, id));
@@ -220,8 +220,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) { public void delete(final Collection<Long> ids) {
distributionSetTypeRepository.deleteAllById(ids); distributionSetTypeRepository.deleteAllById(ids);
} }

View File

@@ -106,10 +106,10 @@ public class JpaRolloutManagement implements RolloutManagement {
private static final List<RolloutStatus> ACTIVE_ROLLOUTS = Arrays.asList(RolloutStatus.CREATING, private static final List<RolloutStatus> ACTIVE_ROLLOUTS = Arrays.asList(RolloutStatus.CREATING,
RolloutStatus.DELETING, RolloutStatus.STARTING, RolloutStatus.READY, RolloutStatus.RUNNING, RolloutStatus.DELETING, RolloutStatus.STARTING, RolloutStatus.READY, RolloutStatus.RUNNING,
RolloutStatus.STOPPING); RolloutStatus.STOPPING);
private static final List<RolloutStatus> ROLLOUT_STATUS_STOPPABLE = Arrays.asList(RolloutStatus.RUNNING, private static final List<RolloutStatus> ROLLOUT_STATUS_STOPPABLE = Arrays.asList(RolloutStatus.RUNNING,
RolloutStatus.CREATING, RolloutStatus.PAUSED, RolloutStatus.READY, RolloutStatus.STARTING, RolloutStatus.CREATING, RolloutStatus.PAUSED, RolloutStatus.READY, RolloutStatus.STARTING,
RolloutStatus.WAITING_FOR_APPROVAL, RolloutStatus.APPROVAL_DENIED); RolloutStatus.WAITING_FOR_APPROVAL, RolloutStatus.APPROVAL_DENIED);
private final TargetManagement targetManagement; private final TargetManagement targetManagement;
private final DistributionSetManagement distributionSetManagement; private final DistributionSetManagement distributionSetManagement;
private final VirtualPropertyReplacer virtualPropertyReplacer; private final VirtualPropertyReplacer virtualPropertyReplacer;
@@ -181,8 +181,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout create(final RolloutCreate rollout, final int amountGroup, final boolean confirmationRequired, public Rollout create(final RolloutCreate rollout, final int amountGroup, final boolean confirmationRequired,
final RolloutGroupConditions conditions, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) { final RolloutGroupConditions conditions, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) {
if (amountGroup < 0) { if (amountGroup < 0) {
@@ -207,8 +207,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout create(@NotNull @Valid RolloutCreate create, int amountGroup, boolean confirmationRequired, public Rollout create(@NotNull @Valid RolloutCreate create, int amountGroup, boolean confirmationRequired,
@NotNull RolloutGroupConditions conditions) { @NotNull RolloutGroupConditions conditions) {
return create(create, amountGroup, confirmationRequired, conditions, null); return create(create, amountGroup, confirmationRequired, conditions, null);
@@ -216,8 +216,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout create(final RolloutCreate rollout, final List<RolloutGroupCreate> groups, public Rollout create(final RolloutCreate rollout, final List<RolloutGroupCreate> groups,
final RolloutGroupConditions conditions) { final RolloutGroupConditions conditions) {
if (groups.isEmpty()) { if (groups.isEmpty()) {
@@ -324,8 +324,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void pauseRollout(final long rolloutId) { public void pauseRollout(final long rolloutId) {
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId); final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
if (RolloutStatus.RUNNING != rollout.getStatus()) { if (RolloutStatus.RUNNING != rollout.getStatus()) {
@@ -343,8 +343,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void resumeRollout(final long rolloutId) { public void resumeRollout(final long rolloutId) {
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId); final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
if (RolloutStatus.PAUSED != rollout.getStatus()) { if (RolloutStatus.PAUSED != rollout.getStatus()) {
@@ -357,29 +357,32 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision) { public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision) {
return this.approveOrDeny(rolloutId, decision, null); return this.approveOrDeny(rolloutId, decision, null);
} }
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision, final String remark) { public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision, final String remark) {
log.debug("approveOrDeny rollout called for rollout {} with decision {}", rolloutId, decision); log.debug("approveOrDeny rollout called for rollout {} with decision {}", rolloutId, decision);
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId); final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL); RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL);
switch (decision) { switch (decision) {
case APPROVED: case APPROVED: {
rollout.setStatus(RolloutStatus.READY); rollout.setStatus(RolloutStatus.READY);
break; break;
case DENIED: }
case DENIED: {
rollout.setStatus(RolloutStatus.APPROVAL_DENIED); rollout.setStatus(RolloutStatus.APPROVAL_DENIED);
break; break;
default: }
default: {
throw new IllegalArgumentException("Unknown approval decision: " + decision); throw new IllegalArgumentException("Unknown approval decision: " + decision);
}
} }
rollout.setApprovalDecidedBy(rolloutApprovalStrategy.getApprovalUser(rollout)); rollout.setApprovalDecidedBy(rolloutApprovalStrategy.getApprovalUser(rollout));
if (remark != null) { if (remark != null) {
@@ -390,8 +393,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout start(final long rolloutId) { public Rollout start(final long rolloutId) {
log.debug("startRollout called for rollout {}", rolloutId); log.debug("startRollout called for rollout {}", rolloutId);
@@ -404,8 +407,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout update(final RolloutUpdate u) { public Rollout update(final RolloutUpdate u) {
final GenericRolloutUpdate update = (GenericRolloutUpdate) u; final GenericRolloutUpdate update = (GenericRolloutUpdate) u;
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(update.getId()); final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(update.getId());
@@ -419,8 +422,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long rolloutId) { public void delete(final long rolloutId) {
final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId) final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId)); .orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
@@ -451,8 +454,8 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void triggerNextGroup(final long rolloutId) { public void triggerNextGroup(final long rolloutId) {
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId); final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
if (RolloutStatus.RUNNING != rollout.getStatus()) { if (RolloutStatus.RUNNING != rollout.getStatus()) {
@@ -479,8 +482,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
public void setRolloutStatusDetails(final Slice<Rollout> rollouts) { public void setRolloutStatusDetails(final Slice<Rollout> rollouts) {
final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).collect(Collectors.toList()); final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).collect(Collectors.toList());
final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout( final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout(rolloutIds);
rolloutIds);
if (allStatesForRollout != null) { if (allStatesForRollout != null) {
rollouts.forEach(rollout -> { rollouts.forEach(rollout -> {
@@ -492,14 +494,13 @@ public class JpaRolloutManagement implements RolloutManagement {
} }
/** /**
* In case the given group is missing conditions or actions, they will be set * In case the given group is missing conditions or actions, they will be set from the supplied default conditions.
* from the supplied default conditions.
* *
* @param create group to check * @param create group to check
* @param conditions default conditions and actions * @param conditions default conditions and actions
*/ */
private static JpaRolloutGroup prepareRolloutGroupWithDefaultConditions(final RolloutGroupCreate create, private static JpaRolloutGroup prepareRolloutGroupWithDefaultConditions(
final RolloutGroupConditions conditions) { final RolloutGroupCreate create, final RolloutGroupConditions conditions) {
final JpaRolloutGroup group = ((JpaRolloutGroupCreate) create).build(); final JpaRolloutGroup group = ((JpaRolloutGroupCreate) create).build();
if (group.getSuccessCondition() == null) { if (group.getSuccessCondition() == null) {

View File

@@ -115,8 +115,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModule> create(final Collection<SoftwareModuleCreate> swModules) { public List<SoftwareModule> create(final Collection<SoftwareModuleCreate> swModules) {
final List<JpaSoftwareModule> modulesToCreate = swModules.stream().map(JpaSoftwareModuleCreate.class::cast) final List<JpaSoftwareModule> modulesToCreate = swModules.stream().map(JpaSoftwareModuleCreate.class::cast)
.map(JpaSoftwareModuleCreate::build).toList(); .map(JpaSoftwareModuleCreate::build).toList();
@@ -135,8 +135,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModule create(final SoftwareModuleCreate c) { public SoftwareModule create(final SoftwareModuleCreate c) {
final JpaSoftwareModuleCreate create = (JpaSoftwareModuleCreate) c; final JpaSoftwareModuleCreate create = (JpaSoftwareModuleCreate) c;
@@ -152,8 +152,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModule update(final SoftwareModuleUpdate u) { public SoftwareModule update(final SoftwareModuleUpdate u) {
final GenericSoftwareModuleUpdate update = (GenericSoftwareModuleUpdate) u; final GenericSoftwareModuleUpdate update = (GenericSoftwareModuleUpdate) u;
@@ -180,16 +180,16 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long id) { public void delete(final long id) {
delete(List.of(id)); delete(List.of(id));
} }
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) { public void delete(final Collection<Long> ids) {
final List<JpaSoftwareModule> swModulesToDelete = softwareModuleRepository.findAllById(ids); final List<JpaSoftwareModule> swModulesToDelete = softwareModuleRepository.findAllById(ids);
if (swModulesToDelete.size() < ids.size()) { if (swModulesToDelete.size() < ids.size()) {
@@ -267,8 +267,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModuleMetadata> createMetaData(final Collection<SoftwareModuleMetadataCreate> create) { public List<SoftwareModuleMetadata> createMetaData(final Collection<SoftwareModuleMetadataCreate> create) {
if (!create.isEmpty()) { if (!create.isEmpty()) {
// check if all metadata entries refer to the same software module // check if all metadata entries refer to the same software module
@@ -304,8 +304,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata createMetaData(final SoftwareModuleMetadataCreate c) { public SoftwareModuleMetadata createMetaData(final SoftwareModuleMetadataCreate c) {
final JpaSoftwareModuleMetadataCreate create = (JpaSoftwareModuleMetadataCreate) c; final JpaSoftwareModuleMetadataCreate create = (JpaSoftwareModuleMetadataCreate) c;
final Long id = create.getSoftwareModuleId(); final Long id = create.getSoftwareModuleId();
@@ -321,8 +321,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteMetaData(final long id, final String key) { public void deleteMetaData(final long id, final String key) {
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(id, final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(id,
key).orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, id, key)); key).orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, id, key));
@@ -439,8 +439,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void lock(final long id) { public void lock(final long id) {
final JpaSoftwareModule softwareModule = softwareModuleRepository final JpaSoftwareModule softwareModule = softwareModuleRepository
.findById(id) .findById(id)
@@ -453,8 +453,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void unlock(final long id) { public void unlock(final long id) {
final JpaSoftwareModule softwareModule = softwareModuleRepository final JpaSoftwareModule softwareModule = softwareModuleRepository
.findById(id) .findById(id)
@@ -467,8 +467,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleMetadata updateMetaData(final SoftwareModuleMetadataUpdate u) { public SoftwareModuleMetadata updateMetaData(final SoftwareModuleMetadataUpdate u) {
final GenericSoftwareModuleMetadataUpdate update = (GenericSoftwareModuleMetadataUpdate) u; final GenericSoftwareModuleMetadataUpdate update = (GenericSoftwareModuleMetadataUpdate) u;

View File

@@ -79,8 +79,8 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<SoftwareModuleType> create(final Collection<SoftwareModuleTypeCreate> c) { public List<SoftwareModuleType> create(final Collection<SoftwareModuleTypeCreate> c) {
final List<JpaSoftwareModuleType> creates = c.stream().map(JpaSoftwareModuleTypeCreate.class::cast) final List<JpaSoftwareModuleType> creates = c.stream().map(JpaSoftwareModuleTypeCreate.class::cast)
.map(JpaSoftwareModuleTypeCreate::build).toList(); .map(JpaSoftwareModuleTypeCreate::build).toList();
@@ -90,8 +90,8 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleType create(final SoftwareModuleTypeCreate c) { public SoftwareModuleType create(final SoftwareModuleTypeCreate c) {
final JpaSoftwareModuleTypeCreate create = (JpaSoftwareModuleTypeCreate) c; final JpaSoftwareModuleTypeCreate create = (JpaSoftwareModuleTypeCreate) c;
@@ -100,8 +100,8 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public SoftwareModuleType update(final SoftwareModuleTypeUpdate u) { public SoftwareModuleType update(final SoftwareModuleTypeUpdate u) {
final GenericSoftwareModuleTypeUpdate update = (GenericSoftwareModuleTypeUpdate) u; final GenericSoftwareModuleTypeUpdate update = (GenericSoftwareModuleTypeUpdate) u;
@@ -121,8 +121,8 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long id) { public void delete(final long id) {
final JpaSoftwareModuleType toDelete = softwareModuleTypeRepository.findById(id) final JpaSoftwareModuleType toDelete = softwareModuleTypeRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, id)); .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, id));
@@ -132,8 +132,8 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) { public void delete(final Collection<Long> ids) {
softwareModuleTypeRepository softwareModuleTypeRepository
.findAll(AccessController.Operation.DELETE, softwareModuleTypeRepository.byIdsSpec(ids)) .findAll(AccessController.Operation.DELETE, softwareModuleTypeRepository.byIdsSpec(ids))

View File

@@ -153,8 +153,8 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteTenant(final String t) { public void deleteTenant(final String t) {
if (artifactRepository == null) { if (artifactRepository == null) {
throw new IllegalStateException("Artifact repository is not available. Can't delete tenant."); throw new IllegalStateException("Artifact repository is not available. Can't delete tenant.");
@@ -278,8 +278,8 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TenantMetaData updateTenantMetadata(final long defaultDsType) { public TenantMetaData updateTenantMetadata(final long defaultDsType) {
final JpaTenantMetaData data = (JpaTenantMetaData) getTenantMetadata(); final JpaTenantMetaData data = (JpaTenantMetaData) getTenantMetadata();

View File

@@ -106,8 +106,8 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetFilterQuery create(final TargetFilterQueryCreate c) { public TargetFilterQuery create(final TargetFilterQueryCreate c) {
final JpaTargetFilterQueryCreate create = (JpaTargetFilterQueryCreate) c; final JpaTargetFilterQueryCreate create = (JpaTargetFilterQueryCreate) c;
@@ -129,8 +129,8 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long targetFilterQueryId) { public void delete(final long targetFilterQueryId) {
if (!targetFilterQueryRepository.existsById(targetFilterQueryId)) { if (!targetFilterQueryRepository.existsById(targetFilterQueryId)) {
throw new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId); throw new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId);

View File

@@ -236,8 +236,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target create(final TargetCreate c) { public Target create(final TargetCreate c) {
final JpaTargetCreate create = (JpaTargetCreate) c; final JpaTargetCreate create = (JpaTargetCreate) c;
return targetRepository.save(AccessController.Operation.CREATE, create.build()); return targetRepository.save(AccessController.Operation.CREATE, create.build());
@@ -245,8 +245,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<Target> create(final Collection<TargetCreate> targets) { public List<Target> create(final Collection<TargetCreate> targets) {
final List<JpaTarget> targetList = targets.stream().map(JpaTargetCreate.class::cast).map(JpaTargetCreate::build) final List<JpaTarget> targetList = targets.stream().map(JpaTargetCreate.class::cast).map(JpaTargetCreate::build)
.toList(); .toList();
@@ -255,8 +255,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Collection<Long> ids) { public void delete(final Collection<Long> ids) {
final List<JpaTarget> targets = targetRepository.findAllById(ids); final List<JpaTarget> targets = targetRepository.findAllById(ids);
if (targets.size() < ids.size()) { if (targets.size() < ids.size()) {
@@ -269,8 +269,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteByControllerID(final String controllerId) { public void deleteByControllerID(final String controllerId) {
targetRepository.delete(getByControllerIdAndThrowIfNotFound(controllerId)); targetRepository.delete(getByControllerIdAndThrowIfNotFound(controllerId));
} }
@@ -500,8 +500,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTypeAssignmentResult assignType(final Collection<String> controllerIds, final Long typeId) { public TargetTypeAssignmentResult assignType(final Collection<String> controllerIds, final Long typeId) {
final JpaTargetType type = targetTypeRepository.findById(typeId) final JpaTargetType type = targetTypeRepository.findById(typeId)
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, typeId)); .orElseThrow(() -> new EntityNotFoundException(TargetType.class, typeId));
@@ -525,8 +525,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTypeAssignmentResult unassignType(final Collection<String> controllerIds) { public TargetTypeAssignmentResult unassignType(final Collection<String> controllerIds) {
final List<JpaTarget> allTargets = findTargetsByInSpecification(controllerIds, null); final List<JpaTarget> allTargets = findTargetsByInSpecification(controllerIds, null);
@@ -543,8 +543,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<Target> assignTag(final Collection<String> controllerIds, final long targetTagId, public List<Target> assignTag(final Collection<String> controllerIds, final long targetTagId,
final Consumer<Collection<String>> notFoundHandler) { final Consumer<Collection<String>> notFoundHandler) {
return updateTag(controllerIds, targetTagId, notFoundHandler, (tag, target) -> { return updateTag(controllerIds, targetTagId, notFoundHandler, (tag, target) -> {
@@ -559,8 +559,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<Target> unassignTag(final Collection<String> controllerIds, final long targetTagId, public List<Target> unassignTag(final Collection<String> controllerIds, final long targetTagId,
final Consumer<Collection<String>> notFoundHandler) { final Consumer<Collection<String>> notFoundHandler) {
return updateTag(controllerIds, targetTagId, notFoundHandler, (tag, target) -> { return updateTag(controllerIds, targetTagId, notFoundHandler, (tag, target) -> {
@@ -575,8 +575,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target unassignType(final String controllerId) { public Target unassignType(final String controllerId) {
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId); final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
target.setTargetType(null); target.setTargetType(null);
@@ -585,8 +585,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target assignType(final String controllerId, final Long targetTypeId) { public Target assignType(final String controllerId, final Long targetTypeId) {
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId); final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
@@ -601,8 +601,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target update(final TargetUpdate u) { public Target update(final TargetUpdate u) {
final JpaTargetUpdate update = (JpaTargetUpdate) u; final JpaTargetUpdate update = (JpaTargetUpdate) u;
@@ -708,8 +708,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<TargetMetadata> createMetaData(final String controllerId, final Collection<MetaData> md) { public List<TargetMetadata> createMetaData(final String controllerId, final Collection<MetaData> md) {
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId); final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
@@ -735,8 +735,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteMetaData(final String controllerId, final String key) { public void deleteMetaData(final String controllerId, final String key) {
final JpaTargetMetadata metadata = (JpaTargetMetadata) getMetaDataByControllerId(controllerId, key) final JpaTargetMetadata metadata = (JpaTargetMetadata) getMetaDataByControllerId(controllerId, key)
.orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, controllerId, key)); .orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, controllerId, key));
@@ -791,8 +791,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetMetadata updateMetadata(final String controllerId, final MetaData md) { public TargetMetadata updateMetadata(final String controllerId, final MetaData md) {
// check if exists otherwise throw entity not found exception // check if exists otherwise throw entity not found exception
@@ -815,8 +815,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTagAssignmentResult toggleTagAssignment(final Collection<String> controllerIds, final String tagName) { public TargetTagAssignmentResult toggleTagAssignment(final Collection<String> controllerIds, final String tagName) {
final TargetTag tag = targetTagRepository final TargetTag tag = targetTagRepository
.findByNameEquals(tagName) .findByNameEquals(tagName)
@@ -852,8 +852,8 @@ public class JpaTargetManagement implements TargetManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target unassignTag(final String controllerId, final long targetTagId) { public Target unassignTag(final String controllerId, final long targetTagId) {
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId); final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);

View File

@@ -67,8 +67,8 @@ public class JpaTargetTagManagement implements TargetTagManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTag create(final TagCreate c) { public TargetTag create(final TagCreate c) {
final JpaTagCreate create = (JpaTagCreate) c; final JpaTagCreate create = (JpaTagCreate) c;
@@ -77,8 +77,8 @@ public class JpaTargetTagManagement implements TargetTagManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<TargetTag> create(final Collection<TagCreate> tt) { public List<TargetTag> create(final Collection<TagCreate> tt) {
final List<JpaTargetTag> targetTagList = tt.stream().map(JpaTagCreate.class::cast) final List<JpaTargetTag> targetTagList = tt.stream().map(JpaTagCreate.class::cast)
.map(JpaTagCreate::buildTargetTag).toList(); .map(JpaTagCreate::buildTargetTag).toList();
@@ -88,8 +88,8 @@ public class JpaTargetTagManagement implements TargetTagManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final String targetTagName) { public void delete(final String targetTagName) {
targetTagRepository.delete( targetTagRepository.delete(
targetTagRepository targetTagRepository
@@ -125,8 +125,8 @@ public class JpaTargetTagManagement implements TargetTagManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetTag update(final TagUpdate u) { public TargetTag update(final TagUpdate u) {
final GenericTagUpdate update = (GenericTagUpdate) u; final GenericTagUpdate update = (GenericTagUpdate) u;

View File

@@ -106,8 +106,8 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetType create(final TargetTypeCreate create) { public TargetType create(final TargetTypeCreate create) {
final JpaTargetType typeCreate = ((JpaTargetTypeCreate) create).build(); final JpaTargetType typeCreate = ((JpaTargetTypeCreate) create).build();
return targetTypeRepository.save(AccessController.Operation.CREATE, typeCreate); return targetTypeRepository.save(AccessController.Operation.CREATE, typeCreate);
@@ -115,8 +115,8 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public List<TargetType> create(final Collection<TargetTypeCreate> creates) { public List<TargetType> create(final Collection<TargetTypeCreate> creates) {
final List<JpaTargetType> typeCreate = final List<JpaTargetType> typeCreate =
creates.stream().map(create -> ((JpaTargetTypeCreate) create).build()).toList(); creates.stream().map(create -> ((JpaTargetTypeCreate) create).build()).toList();
@@ -125,8 +125,8 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final Long id) { public void delete(final Long id) {
getByIdAndThrowIfNotFound(id); getByIdAndThrowIfNotFound(id);
@@ -168,8 +168,8 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetType update(final TargetTypeUpdate update) { public TargetType update(final TargetTypeUpdate update) {
final GenericTargetTypeUpdate typeUpdate = (GenericTargetTypeUpdate) update; final GenericTargetTypeUpdate typeUpdate = (GenericTargetTypeUpdate) update;
@@ -184,8 +184,8 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetType assignCompatibleDistributionSetTypes(final long id, public TargetType assignCompatibleDistributionSetTypes(final long id,
final Collection<Long> distributionSetTypeIds) { final Collection<Long> distributionSetTypeIds) {
final Collection<JpaDistributionSetType> dsTypes = distributionSetTypeRepository final Collection<JpaDistributionSetType> dsTypes = distributionSetTypeRepository
@@ -205,8 +205,8 @@ public class JpaTargetTypeManagement implements TargetTypeManagement {
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TargetType unassignDistributionSetType(final long id, final long distributionSetTypeId) { public TargetType unassignDistributionSetType(final long id, final long distributionSetTypeId) {
final JpaTargetType type = getByIdAndThrowIfNotFound(id); final JpaTargetType type = getByIdAndThrowIfNotFound(id);
assertDistributionSetTypeExists(distributionSetTypeId); assertDistributionSetTypeExists(distributionSetTypeId);

View File

@@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValueChangeNotAllowedException; import org.eclipse.hawkbit.repository.exception.TenantConfigurationValueChangeNotAllowedException;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
@@ -35,7 +36,6 @@ import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder;
import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
@@ -73,8 +73,8 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana
@Override @Override
@CacheEvict(value = "tenantConfiguration", key = "#configurationKeyName") @CacheEvict(value = "tenantConfiguration", key = "#configurationKeyName")
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public <T extends Serializable> TenantConfigurationValue<T> addOrUpdateConfiguration( public <T extends Serializable> TenantConfigurationValue<T> addOrUpdateConfiguration(
final String configurationKeyName, final T value) { final String configurationKeyName, final T value) {
return addOrUpdateConfiguration0(Collections.singletonMap(configurationKeyName, value)).values().iterator().next(); return addOrUpdateConfiguration0(Collections.singletonMap(configurationKeyName, value)).values().iterator().next();
@@ -82,8 +82,8 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana
@Override @Override
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public <T extends Serializable> Map<String, TenantConfigurationValue<T>> addOrUpdateConfiguration(Map<String, T> configurations) { public <T extends Serializable> Map<String, TenantConfigurationValue<T>> addOrUpdateConfiguration(Map<String, T> configurations) {
// Register a callback to be invoked after the transaction is committed - for cache eviction // Register a callback to be invoked after the transaction is committed - for cache eviction
afterCommitExecutor.afterCommit(() -> { afterCommitExecutor.afterCommit(() -> {
@@ -99,8 +99,8 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana
@Override @Override
@CacheEvict(value = "tenantConfiguration", key = "#configurationKeyName") @CacheEvict(value = "tenantConfiguration", key = "#configurationKeyName")
@Transactional @Transactional
@Retryable(include = { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteConfiguration(final String configurationKeyName) { public void deleteConfiguration(final String configurationKeyName) {
tenantConfigurationRepository.deleteByKey(configurationKeyName); tenantConfigurationRepository.deleteByKey(configurationKeyName);
} }

View File

@@ -28,13 +28,10 @@ public class JpaTenantStatsManagement implements TenantStatsManagement {
@Autowired @Autowired
private TargetRepository targetRepository; private TargetRepository targetRepository;
@Autowired @Autowired
private LocalArtifactRepository artifactRepository; private LocalArtifactRepository artifactRepository;
@Autowired @Autowired
private ActionRepository actionRepository; private ActionRepository actionRepository;
@Autowired @Autowired
private TenantAware tenantAware; private TenantAware tenantAware;
@@ -52,4 +49,4 @@ public class JpaTenantStatsManagement implements TenantStatsManagement {
return result; return result;
} }
} }

View File

@@ -47,7 +47,8 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
*/ */
public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy { public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
OfflineDsAssignmentStrategy(final TargetRepository targetRepository, OfflineDsAssignmentStrategy(
final TargetRepository targetRepository,
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder, final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository, final ActionRepository actionRepository, final ActionStatusRepository actionStatusRepository,
final QuotaManagement quotaManagement, final BooleanSupplier multiAssignmentsConfig, final QuotaManagement quotaManagement, final BooleanSupplier multiAssignmentsConfig,

View File

@@ -24,8 +24,8 @@ import jakarta.persistence.Version;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.eclipse.hawkbit.tenancy.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.eclipse.hawkbit.tenancy.TenantAwareAuthenticationDetails;
import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy; import org.springframework.data.annotation.LastModifiedBy;
@@ -96,19 +96,22 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
return optLockRevision; return optLockRevision;
} }
@CreatedBy @LastModifiedDate
public void setCreatedBy(final String createdBy) { public void setLastModifiedAt(final long lastModifiedAt) {
if (isController()) { if (isController()) {
this.createdBy = "CONTROLLER_PLUG_AND_PLAY";
// In general modification audit entry is not changed by the
// controller. However, we want to stay consistent with
// EnableJpaAuditing#modifyOnCreate=true.
this.lastModifiedBy = this.createdBy;
return; return;
} }
this.createdBy = createdBy; this.lastModifiedAt = lastModifiedAt;
}
@LastModifiedBy
public void setLastModifiedBy(final String lastModifiedBy) {
if (isController()) {
return;
}
this.lastModifiedBy = lastModifiedBy;
} }
@CreatedDate @CreatedDate
@@ -123,22 +126,19 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
} }
} }
@LastModifiedBy @CreatedBy
public void setLastModifiedBy(final String lastModifiedBy) { public void setCreatedBy(final String createdBy) {
if (isController()) { if (isController()) {
this.createdBy = "CONTROLLER_PLUG_AND_PLAY";
// In general modification audit entry is not changed by the
// controller. However, we want to stay consistent with
// EnableJpaAuditing#modifyOnCreate=true.
this.lastModifiedBy = this.createdBy;
return; return;
} }
this.lastModifiedBy = lastModifiedBy; this.createdBy = createdBy;
}
@LastModifiedDate
public void setLastModifiedAt(final long lastModifiedAt) {
if (isController()) {
return;
}
this.lastModifiedAt = lastModifiedAt;
} }
@Override @Override
@@ -201,7 +201,8 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity {
private boolean isController() { private boolean isController() {
return SecurityContextHolder.getContext().getAuthentication() != null return SecurityContextHolder.getContext().getAuthentication() != null
&& SecurityContextHolder.getContext().getAuthentication().getDetails() instanceof TenantAwareAuthenticationDetails tenantAwareDetails && SecurityContextHolder.getContext().getAuthentication()
.getDetails() instanceof TenantAwareAuthenticationDetails tenantAwareDetails
&& tenantAwareDetails.isController(); && tenantAwareDetails.isController();
} }
} }

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository.jpa.model;
import java.io.Serializable; import java.io.Serializable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.ConstraintMode; import jakarta.persistence.ConstraintMode;
import jakarta.persistence.EmbeddedId; import jakarta.persistence.EmbeddedId;

Some files were not shown because too many files have changed in this diff Show More