Skip to content

Commit eb7dc25

Browse files
committed
Resolving keytool timeouts on CI
- 60 seconds instead of 10 - Printing output in error messages Signed-off-by: David Matějček <[email protected]>
1 parent 5d944c7 commit eb7dc25

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/KeystoreManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected void createKeyStore(File keyStore, RepositoryConfig config, String mas
9595
final String instanceCertDN = getInstanceCertDN(config);
9696
keyTool.generateKeyPair(INSTANCE_SECURE_ADMIN_ALIAS, instanceCertDN, "RSA", 3650);
9797
} catch (IOException e) {
98-
throw new DomainException(_strMgr.getString("SomeProblemWithKeytool", keyStore), e);
98+
throw new DomainException(_strMgr.getString("SomeProblemWithKeytool"), e);
9999
}
100100
}
101101

@@ -109,7 +109,7 @@ protected final void copyCertificatesToTrustStore(File configRoot, DomainConfig
109109
keyTool.copyCertificate(CERTIFICATE_ALIAS, trustStore);
110110
keyTool.copyCertificate(INSTANCE_SECURE_ADMIN_ALIAS, trustStore);
111111
} catch (IOException e) {
112-
throw new DomainException(_strMgr.getString("SomeProblemWithKeytool", keyStore), e);
112+
throw new DomainException(_strMgr.getString("SomeProblemWithKeytool"), e);
113113
}
114114
}
115115

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/LocalStrings.properties

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ installRoot=install root
3232
cannotDeleteJmsProviderInstance=Error deleting mq broker instance
3333
masterPasswordFileNotRead=Error reading master password file {0}
3434

35-
keyStorePasswordNotChanged=Error changing keystore password for store {0}
35+
keyStorePasswordNotChanged=Error changing keystore password for store {0}.
3636

3737
s1asKeyPasswordNotChanged=Error changing password for default key with alias s1as for store {0}
3838

@@ -71,4 +71,9 @@ runtimeStatusToStringStartCluster.startedToStopped=This should be impossible. T
7171
runtimeStatusToStringStartCluster.error=The clustered instance, {0}, could not be started. It was originally in this state: [{1}] and now it is in this state: [{2}].
7272

7373
CertificateDN=Distinguished Name of the self-signed X.509 Server Certificate is:\n[{0}]
74-
SomeProblemWithKeytool= Domain creation process involves a step that creates primary key and\n self-signed server certificate. This step failed for the reason shown below.\n This could be because JDK provided keytool program could not be found (e.g.\n you are running with JRE) or for some other reason. No need to panic, as you\n can always use JDK-keytool program to do the needful. A temporary JKS-keystore\n will be created. You should replace it with proper keystore before using it for SSL.\n Refer to documentation for details. Actual error is:\n{0}
74+
SomeProblemWithKeytool= Domain creation process involves a step that creates primary key and\n self-signed server certificate.\
75+
This step failed for the reason shown below.\n This could be because JDK provided keytool program could not be found\
76+
(e.g.\n you are running with JRE) or for some other reason. No need to panic, as you\n can always use JDK-keytool program to do the needful.\
77+
A temporary JKS-keystore\n will be created.\
78+
You should replace it with proper keystore before using it for SSL.\n Refer to documentation for details.\
79+
Actual error is:\n

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/RepositoryException.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ public RepositoryException(String message, Throwable cause) {
6060
private String format(String msg, String causeMsg, Throwable cause) {
6161
if (cause != null) {
6262
if (msg == null) {
63-
if (causeMsg != null) {
64-
msg = causeMsg;
65-
} else {
66-
msg = cause.toString();
67-
}
63+
msg = causeMsg == null ? cause.toString() : causeMsg;
6864
} else if (causeMsg != null && !causeMsg.equals(msg)) {
6965
msg += PREFIX + causeMsg + POSTFIX;
7066
} else {

nucleus/common/glassfish-jdk-extensions/src/main/java/org/glassfish/main/jdke/security/KeyTool.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
public class KeyTool {
5151

5252
private static final Logger LOG = System.getLogger(KeyTool.class.getName());
53-
private static final long EXEC_TIMEOUT = 10;
53+
private static final long EXEC_TIMEOUT = Integer.getInteger("org.glassfish.main.keytool.timeout", 60);
5454
private static final String KEYTOOL;
5555

5656
static {
@@ -378,26 +378,30 @@ private static void execute(final File keyStore, final List<String> command, fin
378378
}
379379

380380
if (!process.waitFor(EXEC_TIMEOUT, TimeUnit.SECONDS)) {
381-
throw new IOException("KeyTool command timed out after " + EXEC_TIMEOUT + " seconds");
381+
throw new IOException(
382+
"KeyTool command timed out after " + EXEC_TIMEOUT + " seconds. Output: " + getOutput(process));
382383
}
383384
final int exitCode = process.exitValue();
384-
final ByteArrayOutputStream output = new ByteArrayOutputStream();
385-
process.getInputStream().transferTo(output);
386-
process.getErrorStream().transferTo(output);
387-
LOG.log(DEBUG, () -> "Command output: " + output.toString(Charset.defaultCharset()));
385+
final String output = getOutput(process);
386+
LOG.log(DEBUG, () -> "Command output: " + output);
388387
if (exitCode != 0) {
389-
throw new IOException("KeyTool command failed with exit code: " + exitCode + " and output:"
390-
+ output.toString(Charset.defaultCharset()));
388+
throw new IOException("KeyTool command failed with exit code: " + exitCode + " and output: " + output);
391389
}
392-
} catch (IOException e) {
393-
throw new IOException("Failed to initialize keystore " + keyStore, e);
394390
} catch (InterruptedException e) {
395391
Thread.currentThread().interrupt();
396392
throw new IOException("Interrupted", e);
397393
}
398394
}
399395

400396

397+
private static String getOutput(final Process process) throws IOException {
398+
final ByteArrayOutputStream output = new ByteArrayOutputStream();
399+
process.getInputStream().transferTo(output);
400+
process.getErrorStream().transferTo(output);
401+
return output.toString(Charset.defaultCharset());
402+
}
403+
404+
401405
private static void writeStdIn(char[][] stdinLines, Writer stdin) throws IOException {
402406
for (char[] line : stdinLines) {
403407
writeLine(line, stdin);

0 commit comments

Comments
 (0)