Skip to content

Commit 0718fe2

Browse files
committed
use resource for DeadlineExceeded message text
1 parent 9e31aee commit 0718fe2

File tree

5 files changed

+54
-19
lines changed

5 files changed

+54
-19
lines changed

operator/src/main/java/oracle/kubernetes/operator/JobWatcher.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -312,29 +312,19 @@ public DeadlineExceededException(V1Job job) {
312312
}
313313

314314
public String toString() {
315-
StringBuilder sb = new StringBuilder("Job ")
316-
.append(job.getMetadata().getName()).append(" failed due to reason: DeadlineExceeded.")
317-
.append(" ActiveDeadlineSeconds of the job is configured with "
318-
+ job.getSpec().getActiveDeadlineSeconds()
319-
+ " seconds.")
320-
.append(getJobStartedSecondsMessage())
321-
.append(" Ensure all domain dependencies have been deployed")
322-
.append(" (any secrets, config-maps, PVs, and PVCs that the domain resource references).")
323-
.append(" Use kubectl describe the job and its pod for more job failure information.")
324-
.append(" The job may be retried by the operator up to "
325-
+ DomainPresence.getDomainPresenceFailureRetryMaxCount()
326-
+ " times with longer ActiveDeadlineSeconds value in each subsequent retry.")
327-
.append(" Use tuning parameter \"domainPresenceFailureRetryMaxCount\" to configure max retries.");
328-
return sb.toString();
315+
return LOGGER.getFormattedMessage(
316+
MessageKeys.JOB_DEADLINE_EXCEEDED_MESSAGE,
317+
job.getMetadata().getName(),
318+
job.getSpec().getActiveDeadlineSeconds(),
319+
getJobStartedSeconds(),
320+
DomainPresence.getDomainPresenceFailureRetryMaxCount());
329321
}
330322

331-
private String getJobStartedSecondsMessage() {
323+
private long getJobStartedSeconds() {
332324
if (job.getStatus() != null && job.getStatus().getStartTime() != null) {
333-
return " The job was started "
334-
+ ((System.currentTimeMillis() - job.getStatus().getStartTime().getMillis()) / 1000)
335-
+ " seconds ago.";
325+
return (System.currentTimeMillis() - job.getStatus().getStartTime().getMillis()) / 1000;
336326
}
337-
return null;
327+
return -1;
338328
}
339329
}
340330
}

operator/src/main/java/oracle/kubernetes/operator/logging/LoggingFacade.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package oracle.kubernetes.operator.logging;
66

7+
import java.text.MessageFormat;
78
import java.util.Arrays;
89
import java.util.logging.ConsoleHandler;
910
import java.util.logging.Handler;
@@ -632,6 +633,21 @@ public void trace(String msg, Object... args) {
632633
finer(TRACE + msg, args);
633634
}
634635

636+
/**
637+
* Returns a formatted message.
638+
*
639+
* @param msg the message to be formatted, which is key to the resource bundle
640+
* @param args parameters to the message
641+
* @return A formatted message
642+
*/
643+
public String getFormattedMessage(String msg, Object... args) {
644+
try {
645+
return MessageFormat.format(logger.getResourceBundle().getString(msg), args);
646+
} catch (Exception ex) {
647+
return msg;
648+
}
649+
}
650+
635651
/**
636652
* Obtains caller details, class name and method, to be provided to the actual Logger. This code
637653
* is adapted from ODLLogRecord, which should yield consistency in reporting using PlatformLogger

operator/src/main/java/oracle/kubernetes/operator/logging/MessageKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public class MessageKeys {
153153
public static final String EXTERNAL_CHANNEL_SERVICE_REPLACED = "WLSKO-0151";
154154
public static final String EXTERNAL_CHANNEL_SERVICE_EXISTS = "WLSKO-0152";
155155
public static final String WLS_HEALTH_READ_FAILED_NO_HTTPCLIENT = "WLSKO-0153";
156+
public static final String JOB_DEADLINE_EXCEEDED_MESSAGE = "WLSKO-0154";
156157

157158
private MessageKeys() {
158159
}

operator/src/main/resources/Operator.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,13 @@ WLSKO-0150=Creating external channel service for WebLogic domain with UID: {0}.
151151
WLSKO-0151=Replacing external channel service for WebLogic domain with UID: {0}.
152152
WLSKO-0152=Existing external channel service is correct for WebLogic domain with UID: {0}.
153153
WLSKO-0153=Failed to read health information from server {0}. Unable to connect to server.
154+
WLSKO-0154=Job {0} failed due to reason: DeadlineExceeded. \
155+
ActiveDeadlineSeconds of the job is configured with {1} seconds. \
156+
The job was started {2} seconds ago. \
157+
Ensure all domain dependencies have been deployed \
158+
(any secrets, config-maps, PVs, and PVCs that the domain resource references). \
159+
Use kubectl describe for the job and its pod for more job failure information. \
160+
The job may be retried by the operator up to {3} \
161+
times with longer ActiveDeadlineSeconds value in each subsequent retry. \
162+
Use tuning parameter 'domainPresenceFailureRetryMaxCount' to configure max retries.
163+

operator/src/test/java/oracle/kubernetes/operator/logging/LoggingFacadeTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ public void verifySevereMessageWithThrowableNotLoggedIfLoggingFilterDenies() {
122122
assertThat(mockLogger.isLogpCalled(), is(false));
123123
}
124124

125+
@Test
126+
public void verifyGetFormattedMessage_withArgs_returnsFormattedMessage() {
127+
assertThat(loggingFacade.getFormattedMessage(MessageKeys.CYCLING_SERVERS, "domain1", "list1"),
128+
is("Cycling of servers for Domain with UID domain1 in the list list1 now"));
129+
}
130+
131+
@Test
132+
public void verifyGetFormattedMessage_withNoArgs_returnsFormattedMessage() {
133+
assertThat(loggingFacade.getFormattedMessage(MessageKeys.RESOURCE_BUNDLE_NOT_FOUND),
134+
is("Could not find the resource bundle"));
135+
}
136+
137+
@Test
138+
public void verifyGetFormattedMessage_withNonExistingKey_returnsOriginalMessage() {
139+
assertThat(loggingFacade.getFormattedMessage("Not a key"),
140+
is("Not a key"));
141+
}
142+
125143
static class MockLogger extends Logger {
126144

127145
boolean logpCalled;

0 commit comments

Comments
 (0)