Optimisation and bug fixing of UI push events (#310)

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-10-17 21:59:53 +02:00
committed by GitHub
parent 43511ed63e
commit c7129e6ed7
114 changed files with 1743 additions and 1129 deletions

View File

@@ -11,9 +11,11 @@ package org.eclipse.hawkbit.mgmt.client;
import org.eclipse.hawkbit.feign.core.client.FeignClientConfiguration;
import org.eclipse.hawkbit.feign.core.client.IgnoreMultipleConsumersProducersSpringMvcContract;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtDistributionSetClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtDistributionSetTagClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtRolloutClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtTargetClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtTargetTagClientResource;
import org.eclipse.hawkbit.mgmt.client.scenarios.ConfigurableScenario;
import org.eclipse.hawkbit.mgmt.client.scenarios.CreateStartedRolloutExample;
import org.eclipse.hawkbit.mgmt.client.scenarios.upload.FeignMultipartEncoder;
@@ -27,7 +29,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.support.ResponseEntityDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.hateoas.hal.Jackson2HalModule;
@@ -43,7 +44,6 @@ import feign.slf4j.Slf4jLogger;
@SpringBootApplication
@EnableFeignClients("org.eclipse.hawkbit.mgmt.client.resource")
@EnableConfigurationProperties(ClientConfigurationProperties.class)
@Configuration
@AutoConfigureAfter(FeignClientConfiguration.class)
@Import(FeignClientConfiguration.class)
public class Application implements CommandLineRunner {
@@ -78,10 +78,12 @@ public class Application implements CommandLineRunner {
public ConfigurableScenario configurableScenario(final MgmtDistributionSetClientResource distributionSetResource,
final MgmtSoftwareModuleClientResource softwareModuleResource,
final MgmtTargetClientResource targetResource, final MgmtRolloutClientResource rolloutResource,
final MgmtTargetTagClientResource targetTagResource,
final MgmtDistributionSetTagClientResource distributionSetTagResource,
final ClientConfigurationProperties clientConfigurationProperties) {
return new ConfigurableScenario(distributionSetResource, softwareModuleResource,
uploadSoftwareModule(clientConfigurationProperties), targetResource, rolloutResource,
clientConfigurationProperties);
uploadSoftwareModule(clientConfigurationProperties), targetResource, rolloutResource, targetTagResource,
distributionSetTagResource, clientConfigurationProperties);
}
@Bean
@@ -89,8 +91,8 @@ public class Application implements CommandLineRunner {
return new CreateStartedRolloutExample();
}
@Bean
public MgmtSoftwareModuleClientResource uploadSoftwareModule(final ClientConfigurationProperties configuration) {
private static MgmtSoftwareModuleClientResource uploadSoftwareModule(
final ClientConfigurationProperties configuration) {
final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(new Jackson2HalModule());

View File

@@ -55,8 +55,19 @@ public class ClientConfigurationProperties {
private int artifactsPerSM = 1;
private String targetAddress = "amqp:/simulator.replyTo";
private boolean runRollouts = true;
private short rolloutSuccessThreshold = 80;
private int rolloutDeploymentGroups = 4;
/**
* Targets tags per page.
*/
private int targetTags;
/**
* Distribution Set tags per set
*/
private int dsTags = 5;
/**
* Artifact size. Values can use the suffixed "MB" or "KB" to indicate a
* Megabyte or Kilobyte size.
@@ -167,6 +178,30 @@ public class ClientConfigurationProperties {
this.appModulesPerDistributionSet = appModulesPerDistributionSet;
}
public void setTargetTags(final int targetTags) {
this.targetTags = targetTags;
}
public int getTargetTags() {
return targetTags;
}
public int getDsTags() {
return dsTags;
}
public void setDsTags(final int dsTags) {
this.dsTags = dsTags;
}
public short getRolloutSuccessThreshold() {
return rolloutSuccessThreshold;
}
public void setRolloutSuccessThreshold(final short rolloutSuccessThreshold) {
this.rolloutSuccessThreshold = rolloutSuccessThreshold;
}
}
public List<Scenario> getScenarios() {

View File

@@ -11,23 +11,31 @@ package org.eclipse.hawkbit.mgmt.client.scenarios;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.eclipse.hawkbit.mgmt.client.ClientConfigurationProperties;
import org.eclipse.hawkbit.mgmt.client.ClientConfigurationProperties.Scenario;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtDistributionSetClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtDistributionSetTagClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtRolloutClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtTargetClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtTargetTagClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.builder.DistributionSetBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.RolloutBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleAssigmentBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.TagBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.TargetBuilder;
import org.eclipse.hawkbit.mgmt.client.scenarios.upload.ArtifactFile;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutResponseBody;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtAssignedDistributionSetRequestBody;
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtAssignedTargetRequestBody;
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +49,7 @@ import org.slf4j.LoggerFactory;
*/
public class ConfigurableScenario {
private static final int PAGE_SIZE = 100;
private static final int PAGE_SIZE = 500;
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurableScenario.class);
@@ -51,22 +59,32 @@ public class ConfigurableScenario {
private final MgmtTargetClientResource targetResource;
private final MgmtTargetTagClientResource targetTagResource;
private final MgmtDistributionSetTagClientResource distributionSetTagResource;
private final MgmtRolloutClientResource rolloutResource;
private final ClientConfigurationProperties clientConfigurationProperties;
private final MgmtSoftwareModuleClientResource uploadSoftwareModule;
// Exception - squid:S00107 - this is a simulator that leverages multiple
// resouces/feign beans.
@SuppressWarnings("squid:S00107")
public ConfigurableScenario(final MgmtDistributionSetClientResource distributionSetResource,
final MgmtSoftwareModuleClientResource softwareModuleResource,
final MgmtSoftwareModuleClientResource uploadSoftwareModule, final MgmtTargetClientResource targetResource,
final MgmtRolloutClientResource rolloutResource,
final MgmtRolloutClientResource rolloutResource, final MgmtTargetTagClientResource targetTagResource,
final MgmtDistributionSetTagClientResource distributionSetTagResource,
final ClientConfigurationProperties clientConfigurationProperties) {
this.targetTagResource = targetTagResource;
this.distributionSetResource = distributionSetResource;
this.softwareModuleResource = softwareModuleResource;
this.uploadSoftwareModule = uploadSoftwareModule;
this.targetResource = targetResource;
this.rolloutResource = rolloutResource;
this.distributionSetTagResource = distributionSetTagResource;
this.clientConfigurationProperties = clientConfigurationProperties;
}
@@ -111,7 +129,8 @@ public class ConfigurableScenario {
PagedList<MgmtSoftwareModule> modules;
do {
modules = softwareModuleResource.getSoftwareModules(0, PAGE_SIZE, null, null).getBody();
modules.getContent().forEach(module -> softwareModuleResource.deleteSoftwareModule(module.getModuleId()));
modules.getContent().parallelStream()
.forEach(module -> softwareModuleResource.deleteSoftwareModule(module.getModuleId()));
} while (modules.getTotal() > PAGE_SIZE);
}
@@ -119,16 +138,40 @@ public class ConfigurableScenario {
PagedList<MgmtDistributionSet> distributionSets;
do {
distributionSets = distributionSetResource.getDistributionSets(0, PAGE_SIZE, null, null).getBody();
distributionSets.getContent().forEach(set -> distributionSetResource.deleteDistributionSet(set.getDsId()));
distributionSets.getContent().parallelStream()
.forEach(set -> distributionSetResource.deleteDistributionSet(set.getDsId()));
} while (distributionSets.getTotal() > PAGE_SIZE);
deleteDistributionSetTags();
}
private void deleteDistributionSetTags() {
PagedList<MgmtTag> dsTags;
do {
dsTags = distributionSetTagResource.getDistributionSetTags(0, PAGE_SIZE, null, null).getBody();
dsTags.getContent().parallelStream()
.forEach(ds -> distributionSetTagResource.deleteDistributionSetTag(ds.getTagId()));
} while (dsTags.getTotal() > PAGE_SIZE);
}
private void deleteTargets() {
PagedList<MgmtTarget> targets;
do {
targets = targetResource.getTargets(0, PAGE_SIZE, null, null).getBody();
targets.getContent().forEach(target -> targetResource.deleteTarget(target.getControllerId()));
targets.getContent().parallelStream()
.forEach(target -> targetResource.deleteTarget(target.getControllerId()));
} while (targets.getTotal() > PAGE_SIZE);
deleteTargetTags();
}
private void deleteTargetTags() {
PagedList<MgmtTag> targetTags;
do {
targetTags = targetTagResource.getTargetTags(0, PAGE_SIZE, null, null).getBody();
targetTags.getContent().parallelStream()
.forEach(target -> targetTagResource.deleteTargetTag(target.getTagId()));
} while (targetTags.getTotal() > PAGE_SIZE);
}
private void runRollouts(final Scenario scenario) {
@@ -140,10 +183,10 @@ public class ConfigurableScenario {
private void runRollout(final MgmtDistributionSet set, final Scenario scenario) {
LOGGER.info("Run rollout for set {}", set.getDsId());
// create a Rollout
final MgmtRolloutResponseBody rolloutResponseBody = rolloutResource
.create(new RolloutBuilder().name("Rollout" + set.getName() + set.getVersion())
.groupSize(scenario.getRolloutDeploymentGroups()).targetFilterQuery("name==*")
.distributionSetId(set.getDsId()).successThreshold("80").errorThreshold("5").build())
final MgmtRolloutResponseBody rolloutResponseBody = rolloutResource.create(new RolloutBuilder()
.name("Rollout" + set.getName() + set.getVersion()).groupSize(scenario.getRolloutDeploymentGroups())
.targetFilterQuery("name==*").distributionSetId(set.getDsId())
.successThreshold(String.valueOf(scenario.getRolloutSuccessThreshold())).errorThreshold("5").build())
.getBody();
// start the created Rollout
@@ -164,21 +207,44 @@ public class ConfigurableScenario {
private void createDistributionSets(final Scenario scenario) {
LOGGER.info("Creating {} distribution sets", scenario.getDistributionSets());
final byte[] artifact = generateArtifact(scenario);
distributionSetResource.createDistributionSets(new DistributionSetBuilder().name(scenario.getDsName())
.type("os_app").version("1.0.").buildAsList(scenario.getDistributionSets())).getBody()
.forEach(dsSet -> {
final List<MgmtSoftwareModule> modules = addModules(scenario, dsSet, artifact);
final List<MgmtDistributionSet> sets = distributionSetResource
.createDistributionSets(new DistributionSetBuilder().name(scenario.getDsName()).type("os_app")
.version("1.0.").buildAsList(scenario.getDistributionSets()))
.getBody();
final SoftwareModuleAssigmentBuilder assign = new SoftwareModuleAssigmentBuilder();
modules.forEach(module -> assign.id(module.getModuleId()));
distributionSetResource.assignSoftwareModules(dsSet.getDsId(), assign.build());
});
assignSoftwareModulesTo(scenario, sets);
tagDistributionSets(scenario, sets);
LOGGER.info("Creating {} distribution sets -> Done", scenario.getDistributionSets());
}
private void tagDistributionSets(final Scenario scenario, final List<MgmtDistributionSet> sets) {
for (int i = 0; i < scenario.getDsTags(); i++) {
final MgmtTag tag = distributionSetTagResource
.createDistributionSetTags(
new TagBuilder().name("DS Tag" + i).description("DS tag for DS " + i).build())
.getBody().get(0);
distributionSetTagResource.assignDistributionSets(tag.getTagId(),
sets.stream().map(
set -> new MgmtAssignedDistributionSetRequestBody().setDistributionSetId(set.getDsId()))
.collect(Collectors.toList()));
}
}
private void assignSoftwareModulesTo(final Scenario scenario, final List<MgmtDistributionSet> sets) {
final byte[] artifact = generateArtifact(scenario);
sets.forEach(dsSet -> {
final List<MgmtSoftwareModule> modules = addModules(scenario, dsSet, artifact);
final SoftwareModuleAssigmentBuilder assign = new SoftwareModuleAssigmentBuilder();
modules.forEach(module -> assign.id(module.getModuleId()));
distributionSetResource.assignSoftwareModules(dsSet.getDsId(), assign.build());
});
}
private List<MgmtSoftwareModule> addModules(final Scenario scenario, final MgmtDistributionSet dsSet,
final byte[] artifact) {
final List<MgmtSoftwareModule> modules = softwareModuleResource
@@ -191,8 +257,10 @@ public class ConfigurableScenario {
.getBody());
for (int iArtifact = 0; iArtifact < scenario.getArtifactsPerSM(); iArtifact++) {
final int count = iArtifact;
modules.forEach(module -> {
final ArtifactFile file = new ArtifactFile("dummyfile.dummy", null, "multipart/form-data", artifact);
final ArtifactFile file = new ArtifactFile("dummyfile.dummy" + count, null, "multipart/form-data",
artifact);
uploadSoftwareModule.uploadArtifact(module.getModuleId(), file, null, null, null);
});
}
@@ -202,17 +270,44 @@ public class ConfigurableScenario {
private void createTargets(final Scenario scenario) {
LOGGER.info("Creating {} targets", scenario.getTargets());
for (int i = 0; i < (scenario.getTargets() / PAGE_SIZE); i++) {
targetResource.createTargets(
new TargetBuilder().controllerId(scenario.getTargetName()).address(scenario.getTargetAddress())
.buildAsList(i * PAGE_SIZE, (i + 1) * PAGE_SIZE > scenario.getTargets()
? (scenario.getTargets() - (i * PAGE_SIZE)) : PAGE_SIZE));
}
IntStream.range(0, scenario.getTargets() / PAGE_SIZE).parallel().forEach(i -> createTargetPage(scenario, i));
LOGGER.info("Creating {} targets -> Done", scenario.getTargets());
}
private void createTargetPage(final Scenario scenario, final int page) {
final List<MgmtTarget> targets = createTargets(scenario, page);
tagTargets(scenario, page, targets);
}
private List<MgmtTarget> createTargets(final Scenario scenario, final int page) {
return targetResource
.createTargets(
new TargetBuilder().controllerId(scenario.getTargetName()).address(scenario.getTargetAddress())
.buildAsList(calculateOffset(page),
(page + 1) * PAGE_SIZE > scenario.getTargets()
? (scenario.getTargets() - calculateOffset(page)) : PAGE_SIZE))
.getBody();
}
private void tagTargets(final Scenario scenario, final int page, final List<MgmtTarget> targets) {
if (scenario.getTargetTags() > 0) {
targetTagResource
.createTargetTags(new TagBuilder().name("Page " + page)
.description("Target tag for target page " + page).buildAsList(scenario.getTargetTags()))
.getBody().forEach(
tag -> targetTagResource.assignTargets(tag.getTagId(),
targets.stream()
.map(target -> new MgmtAssignedTargetRequestBody()
.setControllerId(target.getControllerId()))
.collect(Collectors.toList())));
}
}
private static int calculateOffset(final int page) {
return page * PAGE_SIZE;
}
private static int parseSize(final String s) {
final String size = s.toUpperCase();
if (size.endsWith("KB")) {

View File

@@ -11,7 +11,9 @@ hawkbit.url=http://localhost:8080
hawkbit.username=admin
hawkbit.password=admin
spring.main.show-banner=false
spring.main.banner-mode=off
feign.hystrix.enabled=false
hawkbit.scenarios.[0].cleanRepository=false
hawkbit.scenarios.[0].targets=0

View File

@@ -12,7 +12,7 @@
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="feign.Logger" level="debug" />
<logger name="org.eclipse.hawkbit.mgmt.client.resource" level="info" />
<Root level="INFO">
<appender-ref ref="CONSOLE" />