add dummy artifact upload again
Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
@@ -9,12 +9,14 @@
|
|||||||
package org.eclipse.hawkbit.mgmt.client;
|
package org.eclipse.hawkbit.mgmt.client;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.feign.core.client.FeignClientConfiguration;
|
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.MgmtDistributionSetClientResource;
|
||||||
import org.eclipse.hawkbit.mgmt.client.resource.MgmtRolloutClientResource;
|
import org.eclipse.hawkbit.mgmt.client.resource.MgmtRolloutClientResource;
|
||||||
import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleClientResource;
|
import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleClientResource;
|
||||||
import org.eclipse.hawkbit.mgmt.client.resource.MgmtTargetClientResource;
|
import org.eclipse.hawkbit.mgmt.client.resource.MgmtTargetClientResource;
|
||||||
import org.eclipse.hawkbit.mgmt.client.scenarios.ConfigurableScenario;
|
import org.eclipse.hawkbit.mgmt.client.scenarios.ConfigurableScenario;
|
||||||
import org.eclipse.hawkbit.mgmt.client.scenarios.CreateStartedRolloutExample;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.Banner.Mode;
|
import org.springframework.boot.Banner.Mode;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
@@ -23,12 +25,20 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.hateoas.hal.Jackson2HalModule;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import feign.Feign;
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
import feign.auth.BasicAuthRequestInterceptor;
|
import feign.auth.BasicAuthRequestInterceptor;
|
||||||
|
import feign.jackson.JacksonDecoder;
|
||||||
|
import feign.slf4j.Slf4jLogger;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableFeignClients("org.eclipse.hawkbit.mgmt.client.resource")
|
@EnableFeignClients("org.eclipse.hawkbit.mgmt.client.resource")
|
||||||
@@ -69,8 +79,9 @@ public class Application implements CommandLineRunner {
|
|||||||
final MgmtSoftwareModuleClientResource softwareModuleResource,
|
final MgmtSoftwareModuleClientResource softwareModuleResource,
|
||||||
final MgmtTargetClientResource targetResource, final MgmtRolloutClientResource rolloutResource,
|
final MgmtTargetClientResource targetResource, final MgmtRolloutClientResource rolloutResource,
|
||||||
final ClientConfigurationProperties clientConfigurationProperties) {
|
final ClientConfigurationProperties clientConfigurationProperties) {
|
||||||
return new ConfigurableScenario(distributionSetResource, softwareModuleResource, targetResource,
|
return new ConfigurableScenario(distributionSetResource, softwareModuleResource,
|
||||||
rolloutResource, clientConfigurationProperties);
|
uploadSoftwareModule(clientConfigurationProperties), targetResource, rolloutResource,
|
||||||
|
clientConfigurationProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -78,6 +89,19 @@ public class Application implements CommandLineRunner {
|
|||||||
return new CreateStartedRolloutExample();
|
return new CreateStartedRolloutExample();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MgmtSoftwareModuleClientResource uploadSoftwareModule(final ClientConfigurationProperties configuration) {
|
||||||
|
final ObjectMapper mapper = new ObjectMapper()
|
||||||
|
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
|
.registerModule(new Jackson2HalModule());
|
||||||
|
return Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
||||||
|
.requestInterceptor(
|
||||||
|
new BasicAuthRequestInterceptor(configuration.getUsername(), configuration.getPassword()))
|
||||||
|
.logger(new Slf4jLogger()).encoder(new FeignMultipartEncoder())
|
||||||
|
.decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper)))
|
||||||
|
.target(MgmtSoftwareModuleClientResource.class, configuration.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Logger.Level feignLoggerLevel() {
|
public Logger.Level feignLoggerLevel() {
|
||||||
return Logger.Level.FULL;
|
return Logger.Level.FULL;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.mgmt.client.scenarios;
|
package org.eclipse.hawkbit.mgmt.client.scenarios;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.mgmt.client.ClientConfigurationProperties;
|
import org.eclipse.hawkbit.mgmt.client.ClientConfigurationProperties;
|
||||||
@@ -22,6 +23,7 @@ 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.SoftwareModuleAssigmentBuilder;
|
||||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder;
|
import org.eclipse.hawkbit.mgmt.client.resource.builder.SoftwareModuleBuilder;
|
||||||
import org.eclipse.hawkbit.mgmt.client.resource.builder.TargetBuilder;
|
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.PagedList;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
|
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.rollout.MgmtRolloutResponseBody;
|
||||||
@@ -53,12 +55,16 @@ public class ConfigurableScenario {
|
|||||||
|
|
||||||
private final ClientConfigurationProperties clientConfigurationProperties;
|
private final ClientConfigurationProperties clientConfigurationProperties;
|
||||||
|
|
||||||
|
private final MgmtSoftwareModuleClientResource uploadSoftwareModule;
|
||||||
|
|
||||||
public ConfigurableScenario(final MgmtDistributionSetClientResource distributionSetResource,
|
public ConfigurableScenario(final MgmtDistributionSetClientResource distributionSetResource,
|
||||||
final MgmtSoftwareModuleClientResource softwareModuleResource,
|
final MgmtSoftwareModuleClientResource softwareModuleResource,
|
||||||
final MgmtTargetClientResource targetResource, final MgmtRolloutClientResource rolloutResource,
|
final MgmtSoftwareModuleClientResource uploadSoftwareModule, final MgmtTargetClientResource targetResource,
|
||||||
|
final MgmtRolloutClientResource rolloutResource,
|
||||||
final ClientConfigurationProperties clientConfigurationProperties) {
|
final ClientConfigurationProperties clientConfigurationProperties) {
|
||||||
this.distributionSetResource = distributionSetResource;
|
this.distributionSetResource = distributionSetResource;
|
||||||
this.softwareModuleResource = softwareModuleResource;
|
this.softwareModuleResource = softwareModuleResource;
|
||||||
|
this.uploadSoftwareModule = uploadSoftwareModule;
|
||||||
this.targetResource = targetResource;
|
this.targetResource = targetResource;
|
||||||
this.rolloutResource = rolloutResource;
|
this.rolloutResource = rolloutResource;
|
||||||
this.clientConfigurationProperties = clientConfigurationProperties;
|
this.clientConfigurationProperties = clientConfigurationProperties;
|
||||||
@@ -158,11 +164,12 @@ public class ConfigurableScenario {
|
|||||||
|
|
||||||
private void createDistributionSets(final Scenario scenario) {
|
private void createDistributionSets(final Scenario scenario) {
|
||||||
LOGGER.info("Creating {} distribution sets", scenario.getDistributionSets());
|
LOGGER.info("Creating {} distribution sets", scenario.getDistributionSets());
|
||||||
|
final byte[] artifact = generateArtifact(scenario);
|
||||||
|
|
||||||
distributionSetResource.createDistributionSets(new DistributionSetBuilder().name(scenario.getDsName())
|
distributionSetResource.createDistributionSets(new DistributionSetBuilder().name(scenario.getDsName())
|
||||||
.type("os_app").version("1.0.").buildAsList(scenario.getDistributionSets())).getBody()
|
.type("os_app").version("1.0.").buildAsList(scenario.getDistributionSets())).getBody()
|
||||||
.forEach(dsSet -> {
|
.forEach(dsSet -> {
|
||||||
final List<MgmtSoftwareModule> modules = addModules(scenario, dsSet);
|
final List<MgmtSoftwareModule> modules = addModules(scenario, dsSet, artifact);
|
||||||
|
|
||||||
final SoftwareModuleAssigmentBuilder assign = new SoftwareModuleAssigmentBuilder();
|
final SoftwareModuleAssigmentBuilder assign = new SoftwareModuleAssigmentBuilder();
|
||||||
modules.forEach(module -> assign.id(module.getModuleId()));
|
modules.forEach(module -> assign.id(module.getModuleId()));
|
||||||
@@ -172,7 +179,8 @@ public class ConfigurableScenario {
|
|||||||
LOGGER.info("Creating {} distribution sets -> Done", scenario.getDistributionSets());
|
LOGGER.info("Creating {} distribution sets -> Done", scenario.getDistributionSets());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MgmtSoftwareModule> addModules(final Scenario scenario, final MgmtDistributionSet dsSet) {
|
private List<MgmtSoftwareModule> addModules(final Scenario scenario, final MgmtDistributionSet dsSet,
|
||||||
|
final byte[] artifact) {
|
||||||
final List<MgmtSoftwareModule> modules = softwareModuleResource
|
final List<MgmtSoftwareModule> modules = softwareModuleResource
|
||||||
.createSoftwareModules(new SoftwareModuleBuilder().name(scenario.getSmFwName() + "-os")
|
.createSoftwareModules(new SoftwareModuleBuilder().name(scenario.getSmFwName() + "-os")
|
||||||
.version(dsSet.getVersion()).type("os").build())
|
.version(dsSet.getVersion()).type("os").build())
|
||||||
@@ -182,6 +190,13 @@ public class ConfigurableScenario {
|
|||||||
.type("application").buildAsList(scenario.getAppModulesPerDistributionSet()))
|
.type("application").buildAsList(scenario.getAppModulesPerDistributionSet()))
|
||||||
.getBody());
|
.getBody());
|
||||||
|
|
||||||
|
for (int iArtifact = 0; iArtifact < scenario.getArtifactsPerSM(); iArtifact++) {
|
||||||
|
modules.forEach(module -> {
|
||||||
|
final ArtifactFile file = new ArtifactFile("dummyfile.dummy", null, "multipart/form-data", artifact);
|
||||||
|
uploadSoftwareModule.uploadArtifact(module.getModuleId(), file, null, null, null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,4 +223,19 @@ public class ConfigurableScenario {
|
|||||||
}
|
}
|
||||||
return Integer.valueOf(size);
|
return Integer.valueOf(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte[] generateArtifact(final Scenario scenario) {
|
||||||
|
|
||||||
|
// Exception squid:S2245 - not used for cryptographic function
|
||||||
|
@SuppressWarnings("squid:S2245")
|
||||||
|
final Random random = new Random();
|
||||||
|
|
||||||
|
// create byte array
|
||||||
|
final byte[] nbyte = new byte[parseSize(scenario.getArtifactSize())];
|
||||||
|
|
||||||
|
// put the next byte in the array
|
||||||
|
random.nextBytes(nbyte);
|
||||||
|
|
||||||
|
return nbyte;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user