From 5364c093ddc2ed18483d42207ef1041c2a2cf458 Mon Sep 17 00:00:00 2001 From: Jean-Francois Denise Date: Tue, 21 Nov 2023 12:48:18 +0100 Subject: [PATCH] Fix for Issue #373, Introduce jboss.tx.node.id --- docs/guide/intro/index.adoc | 5 +- .../extensions/cloud/CloudExtension.java | 63 ++++++++++++------- .../cloud/CloudExtensionTestCase.java | 20 +++--- .../maven/cloud/openshift-tx-script.cli | 3 +- 4 files changed, 56 insertions(+), 35 deletions(-) diff --git a/docs/guide/intro/index.adoc b/docs/guide/intro/index.adoc index 518e2d00..4d988dfb 100644 --- a/docs/guide/intro/index.adoc +++ b/docs/guide/intro/index.adoc @@ -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 `````` child element ```true|false``` to enable authentication. diff --git a/extensions/cloud/src/main/java/org/wildfly/plugins/bootablejar/extensions/cloud/CloudExtension.java b/extensions/cloud/src/main/java/org/wildfly/plugins/bootablejar/extensions/cloud/CloudExtension.java index 9d181e61..4b213c5c 100644 --- a/extensions/cloud/src/main/java/org/wildfly/plugins/bootablejar/extensions/cloud/CloudExtension.java +++ b/extensions/cloud/src/main/java/org/wildfly/plugins/bootablejar/extensions/cloud/CloudExtension.java @@ -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"); @@ -80,14 +81,15 @@ private static void handleCloud(List args, Path installDir, String hostn } } - boolean hasJbossNodeName = false; + String nodeName = null; Set 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); @@ -105,29 +107,42 @@ private static void handleCloud(List 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; } } diff --git a/extensions/cloud/src/test/java/org/wildfly/plugins/bootablejar/extensions/cloud/CloudExtensionTestCase.java b/extensions/cloud/src/test/java/org/wildfly/plugins/bootablejar/extensions/cloud/CloudExtensionTestCase.java index 446833bc..f678aa51 100644 --- a/extensions/cloud/src/test/java/org/wildfly/plugins/bootablejar/extensions/cloud/CloudExtensionTestCase.java +++ b/extensions/cloud/src/test/java/org/wildfly/plugins/bootablejar/extensions/cloud/CloudExtensionTestCase.java @@ -36,9 +36,10 @@ public void test() throws Exception { p.toFile().deleteOnExit(); List 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 @@ -48,9 +49,10 @@ public void test2() throws Exception { p.toFile().deleteOnExit(); List 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 @@ -60,9 +62,10 @@ public void test3() throws Exception { p.toFile().deleteOnExit(); List 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 @@ -73,9 +76,10 @@ public void test4() throws Exception { List 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 @@ -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"); } @@ -102,8 +107,9 @@ public void test6() throws Exception { List 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))); } } diff --git a/plugin/src/main/resources/org/wildfly/plugins/bootablejar/maven/cloud/openshift-tx-script.cli b/plugin/src/main/resources/org/wildfly/plugins/bootablejar/maven/cloud/openshift-tx-script.cli index d2c3ee48..70573b2b 100644 --- a/plugin/src/main/resources/org/wildfly/plugins/bootablejar/maven/cloud/openshift-tx-script.cli +++ b/plugin/src/main/resources/org/wildfly/plugins/bootablejar/maven/cloud/openshift-tx-script.cli @@ -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 \ No newline at end of file