Skip to content

Commit

Permalink
Fix upload quota check and provide better error message (eclipse#893)
Browse files Browse the repository at this point in the history
* Adjusted upload quota check to include file size and show proper error message

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Fixed failing upload quota tests

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Moved quota check to stream, fixed review findings

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Added missing license header to QuotaInputStream

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Reworked uploadLock, ensured error messages may be translated, review fixes

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Added local artifactrepo to gitignore

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Fixed sonar issues and assignment quota message

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* PR review fixes

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Split quota exceptions, PR fixes

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Removed left over conversion method in quota helper

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>

* Made conversion helper class final

Signed-off-by: Alexander Dobler <alexander.dobler3@bosch-si.com>
  • Loading branch information
dobleralex authored and Dominic Schabel committed Oct 30, 2019
1 parent 59a1e5b commit c540f8c
Show file tree
Hide file tree
Showing 43 changed files with 477 additions and 213 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@ target
.metadata
.project
.idea
artifactrepo

# Windows image file caches
Thumbs.db
Expand Down
Expand Up @@ -137,6 +137,16 @@ public enum SpServerError {
*/
SP_QUOTA_EXCEEDED("hawkbit.server.error.quota.tooManyEntries", "Too many entries have been inserted."),

/**
* error that describes that size of uploaded file exceeds size quota
*/
SP_FILE_SIZE_QUOTA_EXCEEDED("hawkbit.server.error.quota.fileSizeExceeded", "File exceeds size quota."),

/**
* error that describes that size of uploaded file exceeds storage quota
*/
SP_STORAGE_QUOTA_EXCEEDED("hawkbit.server.error.quota.storageExceeded", "Storage quota will be exceeded if file is uploaded."),

/**
* error message, which describes that the action can not be canceled cause
* the action is inactive.
Expand Down
Expand Up @@ -16,7 +16,7 @@
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException;
import org.eclipse.hawkbit.repository.exception.InvalidTargetAttributeException;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -72,7 +72,7 @@ private static boolean invalidState(final Throwable cause) {
}

private static boolean quotaHit(final Throwable cause) {
return cause instanceof QuotaExceededException;
return cause instanceof AssignmentQuotaExceededException;
}

private static boolean doesNotExist(final Throwable cause) {
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.InvalidTargetAttributeException;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
Expand Down Expand Up @@ -56,9 +56,9 @@ public interface ControllerManagement {
* @throws EntityAlreadyExistsException
* if a given entity already exists
*
* @throws QuotaExceededException
* if more than the allowed number of status entries or messages per
* entry are inserted
* @throws AssignmentQuotaExceededException
* if more than the allowed number of status entries or messages
* per entry are inserted
* @throws EntityNotFoundException
* if given action does not exist
* @throws ConstraintViolationException
Expand Down Expand Up @@ -101,9 +101,9 @@ Map<Long, List<SoftwareModuleMetadata>> findTargetVisibleMetaDataBySoftwareModul
*
* @return created {@link ActionStatus} entity
*
* @throws QuotaExceededException
* if more than the allowed number of status entries or messages per
* entry are inserted
* @throws AssignmentQuotaExceededException
* if more than the allowed number of status entries or messages
* per entry are inserted
* @throws EntityNotFoundException
* if given action does not exist
* @throws ConstraintViolationException
Expand All @@ -123,9 +123,9 @@ Map<Long, List<SoftwareModuleMetadata>> findTargetVisibleMetaDataBySoftwareModul
*
* @throws EntityAlreadyExistsException
* if a given entity already exists
* @throws QuotaExceededException
* if more than the allowed number of status entries or messages per
* entry are inserted
* @throws AssignmentQuotaExceededException
* if more than the allowed number of status entries or messages
* per entry are inserted
* @throws EntityNotFoundException
* if action status not exist
* @throws ConstraintViolationException
Expand Down Expand Up @@ -361,7 +361,7 @@ Map<Long, List<SoftwareModuleMetadata>> findTargetVisibleMetaDataBySoftwareModul
*
* @throws EntityNotFoundException
* if target that has to be updated could not be found
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if maximum number of attributes per target is exceeded
* @throws InvalidTargetAttributeException
* if attributes violate constraints
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.exception.MultiAssignmentIsNotEnabledException;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.model.Action;
Expand Down Expand Up @@ -66,7 +66,7 @@ public interface DeploymentManagement {
* if either provided {@link DistributionSet} or {@link Target}s
* do not exist
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of targets the distribution set can be
* assigned to at once is exceeded
* @throws MultiAssignmentIsNotEnabledException
Expand Down Expand Up @@ -97,7 +97,7 @@ List<DistributionSetAssignmentResult> assignDistributionSets(
* if either provided {@link DistributionSet} or {@link Target}s
* do not exist
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of targets the distribution set can be
* assigned to at once is exceeded
* @throws MultiAssignmentIsNotEnabledException
Expand Down Expand Up @@ -151,7 +151,7 @@ static DeploymentRequestBuilder deploymentRequest(final String controllerId, fin
* if either provided {@link DistributionSet} or {@link Target}s
* do not exist
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of targets the distribution set can be
* assigned to at once is exceeded
*
Expand Down
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
Expand Down Expand Up @@ -67,7 +67,7 @@ public interface DistributionSetManagement
* if {@link SoftwareModule#getType()} is not supported by this
* {@link DistributionSet#getType()}.
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of {@link SoftwareModule}s is exceeded
* for the addressed {@link DistributionSet}.
*/
Expand Down Expand Up @@ -109,7 +109,7 @@ public interface DistributionSetManagement
* in case one of the meta data entry already exists for the
* specific key
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of {@link MetaData} entries is exceeded
* for the addressed {@link DistributionSet}
*/
Expand Down
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeUpdate;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
Expand Down Expand Up @@ -65,7 +65,7 @@ public interface DistributionSetTypeManagement
* if the {@link DistributionSetType} while it is already in use
* by a {@link DistributionSet}
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of {@link SoftwareModuleType}s is
* exceeded for the addressed {@link DistributionSetType}
*/
Expand All @@ -90,7 +90,7 @@ DistributionSetType assignOptionalSoftwareModuleTypes(long dsTypeId,
* if the {@link DistributionSetType} while it is already in use
* by a {@link DistributionSet}
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of {@link SoftwareModuleType}s is
* exceeded for the addressed {@link DistributionSetType}
*/
Expand Down
Expand Up @@ -22,7 +22,7 @@
import org.eclipse.hawkbit.repository.builder.RolloutUpdate;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException;
Expand Down Expand Up @@ -124,7 +124,7 @@ public interface RolloutManagement {
* if given {@link DistributionSet} does not exist
* @throws ConstraintViolationException
* if rollout or group parameters are invalid.
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of allowed targets per rollout group is
* exceeded.
*/
Expand Down Expand Up @@ -161,7 +161,7 @@ public interface RolloutManagement {
* if given {@link DistributionSet} does not exist
* @throws ConstraintViolationException
* if rollout or group parameters are invalid
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of allowed targets per rollout group is
* exceeded.
*/
Expand Down
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2019 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;

/**
* Helper class that provides simple conversion of byte values to readable
* strings
*/
public final class SizeConversionHelper {

private static final String KB = "KB";
private static final String MB = "MB";

// do not allow to create instances
private SizeConversionHelper() {
}

/**
* Convert byte values to human readable strings with units
*
* @param byteValue
* Value to convert in bytes
*/
public static String byteValueToReadableString(final long byteValue) {
double outputValue = byteValue / 1024.0;
String unit = KB;
if (outputValue >= 1024) {
outputValue = outputValue / 1024.0;
unit = MB;
}
// We cut decimal places to avoid localization handling
return (long) outputValue + " " + unit;
}
}
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.hawkbit.repository.builder.SoftwareModuleUpdate;
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.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule;
Expand Down Expand Up @@ -75,7 +75,7 @@ public interface SoftwareModuleManagement
* @throws EntityNotFoundException
* if software module with given ID does not exist
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of {@link SoftwareModuleMetadata}
* entries is exceeded for the addressed {@link SoftwareModule}
*/
Expand All @@ -97,7 +97,7 @@ public interface SoftwareModuleManagement
* @throws EntityNotFoundException
* if software module with given ID does not exist
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of {@link SoftwareModuleMetadata}
* entries is exceeded for the addressed {@link SoftwareModule}
*/
Expand Down
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignActionTypeException;
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignDistributionSetException;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public interface TargetFilterQueryManagement {
* if fields are not filled as specified. Check
* {@link TargetFilterQueryCreate} for field constraints.
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of targets that is addressed by the
* given query is exceeded (auto-assignments only)
*/
Expand Down Expand Up @@ -208,7 +208,7 @@ public interface TargetFilterQueryManagement {
* if fields are not filled as specified. Check
* {@link TargetFilterQueryUpdate} for field constraints.
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the update contains a new query which addresses too many
* targets (auto-assignments only)
*/
Expand All @@ -231,7 +231,7 @@ public interface TargetFilterQueryManagement {
* if either {@link TargetFilterQuery} and/or autoAssignDs are
* provided but not found
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the query that is already associated with this filter
* query addresses too many targets (auto-assignments only)
*
Expand Down Expand Up @@ -263,7 +263,7 @@ default TargetFilterQuery updateAutoAssignDS(final long queryId, final Long dsId
* if either {@link TargetFilterQuery} and/or autoAssignDs are
* provided but not found
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the query that is already associated with this filter
* query addresses too many targets (auto-assignments only)
*
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
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.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
Expand Down Expand Up @@ -698,7 +698,7 @@ Slice<Target> findByFilterOrderByLinkedDistributionSet(@NotNull Pageable pageabl
* in case one of the meta data entry already exists for the
* specific key
*
* @throws QuotaExceededException
* @throws AssignmentQuotaExceededException
* if the maximum number of {@link MetaData} entries is exceeded
* for the addressed {@link Target}
*/
Expand Down

0 comments on commit c540f8c

Please sign in to comment.