Removed percentage from the event. Moved event into the repo API.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -45,6 +45,12 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
|
<artifactId>hawkbit-repository-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import static org.mockito.Mockito.verify;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.EntityEvent;
|
import org.eclipse.hawkbit.eventbus.event.EntityEvent;
|
||||||
|
import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -56,7 +56,7 @@ public class EventDistributorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void distributeDistributedEventSendsToRedis() {
|
public void distributeDistributedEventSendsToRedis() {
|
||||||
|
|
||||||
final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 10, 100L, 200L);
|
final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 500L, 100L, 200L);
|
||||||
underTest.distribute(event);
|
underTest.distribute(event);
|
||||||
|
|
||||||
// origin node ID should be set by distributing the event
|
// origin node ID should be set by distributing the event
|
||||||
@@ -67,7 +67,7 @@ public class EventDistributorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void dontDistributeDistributedEventIfSameNode() {
|
public void dontDistributeDistributedEventIfSameNode() {
|
||||||
final String knownNodeId = EventDistributor.getNodeId();
|
final String knownNodeId = EventDistributor.getNodeId();
|
||||||
final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 10, 100L, 200L);
|
final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 500L, 100L, 200L);
|
||||||
event.setNodeId(knownNodeId);
|
event.setNodeId(knownNodeId);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@@ -79,7 +79,7 @@ public class EventDistributorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleDistributedMessageFromRedis() {
|
public void handleDistributedMessageFromRedis() {
|
||||||
final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 10, 100L, 200L);
|
final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 500L, 100L, 200L);
|
||||||
final String knownChannel = "someChannel";
|
final String knownChannel = "someChannel";
|
||||||
|
|
||||||
underTest.handleMessage(event, knownChannel);
|
underTest.handleMessage(event, knownChannel);
|
||||||
@@ -90,7 +90,7 @@ public class EventDistributorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleDistributedMessageFilteredIfSameNodeId() {
|
public void handleDistributedMessageFilteredIfSameNodeId() {
|
||||||
final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 10, 100L, 200L);
|
final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 500L, 100L, 200L);
|
||||||
final String knownChannel = "someChannel";
|
final String knownChannel = "someChannel";
|
||||||
event.setOriginNodeId(EventDistributor.getNodeId());
|
event.setOriginNodeId(EventDistributor.getNodeId());
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomUtils;
|
import org.apache.commons.lang3.RandomUtils;
|
||||||
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
|
import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent;
|
||||||
import org.eclipse.hawkbit.repository.model.Action;
|
import org.eclipse.hawkbit.repository.model.Action;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
|
|
||||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||||
|
import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent;
|
||||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||||
import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException;
|
import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException;
|
||||||
@@ -58,21 +58,20 @@ public interface ControllerManagement {
|
|||||||
Action addCancelActionStatus(@NotNull ActionStatus actionStatus);
|
Action addCancelActionStatus(@NotNull ActionStatus actionStatus);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the download progress in percentage and notifies the
|
* Sends the download progress and notifies the {@link EventBus} with a
|
||||||
* {@link EventBus} with a {@link DownloadProgressEvent}.
|
* {@link DownloadProgressEvent}.
|
||||||
*
|
*
|
||||||
* @param statusId
|
* @param statusId
|
||||||
* the ID of the {@link ActionStatus}
|
* the ID of the {@link ActionStatus}
|
||||||
* @param progressPercent
|
* @param requestedBytes
|
||||||
* the progress in percentage which must be between 0-100
|
* requested bytes of the request
|
||||||
* @param shippedBytesSinceLast
|
* @param shippedBytesSinceLast
|
||||||
* since the last report
|
* since the last report
|
||||||
* @param shippedBytesOverall
|
* @param shippedBytesOverall
|
||||||
* for the {@link ActionStatus}
|
* for the {@link ActionStatus}
|
||||||
*/
|
*/
|
||||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||||
void downloadProgressPercent(long statusId, int progressPercent, long shippedBytesSinceLast,
|
void downloadProgress(Long statusId, Long requestedBytes, Long shippedBytesSinceLast, Long shippedBytesOverall);
|
||||||
long shippedBytesOverall);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple addition of a new {@link ActionStatus} entry to the {@link Action}
|
* Simple addition of a new {@link ActionStatus} entry to the {@link Action}
|
||||||
|
|||||||
@@ -16,10 +16,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
* Management service for statistics of a single tenant.
|
* Management service for statistics of a single tenant.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
public interface TenantStatsManagement {
|
public interface TenantStatsManagement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for stats of a single tenant.
|
* Service for stats of the current tenant.
|
||||||
*
|
*
|
||||||
* @return collected statistics
|
* @return collected statistics
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.eventbus.event;
|
package org.eclipse.hawkbit.repository.eventbus.event;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event that contains an updated download progress for a given Action.
|
* Event that contains an updated download progress for a given ActionStatus
|
||||||
*
|
* that was written for a download request.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DownloadProgressEvent extends AbstractDistributedEvent {
|
public class DownloadProgressEvent extends AbstractDistributedEvent {
|
||||||
@@ -20,7 +20,7 @@ public class DownloadProgressEvent extends AbstractDistributedEvent {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final Long statusId;
|
private final Long statusId;
|
||||||
private final int progressPercent;
|
private final long requestedBytes;
|
||||||
private final long shippedBytesSinceLast;
|
private final long shippedBytesSinceLast;
|
||||||
private final long shippedBytesOverall;
|
private final long shippedBytesOverall;
|
||||||
|
|
||||||
@@ -30,22 +30,21 @@ public class DownloadProgressEvent extends AbstractDistributedEvent {
|
|||||||
* @param tenant
|
* @param tenant
|
||||||
* the tenant for this event
|
* the tenant for this event
|
||||||
* @param statusId
|
* @param statusId
|
||||||
* of {@link ActionStatus}
|
* of ActionStatus that was written for the download request
|
||||||
* @param progressPercent
|
* @param requestedBytes
|
||||||
* number (1-100)
|
* bytes requested
|
||||||
* @param shippedBytesSinceLast
|
* @param shippedBytesSinceLast
|
||||||
* bytes since last event
|
* bytes since last event
|
||||||
* @param shippedBytesOverall
|
* @param shippedBytesOverall
|
||||||
* on the download request
|
* on the download request
|
||||||
*/
|
*/
|
||||||
public DownloadProgressEvent(final String tenant, final Long statusId, final int progressPercent,
|
public DownloadProgressEvent(final String tenant, final Long statusId, final Long requestedBytes,
|
||||||
final long shippedBytesSinceLast, final long shippedBytesOverall) {
|
final Long shippedBytesSinceLast, final Long shippedBytesOverall) {
|
||||||
// the revision of the DownloadProgressEvent is just equal the
|
// the revision of the DownloadProgressEvent is just equal the
|
||||||
// progressPercentage due the
|
// shippedBytesOverall as this is a growing number.
|
||||||
// percentage is going from 0 to 100.
|
super(shippedBytesOverall, tenant);
|
||||||
super(statusId, tenant);
|
|
||||||
this.statusId = statusId;
|
this.statusId = statusId;
|
||||||
this.progressPercent = progressPercent;
|
this.requestedBytes = requestedBytes;
|
||||||
this.shippedBytesSinceLast = shippedBytesSinceLast;
|
this.shippedBytesSinceLast = shippedBytesSinceLast;
|
||||||
this.shippedBytesOverall = shippedBytesOverall;
|
this.shippedBytesOverall = shippedBytesOverall;
|
||||||
}
|
}
|
||||||
@@ -54,8 +53,8 @@ public class DownloadProgressEvent extends AbstractDistributedEvent {
|
|||||||
return statusId;
|
return statusId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getProgressPercent() {
|
public long getRequestedBytes() {
|
||||||
return progressPercent;
|
return requestedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getShippedBytesSinceLast() {
|
public long getShippedBytesSinceLast() {
|
||||||
@@ -39,12 +39,6 @@ public interface Action extends TenantAwareBaseEntity {
|
|||||||
return Status.CANCELING.equals(getStatus()) || Status.CANCELED.equals(getStatus());
|
return Status.CANCELING.equals(getStatus()) || Status.CANCELED.equals(getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return current {@link Status#DOWNLOAD} progress if known by the update
|
|
||||||
* server.
|
|
||||||
*/
|
|
||||||
int getDownloadProgressPercent();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return current {@link Status} of the {@link Action}.
|
* @return current {@link Status} of the {@link Action}.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ public interface ActionStatus extends TenantAwareBaseEntity {
|
|||||||
*/
|
*/
|
||||||
void addMessage(String message);
|
void addMessage(String message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return current {@link Status#DOWNLOAD} progress if known by the update
|
||||||
|
* server.
|
||||||
|
*/
|
||||||
|
int getDownloadProgressPercent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list of message entries that can be added to the
|
* @return list of message entries that can be added to the
|
||||||
* {@link ActionStatus}.
|
* {@link ActionStatus}.
|
||||||
|
|||||||
@@ -469,9 +469,9 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadProgressPercent(final long statusId, final int progressPercent,
|
public void downloadProgress(final Long statusId, final Long requestedBytes, final Long shippedBytesSinceLast,
|
||||||
final long shippedBytesSinceLast, final long shippedBytesOverall) {
|
final Long shippedBytesOverall) {
|
||||||
cacheWriteNotify.downloadProgressPercent(statusId, progressPercent, shippedBytesSinceLast, shippedBytesOverall);
|
cacheWriteNotify.downloadProgress(statusId, requestedBytes, shippedBytesSinceLast, shippedBytesOverall);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.jpa.cache;
|
package org.eclipse.hawkbit.repository.jpa.cache;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent;
|
||||||
import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent;
|
import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||||
@@ -19,6 +21,7 @@ import org.springframework.cache.CacheManager;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
|
import com.google.common.math.DoubleMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An service which combines the functionality for functional use cases to write
|
* An service which combines the functionality for functional use cases to write
|
||||||
@@ -29,10 +32,6 @@ import com.google.common.eventbus.EventBus;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class CacheWriteNotify {
|
public class CacheWriteNotify {
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final int DOWNLOAD_PROGRESS_MAX = 100;
|
private static final int DOWNLOAD_PROGRESS_MAX = 100;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -45,25 +44,29 @@ public class CacheWriteNotify {
|
|||||||
private TenantAware tenantAware;
|
private TenantAware tenantAware;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* writes the download progress in percentage into the cache
|
* writes the download progress into the cache
|
||||||
* {@link CacheKeys#DOWNLOAD_PROGRESS_PERCENT} and notifies the
|
* {@link CacheKeys#DOWNLOAD_PROGRESS_PERCENT} and notifies the
|
||||||
* {@link EventBus} with a {@link DownloadProgressEvent}.
|
* {@link EventBus} with a {@link DownloadProgressEvent}.
|
||||||
*
|
*
|
||||||
* @param statusId
|
* @param statusId
|
||||||
* the ID of the {@link ActionStatus}
|
* the ID of the {@link ActionStatus}
|
||||||
* @param progressPercent
|
* @param requestedBytes
|
||||||
* the progress in percentage which must be between 0-100
|
* requested bytes of the request
|
||||||
* @param shippedBytesSinceLast
|
* @param shippedBytesSinceLast
|
||||||
* since last event
|
* since last event
|
||||||
* @param shippedBytesOverall
|
* @param shippedBytesOverall
|
||||||
* for the download request
|
* for the download request
|
||||||
*/
|
*/
|
||||||
public void downloadProgressPercent(final long statusId, final int progressPercent,
|
public void downloadProgress(final Long statusId, final Long requestedBytes, final Long shippedBytesSinceLast,
|
||||||
final long shippedBytesSinceLast, final long shippedBytesOverall) {
|
final Long shippedBytesOverall) {
|
||||||
|
|
||||||
final Cache cache = cacheManager.getCache(ActionStatus.class.getName());
|
final Cache cache = cacheManager.getCache(ActionStatus.class.getName());
|
||||||
final String cacheKey = CacheKeys.entitySpecificCacheKey(String.valueOf(statusId),
|
final String cacheKey = CacheKeys.entitySpecificCacheKey(String.valueOf(statusId),
|
||||||
CacheKeys.DOWNLOAD_PROGRESS_PERCENT);
|
CacheKeys.DOWNLOAD_PROGRESS_PERCENT);
|
||||||
|
|
||||||
|
final int progressPercent = DoubleMath.roundToInt(shippedBytesOverall * 100.0 / requestedBytes,
|
||||||
|
RoundingMode.DOWN);
|
||||||
|
|
||||||
if (progressPercent < DOWNLOAD_PROGRESS_MAX) {
|
if (progressPercent < DOWNLOAD_PROGRESS_MAX) {
|
||||||
cache.put(cacheKey, progressPercent);
|
cache.put(cacheKey, progressPercent);
|
||||||
} else {
|
} else {
|
||||||
@@ -73,7 +76,7 @@ public class CacheWriteNotify {
|
|||||||
cache.evict(cacheKey);
|
cache.evict(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
eventBus.post(new DownloadProgressEvent(tenantAware.getCurrentTenant(), statusId, progressPercent,
|
eventBus.post(new DownloadProgressEvent(tenantAware.getCurrentTenant(), statusId, requestedBytes,
|
||||||
shippedBytesSinceLast, shippedBytesOverall));
|
shippedBytesSinceLast, shippedBytesOverall));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,7 @@ import javax.persistence.NamedEntityGraphs;
|
|||||||
import javax.persistence.NamedSubgraph;
|
import javax.persistence.NamedSubgraph;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.persistence.Transient;
|
|
||||||
|
|
||||||
import org.eclipse.hawkbit.repository.jpa.cache.CacheField;
|
|
||||||
import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys;
|
|
||||||
import org.eclipse.hawkbit.repository.model.Action;
|
import org.eclipse.hawkbit.repository.model.Action;
|
||||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||||
@@ -89,13 +86,6 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
|
|||||||
@JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rollout"))
|
@JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rollout"))
|
||||||
private JpaRollout rollout;
|
private JpaRollout rollout;
|
||||||
|
|
||||||
/**
|
|
||||||
* Note: filled only in {@link Status#DOWNLOAD}.
|
|
||||||
*/
|
|
||||||
@Transient
|
|
||||||
@CacheField(key = CacheKeys.DOWNLOAD_PROGRESS_PERCENT)
|
|
||||||
private int downloadProgressPercent;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DistributionSet getDistributionSet() {
|
public DistributionSet getDistributionSet() {
|
||||||
return distributionSet;
|
return distributionSet;
|
||||||
@@ -120,15 +110,6 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getDownloadProgressPercent() {
|
|
||||||
return downloadProgressPercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDownloadProgressPercent(final int downloadProgressPercent) {
|
|
||||||
this.downloadProgressPercent = downloadProgressPercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return active;
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ import javax.persistence.ManyToOne;
|
|||||||
import javax.persistence.NamedAttributeNode;
|
import javax.persistence.NamedAttributeNode;
|
||||||
import javax.persistence.NamedEntityGraph;
|
import javax.persistence.NamedEntityGraph;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Transient;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.repository.jpa.cache.CacheField;
|
||||||
|
import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys;
|
||||||
import org.eclipse.hawkbit.repository.model.Action;
|
import org.eclipse.hawkbit.repository.model.Action;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||||
@@ -63,6 +66,13 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements
|
|||||||
@Column(name = "detail_message", length = 512)
|
@Column(name = "detail_message", length = 512)
|
||||||
private final List<String> messages = new ArrayList<>();
|
private final List<String> messages = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: filled only in {@link Status#DOWNLOAD}.
|
||||||
|
*/
|
||||||
|
@Transient
|
||||||
|
@CacheField(key = CacheKeys.DOWNLOAD_PROGRESS_PERCENT)
|
||||||
|
private int downloadProgressPercent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link ActionStatus} object.
|
* Creates a new {@link ActionStatus} object.
|
||||||
*
|
*
|
||||||
@@ -105,6 +115,11 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements
|
|||||||
// JPA default constructor.
|
// JPA default constructor.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDownloadProgressPercent() {
|
||||||
|
return downloadProgressPercent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getOccurredAt() {
|
public Long getOccurredAt() {
|
||||||
return occurredAt;
|
return occurredAt;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import static org.mockito.Matchers.eq;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent;
|
import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent;
|
||||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -59,15 +59,14 @@ public class CacheWriteNotifyTest {
|
|||||||
@Test
|
@Test
|
||||||
public void downloadgProgressIsCachedAndEventSent() {
|
public void downloadgProgressIsCachedAndEventSent() {
|
||||||
final long knownStatusId = 1;
|
final long knownStatusId = 1;
|
||||||
final int knownPercentage = 23;
|
|
||||||
|
|
||||||
when(cacheManagerMock.getCache(ActionStatus.class.getName())).thenReturn(cacheMock);
|
when(cacheManagerMock.getCache(ActionStatus.class.getName())).thenReturn(cacheMock);
|
||||||
when(tenantAwareMock.getCurrentTenant()).thenReturn("default");
|
when(tenantAwareMock.getCurrentTenant()).thenReturn("default");
|
||||||
|
|
||||||
underTest.downloadProgressPercent(knownStatusId, knownPercentage, 100L, 500L);
|
underTest.downloadProgress(knownStatusId, 500L, 100L, 100L);
|
||||||
|
|
||||||
verify(cacheManagerMock).getCache(eq(ActionStatus.class.getName()));
|
verify(cacheManagerMock).getCache(eq(ActionStatus.class.getName()));
|
||||||
verify(cacheMock).put(knownStatusId + "." + CacheKeys.DOWNLOAD_PROGRESS_PERCENT, knownPercentage);
|
verify(cacheMock).put(knownStatusId + "." + CacheKeys.DOWNLOAD_PROGRESS_PERCENT, 20);
|
||||||
verify(eventBusMock).post(any(DownloadProgressEvent.class));
|
verify(eventBusMock).post(any(DownloadProgressEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.eclipse.hawkbit.repository.TagManagement;
|
|||||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||||
import org.eclipse.hawkbit.repository.TenantStatsManagement;
|
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||||
import org.eclipse.hawkbit.security.DosFilter;
|
import org.eclipse.hawkbit.security.DosFilter;
|
||||||
@@ -94,9 +93,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected TargetManagement targetManagement;
|
protected TargetManagement targetManagement;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
protected TenantStatsManagement tenantStatsManagement;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected TargetFilterQueryManagement targetFilterQueryManagement;
|
protected TargetFilterQueryManagement targetFilterQueryManagement;
|
||||||
|
|
||||||
|
|||||||
@@ -320,8 +320,7 @@ public final class RestResourceConversionHelper {
|
|||||||
// every 10 percent an event
|
// every 10 percent an event
|
||||||
if (newPercent == 100 || newPercent > progressPercent + 10) {
|
if (newPercent == 100 || newPercent > progressPercent + 10) {
|
||||||
progressPercent = newPercent;
|
progressPercent = newPercent;
|
||||||
controllerManagement.downloadProgressPercent(statusId, progressPercent, shippedSinceLastEvent,
|
controllerManagement.downloadProgress(statusId, length, shippedSinceLastEvent, total);
|
||||||
total);
|
|
||||||
shippedSinceLastEvent = 0;
|
shippedSinceLastEvent = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user