Skip to content

Commit 2b52bdb

Browse files
committed
Default AS_HOSTNAME can be set from the outside explicitly
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
1 parent e79be4d commit 2b52bdb

11 files changed

Lines changed: 106 additions & 46 deletions

File tree

.github/workflows/build-linux.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ jobs:
1919
with:
2020
java-version: '21'
2121
distribution: 'temurin'
22-
- name: List ports
23-
run: ss -tulpn
22+
- name: Print OS Info
23+
run: |
24+
set -x
25+
hostname
26+
env | sort
27+
cat /etc/hosts
28+
ifconfig
29+
netstat -rn
30+
cat /etc/resolv.conf
31+
resolvectl status
32+
ss -tulpn
33+
cat /proc/cpuinfo
2434
- name: Build with Maven
2535
# qa skips documentation - we check it on Jenkins CI
2636
# We skip checkstyle too - we check it on Jenkins CI

.github/workflows/build-macos.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,27 @@ jobs:
1919
with:
2020
java-version: '21'
2121
distribution: 'temurin'
22+
- name: Print OS Info
23+
run: |
24+
set -x
25+
hostname
26+
env | sort
27+
ifconfig
28+
scutil --dns
29+
scutil --nwi
30+
netstat -rn
31+
sysctl -n machdep.cpu.brand_string
32+
sysctl -n hw.physicalcpu
33+
sysctl -n hw.logicalcpu
2234
- name: Build with Maven
2335
# qa skips documentation - we check it on Jenkins CI
2436
# We skip checkstyle too - we check it on Jenkins CI
37+
# We explicitly run tests sensitive to the OS
2538
run: mvn -B -e -ntp install -Pqa,snapshots '-Dcheckstyle.skip=true' -Pfastest
26-
- name: Test GF Starts
27-
run: mvn -B -e -ntp install -Psnapshots '-Dcheckstyle.skip=true' -pl :glassfish-itest-tools
39+
- name: Run Selected Tests
40+
run: |
41+
mvn -B -e -ntp clean install -Psnapshots '-Dcheckstyle.skip=true' -pl :common-util
42+
mvn -B -e -ntp clean install -Psnapshots '-Dcheckstyle.skip=true' -pl :glassfish-itest-tools
2843
- name: Upload server logs
2944
uses: actions/upload-artifact@v4
3045
if: failure()

.github/workflows/build-windows.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ jobs:
1919
with:
2020
java-version: '21'
2121
distribution: 'temurin'
22+
- name: Print OS Info
23+
shell: pwsh
24+
run: |
25+
ls env: | sort Name
26+
cat C:\Windows\System32\drivers\etc\hosts
27+
Get-NetIPConfiguration -Detailed
28+
Get-DnsClientServerAddress
29+
ipconfig /all
30+
Get-CimInstance Win32_Processor | Format-List *
2231
- name: Build with Maven
2332
# qa skips documentation - we check it on Jenkins CI
2433
# We skip checkstyle too - we check it on Jenkins CI

nucleus/admin/config-api/src/main/java/com/sun/enterprise/config/serverbeans/Config.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2022, 2026 Contributors to the Eclipse Foundation
33
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -20,7 +20,6 @@
2020
import com.sun.common.util.logging.LoggingConfigImpl;
2121
import com.sun.enterprise.config.serverbeans.customvalidators.NotDuplicateTargetName;
2222
import com.sun.enterprise.config.serverbeans.customvalidators.NotTargetKeyword;
23-
import com.sun.enterprise.config.util.ServerHelper;
2423

2524
import jakarta.validation.Payload;
2625
import jakarta.validation.constraints.NotNull;
@@ -344,7 +343,23 @@ private LoggingConfigImpl getLoggingConfig() {
344343
}
345344

346345
default NetworkListener getAdminListener() {
347-
return ServerHelper.getAdminListener(this);
346+
NetworkConfig networkConfig = getNetworkConfig();
347+
if (networkConfig == null) {
348+
throw new IllegalStateException("Can't operate without <http-service>");
349+
}
350+
351+
List<NetworkListener> listeners = networkConfig.getNetworkListeners().getNetworkListener();
352+
if (listeners == null || listeners.isEmpty()) {
353+
throw new IllegalStateException("Can't operate without at least one <network-listener>");
354+
}
355+
356+
for (NetworkListener listener : listeners) {
357+
if (ServerTags.ADMIN_LISTENER_ID.equals(listener.getName())) {
358+
return listener;
359+
}
360+
}
361+
// if we can't find the admin-listener, then use the first one
362+
return listeners.get(0);
348363
}
349364

350365
/**

nucleus/admin/config-api/src/main/java/com/sun/enterprise/config/util/ServerHelper.java

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@
2222
import com.sun.enterprise.config.serverbeans.Node;
2323
import com.sun.enterprise.config.serverbeans.Nodes;
2424
import com.sun.enterprise.config.serverbeans.Server;
25-
import com.sun.enterprise.config.serverbeans.ServerTags;
2625
import com.sun.enterprise.config.serverbeans.SystemProperty;
2726
import com.sun.enterprise.util.StringUtils;
2827
import com.sun.enterprise.util.net.NetUtils;
2928

30-
import java.net.InetAddress;
31-
import java.util.List;
3229
import java.util.Objects;
3330

3431
import org.glassfish.api.admin.ServerEnvironment;
3532
import org.glassfish.config.support.GlassFishConfigBean;
3633
import org.glassfish.config.support.PropertyResolver;
37-
import org.glassfish.grizzly.config.dom.NetworkConfig;
3834
import org.glassfish.grizzly.config.dom.NetworkListener;
3935
import org.jvnet.hk2.config.Dom;
4036

@@ -82,7 +78,7 @@ public final Integer getAdminPort() {
8278
*/
8379
public final String getAdminHost() throws RuntimeException {
8480
// Look at the address for the admin-listener first
85-
String addr = translateAddressAndPort(getAdminListener(config), server, config)[0];
81+
String addr = translateAddressAndPort(config.getAdminListener(), server, config)[0];
8682
if (addr != null && !addr.equals("0.0.0.0")) {
8783
return addr;
8884
}
@@ -109,10 +105,9 @@ public final String getAdminHost() throws RuntimeException {
109105
if (node != null) {
110106
hostName = node.getNodeHost();
111107
}
112-
// XXX Hack to get around the fact that the default localhost
113-
// node entry is malformed
108+
// Hack to get around the fact that the default localhost node entry is malformed
114109
if (hostName == null && nodeName.equals("localhost-" + domain.getName())) {
115-
return InetAddress.getLoopbackAddress().getHostName();
110+
return NetUtils.getHostName();
116111
}
117112
}
118113

@@ -131,25 +126,6 @@ public final boolean isListeningOnAdminPort() {
131126
}
132127
}
133128

134-
public static NetworkListener getAdminListener(Config config) {
135-
NetworkConfig networkConfig = config.getNetworkConfig();
136-
if (networkConfig == null) {
137-
throw new IllegalStateException("Can't operate without <http-service>");
138-
}
139-
140-
List<NetworkListener> listeners = networkConfig.getNetworkListeners().getNetworkListener();
141-
if (listeners == null || listeners.isEmpty()) {
142-
throw new IllegalStateException("Can't operate without at least one <network-listener>");
143-
}
144-
145-
for (NetworkListener listener : listeners) {
146-
if (ServerTags.ADMIN_LISTENER_ID.equals(listener.getName())) {
147-
return listener;
148-
}
149-
}
150-
// if we can't find the admin-listener, then use the first one
151-
return listeners.get(0);
152-
}
153129

154130
///////////////////////////////////////////
155131
/////////////////// all private below
@@ -159,7 +135,7 @@ private static String getAdminPortString(Server server, Config config) {
159135
if (server == null || config == null) {
160136
return null;
161137
}
162-
return translateAddressAndPort(getAdminListener(config), server, config)[1];
138+
return translateAddressAndPort(config.getAdminListener(), server, config)[1];
163139
}
164140

165141
/**

nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import java.util.HashMap;
2525
import java.util.Map;
2626
import java.util.Set;
27+
import java.util.function.Supplier;
2728

29+
import org.glassfish.embeddable.GlassFishVariable;
2830
import org.glassfish.main.jdke.props.EnvToPropsConverter;
2931

3032
import static org.glassfish.embeddable.GlassFishVariable.CONFIG_ROOT;
@@ -50,6 +52,7 @@
5052
*/
5153
public class ASenvPropertyReader {
5254

55+
/** Mapping of env properties to system properties - just for {@link File} values */
5356
private static final Map<String, String> ENV_TO_SYS_PROPERTY = Map.of(
5457
DERBY_ROOT.getEnvName(), DERBY_ROOT.getSystemPropertyName(),
5558
IMQ_LIB.getEnvName(), IMQ_LIB.getSystemPropertyName(),
@@ -123,17 +126,31 @@ public String toString() {
123126
return sb.toString();
124127
}
125128

126-
129+
/**
130+
* Keys: {@link GlassFishVariable#getPropertyName()}
131+
*/
127132
static class ASenvMap extends HashMap<String, String> {
128133

134+
private static final long serialVersionUID = 7637813272148581948L;
135+
129136
ASenvMap(File installDir) {
130-
new EnvToPropsConverter(installDir.toPath()).convert(ENV_TO_SYS_PROPERTY).entrySet()
137+
EnvToPropsConverter converter = new EnvToPropsConverter(installDir.toPath());
138+
converter.convert(ENV_TO_SYS_PROPERTY).entrySet()
131139
.forEach(e -> this.put(e.getKey(), e.getValue().getPath()));
132-
String javaHome = new File(System.getProperty(JAVA_HOME.getSystemPropertyName())).toPath().toString();
133-
putIfAbsent(JAVA_ROOT.getPropertyName(), javaHome);
134-
putIfAbsent(HOST_NAME.getPropertyName(), NetUtils.getCanonicalHostName());
135-
putIfAbsent(INSTALL_ROOT.getPropertyName(), installDir.toPath().toString());
136-
putIfAbsent(PRODUCT_ROOT.getPropertyName(), installDir.getParentFile().toPath().toString());
140+
evaluate(converter, HOST_NAME, NetUtils::getCanonicalHostName);
141+
// Now defaults
142+
computeIfAbsent(JAVA_ROOT, () -> new File(System.getProperty(JAVA_HOME.getSystemPropertyName())));
143+
computeIfAbsent(INSTALL_ROOT, () -> installDir);
144+
computeIfAbsent(PRODUCT_ROOT, () -> installDir.getParentFile());
145+
}
146+
147+
private void computeIfAbsent(GlassFishVariable variable, Supplier<File> defaultValue) {
148+
computeIfAbsent(variable.getPropertyName(), k -> defaultValue.get().toPath().toString());
149+
}
150+
151+
private void evaluate(EnvToPropsConverter converter, GlassFishVariable variable, Supplier<String> defaultValue) {
152+
String value = converter.evaluate(variable.getEnvName(), variable.getSystemPropertyName());
153+
put(variable.getPropertyName(), value == null ? defaultValue.get() : value);
137154
}
138155
}
139156
}

nucleus/common/common-util/src/main/java/com/sun/enterprise/util/net/NetUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.util.function.Predicate;
3535
import java.util.stream.Stream;
3636

37+
import org.glassfish.embeddable.GlassFishVariable;
38+
3739
import static java.lang.System.Logger.Level.TRACE;
3840
import static java.lang.System.Logger.Level.WARNING;
3941

@@ -387,6 +389,10 @@ public static String getHostName() {
387389
*/
388390
public static String getCanonicalHostName() {
389391
// short-circuit out if user has reverse-DNS issues
392+
String envValue = System.getenv(GlassFishVariable.HOST_NAME.getEnvName());
393+
if (envValue != null) {
394+
return envValue;
395+
}
390396
if (Boolean.parseBoolean(System.getenv("AS_NO_REVERSE_DNS"))) {
391397
return getHostName();
392398
}

nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/props/EnvToPropsConverter.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, 2025 Contributors to the Eclipse Foundation.
2+
* Copyright (c) 2024, 2026 Contributors to the Eclipse Foundation.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -90,7 +90,17 @@ public File convert(final String envPropertyName, final String systemPropertyNam
9090
}
9191

9292

93-
private String evaluate(final String envPropertyName, final String systemPropertyName) {
93+
/**
94+
* <ul>
95+
* <li>First tries {@link System#getProperty(String)} using the second parameter.
96+
* <li>Then tries {@link System#getenv(String)} using the first parameter.
97+
* </ul>
98+
*
99+
* @param envPropertyName
100+
* @param systemPropertyName
101+
* @return value or null if neither system property nor environment variable is set.
102+
*/
103+
public String evaluate(final String envPropertyName, final String systemPropertyName) {
94104
if (systemPropertyName != null) {
95105
final String sysValue = System.getProperty(systemPropertyName);
96106
if (sysValue != null) {

nucleus/common/simple-glassfish-api/src/main/java/org/glassfish/embeddable/GlassFishVariable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum GlassFishVariable {
3131
/** Directory where we have domains */
3232
DOMAINS_ROOT("AS_DEF_DOMAINS_PATH", "com.sun.aas.domainsRoot"),
3333
/** Autodetected host name. */
34-
HOST_NAME(null, "com.sun.aas.hostName"),
34+
HOST_NAME("AS_HOSTNAME", "com.sun.aas.hostName"),
3535
/** Java home directory set by JVM automatically via <code>java.home</code> or via JAVA_HOME by user. */
3636
JAVA_HOME("JAVA_HOME", "java.home"),
3737
/** Java home set by AS_JAVA, has higher priority than JAVA_HOME. */

nucleus/distributions/nucleus-common/src/main/resources/config/asenv.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ IF "%AS_DERBY_INSTALL%"=="" SET "AS_DERBY_INSTALL=%AS_INSTALL%\..\javadb"
4343
IF "%AS_IMQ_BIN%"=="" SET "AS_IMQ_BIN=%AS_INSTALL%\..\mq\bin"
4444
IF "%AS_IMQ_LIB%"=="" SET "AS_IMQ_LIB=%AS_INSTALL%\..\mq\lib"
4545

46+
IF "%AS_HOSTNAME%"=="" IF NOT "%COMPUTERNAME%"=="" SET AS_HOSTNAME=%COMPUTERNAME%
4647
IF "%AS_CONFIG%"=="" SET "AS_CONFIG=%AS_INSTALL%\config"
4748
IF "%AS_DEF_DOMAINS_PATH%"=="" SET "AS_DEF_DOMAINS_PATH=%AS_INSTALL%\domains"
4849
IF "%AS_DEF_NODES_PATH%"=="" SET "AS_DEF_NODES_PATH=%AS_INSTALL%\nodes"

0 commit comments

Comments
 (0)