From bd810490e17bcab8536bb76d3cf723ea9927eabd Mon Sep 17 00:00:00 2001 From: Bartosz Spyrko-Smietanko Date: Mon, 8 Jul 2024 15:48:42 +0100 Subject: [PATCH] [WFCORE-6893] Add information to product-info --- .../GlobalInstallationReportHandler.java | 1 + .../operations/InstallationReportHandler.java | 14 ++++---- .../core/instmgr/InstMgrConstants.java | 3 ++ .../core/instmgr/InstMgrHistoryHandler.java | 11 +++++- .../core/instmgr/cli/HistoryCommand.java | 11 ++++-- pom.xml | 2 +- .../AbstractInstallationReporter.java | 36 ++++++++++++++----- .../operations/InstallationReportHandler.java | 15 ++++---- .../TestInstallationManager.java | 9 ++--- 9 files changed, 71 insertions(+), 31 deletions(-) diff --git a/controller/src/main/java/org/jboss/as/controller/operations/global/GlobalInstallationReportHandler.java b/controller/src/main/java/org/jboss/as/controller/operations/global/GlobalInstallationReportHandler.java index bad7b77bb9d..94a86a86070 100644 --- a/controller/src/main/java/org/jboss/as/controller/operations/global/GlobalInstallationReportHandler.java +++ b/controller/src/main/java/org/jboss/as/controller/operations/global/GlobalInstallationReportHandler.java @@ -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"; diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/operations/InstallationReportHandler.java b/host-controller/src/main/java/org/jboss/as/host/controller/operations/InstallationReportHandler.java index d499fc69d3d..7357cff1475 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/operations/InstallationReportHandler.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/operations/InstallationReportHandler.java @@ -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(); @@ -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); } diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java index 2abebd93f1f..bd03ace3e88 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java @@ -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"; @@ -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"; } diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrHistoryHandler.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrHistoryHandler.java index 728da3826ec..ac3f8788f9f 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrHistoryHandler.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrHistoryHandler.java @@ -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. @@ -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()); } @@ -66,6 +75,6 @@ public void execute(OperationContext context, ModelNode operation) throws Operat throw new RuntimeException(e); } } - }, OperationContext.Stage.RUNTIME); + }, OperationContext.Stage.RUNTIME, true); } } diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/HistoryCommand.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/HistoryCommand.java index 83500dd8752..6f6b29b7bb6 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/HistoryCommand.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/cli/HistoryCommand.java @@ -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; @@ -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 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)); } } diff --git a/pom.xml b/pom.xml index f917a132ee3..e4605386482 100644 --- a/pom.xml +++ b/pom.xml @@ -234,7 +234,7 @@ 1.0.1.Final 1.7.0.Final 1.3.0.Final - 1.0.2.Final + 1.0.3.Final-SNAPSHOT 8.0.2.Final 2.2.5.Final 2.2.2.Final diff --git a/server/src/main/java/org/jboss/as/server/operations/AbstractInstallationReporter.java b/server/src/main/java/org/jboss/as/server/operations/AbstractInstallationReporter.java index afa6a3331ed..ac99cbdf7ee 100644 --- a/server/src/main/java/org/jboss/as/server/operations/AbstractInstallationReporter.java +++ b/server/src/main/java/org/jboss/as/server/operations/AbstractInstallationReporter.java @@ -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; @@ -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; @@ -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 channelVersions = installation.getChannelVersions(); + if (channelVersions != null && !channelVersions.isEmpty()) { + product.get(PRODUCT_CHANNEL_VERSIONS).set(channelVersions); + } return product; } @@ -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; } @@ -310,11 +316,23 @@ String getInstallationDir() { } String getLastUpdateDate() { - if (patchingInfo.isDefined()) { - List 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 result = Operations.readResult(installerInfo).asList(); + for (ModelNode installerAtt : result) { + if (installerAtt.has("timestamp")) { + return installerAtt.get("timestamp").asString(); + } + } + } + return null; + } + + List getChannelVersions() { + if (installerInfo.get("result").isDefined()) { + List result = Operations.readResult(installerInfo).asList(); + for (ModelNode installerAtt : result) { + if (installerAtt.has("channel-versions")) { + return installerAtt.get("channel-versions").asList(); } } } diff --git a/server/src/main/java/org/jboss/as/server/operations/InstallationReportHandler.java b/server/src/main/java/org/jboss/as/server/operations/InstallationReportHandler.java index 91ad55426fd..262d2fffb55 100644 --- a/server/src/main/java/org/jboss/as/server/operations/InstallationReportHandler.java +++ b/server/src/main/java/org/jboss/as/server/operations/InstallationReportHandler.java @@ -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); } diff --git a/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java b/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java index 91b5a3928e4..e1363029cfe 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java @@ -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; @@ -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