Skip to content

Commit

Permalink
Merge pull request #377 from jfdenise/9.x
Browse files Browse the repository at this point in the history
[9.x] Fix for Issue #373, Introduce jboss.tx.node.id
  • Loading branch information
jfdenise authored Nov 21, 2023
2 parents 386229f + 5364c09 commit 7cbfe13
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 35 deletions.
5 changes: 3 additions & 2 deletions docs/guide/intro/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,10 @@ The sever configuration is updated in order to properly operate in a cloud envir
* The public and private inet addresses are bound to the value of the ```HOSTNAME``` environment variable if defined (defined in OpenShift PODS).
* The management inet address is bound to the 0.0.0.0 inet address allowing for local (required by WildFly CLI) and remote access (required by OpenShift readiness and liveness probes).
* The http and https socket-bindings are bound to 0.0.0.0 inet address.
* The transaction subsystem id is set to the value of ```jboss.node.name```.
* The ```jboss.node.name``` system propery, if not set, is set to the value of ```HOSTNAME``` environment variable if defined (defined in OpenShift PODS). The node name value
* The transaction subsystem id is set to the value of ```jboss.tx.node.id```.
* The ```jboss.tx.node.id``` system property, if not set, is set to the value of ```HOSTNAME``` environment variable if defined (defined in OpenShift PODS). The node name value
is truncated to a max of 23 characters in order for the transaction subsystem to properly operate. The last 23 characters are taken into account.
* The ```jboss.node.name``` system property, if not set, is set to the value of ```HOSTNAME``` environment variable if defined (defined in OpenShift PODS).
* The server logs are printed to the console.
* jgroups subsystem is configured to use kubernetes.KUBE_PING jgroups protocol for both tcp (default stack) and udp. PING and MPING protocols are removed.
* It is possible to configure jgroups to use un-encrypted password authentication. Set the ```<cloud>``` child element ```<enable-jgroups-password>true|false</enable-jgroups-password>``` to enable authentication.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CloudExtension implements RuntimeExtension {
private static final String KUBERNETES_RESOURCE = "/kubernetes.properties";
private static final String OPENSHIFT_HOST_NAME_ENV = "HOSTNAME";
private static final String JBOSS_NODE_NAME_PROPERTY = "jboss.node.name";
private static final String JBOSS_TX_NODE_ID_PROPERTY = "jboss.tx.node.id";
private static final Path JBOSS_CONTAINER_DIR = Paths.get("/opt/jboss/container");
private static final Path JBOSS_CONTAINER_BOOTABLE_DIR = JBOSS_CONTAINER_DIR.resolve("wildfly-bootable-jar");
private static final Path INSTALL_DIR_FILE = JBOSS_CONTAINER_BOOTABLE_DIR.resolve("install-dir");
Expand Down Expand Up @@ -80,14 +81,15 @@ private static void handleCloud(List<String> args, Path installDir, String hostn
}
}

boolean hasJbossNodeName = false;
String nodeName = null;
Set<String> overridingProps = new HashSet<>();
for (String arg : args) {
if (arg.startsWith("-D" + JBOSS_NODE_NAME_PROPERTY + "=")) {
hasJbossNodeName = true;
int eq = arg.indexOf("=");
nodeName = arg.substring(eq + 1, arg.length());
} else {
if (arg.startsWith("-D")) {
String prop = null;
String prop;
int eq = arg.indexOf("=");
if (eq == -1) {
prop = arg.substring(2);
Expand All @@ -105,29 +107,42 @@ private static void handleCloud(List<String> args, Path installDir, String hostn
}
}

if (!hasJbossNodeName) {
String value = System.getProperty(JBOSS_NODE_NAME_PROPERTY);
if (value == null) {

if (hostname != null) {
// This is a constraint that breaks the server at startup.
if (hostname.length() > 23) {
String originalHostName = hostname;
StringBuilder builder = new StringBuilder();
char[] chars = hostname.toCharArray();
for (int i = 1; i <= 23; i++) {
char c = chars[hostname.length() - i];
builder.insert(0, c);
}
hostname = builder.toString();
System.out.println("The HOSTNAME env variable used to set "
+ "jboss.node.name is longer than 23 bytes. "
+ "jboss.node.name value was adjusted to 23 bytes long string "
+ hostname + " from the original value " + originalHostName);
}
args.add("-Djboss.node.name=" + hostname);
if (nodeName == null) {
boolean setNodeName = true;
nodeName = System.getProperty(JBOSS_NODE_NAME_PROPERTY);
if (nodeName == null) {
nodeName = hostname;
} else {
setNodeName = false;
}
if (nodeName != null) {
String txId = trunkTxIdValue(nodeName);
if (setNodeName) {
args.add("-D" + JBOSS_NODE_NAME_PROPERTY + "=" + nodeName);
}
args.add("-D" + JBOSS_TX_NODE_ID_PROPERTY + "=" + txId);
}
} else {
String txId = trunkTxIdValue(nodeName);
args.add("-D" + JBOSS_TX_NODE_ID_PROPERTY + "=" + txId);
}
}

private static String trunkTxIdValue(String value) {
if (value.length() > 23) {
String originalValue = value;
StringBuilder builder = new StringBuilder();
char[] chars = value.toCharArray();
for (int i = 1; i <= 23; i++) {
char c = chars[value.length() - i];
builder.insert(0, c);
}
value = builder.toString();
System.out.println("The HOSTNAME env variable used to set "
+ JBOSS_TX_NODE_ID_PROPERTY + " is longer than 23 bytes. "
+ JBOSS_TX_NODE_ID_PROPERTY + " value was adjusted to 23 bytes long string "
+ value + " from the original value " + originalValue);
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public void test() throws Exception {
p.toFile().deleteOnExit();
List<String> args = new ArrayList<>();
extension.doBoot(args, p, "abcdefghijklmnopqrstvuwxyz");
assertTrue(args.size() == 2);
assertTrue(args.size() == 3);
assertTrue(args.toString(), "-Dfoo.bar=toto".equals(args.get(0)));
assertTrue(args.toString(), "-Djboss.node.name=defghijklmnopqrstvuwxyz".equals(args.get(1)));
assertTrue(args.toString(), "-Djboss.node.name=abcdefghijklmnopqrstvuwxyz".equals(args.get(1)));
assertTrue(args.toString(), "-Djboss.tx.node.id=defghijklmnopqrstvuwxyz".equals(args.get(2)));
}

@Test
Expand All @@ -48,9 +49,10 @@ public void test2() throws Exception {
p.toFile().deleteOnExit();
List<String> args = new ArrayList<>();
extension.doBoot(args, p, "abcdefghijklmnopqrstvuw");
assertTrue(args.size() == 2);
assertTrue(args.size() == 3);
assertTrue(args.toString(), "-Dfoo.bar=toto".equals(args.get(0)));
assertTrue(args.toString(), "-Djboss.node.name=abcdefghijklmnopqrstvuw".equals(args.get(1)));
assertTrue(args.toString(), "-Djboss.tx.node.id=abcdefghijklmnopqrstvuw".equals(args.get(2)));
}

@Test
Expand All @@ -60,9 +62,10 @@ public void test3() throws Exception {
p.toFile().deleteOnExit();
List<String> args = new ArrayList<>();
extension.doBoot(args, p, "a");
assertTrue(args.size() == 2);
assertTrue(args.size() == 3);
assertTrue(args.toString(), "-Dfoo.bar=toto".equals(args.get(0)));
assertTrue(args.toString(), "-Djboss.node.name=a".equals(args.get(1)));
assertTrue(args.toString(), "-Djboss.tx.node.id=a".equals(args.get(2)));
}

@Test
Expand All @@ -73,9 +76,10 @@ public void test4() throws Exception {
List<String> args = new ArrayList<>();
args.add("-Djboss.node.name=foo");
extension.doBoot(args, p, "abcdef");
assertTrue(args.size() == 2);
assertTrue(args.size() == 3);
assertTrue(args.toString(), "-Djboss.node.name=foo".equals(args.get(0)));
assertTrue(args.toString(), "-Dfoo.bar=toto".equals(args.get(1)));
assertTrue(args.toString(), "-Djboss.tx.node.id=foo".equals(args.get(2)));
}

@Test
Expand All @@ -87,8 +91,9 @@ public void test5() throws Exception {
System.setProperty("jboss.node.name", "foo");
try {
extension.doBoot(args, p, "abcdef");
assertTrue(args.size() == 1);
assertTrue(args.size() == 2);
assertTrue(args.toString(), "-Dfoo.bar=toto".equals(args.get(0)));
assertTrue(args.toString(), "-Djboss.tx.node.id=foo".equals(args.get(1)));
} finally {
System.clearProperty("jboss.node.name");
}
Expand All @@ -102,8 +107,9 @@ public void test6() throws Exception {
List<String> args = new ArrayList<>();
args.add("-Dfoo.bar=fromtest");
extension.doBoot(args, p, "abcdef");
assertTrue(args.size() == 2);
assertTrue(args.size() == 3);
assertTrue(args.toString(), "-Dfoo.bar=fromtest".equals(args.get(0)));
assertTrue(args.toString(), "-Djboss.node.name=abcdef".equals(args.get(1)));
assertTrue(args.toString(), "-Djboss.tx.node.id=abcdef".equals(args.get(2)));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#We must disable jboss.node.name until the boot can set it to a proper value (WF 21).
if (outcome == success) of /subsystem=transactions:read-resource
/subsystem=transactions:write-attribute(name=node-identifier,value=${jboss.node.name:1})
/subsystem=transactions:write-attribute(name=node-identifier,value=${jboss.tx.node.id:1})
/subsystem=transactions:write-attribute(name=recovery-listener,value=true)
end-if

0 comments on commit 7cbfe13

Please sign in to comment.