Fixed nullpointer exception and optimized the code here and there.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -42,6 +42,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||||||
*/
|
*/
|
||||||
public class ConfigurableScenario {
|
public class ConfigurableScenario {
|
||||||
|
|
||||||
|
private static final int PAGE_SIZE = 100;
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurableScenario.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurableScenario.class);
|
||||||
|
|
||||||
private final MgmtDistributionSetClientResource distributionSetResource;
|
private final MgmtDistributionSetClientResource distributionSetResource;
|
||||||
@@ -109,25 +111,25 @@ public class ConfigurableScenario {
|
|||||||
private void deleteSoftwareModules() {
|
private void deleteSoftwareModules() {
|
||||||
PagedList<MgmtSoftwareModule> modules;
|
PagedList<MgmtSoftwareModule> modules;
|
||||||
do {
|
do {
|
||||||
modules = softwareModuleResource.getSoftwareModules(0, 100, null, null).getBody();
|
modules = softwareModuleResource.getSoftwareModules(0, PAGE_SIZE, null, null).getBody();
|
||||||
modules.getContent().forEach(module -> softwareModuleResource.deleteSoftwareModule(module.getModuleId()));
|
modules.getContent().forEach(module -> softwareModuleResource.deleteSoftwareModule(module.getModuleId()));
|
||||||
} while (modules.getTotal() > 100);
|
} while (modules.getTotal() > PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteDistributionSets() {
|
private void deleteDistributionSets() {
|
||||||
PagedList<MgmtDistributionSet> distributionSets;
|
PagedList<MgmtDistributionSet> distributionSets;
|
||||||
do {
|
do {
|
||||||
distributionSets = distributionSetResource.getDistributionSets(0, 100, null, null).getBody();
|
distributionSets = distributionSetResource.getDistributionSets(0, PAGE_SIZE, null, null).getBody();
|
||||||
distributionSets.getContent().forEach(set -> distributionSetResource.deleteDistributionSet(set.getDsId()));
|
distributionSets.getContent().forEach(set -> distributionSetResource.deleteDistributionSet(set.getDsId()));
|
||||||
} while (distributionSets.getTotal() > 100);
|
} while (distributionSets.getTotal() > PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteTargets() {
|
private void deleteTargets() {
|
||||||
PagedList<MgmtTarget> targets;
|
PagedList<MgmtTarget> targets;
|
||||||
do {
|
do {
|
||||||
targets = targetResource.getTargets(0, 100, null, null).getBody();
|
targets = targetResource.getTargets(0, PAGE_SIZE, null, null).getBody();
|
||||||
targets.getContent().forEach(target -> targetResource.deleteTarget(target.getControllerId()));
|
targets.getContent().forEach(target -> targetResource.deleteTarget(target.getControllerId()));
|
||||||
} while (targets.getTotal() > 100);
|
} while (targets.getTotal() > PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runRollouts(final Scenario scenario) {
|
private void runRollouts(final Scenario scenario) {
|
||||||
@@ -217,10 +219,11 @@ public class ConfigurableScenario {
|
|||||||
private void createTargets(final Scenario scenario) {
|
private void createTargets(final Scenario scenario) {
|
||||||
LOGGER.info("Creating {} targets", scenario.getTargets());
|
LOGGER.info("Creating {} targets", scenario.getTargets());
|
||||||
|
|
||||||
for (int i = 0; i < scenario.getTargets() / 100; i++) {
|
for (int i = 0; i < (scenario.getTargets() / PAGE_SIZE); i++) {
|
||||||
targetResource.createTargets(new TargetBuilder().controllerId(scenario.getTargetName())
|
targetResource.createTargets(
|
||||||
.address(scenario.getTargetAddress()).buildAsList(i * 100,
|
new TargetBuilder().controllerId(scenario.getTargetName()).address(scenario.getTargetAddress())
|
||||||
(i + 1) * 100 > scenario.getTargets() ? (scenario.getTargets() - (i * 100)) : 100));
|
.buildAsList(i * PAGE_SIZE, (i + 1) * PAGE_SIZE > scenario.getTargets()
|
||||||
|
? (scenario.getTargets() - (i * PAGE_SIZE)) : PAGE_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info("Creating {} targets -> Done", scenario.getTargets());
|
LOGGER.info("Creating {} targets -> Done", scenario.getTargets());
|
||||||
|
|||||||
@@ -12,11 +12,16 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation for {@link MultipartFile} for hawkBit artifact upload.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class ArtifactFile implements MultipartFile {
|
public class ArtifactFile implements MultipartFile {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
@@ -55,9 +60,9 @@ public class ArtifactFile implements MultipartFile {
|
|||||||
final byte[] content) {
|
final byte[] content) {
|
||||||
Assert.hasLength(name, "Name must not be null");
|
Assert.hasLength(name, "Name must not be null");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.originalFilename = originalFilename != null ? originalFilename : "";
|
this.originalFilename = Optional.ofNullable(originalFilename).orElse("");
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
this.content = content != null ? content : new byte[0];
|
this.content = Optional.ofNullable(content).orElse(new byte[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class FeignMultipartEncoder implements Encoder {
|
|||||||
private final HttpHeaders multipartHeaders = new HttpHeaders();
|
private final HttpHeaders multipartHeaders = new HttpHeaders();
|
||||||
private final HttpHeaders jsonHeaders = new HttpHeaders();
|
private final HttpHeaders jsonHeaders = new HttpHeaders();
|
||||||
|
|
||||||
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||||
|
|
||||||
public FeignMultipartEncoder() {
|
public FeignMultipartEncoder() {
|
||||||
multipartHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
multipartHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
@@ -48,11 +48,8 @@ public class FeignMultipartEncoder implements Encoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(final Object object, final Type bodyType, final RequestTemplate template)
|
public void encode(final Object object, final Type bodyType, final RequestTemplate template) {
|
||||||
throws EncodeException {
|
|
||||||
|
|
||||||
encodeMultipartFormRequest(object, template);
|
encodeMultipartFormRequest(object, template);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void encodeMultipartFormRequest(final Object value, final RequestTemplate template) {
|
private void encodeMultipartFormRequest(final Object value, final RequestTemplate template) {
|
||||||
@@ -66,8 +63,7 @@ public class FeignMultipartEncoder implements Encoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void encodeRequest(final Object value, final HttpHeaders requestHeaders, final RequestTemplate template)
|
private void encodeRequest(final Object value, final HttpHeaders requestHeaders, final RequestTemplate template) {
|
||||||
throws EncodeException {
|
|
||||||
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
final HttpOutputMessage dummyRequest = new HttpOutputMessageImpl(outputStream, requestHeaders);
|
final HttpOutputMessage dummyRequest = new HttpOutputMessageImpl(outputStream, requestHeaders);
|
||||||
try {
|
try {
|
||||||
@@ -150,12 +146,6 @@ public class FeignMultipartEncoder implements Encoder {
|
|||||||
return this.filename;
|
return this.filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream getInputStream() throws IOException, IllegalStateException {
|
|
||||||
return super.getInputStream(); // To change body of generated
|
|
||||||
// methods, choose Tools | Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long contentLength() throws IOException {
|
public long contentLength() throws IOException {
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.eclipse.hawkbit.api.HostnameResolver;
|
import org.eclipse.hawkbit.api.HostnameResolver;
|
||||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||||
@@ -344,16 +345,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
final ActionUpdateStatus actionUpdateStatus = convertMessage(message, ActionUpdateStatus.class);
|
final ActionUpdateStatus actionUpdateStatus = convertMessage(message, ActionUpdateStatus.class);
|
||||||
final Action action = checkActionExist(message, actionUpdateStatus);
|
final Action action = checkActionExist(message, actionUpdateStatus);
|
||||||
|
|
||||||
final ActionStatus actionStatus = entityFactory.generateActionStatus();
|
final ActionStatus actionStatus = createActionStatus(message, actionUpdateStatus, action);
|
||||||
actionUpdateStatus.getMessage().forEach(actionStatus::addMessage);
|
|
||||||
|
|
||||||
if (message.getMessageProperties().getCorrelationId().length > 0) {
|
|
||||||
actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "DMF message correlation-id "
|
|
||||||
+ message.getMessageProperties().getCorrelationId());
|
|
||||||
}
|
|
||||||
|
|
||||||
actionStatus.setAction(action);
|
|
||||||
actionStatus.setOccurredAt(System.currentTimeMillis());
|
|
||||||
|
|
||||||
switch (actionUpdateStatus.getActionStatus()) {
|
switch (actionUpdateStatus.getActionStatus()) {
|
||||||
case DOWNLOAD:
|
case DOWNLOAD:
|
||||||
@@ -391,6 +383,21 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ActionStatus createActionStatus(final Message message, final ActionUpdateStatus actionUpdateStatus,
|
||||||
|
final Action action) {
|
||||||
|
final ActionStatus actionStatus = entityFactory.generateActionStatus();
|
||||||
|
actionUpdateStatus.getMessage().forEach(actionStatus::addMessage);
|
||||||
|
|
||||||
|
if (ArrayUtils.isNotEmpty(message.getMessageProperties().getCorrelationId())) {
|
||||||
|
actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "DMF message correlation-id "
|
||||||
|
+ message.getMessageProperties().getCorrelationId());
|
||||||
|
}
|
||||||
|
|
||||||
|
actionStatus.setAction(action);
|
||||||
|
actionStatus.setOccurredAt(System.currentTimeMillis());
|
||||||
|
return actionStatus;
|
||||||
|
}
|
||||||
|
|
||||||
private Action getUpdateActionStatus(final ActionStatus actionStatus) {
|
private Action getUpdateActionStatus(final ActionStatus actionStatus) {
|
||||||
if (actionStatus.getStatus().equals(Status.CANCELED)) {
|
if (actionStatus.getStatus().equals(Status.CANCELED)) {
|
||||||
return controllerManagement.addCancelActionStatus(actionStatus);
|
return controllerManagement.addCancelActionStatus(actionStatus);
|
||||||
|
|||||||
@@ -253,8 +253,8 @@ public class JpaControllerManagement implements ControllerManagement {
|
|||||||
public Action addUpdateActionStatus(@NotNull final ActionStatus actionStatus) {
|
public Action addUpdateActionStatus(@NotNull final ActionStatus actionStatus) {
|
||||||
final JpaAction action = (JpaAction) actionStatus.getAction();
|
final JpaAction action = (JpaAction) actionStatus.getAction();
|
||||||
|
|
||||||
// if action is already closed we accept further status updates on if
|
// if action is already closed we accept further status updates if
|
||||||
// permitted so by configuration. This is especially use full if the
|
// permitted so by configuration. This is especially useful if the
|
||||||
// action status feedback channel order from the device cannot be
|
// action status feedback channel order from the device cannot be
|
||||||
// guaranteed. However, if an action is closed we do not accept further
|
// guaranteed. However, if an action is closed we do not accept further
|
||||||
// close messages.
|
// close messages.
|
||||||
|
|||||||
Reference in New Issue
Block a user