Cleanup file streaming utilities (#559)
* Cleanup file streaming. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Added missing comments. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix typo. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Split utility class. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Dependency cleanup. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Add missing dependency, Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Remove repository api dependency from rest core. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix build and sonar issues. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Remove custom ConstraintViolationException Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * RequestMapping should be public. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix errors. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Removed dead code. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Not null Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix nullpointer. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Code cleanup. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -13,7 +13,7 @@ import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
|
||||
@@ -196,15 +196,15 @@ public interface ArtifactManagement {
|
||||
Page<Artifact> findArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId);
|
||||
|
||||
/**
|
||||
* Loads {@link DbArtifact} from store for given {@link Artifact}.
|
||||
* Loads {@link AbstractDbArtifact} from store for given {@link Artifact}.
|
||||
*
|
||||
* @param sha1Hash
|
||||
* to search for
|
||||
* @return loaded {@link DbArtifact}
|
||||
* @return loaded {@link AbstractDbArtifact}
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DOWNLOAD_ARTIFACT + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD)
|
||||
Optional<DbArtifact> loadArtifactBinary(@NotEmpty String sha1Hash);
|
||||
Optional<AbstractDbArtifact> loadArtifactBinary(@NotEmpty String sha1Hash);
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
|
||||
@@ -61,22 +60,6 @@ public interface ControllerManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
Action addCancelActionStatus(@NotNull ActionStatusCreate create);
|
||||
|
||||
/**
|
||||
* Sends the download progress and notifies the event publisher with a
|
||||
* {@link DownloadProgressEvent}.
|
||||
*
|
||||
* @param statusId
|
||||
* the ID of the {@link ActionStatus}
|
||||
* @param requestedBytes
|
||||
* requested bytes of the request
|
||||
* @param shippedBytesSinceLast
|
||||
* since the last report
|
||||
* @param shippedBytesOverall
|
||||
* for the {@link ActionStatus}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
void downloadProgress(Long statusId, Long requestedBytes, Long shippedBytesSinceLast, Long shippedBytesOverall);
|
||||
|
||||
/**
|
||||
* Simple addition of a new {@link ActionStatus} entry to the {@link Action}
|
||||
* . No state changes.
|
||||
|
||||
@@ -11,13 +11,13 @@ package org.eclipse.hawkbit.repository;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutUpdate;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
|
||||
/**
|
||||
* TenantAwareEvent that contains an updated download progress for a given
|
||||
* ActionStatus that was written for a download request.
|
||||
@@ -17,7 +19,7 @@ public class DownloadProgressEvent extends RemoteTenantAwareEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long shippedBytesSinceLast;
|
||||
private long shippedBytesSinceLast;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
@@ -31,13 +33,16 @@ public class DownloadProgressEvent extends RemoteTenantAwareEvent {
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant
|
||||
* @param actionStatusId
|
||||
* of the {@link ActionStatus} the download belongs to
|
||||
* @param shippedBytesSinceLast
|
||||
* the shippedBytesSinceLast
|
||||
* @param applicationId
|
||||
* the application id.
|
||||
*/
|
||||
public DownloadProgressEvent(final String tenant, final Long shippedBytesSinceLast, final String applicationId) {
|
||||
super(shippedBytesSinceLast, tenant, applicationId);
|
||||
public DownloadProgressEvent(final String tenant, final Long actionStatusId, final long shippedBytesSinceLast,
|
||||
final String applicationId) {
|
||||
super(actionStatusId, tenant, applicationId);
|
||||
this.shippedBytesSinceLast = shippedBytesSinceLast;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* the {@link ConstraintViolationException} is thrown when an entity is tried to
|
||||
* be saved which has constraint violations
|
||||
*/
|
||||
public class ConstraintViolationException extends AbstractServerRtException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String MESSAGE_FORMATTER_SEPARATOR = " ";
|
||||
|
||||
/**
|
||||
* Constructor for {@link ConstraintViolationException}
|
||||
*
|
||||
* @param ex
|
||||
* the javax.validation.ConstraintViolationException which is
|
||||
* thrown
|
||||
*/
|
||||
public ConstraintViolationException(final javax.validation.ConstraintViolationException ex) {
|
||||
this(getExceptionMessage(ex));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ConstraintViolationException} with the error code
|
||||
* {@link SpServerError#SP_REPO_CONSTRAINT_VIOLATION}.
|
||||
*
|
||||
* @param msgText
|
||||
* the message text for this exception
|
||||
*/
|
||||
public ConstraintViolationException(final String msgText) {
|
||||
super(msgText, SpServerError.SP_REPO_CONSTRAINT_VIOLATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the information of
|
||||
* {@link javax.validation.ConstraintViolationException} to provide a proper
|
||||
* error message for {@link ConstraintViolationException}
|
||||
*
|
||||
* @param ex
|
||||
* javax.validation.ConstraintViolationException which is thrown
|
||||
* @return message String with proper error information
|
||||
*/
|
||||
public static String getExceptionMessage(final javax.validation.ConstraintViolationException ex) {
|
||||
return ex
|
||||
.getConstraintViolations().stream().map(violation -> violation.getPropertyPath()
|
||||
+ MESSAGE_FORMATTER_SEPARATOR + violation.getMessage() + ".")
|
||||
.collect(Collectors.joining(MESSAGE_FORMATTER_SEPARATOR));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.exception;
|
||||
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
/**
|
||||
* Thrown if a multi part exception occurred.
|
||||
*
|
||||
*/
|
||||
public final class MultiPartFileUploadException extends AbstractServerRtException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* @param cause
|
||||
* for the exception
|
||||
*/
|
||||
public MultiPartFileUploadException(final Throwable cause) {
|
||||
super(cause.getMessage(), SpServerError.SP_ARTIFACT_UPLOAD_FAILED, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
|
||||
|
||||
/**
|
||||
* Binaries for a {@link SoftwareModule} Note: the decision which artifacts have
|
||||
@@ -34,7 +34,7 @@ public interface Artifact extends TenantAwareBaseEntity {
|
||||
|
||||
/**
|
||||
* @return SHA-1 hash of the artifact in Base16 format that identifies the
|
||||
* {@link DbArtifact} in the system.
|
||||
* {@link AbstractDbArtifact} in the system.
|
||||
*/
|
||||
String getSha1Hash();
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
|
||||
@@ -12,7 +12,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import javax.validation.ValidationException;
|
||||
|
||||
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
@@ -35,10 +36,10 @@ public final class RolloutHelper {
|
||||
*/
|
||||
public static void verifyRolloutGroupConditions(final RolloutGroupConditions conditions) {
|
||||
if (conditions.getSuccessCondition() == null) {
|
||||
throw new ConstraintViolationException("Rollout group is missing success condition");
|
||||
throw new ValidationException("Rollout group is missing success condition");
|
||||
}
|
||||
if (conditions.getSuccessAction() == null) {
|
||||
throw new ConstraintViolationException("Rollout group is missing success action");
|
||||
throw new ValidationException("Rollout group is missing success action");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,14 +53,14 @@ public final class RolloutHelper {
|
||||
*/
|
||||
public static RolloutGroup verifyRolloutGroupHasConditions(final RolloutGroup group) {
|
||||
if (group.getTargetPercentage() < 1F || group.getTargetPercentage() > 100F) {
|
||||
throw new ConstraintViolationException("Target percentage has to be between 1 and 100");
|
||||
throw new ValidationException("Target percentage has to be between 1 and 100");
|
||||
}
|
||||
|
||||
if (group.getSuccessCondition() == null) {
|
||||
throw new ConstraintViolationException("Rollout group is missing success condition");
|
||||
throw new ValidationException("Rollout group is missing success condition");
|
||||
}
|
||||
if (group.getSuccessAction() == null) {
|
||||
throw new ConstraintViolationException("Rollout group is missing success action");
|
||||
throw new ValidationException("Rollout group is missing success action");
|
||||
}
|
||||
return group;
|
||||
}
|
||||
@@ -74,9 +75,9 @@ public final class RolloutHelper {
|
||||
*/
|
||||
public static void verifyRolloutGroupParameter(final int amountGroup, final QuotaManagement quotaManagement) {
|
||||
if (amountGroup <= 0) {
|
||||
throw new ConstraintViolationException("the amount of groups cannot be lower than zero");
|
||||
throw new ValidationException("the amount of groups cannot be lower than zero");
|
||||
} else if (amountGroup > quotaManagement.getMaxRolloutGroupsPerRollout()) {
|
||||
throw new ConstraintViolationException("the amount of groups cannot be greater than 500");
|
||||
throw new ValidationException("the amount of groups cannot be greater than 500");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,9 +89,9 @@ public final class RolloutHelper {
|
||||
*/
|
||||
public static void verifyRolloutGroupTargetPercentage(final float percentage) {
|
||||
if (percentage <= 0) {
|
||||
throw new ConstraintViolationException("the percentage must be greater than zero");
|
||||
throw new ValidationException("the percentage must be greater than zero");
|
||||
} else if (percentage > 100) {
|
||||
throw new ConstraintViolationException("the percentage must not be greater than 100");
|
||||
throw new ValidationException("the percentage must not be greater than 100");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,11 +241,10 @@ public final class RolloutHelper {
|
||||
*/
|
||||
public static void verifyRemainingTargets(final long targetCount) {
|
||||
if (targetCount > 0) {
|
||||
throw new ConstraintViolationException(
|
||||
"Rollout groups don't match all targets that are targeted by the rollout");
|
||||
throw new ValidationException("Rollout groups don't match all targets that are targeted by the rollout");
|
||||
}
|
||||
if (targetCount != 0) {
|
||||
throw new ConstraintViolationException("Rollout groups target count verification failed");
|
||||
throw new ValidationException("Rollout groups target count verification failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Optional;
|
||||
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
|
||||
import org.eclipse.hawkbit.artifact.repository.ArtifactStoreException;
|
||||
import org.eclipse.hawkbit.artifact.repository.HashNotMatchException;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException;
|
||||
@@ -88,7 +88,7 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
public Artifact createArtifact(final InputStream stream, final Long moduleId, final String filename,
|
||||
final String providedMd5Sum, final String providedSha1Sum, final boolean overrideExisting,
|
||||
final String contentType) {
|
||||
DbArtifact result = null;
|
||||
AbstractDbArtifact result = null;
|
||||
|
||||
final SoftwareModule softwareModule = getModuleAndThrowExceptionIfThatFails(moduleId);
|
||||
|
||||
@@ -184,12 +184,12 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DbArtifact> loadArtifactBinary(final String sha1Hash) {
|
||||
public Optional<AbstractDbArtifact> loadArtifactBinary(final String sha1Hash) {
|
||||
return Optional.ofNullable(artifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), sha1Hash));
|
||||
}
|
||||
|
||||
private Artifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename,
|
||||
final DbArtifact result, final Artifact existing) {
|
||||
final AbstractDbArtifact result, final Artifact existing) {
|
||||
JpaArtifact artifact = (JpaArtifact) existing;
|
||||
if (existing == null) {
|
||||
artifact = new JpaArtifact(result.getHashes().getSha1(), providedFilename, softwareModule);
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
@@ -483,13 +482,6 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadProgress(final Long statusId, final Long requestedBytes, final Long shippedBytesSinceLast,
|
||||
final Long shippedBytesOverall) {
|
||||
eventPublisher.publishEvent(new DownloadProgressEvent(tenantAware.getCurrentTenant(), shippedBytesSinceLast,
|
||||
applicationContext.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Target> findByControllerId(final String controllerId) {
|
||||
return targetRepository.findByControllerId(controllerId);
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.stream.StreamSupport;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.validation.ConstraintDeclarationException;
|
||||
import javax.validation.ValidationException;
|
||||
|
||||
import org.eclipse.hawkbit.repository.AbstractRolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
@@ -37,7 +38,6 @@ import org.eclipse.hawkbit.repository.builder.RolloutUpdate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.RolloutGroupDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
|
||||
@@ -216,7 +216,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
|
||||
final Long totalTargets = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery());
|
||||
if (totalTargets == 0) {
|
||||
throw new ConstraintViolationException("Rollout does not match any existing targets");
|
||||
throw new ValidationException("Rollout does not match any existing targets");
|
||||
}
|
||||
rollout.setTotalTargets(totalTargets);
|
||||
return rolloutRepository.save(rollout);
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import javax.validation.ValidationException;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractSoftwareModuleUpdateCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
@@ -36,7 +37,7 @@ public class JpaSoftwareModuleCreate extends AbstractSoftwareModuleUpdateCreate<
|
||||
|
||||
private SoftwareModuleType getSoftwareModuleTypeFromKeyString(final String type) {
|
||||
if (type == null) {
|
||||
throw new ConstraintViolationException("type cannot be null");
|
||||
throw new ValidationException("type cannot be null");
|
||||
}
|
||||
|
||||
return softwareModuleTypeManagement.findSoftwareModuleTypeByKey(type.trim())
|
||||
|
||||
@@ -21,7 +21,7 @@ import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||
import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
@@ -71,9 +71,9 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art
|
||||
* Constructs artifact.
|
||||
*
|
||||
* @param sha1Hash
|
||||
* that is the link to the {@link DbArtifact} entity.
|
||||
* that is the link to the {@link AbstractDbArtifact} entity.
|
||||
* @param filename
|
||||
* that is used by {@link DbArtifact} store.
|
||||
* that is used by {@link AbstractDbArtifact} store.
|
||||
* @param softwareModule
|
||||
* of this artifact
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,7 @@ public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest {
|
||||
@Test
|
||||
@Description("Verifies that the download progress reloading by remote events works")
|
||||
public void reloadDownloadProgessByRemoteEvent() {
|
||||
final DownloadProgressEvent downloadProgressEvent = new DownloadProgressEvent("DEFAULT", 3L, "Node");
|
||||
final DownloadProgressEvent downloadProgressEvent = new DownloadProgressEvent("DEFAULT", 1L, 3L, "Node");
|
||||
|
||||
DownloadProgressEvent remoteEvent = (DownloadProgressEvent) createProtoStuffEvent(downloadProgressEvent);
|
||||
assertThat(downloadProgressEvent).isEqualTo(remoteEvent);
|
||||
|
||||
@@ -26,7 +26,6 @@ public class ActionTest {
|
||||
@Description("Ensures that timeforced moded switch from soft to forces after defined timeframe.")
|
||||
public void timeforcedHitNewHasCodeIsGenerated() throws InterruptedException {
|
||||
|
||||
final boolean active;
|
||||
// current time + 1 seconds
|
||||
final long sleepTime = 1000;
|
||||
final long timeForceTimeAt = System.currentTimeMillis() + sleepTime;
|
||||
|
||||
@@ -104,10 +104,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1",
|
||||
false);
|
||||
final Artifact result11 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file11", false);
|
||||
final Artifact result12 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file12", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file11", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file12", false);
|
||||
final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(),
|
||||
"file2", false);
|
||||
|
||||
@@ -270,8 +268,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(artifactManagement.findArtifactBySoftwareModule(PAGE, sm.getId())).isEmpty();
|
||||
|
||||
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
|
||||
"file1", false);
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
|
||||
|
||||
assertThat(artifactManagement.findArtifactBySoftwareModule(PAGE, sm.getId())).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -747,7 +747,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Deletes multiple targets and verfies that all related metadat is also deleted.")
|
||||
@Description("Deletes multiple targets and verfies that all related metadata is also deleted.")
|
||||
public void deletesTargetsAndVerifyCascadeDeletes() {
|
||||
|
||||
final String undeployedTargetPrefix = "undep-T";
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.validation.ValidationException;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
@@ -37,7 +39,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
|
||||
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
|
||||
@@ -139,7 +140,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = RolloutUpdatedEvent.class, count = 1),
|
||||
@Expect(type = TargetCreatedEvent.class, count = 10) })
|
||||
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
|
||||
final Rollout createdRollout = testdataFactory.createRollout("xxx");
|
||||
testdataFactory.createRollout("xxx");
|
||||
|
||||
verifyThrownExceptionBy(() -> rolloutManagement.deleteRollout(NOT_EXIST_IDL), "Rollout");
|
||||
|
||||
@@ -1089,7 +1090,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName);
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
assertThatExceptionOfType(ValidationException.class)
|
||||
.isThrownBy(() -> testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups,
|
||||
"id==notExisting", distributionSet, successCondition, errorCondition))
|
||||
.withMessageContaining("does not match any existing");
|
||||
@@ -1336,7 +1337,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutGroups.add(generateRolloutGroup(0, percentTargetsInGroup1, null));
|
||||
rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
assertThatExceptionOfType(ValidationException.class)
|
||||
.isThrownBy(() -> rolloutManagement.createRollout(myRollout, rolloutGroups, conditions))
|
||||
.withMessageContaining("groups don't match");
|
||||
|
||||
@@ -1357,7 +1358,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
generateRolloutGroup(0, percentTargetsInGroup1, null),
|
||||
generateRolloutGroup(1, percentTargetsInGroup2, null));
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
assertThatExceptionOfType(ValidationException.class)
|
||||
.isThrownBy(() -> rolloutManagement.createRollout(myRollout, rolloutGroups, conditions))
|
||||
.withMessageContaining("percentage has to be between 1 and 100");
|
||||
|
||||
@@ -1373,7 +1374,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout);
|
||||
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
assertThatExceptionOfType(ValidationException.class)
|
||||
.isThrownBy(() -> rolloutManagement.createRollout(myRollout, illegalGroupAmount, conditions))
|
||||
.withMessageContaining("not be greater than " + quotaManagement.getMaxRolloutGroupsPerRollout());
|
||||
|
||||
|
||||
@@ -252,8 +252,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Counts all software modules in the repsitory that are not marked as deleted.")
|
||||
public void countSoftwareModulesAll() {
|
||||
// found in test
|
||||
final SoftwareModule one = testdataFactory.createSoftwareModuleOs("one");
|
||||
final SoftwareModule two = testdataFactory.createSoftwareModuleOs("two");
|
||||
testdataFactory.createSoftwareModuleOs("one");
|
||||
testdataFactory.createSoftwareModuleOs("two");
|
||||
final SoftwareModule deleted = testdataFactory.createSoftwareModuleOs("deleted");
|
||||
// ignored
|
||||
softwareModuleManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
@@ -484,8 +484,6 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
private void checkTargetHasTags(final boolean strict, final Iterable<Target> targets, final TargetTag... tags) {
|
||||
_target: for (final Target tl : targets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tt : tagManagement.findAllTargetTags(PAGE, tl.getControllerId())) {
|
||||
for (final Tag tag : tags) {
|
||||
if (tag.getName().equals(tt.getName())) {
|
||||
@@ -502,7 +500,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void checkTargetHasNotTags(final Iterable<Target> targets, final TargetTag... tags) {
|
||||
for (final Target tl : targets) {
|
||||
final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get();
|
||||
targetManagement.findTargetByControllerID(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : tagManagement.findAllTargetTags(PAGE, tl.getControllerId())) {
|
||||
|
||||
@@ -315,8 +315,8 @@ public class RSQLUtilityTest {
|
||||
.thenReturn(mock(Predicate.class));
|
||||
|
||||
// test
|
||||
final Predicate result = RSQLUtility.parse(correctRsql, TestFieldEnum.class, setupMacroLookup())
|
||||
.toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock);
|
||||
RSQLUtility.parse(correctRsql, TestFieldEnum.class, setupMacroLookup()).toPredicate(baseSoftwareModuleRootMock,
|
||||
criteriaQueryMock, criteriaBuilderMock);
|
||||
|
||||
// verification
|
||||
verify(macroResolver).lookup(overdueProp);
|
||||
|
||||
@@ -14,8 +14,6 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
@@ -48,8 +46,6 @@ public class VirtualPropertyResolverTest {
|
||||
|
||||
private StrSubstitutor substitutor;
|
||||
|
||||
private Long nowTestTime;
|
||||
|
||||
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
|
||||
@@ -57,7 +53,6 @@ public class VirtualPropertyResolverTest {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
nowTestTime = Instant.now().toEpochMilli();
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class))
|
||||
.thenReturn(TEST_POLLING_TIME_INTERVAL);
|
||||
when(confMgmt.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class))
|
||||
|
||||
Reference in New Issue
Block a user