Introduce basic functionality for invalidation of distributionsets (#1179)

* Basic DS invalidation functionality

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Add checks for valid/complete DS

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Stop rollouts + auto assignments when invalidating a DS

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Add methods to count AAs + rollouts for invalidation

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Small refactoring for DS management

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Add invalidation functionality to REST API

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Fix update stopped rollouts status

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Add various tests

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Introduce countActionsForInvalidation

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Fix event tests with incomplete DS

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Add H2 migration script

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Fix action count method

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Fix REST documentation tests

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Change flyway version number

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Add lock for DS invalidation + adapt tests

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Move concurrency test to own class

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Handle possible InterruptedException

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Fix concurrency test

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Use one transaction for all invalidations

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Add invalidate endpoint to REST docu

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Execute invalidation in transaction when actions are cancelled

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Check that distribution set is valid when editing/creating metadata

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Remove all changes in UI

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Add DB migration files for all databases

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Implement review findings

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Move DS invalidation to own class to check permissions for single steps

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Move invalidation count methods to management classes

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>

* Fix failing tests

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>
This commit is contained in:
Sebastian Firsching
2021-09-30 15:26:36 +02:00
committed by GitHub
parent b25e118e6c
commit 825cb64448
66 changed files with 2413 additions and 511 deletions

View File

@@ -21,6 +21,7 @@ import org.eclipse.hawkbit.repository.event.remote.MultiActionAssignEvent;
import org.eclipse.hawkbit.repository.event.remote.MultiActionCancelEvent;
import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.RolloutGroupDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.RolloutStoppedEvent;
import org.eclipse.hawkbit.repository.event.remote.SoftwareModuleDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.SoftwareModuleTypeDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
@@ -60,7 +61,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.TenantConfigurationUpd
* The {@link EventType} class declares the event-type and it's corresponding
* encoding value in the payload of an remote header. The event-type is encoded
* into the payload of the message which is distributed.
*
*
* To encode and decode the event class type we need some conversation mapping
* between the actual class and the corresponding integer value which is the
* encoded value in the byte-payload.
@@ -146,6 +147,9 @@ public class EventType {
TYPES.put(40, TenantConfigurationCreatedEvent.class);
TYPES.put(41, TenantConfigurationUpdatedEvent.class);
TYPES.put(42, TenantConfigurationDeletedEvent.class);
// rollout stopped due to invalidated distribution set
TYPES.put(43, RolloutStoppedEvent.class);
}
private int value;
@@ -159,7 +163,7 @@ public class EventType {
/**
* Constructor.
*
*
* @param value
* the value to initialize
*/
@@ -177,7 +181,7 @@ public class EventType {
/**
* Returns a {@link EventType} based on the given class type.
*
*
* @param clazz
* the clazz type to retrieve the corresponding {@link EventType}
* .

View File

@@ -18,6 +18,7 @@ import org.eclipse.hawkbit.cache.TenancyCacheManager;
import org.eclipse.hawkbit.cache.TenantAwareCacheManager;
import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.RolloutGroupDeletedEvent;
import org.eclipse.hawkbit.repository.event.remote.RolloutStoppedEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.AbstractActionEvent;
import org.eclipse.hawkbit.repository.model.Rollout;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
@@ -67,7 +68,7 @@ public class RolloutStatusCache {
/**
* Retrieves cached list of {@link TotalTargetCountActionStatus} of
* {@link Rollout}s.
*
*
* @param rollouts
* rolloutIds to retrieve cache entries for
* @return map of cached entries
@@ -81,7 +82,7 @@ public class RolloutStatusCache {
/**
* Retrieves cached list of {@link TotalTargetCountActionStatus} of
* {@link Rollout}s.
*
*
* @param rolloutId
* to retrieve cache entries for
* @return map of cached entries
@@ -95,7 +96,7 @@ public class RolloutStatusCache {
/**
* Retrieves cached list of {@link TotalTargetCountActionStatus} of
* {@link RolloutGroup}s.
*
*
* @param rolloutGroups
* rolloutGroupsIds to retrieve cache entries for
* @return map of cached entries
@@ -109,7 +110,7 @@ public class RolloutStatusCache {
/**
* Retrieves cached list of {@link TotalTargetCountActionStatus} of
* {@link RolloutGroup}.
*
*
* @param groupId
* to retrieve cache entries for
* @return map of cached entries
@@ -123,7 +124,7 @@ public class RolloutStatusCache {
/**
* Put map of {@link TotalTargetCountActionStatus} for multiple
* {@link Rollout}s into cache.
*
*
* @param put
* map of cached entries
*/
@@ -135,12 +136,12 @@ public class RolloutStatusCache {
/**
* Put {@link TotalTargetCountActionStatus} for one {@link Rollout}s into
* cache.
*
*
* @param rolloutId
* the cache entries belong to
* @param status
* list to cache
*
*
*/
public void putRolloutStatus(final Long rolloutId, final List<TotalTargetCountActionStatus> status) {
final Cache cache = cacheManager.getCache(CACHE_RO_NAME);
@@ -150,7 +151,7 @@ public class RolloutStatusCache {
/**
* Put {@link TotalTargetCountActionStatus} for multiple
* {@link RolloutGroup}s into cache.
*
*
* @param put
* map of cached entries
*/
@@ -162,7 +163,7 @@ public class RolloutStatusCache {
/**
* Put {@link TotalTargetCountActionStatus} for multiple
* {@link RolloutGroup}s into cache.
*
*
* @param groupId
* the cache entries belong to
* @param status
@@ -223,6 +224,18 @@ public class RolloutStatusCache {
cache.evict(event.getEntityId());
}
@EventListener(classes = RolloutStoppedEvent.class)
void invalidateCachedTotalTargetCountOnRolloutStopped(final RolloutStoppedEvent event) {
final Cache cache = tenantAware.runAsTenant(event.getTenant(), () -> cacheManager.getCache(CACHE_RO_NAME));
cache.evict(event.getRolloutId());
for (final long groupId : event.getRolloutGroupIds()) {
final Cache groupCache = tenantAware.runAsTenant(event.getTenant(),
() -> cacheManager.getCache(CACHE_GR_NAME));
groupCache.evict(groupId);
}
}
/**
* Evicts all caches for a given tenant. All caches under a certain tenant
* gets evicted.