Added simulator autostart and cf deployment.
This commit is contained in:
@@ -55,7 +55,7 @@ public class SimulationController {
|
||||
* number of delay in milliseconds to delay polling of DDI
|
||||
* devices
|
||||
* @param gatewayToken
|
||||
* the hawkbit-update-server gatwaytoken in case authentication
|
||||
* the hawkbit-update-server gatewaytoken in case authentication
|
||||
* is enforced in hawkbit
|
||||
* @return a response string that devices has been created
|
||||
* @throws MalformedURLException
|
||||
@@ -68,7 +68,7 @@ public class SimulationController {
|
||||
@RequestParam(value = "endpoint", defaultValue = "http://localhost:8080") final String endpoint,
|
||||
@RequestParam(value = "polldelay", defaultValue = "30") final int pollDelay,
|
||||
@RequestParam(value = "gatewaytoken", defaultValue = "") final String gatewayToken)
|
||||
throws MalformedURLException {
|
||||
throws MalformedURLException {
|
||||
|
||||
final Protocol protocol;
|
||||
switch (api.toLowerCase()) {
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* 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.simulator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* General simulator service properties.
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties("hawkbit.device.simulator")
|
||||
public class SimulationProperties {
|
||||
|
||||
/**
|
||||
* List of tenants where the simulator should auto start simulations after
|
||||
* startup.
|
||||
*/
|
||||
private final List<Autostart> autostarts = new ArrayList<>();
|
||||
|
||||
public List<Autostart> getAutostarts() {
|
||||
return this.autostarts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto start configuration for simulation setups that the simulator begins
|
||||
* after startup.
|
||||
*
|
||||
*/
|
||||
public static class Autostart {
|
||||
/**
|
||||
* Name prefix of simulated devices, followed by counter, e.g.
|
||||
* simulated0, simulated1, simulated2....
|
||||
*/
|
||||
private String name = "simulated";
|
||||
|
||||
/**
|
||||
* Amount of simulated devices.
|
||||
*/
|
||||
private int amount = 20;
|
||||
|
||||
/**
|
||||
* Tenant name for the simulation.
|
||||
*/
|
||||
@NotEmpty
|
||||
private String tenant;
|
||||
|
||||
/**
|
||||
* API for simulation.
|
||||
*/
|
||||
private Protocol api = Protocol.DMF_AMQP;
|
||||
|
||||
/**
|
||||
* Endpoint in case of DDI API based simulation.
|
||||
*/
|
||||
private String endpoint = "http://localhost:8080";
|
||||
|
||||
/**
|
||||
* Poll time in case of DDI API based simulation.
|
||||
*/
|
||||
private int pollDelay = 30;
|
||||
|
||||
/**
|
||||
* Optional gateway token for DDI API based simulation.
|
||||
*/
|
||||
private String gatewayToken = "";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(final int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public String getTenant() {
|
||||
return tenant;
|
||||
}
|
||||
|
||||
public void setTenant(final String tenant) {
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
public Protocol getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
public void setApi(final Protocol api) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
public void setEndpoint(final String endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
}
|
||||
|
||||
public int getPollDelay() {
|
||||
return pollDelay;
|
||||
}
|
||||
|
||||
public void setPollDelay(final int pollDelay) {
|
||||
this.pollDelay = pollDelay;
|
||||
}
|
||||
|
||||
public String getGatewayToken() {
|
||||
return gatewayToken;
|
||||
}
|
||||
|
||||
public void setGatewayToken(final String gatewayToken) {
|
||||
this.gatewayToken = gatewayToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.eclipse.hawkbit.simulator;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.hawkbit.simulator.amqp.SpSenderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Execution of operations after startup. Set up of simulations.
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class SimulatorStartup implements ApplicationListener<ContextRefreshedEvent> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SimulatorStartup.class);
|
||||
|
||||
@Autowired
|
||||
private SimulationProperties simulationProperties;
|
||||
|
||||
@Autowired
|
||||
private SpSenderService spSenderService;
|
||||
|
||||
@Autowired
|
||||
private DeviceSimulatorRepository repository;
|
||||
|
||||
@Autowired
|
||||
private SimulatedDeviceFactory deviceFactory;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(final ContextRefreshedEvent event) {
|
||||
simulationProperties.getAutostarts().forEach(autostart -> {
|
||||
for (int i = 0; i < autostart.getAmount(); i++) {
|
||||
final String deviceId = autostart.getName() + i;
|
||||
try {
|
||||
repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(),
|
||||
autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()),
|
||||
autostart.getGatewayToken()));
|
||||
} catch (final Exception e) {
|
||||
LOGGER.error("Creation of simulated device at startup failed.", e);
|
||||
}
|
||||
|
||||
spSenderService.createOrUpdateThing(autostart.getTenant(), deviceId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,26 +19,25 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@ConfigurationProperties("hawkbit.device.simulator.amqp")
|
||||
public class AmqpProperties {
|
||||
|
||||
/**
|
||||
* Queue for receiving DMF messages from update server.
|
||||
*/
|
||||
private String receiverConnectorQueueFromSp;
|
||||
private String receiverConnectorQueueFromSp = "simulator_receiver";
|
||||
|
||||
/**
|
||||
* Exchange for sending DMF messages to update server.
|
||||
*/
|
||||
private String senderForSpExchange;
|
||||
private String senderForSpExchange = "simulator.replyTo";
|
||||
|
||||
/**
|
||||
* Simulator dead letter queue.
|
||||
*/
|
||||
private String deadLetterQueue;
|
||||
private String deadLetterQueue = "simulator_deadletter";
|
||||
|
||||
/**
|
||||
* Simulator dead letter exchange.
|
||||
*/
|
||||
private String deadLetterExchange;
|
||||
private String deadLetterExchange = "simulator.deadletter";
|
||||
|
||||
public String getReceiverConnectorQueueFromSp() {
|
||||
return receiverConnectorQueueFromSp;
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Component
|
||||
public class SpReceiverService extends ReceiverService {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ReceiverService.class);
|
||||
|
||||
public static final String SOFTWARE_MODULE_FIRMWARE = "firmware";
|
||||
|
||||
@@ -13,8 +13,11 @@ hawkbit.device.simulator.amqp.deadLetterQueue=simulator_deadletter
|
||||
hawkbit.device.simulator.amqp.deadLetterExchange=simulator.deadletter
|
||||
hawkbit.device.simulator.amqp.senderForSpExchange=simulator.replyTo
|
||||
|
||||
## Configuration for simulations
|
||||
hawkbit.device.simulator.autostarts.[0].tenant=DEFAULT
|
||||
|
||||
## Configuration for RabbitMQ integration
|
||||
|
||||
## Configuration for local RabbitMQ integration
|
||||
spring.rabbitmq.username=guest
|
||||
spring.rabbitmq.password=guest
|
||||
spring.rabbitmq.virtualHost=/
|
||||
|
||||
Reference in New Issue
Block a user