Fixed mgmt simulator and sandbox (#584)

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-09-25 15:30:04 +02:00
committed by GitHub
parent edae83a1b5
commit 879c85fd63
6 changed files with 35 additions and 119 deletions

View File

@@ -17,7 +17,6 @@ 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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner.Mode;
@@ -51,9 +50,6 @@ public class Application implements CommandLineRunner {
@Autowired
private ConfigurableScenario configuredScenario;
@Autowired
private CreateStartedRolloutExample gettingStartedRolloutScenario;
public static void main(final String[] args) {
new SpringApplicationBuilder().bannerMode(Mode.OFF).sources(Application.class).run(args);
}
@@ -62,7 +58,7 @@ public class Application implements CommandLineRunner {
public void run(final String... args) throws Exception {
if (containsArg("--createrollout", args)) {
// run the create and start rollout example
gettingStartedRolloutScenario.run();
configuredScenario.runWithRollout();
} else {
// run the configured scenario from properties
configuredScenario.run();
@@ -86,11 +82,6 @@ public class Application implements CommandLineRunner {
distributionSetTagResource, clientConfigurationProperties);
}
@Bean
public CreateStartedRolloutExample createStartedRolloutExample() {
return new CreateStartedRolloutExample();
}
private static MgmtSoftwareModuleClientResource uploadSoftwareModule(
final ClientConfigurationProperties configuration) {
final ObjectMapper mapper = new ObjectMapper()

View File

@@ -101,6 +101,19 @@ public class ConfigurableScenario {
clientConfigurationProperties.getScenarios().forEach(this::createScenario);
}
/**
* Run the default getting started scenario including rollout
*/
public void runWithRollout() {
LOGGER.info("Running Configurable Scenario...");
clientConfigurationProperties.getScenarios().forEach(scenario -> {
scenario.setRunRollouts(true);
createScenario(scenario);
});
}
private void createScenario(final Scenario scenario) {
if (scenario.isCleanRepository()) {
cleanRepository();
@@ -204,11 +217,19 @@ public class ConfigurableScenario {
}
private void runRollouts(final Scenario scenario) {
if (scenario.getDistributionSets() <= 0) {
return;
}
distributionSetResource.getDistributionSets(0, scenario.getDistributionSets(), null, null).getBody()
.getContent().forEach(set -> runRollout(set, scenario));
}
private void runSemiAutomaticRollouts(final Scenario scenario) {
if (scenario.getDistributionSets() <= 0) {
return;
}
distributionSetResource.getDistributionSets(0, scenario.getDistributionSets(), null, null).getBody()
.getContent().forEach(set -> runSemiAutomaticRollout(set, scenario));
}
@@ -319,6 +340,10 @@ public class ConfigurableScenario {
}
private void createDistributionSets(final Scenario scenario) {
if (scenario.getDistributionSets() <= 0) {
return;
}
LOGGER.info("Creating {} distribution sets", scenario.getDistributionSets());
final BigDecimal pages = new BigDecimal(scenario.getDistributionSets())
.divide(new BigDecimal(PAGE_SIZE), BigDecimal.ROUND_UP).max(new BigDecimal(1));
@@ -389,6 +414,10 @@ public class ConfigurableScenario {
}
private void createTargets(final Scenario scenario, final List<Long> deviceGroupTags) {
if (scenario.getTargets() <= 0) {
return;
}
LOGGER.info("Creating {} targets", scenario.getTargets());
final BigDecimal pages = new BigDecimal(scenario.getTargets())
.divide(new BigDecimal(PAGE_SIZE), BigDecimal.ROUND_UP).max(new BigDecimal(1));

View File

@@ -1,108 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.mgmt.client.scenarios;
import java.util.List;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtDistributionSetClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtDistributionSetTypeClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtRolloutClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleTypeClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtTargetClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.builder.DistributionSetBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.DistributionSetTypeBuilder;
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.SoftwareModuleTypeBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.TargetBuilder;
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.softwaremoduletype.MgmtSoftwareModuleType;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Example for creating and starting a Rollout.
*
*/
public class CreateStartedRolloutExample {
/* known software module type name and key */
private static final String SM_MODULE_TYPE = "gettingstarted-rollout-example";
/* known distribution set type name and key */
private static final String DS_MODULE_TYPE = SM_MODULE_TYPE;
@Autowired
private MgmtDistributionSetClientResource distributionSetResource;
@Autowired
private MgmtSoftwareModuleClientResource softwareModuleResource;
@Autowired
private MgmtTargetClientResource targetResource;
@Autowired
private MgmtRolloutClientResource rolloutResource;
@Autowired
private MgmtDistributionSetTypeClientResource distributionSetTypeResource;
@Autowired
private MgmtSoftwareModuleTypeClientResource softwareModuleTypeResource;
/**
* Run the Rollout scenario.
*/
public void run() {
// create three SoftwareModuleTypes
final List<MgmtSoftwareModuleType> createdSoftwareModuleTypes = softwareModuleTypeResource
.createSoftwareModuleTypes(new SoftwareModuleTypeBuilder().key(SM_MODULE_TYPE).name(SM_MODULE_TYPE)
.maxAssignments(1).build())
.getBody();
// create one DistributionSetType
distributionSetTypeResource.createDistributionSetTypes(new DistributionSetTypeBuilder().key(DS_MODULE_TYPE)
.name(DS_MODULE_TYPE).mandatorymodules(createdSoftwareModuleTypes.get(0).getModuleId()).build())
.getBody();
// create one DistributionSet
final List<MgmtDistributionSet> distributionSetsRest = distributionSetResource.createDistributionSets(
new DistributionSetBuilder().name("rollout-example").version("1.0.0").type(DS_MODULE_TYPE).build())
.getBody();
// create three SoftwareModules
final List<MgmtSoftwareModule> softwareModulesRest = softwareModuleResource
.createSoftwareModules(
new SoftwareModuleBuilder().name("firmware").version("1.0.0").type(SM_MODULE_TYPE).build())
.getBody();
// Assign SoftwareModule to DistributionSet
distributionSetResource.assignSoftwareModules(distributionSetsRest.get(0).getDsId(),
new SoftwareModuleAssigmentBuilder().id(softwareModulesRest.get(0).getModuleId()).build());
// create ten targets
targetResource.createTargets(new TargetBuilder().controllerId("00-FF-AA-0").name("00-FF-AA-0")
.description("Targets used for rollout example").buildAsList(10));
// create a Rollout
final MgmtRolloutResponseBody rolloutResponseBody = rolloutResource
.create(new RolloutBuilder().name("MyRollout").groupSize(2).targetFilterQuery("name==00-FF-AA-0*")
.distributionSetId(distributionSetsRest.get(0).getDsId()).successThreshold("80")
.errorThreshold("50").build())
.getBody();
// start the created Rollout
rolloutResource.start(rolloutResponseBody.getRolloutId());
}
}

View File

@@ -22,4 +22,5 @@ hawkbit.scenarios.[0].distribution-sets=3
hawkbit.scenarios.[0].sm-fw-name=gettingstarted-example
hawkbit.scenarios.[0].sm-sw-name=gettingstarted-example
hawkbit.scenarios.[0].runRollouts=false
hawkbit.scenarios.[0].runSemiAutomaticRollouts=false
hawkbit.scenarios.[0].artifactsPerSM=0