Skip to content

Commit dacd47c

Browse files
committed
[WFCORE-6893] Add information to product-info
1 parent 23f9000 commit dacd47c

File tree

11 files changed

+148
-29
lines changed

11 files changed

+148
-29
lines changed

controller/src/main/java/org/jboss/as/controller/operations/global/GlobalInstallationReportHandler.java

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class GlobalInstallationReportHandler extends GlobalOperationHandlers.Abs
6666
public static final String PRODUCT_HOME = "product-home";
6767
public static final String PRODUCT_INSTALLATION_DATE = "installation-date";
6868
public static final String PRODUCT_LAST_UPDATE = "last-update-date";
69+
public static final String PRODUCT_CHANNEL_VERSIONS = "channel-versions";
6970
public static final String STANDALONE_DOMAIN_IDENTIFIER = "standalone-or-domain-identifier";
7071
public static final String SUMMARY = "summary";
7172

host-controller/src/main/java/org/jboss/as/host/controller/operations/InstallationReportHandler.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ private InstallationReportHandler(HostControllerEnvironment environment) {
5353

5454
@Override
5555
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
56-
final ModelNode patchingInfo = new ModelNode();
57-
PathAddress patchingAddress = PathAddress.pathAddress(
56+
final ModelNode installerInfo = new ModelNode();
57+
PathAddress installerAddress = PathAddress.pathAddress(
5858
PathElement.pathElement(HOST, environment.getHostControllerName()),
59-
PathElement.pathElement(CORE_SERVICE, "patching"));
60-
OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(patchingAddress, "show-history");
59+
PathElement.pathElement(CORE_SERVICE, "installer"));
60+
OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(installerAddress, "history");
6161
if(opEntry != null) {
62-
context.addStep(patchingInfo, Util.createOperation("show-history", patchingAddress),
62+
context.addStep(installerInfo, Util.createOperation("history", installerAddress),
6363
opEntry.getOperationHandler(), OperationContext.Stage.RUNTIME);
6464
}
6565
final Path installationDir = environment.getHomeDir().toPath();
@@ -68,7 +68,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
6868
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
6969
ModelNode result = context.getResult();
7070
result.get(SUMMARY_DEFINITION.getName()).set(createProductNode(context, new InstallationConfiguration(
71-
environment, environment.getProductConfig(), patchingInfo, installationDir)));
71+
environment, environment.getProductConfig(), installerInfo, installationDir)));
7272
}
7373
}, OperationContext.Stage.RUNTIME);
7474
}

installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public interface InstMgrConstants {
3333
String HISTORY_DETAILED_CHANNEL_REPOSITORIES = "repositories";
3434
String HISTORY_DETAILED_CHANNEL_STATUS = "status";
3535
String HISTORY_RESULT_DESCRIPTION = "description";
36+
String HISTORY_RESULT_CHANNEL_VERSIONS = "channel-versions";
3637
String HISTORY_RESULT_DETAILED_ARTIFACT_CHANGES = "artifact-changes";
3738
String HISTORY_RESULT_DETAILED_CHANNEL_CHANGES = "channel-changes";
3839
String HISTORY_RESULT_HASH = "hash";
@@ -62,4 +63,6 @@ public interface InstMgrConstants {
6263
String REVISION = "revision";
6364
String TOOL_NAME = "installer";
6465
String INTERNAL_REPO_PREFIX = "repo-";
66+
String INSTALLED_VERSIONS = "installed-versions";
67+
String VERSION = "version";
6568
}

installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrHistoryHandler.java

+18
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
import org.jboss.as.controller.OperationDefinition;
1414
import org.jboss.as.controller.OperationFailedException;
1515
import org.jboss.as.controller.OperationStepHandler;
16+
import org.jboss.as.controller.PathAddress;
17+
import org.jboss.as.controller.PathElement;
1618
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
1719
import org.jboss.as.controller.registry.OperationEntry;
1820
import org.jboss.dmr.ModelNode;
1921
import org.jboss.dmr.ModelType;
2022
import org.wildfly.installationmanager.HistoryResult;
23+
import org.wildfly.installationmanager.ManifestVersion;
2124
import org.wildfly.installationmanager.MavenOptions;
2225
import org.wildfly.installationmanager.spi.InstallationManager;
2326
import org.wildfly.installationmanager.spi.InstallationManagerFactory;
2427

28+
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CORE_SERVICE;
29+
2530
/**
2631
* Operation handler to get the history of the installation manager changes, either artifacts or configuration metadata as
2732
* channel changes.
@@ -38,6 +43,12 @@ public class InstMgrHistoryHandler extends InstMgrOperationStepHandler {
3843

3944
@Override
4045
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
46+
System.out.println("!! InstMgrHistoryRuntimeHandler");
47+
System.out.println(context.getCurrentStage());
48+
PathAddress installerAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "installer"));
49+
OperationEntry installerOpEntry = context.getRootResourceRegistration().getOperationEntry(installerAddress, "history-runtime");
50+
context.addStep(installerOpEntry.getOperationHandler(), OperationContext.Stage.RUNTIME);
51+
4152
context.addStep(new OperationStepHandler() {
4253
@Override
4354
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
@@ -53,6 +64,13 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
5364
entry.get(InstMgrConstants.HISTORY_RESULT_HASH).set(hr.getName());
5465
entry.get(InstMgrConstants.HISTORY_RESULT_TIMESTAMP).set(hr.timestamp().toString());
5566
entry.get(InstMgrConstants.HISTORY_RESULT_TYPE).set(hr.getType().toLowerCase(Locale.ENGLISH));
67+
if (hr.getVersions() != null && !hr.getVersions().isEmpty()) {
68+
final ModelNode versions = entry.get(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS);
69+
hr.getVersions().stream()
70+
.map(ManifestVersion::getDescription)
71+
.map(ModelNode::new)
72+
.forEach(versions::add);
73+
}
5674
if (hr.getDescription() != null) {
5775
entry.get(InstMgrConstants.HISTORY_RESULT_DESCRIPTION).set(hr.getDescription());
5876
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.wildfly.core.instmgr;
2+
3+
import org.jboss.as.controller.OperationContext;
4+
import org.jboss.as.controller.OperationDefinition;
5+
import org.jboss.as.controller.OperationFailedException;
6+
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
7+
import org.jboss.as.controller.registry.OperationEntry;
8+
import org.jboss.dmr.ModelNode;
9+
import org.jboss.dmr.ModelType;
10+
import org.wildfly.installationmanager.HistoryResult;
11+
import org.wildfly.installationmanager.ManifestVersion;
12+
import org.wildfly.installationmanager.MavenOptions;
13+
import org.wildfly.installationmanager.spi.InstallationManager;
14+
import org.wildfly.installationmanager.spi.InstallationManagerFactory;
15+
16+
import java.nio.file.Path;
17+
import java.util.List;
18+
19+
public class InstMgrHistoryRuntimeHandler extends InstMgrOperationStepHandler {
20+
public static final String OPERATION_NAME = "history-runtime";
21+
22+
public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, InstMgrResolver.RESOLVER)
23+
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY).setReplyType(ModelType.LIST)
24+
.setPrivateEntry()
25+
.setRuntimeOnly()
26+
.withFlag(OperationEntry.Flag.HIDDEN)
27+
.setReplyValueType(ModelType.OBJECT).build();
28+
29+
InstMgrHistoryRuntimeHandler(InstMgrService imService, InstallationManagerFactory imf) {
30+
super(imService, imf);
31+
}
32+
33+
@Override
34+
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
35+
try {
36+
Path serverHome = imService.getHomeDir();
37+
MavenOptions mavenOptions = new MavenOptions(null, false);
38+
InstallationManager installationManager = imf.create(serverHome, mavenOptions);
39+
ModelNode resulList = new ModelNode();
40+
41+
List<HistoryResult> history = installationManager.history();
42+
for (HistoryResult hr : history) {
43+
ModelNode entry = new ModelNode();
44+
entry.get(InstMgrConstants.HISTORY_RESULT_HASH).set(hr.getName());
45+
entry.get(InstMgrConstants.HISTORY_RESULT_TIMESTAMP).set(hr.timestamp().toString());
46+
entry.get(InstMgrConstants.HISTORY_RESULT_TYPE).set(hr.getType().toLowerCase());
47+
if (hr.getVersions() != null && !hr.getVersions().isEmpty()) {
48+
final ModelNode versions = entry.get(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS);
49+
hr.getVersions().stream()
50+
.map(ManifestVersion::getDescription)
51+
.map(ModelNode::new)
52+
.forEach(versions::add);
53+
}
54+
if (hr.getDescription() != null) {
55+
entry.get(InstMgrConstants.HISTORY_RESULT_DESCRIPTION).set(hr.getDescription());
56+
}
57+
resulList.add(entry);
58+
}
59+
60+
context.getResult().set(resulList);
61+
} catch (OperationFailedException | RuntimeException e) {
62+
throw e;
63+
} catch (Exception e) {
64+
throw new RuntimeException(e);
65+
}
66+
}
67+
}

installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrResourceDefinition.java

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ public void registerOperations(ManagementResourceRegistration resourceRegistrati
144144
InstMgrHistoryHandler historyHandler = new InstMgrHistoryHandler(imService, imf);
145145
resourceRegistration.registerOperationHandler(InstMgrHistoryHandler.DEFINITION, historyHandler);
146146

147+
InstMgrHistoryRuntimeHandler historyRuntimeHandler = new InstMgrHistoryRuntimeHandler(imService, imf);
148+
resourceRegistration.registerOperationHandler(InstMgrHistoryRuntimeHandler.DEFINITION, historyRuntimeHandler);
149+
147150
InstMgrCreateSnapshotHandler createSnapshotHandler = new InstMgrCreateSnapshotHandler(imService, imf);
148151
resourceRegistration.registerOperationHandler(InstMgrCreateSnapshotHandler.DEFINITION, createSnapshotHandler);
149152

installation-manager/src/main/java/org/wildfly/core/instmgr/cli/HistoryCommand.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
1010

1111
import java.util.List;
12+
import java.util.stream.Collectors;
1213

1314
import org.aesh.command.CommandDefinition;
1415
import org.aesh.command.CommandException;
@@ -109,8 +110,14 @@ public CommandResult execute(CLICommandInvocation commandInvocation) throws Comm
109110
String hash = resultMn.get(InstMgrConstants.HISTORY_RESULT_HASH).asString();
110111
String timeStamp = resultMn.get(InstMgrConstants.HISTORY_RESULT_TIMESTAMP).asString();
111112
String type = resultMn.get(InstMgrConstants.HISTORY_RESULT_TYPE).asString();
112-
String description = resultMn.get(InstMgrConstants.HISTORY_RESULT_DESCRIPTION).asStringOrNull();
113-
description = description == null ? "[]" : description;
113+
final List<String> versions = resultMn.get(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS).asListOrEmpty().stream().map(ModelNode::asString).collect(Collectors.toList());
114+
String description;
115+
if (versions.isEmpty()) {
116+
description = resultMn.get(InstMgrConstants.HISTORY_RESULT_DESCRIPTION).asStringOrNull();
117+
description = description == null ? "[]" : description;
118+
} else {
119+
description = "[" + String.join(" + ", versions) + "]";
120+
}
114121
ctx.printLine(String.format("[%s] %s - %s %s", hash, timeStamp, type, description));
115122
}
116123
}

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
<version.org.wildfly.client.config>1.0.1.Final</version.org.wildfly.client.config>
235235
<version.org.wildfly.common>1.7.0.Final</version.org.wildfly.common>
236236
<version.org.wildfly.discovery>1.3.0.Final</version.org.wildfly.discovery>
237-
<version.org.wildfly.installation-manager.installation-manager-api>1.0.2.Final</version.org.wildfly.installation-manager.installation-manager-api>
237+
<version.org.wildfly.installation-manager.installation-manager-api>2.0.0.Beta1-SNAPSHOT</version.org.wildfly.installation-manager.installation-manager-api>
238238
<version.org.wildfly.legacy.test>8.0.2.Final</version.org.wildfly.legacy.test>
239239
<version.org.wildfly.openssl>2.2.5.Final</version.org.wildfly.openssl>
240240
<version.org.wildfly.openssl.natives>2.2.2.Final</version.org.wildfly.openssl.natives>

server/src/main/java/org/jboss/as/server/operations/AbstractInstallationReporter.java

+27-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.JVM_VENDOR;
2323
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.JVM_VERSION;
2424
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.OS;
25+
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.PRODUCT_CHANNEL_VERSIONS;
2526
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.PRODUCT_TYPE;
2627
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.PRODUCT_COMMUNITY_IDENTIFIER;
2728
import static org.jboss.as.controller.operations.global.GlobalInstallationReportHandler.PRODUCT_HOME;
@@ -39,6 +40,7 @@
3940
import java.util.List;
4041
import java.util.Locale;
4142
import java.util.Properties;
43+
4244
import org.jboss.as.controller.OperationContext;
4345
import org.jboss.as.controller.OperationFailedException;
4446
import org.jboss.as.controller.OperationStepHandler;
@@ -174,6 +176,10 @@ protected ModelNode createProductNode(OperationContext context, InstallationConf
174176
product.get(OS).set(createOSNode());
175177
product.get(CPU).set(createCPUNode());
176178
product.get(JVM).set(createJVMNode());
179+
List<ModelNode> channelVersions = installation.getChannelVersions();
180+
if (channelVersions != null && !channelVersions.isEmpty()) {
181+
product.get(PRODUCT_CHANNEL_VERSIONS).set(channelVersions);
182+
}
177183
return product;
178184
}
179185

@@ -275,18 +281,18 @@ protected static final class InstallationConfiguration {
275281

276282
private final ProcessEnvironment environment;
277283
private final ProductConfig config;
278-
private final ModelNode patchingInfo;
284+
private final ModelNode installerInfo;
279285
private final Path installationDir;
280286

281-
public InstallationConfiguration(ProcessEnvironment environment, ProductConfig config, ModelNode patchingInfo, Path installationDir) {
287+
public InstallationConfiguration(ProcessEnvironment environment, ProductConfig config, ModelNode installerInfo, Path installationDir) {
282288
assert environment != null;
283289
assert config != null;
284-
assert patchingInfo != null;
290+
assert installerInfo != null;
285291
assert installationDir != null;
286292

287293
this.environment = environment;
288294
this.config = config;
289-
this.patchingInfo = patchingInfo;
295+
this.installerInfo = installerInfo;
290296
this.installationDir = installationDir;
291297
}
292298

@@ -310,11 +316,23 @@ String getInstallationDir() {
310316
}
311317

312318
String getLastUpdateDate() {
313-
if (patchingInfo.isDefined()) {
314-
List<ModelNode> result = Operations.readResult(patchingInfo).asList();
315-
for (ModelNode patchAtt : result) {
316-
if (patchAtt.has("applied-at")) {
317-
return patchAtt.get("applied-at").asString();
319+
if (installerInfo.get("result").isDefined()) {
320+
List<ModelNode> result = Operations.readResult(installerInfo).asList();
321+
for (ModelNode installerAtt : result) {
322+
if (installerAtt.has("timestamp")) {
323+
return installerAtt.get("timestamp").asString();
324+
}
325+
}
326+
}
327+
return null;
328+
}
329+
330+
List<ModelNode> getChannelVersions() {
331+
if (installerInfo.get("result").isDefined()) {
332+
List<ModelNode> result = Operations.readResult(installerInfo).asList();
333+
for (ModelNode installerAtt : result) {
334+
if (installerAtt.has("channel-versions")) {
335+
return installerAtt.get("channel-versions").asList();
318336
}
319337
}
320338
}

server/src/main/java/org/jboss/as/server/operations/InstallationReportHandler.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@ private InstallationReportHandler(ServerEnvironment environment) {
5050

5151
@Override
5252
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
53-
final ModelNode patchingInfo = new ModelNode();
54-
PathAddress patchingAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "patching"));
55-
OperationEntry opEntry = context.getRootResourceRegistration().getOperationEntry(patchingAddress, "show-history");
56-
if(opEntry != null) {
57-
context.addStep(patchingInfo, Util.createOperation("show-history", patchingAddress),
58-
opEntry.getOperationHandler(), OperationContext.Stage.RUNTIME);
53+
final ModelNode installerInfo = new ModelNode();
54+
PathAddress installerAddress = PathAddress.pathAddress(PathElement.pathElement(CORE_SERVICE, "installer"));
55+
OperationEntry installerOpEntry = context.getRootResourceRegistration().getOperationEntry(installerAddress, "history-runtime");
56+
if(installerOpEntry != null) {
57+
context.addStep(installerInfo, Util.createOperation("history-runtime", installerAddress),
58+
installerOpEntry.getOperationHandler(), OperationContext.Stage.RUNTIME);
5959
}
60+
6061
final Path installationDir = environment.getHomeDir().toPath();
6162
context.addStep(new OperationStepHandler() {
6263
@Override
6364
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
6465
ModelNode result = context.getResult();
6566
result.get(SUMMARY_DEFINITION.getName()).set(createProductNode(context, new InstallationConfiguration(
66-
environment, environment.getProductConfig(), patchingInfo, installationDir)));
67+
environment, environment.getProductConfig(), installerInfo, installationDir)));
6768
}
6869
}, OperationContext.Stage.RUNTIME);
6970
}

testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.time.Instant;
1616
import java.util.ArrayList;
1717
import java.util.Collection;
18+
import java.util.Collections;
1819
import java.util.HashMap;
1920
import java.util.Iterator;
2021
import java.util.List;
@@ -119,10 +120,10 @@ public static void initialize() throws IOException {
119120

120121
// History sample data
121122
history = new HashMap<>();
122-
history.put("update", new HistoryResult("update", Instant.now(), "update", "update description"));
123-
history.put("install", new HistoryResult("install", Instant.now(), "install", "install description"));
124-
history.put("rollback", new HistoryResult("rollback", Instant.now(), "rollback", "rollback description"));
125-
history.put("config_change", new HistoryResult("config_change", Instant.now(), "config_change", "config_change description"));
123+
history.put("update", new HistoryResult("update", Instant.now(), "update", "update description", Collections.emptyList()));
124+
history.put("install", new HistoryResult("install", Instant.now(), "install", "install description", Collections.emptyList()));
125+
history.put("rollback", new HistoryResult("rollback", Instant.now(), "rollback", "rollback description", Collections.emptyList()));
126+
history.put("config_change", new HistoryResult("config_change", Instant.now(), "config_change", "config_change description", Collections.emptyList()));
126127

127128
// List Updates sample Data
128129

0 commit comments

Comments
 (0)