Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-6893] Add information to product-info #6070

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -6,6 +6,8 @@
package org.wildfly.core.instmgr;

import java.nio.file.Path;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

Expand All @@ -18,10 +20,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 @@ -51,8 +55,18 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
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());
if (hr.timestamp() != null) {
final java.util.Date timestamp = Date.from(hr.timestamp());
entry.get(InstMgrConstants.HISTORY_RESULT_TIMESTAMP).set(DateFormat.getInstance().format(timestamp));
}
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 +80,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
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,18 @@ public void testHistoryChannels() throws Exception {
Assert.assertTrue(entry.hasDefined(InstMgrConstants.HISTORY_RESULT_TIMESTAMP));
Assert.assertTrue(entry.hasDefined(InstMgrConstants.HISTORY_RESULT_TYPE));
Assert.assertTrue(entry.hasDefined(InstMgrConstants.HISTORY_RESULT_DESCRIPTION));

// verify the channel version information is available (only "update" in test collection contains it)
if (entry.get(InstMgrConstants.HISTORY_RESULT_HASH).asString().equals("update")) {
Assert.assertTrue(entry.hasDefined(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS));
final List<ModelNode> versions = entry.get(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS).asList();
Assert.assertEquals(1, versions.size());
Assert.assertEquals("Update 1", versions.get(0).asString());
} else {
Assert.assertFalse(entry.hasDefined(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS));
}
}

}

@Test
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the format given by the legacy tool:

return DateFormat.getInstance().format(new Date());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that probably should happen in InstMgrHistoryHandler, in the Reporter it's too late - we already have a text value

}
}
}
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
Loading
Loading