Tune/fix action cleanup tenant properties (#2782)
* actions.cleanup.onQuotaHit.percent -> action.cleanup.onQuotaHit.percent * action.cleanup.enabled - removed - instead enabled / disable <=> expire < / >= 0 * action.cleanup.actionExpiry -> action.cleanup.auto.expiry and action.cleanup.auto.status - so both are under action.cleanup.auto, and differentiate from on quota hit * auto db convert of props with one backward incompatibility - if you had action.cleanup.enabled=true and not set action.cleanup.actionExpiry (assuming default 30 days) - auto cleanup will be disabled you should set action.cleanup.auto.expiry=2592000000 in order to get the old behavior * Note that if you have configured global action cleanup the properties are changed also this config you shall change manually Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -10,9 +10,8 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.autocleanup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.ACTION_CLEANUP_ACTION_EXPIRY;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.ACTION_CLEANUP_ACTION_STATUS;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.ACTION_CLEANUP_ENABLED;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.ACTION_CLEANUP_AUTO_EXPIRY;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.ACTION_CLEANUP_AUTO_STATUS;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -44,7 +43,7 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void runningActionsAreNotCleanedUp() {
|
||||
// cleanup config for this test case
|
||||
setupCleanupConfiguration(true, 0, Action.Status.CANCELED, Action.Status.ERROR);
|
||||
setupCleanupConfiguration(0, Action.Status.CANCELED, Action.Status.ERROR);
|
||||
|
||||
final Target trg1 = testdataFactory.createTarget("trg1");
|
||||
final Target trg2 = testdataFactory.createTarget("trg2");
|
||||
@@ -69,7 +68,7 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void cleanupDisabled() {
|
||||
// cleanup config for this test case
|
||||
setupCleanupConfiguration(false, 0, Action.Status.CANCELED);
|
||||
setupCleanupConfiguration(-1L, Action.Status.CANCELED);
|
||||
|
||||
final Target trg1 = testdataFactory.createTarget("trg1");
|
||||
final Target trg2 = testdataFactory.createTarget("trg2");
|
||||
@@ -96,7 +95,7 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void canceledAndFailedActionsAreCleanedUp() {
|
||||
// cleanup config for this test case
|
||||
setupCleanupConfiguration(true, 0, Action.Status.CANCELED, Action.Status.ERROR);
|
||||
setupCleanupConfiguration( 0, Action.Status.CANCELED, Action.Status.ERROR);
|
||||
|
||||
final Target trg1 = testdataFactory.createTarget("trg1");
|
||||
final Target trg2 = testdataFactory.createTarget("trg2");
|
||||
@@ -129,7 +128,7 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void canceledActionsAreCleanedUp() {
|
||||
// cleanup config for this test case
|
||||
setupCleanupConfiguration(true, 0, Action.Status.CANCELED);
|
||||
setupCleanupConfiguration(0, Action.Status.CANCELED);
|
||||
|
||||
final Target trg1 = testdataFactory.createTarget("trg1");
|
||||
final Target trg2 = testdataFactory.createTarget("trg2");
|
||||
@@ -164,7 +163,7 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
@SuppressWarnings("squid:S2925")
|
||||
void canceledAndFailedActionsAreCleanedUpWhenExpired() throws InterruptedException {
|
||||
// cleanup config for this test case
|
||||
setupCleanupConfiguration(true, 500, Action.Status.CANCELED, Action.Status.ERROR);
|
||||
setupCleanupConfiguration(500, Action.Status.CANCELED, Action.Status.ERROR);
|
||||
|
||||
final Target trg1 = testdataFactory.createTarget("trg1");
|
||||
final Target trg2 = testdataFactory.createTarget("trg2");
|
||||
@@ -206,11 +205,10 @@ class AutoActionCleanupTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.addUpdateActionStatus(ActionStatusCreate.builder().actionId(id).status(Status.ERROR).build());
|
||||
}
|
||||
|
||||
private void setupCleanupConfiguration(final boolean cleanupEnabled, final long expiry, final Status... status) {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(ACTION_CLEANUP_ENABLED, cleanupEnabled);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(ACTION_CLEANUP_ACTION_EXPIRY, expiry);
|
||||
private void setupCleanupConfiguration(final long expiry, final Status... status) {
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(ACTION_CLEANUP_AUTO_EXPIRY, expiry);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(
|
||||
ACTION_CLEANUP_ACTION_STATUS,
|
||||
ACTION_CLEANUP_AUTO_STATUS,
|
||||
Arrays.stream(status).map(Status::toString).collect(Collectors.joining(",")));
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,11 @@ package org.eclipse.hawkbit.repository.jpa.autocleanup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.AutoCleanupScheduler.CleanupTask;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -44,12 +45,10 @@ class AutoCleanupSchedulerTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void executeHandlerChain() {
|
||||
|
||||
new AutoCleanupScheduler(systemManagement, systemSecurityContext, lockRegistry, Arrays.asList(
|
||||
new SuccessfulCleanup(), new SuccessfulCleanup(), new FailingCleanup(), new SuccessfulCleanup())).run();
|
||||
|
||||
new AutoCleanupScheduler(
|
||||
List.of(new SuccessfulCleanup(), new SuccessfulCleanup(), new FailingCleanup(), new SuccessfulCleanup()),
|
||||
systemManagement, systemSecurityContext, lockRegistry).run();
|
||||
assertThat(counter.get()).isEqualTo(4);
|
||||
|
||||
}
|
||||
|
||||
private class SuccessfulCleanup implements CleanupTask {
|
||||
|
||||
@@ -1698,7 +1698,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
() -> assignDistributionSet(exceededQuotaDsAssign.getId(), target.getControllerId()));
|
||||
|
||||
// set purge config to 25 %
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration("actions.cleanup.onQuotaHit.percent", 25);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ACTION_PURGE_PERCENTAGE_ON_QUOTA_HIT, 25);
|
||||
|
||||
// assign again
|
||||
assignDistributionSet(exceededQuotaDsAssign.getId(), target.getControllerId());
|
||||
@@ -1739,7 +1739,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertEquals(20, deploymentManagement.countActionsByTarget(target.getControllerId()));
|
||||
|
||||
// set purge config to 25 %
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration("actions.cleanup.onQuotaHit.percent", 25);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ACTION_PURGE_PERCENTAGE_ON_QUOTA_HIT, 25);
|
||||
rolloutHandler.handleAll();
|
||||
assertEquals(16, deploymentManagement.countActionsByTarget(target.getControllerId()));
|
||||
|
||||
@@ -1762,7 +1762,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
rolloutHandler.handleAll();
|
||||
}
|
||||
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration("actions.cleanup.onQuotaHit.percent", 25);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.ACTION_PURGE_PERCENTAGE_ON_QUOTA_HIT, 25);
|
||||
deploymentManagement.handleMaxAssignmentsExceeded(target.getId(), 5L, new AssignmentQuotaExceededException());
|
||||
// only 3 actions should be deleted in such case :
|
||||
assertEquals(15, deploymentManagement.countActionsByTarget(target.getControllerId()));
|
||||
|
||||
@@ -140,7 +140,7 @@ class ManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
// jacoco adds some methods with bytecode instrumentation
|
||||
.filter(method -> !"$jacocoInit".equals(method.getName()))
|
||||
// skip maxAssignmentsExceededHandler in DeploymentManagement since it throws quota exception
|
||||
// because of actions.cleanup.onQuotaHit.percent not configured
|
||||
// because of action.cleanup.onQuotaHit.percent not configured
|
||||
// other option would be to configure it for all tests
|
||||
.filter(method -> !"handleMaxAssignmentsExceeded".equals(method.getName()))
|
||||
.map(method -> Arguments.of(clazz, method)))
|
||||
|
||||
Reference in New Issue
Block a user