Fixed download progress event.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
kaizimmerm
2016-07-07 14:46:29 +02:00
parent a9204fe5eb
commit 8fb2bd4322
15 changed files with 73 additions and 127 deletions

View File

@@ -93,12 +93,12 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
// we set a download status only if we are aware of the
// targetid, i.e. authenticated and not anonymous
if (targetid != null && !"anonymous".equals(targetid)) {
final Action action = checkAndReportDownloadByTarget(
final ActionStatus actionStatus = checkAndReportDownloadByTarget(
requestResponseContextHolder.getHttpServletRequest(), targetid, artifact);
result = RestResourceConversionHelper.writeFileResponse(artifact,
requestResponseContextHolder.getHttpServletResponse(),
requestResponseContextHolder.getHttpServletRequest(), file, controllerManagement,
action.getId());
actionStatus.getId());
} else {
result = RestResourceConversionHelper.writeFileResponse(artifact,
requestResponseContextHolder.getHttpServletResponse(),
@@ -131,7 +131,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
return new ResponseEntity<>(HttpStatus.OK);
}
private Action checkAndReportDownloadByTarget(final HttpServletRequest request, final String targetid,
private ActionStatus checkAndReportDownloadByTarget(final HttpServletRequest request, final String targetid,
final LocalArtifact artifact) {
final Target target = controllerManagement.updateLastTargetQuery(targetid,
IpUtil.getClientIpFromRequest(request, securityProperties));
@@ -152,8 +152,8 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
actionStatus.addMessage(
RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI());
}
controllerManagement.addInformationalActionStatus(actionStatus);
return action;
return controllerManagement.addInformationalActionStatus(actionStatus);
}
}

View File

@@ -156,8 +156,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
result = new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
} else {
final Action action = checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(), target,
module);
final ActionStatus action = checkAndLogDownload(requestResponseContextHolder.getHttpServletRequest(),
target, module);
result = RestResourceConversionHelper.writeFileResponse(artifact,
requestResponseContextHolder.getHttpServletResponse(),
requestResponseContextHolder.getHttpServletRequest(), file, controllerManagement,
@@ -167,7 +167,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
return result;
}
private Action checkAndLogDownload(final HttpServletRequest request, final Target target,
private ActionStatus checkAndLogDownload(final HttpServletRequest request, final Target target,
final SoftwareModule module) {
final Action action = controllerManagement
.getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module);
@@ -185,8 +185,8 @@ public class DdiRootController implements DdiRootControllerRestApi {
statusMessage.addMessage(
RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI());
}
controllerManagement.addInformationalActionStatus(statusMessage);
return action;
return controllerManagement.addInformationalActionStatus(statusMessage);
}
private static boolean checkModule(final String fileName, final SoftwareModule module) {

View File

@@ -67,6 +67,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
private volatile int downLoadProgress = 0;
private volatile long shippedBytes = 0;
private volatile long shippedBytesTotal = 0;
@Autowired
private EventBus eventBus;
@@ -240,7 +241,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
public void downloadArtifactThroughFileName() throws Exception {
downLoadProgress = 1;
shippedBytes = 0;
tenantStatsManagement.resetTrafficStatsOfTenant();
shippedBytesTotal = 0;
eventBus.register(this);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
@@ -281,8 +282,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// download complete
assertThat(downLoadProgress).isEqualTo(10);
assertThat(shippedBytes).isEqualTo(ARTIFACT_SIZE)
.isEqualTo(tenantStatsManagement.getStatsOfTenant().getOverallArtifactTrafficInBytes());
assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(ARTIFACT_SIZE);
}
@Test
@@ -321,7 +321,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
public void downloadArtifactByNameFailsIfNotAuthenticated() throws Exception {
downLoadProgress = 1;
shippedBytes = 0;
tenantStatsManagement.resetTrafficStatsOfTenant();
shippedBytesTotal = 0;
eventBus.register(this);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
@@ -329,7 +329,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create target
Target target = entityFactory.generateTarget("4712");
target = targetManagement.createTarget(target);
final List<Target> targets = new ArrayList();
final List<Target> targets = new ArrayList<>();
targets.add(target);
// create ds
@@ -337,7 +337,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// create artifact
final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE);
final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false);
// download fails as artifact is not yet assigned to target
@@ -346,8 +346,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
.andExpect(status().isNotFound());
assertThat(downLoadProgress).isEqualTo(1);
assertThat(shippedBytes).isEqualTo(0)
.isEqualTo(tenantStatsManagement.getStatsOfTenant().getOverallArtifactTrafficInBytes());
assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(0L);
}
@Test
@@ -356,7 +355,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
public void downloadArtifactByNameByNamedController() throws Exception {
downLoadProgress = 1;
shippedBytes = 0;
tenantStatsManagement.resetTrafficStatsOfTenant();
shippedBytesTotal = 0;
eventBus.register(this);
assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0);
@@ -404,8 +403,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
// download complete
assertThat(downLoadProgress).isEqualTo(10);
assertThat(shippedBytes).isEqualTo(ARTIFACT_SIZE)
.isEqualTo(tenantStatsManagement.getStatsOfTenant().getOverallArtifactTrafficInBytes());
assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(ARTIFACT_SIZE);
}
@Test
@@ -567,6 +565,8 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong
@Subscribe
public void listen(final DownloadProgressEvent event) {
downLoadProgress++;
shippedBytes += event.getShippedBytes();
shippedBytes += event.getShippedBytesSinceLast();
shippedBytesTotal = event.getShippedBytesOverall();
}
}