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..2216d24309e 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"); + PathElement.pathElement(CORE_SERVICE, "installer")); + OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(installerAddress, "history"); if(opEntry != null) { - context.addStep(patchingInfo, Util.createOperation("show-history", patchingAddress), + 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..dd4abf53f9f 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 @@ -13,15 +13,20 @@ import org.jboss.as.controller.OperationDefinition; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; +import org.jboss.as.controller.PathAddress; +import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.registry.OperationEntry; 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; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CORE_SERVICE; + /** * Operation handler to get the history of the installation manager changes, either artifacts or configuration metadata as * channel changes. @@ -38,6 +43,12 @@ public class InstMgrHistoryHandler extends InstMgrOperationStepHandler { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { + System.out.println("!! InstMgrHistoryRuntimeHandler"); + System.out.println(context.getCurrentStage()); + PathAddress installerAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "installer")); + OperationEntry installerOpEntry = context.getRootResourceRegistration().getOperationEntry(installerAddress, "history-runtime"); + context.addStep(installerOpEntry.getOperationHandler(), OperationContext.Stage.RUNTIME); + context.addStep(new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { @@ -53,6 +64,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()); } diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrHistoryRuntimeHandler.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrHistoryRuntimeHandler.java new file mode 100644 index 00000000000..3d7387d5650 --- /dev/null +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrHistoryRuntimeHandler.java @@ -0,0 +1,67 @@ +package org.wildfly.core.instmgr; + +import org.jboss.as.controller.OperationContext; +import org.jboss.as.controller.OperationDefinition; +import org.jboss.as.controller.OperationFailedException; +import org.jboss.as.controller.SimpleOperationDefinitionBuilder; +import org.jboss.as.controller.registry.OperationEntry; +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; + +import java.nio.file.Path; +import java.util.List; + +public class InstMgrHistoryRuntimeHandler extends InstMgrOperationStepHandler { + public static final String OPERATION_NAME = "history-runtime"; + + public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, InstMgrResolver.RESOLVER) + .withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY).setReplyType(ModelType.LIST) + .setPrivateEntry() + .setRuntimeOnly() + .withFlag(OperationEntry.Flag.HIDDEN) + .setReplyValueType(ModelType.OBJECT).build(); + + InstMgrHistoryRuntimeHandler(InstMgrService imService, InstallationManagerFactory imf) { + super(imService, imf); + } + + @Override + public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { + try { + Path serverHome = imService.getHomeDir(); + MavenOptions mavenOptions = new MavenOptions(null, false); + InstallationManager installationManager = imf.create(serverHome, mavenOptions); + ModelNode resulList = new ModelNode(); + + List history = installationManager.history(); + for (HistoryResult hr : history) { + ModelNode entry = new ModelNode(); + 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()); + 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()); + } + resulList.add(entry); + } + + context.getResult().set(resulList); + } catch (OperationFailedException | RuntimeException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrResourceDefinition.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrResourceDefinition.java index 890cb8c088a..32afd6c5e1a 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrResourceDefinition.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrResourceDefinition.java @@ -144,6 +144,9 @@ public void registerOperations(ManagementResourceRegistration resourceRegistrati InstMgrHistoryHandler historyHandler = new InstMgrHistoryHandler(imService, imf); resourceRegistration.registerOperationHandler(InstMgrHistoryHandler.DEFINITION, historyHandler); + InstMgrHistoryRuntimeHandler historyRuntimeHandler = new InstMgrHistoryRuntimeHandler(imService, imf); + resourceRegistration.registerOperationHandler(InstMgrHistoryRuntimeHandler.DEFINITION, historyRuntimeHandler); + InstMgrCreateSnapshotHandler createSnapshotHandler = new InstMgrCreateSnapshotHandler(imService, imf); resourceRegistration.registerOperationHandler(InstMgrCreateSnapshotHandler.DEFINITION, createSnapshotHandler); 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..609c05a0f2c 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 + 2.0.0.Beta1-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..b53f3a71851 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(); + PathAddress installerAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "installer")); + OperationEntry installerOpEntry = context.getRootResourceRegistration().getOperationEntry(installerAddress, "history-runtime"); + if(installerOpEntry != null) { + context.addStep(installerInfo, Util.createOperation("history-runtime", 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