Optimisation and bug fixing of UI push events (#310)
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -177,8 +177,8 @@ public class DeviceSimulatorUpdater {
|
||||
|
||||
LOGGER.info("Simulate downloads for {}", device.getId());
|
||||
|
||||
modules.forEach(module -> module.getArtifacts()
|
||||
.forEach(artifact -> handleArtifacts(targetToken, status, artifact)));
|
||||
modules.forEach(
|
||||
module -> module.getArtifacts().forEach(artifact -> handleArtifact(targetToken, status, artifact)));
|
||||
|
||||
final UpdateStatus result = new UpdateStatus(ResponseStatus.SUCCESSFUL);
|
||||
result.getStatusMessages().add("Simulation complete!");
|
||||
@@ -202,7 +202,7 @@ public class DeviceSimulatorUpdater {
|
||||
return ResponseStatus.ERROR.equals(status.getResponseStatus());
|
||||
}
|
||||
|
||||
private static void handleArtifacts(final String targetToken, final List<UpdateStatus> status,
|
||||
private static void handleArtifact(final String targetToken, final List<UpdateStatus> status,
|
||||
final Artifact artifact) {
|
||||
|
||||
if (artifact.getUrls().containsKey("HTTPS")) {
|
||||
|
||||
@@ -32,22 +32,6 @@ public class SimulatedDeviceFactory {
|
||||
@Autowired
|
||||
private SpSenderService spSenderService;
|
||||
|
||||
/**
|
||||
* Creating a simulated devices.
|
||||
*
|
||||
* @param id
|
||||
* the ID of the simulated device
|
||||
* @param tenant
|
||||
* the tenant of the simulated device
|
||||
* @param protocol
|
||||
* the protocol of the device
|
||||
* @return the created simulated device
|
||||
*/
|
||||
public AbstractSimulatedDevice createSimulatedDevice(final String id, final String tenant,
|
||||
final Protocol protocol) {
|
||||
return createSimulatedDevice(id, tenant, protocol, 1800, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating a simulated device.
|
||||
*
|
||||
@@ -70,10 +54,19 @@ public class SimulatedDeviceFactory {
|
||||
*/
|
||||
public AbstractSimulatedDevice createSimulatedDevice(final String id, final String tenant, final Protocol protocol,
|
||||
final int pollDelaySec, final URL baseEndpoint, final String gatewayToken) {
|
||||
return createSimulatedDevice(id, tenant, protocol, pollDelaySec, baseEndpoint, gatewayToken, false);
|
||||
}
|
||||
|
||||
private AbstractSimulatedDevice createSimulatedDevice(final String id, final String tenant, final Protocol protocol,
|
||||
final int pollDelaySec, final URL baseEndpoint, final String gatewayToken, final boolean pollImmediatly) {
|
||||
switch (protocol) {
|
||||
case DMF_AMQP:
|
||||
spSenderService.createOrUpdateThing(tenant, id);
|
||||
return new DMFSimulatedDevice(id, tenant, spSenderService, pollDelaySec);
|
||||
final AbstractSimulatedDevice device = new DMFSimulatedDevice(id, tenant, spSenderService, pollDelaySec);
|
||||
device.setNextPollCounterSec(pollDelaySec);
|
||||
if (pollImmediatly) {
|
||||
spSenderService.createOrUpdateThing(tenant, id);
|
||||
}
|
||||
return device;
|
||||
case DDI_HTTP:
|
||||
final ControllerResource controllerResource = Feign.builder().logger(new Logger.ErrorLogger())
|
||||
.requestInterceptor(new GatewayTokenInterceptor(gatewayToken)).logLevel(Logger.Level.BASIC)
|
||||
@@ -83,4 +76,30 @@ public class SimulatedDeviceFactory {
|
||||
throw new IllegalArgumentException("Protocol " + protocol + " unknown");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creating a simulated device and send an immediate DMF poll to update
|
||||
* server.
|
||||
*
|
||||
* @param id
|
||||
* the ID of the simulated device
|
||||
* @param tenant
|
||||
* the tenant of the simulated device
|
||||
* @param protocol
|
||||
* 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 and {@link DMFSimulatedDevice}
|
||||
* @param baseEndpoint
|
||||
* the http base endpoint which should be used for
|
||||
* {@link DDISimulatedDevice}s
|
||||
* @param gatewayToken
|
||||
* the gatewayToken to be used to authenticate
|
||||
* {@link DDISimulatedDevice}s at the endpoint
|
||||
* @return the created simulated device
|
||||
*/
|
||||
public AbstractSimulatedDevice createSimulatedDeviceWithImmediatePoll(final String id, final String tenant,
|
||||
final Protocol protocol, final int pollDelaySec, final URL baseEndpoint, final String gatewayToken) {
|
||||
return createSimulatedDevice(id, tenant, protocol, pollDelaySec, baseEndpoint, gatewayToken, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ public class SimulationController {
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
final String deviceId = name + i;
|
||||
repository.add(deviceFactory.createSimulatedDevice(deviceId, tenant, protocol, pollDelay, new URL(endpoint),
|
||||
gatewayToken));
|
||||
repository.add(deviceFactory.createSimulatedDeviceWithImmediatePoll(deviceId, tenant, protocol, pollDelay,
|
||||
new URL(endpoint), gatewayToken));
|
||||
}
|
||||
|
||||
return ResponseEntity.ok("Updated " + amount + " " + protocol + " connected targets!");
|
||||
|
||||
@@ -48,9 +48,9 @@ public class SimulatorStartup implements ApplicationListener<ContextRefreshedEve
|
||||
final String deviceId = autostart.getName() + i;
|
||||
try {
|
||||
if (amqpProperties.isEnabled()) {
|
||||
repository.add(deviceFactory.createSimulatedDevice(deviceId, autostart.getTenant(),
|
||||
autostart.getApi(), autostart.getPollDelay(), new URL(autostart.getEndpoint()),
|
||||
autostart.getGatewayToken()));
|
||||
repository.add(deviceFactory.createSimulatedDeviceWithImmediatePoll(deviceId,
|
||||
autostart.getTenant(), autostart.getApi(), autostart.getPollDelay(),
|
||||
new URL(autostart.getEndpoint()), autostart.getGatewayToken()));
|
||||
}
|
||||
|
||||
} catch (final MalformedURLException e) {
|
||||
|
||||
@@ -268,8 +268,9 @@ public class SimulatorView extends VerticalLayout implements View {
|
||||
new GenerateDialog((namePrefix, tenant, amount, pollDelay, basePollUrl, gatewayToken, protocol) -> {
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final String deviceId = namePrefix + index;
|
||||
beanContainer.addBean(repository.add(deviceFactory.createSimulatedDevice(deviceId,
|
||||
tenant.toLowerCase(), protocol, pollDelay, basePollUrl, gatewayToken)));
|
||||
beanContainer
|
||||
.addBean(repository.add(deviceFactory.createSimulatedDeviceWithImmediatePoll(deviceId,
|
||||
tenant.toLowerCase(), protocol, pollDelay, basePollUrl, gatewayToken)));
|
||||
}
|
||||
}, amqpProperties.isEnabled()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user