Fixed download progress event.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -451,8 +451,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void addInformationalActionStatus(final ActionStatus statusMessage) {
|
||||
actionStatusRepository.save((JpaActionStatus) statusMessage);
|
||||
public ActionStatus addInformationalActionStatus(final ActionStatus statusMessage) {
|
||||
return actionStatusRepository.save((JpaActionStatus) statusMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -469,8 +469,9 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadProgressPercent(final long statusId, final int progressPercent, final long shippedBytes) {
|
||||
cacheWriteNotify.downloadProgressPercent(statusId, progressPercent, shippedBytes);
|
||||
public void downloadProgressPercent(final long statusId, final int progressPercent,
|
||||
final long shippedBytesSinceLast, final long shippedBytesOverall) {
|
||||
cacheWriteNotify.downloadProgressPercent(statusId, progressPercent, shippedBytesSinceLast, shippedBytesOverall);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
|
||||
import org.eclipse.hawkbit.repository.TenantStatsManagement;
|
||||
import org.eclipse.hawkbit.repository.report.model.TenantUsage;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
@@ -23,8 +19,6 @@ import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
/**
|
||||
* Management service for statistics of a single tenant.
|
||||
*
|
||||
@@ -44,8 +38,6 @@ public class JpaTenantStatsManagement implements TenantStatsManagement {
|
||||
@Autowired
|
||||
private TenantAware tenantAware;
|
||||
|
||||
private final Map<String, AtomicLong> traffic = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED)
|
||||
public TenantUsage getStatsOfTenant() {
|
||||
@@ -64,26 +56,9 @@ public class JpaTenantStatsManagement implements TenantStatsManagement {
|
||||
}
|
||||
|
||||
result.setActions(actionRepository.count());
|
||||
if (traffic.containsKey(tenant)) {
|
||||
result.setOverallArtifactTrafficInBytes(traffic.get(tenant).get());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTrafficStatsOfTenant() {
|
||||
traffic.remove(tenantAware.getCurrentTenant());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void listen(final DownloadProgressEvent event) {
|
||||
if (traffic.containsKey(event.getTenant())) {
|
||||
traffic.get(event.getTenant()).addAndGet(event.getShippedBytes());
|
||||
} else {
|
||||
traffic.put(event.getTenant(), new AtomicLong(event.getShippedBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository.jpa.cache;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
|
||||
import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
@@ -54,12 +53,15 @@ public class CacheWriteNotify {
|
||||
* the ID of the {@link ActionStatus}
|
||||
* @param progressPercent
|
||||
* the progress in percentage which must be between 0-100
|
||||
* @param shippedBytes
|
||||
* @param shippedBytesSinceLast
|
||||
* since last event
|
||||
* @param shippedBytesOverall
|
||||
* for the download request
|
||||
*/
|
||||
public void downloadProgressPercent(final long statusId, final int progressPercent, final long shippedBytes) {
|
||||
public void downloadProgressPercent(final long statusId, final int progressPercent,
|
||||
final long shippedBytesSinceLast, final long shippedBytesOverall) {
|
||||
|
||||
final Cache cache = cacheManager.getCache(Action.class.getName());
|
||||
final Cache cache = cacheManager.getCache(ActionStatus.class.getName());
|
||||
final String cacheKey = CacheKeys.entitySpecificCacheKey(String.valueOf(statusId),
|
||||
CacheKeys.DOWNLOAD_PROGRESS_PERCENT);
|
||||
if (progressPercent < DOWNLOAD_PROGRESS_MAX) {
|
||||
@@ -71,8 +73,8 @@ public class CacheWriteNotify {
|
||||
cache.evict(cacheKey);
|
||||
}
|
||||
|
||||
eventBus.post(
|
||||
new DownloadProgressEvent(tenantAware.getCurrentTenant(), statusId, progressPercent, shippedBytes));
|
||||
eventBus.post(new DownloadProgressEvent(tenantAware.getCurrentTenant(), statusId, progressPercent,
|
||||
shippedBytesSinceLast, shippedBytesOverall));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -61,12 +61,12 @@ public class CacheWriteNotifyTest {
|
||||
final long knownStatusId = 1;
|
||||
final int knownPercentage = 23;
|
||||
|
||||
when(cacheManagerMock.getCache(Action.class.getName())).thenReturn(cacheMock);
|
||||
when(cacheManagerMock.getCache(ActionStatus.class.getName())).thenReturn(cacheMock);
|
||||
when(tenantAwareMock.getCurrentTenant()).thenReturn("default");
|
||||
|
||||
underTest.downloadProgressPercent(knownStatusId, knownPercentage, 100L);
|
||||
underTest.downloadProgressPercent(knownStatusId, knownPercentage, 100L, 500L);
|
||||
|
||||
verify(cacheManagerMock).getCache(eq(Action.class.getName()));
|
||||
verify(cacheManagerMock).getCache(eq(ActionStatus.class.getName()));
|
||||
verify(cacheMock).put(knownStatusId + "." + CacheKeys.DOWNLOAD_PROGRESS_PERCENT, knownPercentage);
|
||||
verify(eventBusMock).post(any(DownloadProgressEvent.class));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user