Refactoring/Improving source: dmf 2 (#1612)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-02-04 11:46:43 +02:00
committed by GitHub
parent da3a6470ec
commit c320a45b55
30 changed files with 135 additions and 505 deletions

View File

@@ -9,20 +9,15 @@
*/
package org.eclipse.hawkbit.dmf.amqp.api;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* Global constants for RabbitMQ settings.
*
*
*
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AmqpSettings {
public static final String DMF_EXCHANGE = "dmf.exchange";
public static final String AUTHENTICATION_EXCHANGE = "authentication.exchange";
private AmqpSettings() {
}
}
}

View File

@@ -18,52 +18,42 @@ public enum EventTopic {
* Topic when sending and receiving a update status.
*/
UPDATE_ACTION_STATUS,
/**
* Topic when sending and receiving a download and install task.
*/
DOWNLOAD_AND_INSTALL,
/**
* Topic when sending and receiving a cancel download task.
*/
CANCEL_DOWNLOAD,
/**
* Topic when updating device attributes.
*/
UPDATE_ATTRIBUTES,
/**
* Topic when updating auto-confirmation state.
*/
UPDATE_AUTO_CONFIRM,
/**
* Topic when sending a download only task, skipping the install.
*/
DOWNLOAD,
/**
* Topic when an update of device attributes is requested.
*/
REQUEST_ATTRIBUTES_UPDATE,
/**
* Topic to send multiple actions to the device.
*/
MULTI_ACTION,
/**
* Topic when sending a download only action to multiple devices.
*/
BATCH_DOWNLOAD,
/**
* Topic when sending a download and install action to multiple devices.
*/
BATCH_DOWNLOAD_AND_INSTALL,
/**
* Topic when confirmation of an action is requested.
*/

View File

@@ -9,46 +9,37 @@
*/
package org.eclipse.hawkbit.dmf.amqp.api;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* The constant of all amqp message header.
*
*
*
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MessageHeaderKey {
/**
* The message type.
*/
public static final String TYPE = "type";
/**
* The used tenant.
*/
public static final String TENANT = "tenant";
/**
* The name of the thing/target.
*/
public static final String THING_ID = "thingId";
/**
* The name of the sender who has send the message.
*/
public static final String SENDER = "sender";
/**
* The topic to handle events different.
*/
public static final String TOPIC = "topic";
/**
* The content type.
*/
public static final String CONTENT_TYPE = "content-type";
private MessageHeaderKey() {
}
}
}

View File

@@ -19,30 +19,24 @@ public enum MessageType {
* The event type related to interaction with a thing.
*/
EVENT,
/**
* The thing created type.
*/
THING_CREATED,
/**
* The thing deleted type.
*/
THING_DELETED,
/**
* The request to delete a target.
*/
THING_REMOVED,
/**
* DMF receiver health check type.
*/
PING,
/**
* DMF receiver health check response type.
*/
PING_RESPONSE
}
}

View File

@@ -13,22 +13,16 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* JSON representation of an action related request.
*
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfActionRequest {
@JsonProperty
private Long actionId;
public Long getActionId() {
return actionId;
}
public void setActionId(final Long correlator) {
this.actionId = correlator;
}
}
}

View File

@@ -15,65 +15,53 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
/**
* The json message action status.
*
*
*
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public enum DmfActionStatus {
/**
* Action requests download by this target which has now started.
*/
DOWNLOAD,
/**
* Action has been send to the target.
*/
RETRIEVED,
/**
* Action is still running for this target.
*/
RUNNING,
/**
* Action is finished successfully for this target.
*/
FINISHED,
/**
* Action has failed for this target.
*/
ERROR,
/**
* Action is still running but with warnings.
*/
WARNING,
/**
* Action has been canceled for this target.
*/
CANCELED,
/**
* Cancellation has been rejected by the target..
*/
CANCEL_REJECTED,
/**
* Action has been downloaded for this target.
*/
DOWNLOADED,
/**
* Action is confirmed by the target.
*/
CONFIRMED,
/**
* Action has been denied by the target.
*/
DENIED
}
}

View File

@@ -20,10 +20,14 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;
/**
* JSON representation of action update status.
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfActionUpdateStatus {
@@ -34,6 +38,7 @@ public class DmfActionUpdateStatus {
@JsonProperty
private Long softwareModuleId;
@Setter(AccessLevel.NONE)
@JsonProperty
private List<String> message;
@@ -46,31 +51,11 @@ public class DmfActionUpdateStatus {
this.actionStatus = actionStatus;
}
public Long getActionId() {
return actionId;
}
public Long getSoftwareModuleId() {
return softwareModuleId;
}
public void setSoftwareModuleId(final Long softwareModuleId) {
this.softwareModuleId = softwareModuleId;
}
public DmfActionStatus getActionStatus() {
return actionStatus;
}
@JsonIgnore
public Optional<Integer> getCode() {
return Optional.ofNullable(code);
}
public void setCode(final Integer code) {
this.code = code;
}
public List<String> getMessage() {
if (message == null) {
return Collections.emptyList();
@@ -99,9 +84,4 @@ public class DmfActionUpdateStatus {
return message.addAll(messages);
}
public void setCode(final int code) {
this.code = code;
}
}
}

View File

@@ -16,25 +16,24 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* JSON representation of artifact.
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfArtifact {
@JsonProperty
private String filename;
@JsonProperty
private DmfArtifactHash hashes;
@JsonProperty
private long size;
@JsonProperty
private long lastModified;
@JsonProperty
private Map<String, String> urls;
@@ -45,41 +44,4 @@ public class DmfArtifact {
return Collections.unmodifiableMap(urls);
}
public long getLastModified() {
return lastModified;
}
public void setLastModified(final long lastModified) {
this.lastModified = lastModified;
}
public void setUrls(final Map<String, String> urls) {
this.urls = urls;
}
public String getFilename() {
return filename;
}
public void setFilename(final String filename) {
this.filename = filename;
}
public DmfArtifactHash getHashes() {
return hashes;
}
public void setHashes(final DmfArtifactHash hashes) {
this.hashes = hashes;
}
public long getSize() {
return size;
}
public void setSize(final long size) {
this.size = size;
}
}
}

View File

@@ -11,46 +11,28 @@ package org.eclipse.hawkbit.dmf.json.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* JSON representation of artifact hash.
*/
@Data
public class DmfArtifactHash {
@JsonProperty
private String sha1;
@JsonProperty
private String md5;
/**
* Constructor.
*
* @param sha1
* the sha1 hash
* @param md5
* the md5 hash
* @param sha1 the sha1 hash
* @param md5 the md5 hash
*/
@JsonCreator
public DmfArtifactHash(@JsonProperty("sha1") final String sha1, @JsonProperty("md5") final String md5) {
this.sha1 = sha1;
this.md5 = md5;
}
public void setSha1(final String sha1) {
this.sha1 = sha1;
}
public void setMd5(final String md5) {
this.md5 = md5;
}
public String getSha1() {
return sha1;
}
public String getMd5() {
return md5;
}
}
}

View File

@@ -16,10 +16,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* JSON representation of the Attribute Update message.
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfAttributeUpdate {
@@ -29,17 +31,4 @@ public class DmfAttributeUpdate {
@JsonProperty
private DmfUpdateMode mode;
public DmfUpdateMode getMode() {
return mode;
}
public void setMode(final DmfUpdateMode mode) {
this.mode = mode;
}
public Map<String, String> getAttributes() {
return attributes;
}
}
}

View File

@@ -13,46 +13,20 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* JSON representation of auto confirmation config.
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfAutoConfirmation {
@JsonProperty
private boolean enabled;
@JsonProperty
private String initiator;
@JsonProperty
private String remark;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
public String getInitiator() {
return initiator;
}
public void setInitiator(final String initiator) {
this.initiator = initiator;
}
public String getRemark() {
return remark;
}
public void setRemark(final String remark) {
this.remark = remark;
}
}
}

View File

@@ -13,6 +13,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.Collections;
@@ -26,6 +28,7 @@ import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfBatchDownloadAndUpdateRequest {
@Getter @Setter
@JsonProperty
private Long timestamp;
@@ -35,14 +38,6 @@ public class DmfBatchDownloadAndUpdateRequest {
@JsonProperty
private List<DmfSoftwareModule> softwareModules;
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(final Long timestamp) {
this.timestamp = timestamp;
}
public List<DmfSoftwareModule> getSoftwareModules() {
if (softwareModules == null) {
return Collections.emptyList();
@@ -54,8 +49,7 @@ public class DmfBatchDownloadAndUpdateRequest {
/**
* Add a Software module.
*
* @param createSoftwareModule
* the module
* @param createSoftwareModule the module
*/
public void addSoftwareModule(final DmfSoftwareModule createSoftwareModule) {
if (softwareModules == null) {
@@ -73,7 +67,6 @@ public class DmfBatchDownloadAndUpdateRequest {
return Collections.unmodifiableList(targets);
}
/**
* Add a Target.
*
@@ -91,8 +84,7 @@ public class DmfBatchDownloadAndUpdateRequest {
/**
* Add multiple Targets.
*
* @param targets
* the target
* @param targets the target
*/
public void addTargets(final List<DmfTarget> targets) {
if (this.targets == null) {
@@ -100,4 +92,4 @@ public class DmfBatchDownloadAndUpdateRequest {
}
this.targets.addAll(targets);
}
}
}

View File

@@ -13,6 +13,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.Collections;
@@ -20,26 +22,18 @@ import java.util.List;
/**
* JSON representation of confirm request.
*
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfConfirmRequest extends DmfActionRequest {
@Getter @Setter
@JsonProperty
private String targetSecurityToken;
@JsonProperty
private List<DmfSoftwareModule> softwareModules;
public String getTargetSecurityToken() {
return targetSecurityToken;
}
public void setTargetSecurityToken(final String targetSecurityToken) {
this.targetSecurityToken = targetSecurityToken;
}
public List<DmfSoftwareModule> getSoftwareModules() {
if (softwareModules == null) {
return Collections.emptyList();

View File

@@ -13,10 +13,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* JSON representation of the Attribute THING_CREATED message.
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfCreateThing {
@@ -29,28 +31,4 @@ public class DmfCreateThing {
@JsonProperty
private DmfAttributeUpdate attributeUpdate;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(final String type) {
this.type = type;
}
public DmfAttributeUpdate getAttributeUpdate() {
return attributeUpdate;
}
public void setAttributeUpdate(final DmfAttributeUpdate attributeUpdate) {
this.attributeUpdate = attributeUpdate;
}
}
}

View File

@@ -17,25 +17,22 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
/**
* JSON representation of download and update request.
*
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfDownloadAndUpdateRequest extends DmfActionRequest {
@Getter
@JsonProperty
private String targetSecurityToken;
@JsonProperty
private List<DmfSoftwareModule> softwareModules;
public String getTargetSecurityToken() {
return targetSecurityToken;
}
public void setTargetSecurityToken(final String targetSecurityToken) {
this.targetSecurityToken = targetSecurityToken;
}
@@ -62,4 +59,4 @@ public class DmfDownloadAndUpdateRequest extends DmfActionRequest {
softwareModules.add(createSoftwareModule);
}
}
}

View File

@@ -13,58 +13,22 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* The authentification response JSON representation.
*
*
*
* The download response JSON representation.
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfDownloadResponse {
@JsonProperty
private String downloadUrl;
@JsonProperty
private DmfArtifact artifact;
@JsonProperty
private int responseCode;
@JsonProperty
private String message;
public String getMessage() {
return message;
}
public void setMessage(final String message) {
this.message = message;
}
public int getResponseCode() {
return responseCode;
}
public void setResponseCode(final int responseCode) {
this.responseCode = responseCode;
}
public String getDownloadUrl() {
return downloadUrl;
}
public void setDownloadUrl(final String downloadUrl) {
this.downloadUrl = downloadUrl;
}
public DmfArtifact getArtifact() {
return artifact;
}
public void setArtifact(final DmfArtifact artifact) {
this.artifact = artifact;
}
}
}

View File

@@ -14,11 +14,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* Additional metadata to be provided for the target/device.
*
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfMetadata {
@@ -33,55 +34,4 @@ public class DmfMetadata {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final DmfMetadata other = (DmfMetadata) obj;
if (key == null) {
if (other.key != null) {
return false;
}
} else if (!key.equals(other.key)) {
return false;
}
if (value == null) {
if (other.value != null) {
return false;
}
} else if (!value.equals(other.value)) {
return false;
}
return true;
}
@Override
public String toString() {
return String.format("DmfMetadata [key='%s', value='%s']", key, value);
}
}
}

View File

@@ -12,6 +12,8 @@ package org.eclipse.hawkbit.dmf.json.model;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.dmf.amqp.api.EventTopic;
import com.fasterxml.jackson.annotation.JsonCreator;
@@ -27,15 +29,13 @@ import com.fasterxml.jackson.annotation.JsonValue;
/**
* JSON representation of a multi-action request.
*/
@NoArgsConstructor
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfMultiActionRequest {
private List<DmfMultiActionElement> elements;
public DmfMultiActionRequest() {
}
@JsonCreator
public DmfMultiActionRequest(final List<DmfMultiActionElement> elements) {
this.elements = elements;
@@ -64,6 +64,7 @@ public class DmfMultiActionRequest {
/**
* Represents an element within a {@link DmfMultiActionRequest}.
*/
@Data
public static class DmfMultiActionElement {
@JsonProperty
@@ -75,32 +76,11 @@ public class DmfMultiActionRequest {
@JsonProperty
private int weight;
public DmfActionRequest getAction() {
return action;
}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "topic", defaultImpl = DmfActionRequest.class)
@JsonSubTypes({ @Type(value = DmfDownloadAndUpdateRequest.class, name = "DOWNLOAD"),
@Type(value = DmfDownloadAndUpdateRequest.class, name = "DOWNLOAD_AND_INSTALL") })
public void setAction(final DmfActionRequest action) {
this.action = action;
}
public EventTopic getTopic() {
return topic;
}
public void setTopic(final EventTopic actionType) {
this.topic = actionType;
}
public void setWeight(final int weight) {
this.weight = weight;
}
public int getWeight() {
return weight;
}
}
}

View File

@@ -17,11 +17,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* JSON representation of a software module.
*
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfSoftwareModule {
@@ -39,22 +40,6 @@ public class DmfSoftwareModule {
@JsonProperty
private List<DmfMetadata> metadata;
public String getModuleType() {
return moduleType;
}
public void setModuleType(final String moduleType) {
this.moduleType = moduleType;
}
public String getModuleVersion() {
return moduleVersion;
}
public void setModuleVersion(final String moduleVersion) {
this.moduleVersion = moduleVersion;
}
public List<DmfArtifact> getArtifacts() {
if (artifacts == null) {
return Collections.emptyList();
@@ -63,41 +48,9 @@ public class DmfSoftwareModule {
return Collections.unmodifiableList(artifacts);
}
public Long getModuleId() {
return moduleId;
}
@JsonIgnore
public void setModuleId(final Long moduleId) {
this.moduleId = moduleId;
}
public void setArtifacts(final List<DmfArtifact> artifacts) {
this.artifacts = artifacts;
}
public List<DmfMetadata> getMetadata() {
return metadata;
}
public void setMetadata(final List<DmfMetadata> metadata) {
if (metadata != null && !metadata.isEmpty()) {
this.metadata = metadata;
}
}
public Boolean getEncrypted() {
return encrypted;
}
public void setEncrypted(final Boolean encrypted) {
this.encrypted = encrypted;
}
@Override
public String toString() {
return String.format(
"DmfSoftwareModule [moduleId=%d, moduleType='%s', moduleVersion='%s', encrypted='%s' artifacts=%s, metadata=%s]",
moduleId, moduleType, moduleVersion, encrypted, artifacts, metadata);
}
}
}

View File

@@ -13,53 +13,22 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.ToString;
/**
* Json representation of Target used in batch download and update request.
*
*/
@Data
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DmfTarget {
@JsonProperty
private Long actionId;
@JsonProperty
private String controllerId;
@ToString.Exclude
@JsonProperty
private String targetSecurityToken;
public Long getActionId() {
return actionId;
}
public void setActionId(final Long actionId) {
this.actionId = actionId;
}
public String getControllerId() {
return controllerId;
}
public void setControllerId(final String controllerId) {
this.controllerId = controllerId;
}
public String getTargetSecurityToken() {
return targetSecurityToken;
}
public void setTargetSecurityToken(final String targetSecurityToken) {
this.targetSecurityToken = targetSecurityToken;
}
@Override
public String toString() {
return String.format(
"DmfTarget [actionId=%d controllerId='%s']",
actionId, controllerId);
}
}
}

View File

@@ -21,15 +21,12 @@ public enum DmfUpdateMode {
* Merge update strategy
*/
MERGE,
/**
* Replacement update strategy
*/
REPLACE,
/**
* Removal update strategy
*/
REMOVE
}
}