Introduce action status scoped custom code (#1277)

* Allow providing a custom code with an action status feedback to give more fine grained device specific details.
* Add ddi rest docs for new optional status code value.
* Provide new code value via mgmt api. Fix review findings.
* Fix failing tests

Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io>
Co-authored-by: Stefan Behl <stefan.behl@bosch.io>
This commit is contained in:
Michael Herdt
2022-09-21 15:20:34 +02:00
committed by GitHub
parent 32718676a4
commit 5e963f8308
28 changed files with 338 additions and 43 deletions

View File

@@ -37,6 +37,8 @@ public interface ActionStatusCreate {
*/
ActionStatusCreate occurredAt(long occurredAt);
ActionStatusCreate code(int code);
/**
* @param messages
* for {@link ActionStatus#getMessages()}

View File

@@ -8,6 +8,7 @@
*/
package org.eclipse.hawkbit.repository.model;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.eclipse.hawkbit.repository.model.Action.Status;
@@ -39,4 +40,6 @@ public interface ActionStatus extends TenantAwareBaseEntity {
*/
Status getStatus();
Optional<Integer> getCode();
}

View File

@@ -25,9 +25,13 @@ import org.springframework.util.StringUtils;
* update or create builder interface
*/
public abstract class AbstractActionStatusCreate<T> {
protected Status status;
protected Long occurredAt;
protected Integer code;
protected List<@ValidString String> messages;
protected Long actionId;
@@ -48,6 +52,12 @@ public abstract class AbstractActionStatusCreate<T> {
return (T) this;
}
public T code(final int code) {
this.code = code;
return (T) this;
}
public T messages(final Collection<String> messages) {
if (this.messages == null) {
this.messages = messages.stream().map(StringUtils::trimWhitespace).collect(Collectors.toList());

View File

@@ -29,6 +29,9 @@ public class JpaActionStatusCreate extends AbstractActionStatusCreate<ActionStat
if (messages != null) {
messages.forEach(result::addMessage);
}
if (code != null) {
result.setCode(code);
}
return result;
}
}

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
@@ -85,6 +86,9 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements
@Column(name = "detail_message", length = MESSAGE_ENTRY_LENGTH, nullable = false, updatable = false)
private List<String> messages;
@Column(name = "code", nullable = true, updatable = false)
private Integer code;
/**
* Creates a new {@link ActionStatus} object.
*
@@ -184,4 +188,11 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements
this.status = status;
}
public Optional<Integer> getCode() {
return Optional.ofNullable(code);
}
public void setCode(final Integer code) {
this.code = code;
}
}

View File

@@ -0,0 +1,2 @@
ALTER TABLE sp_action_status ADD COLUMN code INTEGER;
CREATE INDEX sp_idx_action_status_03 ON sp_action_status (tenant, code);

View File

@@ -0,0 +1,2 @@
ALTER TABLE sp_action_status ADD column code integer;
CREATE INDEX sp_idx_action_status_03 ON sp_action_status (tenant, code);

View File

@@ -0,0 +1,2 @@
ALTER TABLE sp_action_status ADD COLUMN code integer;
CREATE INDEX sp_idx_action_status_03 ON sp_action_status (tenant, code);

View File

@@ -0,0 +1,2 @@
ALTER TABLE sp_action_status ADD code INT;
CREATE INDEX sp_idx_action_status_03 ON sp_action_status (tenant, code);

View File

@@ -47,7 +47,6 @@ import org.eclipse.hawkbit.repository.exception.IncompatibleTargetTypeException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
import org.eclipse.hawkbit.repository.exception.MultiAssignmentIsNotEnabledException;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;