Configurable basic scenario.

Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-06-10 08:37:56 +02:00
parent ec25f2961e
commit d5e591a4a6
11 changed files with 264 additions and 177 deletions

View File

@@ -9,8 +9,8 @@
package org.eclipse.hawkbit.mgmt.client;
import org.eclipse.hawkbit.feign.core.client.FeignClientConfiguration;
import org.eclipse.hawkbit.mgmt.client.scenarios.ConfigurableScenario;
import org.eclipse.hawkbit.mgmt.client.scenarios.CreateStartedRolloutExample;
import org.eclipse.hawkbit.mgmt.client.scenarios.GettingStartedDefaultScenario;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -36,7 +36,7 @@ public class Application implements CommandLineRunner {
private ClientConfigurationProperties configuration;
@Autowired
private GettingStartedDefaultScenario gettingStarted;
private ConfigurableScenario configurableScenario;
@Autowired
private CreateStartedRolloutExample gettingStartedRolloutScenario;
@@ -53,7 +53,7 @@ public class Application implements CommandLineRunner {
} else {
// run the getting started scenario which creates a setup of
// distribution set and software modules to be used
gettingStarted.run();
configurableScenario.run();
}
}
@@ -63,8 +63,8 @@ public class Application implements CommandLineRunner {
}
@Bean
public GettingStartedDefaultScenario gettingStartedDefaultScenario() {
return new GettingStartedDefaultScenario();
public ConfigurableScenario configurableScenario() {
return new ConfigurableScenario();
}
@Bean

View File

@@ -8,6 +8,9 @@
*/
package org.eclipse.hawkbit.mgmt.client;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
@@ -34,6 +37,79 @@ public class ClientConfigurationProperties {
private String password = "admin"; // NOSONAR this password is only used for
// examples
private final List<Scenario> scenarios = new ArrayList<>();
public static class Scenario {
private int targets = 100;
private int distributionSets = 10;
private int appModulesPerDistributionSet = 2;
private String dsName = "Package";
private String smSwName = "Application";
private String smFwName = "Firmware";
private String targetName = "Device";
public String getTargetName() {
return targetName;
}
public void setTargetName(final String targetName) {
this.targetName = targetName;
}
public String getDsName() {
return dsName;
}
public void setDsName(final String dsName) {
this.dsName = dsName;
}
public String getSmSwName() {
return smSwName;
}
public void setSmSwName(final String smSwName) {
this.smSwName = smSwName;
}
public String getSmFwName() {
return smFwName;
}
public void setSmFwName(final String smFwName) {
this.smFwName = smFwName;
}
public int getTargets() {
return targets;
}
public int getDistributionSets() {
return distributionSets;
}
public int getAppModulesPerDistributionSet() {
return appModulesPerDistributionSet;
}
public void setTargets(final int targets) {
this.targets = targets;
}
public void setDistributionSets(final int distributionSets) {
this.distributionSets = distributionSets;
}
public void setAppModulesPerDistributionSet(final int appModulesPerDistributionSet) {
this.appModulesPerDistributionSet = appModulesPerDistributionSet;
}
}
public List<Scenario> getScenarios() {
return scenarios;
}
public String getUrl() {
return url;
}

View File

@@ -0,0 +1,92 @@
/**
* 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.ClientConfigurationProperties;
import org.eclipse.hawkbit.mgmt.client.ClientConfigurationProperties.Scenario;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtDistributionSetClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleClientResource;
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.SoftwareModuleAssigmentBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.TargetBuilder;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Default getting started scenario.
*
*/
public class ConfigurableScenario {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurableScenario.class);
@Autowired
private MgmtDistributionSetClientResource distributionSetResource;
@Autowired
private MgmtSoftwareModuleClientResource softwareModuleResource;
@Autowired
private MgmtTargetClientResource targetResource;
@Autowired
private ClientConfigurationProperties clientConfigurationProperties;
/**
* Run the default getting started scenario.
*/
public void run() {
LOGGER.info("Running Configurable Scenario...");
clientConfigurationProperties.getScenarios().parallelStream().forEach(this::createScenario);
}
private void createScenario(final Scenario scenario) {
createTargets(scenario);
createDistributionSets(scenario);
}
private void createDistributionSets(final Scenario scenario) {
distributionSetResource
.createDistributionSets(new DistributionSetBuilder().name(scenario.getDsName()).type("os_app")
.version("1.0.").buildAsList(scenario.getDistributionSets()))
.getBody().parallelStream().forEach(dsSet -> {
final List<MgmtSoftwareModule> modules = softwareModuleResource
.createSoftwareModules(new SoftwareModuleBuilder().name(scenario.getSmFwName())
.version(dsSet.getVersion()).type("os").build())
.getBody();
modules.addAll(
softwareModuleResource
.createSoftwareModules(new SoftwareModuleBuilder().name(scenario.getSmSwName())
.version(dsSet.getVersion() + ".").type("application")
.buildAsList(scenario.getAppModulesPerDistributionSet()))
.getBody());
final SoftwareModuleAssigmentBuilder assign = new SoftwareModuleAssigmentBuilder();
modules.forEach(module -> assign.id(module.getModuleId()));
distributionSetResource.assignSoftwareModules(dsSet.getDsId(), assign.build());
});
}
private void createTargets(final Scenario scenario) {
for (int i = 0; i < scenario.getTargets() / 100; i++) {
targetResource.createTargets(new TargetBuilder().controllerId(scenario.getTargetName()).buildAsList(i * 100,
(i + 1) * 100 > scenario.getTargets() ? scenario.getTargets() : (i + 1) * 100));
}
}
}

View File

@@ -36,7 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
public class CreateStartedRolloutExample {
/* known software module type name and key */
private static final String SM_MODULE_TYPE = "firmware";
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;

View File

@@ -1,135 +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.MgmtSoftwareModuleClientResource;
import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleTypeClientResource;
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.SoftwareModuleAssigmentBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder;
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleTypeBuilder;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Default getting started scenario.
*
*/
public class GettingStartedDefaultScenario {
private static final Logger LOGGER = LoggerFactory.getLogger(GettingStartedDefaultScenario.class);
/* known software module type name and key */
private static final String SM_MODULE_TYPE = "gettingstarted";
/* known distribution set type name and key */
private static final String DS_MODULE_TYPE = SM_MODULE_TYPE;
/* known distribution name of this getting started example */
private static final String SM_EXAMPLE_NAME = "gettingstarted-example";
/* known distribution name of this getting started example */
private static final String DS_EXAMPLE_NAME = SM_EXAMPLE_NAME;
@Autowired
private MgmtDistributionSetClientResource distributionSetResource;
@Autowired
private MgmtDistributionSetTypeClientResource distributionSetTypeResource;
@Autowired
private MgmtSoftwareModuleClientResource softwareModuleResource;
@Autowired
private MgmtSoftwareModuleTypeClientResource softwareModuleTypeResource;
/**
* Run the default getting started scenario.
*/
public void run() {
LOGGER.info("Running Getting-Started-Scenario...");
// create one SoftwareModuleTypes
LOGGER.info("Creating software module type {}", SM_MODULE_TYPE);
final List<MgmtSoftwareModuleType> createdSoftwareModuleTypes = softwareModuleTypeResource
.createSoftwareModuleTypes(new SoftwareModuleTypeBuilder().key(SM_MODULE_TYPE).name(SM_MODULE_TYPE)
.maxAssignments(1).build())
.getBody();
// create one DistributionSetType
LOGGER.info("Creating distribution set type {}", DS_MODULE_TYPE);
distributionSetTypeResource.createDistributionSetTypes(new DistributionSetTypeBuilder().key(DS_MODULE_TYPE)
.name(DS_MODULE_TYPE).mandatorymodules(createdSoftwareModuleTypes.get(0).getModuleId()).build());
// create three DistributionSet
final String dsVersion1 = "1.0.0";
final String dsVersion2 = "2.0.0";
final String dsVersion3 = "2.1.0";
LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion1);
final List<MgmtDistributionSet> distributionSetsRest1 = distributionSetResource.createDistributionSets(
new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion1).type(DS_MODULE_TYPE).build())
.getBody();
LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion2);
final List<MgmtDistributionSet> distributionSetsRest2 = distributionSetResource.createDistributionSets(
new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion2).type(DS_MODULE_TYPE).build())
.getBody();
LOGGER.info("Creating distribution set {}:{}", DS_EXAMPLE_NAME, dsVersion3);
final List<MgmtDistributionSet> distributionSetsRest3 = distributionSetResource.createDistributionSets(
new DistributionSetBuilder().name(DS_EXAMPLE_NAME).version(dsVersion3).type(DS_MODULE_TYPE).build())
.getBody();
// create three SoftwareModules
final String swVersion1 = "1";
final String swVersion2 = "2";
final String swVersion3 = "3";
LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion1);
final List<MgmtSoftwareModule> softwareModulesRest1 = softwareModuleResource.createSoftwareModules(
new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion1).type(SM_MODULE_TYPE).build())
.getBody();
LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion2);
final List<MgmtSoftwareModule> softwareModulesRest2 = softwareModuleResource.createSoftwareModules(
new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion2).type(SM_MODULE_TYPE).build())
.getBody();
LOGGER.info("Creating distribution set {}:{}", SM_EXAMPLE_NAME, swVersion3);
final List<MgmtSoftwareModule> softwareModulesRest3 = softwareModuleResource.createSoftwareModules(
new SoftwareModuleBuilder().name(SM_EXAMPLE_NAME).version(swVersion3).type(SM_MODULE_TYPE).build())
.getBody();
// Assign SoftwareModules to DistributionSet
LOGGER.info("Assign software module {}:{} to distribution set {}:{}", SM_EXAMPLE_NAME, swVersion1,
DS_EXAMPLE_NAME, dsVersion1);
distributionSetResource.assignSoftwareModules(distributionSetsRest1.get(0).getDsId(),
new SoftwareModuleAssigmentBuilder().id(softwareModulesRest1.get(0).getModuleId()).build());
LOGGER.info("Assign software module {}:{} to distribution set {}:{}", SM_EXAMPLE_NAME, swVersion2,
DS_EXAMPLE_NAME, dsVersion2);
distributionSetResource.assignSoftwareModules(distributionSetsRest2.get(0).getDsId(),
new SoftwareModuleAssigmentBuilder().id(softwareModulesRest2.get(0).getModuleId()).build());
LOGGER.info("Assign software module {}:{} to distribution set {}:{}", SM_EXAMPLE_NAME, swVersion3,
DS_EXAMPLE_NAME, dsVersion3);
distributionSetResource.assignSoftwareModules(distributionSetsRest3.get(0).getDsId(),
new SoftwareModuleAssigmentBuilder().id(softwareModulesRest3.get(0).getModuleId()).build());
}
}

View File

@@ -11,4 +11,13 @@ hawkbit.url=localhost:8080
hawkbit.username=admin
hawkbit.password=admin
spring.main.show-banner=false
spring.main.show-banner=false
#hawkbit.scenarios.[0].targets=0
#hawkbit.scenarios.[0].ds-name=gettingstarted-example
#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].targets=10000
hawkbit.scenarios.[0].distribution-sets=100