diff --git a/examples/hawkbit-device-simulator/pom.xml b/examples/hawkbit-device-simulator/pom.xml
index 3c3df9486..035bcebfc 100644
--- a/examples/hawkbit-device-simulator/pom.xml
+++ b/examples/hawkbit-device-simulator/pom.xml
@@ -71,6 +71,10 @@
org.springframework.boot
spring-boot-starter-web
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
org.springframework.security
spring-security-web
@@ -83,26 +87,6 @@
org.springframework.boot
spring-boot-starter
-
-
- org.apache.logging.log4j
- log4j-api
-
-
-
- org.slf4j
- jul-to-slf4j
-
-
-
- org.slf4j
- jcl-over-slf4j
-
-
-
- org.slf4j
- log4j-over-slf4j
-
com.vaadin
vaadin-spring-boot-starter
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/AbstractSimulatedDevice.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/AbstractSimulatedDevice.java
index 890f43367..a2a036e1b 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/AbstractSimulatedDevice.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/AbstractSimulatedDevice.java
@@ -27,7 +27,7 @@ public abstract class AbstractSimulatedDevice {
private UpdateStatus updateStatus = new UpdateStatus(ResponseStatus.SUCCESSFUL, "Simulation complete!");
private Protocol protocol = Protocol.DMF_AMQP;
private String targetSecurityToken;
-
+ private int pollDelaySec;
private int nextPollCounterSec;
/**
@@ -84,13 +84,30 @@ public abstract class AbstractSimulatedDevice {
* the ID of the simulated device
* @param tenant
* the tenant of the simulated device
+ * @param int
+ * pollDelaySec
*/
- AbstractSimulatedDevice(final String id, final String tenant, final Protocol protocol) {
+ AbstractSimulatedDevice(final String id, final String tenant, final Protocol protocol, final int pollDelaySec) {
this.id = id;
this.tenant = tenant;
this.status = Status.UNKNWON;
this.progress = 0.0;
this.protocol = protocol;
+ this.pollDelaySec = pollDelaySec;
+ }
+
+ /**
+ * Can be called by a scheduler to trigger a device polling, like in real
+ * scenarios devices are frequently asking for updates etc.
+ */
+ public abstract void poll();
+
+ public int getPollDelaySec() {
+ return pollDelaySec;
+ }
+
+ public void setPollDelaySec(final int pollDelaySec) {
+ this.pollDelaySec = pollDelaySec;
}
/**
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DDISimulatedDevice.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DDISimulatedDevice.java
index 26e613dd9..677d77a37 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DDISimulatedDevice.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DDISimulatedDevice.java
@@ -23,7 +23,6 @@ public class DDISimulatedDevice extends AbstractSimulatedDevice {
private static final Logger LOGGER = LoggerFactory.getLogger(DDISimulatedDevice.class);
- private final int pollDelaySec;
private final ControllerResource controllerResource;
private final DeviceSimulatorUpdater deviceUpdater;
@@ -45,11 +44,9 @@ public class DDISimulatedDevice extends AbstractSimulatedDevice {
*/
public DDISimulatedDevice(final String id, final String tenant, final int pollDelaySec,
final ControllerResource controllerResource, final DeviceSimulatorUpdater deviceUpdater) {
- super(id, tenant, Protocol.DDI_HTTP);
- this.pollDelaySec = pollDelaySec;
+ super(id, tenant, Protocol.DDI_HTTP, pollDelaySec);
this.controllerResource = controllerResource;
this.deviceUpdater = deviceUpdater;
- setNextPollCounterSec(pollDelaySec);
}
@Override
@@ -58,13 +55,10 @@ public class DDISimulatedDevice extends AbstractSimulatedDevice {
removed = true;
}
- public int getPollDelaySec() {
- return pollDelaySec;
- }
-
/**
* Polls the base URL for the DDI API interface.
*/
+ @Override
public void poll() {
if (!removed) {
final String basePollJson = controllerResource.get(getTenant(), getId());
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DMFSimulatedDevice.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DMFSimulatedDevice.java
index 6b79a85b8..65227b55d 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DMFSimulatedDevice.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DMFSimulatedDevice.java
@@ -8,10 +8,13 @@
*/
package org.eclipse.hawkbit.simulator;
+import org.eclipse.hawkbit.simulator.amqp.SpSenderService;
+
/**
* A simulated device using the DMF API of the hawkBit update server.
*/
public class DMFSimulatedDevice extends AbstractSimulatedDevice {
+ private final SpSenderService spSenderService;
/**
* @param id
@@ -19,8 +22,15 @@ public class DMFSimulatedDevice extends AbstractSimulatedDevice {
* @param tenant
* the tenant of the simulated device
*/
- public DMFSimulatedDevice(final String id, final String tenant) {
- super(id, tenant, Protocol.DMF_AMQP);
+ public DMFSimulatedDevice(final String id, final String tenant, final SpSenderService spSenderService,
+ final int pollDelaySec) {
+ super(id, tenant, Protocol.DMF_AMQP, pollDelaySec);
+ this.spSenderService = spSenderService;
+ }
+
+ @Override
+ public void poll() {
+ spSenderService.createOrUpdateThing(super.getTenant(), super.getId());
}
}
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorRepository.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorRepository.java
index 68db9df45..66ceacc8e 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorRepository.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorRepository.java
@@ -9,8 +9,8 @@
package org.eclipse.hawkbit.simulator;
import java.util.Collection;
-import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -25,7 +25,7 @@ import org.springframework.stereotype.Service;
@Service
public class DeviceSimulatorRepository {
- private final Map devices = new LinkedHashMap<>();
+ private final Map devices = new ConcurrentHashMap<>();
@Autowired
private SimulatedDeviceFactory deviceFactory;
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/NextPollTimeController.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/NextPollTimeController.java
index 956d6d36a..96b4a1e97 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/NextPollTimeController.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/NextPollTimeController.java
@@ -8,12 +8,11 @@
*/
package org.eclipse.hawkbit.simulator;
-import java.util.List;
+import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
import org.eclipse.hawkbit.simulator.event.NextPollCounterUpdate;
import org.slf4j.Logger;
@@ -51,18 +50,17 @@ public class NextPollTimeController {
private class NextPollUpdaterRunnable implements Runnable {
@Override
public void run() {
- final List devices = repository.getAll().stream()
- .filter(device -> device instanceof DDISimulatedDevice).collect(Collectors.toList());
+ final Collection devices = repository.getAll();
devices.forEach(device -> {
int nextCounter = device.getNextPollCounterSec() - 1;
- if (nextCounter < 0 && device instanceof DDISimulatedDevice) {
+ if (nextCounter < 0) {
try {
- pollService.submit(() -> ((DDISimulatedDevice) device).poll());
+ pollService.submit(() -> device.poll());
} catch (final IllegalStateException e) {
LOGGER.trace("Device could not be polled", e);
}
- nextCounter = ((DDISimulatedDevice) device).getPollDelaySec();
+ nextCounter = device.getPollDelaySec();
}
device.setNextPollCounterSec(nextCounter);
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatedDeviceFactory.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatedDeviceFactory.java
index f29aad001..35829c673 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatedDeviceFactory.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulatedDeviceFactory.java
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.simulator;
import java.net.URL;
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol;
+import org.eclipse.hawkbit.simulator.amqp.SpSenderService;
import org.eclipse.hawkbit.simulator.http.ControllerResource;
import org.eclipse.hawkbit.simulator.http.GatewayTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +29,9 @@ public class SimulatedDeviceFactory {
@Autowired
private DeviceSimulatorUpdater deviceUpdater;
+ @Autowired
+ private SpSenderService spSenderService;
+
/**
* Creating a simulated devices.
*
@@ -55,7 +59,7 @@ public class SimulatedDeviceFactory {
* the protocol which should be used be the simulated device
* @param pollDelaySec
* the poll delay time in seconds which should be used for
- * {@link DDISimulatedDevice}s
+ * {@link DDISimulatedDevice}s and {@link DMFSimulatedDevice}
* @param baseEndpoint
* the http base endpoint which should be used for
* {@link DDISimulatedDevice}s
@@ -68,7 +72,7 @@ public class SimulatedDeviceFactory {
final int pollDelaySec, final URL baseEndpoint, final String gatewayToken) {
switch (protocol) {
case DMF_AMQP:
- return new DMFSimulatedDevice(id, tenant);
+ return new DMFSimulatedDevice(id, tenant, spSenderService, pollDelaySec);
case DDI_HTTP:
final ControllerResource controllerResource = Feign.builder().logger(new Logger.ErrorLogger())
.requestInterceptor(new GatewayTokenInterceptor(gatewayToken)).logLevel(Logger.Level.BASIC)
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java
index 649d88477..3bd6b41f2 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationController.java
@@ -66,7 +66,7 @@ public class SimulationController {
@RequestParam(value = "tenant", defaultValue = "DEFAULT") final String tenant,
@RequestParam(value = "api", defaultValue = "dmf") final String api,
@RequestParam(value = "endpoint", defaultValue = "http://localhost:8080") final String endpoint,
- @RequestParam(value = "polldelay", defaultValue = "30") final int pollDelay,
+ @RequestParam(value = "polldelay", defaultValue = "1800") final int pollDelay,
@RequestParam(value = "gatewaytoken", defaultValue = "") final String gatewayToken)
throws MalformedURLException {
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java
index 354263934..fb98ff67e 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/SimulationProperties.java
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.simulator;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol;
import org.hibernate.validator.constraints.NotEmpty;
@@ -68,9 +69,9 @@ public class SimulationProperties {
private String endpoint = "http://localhost:8080";
/**
- * Poll time in case of DDI API based simulation.
+ * Poll time in {@link TimeUnit#SECONDS} for simulated devices.
*/
- private int pollDelay = 30;
+ private int pollDelay = (int) TimeUnit.MINUTES.toSeconds(30);
/**
* Optional gateway token for DDI API based simulation.
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java
index e954cec96..5be5c7dcb 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/AmqpConfiguration.java
@@ -12,52 +12,103 @@ import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
-import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.retry.backoff.ExponentialBackOffPolicy;
+import org.springframework.retry.support.RetryTemplate;
/**
* The spring AMQP configuration to use a AMQP for communication with SP update
* server.
- *
- *
- *
*/
@Configuration
@EnableConfigurationProperties(AmqpProperties.class)
public class AmqpConfiguration {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AmqpConfiguration.class);
+
@Autowired
protected AmqpProperties amqpProperties;
@Autowired
private ConnectionFactory connectionFactory;
- @Autowired
- private RabbitTemplate rabbitTemplate;
-
/**
- * Create jackson message converter bean.
- *
- * @return the jackson message converter
+ * @return {@link RabbitTemplate} with automatic retry, published confirms
+ * and {@link Jackson2JsonMessageConverter}.
*/
@Bean
- public MessageConverter jsonMessageConverter() {
- final Jackson2JsonMessageConverter jackson2JsonMessageConverter = new Jackson2JsonMessageConverter();
- rabbitTemplate.setMessageConverter(jackson2JsonMessageConverter);
- return jackson2JsonMessageConverter;
+ public RabbitTemplate rabbitTemplate() {
+ final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
+ rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
+
+ final RetryTemplate retryTemplate = new RetryTemplate();
+ retryTemplate.setBackOffPolicy(new ExponentialBackOffPolicy());
+ rabbitTemplate.setRetryTemplate(retryTemplate);
+
+ rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
+ if (ack) {
+ LOGGER.debug("Message with correlation ID {} confirmed by broker.", correlationData.getId());
+ } else {
+ LOGGER.error("Broker is unable to handle message with correlation ID {} : {}", correlationData.getId(),
+ cause);
+ }
+
+ });
+
+ return rabbitTemplate;
+ }
+
+ @Configuration
+ protected static class RabbitConnectionFactoryCreator {
+
+ /**
+ * {@link ConnectionFactory} with enabled publisher confirms and
+ * heartbeat.
+ *
+ * @param config
+ * with standard {@link RabbitProperties}
+ * @return {@link ConnectionFactory}
+ */
+ @Bean
+ public ConnectionFactory rabbitConnectionFactory(final RabbitProperties config) {
+ final CachingConnectionFactory factory = new CachingConnectionFactory();
+ factory.setRequestedHeartBeat(60);
+ factory.setPublisherConfirms(true);
+
+ final String addresses = config.getAddresses();
+ factory.setAddresses(addresses);
+ if (config.getHost() != null) {
+ factory.setHost(config.getHost());
+ factory.setPort(config.getPort());
+ }
+ if (config.getUsername() != null) {
+ factory.setUsername(config.getUsername());
+ }
+ if (config.getPassword() != null) {
+ factory.setPassword(config.getPassword());
+ }
+ if (config.getVirtualHost() != null) {
+ factory.setVirtualHost(config.getVirtualHost());
+ }
+ return factory;
+ }
}
/**
@@ -136,10 +187,10 @@ public class AmqpConfiguration {
@Bean(name = { "listenerContainerFactory" })
public SimpleRabbitListenerContainerFactory listenerContainerFactory() {
final SimpleRabbitListenerContainerFactory containerFactory = new SimpleRabbitListenerContainerFactory();
- containerFactory.setDefaultRequeueRejected(false);
+ containerFactory.setDefaultRequeueRejected(true);
containerFactory.setConnectionFactory(connectionFactory);
- containerFactory.setConcurrentConsumers(20);
- containerFactory.setMaxConcurrentConsumers(20);
+ containerFactory.setConcurrentConsumers(3);
+ containerFactory.setMaxConcurrentConsumers(10);
containerFactory.setPrefetchCount(20);
return containerFactory;
}
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/ReceiverService.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/ReceiverService.java
index f5c02789e..2e8833bab 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/ReceiverService.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/ReceiverService.java
@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.simulator.amqp;
+import org.springframework.amqp.AmqpRejectAndDontRequeueException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@@ -55,7 +56,7 @@ public abstract class ReceiverService extends MessageService {
if (contentType != null && contentType.contains("json")) {
return;
}
- throw new IllegalArgumentException("Content-Type is not JSON compatible");
+ throw new AmqpRejectAndDontRequeueException("Content-Type is not JSON compatible");
}
}
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SenderService.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SenderService.java
index 6ed6ff0cb..f2c0e7fcb 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SenderService.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SenderService.java
@@ -8,9 +8,14 @@
*/
package org.eclipse.hawkbit.simulator.amqp;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired;
*/
public abstract class SenderService extends MessageService {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SenderService.class);
+
/**
* Constructor for sender service.
*
@@ -40,18 +47,26 @@ public abstract class SenderService extends MessageService {
/**
* Send a message if the message is not null.
*
- * @param adress
+ * @param address
* the exchange name
* @param message
* the amqp message which will be send if its not null
*/
- public void sendMessage(final String adress, final Message message) {
+ public void sendMessage(final String address, final Message message) {
if (message == null) {
return;
}
message.getMessageProperties().getHeaders().remove(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME);
- rabbitTemplate.setExchange(adress);
- rabbitTemplate.send(message);
+ final String correlationId = UUID.randomUUID().toString();
+ message.getMessageProperties().setCorrelationId(correlationId.getBytes());
+
+ if (LOGGER.isTraceEnabled()) {
+ LOGGER.trace("Sending message {} to exchange {} with correlationId {}", message, address, correlationId);
+ } else {
+ LOGGER.debug("Sending message to exchange {} with correlationId {}", address, correlationId);
+ }
+
+ rabbitTemplate.send(address, null, message, new CorrelationData(correlationId));
}
/**
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java
index e06b2baf3..4f2981be1 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/amqp/SpReceiverService.java
@@ -35,14 +35,21 @@ import com.google.common.collect.Lists;
public class SpReceiverService extends ReceiverService {
private static final Logger LOGGER = LoggerFactory.getLogger(ReceiverService.class);
- public static final String SOFTWARE_MODULE_FIRMWARE = "firmware";
-
private final SpSenderService spSenderService;
private final DeviceSimulatorUpdater deviceUpdater;
/**
* Constructor.
+ *
+ * @param rabbitTemplate
+ * for sending messages
+ * @param amqpProperties
+ * for amqp configuration
+ * @param spSenderService
+ * to send messages
+ * @param deviceUpdater
+ * simulator service for updates
*/
@Autowired
public SpReceiverService(final RabbitTemplate rabbitTemplate, final AmqpProperties amqpProperties,
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/NextPollCounterUpdate.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/NextPollCounterUpdate.java
index b9d7b9027..5e98ebb64 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/NextPollCounterUpdate.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/NextPollCounterUpdate.java
@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.simulator.event;
-import java.util.List;
+import java.util.Collection;
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice;
@@ -20,7 +20,7 @@ import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice;
*/
public class NextPollCounterUpdate {
- private final List devices;
+ private final Collection devices;
/**
* Creates poll timer update event.
@@ -28,14 +28,14 @@ public class NextPollCounterUpdate {
* @param devices
* the devices which progress has been updated
*/
- public NextPollCounterUpdate(final List devices) {
+ public NextPollCounterUpdate(final Collection devices) {
this.devices = devices;
}
/**
* @return the devices of the event
*/
- public List getDevices() {
+ public Collection getDevices() {
return devices;
}
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/GenerateDialog.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/GenerateDialog.java
index e337e86e7..272531407 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/GenerateDialog.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/GenerateDialog.java
@@ -76,7 +76,6 @@ public class GenerateDialog extends Window {
pollDelayTextField = createRequiredTextfield("poll delay (sec)", new ObjectProperty(10),
FontAwesome.CLOCK_O, new RangeValidator("Must be between 1 and 60", Integer.class, 1, 60));
- pollDelayTextField.setVisible(false);
pollUrlTextField = createRequiredTextfield("base poll URL endpoint", "http://localhost:8080",
FontAwesome.FLAG_O, new RegexpValidator(
@@ -193,7 +192,6 @@ public class GenerateDialog extends Window {
protocolGroup.select(Protocol.DMF_AMQP);
protocolGroup.addValueChangeListener(event -> {
final boolean directDeviceOptionSelected = event.getProperty().getValue().equals(Protocol.DDI_HTTP);
- pollDelayTextField.setVisible(directDeviceOptionSelected);
pollUrlTextField.setVisible(directDeviceOptionSelected);
gatewayTokenTextField.setVisible(directDeviceOptionSelected);
});
diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java
index 4834bece9..9405edd2b 100644
--- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java
+++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java
@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.simulator.ui;
-import java.util.List;
+import java.util.Collection;
import java.util.Locale;
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice;
@@ -167,7 +167,7 @@ public class SimulatorView extends VerticalLayout implements View {
@SuppressWarnings("unchecked")
@Subscribe
public void pollCounterUpdate(final NextPollCounterUpdate update) {
- final List devices = update.getDevices();
+ final Collection devices = update.getDevices();
this.getUI().access(() -> devices.forEach(device -> {
final BeanItem item = beanContainer.getItem(device.getId());
if (item != null) {
diff --git a/examples/hawkbit-device-simulator/src/main/resources/application.properties b/examples/hawkbit-device-simulator/src/main/resources/application.properties
index fbe7261be..5d3f04be7 100644
--- a/examples/hawkbit-device-simulator/src/main/resources/application.properties
+++ b/examples/hawkbit-device-simulator/src/main/resources/application.properties
@@ -24,7 +24,6 @@ spring.rabbitmq.virtualHost=/
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.dynamic=true
-spring.rabbitmq.listener.prefetch=100
security.basic.enabled=false
server.port=8083
diff --git a/examples/hawkbit-device-simulator/src/main/resources/logback.xml b/examples/hawkbit-device-simulator/src/main/resources/logback.xml
index 469c7bde3..5f3f1dbef 100644
--- a/examples/hawkbit-device-simulator/src/main/resources/logback.xml
+++ b/examples/hawkbit-device-simulator/src/main/resources/logback.xml
@@ -19,10 +19,7 @@
-
-
-
-
+
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetClientResource.java
index 7bf696a8f..40eb13b55 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetClientResource.java
@@ -15,7 +15,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
/**
* Client binding for the DistributionSet resource of the management API.
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
public interface MgmtDistributionSetClientResource extends MgmtDistributionSetRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetTagClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetTagClientResource.java
index 783cc09fa..1070bbd9c 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetTagClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetTagClientResource.java
@@ -15,6 +15,6 @@ import org.springframework.cloud.netflix.feign.FeignClient;
/**
* Client binding for the DistributionSetTag resource of the management API.
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
public interface MgmtDistributionSetTagClientResource extends MgmtDistributionSetTagRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetTypeClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetTypeClientResource.java
index 35f26781f..451c53942 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetTypeClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDistributionSetTypeClientResource.java
@@ -16,7 +16,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
* Client binding for the DistributionSetType resource of the management API.
*
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
public interface MgmtDistributionSetTypeClientResource extends MgmtDistributionSetTypeRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDownloadArtifactClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDownloadArtifactClientResource.java
index d25a609b2..5c93edce5 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDownloadArtifactClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDownloadArtifactClientResource.java
@@ -16,7 +16,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
* A feign-client interface declaration which allows to build a feign-client
* stub.
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
public interface MgmtDownloadArtifactClientResource extends MgmtDownloadArtifactRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDownloadClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDownloadClientResource.java
index 9a1dcee61..330d3908f 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDownloadClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtDownloadClientResource.java
@@ -15,6 +15,6 @@ import org.springframework.cloud.netflix.feign.FeignClient;
/**
*
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING_BASE)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING_BASE)
public interface MgmtDownloadClientResource extends MgmtDownloadRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtRolloutClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtRolloutClientResource.java
index d2643a938..acc00d6fe 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtRolloutClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtRolloutClientResource.java
@@ -15,6 +15,6 @@ import org.springframework.cloud.netflix.feign.FeignClient;
/**
* Client binding for the Rollout resource of the management API.
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING)
public interface MgmtRolloutClientResource extends MgmtRolloutRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSoftwareModuleClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSoftwareModuleClientResource.java
index 16ea188bd..7a2267e24 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSoftwareModuleClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSoftwareModuleClientResource.java
@@ -24,9 +24,10 @@ import feign.Param;
/**
* Client binding for the SoftwareModule resource of the management API.
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
public interface MgmtSoftwareModuleClientResource extends MgmtSoftwareModuleRestApi {
+ @Override
@RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/artifacts")
ResponseEntity uploadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
@Param("file") final MultipartFile file,
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSoftwareModuleTypeClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSoftwareModuleTypeClientResource.java
index 1e9462c47..603e82f10 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSoftwareModuleTypeClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSoftwareModuleTypeClientResource.java
@@ -15,6 +15,6 @@ import org.springframework.cloud.netflix.feign.FeignClient;
/**
* Client binding for the SoftwareModuleType resource of the management API.
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)
public interface MgmtSoftwareModuleTypeClientResource extends MgmtSoftwareModuleTypeRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSystemClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSystemClientResource.java
index 7d6967fed..e1bbd909c 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSystemClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSystemClientResource.java
@@ -16,6 +16,6 @@ import org.springframework.cloud.netflix.feign.FeignClient;
* Client binding for the {@link MgmtSystemRestApi}.
*
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING)
public interface MgmtSystemClientResource extends MgmtSystemRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSystemManagementClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSystemManagementClientResource.java
index d1974b43f..802194fe8 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSystemManagementClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtSystemManagementClientResource.java
@@ -16,7 +16,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
* Client binding for the {@link MgmtSystemManagementRestApi}.
*
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.SYSTEM_ADMIN_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SYSTEM_ADMIN_MAPPING)
public interface MgmtSystemManagementClientResource extends MgmtSystemManagementRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetClientResource.java
index 872c4251a..c0a0193af 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetClientResource.java
@@ -15,6 +15,6 @@ import org.springframework.cloud.netflix.feign.FeignClient;
/**
* Client binding for the Target resource of the management API.
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
public interface MgmtTargetClientResource extends MgmtTargetRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetTagClientResource.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetTagClientResource.java
index 7b0c213af..3f9264337 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetTagClientResource.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetTagClientResource.java
@@ -15,6 +15,6 @@ import org.springframework.cloud.netflix.feign.FeignClient;
/**
* Client binding for the TargetTag resource of the management API.
*/
-@FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
+@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
public interface MgmtTargetTagClientResource extends MgmtTargetTagRestApi {
}
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java
index 1e58b8415..a51d96d88 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java
@@ -84,32 +84,48 @@ public class DistributionSetBuilder {
* @return a single entry list of {@link MgmtDistributionSetRequestBodyPost}
*/
public List build() {
- return Lists.newArrayList(doBuild(name));
+ return Lists.newArrayList(doBuild(""));
}
/**
* Builds a list of multiple {@link MgmtDistributionSetRequestBodyPost} to
* create multiple distribution sets at once. An increasing number will be
- * added to the name of the distribution set. The version and type will
- * remain the same.
+ * used for version of the distribution set. The name and type will remain
+ * the same.
*
* @param count
* the amount of distribution sets body which should be created
* @return a list of {@link MgmtDistributionSetRequestBodyPost}
*/
public List buildAsList(final int count) {
+ return buildAsList(0, count);
+ }
+
+ /**
+ * Builds a list of multiple {@link MgmtDistributionSetRequestBodyPost} to
+ * create multiple distribution sets at once. An increasing number will be
+ * used for version of the distribution set starting from given offset. The
+ * name and type will remain the same.
+ *
+ * @param count
+ * the amount of distribution sets body which should be created
+ * @param offset
+ * for for index start
+ * @return a list of {@link MgmtDistributionSetRequestBodyPost}
+ */
+ public List buildAsList(final int offset, final int count) {
final ArrayList bodyList = Lists.newArrayList();
- for (int index = 0; index < count; index++) {
- bodyList.add(doBuild(name + index));
+ for (int index = offset; index < count + offset; index++) {
+ bodyList.add(doBuild(String.valueOf(index)));
}
return bodyList;
}
- private MgmtDistributionSetRequestBodyPost doBuild(final String prefixName) {
+ private MgmtDistributionSetRequestBodyPost doBuild(final String suffix) {
final MgmtDistributionSetRequestBodyPost body = new MgmtDistributionSetRequestBodyPost();
- body.setName(prefixName);
- body.setVersion(version);
+ body.setName(name);
+ body.setVersion(version + suffix);
body.setType(type);
body.setDescription(description);
body.setModules(modules);
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java
index 1ce2ff270..028060f37 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java
@@ -101,7 +101,7 @@ public class DistributionSetTypeBuilder {
* {@link MgmtDistributionSetTypeRequestBodyPost}
*/
public List build() {
- return Lists.newArrayList(doBuild(name, key));
+ return Lists.newArrayList(doBuild(""));
}
/**
@@ -118,16 +118,16 @@ public class DistributionSetTypeBuilder {
public List buildAsList(final int count) {
final ArrayList bodyList = Lists.newArrayList();
for (int index = 0; index < count; index++) {
- bodyList.add(doBuild(name + index, key + index));
+ bodyList.add(doBuild(String.valueOf(index)));
}
return bodyList;
}
- private MgmtDistributionSetTypeRequestBodyPost doBuild(final String prefixName, final String prefixKey) {
+ private MgmtDistributionSetTypeRequestBodyPost doBuild(final String suffix) {
final MgmtDistributionSetTypeRequestBodyPost body = new MgmtDistributionSetTypeRequestBodyPost();
- body.setKey(prefixKey);
- body.setName(prefixName);
+ body.setKey(key + suffix);
+ body.setName(name + suffix);
body.setDescription(description);
body.setMandatorymodules(mandatorymodules);
body.setOptionalmodules(optionalmodules);
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java
index b2e544f88..db7941bfc 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java
@@ -90,13 +90,13 @@ public class SoftwareModuleBuilder {
* @return a single entry list of {@link MgmtSoftwareModuleRequestBodyPost}
*/
public List build() {
- return Lists.newArrayList(doBuild(name));
+ return Lists.newArrayList(doBuild(""));
}
/**
* Builds a list of multiple {@link MgmtSoftwareModuleRequestBodyPost} to
* create multiple software module at once. An increasing number will be
- * added to the name of the software module. The version and type will
+ * added to the version of the software module. The name and type will
* remain the same.
*
* @param count
@@ -106,16 +106,16 @@ public class SoftwareModuleBuilder {
public List buildAsList(final int count) {
final ArrayList bodyList = Lists.newArrayList();
for (int index = 0; index < count; index++) {
- bodyList.add(doBuild(name + index));
+ bodyList.add(doBuild(String.valueOf(index)));
}
return bodyList;
}
- private MgmtSoftwareModuleRequestBodyPost doBuild(final String prefixName) {
+ private MgmtSoftwareModuleRequestBodyPost doBuild(final String suffix) {
final MgmtSoftwareModuleRequestBodyPost body = new MgmtSoftwareModuleRequestBodyPost();
- body.setName(prefixName);
- body.setVersion(version);
+ body.setName(name);
+ body.setVersion(version + suffix);
body.setType(type);
body.setVendor(vendor);
body.setDescription(description);
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java
index 7981e61cf..7807d0f11 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleTypeBuilder.java
@@ -69,7 +69,7 @@ public class SoftwareModuleTypeBuilder {
* {@link MgmtSoftwareModuleTypeRequestBodyPost}
*/
public List build() {
- return Lists.newArrayList(doBuild(key, name));
+ return Lists.newArrayList(doBuild(""));
}
/**
@@ -85,15 +85,15 @@ public class SoftwareModuleTypeBuilder {
public List buildAsList(final int count) {
final ArrayList bodyList = Lists.newArrayList();
for (int index = 0; index < count; index++) {
- bodyList.add(doBuild(key + index, name + index));
+ bodyList.add(doBuild(String.valueOf(index)));
}
return bodyList;
}
- private MgmtSoftwareModuleTypeRequestBodyPost doBuild(final String prefixKey, final String prefixName) {
+ private MgmtSoftwareModuleTypeRequestBodyPost doBuild(final String suffix) {
final MgmtSoftwareModuleTypeRequestBodyPost body = new MgmtSoftwareModuleTypeRequestBodyPost();
- body.setKey(prefixKey);
- body.setName(prefixName);
+ body.setKey(key + suffix);
+ body.setName(name + suffix);
body.setDescription(description);
body.setMaxAssignments(maxAssignments);
return body;
diff --git a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java
index 7bcc0af09..5fbcd0313 100644
--- a/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java
+++ b/examples/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java
@@ -8,7 +8,6 @@
*/
package org.eclipse.hawkbit.mgmt.client.resource.builder;
-import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost;
@@ -28,6 +27,7 @@ public class TargetBuilder {
private String controllerId;
private String name;
private String description;
+ private String address;
/**
* @param controllerId
@@ -49,6 +49,16 @@ public class TargetBuilder {
return this;
}
+ /**
+ * @param address
+ * the address of the target
+ * @return the builder itself
+ */
+ public TargetBuilder address(final String address) {
+ this.address = address;
+ return this;
+ }
+
/**
* @param description
* the description of the target
@@ -66,32 +76,54 @@ public class TargetBuilder {
* @return a single entry list of {@link MgmtTargetRequestBody}
*/
public List build() {
- return Lists.newArrayList(doBuild(controllerId));
+ return Lists.newArrayList(doBuild(""));
}
/**
* Builds a list of multiple {@link MgmtTargetRequestBody} to create
* multiple targets at once. An increasing number will be added to the
- * controllerId of the target. The name and description will remain.
+ * controllerId and name of the target. The description will remain.
*
* @param count
- * the amount of software module type bodies which should be
- * created
+ * the amount of target bodies which should be created
+ * @param offset
+ * for
* @return a list of {@link MgmtSoftwareModuleTypeRequestBodyPost}
*/
public List buildAsList(final int count) {
- final ArrayList bodyList = Lists.newArrayList();
- for (int index = 0; index < count; index++) {
- bodyList.add(doBuild(controllerId + index));
+
+ return buildAsList(0, count);
+ }
+
+ /**
+ * Builds a list of multiple {@link MgmtTargetRequestBody} to create
+ * multiple targets at once. An increasing number will be added to the
+ * controllerId and name of the target starting from the provided offset.
+ * The description will remain.
+ *
+ * @param count
+ * the amount of target bodies which should be created
+ * @param offset
+ * for for index start
+ * @return a list of {@link MgmtSoftwareModuleTypeRequestBodyPost}
+ */
+ public List buildAsList(final int offset, final int count) {
+ final List bodyList = Lists.newArrayList();
+ for (int index = offset; index < count + offset; index++) {
+ bodyList.add(doBuild(String.valueOf(index)));
}
return bodyList;
}
- private MgmtTargetRequestBody doBuild(final String prefixControllerId) {
+ private MgmtTargetRequestBody doBuild(final String suffix) {
final MgmtTargetRequestBody body = new MgmtTargetRequestBody();
- body.setControllerId(prefixControllerId);
- body.setName(name);
+ body.setControllerId(controllerId + suffix);
+ if (name == null) {
+ name = controllerId;
+ }
+ body.setName(name + suffix);
body.setDescription(description);
+ body.setAddress(address);
return body;
}
diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/Application.java b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/Application.java
index 7e1f191a9..ac65455b5 100644
--- a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/Application.java
+++ b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/Application.java
@@ -9,23 +9,40 @@
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.MgmtRolloutClientResource;
+import org.eclipse.hawkbit.mgmt.client.resource.MgmtSoftwareModuleClientResource;
+import org.eclipse.hawkbit.mgmt.client.resource.MgmtTargetClientResource;
+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.eclipse.hawkbit.mgmt.client.scenarios.upload.FeignMultipartEncoder;
+import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
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;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import feign.Feign;
+import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
+import feign.jackson.JacksonDecoder;
+import feign.slf4j.Slf4jLogger;
@SpringBootApplication
-@EnableFeignClients
+@EnableFeignClients("org.eclipse.hawkbit.mgmt.client.resource")
@EnableConfigurationProperties(ClientConfigurationProperties.class)
@Configuration
@AutoConfigureAfter(FeignClientConfiguration.class)
@@ -36,7 +53,7 @@ public class Application implements CommandLineRunner {
private ClientConfigurationProperties configuration;
@Autowired
- private GettingStartedDefaultScenario gettingStarted;
+ private ConfigurableScenario configuredScenario;
@Autowired
private CreateStartedRolloutExample gettingStartedRolloutScenario;
@@ -51,9 +68,8 @@ public class Application implements CommandLineRunner {
// run the create and start rollout example
gettingStartedRolloutScenario.run();
} else {
- // run the getting started scenario which creates a setup of
- // distribution set and software modules to be used
- gettingStarted.run();
+ // run the configured scenario from properties
+ configuredScenario.run();
}
}
@@ -63,8 +79,13 @@ public class Application implements CommandLineRunner {
}
@Bean
- public GettingStartedDefaultScenario gettingStartedDefaultScenario() {
- return new GettingStartedDefaultScenario();
+ public ConfigurableScenario configurableScenario(final MgmtDistributionSetClientResource distributionSetResource,
+ @Qualifier("mgmtSoftwareModuleClientResource") final MgmtSoftwareModuleClientResource softwareModuleResource,
+ @Qualifier("uploadSoftwareModule") final MgmtSoftwareModuleClientResource uploadSoftwareModule,
+ final MgmtTargetClientResource targetResource, final MgmtRolloutClientResource rolloutResource,
+ final ClientConfigurationProperties clientConfigurationProperties) {
+ return new ConfigurableScenario(distributionSetResource, softwareModuleResource, uploadSoftwareModule,
+ targetResource, rolloutResource, clientConfigurationProperties);
}
@Bean
@@ -72,7 +93,27 @@ public class Application implements CommandLineRunner {
return new CreateStartedRolloutExample();
}
- private boolean containsArg(final String containsArg, final String... args) {
+ @Bean
+ public Logger.Level feignLoggerLevel() {
+ return Logger.Level.FULL;
+ }
+
+ @Bean
+ public MgmtSoftwareModuleClientResource uploadSoftwareModule() {
+ 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() + MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING);
+ }
+
+ private static boolean containsArg(final String containsArg, final String... args) {
for (final String arg : args) {
if (arg.equalsIgnoreCase(containsArg)) {
return true;
@@ -80,4 +121,4 @@ public class Application implements CommandLineRunner {
}
return false;
}
-}
\ No newline at end of file
+}
diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/ClientConfigurationProperties.java b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/ClientConfigurationProperties.java
index 68f35b550..83a0844d4 100644
--- a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/ClientConfigurationProperties.java
+++ b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/ClientConfigurationProperties.java
@@ -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,142 @@ public class ClientConfigurationProperties {
private String password = "admin"; // NOSONAR this password is only used for
// examples
+ private final List scenarios = new ArrayList<>();
+
+ /**
+ * Simulation {@link Scenario}.
+ *
+ */
+ public static class Scenario {
+ private boolean cleanRepository;
+ 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";
+ private int artifactsPerSM = 1;
+ private String targetAddress = "amqp:/simulator.replyTo";
+ private boolean runRollouts = true;
+ private int rolloutDeploymentGroups = 4;
+
+ /**
+ * Artifact size. Values can use the suffixed "MB" or "KB" to indicate a
+ * Megabyte or Kilobyte size.
+ */
+ private String artifactSize = "1MB";
+
+ public boolean isCleanRepository() {
+ return cleanRepository;
+ }
+
+ public void setCleanRepository(final boolean cleanRepository) {
+ this.cleanRepository = cleanRepository;
+ }
+
+ public int getRolloutDeploymentGroups() {
+ return rolloutDeploymentGroups;
+ }
+
+ public void setRolloutDeploymentGroups(final int rolloutDeploymentGroups) {
+ this.rolloutDeploymentGroups = rolloutDeploymentGroups;
+ }
+
+ public boolean isRunRollouts() {
+ return runRollouts;
+ }
+
+ public void setRunRollouts(final boolean runRollouts) {
+ this.runRollouts = runRollouts;
+ }
+
+ public String getTargetAddress() {
+ return targetAddress;
+ }
+
+ public void setTargetAddress(final String targetAddress) {
+ this.targetAddress = targetAddress;
+ }
+
+ public int getArtifactsPerSM() {
+ return artifactsPerSM;
+ }
+
+ public void setArtifactsPerSM(final int artifactsPerSM) {
+ this.artifactsPerSM = artifactsPerSM;
+ }
+
+ public String getArtifactSize() {
+ return artifactSize;
+ }
+
+ public void setArtifactSize(final String artifactSize) {
+ this.artifactSize = artifactSize;
+ }
+
+ 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 getScenarios() {
+ return scenarios;
+ }
+
public String getUrl() {
return url;
}
diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/ConfigurableScenario.java b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/ConfigurableScenario.java
new file mode 100644
index 000000000..a09459e07
--- /dev/null
+++ b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/ConfigurableScenario.java
@@ -0,0 +1,242 @@
+/**
+ * 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 java.util.Random;
+import java.util.concurrent.TimeUnit;
+
+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.MgmtRolloutClientResource;
+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.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.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.target.MgmtTarget;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Qualifier;
+
+/**
+ *
+ * A configurable scenario which runs the configured scenarios.
+ *
+ * @see {@link ClientConfigurationProperties#getScenarios()}
+ *
+ */
+public class ConfigurableScenario {
+
+ private static final int PAGE_SIZE = 100;
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurableScenario.class);
+
+ private final MgmtDistributionSetClientResource distributionSetResource;
+
+ private final MgmtSoftwareModuleClientResource softwareModuleResource;
+
+ private final MgmtSoftwareModuleClientResource uploadSoftwareModule;
+
+ private final MgmtTargetClientResource targetResource;
+
+ private final MgmtRolloutClientResource rolloutResource;
+
+ private final ClientConfigurationProperties clientConfigurationProperties;
+
+ public ConfigurableScenario(final MgmtDistributionSetClientResource distributionSetResource,
+ @Qualifier("mgmtSoftwareModuleClientResource") final MgmtSoftwareModuleClientResource softwareModuleResource,
+ @Qualifier("uploadSoftwareModule") final MgmtSoftwareModuleClientResource uploadSoftwareModule,
+ final MgmtTargetClientResource targetResource, final MgmtRolloutClientResource rolloutResource,
+ final ClientConfigurationProperties clientConfigurationProperties) {
+ this.distributionSetResource = distributionSetResource;
+ this.softwareModuleResource = softwareModuleResource;
+ this.uploadSoftwareModule = uploadSoftwareModule;
+ this.targetResource = targetResource;
+ this.rolloutResource = rolloutResource;
+ this.clientConfigurationProperties = clientConfigurationProperties;
+ }
+
+ /**
+ * Run the default getting started scenario.
+ */
+ public void run() {
+
+ LOGGER.info("Running Configurable Scenario...");
+
+ clientConfigurationProperties.getScenarios().forEach(this::createScenario);
+ }
+
+ private void createScenario(final Scenario scenario) {
+ if (scenario.isCleanRepository()) {
+ cleanRepository();
+ }
+
+ createTargets(scenario);
+ createDistributionSets(scenario);
+
+ if (scenario.isRunRollouts()) {
+ runRollouts(scenario);
+ }
+ }
+
+ private void cleanRepository() {
+ LOGGER.info("Cleaning repository");
+ deleteTargets();
+ deleteRollouts();
+ deleteDistributionSets();
+ deleteSoftwareModules();
+ LOGGER.info("Cleaning repository -> Done");
+ }
+
+ private void deleteRollouts() {
+ // TODO: complete this as soon as rollouts can be deleted
+
+ }
+
+ private void deleteSoftwareModules() {
+ PagedList modules;
+ do {
+ modules = softwareModuleResource.getSoftwareModules(0, PAGE_SIZE, null, null).getBody();
+ modules.getContent().forEach(module -> softwareModuleResource.deleteSoftwareModule(module.getModuleId()));
+ } while (modules.getTotal() > PAGE_SIZE);
+ }
+
+ private void deleteDistributionSets() {
+ PagedList distributionSets;
+ do {
+ distributionSets = distributionSetResource.getDistributionSets(0, PAGE_SIZE, null, null).getBody();
+ distributionSets.getContent().forEach(set -> distributionSetResource.deleteDistributionSet(set.getDsId()));
+ } while (distributionSets.getTotal() > PAGE_SIZE);
+ }
+
+ private void deleteTargets() {
+ PagedList targets;
+ do {
+ targets = targetResource.getTargets(0, PAGE_SIZE, null, null).getBody();
+ targets.getContent().forEach(target -> targetResource.deleteTarget(target.getControllerId()));
+ } while (targets.getTotal() > PAGE_SIZE);
+ }
+
+ private void runRollouts(final Scenario scenario) {
+ distributionSetResource.getDistributionSets(0, scenario.getDistributionSets(), null, null).getBody()
+ .getContent().forEach(set -> runRollout(set, scenario));
+
+ }
+
+ 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())
+ .getBody();
+
+ // start the created Rollout
+ rolloutResource.start(rolloutResponseBody.getRolloutId(), true);
+
+ // wait until rollout is complete
+ do {
+ try {
+ TimeUnit.SECONDS.sleep(35);
+ } catch (final InterruptedException e) {
+ LOGGER.warn("Interrupted!");
+ Thread.currentThread().interrupt();
+ }
+ } while (targetResource.getTargets(0, 1, null, "updateStatus==IN_SYNC").getBody().getTotal() < scenario
+ .getTargets());
+ LOGGER.info("Run rollout for set {} -> Done", set.getDsId());
+ }
+
+ 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 modules = addModules(scenario, dsSet, artifact);
+
+ final SoftwareModuleAssigmentBuilder assign = new SoftwareModuleAssigmentBuilder();
+ modules.forEach(module -> assign.id(module.getModuleId()));
+ distributionSetResource.assignSoftwareModules(dsSet.getDsId(), assign.build());
+ });
+
+ LOGGER.info("Creating {} distribution sets -> Done", scenario.getDistributionSets());
+ }
+
+ private List addModules(final Scenario scenario, final MgmtDistributionSet dsSet,
+ final byte[] artifact) {
+ final List modules = softwareModuleResource
+ .createSoftwareModules(new SoftwareModuleBuilder().name(scenario.getSmFwName() + "-os")
+ .version(dsSet.getVersion()).type("os").build())
+ .getBody();
+ modules.addAll(softwareModuleResource.createSoftwareModules(
+ new SoftwareModuleBuilder().name(scenario.getSmSwName() + "-app").version(dsSet.getVersion() + ".")
+ .type("application").buildAsList(scenario.getAppModulesPerDistributionSet()))
+ .getBody());
+
+ for (int x = 0; x < scenario.getArtifactsPerSM(); x++) {
+ 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;
+ }
+
+ 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;
+ }
+
+ 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));
+ }
+
+ LOGGER.info("Creating {} targets -> Done", scenario.getTargets());
+ }
+
+ private static int parseSize(final String s) {
+ final String size = s.toUpperCase();
+ if (size.endsWith("KB")) {
+ return Integer.valueOf(size.substring(0, size.length() - 2)) * 1024;
+ }
+ if (size.endsWith("MB")) {
+ return Integer.valueOf(size.substring(0, size.length() - 2)) * 1024 * 1024;
+ }
+ return Integer.valueOf(size);
+ }
+}
diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java
index 90d61471e..b450bbde2 100644
--- a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java
+++ b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/CreateStartedRolloutExample.java
@@ -28,6 +28,7 @@ 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;
+import org.springframework.beans.factory.annotation.Qualifier;
/**
* Example for creating and starting a Rollout.
@@ -36,7 +37,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;
@@ -45,6 +46,7 @@ public class CreateStartedRolloutExample {
private MgmtDistributionSetClientResource distributionSetResource;
@Autowired
+ @Qualifier("mgmtSoftwareModuleClientResource")
private MgmtSoftwareModuleClientResource softwareModuleResource;
@Autowired
diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java
deleted file mode 100644
index fdb824e8e..000000000
--- a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/GettingStartedDefaultScenario.java
+++ /dev/null
@@ -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 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 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 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 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 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 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 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());
- }
-}
diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/upload/ArtifactFile.java b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/upload/ArtifactFile.java
new file mode 100644
index 000000000..379455580
--- /dev/null
+++ b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/upload/ArtifactFile.java
@@ -0,0 +1,108 @@
+/**
+ * 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.upload;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Optional;
+
+import org.springframework.util.Assert;
+import org.springframework.util.FileCopyUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * Implementation for {@link MultipartFile} for hawkBit artifact upload.
+ *
+ */
+public class ArtifactFile implements MultipartFile {
+
+ private final String name;
+
+ private final String originalFilename;
+
+ private final String contentType;
+
+ private final byte[] content;
+
+ /**
+ * Create a new ArtifactFile with the given content.
+ *
+ * @param name
+ * the name of the file
+ * @param content
+ * the content of the file
+ */
+ public ArtifactFile(final String name, final byte[] content) {
+ this(name, "", null, content);
+ }
+
+ /**
+ * Create a new ArtifactFile with the given content.
+ *
+ * @param name
+ * of the file
+ * @param originalFilename
+ * the original filename (as on the client's machine)
+ * @param contentType
+ * the content type
+ * @param content
+ * of the file
+ */
+ public ArtifactFile(final String name, final String originalFilename, final String contentType,
+ final byte[] content) {
+ Assert.hasLength(name, "Name must not be null");
+ this.name = name;
+ this.originalFilename = Optional.ofNullable(originalFilename).orElse("");
+ this.contentType = contentType;
+ this.content = Optional.ofNullable(content).orElse(new byte[0]);
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ public String getOriginalFilename() {
+ return this.originalFilename;
+ }
+
+ @Override
+ public String getContentType() {
+ return this.contentType;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.content.length == 0;
+ }
+
+ @Override
+ public long getSize() {
+ return this.content.length;
+ }
+
+ @Override
+ public byte[] getBytes() throws IOException {
+ return this.content;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return new ByteArrayInputStream(this.content);
+ }
+
+ @Override
+ public void transferTo(final File dest) throws IOException {
+ FileCopyUtils.copy(this.content, dest);
+ }
+
+}
diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/upload/FeignMultipartEncoder.java b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/upload/FeignMultipartEncoder.java
new file mode 100644
index 000000000..5d1e43e96
--- /dev/null
+++ b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/upload/FeignMultipartEncoder.java
@@ -0,0 +1,155 @@
+/**
+ * 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.upload;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Type;
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpOutputMessage;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
+
+import feign.RequestTemplate;
+import feign.codec.EncodeException;
+import feign.codec.Encoder;
+
+/**
+ * A feign encoder implementation which handles {@link MultipartFile} body.
+ */
+public class FeignMultipartEncoder implements Encoder {
+
+ private final List> converters = new RestTemplate().getMessageConverters();
+ private final HttpHeaders multipartHeaders = new HttpHeaders();
+ private final HttpHeaders jsonHeaders = new HttpHeaders();
+
+ private static final Charset UTF_8 = Charset.forName("UTF-8");
+
+ public FeignMultipartEncoder() {
+ multipartHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
+ jsonHeaders.setContentType(MediaType.APPLICATION_JSON);
+ }
+
+ @Override
+ public void encode(final Object object, final Type bodyType, final RequestTemplate template) {
+ encodeMultipartFormRequest(object, template);
+ }
+
+ private void encodeMultipartFormRequest(final Object value, final RequestTemplate template) {
+ if (value == null) {
+ throw new EncodeException("Cannot encode request with null value.");
+ }
+ if (!isMultipartFile(value)) {
+ throw new EncodeException("Only multipart can be handled by this encoder");
+ }
+ encodeRequest(encodeMultipartFile((MultipartFile) value), multipartHeaders, template);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void encodeRequest(final Object value, final HttpHeaders requestHeaders, final RequestTemplate template) {
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ final HttpOutputMessage dummyRequest = new HttpOutputMessageImpl(outputStream, requestHeaders);
+ try {
+ final Class> requestType = value.getClass();
+ final MediaType requestContentType = requestHeaders.getContentType();
+ for (final HttpMessageConverter> messageConverter : converters) {
+ if (messageConverter.canWrite(requestType, requestContentType)) {
+ ((HttpMessageConverter
+
+ com.rabbitmq
+ amqp-client
+ ${rabbitmq.version}
+
cz.jirutka.rsql