Skip to content

Commit 52c95d2

Browse files
authored
Merge pull request #6441 from bstansberry/WFCORE-7276
[WFCORE-7276] InterfaceAddHandler should consider updates made by lat…
2 parents b3dc473 + bb26c8d commit 52c95d2

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

controller/src/main/java/org/jboss/as/controller/interfaces/ParsedInterfaceCriteria.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.net.InetAddress;
1313
import java.net.UnknownHostException;
14+
import java.util.Iterator;
1415
import java.util.LinkedHashSet;
1516
import java.util.List;
1617
import java.util.Set;
@@ -39,7 +40,7 @@ public final class ParsedInterfaceCriteria {
3940

4041
private final String failureMessage;
4142
private final boolean anyLocal;
42-
private final Set<InterfaceCriteria> criteria = new LinkedHashSet<InterfaceCriteria>();
43+
private final Set<InterfaceCriteria> criteria = new LinkedHashSet<>();
4344

4445
private ParsedInterfaceCriteria(final String failureMessage) {
4546
this.failureMessage = failureMessage;
@@ -84,12 +85,19 @@ public static ParsedInterfaceCriteria parse(final ModelNode model, final boolean
8485
} else {
8586
try {
8687
final List<Property> nodes = subModel.asPropertyList();
87-
final Set<InterfaceCriteria> criteriaSet = new LinkedHashSet<InterfaceCriteria>();
88-
for (final Property property : nodes) {
88+
final Set<InterfaceCriteria> criteriaSet = new LinkedHashSet<>();
89+
int definedPropertyCount = 0;
90+
for (Iterator<Property> propertyIterator = nodes.iterator(); propertyIterator.hasNext() ; ) {
91+
Property property = propertyIterator.next();
92+
// The model will have properties for all attributes; ignore the undefined ones
93+
if (!property.getValue().isDefined()) {
94+
continue;
95+
}
96+
definedPropertyCount++;
8997
final InterfaceCriteria criterion = parseCriteria(property, false, expressionResolver);
9098
if (criterion instanceof WildcardInetAddressInterfaceCriteria) {
91-
// AS7-1668: stop processing and just return the any binding.
92-
if (nodes.size() > 1) {
99+
// AS7-1668: stop processing and just return the 'any' binding.
100+
if (definedPropertyCount > 1 || hasMoreDefinedProperties(propertyIterator)) {
93101
MGMT_OP_LOGGER.wildcardAddressDetected();
94102
}
95103
return ParsedInterfaceCriteria.ANY;
@@ -172,7 +180,7 @@ private static InterfaceCriteria parseNested(final ModelNode subModel, final boo
172180
if(!subModel.isDefined() || subModel.asInt() == 0) {
173181
return null;
174182
}
175-
final Set<InterfaceCriteria> criteriaSet = new LinkedHashSet<InterfaceCriteria>();
183+
final Set<InterfaceCriteria> criteriaSet = new LinkedHashSet<>();
176184
for(final Property nestedProperty : subModel.asPropertyList()) {
177185
final Element element = Element.forName(nestedProperty.getName());
178186
switch (element) {
@@ -272,6 +280,15 @@ private static ModelNode parsePossibleExpression(final ModelNode node) {
272280
return (node.getType() == ModelType.STRING) ? ParseUtils.parsePossibleExpression(node.asString()) : node;
273281
}
274282

283+
private static boolean hasMoreDefinedProperties(Iterator<Property> iterator) {
284+
while (iterator.hasNext()) {
285+
if (iterator.next().getValue().isDefined()) {
286+
return true;
287+
}
288+
}
289+
return false;
290+
}
291+
275292
private static class ParsingException extends RuntimeException {
276293
private static final long serialVersionUID = -5627251228393035383L;
277294

controller/src/main/java/org/jboss/as/controller/operations/common/InterfaceAddHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected void validateAndSet(final AttributeDefinition definition, final ModelN
5959

6060
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
6161
String name = context.getCurrentAddressValue();
62-
ParsedInterfaceCriteria parsed = getCriteria(context, operation);
62+
ParsedInterfaceCriteria parsed = getCriteria(context, model);
6363
if (parsed.getFailureMessage() != null) {
6464
throw new OperationFailedException(parsed.getFailureMessage());
6565
}

controller/src/main/java/org/jboss/as/controller/operations/common/InterfaceCriteriaWriteHandler.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,18 @@ public void execute(final OperationContext context, final ModelNode operation) t
6666
} else {
6767
throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.unknownAttribute(attributeName));
6868
}
69-
if (updateRuntime) {
69+
// A runtime update after boot must be via a reload.
70+
// During boot, no reload is needed because we just modified the model
71+
// and the Stage.RUNTIME handler for the op that added this interface
72+
// will process a model that includes our update.
73+
boolean reload = updateRuntime && !context.isBooting();
74+
if (reload) {
7075
// Require a reload
7176
context.reloadRequired();
7277
}
7378
// Verify the model in a later step
7479
context.addStep(VERIFY_HANDLER, OperationContext.Stage.MODEL);
75-
OperationContext.RollbackHandler rollbackHandler = updateRuntime
80+
OperationContext.RollbackHandler rollbackHandler = reload
7681
? OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER
7782
: OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
7883
context.completeStep(rollbackHandler);

testsuite/manualmode/src/test/java/org/jboss/as/test/manualmode/management/persistence/yaml/YamlExtensionTestCase.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import java.io.ByteArrayOutputStream;
2323
import java.io.InputStream;
2424
import java.io.PrintStream;
25+
import java.net.Inet4Address;
26+
import java.net.InetAddress;
27+
import java.net.UnknownHostException;
2528
import java.nio.charset.StandardCharsets;
2629
import java.nio.file.Files;
2730
import java.nio.file.Path;
@@ -46,8 +49,10 @@
4649
import org.jboss.as.controller.client.helpers.Operations;
4750
import org.jboss.as.controller.client.impl.AdditionalBootCliScriptInvoker;
4851
import org.jboss.as.controller.operations.common.Util;
52+
import org.jboss.as.network.NetworkUtils;
4953
import org.jboss.as.test.integration.management.util.CLIWrapper;
5054
import org.jboss.as.test.shared.AssumeTestGroupUtil;
55+
import org.jboss.as.test.shared.TestSuiteEnvironment;
5156
import org.jboss.as.test.shared.TimeoutUtil;
5257
import org.jboss.dmr.ModelNode;
5358
import org.jboss.logging.Logger;
@@ -93,6 +98,7 @@ public class YamlExtensionTestCase {
9398
private static Path testSocketOverrideYaml;
9499
private static Path testPortOffsetOverrideYaml;
95100
private static Path testRemoveSocketYaml;
101+
private static Path testInterfaceOverrideYaml;
96102
private static Path testAddingExtensionPathDeploymentOverlayIgnored;
97103
private static Path testAddingEmptyExtensionFailYaml;
98104
private static Path testDeploymentYaml;
@@ -151,6 +157,7 @@ public static void setup() throws Exception {
151157
testSocketOverrideYaml = getResourceFilePath("test-socket-override.yml");
152158
testPortOffsetOverrideYaml = getResourceFilePath("test-port-offset-override.yml");
153159
testRemoveSocketYaml = getResourceFilePath("test-remove-socket.yml");
160+
testInterfaceOverrideYaml = getResourceFilePath("test-interface-override.yml");
154161
testAddingExtensionPathDeploymentOverlayIgnored = getResourceFilePath("test-adding-extension-path-deployment-overlay-ignored.yml");
155162
testAddingEmptyExtensionFailYaml = getResourceFilePath("test-adding-empty-extension.yml");
156163
testDeploymentYaml = getResourceFilePath("test-deployment.yml");
@@ -644,6 +651,21 @@ public void testPostStartCLIChangesToModelDoNotSurviveRestart() throws Exception
644651
Assert.assertEquals("Yaml changes to configuration were persisted to xml. This should never happen.", defaultXml, readConfigAsXml());
645652
}
646653

654+
@Test
655+
public void testInterfaceOverride() throws UnknownHostException {
656+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
657+
container.startYamlExtension(new PrintStream(byteArrayOutputStream), new Path[]{testInterfaceOverrideYaml});
658+
String logged = byteArrayOutputStream.toString();
659+
660+
InetAddress serverAddress = InetAddress.getByName(TestSuiteEnvironment.getServerAddress());
661+
String expectedAddress = serverAddress instanceof Inet4Address ? "0.0.0.0" : "[0:0:0:0:0:0:0:0]";
662+
String expectedConsoleOutput = "http://"+ expectedAddress + ":9990/management";
663+
assertThat("The server didn't log it is listening on address 0.0.0.0.", logged, CoreMatchers.containsString(expectedConsoleOutput));
664+
String unexpectedAddress = NetworkUtils.formatIPAddressForURI(serverAddress);
665+
String unexpectedConsoleOutput = "http://" + unexpectedAddress + ":9990/management";
666+
assertThat("The server logged it is listening on address 127.0.0.1.", logged, CoreMatchers.not(CoreMatchers.containsString(unexpectedConsoleOutput)));
667+
}
668+
647669
private void waitForRunningMode(String runningMode) throws Exception {
648670
// Following a reload to normal mode, we might read the running mode too early and hit the admin-only server
649671
// Cycle around a bit to make sure we get the server reloaded into normal mode
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
wildfly-configuration:
3+
interface:
4+
management:
5+
inet-address: "0.0.0.0"

0 commit comments

Comments
 (0)