Spring Boot 2.0 (#721)
* Migration to Boot 2.0. Signed-off-by: Kai Zimmermann <kai.zimmermann@microsoft.com>
This commit is contained in:
@@ -42,8 +42,20 @@
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
<artifactId>kryo-shaded</artifactId>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-rsa</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.objenesis</groupId>
|
||||
<artifactId>objenesis</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-el</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-context</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidTargetAttributeException;
|
||||
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
@@ -400,9 +400,9 @@ public interface ControllerManagement {
|
||||
|
||||
/**
|
||||
* Cancels given {@link Action} for this {@link Target}. However, it might
|
||||
* be possible that the controller will continue to work on the cancelation.
|
||||
* The controller needs to acknowledge or reject the cancelation using
|
||||
* {@link DdiRootController#postCancelActionFeedback}.
|
||||
* be possible that the controller will continue to work on the
|
||||
* cancellation. The controller needs to acknowledge or reject the
|
||||
* cancellation using {@link DdiRootController#postCancelActionFeedback}.
|
||||
*
|
||||
* @param actionId
|
||||
* to be canceled
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.data.domain.Sort;
|
||||
public final class OffsetBasedPageRequest extends PageRequest {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final int offset;
|
||||
private final long offset;
|
||||
|
||||
/**
|
||||
* Creates a new {@link OffsetBasedPageRequest}. Offsets are zero indexed,
|
||||
@@ -32,8 +32,8 @@ public final class OffsetBasedPageRequest extends PageRequest {
|
||||
* @param limit
|
||||
* the limit of the page to be returned.
|
||||
*/
|
||||
public OffsetBasedPageRequest(final int offset, final int limit) {
|
||||
this(offset, limit, null);
|
||||
public OffsetBasedPageRequest(final long offset, final int limit) {
|
||||
this(offset, limit, Sort.unsorted());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,13 +47,13 @@ public final class OffsetBasedPageRequest extends PageRequest {
|
||||
* @param sort
|
||||
* sort can be {@literal null}.
|
||||
*/
|
||||
public OffsetBasedPageRequest(final int offset, final int limit, final Sort sort) {
|
||||
public OffsetBasedPageRequest(final long offset, final int limit, final Sort sort) {
|
||||
super(0, limit, sort);
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
public long getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public final class OffsetBasedPageRequest extends PageRequest {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + offset;
|
||||
result = prime * result + (int) (offset ^ (offset >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -79,11 +79,14 @@ public final class OffsetBasedPageRequest extends PageRequest {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof OffsetBasedPageRequest)) {
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final OffsetBasedPageRequest other = (OffsetBasedPageRequest) obj;
|
||||
return offset == other.offset;
|
||||
if (offset != other.offset) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -631,6 +631,7 @@ public interface TargetManagement {
|
||||
* @throws EntityNotFoundException
|
||||
* if target with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Map<String, String> getControllerAttributes(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
@@ -642,6 +643,7 @@ public interface TargetManagement {
|
||||
* @throws EntityNotFoundException
|
||||
* if target with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||
void requestControllerAttributes(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
@@ -652,8 +654,33 @@ public interface TargetManagement {
|
||||
* @return {@code true}: update of controller attributes triggered.
|
||||
* {@code false}: update of controller attributes not requested.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
boolean isControllerAttributesRequested(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Retrieves {@link Target}s where
|
||||
* {@link #isControllerAttributesRequested(String)}.
|
||||
*
|
||||
* @param pageReq
|
||||
* page parameter
|
||||
*
|
||||
* @return the found {@link Target}s
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Page<Target> findByControllerAttributesRequested(@NotNull Pageable pageReq);
|
||||
|
||||
/**
|
||||
* Verifies that {@link Target} with given controller ID exists in the
|
||||
* repository.
|
||||
*
|
||||
* @param controllerId
|
||||
* of target
|
||||
* @return {@code true} if target with given ID exists
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
boolean existsByControllerId(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Creates a list of target meta data entries.
|
||||
*
|
||||
|
||||
@@ -40,7 +40,7 @@ public class RemoteTenantAwareEvent extends RemoteApplicationEvent implements Te
|
||||
* the applicationId
|
||||
*/
|
||||
public RemoteTenantAwareEvent(final Object source, final String tenant, final String applicationId) {
|
||||
super(source, applicationId, "**");
|
||||
super(source, applicationId);
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public final class ArtifactBinaryNotFoundException extends AbstractServerRtExcep
|
||||
|
||||
/**
|
||||
* Creates a new FileUploadFailedException with
|
||||
* {@link SpServerError#SP_REST_BODY_NOT_READABLE} error.
|
||||
* {@link SpServerError#SP_ARTIFACT_LOAD_FAILED} error.
|
||||
*/
|
||||
public ArtifactBinaryNotFoundException() {
|
||||
super(SpServerError.SP_ARTIFACT_LOAD_FAILED);
|
||||
|
||||
@@ -26,7 +26,7 @@ public final class ArtifactDeleteFailedException extends AbstractServerRtExcepti
|
||||
|
||||
/**
|
||||
* Creates a new FileUploadFailedException with
|
||||
* {@link SpServerError#SP_REST_BODY_NOT_READABLE} error.
|
||||
* {@link SpServerError#SP_ARTIFACT_DELETE_FAILED} error.
|
||||
*/
|
||||
public ArtifactDeleteFailedException() {
|
||||
super(SpServerError.SP_ARTIFACT_DELETE_FAILED);
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class ArtifactUploadFailedException extends AbstractServerRtExcepti
|
||||
|
||||
/**
|
||||
* Creates a new FileUploadFailedException with
|
||||
* {@link SpServerError#SP_REST_BODY_NOT_READABLE} error.
|
||||
* {@link SpServerError#SP_ARTIFACT_UPLOAD_FAILED} error.
|
||||
*/
|
||||
public ArtifactUploadFailedException() {
|
||||
super(SpServerError.SP_ARTIFACT_UPLOAD_FAILED);
|
||||
|
||||
@@ -8,13 +8,15 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Implementations map a placeholder to the associated value.
|
||||
* <p>
|
||||
* This is used in context of string replacement.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface VirtualPropertyReplacer {
|
||||
public interface VirtualPropertyReplacer extends Serializable {
|
||||
|
||||
/**
|
||||
* Looks up a placeholders and replaces them
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
package org.eclipse.hawkbit.repository.model.helper;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ public final class EventPublisherHolder {
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private BusProperties bus;
|
||||
|
||||
private EventPublisherHolder() {
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class EventPublisherHolder {
|
||||
}
|
||||
|
||||
public String getApplicationId() {
|
||||
return applicationContext.getId();
|
||||
return bus.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,10 +42,12 @@ import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
*/
|
||||
public class VirtualPropertyResolver extends StrLookup<String> implements VirtualPropertyReplacer {
|
||||
|
||||
private StrSubstitutor substitutor;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private transient StrSubstitutor substitutor;
|
||||
|
||||
@Override
|
||||
public String lookup(String rhs) {
|
||||
public String lookup(final String rhs) {
|
||||
String resolved = null;
|
||||
|
||||
if ("now_ts".equalsIgnoreCase(rhs)) {
|
||||
@@ -57,7 +59,7 @@ public class VirtualPropertyResolver extends StrLookup<String> implements Virtua
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replace(String input) {
|
||||
public String replace(final String input) {
|
||||
if (substitutor == null) {
|
||||
substitutor = new StrSubstitutor(this, StrSubstitutor.DEFAULT_PREFIX, StrSubstitutor.DEFAULT_SUFFIX,
|
||||
StrSubstitutor.DEFAULT_ESCAPE);
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
|
||||
@@ -103,16 +103,6 @@
|
||||
<artifactId>allure-junit4</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -121,7 +111,7 @@
|
||||
<plugin>
|
||||
<groupId>com.ethlo.persistence.tools</groupId>
|
||||
<artifactId>eclipselink-maven-plugin</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<version>2.7.1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>modelgen</id>
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -50,19 +50,19 @@ public abstract class AbstractDsAssignmentStrategy {
|
||||
protected final TargetRepository targetRepository;
|
||||
protected final AfterTransactionCommitExecutor afterCommit;
|
||||
protected final ApplicationEventPublisher eventPublisher;
|
||||
protected final ApplicationContext applicationContext;
|
||||
protected final BusProperties bus;
|
||||
private final ActionRepository actionRepository;
|
||||
private final ActionStatusRepository actionStatusRepository;
|
||||
private final QuotaManagement quotaManagement;
|
||||
|
||||
AbstractDsAssignmentStrategy(final TargetRepository targetRepository,
|
||||
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
|
||||
final ApplicationContext applicationContext, final ActionRepository actionRepository,
|
||||
final BusProperties bus, final ActionRepository actionRepository,
|
||||
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement) {
|
||||
this.targetRepository = targetRepository;
|
||||
this.afterCommit = afterCommit;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.applicationContext = applicationContext;
|
||||
this.bus = bus;
|
||||
this.actionRepository = actionRepository;
|
||||
this.actionStatusRepository = actionStatusRepository;
|
||||
this.quotaManagement = quotaManagement;
|
||||
@@ -138,14 +138,12 @@ public abstract class AbstractDsAssignmentStrategy {
|
||||
return;
|
||||
}
|
||||
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant, distributionSetId,
|
||||
actions, applicationContext.getId(), actions.get(0).isMaintenanceWindowAvailable())));
|
||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant,
|
||||
distributionSetId, actions, bus.getId(), actions.get(0).isMaintenanceWindowAvailable())));
|
||||
}
|
||||
|
||||
protected void sendTargetUpdatedEvent(final JpaTarget target) {
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId())));
|
||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,8 +214,8 @@ public abstract class AbstractDsAssignmentStrategy {
|
||||
* the action id of the assignment
|
||||
*/
|
||||
void cancelAssignDistributionSetEvent(final Target target, final Long actionId) {
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new CancelTargetAssignmentEvent(target, actionId, applicationContext.getId())));
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new CancelTargetAssignmentEvent(target, actionId, bus.getId())));
|
||||
}
|
||||
|
||||
JpaAction createTargetAction(final Map<String, TargetWithActionType> targetsWithActionMap, final JpaTarget target,
|
||||
|
||||
@@ -147,7 +147,7 @@ public interface DistributionSetRepository
|
||||
@Override
|
||||
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
|
||||
@Query("SELECT d FROM JpaDistributionSet d WHERE d.id IN ?1")
|
||||
List<JpaDistributionSet> findAll(Iterable<Long> ids);
|
||||
List<JpaDistributionSet> findAllById(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
* Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety
|
||||
|
||||
@@ -86,5 +86,5 @@ public interface DistributionSetTagRepository
|
||||
@Override
|
||||
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
|
||||
@Query("SELECT d FROM JpaDistributionSetTag d WHERE d.id IN ?1")
|
||||
List<JpaDistributionSetTag> findAll(Iterable<Long> ids);
|
||||
List<JpaDistributionSetTag> findAllById(Iterable<Long> ids);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public interface DistributionSetTypeRepository
|
||||
*/
|
||||
@Override
|
||||
@Query("SELECT d FROM JpaDistributionSetType d WHERE d.id IN ?1")
|
||||
List<JpaDistributionSetType> findAll(Iterable<Long> ids);
|
||||
List<JpaDistributionSetType> findAllById(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
* Counts the {@link SoftwareModuleType}s which are associated with the
|
||||
|
||||
@@ -193,12 +193,12 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
|
||||
((JpaSoftwareModule) existing.getSoftwareModule()).removeArtifact(existing);
|
||||
softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule());
|
||||
localArtifactRepository.delete(id);
|
||||
localArtifactRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Artifact> get(final long id) {
|
||||
return Optional.ofNullable(localArtifactRepository.findOne(id));
|
||||
return Optional.ofNullable(localArtifactRepository.findById(id).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -226,7 +226,7 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
private void throwExceptionIfSoftwareModuleDoesNotExist(final Long swId) {
|
||||
if (!softwareModuleRepository.exists(swId)) {
|
||||
if (!softwareModuleRepository.existsById(swId)) {
|
||||
throw new EntityNotFoundException(SoftwareModule.class, swId);
|
||||
}
|
||||
}
|
||||
@@ -256,13 +256,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) {
|
||||
final SoftwareModule softwareModule = softwareModuleRepository.findOne(moduleId);
|
||||
|
||||
if (softwareModule == null) {
|
||||
LOG.debug("no software module with ID {} exists", moduleId);
|
||||
throw new EntityNotFoundException(SoftwareModule.class, moduleId);
|
||||
}
|
||||
return softwareModule;
|
||||
return softwareModuleRepository.findById(moduleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ import org.eclipse.hawkbit.repository.MaintenanceScheduleHelper;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.UpdateMode;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
|
||||
@@ -76,7 +76,7 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.T
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -94,7 +94,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -119,9 +118,6 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Autowired
|
||||
private TargetRepository targetRepository;
|
||||
|
||||
@Autowired
|
||||
private TargetManagement targetManagement;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleRepository softwareModuleRepository;
|
||||
|
||||
@@ -144,7 +140,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private BusProperties bus;
|
||||
|
||||
@Autowired
|
||||
private AfterTransactionCommitExecutor afterCommit;
|
||||
@@ -215,7 +211,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
return getPollingTime();
|
||||
}
|
||||
|
||||
return (new EventTimer(getPollingTime(), getMinPollingTime(), ChronoUnit.SECONDS))
|
||||
return new EventTimer(getPollingTime(), getMinPollingTime(), ChronoUnit.SECONDS)
|
||||
.timeToNextEvent(getMaintenanceWindowPollCount(), action.getMaintenanceWindowStartTime().orElse(null));
|
||||
}
|
||||
|
||||
@@ -324,13 +320,13 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
private void throwExceptionIfTargetDoesNotExist(final Long targetId) {
|
||||
if (!targetRepository.exists(targetId)) {
|
||||
if (!targetRepository.existsById(targetId)) {
|
||||
throw new EntityNotFoundException(Target.class, targetId);
|
||||
}
|
||||
}
|
||||
|
||||
private void throwExceptionIfSoftwareModuleDoesNotExist(final Long moduleId) {
|
||||
if (!softwareModuleRepository.exists(moduleId)) {
|
||||
if (!softwareModuleRepository.existsById(moduleId)) {
|
||||
throw new EntityNotFoundException(SoftwareModule.class, moduleId);
|
||||
}
|
||||
}
|
||||
@@ -372,21 +368,20 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
final Specification<JpaTarget> spec = (targetRoot, query, cb) -> cb
|
||||
.equal(targetRoot.get(JpaTarget_.controllerId), controllerId);
|
||||
|
||||
final JpaTarget target = targetRepository.findOne(spec);
|
||||
final Optional<JpaTarget> target = targetRepository.findOne(spec);
|
||||
|
||||
if (target == null) {
|
||||
if (!target.isPresent()) {
|
||||
final Target result = targetRepository.save((JpaTarget) entityFactory.target().create()
|
||||
.controllerId(controllerId).description("Plug and Play target: " + controllerId).name(controllerId)
|
||||
.status(TargetUpdateStatus.REGISTERED).lastTargetQuery(System.currentTimeMillis())
|
||||
.address(Optional.ofNullable(address).map(URI::toString).orElse(null)).build());
|
||||
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetPollEvent(result, applicationContext.getId())));
|
||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetPollEvent(result, bus.getId())));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return updateTargetStatus(target, address);
|
||||
return updateTargetStatus(target.get(), address);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -433,8 +428,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
|
||||
pollChunks.forEach(chunk -> {
|
||||
setLastTargetQuery(tenant, System.currentTimeMillis(), chunk);
|
||||
chunk.forEach(controllerId -> afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new TargetPollEvent(controllerId, tenant, applicationContext.getId()))));
|
||||
chunk.forEach(controllerId -> afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetPollEvent(controllerId, tenant, bus.getId()))));
|
||||
});
|
||||
|
||||
return null;
|
||||
@@ -468,7 +463,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
private static String formatQueryInStatementParams(final Collection<String> paramNames) {
|
||||
return "#" + Joiner.on(",#").join(paramNames);
|
||||
return "#" + String.join(",#", paramNames);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,8 +483,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
toUpdate.setAddress(address.toString());
|
||||
toUpdate.setLastTargetQuery(System.currentTimeMillis());
|
||||
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new TargetPollEvent(toUpdate, applicationContext.getId())));
|
||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetPollEvent(toUpdate, bus.getId())));
|
||||
|
||||
return targetRepository.save(toUpdate);
|
||||
}
|
||||
@@ -583,7 +577,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
private boolean actionIsNotActiveButIntermediateFeedbackStillAllowed(final ActionStatus actionStatus,
|
||||
final boolean actionActive) {
|
||||
return !actionActive && (repositoryProperties.isRejectActionStatusForClosedAction()
|
||||
|| (Status.ERROR.equals(actionStatus.getStatus()) || Status.FINISHED.equals(actionStatus.getStatus())));
|
||||
|| Status.ERROR.equals(actionStatus.getStatus()) || Status.FINISHED.equals(actionStatus.getStatus()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -615,12 +609,23 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
final Action savedAction = actionRepository.save(action);
|
||||
|
||||
if (controllerId != null) {
|
||||
targetManagement.requestControllerAttributes(controllerId);
|
||||
requestControllerAttributes(controllerId);
|
||||
}
|
||||
|
||||
return savedAction;
|
||||
}
|
||||
|
||||
private void requestControllerAttributes(final String controllerId) {
|
||||
final JpaTarget target = (JpaTarget) getByControllerId(controllerId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
|
||||
|
||||
target.setRequestControllerAttributes(true);
|
||||
|
||||
eventPublisher.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
|
||||
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
|
||||
JpaTarget.class.getName(), bus.getId()));
|
||||
}
|
||||
|
||||
private void handleErrorOnAction(final JpaAction mergedAction, final JpaTarget mergedTarget) {
|
||||
mergedAction.setActive(false);
|
||||
mergedAction.setStatus(Status.ERROR);
|
||||
@@ -823,12 +828,12 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
|
||||
@Override
|
||||
public Optional<Target> get(final long targetId) {
|
||||
return Optional.ofNullable(targetRepository.findOne(targetId));
|
||||
return targetRepository.findById(targetId).map(t -> (Target) t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ActionStatus> findActionStatusByAction(final Pageable pageReq, final long actionId) {
|
||||
if (!actionRepository.exists(actionId)) {
|
||||
if (!actionRepository.existsById(actionId)) {
|
||||
throw new EntityNotFoundException(Action.class, actionId);
|
||||
}
|
||||
|
||||
@@ -848,7 +853,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
? RepositoryConstants.MAX_ACTION_HISTORY_MSG_COUNT
|
||||
: messageCount;
|
||||
|
||||
final PageRequest pageable = new PageRequest(0, limit, new Sort(Direction.DESC, "occurredAt"));
|
||||
final PageRequest pageable = PageRequest.of(0, limit, new Sort(Direction.DESC, "occurredAt"));
|
||||
final Page<String> messages = actionStatusRepository.findMessagesByActionIdAndMessageNotLike(pageable, actionId,
|
||||
RepositoryConstants.SERVER_MESSAGE_PREFIX + "%");
|
||||
|
||||
@@ -860,7 +865,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
|
||||
@Override
|
||||
public Optional<SoftwareModule> getSoftwareModule(final long id) {
|
||||
return Optional.ofNullable(softwareModuleRepository.findOne(id));
|
||||
return softwareModuleRepository.findById(id).map(s -> (SoftwareModule) s);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -868,7 +873,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
final Collection<Long> moduleId) {
|
||||
|
||||
return softwareModuleMetadataRepository
|
||||
.findBySoftwareModuleIdInAndTargetVisible(new PageRequest(0, RepositoryConstants.MAX_META_DATA_COUNT),
|
||||
.findBySoftwareModuleIdInAndTargetVisible(PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT),
|
||||
moduleId, true)
|
||||
.getContent().stream().collect(Collectors.groupingBy(o -> (Long) o[0],
|
||||
Collectors.mapping(o -> (SoftwareModuleMetadata) o[1], Collectors.toList())));
|
||||
@@ -896,8 +901,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((controllerId == null) ? 0 : controllerId.hashCode());
|
||||
result = prime * result + ((tenant == null) ? 0 : tenant.hashCode());
|
||||
result = prime * result + (controllerId == null ? 0 : controllerId.hashCode());
|
||||
result = prime * result + (tenant == null ? 0 : tenant.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -980,7 +985,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
private void cancelAssignDistributionSetEvent(final JpaTarget target, final Long actionId) {
|
||||
afterCommit.afterCommit(() -> eventPublisher
|
||||
.publishEvent(new CancelTargetAssignmentEvent(target, actionId, applicationContext.getId())));
|
||||
afterCommit.afterCommit(
|
||||
() -> eventPublisher.publishEvent(new CancelTargetAssignmentEvent(target, actionId, bus.getId())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
@@ -88,7 +88,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
@@ -125,7 +124,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
private final TargetManagement targetManagement;
|
||||
private final AuditorAware<String> auditorProvider;
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
private final ApplicationContext applicationContext;
|
||||
private final BusProperties bus;
|
||||
private final AfterTransactionCommitExecutor afterCommit;
|
||||
private final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
private final PlatformTransactionManager txManager;
|
||||
@@ -141,7 +140,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
final DistributionSetRepository distributionSetRepository, final TargetRepository targetRepository,
|
||||
final ActionStatusRepository actionStatusRepository, final TargetManagement targetManagement,
|
||||
final AuditorAware<String> auditorProvider, final ApplicationEventPublisher eventPublisher,
|
||||
final ApplicationContext applicationContext, final AfterTransactionCommitExecutor afterCommit,
|
||||
final BusProperties bus, final AfterTransactionCommitExecutor afterCommit,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
|
||||
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware, final Database database) {
|
||||
@@ -153,14 +152,14 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
this.targetManagement = targetManagement;
|
||||
this.auditorProvider = auditorProvider;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.applicationContext = applicationContext;
|
||||
this.bus = bus;
|
||||
this.afterCommit = afterCommit;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
this.txManager = txManager;
|
||||
onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher,
|
||||
applicationContext, actionRepository, actionStatusRepository, quotaManagement);
|
||||
onlineDsAssignmentStrategy = new OnlineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher, bus,
|
||||
actionRepository, actionStatusRepository, quotaManagement);
|
||||
offlineDsAssignmentStrategy = new OfflineDsAssignmentStrategy(targetRepository, afterCommit, eventPublisher,
|
||||
applicationContext, actionRepository, actionStatusRepository, quotaManagement);
|
||||
bus, actionRepository, actionStatusRepository, quotaManagement);
|
||||
this.tenantConfigurationManagement = tenantConfigurationManagement;
|
||||
this.quotaManagement = quotaManagement;
|
||||
this.systemSecurityContext = systemSecurityContext;
|
||||
@@ -367,7 +366,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
private void setAssignedDistributionSetAndTargetUpdateStatus(final AbstractDsAssignmentStrategy assignmentStrategy,
|
||||
final JpaDistributionSet set, final List<List<Long>> targetIdsChunks) {
|
||||
final String currentUser = auditorProvider != null ? auditorProvider.getCurrentAuditor() : null;
|
||||
final String currentUser = auditorProvider.getCurrentAuditor().orElse(null);
|
||||
assignmentStrategy.updateTargetStatus(set, targetIdsChunks, currentUser);
|
||||
}
|
||||
|
||||
@@ -385,7 +384,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
private void createActionsStatus(final Collection<JpaAction> actions,
|
||||
final AbstractDsAssignmentStrategy assignmentStrategy, final String actionMessage) {
|
||||
actionStatusRepository
|
||||
.save(actions.stream().map(action -> assignmentStrategy.createActionStatus(action, actionMessage))
|
||||
.saveAll(actions.stream().map(action -> assignmentStrategy.createActionStatus(action, actionMessage))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@@ -493,7 +492,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
if (!CollectionUtils.isEmpty(targetAssignments)) {
|
||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant,
|
||||
distributionSetId, targetAssignments, applicationContext.getId(), maintenanceWindowAvailable)));
|
||||
distributionSetId, targetAssignments, bus.getId(), maintenanceWindowAvailable)));
|
||||
}
|
||||
|
||||
return rolloutGroupActions.getTotalElements();
|
||||
@@ -503,7 +502,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
private Page<Action> findActionsByRolloutAndRolloutGroupParent(final Long rolloutId,
|
||||
final Long rolloutGroupParentId, final int limit) {
|
||||
|
||||
final PageRequest pageRequest = new PageRequest(0, limit);
|
||||
final PageRequest pageRequest = PageRequest.of(0, limit);
|
||||
if (rolloutGroupParentId == null) {
|
||||
return actionRepository.findByRolloutIdAndRolloutGroupParentIsNullAndStatus(pageRequest, rolloutId,
|
||||
Action.Status.SCHEDULED);
|
||||
@@ -577,7 +576,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
@Override
|
||||
public Optional<Action> findAction(final long actionId) {
|
||||
return Optional.ofNullable(actionRepository.findOne(actionId));
|
||||
return actionRepository.findById(actionId).map(a -> (Action) a);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -644,7 +643,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
private void throwExceptionIfDistributionSetDoesNotExist(final Long dsId) {
|
||||
if (!distributionSetRepository.exists(dsId)) {
|
||||
if (!distributionSetRepository.existsById(dsId)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, dsId);
|
||||
}
|
||||
}
|
||||
@@ -666,7 +665,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
|
||||
@Override
|
||||
public Page<ActionStatus> findActionStatusByAction(final Pageable pageReq, final long actionId) {
|
||||
if (!actionRepository.exists(actionId)) {
|
||||
if (!actionRepository.existsById(actionId)) {
|
||||
throw new EntityNotFoundException(Action.class, actionId);
|
||||
}
|
||||
|
||||
@@ -690,7 +689,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
final CriteriaQuery<String> selMsgQuery = msgQuery.select(join);
|
||||
selMsgQuery.where(cb.equal(as.get(JpaActionStatus_.id), actionStatusId));
|
||||
|
||||
final List<String> result = entityManager.createQuery(selMsgQuery).setFirstResult(pageable.getOffset())
|
||||
final List<String> result = entityManager.createQuery(selMsgQuery).setFirstResult((int) pageable.getOffset())
|
||||
.setMaxResults(pageable.getPageSize()).getResultList().stream().collect(Collectors.toList());
|
||||
|
||||
return new PageImpl<>(result, pageable, totalCount);
|
||||
@@ -777,7 +776,7 @@ public class JpaDeploymentManagement implements DeploymentManagement {
|
||||
}
|
||||
|
||||
private static String formatInClause(final Collection<String> elements) {
|
||||
return "#" + Joiner.on(",#").join(elements);
|
||||
return "#" + String.join(",#", elements);
|
||||
}
|
||||
|
||||
protected ActionRepository getActionRepository() {
|
||||
|
||||
@@ -57,7 +57,7 @@ import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -105,7 +105,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
private final BusProperties bus;
|
||||
|
||||
private final TenantAware tenantAware;
|
||||
|
||||
@@ -126,7 +126,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
final DistributionSetMetadataRepository distributionSetMetadataRepository,
|
||||
final TargetFilterQueryRepository targetFilterQueryRepository, final ActionRepository actionRepository,
|
||||
final NoCountPagingRepository criteriaNoCountDao, final ApplicationEventPublisher eventPublisher,
|
||||
final ApplicationContext applicationContext, final TenantAware tenantAware,
|
||||
final BusProperties bus, final TenantAware tenantAware,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final SoftwareModuleRepository softwareModuleRepository,
|
||||
final DistributionSetTagRepository distributionSetTagRepository,
|
||||
@@ -142,7 +142,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
this.actionRepository = actionRepository;
|
||||
this.criteriaNoCountDao = criteriaNoCountDao;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.applicationContext = applicationContext;
|
||||
this.bus = bus;
|
||||
this.tenantAware = tenantAware;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
this.softwareModuleRepository = softwareModuleRepository;
|
||||
@@ -153,7 +153,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSet> getWithDetails(final long distid) {
|
||||
return Optional.ofNullable(distributionSetRepository.findOne(DistributionSetSpecification.byId(distid)));
|
||||
return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid))
|
||||
.map(d -> (DistributionSet) d);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -242,7 +243,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
private JpaSoftwareModule findSoftwareModuleAndThrowExceptionIfNotFound(final Long moduleId) {
|
||||
return Optional.ofNullable(softwareModuleRepository.findOne(moduleId))
|
||||
return softwareModuleRepository.findById(moduleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId));
|
||||
}
|
||||
|
||||
@@ -282,7 +283,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
afterCommit.afterCommit(() -> distributionSetIDs.forEach(
|
||||
dsId -> eventPublisher.publishEvent(new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(),
|
||||
dsId, JpaDistributionSet.class.getName(), applicationContext.getId()))));
|
||||
dsId, JpaDistributionSet.class.getName(), bus.getId()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -370,12 +371,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
* @return a single DistributionSet which is either installed or assigned to
|
||||
* a specific target or {@code null}.
|
||||
*/
|
||||
private DistributionSet findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
|
||||
private Optional<JpaDistributionSet> findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
|
||||
final DistributionSetFilter distributionSetFilter) {
|
||||
final List<Specification<JpaDistributionSet>> specList = buildDistributionSetSpecifications(
|
||||
distributionSetFilter);
|
||||
if (CollectionUtils.isEmpty(specList)) {
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
return distributionSetRepository.findOne(SpecificationsBuilder.combineWithAnd(specList));
|
||||
}
|
||||
@@ -400,12 +401,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
final DistributionSetFilter filterWithInstalledTargets = distributionSetFilterBuilder
|
||||
.setInstalledTargetId(assignedOrInstalled).setAssignedTargetId(null).build();
|
||||
final DistributionSet installedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
|
||||
final Optional<JpaDistributionSet> installedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
|
||||
filterWithInstalledTargets);
|
||||
|
||||
final DistributionSetFilter filterWithAssignedTargets = distributionSetFilterBuilder.setInstalledTargetId(null)
|
||||
.setAssignedTargetId(assignedOrInstalled).build();
|
||||
final DistributionSet assignedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
|
||||
final Optional<JpaDistributionSet> assignedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
|
||||
filterWithAssignedTargets);
|
||||
|
||||
final DistributionSetFilter dsFilterWithNoTargetLinked = distributionSetFilterBuilder.setInstalledTargetId(null)
|
||||
@@ -417,20 +418,20 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
final List<DistributionSet> resultSet = new ArrayList<>(findDistributionSetsByFilters.getContent());
|
||||
int orderIndex = 0;
|
||||
if (installedDS != null) {
|
||||
final boolean remove = resultSet.remove(installedDS);
|
||||
if (installedDS.isPresent()) {
|
||||
final boolean remove = resultSet.remove(installedDS.get());
|
||||
if (!remove) {
|
||||
resultSet.remove(resultSet.size() - 1);
|
||||
}
|
||||
resultSet.add(orderIndex, installedDS);
|
||||
resultSet.add(orderIndex, installedDS.get());
|
||||
orderIndex++;
|
||||
}
|
||||
if (assignedDS != null && !assignedDS.equals(installedDS)) {
|
||||
final boolean remove = resultSet.remove(assignedDS);
|
||||
if (assignedDS.isPresent() && !assignedDS.equals(installedDS)) {
|
||||
final boolean remove = resultSet.remove(assignedDS.get());
|
||||
if (!remove) {
|
||||
resultSet.remove(resultSet.size() - 1);
|
||||
}
|
||||
resultSet.add(orderIndex, assignedDS);
|
||||
resultSet.add(orderIndex, assignedDS.get());
|
||||
}
|
||||
|
||||
return new PageImpl<>(resultSet, pageable, findDistributionSetsByFilters.getTotalElements());
|
||||
@@ -440,7 +441,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
public Optional<DistributionSet> getByNameAndVersion(final String distributionName, final String version) {
|
||||
final Specification<JpaDistributionSet> spec = DistributionSetSpecification
|
||||
.equalsNameAndVersionIgnoreCase(distributionName, version);
|
||||
return Optional.ofNullable(distributionSetRepository.findOne(spec));
|
||||
return distributionSetRepository.findOne(spec).map(d -> (DistributionSet) d);
|
||||
|
||||
}
|
||||
|
||||
@@ -508,7 +509,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
() -> new EntityNotFoundException(DistributionSetMetadata.class, distributionSetId, key));
|
||||
|
||||
touch(metadata.getDistributionSet());
|
||||
distributionSetMetadataRepository.delete(metadata.getId());
|
||||
distributionSetMetadataRepository.deleteById(metadata.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -579,12 +580,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
public Optional<DistributionSetMetadata> getMetaDataByDistributionSetId(final long setId, final String key) {
|
||||
throwExceptionIfDistributionSetDoesNotExist(setId);
|
||||
|
||||
return Optional.ofNullable(distributionSetMetadataRepository.findOne(new DsMetadataCompositeKey(setId, key)));
|
||||
return distributionSetMetadataRepository.findById(new DsMetadataCompositeKey(setId, key))
|
||||
.map(dmd -> (DistributionSetMetadata) dmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSet> getByAction(final long actionId) {
|
||||
if (!actionRepository.exists(actionId)) {
|
||||
if (!actionRepository.existsById(actionId)) {
|
||||
throw new EntityNotFoundException(Action.class, actionId);
|
||||
}
|
||||
|
||||
@@ -676,7 +678,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
private void checkAndThrowIfDistributionSetMetadataAlreadyExists(final DsMetadataCompositeKey metadataId) {
|
||||
if (distributionSetMetadataRepository.exists(metadataId)) {
|
||||
if (distributionSetMetadataRepository.existsById(metadataId)) {
|
||||
throw new EntityAlreadyExistsException(
|
||||
"Metadata entry with key '" + metadataId.getKey() + "' already exists");
|
||||
}
|
||||
@@ -738,14 +740,14 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
private void throwExceptionIfDistributionSetDoesNotExist(final Long setId) {
|
||||
if (!distributionSetRepository.exists(setId)) {
|
||||
if (!distributionSetRepository.existsById(setId)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, setId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DistributionSet> get(final Collection<Long> ids) {
|
||||
return Collections.unmodifiableList(distributionSetRepository.findAll(ids));
|
||||
return Collections.unmodifiableList(distributionSetRepository.findAllById(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -757,7 +759,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
}
|
||||
|
||||
private void throwEntityNotFoundExceptionIfDsTagDoesNotExist(final Long tagId) {
|
||||
if (!distributionSetTagRepository.exists(tagId)) {
|
||||
if (!distributionSetTagRepository.existsById(tagId)) {
|
||||
throw new EntityNotFoundException(DistributionSetTag.class, tagId);
|
||||
}
|
||||
}
|
||||
@@ -791,12 +793,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSet> get(final long id) {
|
||||
return Optional.ofNullable(distributionSetRepository.findOne(id));
|
||||
return distributionSetRepository.findById(id).map(d -> (DistributionSet) d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(final long id) {
|
||||
return distributionSetRepository.exists(id);
|
||||
return distributionSetRepository.existsById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
|
||||
|
||||
@Override
|
||||
public Page<DistributionSetTag> findByDistributionSet(final Pageable pageable, final long setId) {
|
||||
if (!distributionSetRepository.exists(setId)) {
|
||||
if (!distributionSetRepository.existsById(setId)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, setId);
|
||||
}
|
||||
|
||||
@@ -165,24 +165,24 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final Collection<Long> ids) {
|
||||
final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAll(ids);
|
||||
final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAllById(ids);
|
||||
|
||||
if (setsFound.size() < ids.size()) {
|
||||
throw new EntityNotFoundException(DistributionSetTag.class, ids,
|
||||
setsFound.stream().map(DistributionSetTag::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
distributionSetTagRepository.delete(setsFound);
|
||||
distributionSetTagRepository.deleteAll(setsFound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DistributionSetTag> get(final Collection<Long> ids) {
|
||||
return Collections.unmodifiableList(distributionSetTagRepository.findAll(ids));
|
||||
return Collections.unmodifiableList(distributionSetTagRepository.findAllById(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSetTag> get(final long id) {
|
||||
return Optional.ofNullable(distributionSetTagRepository.findOne(id));
|
||||
return distributionSetTagRepository.findById(id).map(dst -> (DistributionSetTag) dst);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -190,12 +190,12 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final long id) {
|
||||
distributionSetTagRepository.delete(id);
|
||||
distributionSetTagRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(final long id) {
|
||||
return distributionSetTagRepository.exists(id);
|
||||
return distributionSetTagRepository.existsById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -99,9 +99,9 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
|
||||
checkDistributionSetTypeSoftwareModuleTypesIsAllowedToModify(update.getId());
|
||||
|
||||
update.getMandatory().ifPresent(
|
||||
mand -> softwareModuleTypeRepository.findAll(mand).forEach(type::addMandatoryModuleType));
|
||||
update.getOptional()
|
||||
.ifPresent(opt -> softwareModuleTypeRepository.findAll(opt).forEach(type::addOptionalModuleType));
|
||||
mand -> softwareModuleTypeRepository.findAllById(mand).forEach(type::addMandatoryModuleType));
|
||||
update.getOptional().ifPresent(
|
||||
opt -> softwareModuleTypeRepository.findAllById(opt).forEach(type::addOptionalModuleType));
|
||||
}
|
||||
|
||||
return distributionSetTypeRepository.save(type);
|
||||
@@ -113,7 +113,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public DistributionSetType assignMandatorySoftwareModuleTypes(final long dsTypeId,
|
||||
final Collection<Long> softwareModulesTypeIds) {
|
||||
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository.findAll(softwareModulesTypeIds);
|
||||
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
|
||||
.findAllById(softwareModulesTypeIds);
|
||||
|
||||
if (modules.size() < softwareModulesTypeIds.size()) {
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
|
||||
@@ -136,7 +137,8 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
|
||||
public DistributionSetType assignOptionalSoftwareModuleTypes(final long dsTypeId,
|
||||
final Collection<Long> softwareModulesTypeIds) {
|
||||
|
||||
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository.findAll(softwareModulesTypeIds);
|
||||
final Collection<JpaSoftwareModuleType> modules = softwareModuleTypeRepository
|
||||
.findAllById(softwareModulesTypeIds);
|
||||
|
||||
if (modules.size() < softwareModulesTypeIds.size()) {
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModulesTypeIds,
|
||||
@@ -206,13 +208,14 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSetType> getByName(final String name) {
|
||||
return Optional
|
||||
.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name)));
|
||||
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name))
|
||||
.map(dst -> (DistributionSetType) dst);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSetType> getByKey(final String key) {
|
||||
return Optional.ofNullable(distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key)));
|
||||
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key))
|
||||
.map(dst -> (DistributionSetType) dst);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -238,7 +241,7 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
|
||||
toDelete.setDeleted(true);
|
||||
distributionSetTypeRepository.save(toDelete);
|
||||
} else {
|
||||
distributionSetTypeRepository.delete(typeId);
|
||||
distributionSetTypeRepository.deleteById(typeId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,29 +294,29 @@ public class JpaDistributionSetTypeManagement implements DistributionSetTypeMana
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final Collection<Long> ids) {
|
||||
final List<JpaDistributionSetType> setsFound = distributionSetTypeRepository.findAll(ids);
|
||||
final List<JpaDistributionSetType> setsFound = distributionSetTypeRepository.findAllById(ids);
|
||||
|
||||
if (setsFound.size() < ids.size()) {
|
||||
throw new EntityNotFoundException(DistributionSetType.class, ids,
|
||||
setsFound.stream().map(DistributionSetType::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
distributionSetTypeRepository.delete(setsFound);
|
||||
distributionSetTypeRepository.deleteAll(setsFound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DistributionSetType> get(final Collection<Long> ids) {
|
||||
return Collections.unmodifiableList(distributionSetTypeRepository.findAll(ids));
|
||||
return Collections.unmodifiableList(distributionSetTypeRepository.findAllById(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSetType> get(final long id) {
|
||||
return Optional.ofNullable(distributionSetTypeRepository.findOne(id));
|
||||
return distributionSetTypeRepository.findById(id).map(dst -> (DistributionSetType) dst);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(final long id) {
|
||||
return distributionSetTypeRepository.exists(id);
|
||||
return distributionSetTypeRepository.existsById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
|
||||
@Override
|
||||
public Optional<RolloutGroup> get(final long rolloutGroupId) {
|
||||
return Optional.ofNullable(rolloutGroupRepository.findOne(rolloutGroupId));
|
||||
return rolloutGroupRepository.findById(rolloutGroupId).map(rg -> (RolloutGroup) rg);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,7 +128,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
}
|
||||
|
||||
private void throwEntityNotFoundExceptionIfRolloutDoesNotExist(final Long rolloutId) {
|
||||
if (!rolloutRepository.exists(rolloutId)) {
|
||||
if (!rolloutRepository.existsById(rolloutId)) {
|
||||
throw new EntityNotFoundException(Rollout.class, rolloutId);
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
.where(cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id),
|
||||
rolloutGroupId));
|
||||
final List<TargetWithActionStatus> targetWithActionStatus = entityManager.createQuery(multiselect)
|
||||
.setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList()
|
||||
.setFirstResult((int) pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList()
|
||||
.stream().map(o -> new TargetWithActionStatus((Target) o[0], (Action.Status) o[1]))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -285,7 +285,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
}
|
||||
|
||||
private void throwExceptionIfRolloutGroupDoesNotExist(final Long rolloutGroupId) {
|
||||
if (!rolloutGroupRepository.exists(rolloutGroupId)) {
|
||||
if (!rolloutGroupRepository.existsById(rolloutGroupId)) {
|
||||
throw new EntityNotFoundException(RolloutGroup.class, rolloutGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
@@ -149,20 +150,21 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
@Autowired
|
||||
private RolloutStatusCache rolloutStatusCache;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private final BusProperties bus;
|
||||
|
||||
private final Database database;
|
||||
|
||||
JpaRolloutManagement(final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final RolloutGroupManagement rolloutGroupManagement,
|
||||
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
||||
final ApplicationEventPublisher eventPublisher, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final PlatformTransactionManager txManager, final TenantAware tenantAware, final LockRegistry lockRegistry,
|
||||
final Database database, final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
||||
final BusProperties bus, final ApplicationEventPublisher eventPublisher,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
||||
final TenantAware tenantAware, final LockRegistry lockRegistry, final Database database,
|
||||
final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
||||
super(targetManagement, deploymentManagement, rolloutGroupManagement, distributionSetManagement, context,
|
||||
eventPublisher, virtualPropertyReplacer, txManager, tenantAware, lockRegistry, rolloutApprovalStrategy);
|
||||
this.database = database;
|
||||
this.bus = bus;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,7 +196,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
|
||||
@Override
|
||||
public Optional<Rollout> get(final long rolloutId) {
|
||||
return Optional.ofNullable(rolloutRepository.findOne(rolloutId));
|
||||
return rolloutRepository.findById(rolloutId).map(r -> (Rollout) r);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -337,7 +339,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
LOGGER.debug("handleCreateRollout called for rollout {}", rollout.getId());
|
||||
|
||||
final List<RolloutGroup> rolloutGroups = rolloutGroupManagement.findByRollout(
|
||||
new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id")),
|
||||
PageRequest.of(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id")),
|
||||
rollout.getId()).getContent();
|
||||
|
||||
int readyGroups = 0;
|
||||
@@ -431,7 +433,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
final String targetFilter, final long limit) {
|
||||
|
||||
return DeploymentHelper.runInNewTransaction(txManager, "assignTargetsToRolloutGroup", status -> {
|
||||
final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit));
|
||||
final PageRequest pageRequest = PageRequest.of(0, Math.toIntExact(limit));
|
||||
final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(),
|
||||
RolloutGroupStatus.READY, group);
|
||||
final Page<Target> targets = targetManagement.findByTargetFilterQueryAndNotInRolloutGroups(pageRequest,
|
||||
@@ -582,9 +584,11 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
|
||||
private Long createActionsForTargetsInNewTransaction(final long rolloutId, final long groupId, final int limit) {
|
||||
return DeploymentHelper.runInNewTransaction(txManager, "createActionsForTargets", status -> {
|
||||
final PageRequest pageRequest = new PageRequest(0, limit);
|
||||
final Rollout rollout = rolloutRepository.findOne(rolloutId);
|
||||
final RolloutGroup group = rolloutGroupRepository.findOne(groupId);
|
||||
final PageRequest pageRequest = PageRequest.of(0, limit);
|
||||
final Rollout rollout = rolloutRepository.findById(rolloutId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
|
||||
final RolloutGroup group = rolloutGroupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, groupId));
|
||||
|
||||
final DistributionSet distributionSet = rollout.getDistributionSet();
|
||||
final ActionType actionType = rollout.getActionType();
|
||||
@@ -832,9 +836,10 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
}
|
||||
}
|
||||
|
||||
private long executeFittingHandler(final Long rolloutId) {
|
||||
private long executeFittingHandler(final long rolloutId) {
|
||||
LOGGER.debug("handle rollout {}", rolloutId);
|
||||
final JpaRollout rollout = rolloutRepository.findOne(rolloutId);
|
||||
final JpaRollout rollout = rolloutRepository.findById(rolloutId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
|
||||
|
||||
switch (rollout.getStatus()) {
|
||||
case CREATING:
|
||||
@@ -882,7 +887,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final long rolloutId) {
|
||||
final JpaRollout jpaRollout = rolloutRepository.findOne(rolloutId);
|
||||
final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
|
||||
|
||||
if (jpaRollout == null) {
|
||||
throw new EntityNotFoundException(Rollout.class, rolloutId);
|
||||
@@ -945,7 +951,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
|
||||
afterCommit.afterCommit(() -> groupIds.forEach(rolloutGroupId -> eventPublisher
|
||||
.publishEvent(new RolloutGroupDeletedEvent(tenantAware.getCurrentTenant(), rolloutGroupId,
|
||||
JpaRolloutGroup.class.getName(), applicationContext.getId()))));
|
||||
JpaRolloutGroup.class.getName(), bus.getId()))));
|
||||
}
|
||||
|
||||
private void hardDeleteRollout(final JpaRollout rollout) {
|
||||
@@ -971,7 +977,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
}
|
||||
|
||||
private Slice<JpaAction> findScheduledActionsByRollout(final JpaRollout rollout) {
|
||||
return actionRepository.findByRolloutIdAndStatus(new PageRequest(0, TRANSACTION_ACTIONS), rollout.getId(),
|
||||
return actionRepository.findByRolloutIdAndStatus(PageRequest.of(0, TRANSACTION_ACTIONS), rollout.getId(),
|
||||
Status.SCHEDULED);
|
||||
}
|
||||
|
||||
@@ -1071,7 +1077,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
|
||||
@Override
|
||||
public boolean exists(final long rolloutId) {
|
||||
return rolloutRepository.exists(rolloutId);
|
||||
return rolloutRepository.existsById(rolloutId);
|
||||
}
|
||||
|
||||
private Map<Long, List<TotalTargetCountActionStatus>> getStatusCountItemForRollout(final List<Long> rollouts) {
|
||||
|
||||
@@ -180,7 +180,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
}
|
||||
|
||||
private void throwExceptionIfSoftwareModuleTypeDoesNotExist(final Long typeId) {
|
||||
if (!softwareModuleTypeRepository.exists(typeId)) {
|
||||
if (!softwareModuleTypeRepository.existsById(typeId)) {
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, typeId);
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
|
||||
@Override
|
||||
public Optional<SoftwareModule> get(final long id) {
|
||||
return Optional.ofNullable(softwareModuleRepository.findOne(id));
|
||||
return softwareModuleRepository.findById(id).map(sm -> (SoftwareModule) sm);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,7 +252,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
deleteGridFsArtifacts(swModule);
|
||||
|
||||
if (isUnassigned(swModule.getId())) {
|
||||
softwareModuleRepository.delete(swModule.getId());
|
||||
softwareModuleRepository.deleteById(swModule.getId());
|
||||
} else {
|
||||
assignedModuleIds.add(swModule.getId());
|
||||
}
|
||||
@@ -261,7 +261,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
if (!assignedModuleIds.isEmpty()) {
|
||||
String currentUser = null;
|
||||
if (auditorProvider != null) {
|
||||
currentUser = auditorProvider.getCurrentAuditor();
|
||||
currentUser = auditorProvider.getCurrentAuditor().orElse(null);
|
||||
}
|
||||
softwareModuleRepository.deleteSoftwareModule(System.currentTimeMillis(), currentUser,
|
||||
assignedModuleIds.toArray(new Long[0]));
|
||||
@@ -374,7 +374,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
// map result
|
||||
if (pageable.getOffset() < assignedSoftwareModules.size()) {
|
||||
assignedSoftwareModules
|
||||
.subList(pageable.getOffset(), Math.min(assignedSoftwareModules.size(), pageable.getPageSize()))
|
||||
.subList((int) pageable.getOffset(),
|
||||
Math.min(assignedSoftwareModules.size(), pageable.getPageSize()))
|
||||
.forEach(sw -> resultList.add(new AssignedSoftwareModule(sw, true)));
|
||||
}
|
||||
|
||||
@@ -401,7 +402,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
unassignedQuery.orderBy(cb.asc(unassignedRoot.get(JpaSoftwareModule_.name)),
|
||||
cb.asc(unassignedRoot.get(JpaSoftwareModule_.version)));
|
||||
final List<JpaSoftwareModule> unassignedSoftwareModules = entityManager.createQuery(unassignedQuery)
|
||||
.setFirstResult(Math.max(0, pageable.getOffset() - assignedSoftwareModules.size()))
|
||||
.setFirstResult((int) Math.max(0, pageable.getOffset() - assignedSoftwareModules.size()))
|
||||
.setMaxResults(pageSize).getResultList();
|
||||
// map result
|
||||
unassignedSoftwareModules.forEach(sw -> resultList.add(new AssignedSoftwareModule(sw, false)));
|
||||
@@ -456,7 +457,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
|
||||
@Override
|
||||
public Page<SoftwareModule> findByAssignedTo(final Pageable pageable, final long setId) {
|
||||
if (!distributionSetRepository.exists(setId)) {
|
||||
if (!distributionSetRepository.existsById(setId)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, setId);
|
||||
}
|
||||
|
||||
@@ -527,7 +528,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
|
||||
private void assertSoftwareModuleMetadataDoesNotExist(final Long moduleId,
|
||||
final JpaSoftwareModuleMetadataCreate md) {
|
||||
if (softwareModuleMetadataRepository.exists(new SwMetadataCompositeKey(moduleId, md.getKey()))) {
|
||||
if (softwareModuleMetadataRepository.existsById(new SwMetadataCompositeKey(moduleId, md.getKey()))) {
|
||||
throwMetadataKeyAlreadyExists(md.getKey());
|
||||
}
|
||||
}
|
||||
@@ -607,11 +608,11 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
key).orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, key));
|
||||
|
||||
touch(metadata.getSoftwareModule());
|
||||
softwareModuleMetadataRepository.delete(metadata.getId());
|
||||
softwareModuleMetadataRepository.deleteById(metadata.getId());
|
||||
}
|
||||
|
||||
private void throwExceptionIfSoftwareModuleDoesNotExist(final Long swId) {
|
||||
if (!softwareModuleRepository.exists(swId)) {
|
||||
if (!softwareModuleRepository.existsById(swId)) {
|
||||
throw new EntityNotFoundException(SoftwareModule.class, swId);
|
||||
}
|
||||
}
|
||||
@@ -654,7 +655,8 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
public Optional<SoftwareModuleMetadata> getMetaDataBySoftwareModuleId(final long moduleId, final String key) {
|
||||
throwExceptionIfSoftwareModuleDoesNotExist(moduleId);
|
||||
|
||||
return Optional.ofNullable(softwareModuleMetadataRepository.findOne(new SwMetadataCompositeKey(moduleId, key)));
|
||||
return softwareModuleMetadataRepository.findById(new SwMetadataCompositeKey(moduleId, key))
|
||||
.map(smmd -> (SoftwareModuleMetadata) smmd);
|
||||
}
|
||||
|
||||
private static void throwMetadataKeyAlreadyExists(final String metadataKey) {
|
||||
@@ -671,7 +673,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
|
||||
@Override
|
||||
public boolean exists(final long id) {
|
||||
return softwareModuleRepository.exists(id);
|
||||
return softwareModuleRepository.existsById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -680,7 +682,7 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
throwExceptionIfSoftwareModuleDoesNotExist(moduleId);
|
||||
|
||||
return convertMdPage(softwareModuleMetadataRepository.findBySoftwareModuleIdAndTargetVisible(
|
||||
new PageRequest(0, RepositoryConstants.MAX_META_DATA_COUNT), moduleId, true), pageable);
|
||||
PageRequest.of(0, RepositoryConstants.MAX_META_DATA_COUNT), moduleId, true), pageable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -168,29 +168,29 @@ public class JpaSoftwareModuleTypeManagement implements SoftwareModuleTypeManage
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final Collection<Long> ids) {
|
||||
final List<JpaSoftwareModuleType> setsFound = softwareModuleTypeRepository.findAll(ids);
|
||||
final List<JpaSoftwareModuleType> setsFound = softwareModuleTypeRepository.findAllById(ids);
|
||||
|
||||
if (setsFound.size() < ids.size()) {
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, ids,
|
||||
setsFound.stream().map(SoftwareModuleType::getId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
softwareModuleTypeRepository.delete(setsFound);
|
||||
softwareModuleTypeRepository.deleteAll(setsFound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SoftwareModuleType> get(final Collection<Long> ids) {
|
||||
return Collections.unmodifiableList(softwareModuleTypeRepository.findAll(ids));
|
||||
return Collections.unmodifiableList(softwareModuleTypeRepository.findAllById(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SoftwareModuleType> get(final long id) {
|
||||
return Optional.ofNullable(softwareModuleTypeRepository.findOne(id));
|
||||
return softwareModuleTypeRepository.findById(id).map(smt -> (SoftwareModuleType) smt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(final long id) {
|
||||
return softwareModuleTypeRepository.exists(id);
|
||||
return softwareModuleTypeRepository.existsById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.cache.TenancyCacheManager;
|
||||
import org.eclipse.hawkbit.repository.RolloutStatusCache;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantStatsManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
@@ -160,7 +161,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
}
|
||||
|
||||
private void usageStatsPerTenant(final SystemUsageReportWithTenants report) {
|
||||
final List<String> tenants = findTenants(new PageRequest(0, MAX_TENANTS_QUERY)).getContent();
|
||||
final List<String> tenants = findTenants(PageRequest.of(0, MAX_TENANTS_QUERY)).getContent();
|
||||
|
||||
tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
|
||||
report.addTenantData(systemStatsManagement.getStatsOfTenant());
|
||||
@@ -276,7 +277,8 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
public TenantMetaData updateTenantMetadata(final long defaultDsType) {
|
||||
final JpaTenantMetaData data = (JpaTenantMetaData) getTenantMetadata();
|
||||
|
||||
data.setDefaultDsType(distributionSetTypeRepository.findOne(defaultDsType));
|
||||
data.setDefaultDsType(distributionSetTypeRepository.findById(defaultDsType)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, defaultDsType)));
|
||||
|
||||
return tenantMetaDataRepository.save(data);
|
||||
}
|
||||
@@ -312,15 +314,19 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
|
||||
@Override
|
||||
public TenantMetaData getTenantMetadata(final long tenantId) {
|
||||
return tenantMetaDataRepository.findOne(tenantId);
|
||||
return tenantMetaDataRepository.findById(tenantId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TenantMetaData.class, tenantId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
// Exception squid:S2229 - calling findTenants without transaction is
|
||||
// intended in this case
|
||||
@SuppressWarnings("squid:S2229")
|
||||
public void forEachTenant(final Consumer<String> consumer) {
|
||||
|
||||
Page<String> tenants;
|
||||
Pageable query = new PageRequest(0, MAX_TENANTS_QUERY);
|
||||
Pageable query = PageRequest.of(0, MAX_TENANTS_QUERY);
|
||||
do {
|
||||
tenants = findTenants(query);
|
||||
tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.domain.Specifications;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
import org.springframework.retry.annotation.Backoff;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
@@ -99,11 +98,11 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final long targetFilterQueryId) {
|
||||
if (!targetFilterQueryRepository.exists(targetFilterQueryId)) {
|
||||
if (!targetFilterQueryRepository.existsById(targetFilterQueryId)) {
|
||||
throw new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId);
|
||||
}
|
||||
|
||||
targetFilterQueryRepository.delete(targetFilterQueryId);
|
||||
targetFilterQueryRepository.deleteById(targetFilterQueryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,7 +177,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
return targetFilterQueryRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
final Specifications<JpaTargetFilterQuery> specs = SpecificationsBuilder.combineWithAnd(specList);
|
||||
final Specification<JpaTargetFilterQuery> specs = SpecificationsBuilder.combineWithAnd(specList);
|
||||
return targetFilterQueryRepository.findAll(specs, pageable);
|
||||
}
|
||||
|
||||
@@ -189,7 +188,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme
|
||||
|
||||
@Override
|
||||
public Optional<TargetFilterQuery> get(final long targetFilterQueryId) {
|
||||
return Optional.ofNullable(targetFilterQueryRepository.findOne(targetFilterQueryId));
|
||||
return targetFilterQueryRepository.findById(targetFilterQueryId).map(tfq -> (TargetFilterQuery) tfq);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,7 +64,7 @@ import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -111,7 +111,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
private final BusProperties bus;
|
||||
|
||||
private final TenantAware tenantAware;
|
||||
|
||||
@@ -127,9 +127,9 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSetRepository distributionSetRepository,
|
||||
final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||
final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
|
||||
final ApplicationEventPublisher eventPublisher, final ApplicationContext applicationContext,
|
||||
final TenantAware tenantAware, final AfterTransactionCommitExecutor afterCommit,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final Database database) {
|
||||
final ApplicationEventPublisher eventPublisher, final BusProperties bus, final TenantAware tenantAware,
|
||||
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final Database database) {
|
||||
this.entityManager = entityManager;
|
||||
this.quotaManagement = quotaManagement;
|
||||
this.targetRepository = targetRepository;
|
||||
@@ -140,7 +140,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
this.targetTagRepository = targetTagRepository;
|
||||
this.criteriaNoCountDao = criteriaNoCountDao;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.applicationContext = applicationContext;
|
||||
this.bus = bus;
|
||||
this.tenantAware = tenantAware;
|
||||
this.afterCommit = afterCommit;
|
||||
this.virtualPropertyReplacer = virtualPropertyReplacer;
|
||||
@@ -190,13 +190,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
// TargetUpdatedEvent is not sent within the touch() method due to the
|
||||
// "lastModifiedAt" field being ignored in JpaTarget
|
||||
eventPublisher.publishEvent(new TargetUpdatedEvent(updatedTarget, applicationContext.getId()));
|
||||
eventPublisher.publishEvent(new TargetUpdatedEvent(updatedTarget, bus.getId()));
|
||||
|
||||
return createdMetadata;
|
||||
}
|
||||
|
||||
private void checkAndThrowIfTargetMetadataAlreadyExists(final TargetMetadataCompositeKey metadataId) {
|
||||
if (targetMetadataRepository.exists(metadataId)) {
|
||||
if (targetMetadataRepository.existsById(metadataId)) {
|
||||
throw new EntityAlreadyExistsException(
|
||||
"Metadata entry with key '" + metadataId.getKey() + "' already exists");
|
||||
}
|
||||
@@ -230,8 +230,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
// check if exists otherwise throw entity not found exception
|
||||
final JpaTargetMetadata updatedMetadata = (JpaTargetMetadata) getMetaDataByControllerId(controllerId,
|
||||
md.getKey())
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, controllerId, md.getKey()));
|
||||
md.getKey()).orElseThrow(
|
||||
() -> new EntityNotFoundException(TargetMetadata.class, controllerId, md.getKey()));
|
||||
updatedMetadata.setValue(md.getValue());
|
||||
// touch it to update the lock revision because we are modifying the
|
||||
// target indirectly
|
||||
@@ -239,7 +239,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final JpaTargetMetadata matadata = targetMetadataRepository.save(updatedMetadata);
|
||||
// target update event is set to ignore "lastModifiedAt" field so it is
|
||||
// not send automatically within the touch() method
|
||||
eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId()));
|
||||
eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId()));
|
||||
return matadata;
|
||||
}
|
||||
|
||||
@@ -252,10 +252,10 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetMetadata.class, controllerId, key));
|
||||
|
||||
final JpaTarget target = touch(controllerId);
|
||||
targetMetadataRepository.delete(metadata.getId());
|
||||
targetMetadataRepository.deleteById(metadata.getId());
|
||||
// target update event is set to ignore "lastModifiedAt" field so it is
|
||||
// not send automatically within the touch() method
|
||||
eventPublisher.publishEvent(new TargetUpdatedEvent(target, applicationContext.getId()));
|
||||
eventPublisher.publishEvent(new TargetUpdatedEvent(target, bus.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -294,7 +294,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Optional<TargetMetadata> getMetaDataByControllerId(final String controllerId, final String key) {
|
||||
final Long targetId = getByControllerIdAndThrowIfNotFound(controllerId).getId();
|
||||
|
||||
return Optional.ofNullable(targetMetadataRepository.findOne(new TargetMetadataCompositeKey(targetId, key)));
|
||||
return targetMetadataRepository.findById(new TargetMetadataCompositeKey(targetId, key))
|
||||
.map(t -> (TargetMetadata) t);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -344,7 +345,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final Collection<Long> targetIDs) {
|
||||
final List<JpaTarget> targets = targetRepository.findAll(targetIDs);
|
||||
final List<JpaTarget> targets = targetRepository.findAllById(targetIDs);
|
||||
|
||||
if (targets.size() < targetIDs.size()) {
|
||||
throw new EntityNotFoundException(Target.class, targetIDs,
|
||||
@@ -356,7 +357,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
afterCommit.afterCommit(() -> targets.forEach(target -> eventPublisher.publishEvent(
|
||||
new TargetDeletedEvent(tenantAware.getCurrentTenant(), target.getId(), target.getControllerId(),
|
||||
Optional.ofNullable(target.getAddress()).map(URI::toString).orElse(null),
|
||||
JpaTarget.class.getName(), applicationContext.getId()))));
|
||||
JpaTarget.class.getName(), bus.getId()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -366,7 +367,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public void deleteByControllerID(final String controllerID) {
|
||||
final Target target = getByControllerIdAndThrowIfNotFound(controllerID);
|
||||
|
||||
targetRepository.delete(target.getId());
|
||||
targetRepository.deleteById(target.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -394,7 +395,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
private void throwEntityNotFoundIfDsDoesNotExist(final Long distributionSetID) {
|
||||
if (!distributionSetRepository.exists(distributionSetID)) {
|
||||
if (!distributionSetRepository.existsById(distributionSetID)) {
|
||||
throw new EntityNotFoundException(DistributionSet.class, distributionSetID);
|
||||
}
|
||||
}
|
||||
@@ -452,7 +453,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
private List<Specification<JpaTarget>> buildSpecificationList(final FilterParams filterParams) {
|
||||
final List<Specification<JpaTarget>> specList = new ArrayList<>();
|
||||
if (filterParams.getFilterByStatus() != null && !filterParams.getFilterByStatus().isEmpty()) {
|
||||
if ((filterParams.getFilterByStatus() != null) && !filterParams.getFilterByStatus().isEmpty()) {
|
||||
specList.add(TargetSpecifications.hasTargetUpdateStatus(filterParams.getFilterByStatus()));
|
||||
}
|
||||
if (filterParams.getOverdueState() != null) {
|
||||
@@ -475,8 +476,8 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
private static boolean isHasTagsFilterActive(final FilterParams filterParams) {
|
||||
return filterParams.getSelectTargetWithNoTag() != null && (filterParams.getSelectTargetWithNoTag()
|
||||
|| (filterParams.getFilterByTagNames() != null && filterParams.getFilterByTagNames().length > 0));
|
||||
return ((filterParams.getSelectTargetWithNoTag() != null) && filterParams.getSelectTargetWithNoTag())
|
||||
|| ((filterParams.getFilterByTagNames() != null) && (filterParams.getFilterByTagNames().length > 0));
|
||||
}
|
||||
|
||||
private Slice<Target> findByCriteriaAPI(final Pageable pageable, final List<Specification<JpaTarget>> specList) {
|
||||
@@ -617,7 +618,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
// index of the array and
|
||||
// the 2nd contains the selectCase int value.
|
||||
final int pageSize = pageable.getPageSize();
|
||||
final List<JpaTarget> resultList = entityManager.createQuery(query).setFirstResult(pageable.getOffset())
|
||||
final List<JpaTarget> resultList = entityManager.createQuery(query).setFirstResult((int) pageable.getOffset())
|
||||
.setMaxResults(pageSize + 1).getResultList();
|
||||
final boolean hasNext = resultList.size() > pageSize;
|
||||
return new SliceImpl<>(Collections.unmodifiableList(resultList), pageable, hasNext);
|
||||
@@ -676,7 +677,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Page<Target> findByInRolloutGroupWithoutAction(final Pageable pageRequest, final long group) {
|
||||
if (!rolloutGroupRepository.exists(group)) {
|
||||
if (!rolloutGroupRepository.existsById(group)) {
|
||||
throw new EntityNotFoundException(RolloutGroup.class, group);
|
||||
}
|
||||
|
||||
@@ -733,7 +734,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
private void throwEntityNotFoundExceptionIfTagDoesNotExist(final Long tagId) {
|
||||
if (!targetTagRepository.exists(tagId)) {
|
||||
if (!targetTagRepository.existsById(tagId)) {
|
||||
throw new EntityNotFoundException(TargetTag.class, tagId);
|
||||
}
|
||||
}
|
||||
@@ -773,12 +774,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public Optional<Target> get(final long id) {
|
||||
return Optional.ofNullable(targetRepository.findOne(id));
|
||||
return targetRepository.findById(id).map(t -> (Target) t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> get(final Collection<Long> ids) {
|
||||
return Collections.unmodifiableList(targetRepository.findAll(ids));
|
||||
return Collections.unmodifiableList(targetRepository.findAllById(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -796,7 +797,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
eventPublisher.publishEvent(new TargetAttributesRequestedEvent(tenantAware.getCurrentTenant(), target.getId(),
|
||||
target.getControllerId(), target.getAddress() != null ? target.getAddress().toString() : null,
|
||||
JpaTarget.class.getName(), applicationContext.getId()));
|
||||
JpaTarget.class.getName(), bus.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -806,4 +807,14 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return target.isRequestControllerAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByControllerId(final String controllerId) {
|
||||
return targetRepository.existsByControllerId(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findByControllerAttributesRequested(final Pageable pageReq) {
|
||||
return targetRepository.findByRequestControllerAttributesIsTrue(pageReq);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class JpaTargetTagManagement implements TargetTagManagement {
|
||||
|
||||
@Override
|
||||
public Optional<TargetTag> get(final long id) {
|
||||
return Optional.ofNullable(targetTagRepository.findOne(id));
|
||||
return targetTagRepository.findById(id).map(tt -> (TargetTag) tt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -103,7 +103,7 @@ public class NoCountPagingRepository {
|
||||
|
||||
@Override
|
||||
protected Page<T> readPage(final TypedQuery<T> query, final Pageable pageable, final Specification<T> spec) {
|
||||
query.setFirstResult(pageable.getOffset());
|
||||
query.setFirstResult((int) pageable.getOffset());
|
||||
query.setMaxResults(pageable.getPageSize());
|
||||
|
||||
final List<T> content = query.getResultList();
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -43,10 +43,10 @@ public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||
|
||||
OfflineDsAssignmentStrategy(final TargetRepository targetRepository,
|
||||
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
|
||||
final ApplicationContext applicationContext, final ActionRepository actionRepository,
|
||||
final BusProperties bus, final ActionRepository actionRepository,
|
||||
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement) {
|
||||
super(targetRepository, afterCommit, eventPublisher, applicationContext, actionRepository,
|
||||
actionStatusRepository, quotaManagement);
|
||||
super(targetRepository, afterCommit, eventPublisher, bus, actionRepository, actionStatusRepository,
|
||||
quotaManagement);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -41,10 +41,10 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
||||
|
||||
OnlineDsAssignmentStrategy(final TargetRepository targetRepository,
|
||||
final AfterTransactionCommitExecutor afterCommit, final ApplicationEventPublisher eventPublisher,
|
||||
final ApplicationContext applicationContext, final ActionRepository actionRepository,
|
||||
final BusProperties bus, final ActionRepository actionRepository,
|
||||
final ActionStatusRepository actionStatusRepository, final QuotaManagement quotaManagement) {
|
||||
super(targetRepository, afterCommit, eventPublisher, applicationContext, actionRepository,
|
||||
actionStatusRepository, quotaManagement);
|
||||
super(targetRepository, afterCommit, eventPublisher, bus, actionRepository, actionStatusRepository,
|
||||
quotaManagement);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,6 +63,7 @@ import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleMetadataBuild
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetFilterQueryBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.event.JpaEventEntityManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitDefaultServiceExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
@@ -70,6 +71,10 @@ import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHol
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.rollout.RolloutScheduler;
|
||||
import org.eclipse.hawkbit.repository.jpa.rollout.condition.PauseRolloutGroupAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.rollout.condition.StartNextGroupRolloutGroupSuccessAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.rollout.condition.ThresholdRolloutGroupErrorCondition;
|
||||
import org.eclipse.hawkbit.repository.jpa.rollout.condition.ThresholdRolloutGroupSuccessCondition;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RsqlParserValidationOracle;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
@@ -87,16 +92,18 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.persistence.config.PersistenceUnitProperties;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.boot.orm.jpa.EntityScan;
|
||||
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
|
||||
import org.springframework.cloud.bus.BusProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -123,23 +130,71 @@ import com.google.common.collect.Maps;
|
||||
* General configuration for hawkBit's Repository.
|
||||
*
|
||||
*/
|
||||
@EnableJpaRepositories(basePackages = { "org.eclipse.hawkbit.repository.jpa" })
|
||||
@EnableJpaRepositories("org.eclipse.hawkbit.repository.jpa")
|
||||
@EnableTransactionManagement
|
||||
@EnableJpaAuditing
|
||||
@EnableAspectJAutoProxy
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@EnableScheduling
|
||||
@EnableRetry
|
||||
@EntityScan("org.eclipse.hawkbit.repository.jpa.model")
|
||||
@PropertySource("classpath:/hawkbit-jpa-defaults.properties")
|
||||
@Import({ RepositoryDefaultConfiguration.class })
|
||||
@Import({ RepositoryDefaultConfiguration.class, DataSourceAutoConfiguration.class,
|
||||
SystemManagementCacheKeyGenerator.class })
|
||||
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
|
||||
public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
|
||||
@Autowired
|
||||
RepositoryApplicationConfiguration(final DataSource dataSource, final JpaProperties jpaProperties,
|
||||
final ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider) {
|
||||
super(dataSource, jpaProperties, jtaTransactionManagerProvider);
|
||||
protected RepositoryApplicationConfiguration(final DataSource dataSource, final JpaProperties properties,
|
||||
final ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider,
|
||||
final ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
|
||||
super(dataSource, properties, jtaTransactionManagerProvider, transactionManagerCustomizers);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
PauseRolloutGroupAction pauseRolloutGroupAction(final RolloutManagement rolloutManagement,
|
||||
final RolloutGroupRepository rolloutGroupRepository, final SystemSecurityContext systemSecurityContext) {
|
||||
return new PauseRolloutGroupAction(rolloutManagement, rolloutGroupRepository, systemSecurityContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction(
|
||||
final RolloutGroupRepository rolloutGroupRepository, final DeploymentManagement deploymentManagement,
|
||||
final SystemSecurityContext systemSecurityContext) {
|
||||
return new StartNextGroupRolloutGroupSuccessAction(rolloutGroupRepository, deploymentManagement,
|
||||
systemSecurityContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ThresholdRolloutGroupErrorCondition thresholdRolloutGroupErrorCondition(final ActionRepository actionRepository) {
|
||||
return new ThresholdRolloutGroupErrorCondition(actionRepository);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ThresholdRolloutGroupSuccessCondition thresholdRolloutGroupSuccessCondition(
|
||||
final ActionRepository actionRepository) {
|
||||
return new ThresholdRolloutGroupSuccessCondition(actionRepository);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
SystemManagementCacheKeyGenerator systemManagementCacheKeyGenerator() {
|
||||
return new SystemManagementCacheKeyGenerator();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
AfterTransactionCommitDefaultServiceExecutor afterTransactionCommitDefaultServiceExecutor() {
|
||||
return new AfterTransactionCommitDefaultServiceExecutor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
NoCountPagingRepository noCountPagingRepository() {
|
||||
return new NoCountPagingRepository();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -163,7 +218,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ApplicationEventFilter applicationEventFilter(final RepositoryProperties repositoryProperties) {
|
||||
return e -> (e instanceof TargetPollEvent) && !repositoryProperties.isPublishTargetPollEvent();
|
||||
return e -> e instanceof TargetPollEvent && !repositoryProperties.isPublishTargetPollEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -389,16 +444,16 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
final DistributionSetMetadataRepository distributionSetMetadataRepository,
|
||||
final TargetFilterQueryRepository targetFilterQueryRepository, final ActionRepository actionRepository,
|
||||
final NoCountPagingRepository criteriaNoCountDao, final ApplicationEventPublisher eventPublisher,
|
||||
final ApplicationContext applicationContext, final TenantAware tenantAware,
|
||||
final BusProperties bus, final TenantAware tenantAware,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final SoftwareModuleRepository softwareModuleRepository,
|
||||
final DistributionSetTagRepository distributionSetTagRepository,
|
||||
final AfterTransactionCommitExecutor afterCommit, final JpaProperties properties) {
|
||||
return new JpaDistributionSetManagement(entityManager, distributionSetRepository, distributionSetTagManagement,
|
||||
systemManagement, distributionSetTypeManagement, quotaManagement, distributionSetMetadataRepository,
|
||||
targetFilterQueryRepository, actionRepository, criteriaNoCountDao, eventPublisher, applicationContext,
|
||||
tenantAware, virtualPropertyReplacer, softwareModuleRepository, distributionSetTagRepository,
|
||||
afterCommit, properties.getDatabase());
|
||||
targetFilterQueryRepository, actionRepository, criteriaNoCountDao, eventPublisher, bus, tenantAware,
|
||||
virtualPropertyReplacer, softwareModuleRepository, distributionSetTagRepository, afterCommit,
|
||||
properties.getDatabase());
|
||||
|
||||
}
|
||||
|
||||
@@ -455,13 +510,13 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
final DistributionSetRepository distributionSetRepository,
|
||||
final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||
final TargetTagRepository targetTagRepository, final NoCountPagingRepository criteriaNoCountDao,
|
||||
final ApplicationEventPublisher eventPublisher, final ApplicationContext applicationContext,
|
||||
final TenantAware tenantAware, final AfterTransactionCommitExecutor afterCommit,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final JpaProperties properties) {
|
||||
final ApplicationEventPublisher eventPublisher, final BusProperties bus, final TenantAware tenantAware,
|
||||
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final JpaProperties properties) {
|
||||
return new JpaTargetManagement(entityManager, quotaManagement, targetRepository, targetMetadataRepository,
|
||||
rolloutGroupRepository, distributionSetRepository, targetFilterQueryRepository, targetTagRepository,
|
||||
criteriaNoCountDao, eventPublisher, applicationContext, tenantAware, afterCommit,
|
||||
virtualPropertyReplacer, properties.getDatabase());
|
||||
criteriaNoCountDao, eventPublisher, bus, tenantAware, afterCommit, virtualPropertyReplacer,
|
||||
properties.getDatabase());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -565,12 +620,13 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
RolloutManagement rolloutManagement(final TargetManagement targetManagement,
|
||||
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
|
||||
final DistributionSetManagement distributionSetManagement, final ApplicationContext context,
|
||||
final ApplicationEventPublisher eventPublisher, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final PlatformTransactionManager txManager, final TenantAware tenantAware, final LockRegistry lockRegistry,
|
||||
final JpaProperties properties, final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
||||
final BusProperties bus, final ApplicationEventPublisher eventPublisher,
|
||||
final VirtualPropertyReplacer virtualPropertyReplacer, final PlatformTransactionManager txManager,
|
||||
final TenantAware tenantAware, final LockRegistry lockRegistry, final JpaProperties properties,
|
||||
final RolloutApprovalStrategy rolloutApprovalStrategy) {
|
||||
return new JpaRolloutManagement(targetManagement, deploymentManagement, rolloutGroupManagement,
|
||||
distributionSetManagement, context, eventPublisher, virtualPropertyReplacer, txManager, tenantAware,
|
||||
lockRegistry, properties.getDatabase(), rolloutApprovalStrategy);
|
||||
distributionSetManagement, context, bus, eventPublisher, virtualPropertyReplacer, txManager,
|
||||
tenantAware, lockRegistry, properties.getDatabase(), rolloutApprovalStrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -614,15 +670,15 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
final ActionRepository actionRepository, final DistributionSetRepository distributionSetRepository,
|
||||
final TargetRepository targetRepository, final ActionStatusRepository actionStatusRepository,
|
||||
final TargetManagement targetManagement, final AuditorAware<String> auditorProvider,
|
||||
final ApplicationEventPublisher eventPublisher, final ApplicationContext applicationContext,
|
||||
final ApplicationEventPublisher eventPublisher, final BusProperties bus,
|
||||
final AfterTransactionCommitExecutor afterCommit, final VirtualPropertyReplacer virtualPropertyReplacer,
|
||||
final PlatformTransactionManager txManager,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement, final QuotaManagement quotaManagement,
|
||||
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware,
|
||||
final JpaProperties properties) {
|
||||
return new JpaDeploymentManagement(entityManager, actionRepository, distributionSetRepository, targetRepository,
|
||||
actionStatusRepository, targetManagement, auditorProvider, eventPublisher, applicationContext,
|
||||
afterCommit, virtualPropertyReplacer, txManager, tenantConfigurationManagement, quotaManagement,
|
||||
actionStatusRepository, targetManagement, auditorProvider, eventPublisher, bus, afterCommit,
|
||||
virtualPropertyReplacer, txManager, tenantConfigurationManagement, quotaManagement,
|
||||
systemSecurityContext, tenantAware, properties.getDatabase());
|
||||
}
|
||||
|
||||
|
||||
@@ -84,5 +84,5 @@ public interface SoftwareModuleTypeRepository
|
||||
@Override
|
||||
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
|
||||
@Query("SELECT d FROM JpaSoftwareModuleType d WHERE d.id IN ?1")
|
||||
List<JpaSoftwareModuleType> findAll(Iterable<Long> ids);
|
||||
List<JpaSoftwareModuleType> findAllById(Iterable<Long> ids);
|
||||
}
|
||||
|
||||
@@ -15,13 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.cache.interceptor.SimpleKeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Implementation of {@link CurrentTenantCacheKeyGenerator}.
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class SystemManagementCacheKeyGenerator implements CurrentTenantCacheKeyGenerator {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -177,6 +177,18 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
*/
|
||||
Page<Target> findByAssignedDistributionSetId(Pageable pageable, Long setID);
|
||||
|
||||
/**
|
||||
* retrieves {@link Target}s where
|
||||
* {@link JpaTarget#isRequestControllerAttributes()}.
|
||||
*
|
||||
* @param pageReq
|
||||
* page parameter
|
||||
*
|
||||
* @return the found {@link Target}s
|
||||
*
|
||||
*/
|
||||
Page<Target> findByRequestControllerAttributesIsTrue(Pageable pageable);
|
||||
|
||||
/**
|
||||
* Counts number of targets with given distribution set Id.
|
||||
*
|
||||
@@ -209,7 +221,7 @@ public interface TargetRepository extends BaseEntityRepository<JpaTarget, Long>,
|
||||
@Override
|
||||
// Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
|
||||
@Query("SELECT t FROM JpaTarget t WHERE t.id IN ?1")
|
||||
List<JpaTarget> findAll(Iterable<Long> ids);
|
||||
List<JpaTarget> findAllById(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -102,7 +102,7 @@ public class AutoAssignChecker {
|
||||
public void check() {
|
||||
LOGGER.debug("Auto assigned check call");
|
||||
|
||||
final PageRequest pageRequest = new PageRequest(0, PAGE_SIZE);
|
||||
final PageRequest pageRequest = PageRequest.of(0, PAGE_SIZE);
|
||||
|
||||
final Page<TargetFilterQuery> filterQueries = targetFilterQueryManagement
|
||||
.findWithAutoAssignDS(pageRequest);
|
||||
@@ -176,7 +176,7 @@ public class AutoAssignChecker {
|
||||
private List<TargetWithActionType> getTargetsWithActionType(final String targetFilterQuery, final Long dsId,
|
||||
final int count) {
|
||||
final Page<Target> targets = targetManagement
|
||||
.findByTargetFilterQueryAndNonDS(new PageRequest(0, count), dsId, targetFilterQuery);
|
||||
.findByTargetFilterQueryAndNonDS(PageRequest.of(0, count), dsId, targetFilterQuery);
|
||||
|
||||
return targets.getContent().stream().map(t -> new TargetWithActionType(t.getControllerId(),
|
||||
Action.ActionType.FORCED, RepositoryModelConstants.NO_FORCE_TIME)).collect(Collectors.toList());
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
@@ -22,7 +21,6 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
* A Service which calls register runnable. This runnables will executed after a
|
||||
* successful spring transaction commit.The class is thread safe.
|
||||
*/
|
||||
@Service
|
||||
public class AfterTransactionCommitDefaultServiceExecutor extends TransactionSynchronizationAdapter
|
||||
implements AfterTransactionCommitExecutor {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AfterTransactionCommitDefaultServiceExecutor.class);
|
||||
|
||||
@@ -77,8 +77,8 @@ public class JpaTenantMetaData extends AbstractJpaBaseEntity implements TenantMe
|
||||
return defaultDsType;
|
||||
}
|
||||
|
||||
public void setDefaultDsType(final DistributionSetType defaultDsType) {
|
||||
this.defaultDsType = (JpaDistributionSetType) defaultDsType;
|
||||
public void setDefaultDsType(final JpaDistributionSetType defaultDsType) {
|
||||
this.defaultDsType = defaultDsType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,24 +15,25 @@ import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Error action evaluator which pauses the whole {@link Rollout} and sets the
|
||||
* current {@link RolloutGroup} to error.
|
||||
*/
|
||||
@Component("pauseRolloutGroupAction")
|
||||
public class PauseRolloutGroupAction implements RolloutGroupActionEvaluator {
|
||||
|
||||
@Autowired
|
||||
private RolloutManagement rolloutManagement;
|
||||
private final RolloutManagement rolloutManagement;
|
||||
|
||||
@Autowired
|
||||
private RolloutGroupRepository rolloutGroupRepository;
|
||||
private final RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
@Autowired
|
||||
private SystemSecurityContext systemSecurityContext;
|
||||
private final SystemSecurityContext systemSecurityContext;
|
||||
|
||||
public PauseRolloutGroupAction(final RolloutManagement rolloutManagement,
|
||||
final RolloutGroupRepository rolloutGroupRepository, final SystemSecurityContext systemSecurityContext) {
|
||||
this.rolloutManagement = rolloutManagement;
|
||||
this.rolloutGroupRepository = rolloutGroupRepository;
|
||||
this.systemSecurityContext = systemSecurityContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyExpression(final String expression) {
|
||||
|
||||
@@ -19,25 +19,26 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Success action which starts the next following {@link RolloutGroup}.
|
||||
*/
|
||||
@Component("startNextRolloutGroupAction")
|
||||
public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActionEvaluator {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(StartNextGroupRolloutGroupSuccessAction.class);
|
||||
|
||||
@Autowired
|
||||
private RolloutGroupRepository rolloutGroupRepository;
|
||||
private final RolloutGroupRepository rolloutGroupRepository;
|
||||
|
||||
@Autowired
|
||||
private DeploymentManagement deploymentManagement;
|
||||
private final DeploymentManagement deploymentManagement;
|
||||
|
||||
@Autowired
|
||||
private SystemSecurityContext systemSecurityContext;
|
||||
private final SystemSecurityContext systemSecurityContext;
|
||||
|
||||
public StartNextGroupRolloutGroupSuccessAction(final RolloutGroupRepository rolloutGroupRepository,
|
||||
final DeploymentManagement deploymentManagement, final SystemSecurityContext systemSecurityContext) {
|
||||
this.rolloutGroupRepository = rolloutGroupRepository;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
this.systemSecurityContext = systemSecurityContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyExpression(final String expression) {
|
||||
|
||||
@@ -16,19 +16,19 @@ import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Component("thresholdRolloutGroupErrorCondition")
|
||||
public class ThresholdRolloutGroupErrorCondition implements RolloutGroupConditionEvaluator {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ThresholdRolloutGroupErrorCondition.class);
|
||||
|
||||
@Autowired
|
||||
private ActionRepository actionRepository;
|
||||
private final ActionRepository actionRepository;
|
||||
|
||||
public ThresholdRolloutGroupErrorCondition(final ActionRepository actionRepository) {
|
||||
this.actionRepository = actionRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eval(final Rollout rollout, final RolloutGroup rolloutGroup, final String expression) {
|
||||
|
||||
@@ -14,19 +14,19 @@ import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Threshold to calculate if rollout group success condition is reached and the
|
||||
* next rollout group can get started.
|
||||
*/
|
||||
@Component("thresholdRolloutGroupSuccessCondition")
|
||||
public class ThresholdRolloutGroupSuccessCondition implements RolloutGroupConditionEvaluator {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ThresholdRolloutGroupSuccessCondition.class);
|
||||
|
||||
@Autowired
|
||||
private ActionRepository actionRepository;
|
||||
private final ActionRepository actionRepository;
|
||||
|
||||
public ThresholdRolloutGroupSuccessCondition(final ActionRepository actionRepository) {
|
||||
this.actionRepository = actionRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eval(final Rollout rollout, final RolloutGroup rolloutGroup, final String expression) {
|
||||
|
||||
@@ -159,6 +159,8 @@ public final class RSQLUtility {
|
||||
|
||||
private static final class RSQLSpecification<A extends Enum<A> & FieldNameProvider, T> implements Specification<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String rsql;
|
||||
private final Class<A> enumType;
|
||||
private final VirtualPropertyReplacer virtualPropertyReplacer;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle {
|
||||
context.setSyntaxErrorContext(errorContext);
|
||||
|
||||
try {
|
||||
targetManagement.findByRsql(new PageRequest(0, 1), rsqlQuery);
|
||||
targetManagement.findByRsql(PageRequest.of(0, 1), rsqlQuery);
|
||||
context.setSyntaxError(false);
|
||||
suggestionContext.getSuggestions().addAll(getLogicalOperatorSuggestion(rsqlQuery));
|
||||
} catch (final RSQLParameterSyntaxException | RSQLParserException ex) {
|
||||
|
||||
@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.domain.Specifications;
|
||||
|
||||
/**
|
||||
* Helper class to easily combine {@link Specification} instances.
|
||||
@@ -31,11 +30,11 @@ public final class SpecificationsBuilder {
|
||||
* all specification which will combine
|
||||
* @return <null> if the given specification list is empty
|
||||
*/
|
||||
public static <T> Specifications<T> combineWithAnd(final List<Specification<T>> specList) {
|
||||
public static <T> Specification<T> combineWithAnd(final List<Specification<T>> specList) {
|
||||
if (specList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Specifications<T> specs = Specifications.where(specList.get(0));
|
||||
Specification<T> specs = Specification.where(specList.get(0));
|
||||
for (final Specification<T> specification : specList.subList(1, specList.size())) {
|
||||
specs = specs.and(specification);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
|
||||
### JPA / Datasource - START
|
||||
spring.jpa.database=H2
|
||||
spring.jpa.show-sql=false
|
||||
@@ -17,8 +19,9 @@ spring.jpa.properties.eclipselink.logging.level=off
|
||||
spring.datasource.eclipselink.query-results-cache=false
|
||||
spring.datasource.eclipselink.cache.shared.default=false
|
||||
# Flyway DDL
|
||||
flyway.enabled=true
|
||||
flyway.initOnMigrate=true
|
||||
flyway.cleanDisabled=true
|
||||
flyway.sqlMigrationSuffix=${spring.jpa.database}.sql
|
||||
spring.flyway.enabled=true
|
||||
spring.flyway.init-on-migrate=true
|
||||
spring.flyway.clean-disabled=true
|
||||
spring.flyway.sql-migration-suffixes=${spring.jpa.database}.sql
|
||||
spring.flyway.table=schema_version
|
||||
### JPA / Datasource - END
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class AbstractRemoteEventTest extends AbstractJpaIntegrationTest
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
final BusJacksonAutoConfiguration autoConfiguration = new BusJacksonAutoConfiguration();
|
||||
this.jacksonMessageConverter = autoConfiguration.busJsonConverter();
|
||||
this.jacksonMessageConverter = autoConfiguration.busJsonConverter(null);
|
||||
ReflectionTestUtils.setField(jacksonMessageConverter, "packagesToScan",
|
||||
new String[] { "org.eclipse.hawkbit.repository.event.remote",
|
||||
ClassUtils.getPackageName(RemoteApplicationEvent.class) });
|
||||
|
||||
@@ -26,23 +26,25 @@ import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.test.TestConfiguration;
|
||||
import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.test.util.RolloutTestApprovalStrategy;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@SpringApplicationConfiguration(classes = {
|
||||
org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration.class })
|
||||
@ContextConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class,
|
||||
TestSupportBinderAutoConfiguration.class })
|
||||
@TestPropertySource(locations = "classpath:/jpa-test.properties")
|
||||
public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest {
|
||||
|
||||
protected static final String INVALID_TEXT_HTML = "</noscript><br><script>";
|
||||
protected static final String NOT_EXIST_ID = "1234";
|
||||
protected static final String NOT_EXIST_ID = "12345678990";
|
||||
protected static final long NOT_EXIST_IDL = Long.parseLong(NOT_EXIST_ID);
|
||||
|
||||
@PersistenceContext
|
||||
|
||||
@@ -82,8 +82,9 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
NOT_EXIST_IDL, "xxx", null, null, false, null, artifactSize)),
|
||||
"SoftwareModule");
|
||||
|
||||
verifyThrownExceptionBy(() -> artifactManagement.create(
|
||||
new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"), 1234L, "xxx", false, artifactSize)),
|
||||
verifyThrownExceptionBy(
|
||||
() -> artifactManagement.create(new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"),
|
||||
NOT_EXIST_IDL, "xxx", null, null, false, null, artifactSize)),
|
||||
"SoftwareModule");
|
||||
|
||||
verifyThrownExceptionBy(() -> artifactManagement.delete(NOT_EXIST_IDL), "Artifact");
|
||||
@@ -120,7 +121,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Artifact artifact1 = createArtifactForSoftwareModule("file1", sm.getId(), artifactSize, inputStream1);
|
||||
createArtifactForSoftwareModule("file11", sm.getId(), artifactSize, inputStream2);
|
||||
createArtifactForSoftwareModule("file12", sm.getId(), artifactSize, inputStream3);
|
||||
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize, inputStream4);
|
||||
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize,
|
||||
inputStream4);
|
||||
|
||||
assertThat(artifact1).isInstanceOf(Artifact.class);
|
||||
assertThat(artifact1.getSoftwareModule().getId()).isEqualTo(sm.getId());
|
||||
@@ -152,9 +154,9 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final long smID = softwareModuleRepository
|
||||
.save(new JpaSoftwareModule(osType, "smIllegalFilenameTest", "1.0", null, null)).getId();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(() -> artifactManagement.create(
|
||||
new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"), smID, illegalFilename, false,
|
||||
artifactSize)));
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
|
||||
() -> artifactManagement.create(new ArtifactUpload(IOUtils.toInputStream(artifactData, "UTF-8"), smID,
|
||||
illegalFilename, false, artifactSize)));
|
||||
assertThat(softwareModuleManagement.get(smID).get().getArtifacts()).hasSize(0);
|
||||
}
|
||||
|
||||
@@ -284,7 +286,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
final InputStream inputStream2 = new RandomGeneratedInputStream(artifactSize)) {
|
||||
|
||||
final Artifact artifact1 = createArtifactForSoftwareModule("file1", sm.getId(), artifactSize, inputStream1);
|
||||
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize, inputStream2);
|
||||
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize,
|
||||
inputStream2);
|
||||
|
||||
assertThat(artifactRepository.findAll()).hasSize(2);
|
||||
|
||||
@@ -292,16 +295,18 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(artifact2.getId()).isNotNull();
|
||||
assertThat(((JpaArtifact) artifact1).getSha1Hash()).isNotEqualTo(((JpaArtifact) artifact2).getSha1Hash());
|
||||
|
||||
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNotNull();
|
||||
assertThat(
|
||||
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNotNull();
|
||||
assertThat(
|
||||
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact2.getSha1Hash()))
|
||||
.isNotNull();
|
||||
|
||||
artifactManagement.delete(artifact1.getId());
|
||||
|
||||
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNull();
|
||||
assertThat(
|
||||
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNull();
|
||||
assertThat(
|
||||
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact2.getSha1Hash()))
|
||||
.isNotNull();
|
||||
@@ -331,22 +336,26 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
try (final InputStream inputStream1 = new ByteArrayInputStream(randomBytes);
|
||||
final InputStream inputStream2 = new ByteArrayInputStream(randomBytes)) {
|
||||
final Artifact artifact1 = createArtifactForSoftwareModule("file1", sm.getId(), artifactSize, inputStream1);
|
||||
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize, inputStream2);
|
||||
final Artifact artifact2 = createArtifactForSoftwareModule("file2", sm2.getId(), artifactSize,
|
||||
inputStream2);
|
||||
|
||||
assertThat(artifactRepository.findAll()).hasSize(2);
|
||||
assertThat(artifact1.getId()).isNotNull();
|
||||
assertThat(artifact2.getId()).isNotNull();
|
||||
assertThat(((JpaArtifact) artifact1).getSha1Hash()).isEqualTo(((JpaArtifact) artifact2).getSha1Hash());
|
||||
|
||||
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNotNull();
|
||||
assertThat(
|
||||
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNotNull();
|
||||
artifactManagement.delete(artifact1.getId());
|
||||
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNotNull();
|
||||
assertThat(
|
||||
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNotNull();
|
||||
|
||||
artifactManagement.delete(artifact2.getId());
|
||||
assertThat(binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNull();
|
||||
assertThat(
|
||||
binaryArtifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), artifact1.getSha1Hash()))
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -688,8 +688,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
// populated;
|
||||
final List<JpaTarget> allFoundTargets = targetRepository.findAll();
|
||||
|
||||
final List<JpaTarget> deployedTargetsFromDB = targetRepository.findAll(deployedTargetIDs);
|
||||
final List<JpaTarget> undeployedTargetsFromDB = targetRepository.findAll(undeployedTargetIDs);
|
||||
final List<JpaTarget> deployedTargetsFromDB = targetRepository.findAllById(deployedTargetIDs);
|
||||
final List<JpaTarget> undeployedTargetsFromDB = targetRepository.findAllById(undeployedTargetIDs);
|
||||
|
||||
// test that number of Targets
|
||||
assertThat(allFoundTargets.spliterator().getExactSizeIfKnown()).as("number of target is wrong")
|
||||
@@ -721,7 +721,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
+ "from target/controller. Expected behaviour is that in case of OK finished update the target will go to "
|
||||
+ "IN_SYNC status and installed DS is set to the assigned DS entry.")
|
||||
public void assignDistributionSetAndAddFinishedActionStatus() {
|
||||
final PageRequest pageRequest = new PageRequest(0, 100, Direction.ASC, ActionStatusFields.ID.getFieldName());
|
||||
final PageRequest pageRequest = PageRequest.of(0, 100, Direction.ASC, ActionStatusFields.ID.getFieldName());
|
||||
|
||||
final DeploymentResult deployResWithDsA = prepareComplexRepo("undep-A-T", 2, "dep-A-T", 4, 1, "dsA");
|
||||
final DeploymentResult deployResWithDsB = prepareComplexRepo("undep-B-T", 3, "dep-B-T", 5, 1, "dsB");
|
||||
@@ -815,7 +815,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
+ "if the DS is assigned to a target and a hard delete if the DS is not in use at all.")
|
||||
public void deleteDistributionSet() {
|
||||
|
||||
final PageRequest pageRequest = new PageRequest(0, 100, Direction.ASC, "id");
|
||||
final PageRequest pageRequest = PageRequest.of(0, 100, Direction.ASC, "id");
|
||||
|
||||
final String undeployedTargetPrefix = "undep-T";
|
||||
final int noOfUndeployedTargets = 2;
|
||||
|
||||
@@ -868,10 +868,10 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
final Page<DistributionSetMetadata> metadataOfDs1 = distributionSetManagement
|
||||
.findMetaDataByDistributionSetId(new PageRequest(0, 100), ds1.getId());
|
||||
.findMetaDataByDistributionSetId(PageRequest.of(0, 100), ds1.getId());
|
||||
|
||||
final Page<DistributionSetMetadata> metadataOfDs2 = distributionSetManagement
|
||||
.findMetaDataByDistributionSetId(new PageRequest(0, 100), ds2.getId());
|
||||
.findMetaDataByDistributionSetId(PageRequest.of(0, 100), ds2.getId());
|
||||
|
||||
assertThat(metadataOfDs1.getNumberOfElements()).isEqualTo(10);
|
||||
assertThat(metadataOfDs1.getTotalElements()).isEqualTo(10);
|
||||
|
||||
@@ -59,15 +59,12 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
@ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class, count = 0),
|
||||
@Expect(type = TargetTagUpdatedEvent.class, count = 0) })
|
||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID),
|
||||
"DistributionSetTag");
|
||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.delete(NOT_EXIST_ID), "DistributionSetTag");
|
||||
|
||||
verifyThrownExceptionBy(
|
||||
() -> distributionSetTagManagement.findByDistributionSet(PAGE, NOT_EXIST_IDL),
|
||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.findByDistributionSet(PAGE, NOT_EXIST_IDL),
|
||||
"DistributionSet");
|
||||
|
||||
verifyThrownExceptionBy(
|
||||
() -> distributionSetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
|
||||
verifyThrownExceptionBy(() -> distributionSetTagManagement.update(entityFactory.tag().update(NOT_EXIST_IDL)),
|
||||
"DistributionSetTag");
|
||||
}
|
||||
|
||||
@@ -82,16 +79,11 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
final Collection<DistributionSet> dsBCs = testdataFactory.createDistributionSets("DS-BC", 13);
|
||||
final Collection<DistributionSet> dsABCs = testdataFactory.createDistributionSets("DS-ABC", 9);
|
||||
|
||||
final DistributionSetTag tagA = distributionSetTagManagement
|
||||
.create(entityFactory.tag().create().name("A"));
|
||||
final DistributionSetTag tagB = distributionSetTagManagement
|
||||
.create(entityFactory.tag().create().name("B"));
|
||||
final DistributionSetTag tagC = distributionSetTagManagement
|
||||
.create(entityFactory.tag().create().name("C"));
|
||||
final DistributionSetTag tagX = distributionSetTagManagement
|
||||
.create(entityFactory.tag().create().name("X"));
|
||||
final DistributionSetTag tagY = distributionSetTagManagement
|
||||
.create(entityFactory.tag().create().name("Y"));
|
||||
final DistributionSetTag tagA = distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
|
||||
final DistributionSetTag tagB = distributionSetTagManagement.create(entityFactory.tag().create().name("B"));
|
||||
final DistributionSetTag tagC = distributionSetTagManagement.create(entityFactory.tag().create().name("C"));
|
||||
final DistributionSetTag tagX = distributionSetTagManagement.create(entityFactory.tag().create().name("X"));
|
||||
final DistributionSetTag tagY = distributionSetTagManagement.create(entityFactory.tag().create().name("Y"));
|
||||
|
||||
toggleTagAssignment(dsAs, tagA);
|
||||
toggleTagAssignment(dsBs, tagB);
|
||||
@@ -210,8 +202,8 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
assertThat(result.getAssigned()).isEqualTo(0);
|
||||
assertThat(result.getAssignedEntity()).isEmpty();
|
||||
assertThat(result.getUnassigned()).isEqualTo(40);
|
||||
assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.get(
|
||||
concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
||||
assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement
|
||||
.get(concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList())));
|
||||
assertThat(result.getDistributionSetTag()).isEqualTo(tag);
|
||||
|
||||
}
|
||||
@@ -219,15 +211,15 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
@Test
|
||||
@Description("Ensures that a created tag is persisted in the repository as defined.")
|
||||
public void createDistributionSetTag() {
|
||||
final Tag tag = distributionSetTagManagement.create(
|
||||
entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
|
||||
final Tag tag = distributionSetTagManagement
|
||||
.create(entityFactory.tag().create().name("kai1").description("kai2").colour("colour"));
|
||||
|
||||
assertThat(distributionSetTagRepository.findByNameEquals("kai1").get().getDescription()).as("wrong tag found")
|
||||
.isEqualTo("kai2");
|
||||
assertThat(distributionSetTagManagement.getByName("kai1").get().getColour()).as("wrong tag found")
|
||||
.isEqualTo("colour");
|
||||
assertThat(distributionSetTagManagement.get(tag.getId()).get().getColour())
|
||||
.as("wrong tag found").isEqualTo("colour");
|
||||
assertThat(distributionSetTagManagement.get(tag.getId()).get().getColour()).as("wrong tag found")
|
||||
.isEqualTo("colour");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,7 +230,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
final DistributionSetTag toDelete = tags.iterator().next();
|
||||
|
||||
for (final DistributionSet set : distributionSetRepository.findAll()) {
|
||||
assertThat(distributionSetRepository.findOne(set.getId()).getTags()).as("Wrong tag found")
|
||||
assertThat(distributionSetRepository.findById(set.getId()).get().getTags()).as("Wrong tag found")
|
||||
.contains(toDelete);
|
||||
}
|
||||
|
||||
@@ -246,12 +238,13 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
distributionSetTagManagement.delete(tags.iterator().next().getName());
|
||||
|
||||
// check
|
||||
assertThat(distributionSetTagRepository.findOne(toDelete.getId())).as("Deleted tag should be null").isNull();
|
||||
assertThat(distributionSetTagManagement.findAll(PAGE).getContent())
|
||||
.as("Wrong size of tags after deletion").hasSize(19);
|
||||
assertThat(distributionSetTagRepository.findById(toDelete.getId())).as("Deleted tag should be null")
|
||||
.isNotPresent();
|
||||
assertThat(distributionSetTagManagement.findAll(PAGE).getContent()).as("Wrong size of tags after deletion")
|
||||
.hasSize(19);
|
||||
|
||||
for (final DistributionSet set : distributionSetRepository.findAll()) {
|
||||
assertThat(distributionSetRepository.findOne(set.getId()).getTags()).as("Wrong found tags")
|
||||
assertThat(distributionSetRepository.findById(set.getId()).get().getTags()).as("Wrong found tags")
|
||||
.doesNotContain(toDelete);
|
||||
}
|
||||
}
|
||||
@@ -272,8 +265,7 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).")
|
||||
public void failedDuplicateDsTagNameExceptionAfterUpdate() {
|
||||
distributionSetTagManagement.create(entityFactory.tag().create().name("A"));
|
||||
final DistributionSetTag tag = distributionSetTagManagement
|
||||
.create(entityFactory.tag().create().name("B"));
|
||||
final DistributionSetTag tag = distributionSetTagManagement.create(entityFactory.tag().create().name("B"));
|
||||
|
||||
try {
|
||||
distributionSetTagManagement.update(entityFactory.tag().update(tag.getId()).name("A"));
|
||||
@@ -294,14 +286,13 @@ public class DistributionSetTagManagementTest extends AbstractJpaIntegrationTest
|
||||
final DistributionSetTag savedAssigned = tags.iterator().next();
|
||||
|
||||
// persist
|
||||
distributionSetTagManagement
|
||||
.update(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
|
||||
distributionSetTagManagement.update(entityFactory.tag().update(savedAssigned.getId()).name("test123"));
|
||||
|
||||
// check data
|
||||
assertThat(distributionSetTagManagement.findAll(PAGE).getContent())
|
||||
.as("Wrong size of ds tags").hasSize(tags.size());
|
||||
assertThat(distributionSetTagRepository.findOne(savedAssigned.getId()).getName()).as("Wrong ds tag found")
|
||||
.isEqualTo("test123");
|
||||
assertThat(distributionSetTagManagement.findAll(PAGE).getContent()).as("Wrong size of ds tags")
|
||||
.hasSize(tags.size());
|
||||
assertThat(distributionSetTagRepository.findById(savedAssigned.getId()).get().getName())
|
||||
.as("Wrong ds tag found").isEqualTo("test123");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DistributionSetTypeManagementTest extends AbstractJpaIntegrationTes
|
||||
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(), Arrays.asList(NOT_EXIST_IDL)),
|
||||
"SoftwareModuleType");
|
||||
|
||||
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(1234L,
|
||||
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(NOT_EXIST_IDL,
|
||||
Arrays.asList(osType.getId())), "DistributionSetType");
|
||||
verifyThrownExceptionBy(() -> distributionSetTypeManagement.assignOptionalSoftwareModuleTypes(
|
||||
testdataFactory.findOrCreateDistributionSetType("xxx", "xxx").getId(), Arrays.asList(NOT_EXIST_IDL)),
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutCreatedEvent;
|
||||
@@ -20,8 +22,6 @@ import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -1547,41 +1548,40 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Creating a rollout with approval role or approval engine disabled results in the rollout being in " +
|
||||
"READY state.")
|
||||
@Description("Creating a rollout with approval role or approval engine disabled results in the rollout being in "
|
||||
+ "READY state.")
|
||||
public void createdRolloutWithApprovalRoleOrApprovalDisabledTransitionsToReadyState() {
|
||||
approvalStrategy.setApprovalNeeded(false);
|
||||
final String successCondition = "50";
|
||||
final String errorCondition = "80";
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10,
|
||||
5, successCondition, errorCondition);
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 5, successCondition,
|
||||
errorCondition);
|
||||
assertThat(rollout.getStatus()).isEqualTo(Rollout.RolloutStatus.READY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Creating a rollout without approver role and approval enabled leads to transition to " +
|
||||
"WAITING_FOR_APPROVAL state.")
|
||||
@Description("Creating a rollout without approver role and approval enabled leads to transition to "
|
||||
+ "WAITING_FOR_APPROVAL state.")
|
||||
public void createdRolloutWithoutApprovalRoleTransitionsToWaitingForApprovalState() {
|
||||
approvalStrategy.setApprovalNeeded(true);
|
||||
final String successCondition = "50";
|
||||
final String errorCondition = "80";
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10,
|
||||
5, successCondition, errorCondition);
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 5, successCondition,
|
||||
errorCondition);
|
||||
assertThat(rollout.getStatus()).isEqualTo(Rollout.RolloutStatus.WAITING_FOR_APPROVAL);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Description("Approving a rollout leads to transition to READY state.")
|
||||
public void approvedRolloutTransitionsToReadyState() {
|
||||
approvalStrategy.setApprovalNeeded(true);
|
||||
final String successCondition = "50";
|
||||
final String errorCondition = "80";
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10,
|
||||
5, successCondition, errorCondition);
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 5, successCondition,
|
||||
errorCondition);
|
||||
assertThat(rollout.getStatus()).isEqualTo(Rollout.RolloutStatus.WAITING_FOR_APPROVAL);
|
||||
rolloutManagement.approveOrDeny(rollout.getId(), Rollout.ApprovalDecision.APPROVED);
|
||||
final Rollout resultingRollout = rolloutRepository.findOne(rollout.getId());
|
||||
final Rollout resultingRollout = rolloutRepository.findById(rollout.getId()).get();
|
||||
assertThat(resultingRollout.getStatus()).isEqualTo(Rollout.RolloutStatus.READY);
|
||||
}
|
||||
|
||||
@@ -1591,11 +1591,11 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
approvalStrategy.setApprovalNeeded(true);
|
||||
final String successCondition = "50";
|
||||
final String errorCondition = "80";
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10,
|
||||
5, successCondition, errorCondition);
|
||||
final Rollout rollout = createSimpleTestRolloutWithTargetsAndDistributionSet(10, 10, 5, successCondition,
|
||||
errorCondition);
|
||||
assertThat(rollout.getStatus()).isEqualTo(Rollout.RolloutStatus.WAITING_FOR_APPROVAL);
|
||||
rolloutManagement.approveOrDeny(rollout.getId(), Rollout.ApprovalDecision.DENIED);
|
||||
final Rollout resultingRollout = rolloutRepository.findOne(rollout.getId());
|
||||
final Rollout resultingRollout = rolloutRepository.findById(rollout.getId()).get();
|
||||
assertThat(resultingRollout.getStatus()).isEqualTo(RolloutStatus.APPROVAL_DENIED);
|
||||
}
|
||||
|
||||
@@ -1622,8 +1622,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
// verify
|
||||
final JpaRollout deletedRollout = rolloutRepository.findOne(createdRollout.getId());
|
||||
assertThat(deletedRollout).isNull();
|
||||
final Optional<JpaRollout> deletedRollout = rolloutRepository.findById(createdRollout.getId());
|
||||
assertThat(deletedRollout).isNotPresent();
|
||||
assertThat(rolloutGroupRepository.count()).isZero();
|
||||
assertThat(rolloutTargetGroupRepository.count()).isZero();
|
||||
}
|
||||
@@ -1663,7 +1663,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
// verify
|
||||
final JpaRollout deletedRollout = rolloutRepository.findOne(createdRollout.getId());
|
||||
final JpaRollout deletedRollout = rolloutRepository.findById(createdRollout.getId()).get();
|
||||
assertThat(deletedRollout).isNotNull();
|
||||
|
||||
assertThat(deletedRollout.getStatus()).isEqualTo(RolloutStatus.DELETED);
|
||||
|
||||
@@ -284,8 +284,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertArtifactNull(artifact1, artifact2);
|
||||
|
||||
// verify: meta data of artifact is deleted
|
||||
assertThat(artifactRepository.findOne(artifact1.getId())).isNull();
|
||||
assertThat(artifactRepository.findOne(artifact2.getId())).isNull();
|
||||
assertThat(artifactRepository.findById(artifact1.getId())).isNotPresent();
|
||||
assertThat(artifactRepository.findById(artifact2.getId())).isNotPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -315,8 +315,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertArtifactNull(artifact1, artifact2);
|
||||
|
||||
// verify: artifact meta data is still available
|
||||
assertThat(artifactRepository.findOne(artifact1.getId())).isNotNull();
|
||||
assertThat(artifactRepository.findOne(artifact2.getId())).isNotNull();
|
||||
assertThat(artifactRepository.findById(artifact1.getId())).isNotNull();
|
||||
assertThat(artifactRepository.findById(artifact2.getId())).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -355,8 +355,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertArtifactNull(artifact1, artifact2);
|
||||
|
||||
// verify: artifact meta data is still available
|
||||
assertThat(artifactRepository.findOne(artifact1.getId())).isNotNull();
|
||||
assertThat(artifactRepository.findOne(artifact2.getId())).isNotNull();
|
||||
assertThat(artifactRepository.findById(artifact1.getId())).isNotNull();
|
||||
assertThat(artifactRepository.findById(artifact2.getId())).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -398,10 +398,11 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertArtifactNotNull(artifactY);
|
||||
|
||||
// verify: meta data of artifactX is deleted
|
||||
assertThat(artifactRepository.findOne(artifactX.getId())).isNull();
|
||||
assertThat(artifactRepository.findById(artifactX.getId())).isNotPresent();
|
||||
|
||||
// verify: meta data of artifactY is not deleted
|
||||
assertThat(artifactRepository.findOne(artifactY.getId())).isNotNull();
|
||||
assertThat(artifactRepository.findById(artifactY.getId())).isPresent();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -459,7 +460,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertArtifactNull(artifactX, artifactY);
|
||||
|
||||
// verify: meta data of artifactX and artifactY is not deleted
|
||||
assertThat(artifactRepository.findOne(artifactY.getId())).isNotNull();
|
||||
assertThat(artifactRepository.findById(artifactY.getId())).isNotNull();
|
||||
}
|
||||
|
||||
private SoftwareModule createSoftwareModuleWithArtifacts(final SoftwareModuleType type, final String name,
|
||||
@@ -488,7 +489,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertArtifactNotNull(artifacts.toArray(new Artifact[artifacts.size()]));
|
||||
}
|
||||
|
||||
artifacts.forEach(artifact -> assertThat(artifactRepository.findOne(artifact.getId())).isNotNull());
|
||||
artifacts.forEach(artifact -> assertThat(artifactRepository.findById(artifact.getId())).isNotNull());
|
||||
return softwareModule;
|
||||
}
|
||||
|
||||
@@ -791,13 +792,15 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
ah = softwareModuleManagement.get(ah.getId()).get();
|
||||
|
||||
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(new PageRequest(0, 10), ah.getId())
|
||||
.getContent()).as("Contains the created metadata element")
|
||||
assertThat(
|
||||
softwareModuleManagement.findMetaDataBySoftwareModuleId(PageRequest.of(0, 10), ah.getId()).getContent())
|
||||
.as("Contains the created metadata element")
|
||||
.containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1));
|
||||
|
||||
softwareModuleManagement.deleteMetaData(ah.getId(), knownKey1);
|
||||
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(new PageRequest(0, 10), ah.getId())
|
||||
.getContent()).as("Metadata elemenets are").isEmpty();
|
||||
assertThat(
|
||||
softwareModuleManagement.findMetaDataBySoftwareModuleId(PageRequest.of(0, 10), ah.getId()).getContent())
|
||||
.as("Metadata elemenets are").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -835,10 +838,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
Page<SoftwareModuleMetadata> metadataSw1 = softwareModuleManagement
|
||||
.findMetaDataBySoftwareModuleId(new PageRequest(0, 100), sw1.getId());
|
||||
.findMetaDataBySoftwareModuleId(PageRequest.of(0, 100), sw1.getId());
|
||||
|
||||
Page<SoftwareModuleMetadata> metadataSw2 = softwareModuleManagement
|
||||
.findMetaDataBySoftwareModuleId(new PageRequest(0, 100), sw2.getId());
|
||||
.findMetaDataBySoftwareModuleId(PageRequest.of(0, 100), sw2.getId());
|
||||
|
||||
assertThat(metadataSw1.getNumberOfElements()).isEqualTo(metadataCountSw1);
|
||||
assertThat(metadataSw1.getTotalElements()).isEqualTo(metadataCountSw1);
|
||||
@@ -846,10 +849,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(metadataSw2.getNumberOfElements()).isEqualTo(metadataCountSw2);
|
||||
assertThat(metadataSw2.getTotalElements()).isEqualTo(metadataCountSw2);
|
||||
|
||||
metadataSw1 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(new PageRequest(0, 100),
|
||||
metadataSw1 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(PageRequest.of(0, 100),
|
||||
sw1.getId());
|
||||
|
||||
metadataSw2 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(new PageRequest(0, 100),
|
||||
metadataSw2 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(PageRequest.of(0, 100),
|
||||
sw2.getId());
|
||||
|
||||
assertThat(metadataSw1.getNumberOfElements()).isEqualTo(metadataCountSw1);
|
||||
|
||||
@@ -49,20 +49,18 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
|
||||
+ " by means of throwing EntityNotFoundException.")
|
||||
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 0) })
|
||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
verifyThrownExceptionBy(() -> softwareModuleTypeManagement.delete(NOT_EXIST_IDL),
|
||||
"SoftwareModuleType");
|
||||
verifyThrownExceptionBy(() -> softwareModuleTypeManagement.delete(NOT_EXIST_IDL), "SoftwareModuleType");
|
||||
|
||||
verifyThrownExceptionBy(
|
||||
() -> softwareModuleTypeManagement
|
||||
.update(entityFactory.softwareModuleType().update(1234L)),
|
||||
() -> softwareModuleTypeManagement.update(entityFactory.softwareModuleType().update(NOT_EXIST_IDL)),
|
||||
"SoftwareModuleType");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
|
||||
public void updateNothingResultsInUnchangedRepositoryForType() {
|
||||
final SoftwareModuleType created = softwareModuleTypeManagement.create(
|
||||
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
|
||||
final SoftwareModuleType created = softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
|
||||
|
||||
final SoftwareModuleType updated = softwareModuleTypeManagement
|
||||
.update(entityFactory.softwareModuleType().update(created.getId()));
|
||||
@@ -75,8 +73,8 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
|
||||
@Test
|
||||
@Description("Calling update for changed fields results in change in the repository.")
|
||||
public void updateSoftareModuleTypeFieldsToNewValue() {
|
||||
final SoftwareModuleType created = softwareModuleTypeManagement.create(
|
||||
entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
|
||||
final SoftwareModuleType created = softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("test-key").name("test-name"));
|
||||
|
||||
final SoftwareModuleType updated = softwareModuleTypeManagement.update(
|
||||
entityFactory.softwareModuleType().update(created.getId()).description("changed").colour("changed"));
|
||||
@@ -106,39 +104,34 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
|
||||
@Test
|
||||
@Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).")
|
||||
public void deleteAssignedAndUnassignedSoftwareModuleTypes() {
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType,
|
||||
runtimeType, appType);
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType);
|
||||
|
||||
SoftwareModuleType type = softwareModuleTypeManagement.create(
|
||||
entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle"));
|
||||
SoftwareModuleType type = softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle"));
|
||||
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType,
|
||||
runtimeType, appType, type);
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType, runtimeType, appType, type);
|
||||
|
||||
// delete unassigned
|
||||
softwareModuleTypeManagement.delete(type.getId());
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType,
|
||||
runtimeType, appType);
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType);
|
||||
assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType,
|
||||
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType);
|
||||
|
||||
type = softwareModuleTypeManagement.create(
|
||||
entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2"));
|
||||
type = softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2"));
|
||||
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType,
|
||||
runtimeType, appType, type);
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(4).contains(osType, runtimeType, appType, type);
|
||||
|
||||
softwareModuleManagement.create(
|
||||
entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0"));
|
||||
softwareModuleManagement
|
||||
.create(entityFactory.softwareModule().create().type(type).name("Test SM").version("1.0"));
|
||||
|
||||
// delete assigned
|
||||
softwareModuleTypeManagement.delete(type.getId());
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType,
|
||||
runtimeType, appType);
|
||||
assertThat(softwareModuleTypeManagement.findAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType);
|
||||
|
||||
assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains((JpaSoftwareModuleType) osType,
|
||||
(JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType,
|
||||
softwareModuleTypeRepository.findOne(type.getId()));
|
||||
softwareModuleTypeRepository.findById(type.getId()).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,21 +140,19 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
|
||||
testdataFactory.createSoftwareModuleOs();
|
||||
final SoftwareModuleType found = softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
softwareModuleTypeManagement.create(
|
||||
entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
|
||||
softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("thetype2").name("anothername"));
|
||||
|
||||
assertThat(softwareModuleTypeManagement.getByName("thename").get())
|
||||
.as("Type with given name").isEqualTo(found);
|
||||
assertThat(softwareModuleTypeManagement.getByName("thename").get()).as("Type with given name").isEqualTo(found);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that it is not possible to create a type that alrady exists.")
|
||||
public void createSoftwareModuleTypeFailsWithExistingEntity() {
|
||||
softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
try {
|
||||
softwareModuleTypeManagement.create(
|
||||
entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
fail("should not have worked as module type already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
|
||||
@@ -172,11 +163,10 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
|
||||
@Test
|
||||
@Description("Verfies that it is not possible to create a list of types where one already exists.")
|
||||
public void createSoftwareModuleTypesFailsWithExistingEntity() {
|
||||
softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create().key("thetype").name("thename"));
|
||||
try {
|
||||
softwareModuleTypeManagement.create(
|
||||
Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
|
||||
softwareModuleTypeManagement
|
||||
.create(Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
|
||||
entityFactory.softwareModuleType().create().key("anothertype").name("anothername")));
|
||||
fail("should not have worked as module type already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
@@ -188,8 +178,8 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Verifies that the creation of a softwareModuleType is failing because of invalid max assignment")
|
||||
public void createSoftwareModuleTypesFailsWithInvalidMaxAssignment() {
|
||||
try {
|
||||
softwareModuleTypeManagement.create(
|
||||
entityFactory.softwareModuleType().create().key("type").name("name").maxAssignments(0));
|
||||
softwareModuleTypeManagement
|
||||
.create(entityFactory.softwareModuleType().create().key("type").name("name").maxAssignments(0));
|
||||
fail("should not have worked as max assignment is invalid. Should be greater than 0.");
|
||||
} catch (final ConstraintViolationException e) {
|
||||
|
||||
@@ -199,13 +189,12 @@ public class SoftwareModuleTypeManagementTest extends AbstractJpaIntegrationTest
|
||||
@Test
|
||||
@Description("Verfies that multiple types are created as requested.")
|
||||
public void createMultipleSoftwareModuleTypes() {
|
||||
final List<SoftwareModuleType> created = softwareModuleTypeManagement.create(
|
||||
Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
|
||||
final List<SoftwareModuleType> created = softwareModuleTypeManagement
|
||||
.create(Arrays.asList(entityFactory.softwareModuleType().create().key("thetype").name("thename"),
|
||||
entityFactory.softwareModuleType().create().key("thetype2").name("thename2")));
|
||||
|
||||
assertThat(created.size()).as("Number of created types").isEqualTo(2);
|
||||
assertThat(softwareModuleTypeManagement.count()).as("Number of types in repository")
|
||||
.isEqualTo(5);
|
||||
assertThat(softwareModuleTypeManagement.count()).as("Number of types in repository").isEqualTo(5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
verifyThrownExceptionBy(
|
||||
() -> targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL),
|
||||
"DistributionSet");
|
||||
verifyThrownExceptionBy(() -> targetFilterQueryManagement.updateAutoAssignDS(1234L, set.getId()),
|
||||
verifyThrownExceptionBy(() -> targetFilterQueryManagement.updateAutoAssignDS(NOT_EXIST_IDL, set.getId()),
|
||||
"TargetFilterQuery");
|
||||
verifyThrownExceptionBy(
|
||||
() -> targetFilterQueryManagement.updateAutoAssignDS(targetFilterQuery.getId(), NOT_EXIST_IDL),
|
||||
@@ -123,7 +123,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
entityFactory.targetFilterQuery().create().name("someOtherFilter").query("name==PendingTargets002"));
|
||||
|
||||
final List<TargetFilterQuery> results = targetFilterQueryManagement
|
||||
.findByRsql(new PageRequest(0, 10), "name==" + filterName).getContent();
|
||||
.findByRsql(PageRequest.of(0, 10), "name==" + filterName).getContent();
|
||||
assertEquals("Search result should have 1 result", 1, results.size());
|
||||
assertEquals("Retrieved newly created custom target filter", targetFilterQuery, results.get(0));
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
@Description("Test searching a target filter query with an invalid filter.")
|
||||
public void searchTargetFilterQueryInvalidField() {
|
||||
// Should throw an exception
|
||||
targetFilterQueryManagement.findByRsql(new PageRequest(0, 10), "unknownField==testValue").getContent();
|
||||
targetFilterQueryManagement.findByRsql(PageRequest.of(0, 10), "unknownField==testValue").getContent();
|
||||
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
assertEquals(4L, targetFilterQueryManagement.count());
|
||||
|
||||
// check if find works
|
||||
Page<TargetFilterQuery> tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(new PageRequest(0, 500),
|
||||
Page<TargetFilterQuery> tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(PageRequest.of(0, 500),
|
||||
distributionSet.getId(), null);
|
||||
assertThat(1L).as("Target filter query").isEqualTo(tfqList.getTotalElements());
|
||||
|
||||
@@ -325,22 +325,22 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest
|
||||
targetFilterQueryManagement.updateAutoAssignDS(tfq2.getId(), distributionSet.getId());
|
||||
|
||||
// check if find works for two
|
||||
tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(new PageRequest(0, 500),
|
||||
distributionSet.getId(), null);
|
||||
tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(PageRequest.of(0, 500), distributionSet.getId(),
|
||||
null);
|
||||
assertThat(2L).as("Target filter query count").isEqualTo(tfqList.getTotalElements());
|
||||
Iterator<TargetFilterQuery> iterator = tfqList.iterator();
|
||||
assertEquals("Returns correct target filter query 1", tfq.getId(), iterator.next().getId());
|
||||
assertEquals("Returns correct target filter query 2", tfq2.getId(), iterator.next().getId());
|
||||
|
||||
// check if find works with name filter
|
||||
tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(new PageRequest(0, 500),
|
||||
distributionSet.getId(), "name==" + filterName);
|
||||
tfqList = targetFilterQueryManagement.findByAutoAssignDSAndRsql(PageRequest.of(0, 500), distributionSet.getId(),
|
||||
"name==" + filterName);
|
||||
assertThat(1L).as("Target filter query count").isEqualTo(tfqList.getTotalElements());
|
||||
|
||||
assertEquals("Returns correct target filter query", tfq2.getId(), tfqList.iterator().next().getId());
|
||||
|
||||
// check if find works for all with auto assign DS
|
||||
tfqList = targetFilterQueryManagement.findWithAutoAssignDS(new PageRequest(0, 500));
|
||||
tfqList = targetFilterQueryManagement.findWithAutoAssignDS(PageRequest.of(0, 500));
|
||||
assertThat(2L).as("Target filter query count").isEqualTo(tfqList.getTotalElements());
|
||||
iterator = tfqList.iterator();
|
||||
assertEquals("Returns correct target filter query 1", tfq.getId(), iterator.next().getId());
|
||||
|
||||
@@ -419,8 +419,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
target = createTargetWithAttributes("4711");
|
||||
assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(1);
|
||||
assertThat(targetManagement.existsByControllerId("4711")).isTrue();
|
||||
targetManagement.delete(Collections.singletonList(target.getId()));
|
||||
assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(0);
|
||||
assertThat(targetManagement.existsByControllerId("4711")).isFalse();
|
||||
|
||||
final List<Long> targets = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -664,7 +666,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
targetManagement.delete(targetsIdsToDelete);
|
||||
|
||||
final List<Target> targetsLeft = targetManagement.findAll(new PageRequest(0, 200)).getContent();
|
||||
final List<Target> targetsLeft = targetManagement.findAll(PageRequest.of(0, 200)).getContent();
|
||||
assertThat(firstList.spliterator().getExactSizeIfKnown() - numberToDelete).as("Size of split list")
|
||||
.isEqualTo(targetsLeft.spliterator().getExactSizeIfKnown());
|
||||
|
||||
@@ -905,12 +907,18 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Verify that the flag for requesting controller attributes is set correctly.")
|
||||
public void verifyRequestControllerAttributes() {
|
||||
final String knownTargetId = "KnownControllerId";
|
||||
createTargetWithAttributes(knownTargetId);
|
||||
final String knownControllerId = "KnownControllerId";
|
||||
final Target target = createTargetWithAttributes(knownControllerId);
|
||||
|
||||
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isFalse();
|
||||
targetManagement.requestControllerAttributes(knownTargetId);
|
||||
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isTrue();
|
||||
assertThat(targetManagement.findByControllerAttributesRequested(PAGE)).isEmpty();
|
||||
assertThat(targetManagement.isControllerAttributesRequested(knownControllerId)).isFalse();
|
||||
|
||||
targetManagement.requestControllerAttributes(knownControllerId);
|
||||
final Target updated = targetManagement.getByControllerID(knownControllerId).get();
|
||||
|
||||
assertThat(target.isRequestControllerAttributes()).isFalse();
|
||||
assertThat(targetManagement.findByControllerAttributesRequested(PAGE).getContent()).contains(updated);
|
||||
assertThat(targetManagement.isControllerAttributesRequested(knownControllerId)).isTrue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -245,7 +245,7 @@ public class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetTagManagement.findByTarget(PAGE, target.getControllerId()).getContent())
|
||||
.doesNotContain(toDelete);
|
||||
}
|
||||
assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull();
|
||||
assertThat(targetTagRepository.findById(toDelete.getId())).as("No tag should be found").isNotPresent();
|
||||
assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(19);
|
||||
}
|
||||
|
||||
@@ -262,9 +262,9 @@ public class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// check data
|
||||
assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(tags.size());
|
||||
assertThat(targetTagRepository.findOne(savedAssigned.getId()).getName()).as("wrong target tag is saved")
|
||||
assertThat(targetTagRepository.findById(savedAssigned.getId()).get().getName()).as("wrong target tag is saved")
|
||||
.isEqualTo("test123");
|
||||
assertThat(targetTagRepository.findOne(savedAssigned.getId()).getOptLockRevision())
|
||||
assertThat(targetTagRepository.findById(savedAssigned.getId()).get().getOptLockRevision())
|
||||
.as("wrong target tag is saved").isEqualTo(2);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
||||
@@ -44,7 +44,7 @@ import io.qameta.allure.Story;
|
||||
|
||||
@Feature("Component Tests - Repository")
|
||||
@Story("Entity Events")
|
||||
@SpringApplicationConfiguration(classes = RepositoryTestConfiguration.class)
|
||||
@SpringBootTest(classes = { RepositoryTestConfiguration.class })
|
||||
public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -90,7 +90,7 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Slice<Action> findEnitity = deploymentManagement.findActionsByTarget(rsqlParam, target.getControllerId(),
|
||||
new PageRequest(0, 100));
|
||||
PageRequest.of(0, 100));
|
||||
final long countAllEntities = deploymentManagement.countActionsByTarget(rsqlParam, target.getControllerId());
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
|
||||
@@ -145,7 +145,7 @@ public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
final Page<DistributionSet> find = distributionSetManagement.findByRsql(new PageRequest(0, 100), rsqlParam);
|
||||
final Page<DistributionSet> find = distributionSetManagement.findByRsql(PageRequest.of(0, 100), rsqlParam);
|
||||
final long countAll = find.getTotalElements();
|
||||
assertThat(find).as("Founded entity is should not be null").isNotNull();
|
||||
assertThat(countAll).as("Founded entity size is wrong").isEqualTo(excpectedEntity);
|
||||
|
||||
@@ -73,7 +73,7 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractJpaIntegratio
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Page<DistributionSetMetadata> findEnitity = distributionSetManagement
|
||||
.findMetaDataByDistributionSetIdAndRsql(new PageRequest(0, 100), distributionSetId, rsqlParam);
|
||||
.findMetaDataByDistributionSetIdAndRsql(PageRequest.of(0, 100), distributionSetId, rsqlParam);
|
||||
final long countAllEntities = findEnitity.getTotalElements();
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) {
|
||||
final Page<RolloutGroup> findTargetPage = rolloutGroupManagement.findByRolloutAndRsql(new PageRequest(0, 100),
|
||||
final Page<RolloutGroup> findTargetPage = rolloutGroupManagement.findByRolloutAndRsql(PageRequest.of(0, 100),
|
||||
rollout.getId(), rsqlParam);
|
||||
final long countTargetsAll = findTargetPage.getTotalElements();
|
||||
assertThat(findTargetPage).isNotNull();
|
||||
|
||||
@@ -116,7 +116,7 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
final Page<SoftwareModule> find = softwareModuleManagement.findByRsql(new PageRequest(0, 100), rsqlParam);
|
||||
final Page<SoftwareModule> find = softwareModuleManagement.findByRsql(PageRequest.of(0, 100), rsqlParam);
|
||||
final long countAll = find.getTotalElements();
|
||||
assertThat(find).isNotNull();
|
||||
assertThat(countAll).isEqualTo(excpectedEntity);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Page<SoftwareModuleMetadata> findEnitity = softwareModuleManagement
|
||||
.findMetaDataByRsql(new PageRequest(0, 100), softwareModuleId, rsqlParam);
|
||||
.findMetaDataByRsql(PageRequest.of(0, 100), softwareModuleId, rsqlParam);
|
||||
final long countAllEntities = findEnitity.getTotalElements();
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractJpaIntegrationTest
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
final Page<SoftwareModuleType> find = softwareModuleTypeManagement.findByRsql(new PageRequest(0, 100),
|
||||
final Page<SoftwareModuleType> find = softwareModuleTypeManagement.findByRsql(PageRequest.of(0, 100),
|
||||
rsqlParam);
|
||||
final long countAll = find.getTotalElements();
|
||||
assertThat(find).isNotNull();
|
||||
|
||||
@@ -119,7 +119,7 @@ public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void assertRSQLQueryDistributionSet(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Page<DistributionSetTag> findEnitity = distributionSetTagManagement.findByRsql(new PageRequest(0, 100),
|
||||
final Page<DistributionSetTag> findEnitity = distributionSetTagManagement.findByRsql(PageRequest.of(0, 100),
|
||||
rsqlParam);
|
||||
final long countAllEntities = findEnitity.getTotalElements();
|
||||
assertThat(findEnitity).isNotNull();
|
||||
@@ -128,7 +128,7 @@ public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void assertRSQLQueryTarget(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
final Page<TargetTag> findEnitity = targetTagManagement.findByRsql(new PageRequest(0, 100), rsqlParam);
|
||||
final Page<TargetTag> findEnitity = targetTagManagement.findByRsql(PageRequest.of(0, 100), rsqlParam);
|
||||
final long countAllEntities = findEnitity.getTotalElements();
|
||||
assertThat(findEnitity).isNotNull();
|
||||
assertThat(countAllEntities).isEqualTo(expectedEntities);
|
||||
|
||||
@@ -9,16 +9,15 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
@@ -33,11 +32,11 @@ import org.eclipse.hawkbit.repository.FieldNameProvider;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
@@ -45,18 +44,19 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.orm.jpa.vendor.Database;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@Feature("Component Tests - Repository")
|
||||
@Story("RSQL search utility")
|
||||
@PrepareForTest(TimestampCalculator.class)
|
||||
// TODO: fully document tests -> @Description for long text and reasonable
|
||||
// method name as short text
|
||||
public class RSQLUtilityTest {
|
||||
@@ -64,7 +64,7 @@ public class RSQLUtilityTest {
|
||||
@Spy
|
||||
private final VirtualPropertyResolver macroResolver = new VirtualPropertyResolver();
|
||||
|
||||
@Mock
|
||||
@MockBean
|
||||
private TenantConfigurationManagement confMgmt;
|
||||
|
||||
@Mock
|
||||
@@ -80,6 +80,14 @@ public class RSQLUtilityTest {
|
||||
@Mock
|
||||
private Attribute attribute;
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
TenantConfigurationManagementHolder tenantConfigurationManagementHolder() {
|
||||
return TenantConfigurationManagementHolder.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
|
||||
.<String> builder().value("00:05:00").build();
|
||||
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue
|
||||
@@ -179,7 +187,9 @@ public class RSQLUtilityTest {
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.get("version")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
|
||||
when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
|
||||
@@ -197,7 +207,8 @@ public class RSQLUtilityTest {
|
||||
final String correctRsql = "name!=abc";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.notLike(any(Expression.class), anyString(), eq('\\')))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
@@ -218,7 +229,7 @@ public class RSQLUtilityTest {
|
||||
final String correctRsql = "name==a%";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
@@ -239,11 +250,11 @@ public class RSQLUtilityTest {
|
||||
final String correctRsql = "name==a%";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
|
||||
when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, SoftwareModuleFields.class, null, Database.SQL_SERVER)
|
||||
@@ -261,7 +272,7 @@ public class RSQLUtilityTest {
|
||||
final String correctRsql = "name=lt=abc";
|
||||
when(baseSoftwareModuleRootMock.get("name")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) SoftwareModule.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.lessThan(any(Expression.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> greaterThanOrEqualTo(any(Expression.class), any(String.class)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
// test
|
||||
@@ -279,7 +290,7 @@ public class RSQLUtilityTest {
|
||||
final String correctRsql = "testfield==bumlux";
|
||||
when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) TestValueEnum.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.equal(any(Root.class), any(TestValueEnum.class))).thenReturn(mock(Predicate.class));
|
||||
|
||||
// test
|
||||
RSQLUtility.parse(correctRsql, TestFieldEnum.class, null, testDb).toPredicate(baseSoftwareModuleRootMock,
|
||||
@@ -317,7 +328,9 @@ public class RSQLUtilityTest {
|
||||
final String correctRsql = "testfield=le=" + overduePropPlaceholder;
|
||||
when(baseSoftwareModuleRootMock.get("testfield")).thenReturn(baseSoftwareModuleRootMock);
|
||||
when(baseSoftwareModuleRootMock.getJavaType()).thenReturn((Class) String.class);
|
||||
when(criteriaBuilderMock.equal(any(Root.class), anyString())).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.upper(eq(pathOfString(baseSoftwareModuleRootMock))))
|
||||
.thenReturn(pathOfString(baseSoftwareModuleRootMock));
|
||||
when(criteriaBuilderMock.like(any(Expression.class), anyString(), eq('\\'))).thenReturn(mock(Predicate.class));
|
||||
when(criteriaBuilderMock.<String> lessThanOrEqualTo(any(Expression.class), eq(overduePropPlaceholder)))
|
||||
.thenReturn(mock(Predicate.class));
|
||||
|
||||
@@ -365,9 +378,6 @@ public class RSQLUtilityTest {
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class))
|
||||
.thenReturn(TEST_POLLING_OVERDUE_TIME_INTERVAL);
|
||||
|
||||
mockStatic(TimestampCalculator.class);
|
||||
when(TimestampCalculator.getTenantConfigurationManagement()).thenReturn(confMgmt);
|
||||
|
||||
return macroResolver;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,36 +12,35 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@Feature("Unit Tests - Repository")
|
||||
@Story("Placeholder resolution for virtual properties")
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(TimestampCalculator.class)
|
||||
public class VirtualPropertyResolverTest {
|
||||
|
||||
@Spy
|
||||
private final VirtualPropertyResolver resolverUnderTest = new VirtualPropertyResolver();
|
||||
|
||||
@Mock
|
||||
@MockBean
|
||||
private TenantConfigurationManagement confMgmt;
|
||||
|
||||
private StrSubstitutor substitutor;
|
||||
@@ -51,6 +50,14 @@ public class VirtualPropertyResolverTest {
|
||||
private static final TenantConfigurationValue<String> TEST_POLLING_OVERDUE_TIME_INTERVAL = TenantConfigurationValue
|
||||
.<String> builder().value("00:07:37").build();
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
TenantConfigurationManagementHolder tenantConfigurationManagementHolder() {
|
||||
return TenantConfigurationManagementHolder.getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class))
|
||||
@@ -58,9 +65,6 @@ public class VirtualPropertyResolverTest {
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class))
|
||||
.thenReturn(TEST_POLLING_OVERDUE_TIME_INTERVAL);
|
||||
|
||||
mockStatic(TimestampCalculator.class);
|
||||
when(TimestampCalculator.getTenantConfigurationManagement()).thenReturn(confMgmt);
|
||||
|
||||
substitutor = new StrSubstitutor(resolverUnderTest, StrSubstitutor.DEFAULT_PREFIX,
|
||||
StrSubstitutor.DEFAULT_SUFFIX, StrSubstitutor.DEFAULT_ESCAPE);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.specifications;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -28,7 +28,6 @@ import javax.persistence.criteria.Root;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.domain.Specifications;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
@@ -41,20 +40,20 @@ public class SpecificationsBuilderTest {
|
||||
@Test
|
||||
@Description("Test the combination of specs on an empty list which returns null")
|
||||
public void combineWithAndEmptyList() {
|
||||
List<Specification<Object>> specList = Collections.emptyList();
|
||||
final List<Specification<Object>> specList = Collections.emptyList();
|
||||
assertThat(SpecificationsBuilder.combineWithAnd(specList)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test the combination of specs on an immutable list with one entry")
|
||||
public void combineWithAndSingleImmutableList() {
|
||||
Specification<Object> spec = (root, query, cb) -> cb.equal(root.get("field1"), "testValue");
|
||||
List<Specification<Object>> specList = Collections.singletonList(spec);
|
||||
Specifications<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
|
||||
final Specification<Object> spec = (root, query, cb) -> cb.equal(root.get("field1"), "testValue");
|
||||
final List<Specification<Object>> specList = Collections.singletonList(spec);
|
||||
final Specification<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
|
||||
assertThat(specifications).as("Specifications").isNotNull();
|
||||
|
||||
// mocks to call toPredicate on specifications
|
||||
CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class);
|
||||
final CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class);
|
||||
final Path field1 = mock(Path.class);
|
||||
final Predicate equalPredicate = mock(Predicate.class);
|
||||
final CriteriaQuery<Object[]> query = mock(CriteriaQuery.class);
|
||||
@@ -63,28 +62,27 @@ public class SpecificationsBuilderTest {
|
||||
when(criteriaBuilder.equal(any(Expression.class), anyString())).thenReturn(equalPredicate);
|
||||
when(root.get("field1")).thenReturn(field1);
|
||||
|
||||
Predicate predicate = specifications.toPredicate(root, query, criteriaBuilder);
|
||||
final Predicate predicate = specifications.toPredicate(root, query, criteriaBuilder);
|
||||
|
||||
assertThat(predicate).isEqualTo(equalPredicate);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Description("Test the combination of specs on a list with multiple entries")
|
||||
public void combineWithAndList() {
|
||||
Specification<Object> spec1 = (root, query, cb) -> cb.equal(root.get("field1"), "testValue1");
|
||||
Specification<Object> spec2 = (root, query, cb) -> cb.equal(root.get("field2"), "testValue2");
|
||||
final Specification<Object> spec1 = (root, query, cb) -> cb.equal(root.get("field1"), "testValue1");
|
||||
final Specification<Object> spec2 = (root, query, cb) -> cb.equal(root.get("field2"), "testValue2");
|
||||
|
||||
List<Specification<Object>> specList = new ArrayList<>(2);
|
||||
final List<Specification<Object>> specList = new ArrayList<>(2);
|
||||
specList.add(spec1);
|
||||
specList.add(spec2);
|
||||
|
||||
Specifications<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
|
||||
final Specification<Object> specifications = SpecificationsBuilder.combineWithAnd(specList);
|
||||
assertThat(specifications).as("Specifications").isNotNull();
|
||||
|
||||
// mocks to call toPredicate on specifications
|
||||
CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class);
|
||||
final CriteriaBuilder criteriaBuilder = mock(CriteriaBuilder.class);
|
||||
final Path field1 = mock(Path.class);
|
||||
final Path field2 = mock(Path.class);
|
||||
final Predicate equalPredicate1 = mock(Predicate.class);
|
||||
@@ -99,7 +97,7 @@ public class SpecificationsBuilderTest {
|
||||
when(root.get("field1")).thenReturn(field1);
|
||||
when(root.get("field2")).thenReturn(field2);
|
||||
|
||||
Predicate predicate = specifications.toPredicate(root, query, criteriaBuilder);
|
||||
final Predicate predicate = specifications.toPredicate(root, query, criteriaBuilder);
|
||||
|
||||
assertThat(predicate).as("Combined predicate").isEqualTo(combinedPredicate);
|
||||
|
||||
|
||||
@@ -89,10 +89,6 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@@ -130,7 +126,7 @@
|
||||
<artifactId>protostuff-runtime</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.awaitility</groupId>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -42,12 +42,9 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cache.guava.GuavaCacheManager;
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
import org.springframework.cloud.bus.ConditionalOnBusEnabled;
|
||||
import org.springframework.cloud.bus.ServiceMatcher;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.annotation.AdviceMode;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -65,7 +62,6 @@ import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService;
|
||||
import org.springframework.security.concurrent.DelegatingSecurityContextScheduledExecutorService;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
@@ -128,8 +124,9 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
|
||||
@Bean
|
||||
TenantAwareCacheManager cacheManager() {
|
||||
return new TenantAwareCacheManager(new GuavaCacheManager(), tenantAware());
|
||||
return new TenantAwareCacheManager(new CaffeineCacheManager(), tenantAware());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bean for the download id cache.
|
||||
*
|
||||
@@ -206,15 +203,6 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
return new VirtualPropertyResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
ServiceMatcher serviceMatcher(final ApplicationContext applicationContext) {
|
||||
final ServiceMatcher serviceMatcher = new ServiceMatcher();
|
||||
serviceMatcher.setMatcher(new AntPathMatcher(":"));
|
||||
serviceMatcher.setApplicationContext(applicationContext);
|
||||
return serviceMatcher;
|
||||
}
|
||||
|
||||
@Bean
|
||||
RolloutApprovalStrategy rolloutApprovalStrategy() {
|
||||
return new RolloutTestApprovalStrategy();
|
||||
|
||||
@@ -37,8 +37,8 @@ import org.springframework.test.context.support.AbstractTestExecutionListener;
|
||||
import com.google.common.collect.ConcurrentHashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.jayway.awaitility.core.ConditionTimeoutException;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.core.ConditionTimeoutException;
|
||||
|
||||
/**
|
||||
* Test rule to setup and verify the event count for a method.
|
||||
|
||||
@@ -17,9 +17,7 @@ import java.net.URI;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -71,7 +69,7 @@ import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.bus.ServiceMatcher;
|
||||
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -80,18 +78,22 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.TestExecutionListeners.MergeMode;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
import com.google.common.io.Files;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ActiveProfiles({ "test" })
|
||||
@WithUser(principal = "bumlux", allSpPermissions = true, authorities = { CONTROLLER_ROLE, SYSTEM_ROLE })
|
||||
@SpringApplicationConfiguration(classes = { TestConfiguration.class, TestSupportBinderAutoConfiguration.class })
|
||||
@SpringBootTest
|
||||
@ContextConfiguration(classes = { TestConfiguration.class, TestSupportBinderAutoConfiguration.class })
|
||||
// destroy the context after each test class because otherwise we get problem
|
||||
// when context is
|
||||
// refreshed we e.g. get two instances of CacheManager which leads to very
|
||||
@@ -102,19 +104,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
// important!
|
||||
@TestExecutionListeners(inheritListeners = true, listeners = { EventVerifier.class, CleanupTestExecutionListener.class,
|
||||
MySqlTestDatabase.class, MsSqlTestDatabase.class }, mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
|
||||
@TestPropertySource(properties = "spring.main.allow-bean-definition-overriding=true")
|
||||
public abstract class AbstractIntegrationTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractIntegrationTest.class);
|
||||
|
||||
protected static final Pageable PAGE = new PageRequest(0, 400, new Sort(Direction.ASC, "id"));
|
||||
protected static final Pageable PAGE = PageRequest.of(0, 400, new Sort(Direction.ASC, "id"));
|
||||
|
||||
protected static final URI LOCALHOST = URI.create("http://127.0.0.1");
|
||||
|
||||
/**
|
||||
* Constant for MediaType HAL with encoding UTF-8. Necessary since Spring
|
||||
* version 4.3.2 @see https://jira.spring.io/browse/SPR-14577
|
||||
*/
|
||||
protected static final String APPLICATION_JSON_HAL_UTF = MediaTypes.HAL_JSON + ";charset=UTF-8";
|
||||
|
||||
/**
|
||||
* Number of {@link DistributionSetType}s that exist in every test case. One
|
||||
* generated by using
|
||||
@@ -362,7 +359,8 @@ public abstract class AbstractIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
private static String artifactDirectory = "./artifactrepo/" + RandomStringUtils.randomAlphanumeric(20);
|
||||
private static String artifactDirectory = Files.createTempDir().getAbsolutePath() + "/"
|
||||
+ RandomStringUtils.randomAlphanumeric(20);
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
@@ -416,20 +414,4 @@ public abstract class AbstractIntegrationTest {
|
||||
final ZonedDateTime currentTime = ZonedDateTime.now();
|
||||
return currentTime.getOffset().getId().replace("Z", "+00:00");
|
||||
}
|
||||
|
||||
protected static Map<String, String> getMaintenanceWindow(final String schedule, final String duration,
|
||||
final String timezone) {
|
||||
final Map<String, String> maintenanceWindowMap = new HashMap<>();
|
||||
maintenanceWindowMap.put("schedule", schedule);
|
||||
maintenanceWindowMap.put("duration", duration);
|
||||
maintenanceWindowMap.put("timezone", timezone);
|
||||
return maintenanceWindowMap;
|
||||
}
|
||||
|
||||
protected static Map<String, String> getMaintenanceWindowWithNextStart(final String schedule, final String duration,
|
||||
final String timezone, final long nextStartAt) {
|
||||
final Map<String, String> maintenanceWindowMap = getMaintenanceWindow(schedule, duration, timezone);
|
||||
maintenanceWindowMap.put("nextStartAt", String.valueOf(nextStartAt));
|
||||
return maintenanceWindowMap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.domain.Sort.Direction;
|
||||
public class JpaTestRepositoryManagement {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JpaTestRepositoryManagement.class);
|
||||
private static final Pageable PAGE = new PageRequest(0, 400, new Sort(Direction.ASC, "id"));
|
||||
private static final Pageable PAGE = PageRequest.of(0, 400, new Sort(Direction.ASC, "id"));
|
||||
|
||||
private final TenantAwareCacheManager cacheManager;
|
||||
|
||||
|
||||
@@ -886,7 +886,8 @@ public class TestdataFactory {
|
||||
final String descriptionPrefix, final Long lastTargetQuery) {
|
||||
|
||||
return targetManagement.create(IntStream.range(0, numberOfTargets)
|
||||
.mapToObj(i -> entityFactory.target().create().controllerId(controllerIdPrefix + i)
|
||||
.mapToObj(i -> entityFactory.target().create()
|
||||
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
||||
.description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
@@ -973,7 +974,7 @@ public class TestdataFactory {
|
||||
final List<Action> result = new ArrayList<>();
|
||||
for (final Target target : targets) {
|
||||
final List<Action> findByTarget = deploymentManagement
|
||||
.findActionsByTarget(target.getControllerId(), new PageRequest(0, 400)).getContent();
|
||||
.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 400)).getContent();
|
||||
for (final Action action : findByTarget) {
|
||||
result.add(sendUpdateActionStatusToTarget(status, action, msgs));
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@ import java.lang.annotation.Target;
|
||||
/**
|
||||
* Annotation to run test classes or test methods with a specific user with
|
||||
* specific permissions.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
|
||||
@@ -20,10 +20,6 @@ spring.jpa.properties.eclipselink.logging.parameters=true
|
||||
# Test utility properties for easier fault investigation - END
|
||||
|
||||
# Default properties for test that can be overridden during test run - START
|
||||
## JPA Repository - START
|
||||
spring.datasource.url=jdbc:h2:mem:sp-db;DB_CLOSE_ON_EXIT=FALSE
|
||||
## JPA Repository - END
|
||||
|
||||
# Enforce persistence of targetpolls for test predictability.
|
||||
hawkbit.server.repository.eagerPollPersistence=true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user