Skip to content

Commit

Permalink
simple-ui: Also show target attributes in Target's view (eclipse-hawk…
Browse files Browse the repository at this point in the history
…bit#2304)

It is useful to see target attributes in the Target's view: for instance
SWUpdate can deliver values from the platform which identify some
features of it. This can include an arbitrary data, e.g. platform HW
revision, component's versions etc.
Thus, add a possibility to see those attributes in the dedicated view.

Signed-off-by: Oleksandr Andrushchenko <[email protected]>
  • Loading branch information
andr2000 authored Feb 28, 2025
1 parent 6bf85a2 commit 970a434
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public interface Constants {
String LAST_MODIFIED_BY = "Last modified by";
String LAST_MODIFIED_AT = "Last modified at";
String SECURITY_TOKEN = "Security Token";
String ATTRIBUTES = "Attributes";

// rollout
String GROUP_COUNT = "Group Count";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;
Expand Down Expand Up @@ -51,6 +52,7 @@
import org.eclipse.hawkbit.ui.simple.view.util.TableView;
import org.eclipse.hawkbit.ui.simple.view.util.Utils;
import org.springframework.util.ObjectUtils;
import java.util.stream.Collectors;

@PageTitle("Targets")
@Route(value = "targets", layout = MainLayout.class)
Expand All @@ -73,7 +75,7 @@ protected void addColumns(final Grid<MgmtTarget> grid) {
grid.addColumn(MgmtTarget::getTargetTypeName).setHeader(Constants.TYPE).setAutoWidth(true);

grid.setItemDetailsRenderer(new ComponentRenderer<>(
TargetDetails::new, TargetDetails::setItem));
() -> new TargetDetails(hawkbitClient), TargetDetails::setItem));
}
},
(query, filter) -> hawkbitClient.getTargetRestApi()
Expand Down Expand Up @@ -209,20 +211,23 @@ public String filter() {

private static class TargetDetails extends FormLayout {

private final transient HawkbitMgmtClient hawkbitClient;
private final TextArea description = new TextArea(Constants.DESCRIPTION);
private final TextField createdBy = Utils.textField(Constants.CREATED_BY);
private final TextField createdAt = Utils.textField(Constants.CREATED_AT);
private final TextField lastModifiedBy = Utils.textField(Constants.LAST_MODIFIED_BY);
private final TextField lastModifiedAt = Utils.textField(Constants.LAST_MODIFIED_AT);
private final TextField securityToken = Utils.textField(Constants.SECURITY_TOKEN);
private final TextArea targetAttributes = new TextArea(Constants.ATTRIBUTES);

private TargetDetails() {
private TargetDetails(HawkbitMgmtClient hawkbitClient) {
this.hawkbitClient = hawkbitClient;
description.setMinLength(2);
Stream.of(
description,
createdBy, createdAt,
lastModifiedBy, lastModifiedAt,
securityToken)
securityToken, targetAttributes)
.forEach(field -> {
field.setReadOnly(true);
add(field);
Expand All @@ -239,6 +244,13 @@ private void setItem(final MgmtTarget target) {
lastModifiedBy.setValue(target.getLastModifiedBy());
lastModifiedAt.setValue(new Date(target.getLastModifiedAt()).toString());
securityToken.setValue(target.getSecurityToken());
var response = hawkbitClient.getTargetRestApi().getAttributes(target.getControllerId());
if (response.getStatusCode().is2xxSuccessful()) {
targetAttributes.setValue(Objects.requireNonNullElse(response.getBody(), Collections.emptyMap()).entrySet().stream().map(entry -> entry.getKey() + ": " +
entry.getValue()).collect(Collectors.joining("\n")));
} else {
targetAttributes.setValue("Error occurred fetching attributes from server: " + response.getStatusCode());
}
}
}

Expand Down

0 comments on commit 970a434

Please sign in to comment.