Skip to content

Commit

Permalink
[WFCORE-6893] Add information to product-info
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob committed Jul 16, 2024
1 parent 23f9000 commit bd81049
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class GlobalInstallationReportHandler extends GlobalOperationHandlers.Abs
public static final String PRODUCT_HOME = "product-home";
public static final String PRODUCT_INSTALLATION_DATE = "installation-date";
public static final String PRODUCT_LAST_UPDATE = "last-update-date";
public static final String PRODUCT_CHANNEL_VERSIONS = "channel-versions";
public static final String STANDALONE_DOMAIN_IDENTIFIER = "standalone-or-domain-identifier";
public static final String SUMMARY = "summary";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ private InstallationReportHandler(HostControllerEnvironment environment) {

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ModelNode patchingInfo = new ModelNode();
PathAddress patchingAddress = PathAddress.pathAddress(
final ModelNode installerInfo = new ModelNode();
PathAddress installerAddress = PathAddress.pathAddress(
PathElement.pathElement(HOST, environment.getHostControllerName()),
PathElement.pathElement(CORE_SERVICE, "patching"));
OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(patchingAddress, "show-history");
if(opEntry != null) {
context.addStep(patchingInfo, Util.createOperation("show-history", patchingAddress),
PathElement.pathElement(CORE_SERVICE, "installer"));
OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(installerAddress, "history");
if (opEntry != null) {
context.addStep(installerInfo, Util.createOperation("history", installerAddress),
opEntry.getOperationHandler(), OperationContext.Stage.RUNTIME);
}
final Path installationDir = environment.getHomeDir().toPath();
Expand All @@ -68,7 +68,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
ModelNode result = context.getResult();
result.get(SUMMARY_DEFINITION.getName()).set(createProductNode(context, new InstallationConfiguration(
environment, environment.getProductConfig(), patchingInfo, installationDir)));
environment, environment.getProductConfig(), installerInfo, installationDir)));
}
}, OperationContext.Stage.RUNTIME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public interface InstMgrConstants {
String HISTORY_DETAILED_CHANNEL_REPOSITORIES = "repositories";
String HISTORY_DETAILED_CHANNEL_STATUS = "status";
String HISTORY_RESULT_DESCRIPTION = "description";
String HISTORY_RESULT_CHANNEL_VERSIONS = "channel-versions";
String HISTORY_RESULT_DETAILED_ARTIFACT_CHANGES = "artifact-changes";
String HISTORY_RESULT_DETAILED_CHANNEL_CHANGES = "channel-changes";
String HISTORY_RESULT_HASH = "hash";
Expand Down Expand Up @@ -62,4 +63,6 @@ public interface InstMgrConstants {
String REVISION = "revision";
String TOOL_NAME = "installer";
String INTERNAL_REPO_PREFIX = "repo-";
String INSTALLED_VERSIONS = "installed-versions";
String VERSION = "version";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.wildfly.installationmanager.HistoryResult;
import org.wildfly.installationmanager.ManifestVersion;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.spi.InstallationManager;
import org.wildfly.installationmanager.spi.InstallationManagerFactory;


/**
* Operation handler to get the history of the installation manager changes, either artifacts or configuration metadata as
* channel changes.
Expand Down Expand Up @@ -53,6 +55,13 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
entry.get(InstMgrConstants.HISTORY_RESULT_HASH).set(hr.getName());
entry.get(InstMgrConstants.HISTORY_RESULT_TIMESTAMP).set(hr.timestamp().toString());
entry.get(InstMgrConstants.HISTORY_RESULT_TYPE).set(hr.getType().toLowerCase(Locale.ENGLISH));
if (hr.getVersions() != null && !hr.getVersions().isEmpty()) {
final ModelNode versions = entry.get(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS);
hr.getVersions().stream()
.map(ManifestVersion::getDescription)
.map(ModelNode::new)
.forEach(versions::add);
}
if (hr.getDescription() != null) {
entry.get(InstMgrConstants.HISTORY_RESULT_DESCRIPTION).set(hr.getDescription());
}
Expand All @@ -66,6 +75,6 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
throw new RuntimeException(e);
}
}
}, OperationContext.Stage.RUNTIME);
}, OperationContext.Stage.RUNTIME, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;

import java.util.List;
import java.util.stream.Collectors;

import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandException;
Expand Down Expand Up @@ -109,8 +110,14 @@ public CommandResult execute(CLICommandInvocation commandInvocation) throws Comm
String hash = resultMn.get(InstMgrConstants.HISTORY_RESULT_HASH).asString();
String timeStamp = resultMn.get(InstMgrConstants.HISTORY_RESULT_TIMESTAMP).asString();
String type = resultMn.get(InstMgrConstants.HISTORY_RESULT_TYPE).asString();
String description = resultMn.get(InstMgrConstants.HISTORY_RESULT_DESCRIPTION).asStringOrNull();
description = description == null ? "[]" : description;
final List<String> versions = resultMn.get(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS).asListOrEmpty().stream().map(ModelNode::asString).collect(Collectors.toList());
String description;
if (versions.isEmpty()) {
description = resultMn.get(InstMgrConstants.HISTORY_RESULT_DESCRIPTION).asStringOrNull();
description = description == null ? "[]" : description;
} else {
description = "[" + String.join(" + ", versions) + "]";
}
ctx.printLine(String.format("[%s] %s - %s %s", hash, timeStamp, type, description));
}
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
<version.org.wildfly.client.config>1.0.1.Final</version.org.wildfly.client.config>
<version.org.wildfly.common>1.7.0.Final</version.org.wildfly.common>
<version.org.wildfly.discovery>1.3.0.Final</version.org.wildfly.discovery>
<version.org.wildfly.installation-manager.installation-manager-api>1.0.2.Final</version.org.wildfly.installation-manager.installation-manager-api>
<version.org.wildfly.installation-manager.installation-manager-api>1.0.3.Final-SNAPSHOT</version.org.wildfly.installation-manager.installation-manager-api>
<version.org.wildfly.legacy.test>8.0.2.Final</version.org.wildfly.legacy.test>
<version.org.wildfly.openssl>2.2.5.Final</version.org.wildfly.openssl>
<version.org.wildfly.openssl.natives>2.2.2.Final</version.org.wildfly.openssl.natives>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.JVM_VENDOR;
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.JVM_VERSION;
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.OS;
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.PRODUCT_CHANNEL_VERSIONS;
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.PRODUCT_TYPE;
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.PRODUCT_COMMUNITY_IDENTIFIER;
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.PRODUCT_HOME;
Expand All @@ -39,6 +40,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Properties;

import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
Expand Down Expand Up @@ -174,6 +176,10 @@ protected ModelNode createProductNode(OperationContext context, InstallationConf
product.get(OS).set(createOSNode());
product.get(CPU).set(createCPUNode());
product.get(JVM).set(createJVMNode());
List<ModelNode> channelVersions = installation.getChannelVersions();
if (channelVersions != null && !channelVersions.isEmpty()) {
product.get(PRODUCT_CHANNEL_VERSIONS).set(channelVersions);
}
return product;
}

Expand Down Expand Up @@ -275,18 +281,18 @@ protected static final class InstallationConfiguration {

private final ProcessEnvironment environment;
private final ProductConfig config;
private final ModelNode patchingInfo;
private final ModelNode installerInfo;
private final Path installationDir;

public InstallationConfiguration(ProcessEnvironment environment, ProductConfig config, ModelNode patchingInfo, Path installationDir) {
public InstallationConfiguration(ProcessEnvironment environment, ProductConfig config, ModelNode installerInfo, Path installationDir) {
assert environment != null;
assert config != null;
assert patchingInfo != null;
assert installerInfo != null;
assert installationDir != null;

this.environment = environment;
this.config = config;
this.patchingInfo = patchingInfo;
this.installerInfo = installerInfo;
this.installationDir = installationDir;
}

Expand All @@ -310,11 +316,23 @@ String getInstallationDir() {
}

String getLastUpdateDate() {
if (patchingInfo.isDefined()) {
List<ModelNode> result = Operations.readResult(patchingInfo).asList();
for (ModelNode patchAtt : result) {
if (patchAtt.has("applied-at")) {
return patchAtt.get("applied-at").asString();
if (installerInfo.get("result").isDefined()) {
List<ModelNode> result = Operations.readResult(installerInfo).asList();
for (ModelNode installerAtt : result) {
if (installerAtt.has("timestamp")) {
return installerAtt.get("timestamp").asString();
}
}
}
return null;
}

List<ModelNode> getChannelVersions() {
if (installerInfo.get("result").isDefined()) {
List<ModelNode> result = Operations.readResult(installerInfo).asList();
for (ModelNode installerAtt : result) {
if (installerAtt.has("channel-versions")) {
return installerAtt.get("channel-versions").asList();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ private InstallationReportHandler(ServerEnvironment environment) {

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ModelNode patchingInfo = new ModelNode();
PathAddress patchingAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "patching"));
OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(patchingAddress, "show-history");
if(opEntry != null) {
context.addStep(patchingInfo, Util.createOperation("show-history", patchingAddress),
opEntry.getOperationHandler(), OperationContext.Stage.RUNTIME);
final ModelNode installerInfo = new ModelNode();
final PathAddress installerAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "installer"));
final OperationEntry installerOpEntry = context.getRootResourceRegistration().getOperationEntry(installerAddress, "history");
if (installerOpEntry != null) {
context.addStep(installerInfo, Util.createOperation("history", installerAddress),
installerOpEntry.getOperationHandler(), OperationContext.Stage.RUNTIME);
}

final Path installationDir = environment.getHomeDir().toPath();
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
ModelNode result = context.getResult();
result.get(SUMMARY_DEFINITION.getName()).set(createProductNode(context, new InstallationConfiguration(
environment, environment.getProductConfig(), patchingInfo, installationDir)));
environment, environment.getProductConfig(), installerInfo, installationDir)));
}
}, OperationContext.Stage.RUNTIME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -119,10 +120,10 @@ public static void initialize() throws IOException {

// History sample data
history = new HashMap<>();
history.put("update", new HistoryResult("update", Instant.now(), "update", "update description"));
history.put("install", new HistoryResult("install", Instant.now(), "install", "install description"));
history.put("rollback", new HistoryResult("rollback", Instant.now(), "rollback", "rollback description"));
history.put("config_change", new HistoryResult("config_change", Instant.now(), "config_change", "config_change description"));
history.put("update", new HistoryResult("update", Instant.now(), "update", "update description", Collections.emptyList()));
history.put("install", new HistoryResult("install", Instant.now(), "install", "install description", Collections.emptyList()));
history.put("rollback", new HistoryResult("rollback", Instant.now(), "rollback", "rollback description", Collections.emptyList()));
history.put("config_change", new HistoryResult("config_change", Instant.now(), "config_change", "config_change description", Collections.emptyList()));

// List Updates sample Data

Expand Down

0 comments on commit bd81049

Please sign in to comment.