Skip to content

Commit

Permalink
SDK DMF Support - from declarative to imperative - to support host pe…
Browse files Browse the repository at this point in the history
…r tenant (#1709)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Apr 11, 2024
1 parent c8220c4 commit b491d6d
Show file tree
Hide file tree
Showing 14 changed files with 351 additions and 442 deletions.
Expand Up @@ -34,5 +34,22 @@ public class Tenant {
@Nullable
private String gatewayToken;

// amqp settings (if DMF is used)
@Nullable
private DMF dmf;

private boolean downloadAuthenticationEnabled = true;

@Data
@ToString
public static class DMF {

@Nullable
private String virtualHost;
@Nullable
private String username;
@Nullable
@ToString.Exclude
private String password;
}
}
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.sdk.device;

import lombok.Getter;
import org.eclipse.hawkbit.sdk.Controller;
import org.eclipse.hawkbit.sdk.HawkbitClient;
import org.eclipse.hawkbit.sdk.Tenant;

import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

/**
* An in-memory simulated DMF Tenant to hold the controller twins in
* memory and be able to retrieve them again.
*/
public class DdiTenant {

@Getter
private final Tenant tenant;

private final Map<String, DdiController> controllers = new ConcurrentHashMap<>();
private final HawkbitClient hawkbitClient;

public DdiTenant(final Tenant tenant, final HawkbitClient hawkbitClient) {
this.tenant = tenant;
this.hawkbitClient = hawkbitClient;
}

public void destroy() {
controllers.values().forEach(DdiController::stop);
controllers.clear();
}

public DdiController create(final Controller controller, final UpdateHandler updateHandler) {
final DdiController ddiController = new DdiController(tenant, controller, updateHandler, hawkbitClient);
controllers.put(controller.getControllerId(), ddiController);
return ddiController;
}

public void remove(final String controllerId) {
Optional.ofNullable(controllers.remove(controllerId)).ifPresent(DdiController::stop);
}

public Optional<DdiController> getController(final String controllerId) {
return Optional.ofNullable(controllers.get(controllerId));
}
}

This file was deleted.

Expand Up @@ -16,7 +16,7 @@
import org.eclipse.hawkbit.dmf.json.model.DmfDownloadAndUpdateRequest;
import org.eclipse.hawkbit.sdk.Controller;
import org.eclipse.hawkbit.sdk.Tenant;
import org.eclipse.hawkbit.sdk.dmf.amqp.DmfSenderService;
import org.eclipse.hawkbit.sdk.dmf.amqp.DmfSender;

import java.util.Collections;
import java.util.Map;
Expand All @@ -36,7 +36,7 @@ public class DmfController {
private final String tenantId;
private final String controllerId;
private final UpdateHandler updateHandler;
private final DmfSenderService dmfSenderService;
private final DmfSender dmfSender;

// configuration
private final boolean downloadAuthenticationEnabled;
Expand All @@ -54,26 +54,26 @@ public class DmfController {
* @param tenant the tenant of the device belongs to
* @param controller the controller
*/
public DmfController(
DmfController(
final Tenant tenant, final Controller controller,
final UpdateHandler updateHandler,
final DmfSenderService dmfSenderService) {
final DmfSender dmfSender) {
this.tenantId = tenant.getTenantId();
downloadAuthenticationEnabled = tenant.isDownloadAuthenticationEnabled();
this.controllerId = controller.getControllerId();
this.updateHandler = updateHandler == null ? UpdateHandler.SKIP : updateHandler;
this.dmfSenderService = dmfSenderService;
this.dmfSender = dmfSender;
}

public void connect() {
log.debug(LOG_PREFIX + "Connecting/Polling ...", getTenantId(), getControllerId());
dmfSenderService.createOrUpdateThing(getTenantId(), getControllerId());
dmfSender.createOrUpdateThing(getTenantId(), getControllerId());
log.debug(LOG_PREFIX + "Done. Create thing sent.", getTenantId(), getControllerId());
}

public void poll() {
log.debug(LOG_PREFIX + "Polling ..", getTenantId(), getControllerId());
dmfSenderService.createOrUpdateThing(getTenantId(), getControllerId());
dmfSender.createOrUpdateThing(getTenantId(), getControllerId());
log.debug(LOG_PREFIX + "Done. Create thing sent.", getTenantId(), getControllerId());
}

Expand All @@ -87,6 +87,6 @@ public void processUpdate(final EventTopic actionType, final DmfDownloadAndUpdat
}

public void sendFeedback(final UpdateStatus updateStatus) {
dmfSenderService.sendFeedback(tenantId, currentActionId, updateStatus);
dmfSender.sendFeedback(tenantId, currentActionId, updateStatus);
}
}

This file was deleted.

This file was deleted.

0 comments on commit b491d6d

Please sign in to comment.