Simulator throughpout improvements.
Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -10,8 +10,6 @@ package org.eclipse.hawkbit.simulator;
|
|||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.DigestOutputStream;
|
import java.security.DigestOutputStream;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
@@ -34,6 +32,7 @@ import org.apache.http.conn.ssl.SSLContextBuilder;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.eclipse.hawkbit.dmf.json.model.Artifact;
|
import org.eclipse.hawkbit.dmf.json.model.Artifact;
|
||||||
|
import org.eclipse.hawkbit.dmf.json.model.Artifact.UrlProtocol;
|
||||||
import org.eclipse.hawkbit.dmf.json.model.SoftwareModule;
|
import org.eclipse.hawkbit.dmf.json.model.SoftwareModule;
|
||||||
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol;
|
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol;
|
||||||
import org.eclipse.hawkbit.simulator.UpdateStatus.ResponseStatus;
|
import org.eclipse.hawkbit.simulator.UpdateStatus.ResponseStatus;
|
||||||
@@ -59,7 +58,7 @@ import com.google.common.io.ByteStreams;
|
|||||||
public class DeviceSimulatorUpdater {
|
public class DeviceSimulatorUpdater {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceSimulatorUpdater.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DeviceSimulatorUpdater.class);
|
||||||
|
|
||||||
private static final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(4);
|
private static final ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(8);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SpSenderService spSenderService;
|
private SpSenderService spSenderService;
|
||||||
@@ -198,18 +197,14 @@ public class DeviceSimulatorUpdater {
|
|||||||
|
|
||||||
private static void handleArtifacts(final String targetToken, final List<UpdateStatus> status,
|
private static void handleArtifacts(final String targetToken, final List<UpdateStatus> status,
|
||||||
final Artifact artifact) {
|
final Artifact artifact) {
|
||||||
artifact.getUrls().entrySet().forEach(entry -> {
|
|
||||||
switch (entry.getKey()) {
|
if (artifact.getUrls().containsKey(UrlProtocol.HTTPS)) {
|
||||||
case HTTP:
|
status.add(downloadUrl(artifact.getUrls().get(UrlProtocol.HTTPS), targetToken,
|
||||||
case HTTPS:
|
artifact.getHashes().getSha1(), artifact.getSize()));
|
||||||
status.add(downloadUrl(entry.getValue(), targetToken, artifact.getHashes().getSha1(),
|
} else if (artifact.getUrls().containsKey(UrlProtocol.HTTP)) {
|
||||||
artifact.getSize()));
|
status.add(downloadUrl(artifact.getUrls().get(UrlProtocol.HTTP), targetToken,
|
||||||
break;
|
artifact.getHashes().getSha1(), artifact.getSize()));
|
||||||
default:
|
}
|
||||||
// not supported yet
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UpdateStatus downloadUrl(final String url, final String targetToken, final String sha1Hash,
|
private static UpdateStatus downloadUrl(final String url, final String targetToken, final String sha1Hash,
|
||||||
@@ -236,22 +231,15 @@ public class DeviceSimulatorUpdater {
|
|||||||
return new UpdateStatus(ResponseStatus.ERROR, message);
|
return new UpdateStatus(ResponseStatus.ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
final File tempFile = File.createTempFile("uploadFile", null);
|
|
||||||
|
|
||||||
// Exception squid:S2070 - not used for hashing sensitive
|
// Exception squid:S2070 - not used for hashing sensitive
|
||||||
// data
|
// data
|
||||||
@SuppressWarnings("squid:S2070")
|
@SuppressWarnings("squid:S2070")
|
||||||
final MessageDigest md = MessageDigest.getInstance("SHA-1");
|
final MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||||
|
|
||||||
try (final DigestOutputStream dos = new DigestOutputStream(new FileOutputStream(tempFile), md)) {
|
try (final BufferedOutputStream bdos = new BufferedOutputStream(
|
||||||
try (final BufferedOutputStream bdos = new BufferedOutputStream(dos)) {
|
new DigestOutputStream(ByteStreams.nullOutputStream(), md))) {
|
||||||
try (BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) {
|
try (BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent())) {
|
||||||
overallread = ByteStreams.copy(bis, bdos);
|
overallread = ByteStreams.copy(bis, bdos);
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (tempFile != null && !tempFile.delete()) {
|
|
||||||
LOGGER.error("Could not delete temporary file: {}", tempFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user