diff --git a/kubernetes/samples/scripts/domain-lifecycle/README.md b/kubernetes/samples/scripts/domain-lifecycle/README.md index d24709517fe..0eeab95d56b 100644 --- a/kubernetes/samples/scripts/domain-lifecycle/README.md +++ b/kubernetes/samples/scripts/domain-lifecycle/README.md @@ -81,9 +81,9 @@ domain.weblogic.oracle/domain1 patched The `scaleCluster.sh` script scales a WebLogic cluster by patching the `spec.clusters[].replicas` attribute of the domain resource to the specified value. The operator will perform the scaling operation for the WebLogic cluster based on the specified value of the `replicas` attribute after its value is updated. See the script `usage` information by using the `-h` option. ``` $ scaleCluster.sh -d domain1 -n weblogic-domain-1 -c cluster-1 -r 3 -[2021-02-26T19:04:14.335 UTC][INFO] Patching replicas for cluster 'cluster-1' to '3'. +[2021-02-26T19:04:14.335000Z][INFO] Patching replicas for cluster 'cluster-1' to '3'. domain.weblogic.oracle/domain1 patched -[2021-02-26T19:04:14.466 UTC][INFO] Successfully patched replicas for cluster 'cluster-1'! +[2021-02-26T19:04:14.466000Z][INFO] Successfully patched replicas for cluster 'cluster-1'! ``` ### Script to view the status of a WebLogic cluster @@ -123,42 +123,42 @@ The `rollDomain.sh` script updates the value of the `spec.restartVersion` attrib ``` $ rollDomain.sh -d domain1 -n weblogic-domain-1 -[2021-03-24T04:01:19.733 UTC][INFO] Patching restartVersion for domain 'domain1' to '1'. +[2021-03-24T04:01:19.733000Z][INFO] Patching restartVersion for domain 'domain1' to '1'. domain.weblogic.oracle/domain1 patched -[2021-03-24T04:01:19.850 UTC][INFO] Successfully patched restartVersion for domain 'domain1'! +[2021-03-24T04:01:19.850000Z][INFO] Successfully patched restartVersion for domain 'domain1'! ``` Use the following command to roll the Server Pods in a WebLogic domain with a specific `restartVersion`: ``` $ rollDomain.sh -r v1 -d domain1 -n weblogic-domain-1 -[2021-03-24T13:43:47.586 UTC][INFO] Patching restartVersion for domain 'domain1' to 'v1'. +[2021-03-24T13:43:47.586000Z][INFO] Patching restartVersion for domain 'domain1' to 'v1'. domain.weblogic.oracle/domain1 patched -[2021-03-24T13:43:47.708 UTC][INFO] Successfully patched restartVersion for domain 'domain1'! +[2021-03-24T13:43:47.708000Z][INFO] Successfully patched restartVersion for domain 'domain1'! ``` The `rollCluster.sh` script updates the value of the `spec.clusters[].restartVersion` attribute of the domain resource. Then, the operator will do a rolling restart of the WebLogic cluster Server Pods after the value of the `spec.clusters[].restartVersion` is updated. You can provide the new value of the `restartVersion` as a parameter to the script or the script will automatically generate a new value to trigger the rolling restart. See the script `usage` information by using the `-h` option. ``` $ rollCluster.sh -c cluster-1 -d domain1 -n weblogic-domain-1 -[2021-03-24T04:03:27.521 UTC][INFO] Patching restartVersion for cluster 'cluster-1' to '2'. +[2021-03-24T04:03:27.521000Z][INFO] Patching restartVersion for cluster 'cluster-1' to '2'. domain.weblogic.oracle/domain1 patched -[2021-03-24T04:03:27.669 UTC][INFO] Successfully patched restartVersion for cluster 'cluster-1'! +[2021-03-24T04:03:27.669000Z][INFO] Successfully patched restartVersion for cluster 'cluster-1'! ``` Use the following command to roll the WebLogic Cluster Servers with a specific `restartVersion`: ``` $ rollCluster.sh -r v2 -c cluster-1 -d domain1 -n weblogic-domain-1 -[2021-03-24T13:46:16.833 UTC][INFO] Patching restartVersion for cluster 'cluster-1' to 'v2'. +[2021-03-24T13:46:16.833000Z][INFO] Patching restartVersion for cluster 'cluster-1' to 'v2'. domain.weblogic.oracle/domain1 patched -[2021-03-24T13:46:16.975 UTC][INFO] Successfully patched restartVersion for cluster 'cluster-1'! +[2021-03-24T13:46:16.975000Z][INFO] Successfully patched restartVersion for cluster 'cluster-1'! ``` ### Scripts to restart a WebLogic Server in a domain The `restartServer.sh` script can be used to restart a WebLogic Server in a domain. This script restarts the Server by deleting the Server Pod for the WebLogic Server instance. ``` $ restartServer.sh -s managed-server1 -d domain1 -n weblogic-domain-1 -[2021-03-24T22:20:22.498 UTC][INFO] Initiating restart of 'managed-server1' by deleting server pod 'domain1-managed-server1'. -[2021-03-24T22:20:37.614 UTC][INFO] Server restart succeeded ! +[2021-03-24T22:20:22.498000Z][INFO] Initiating restart of 'managed-server1' by deleting server pod 'domain1-managed-server1'. +[2021-03-24T22:20:37.614000Z][INFO] Server restart succeeded ! ``` ### Scripts to explicitly initiate introspection of a WebLogic domain @@ -168,17 +168,17 @@ The `introspectDomain.sh` script can be used to rerun a WebLogic domain's intros Use the following command to rerun a domain's introspect job with the `introspectVersion` value generated by the script. ``` $ introspectDomain.sh -d domain1 -n weblogic-domain-1 -[2021-03-24T21:37:55.989 UTC][INFO] Patching introspectVersion for domain 'domain1' to '1'. +[2021-03-24T21:37:55.989000Z][INFO] Patching introspectVersion for domain 'domain1' to '1'. domain.weblogic.oracle/domain1 patched -[2021-03-24T21:37:56.110 UTC][INFO] Successfully patched introspectVersion for domain 'domain1'! +[2021-03-24T21:37:56.110000Z][INFO] Successfully patched introspectVersion for domain 'domain1'! ``` Use the following command to rerun a domain's introspect job with a specific `introspectVersion` value. ``` $ introspectDomain.sh -i v1 -d domain1 -n weblogic-domain-1 -[2021-03-24T21:38:34.369 UTC][INFO] Patching introspectVersion for domain 'domain1' to 'v1'. +[2021-03-24T21:38:34.369000Z][INFO] Patching introspectVersion for domain 'domain1' to 'v1'. domain.weblogic.oracle/domain1 patched -[2021-03-24T21:38:34.488 UTC][INFO] Successfully patched introspectVersion for domain 'domain1'! +[2021-03-24T21:38:34.488000Z][INFO] Successfully patched introspectVersion for domain 'domain1'! ``` ### Watching the Pods after executing life cycle scripts diff --git a/kubernetes/samples/scripts/domain-lifecycle/helper.sh b/kubernetes/samples/scripts/domain-lifecycle/helper.sh index 4216dcd5b41..efb277e63a8 100644 --- a/kubernetes/samples/scripts/domain-lifecycle/helper.sh +++ b/kubernetes/samples/scripts/domain-lifecycle/helper.sh @@ -1006,19 +1006,15 @@ function executePatchCommand { } # timestamp -# purpose: echo timestamp in the form yyyymmddThh:mm:ss.mmm ZZZ -# example: 20181001T14:00:00.001 UTC +# purpose: echo timestamp in the form yyyy-mm-ddThh:mm:ss.nnnnnnZ +# example: 2018-10-01T14:00:00.000001Z function timestamp() { - timestamp="$(set +e && date --utc '+%Y-%m-%dT%H:%M:%S %N %s %Z' 2>&1 || echo illegal)" + local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S.%NZ' 2>&1`" if [ ! "${timestamp/illegal/xyz}" = "${timestamp}" ]; then # old shell versions don't support %N or --utc - timestamp="`date -u '+%Y-%m-%dT%H:%M:%S 000000 %s %Z' 2>&1`" + timestamp="`date -u '+%Y-%m-%dT%H:%M:%S.000000Z' 2>&1`" fi - local ymdhms="`echo $timestamp | awk '{ print $1 }'`" - # convert nano to milli - local milli="`echo $timestamp | awk '{ print $2 }' | sed 's/\(^...\).*/\1/'`" - local timezone="`echo $timestamp | awk '{ print $4 }'`" - echo "${ymdhms}.${milli} ${timezone}" + echo "${timestamp}" } # diff --git a/operator/scripts/scaling/scalingAction.sh b/operator/scripts/scaling/scalingAction.sh index e0a162a10f5..9cc1ddcf0ec 100755 --- a/operator/scripts/scaling/scalingAction.sh +++ b/operator/scripts/scaling/scalingAction.sh @@ -17,19 +17,15 @@ kubernetes_master="https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT} log_file_name="scalingAction.log" # timestamp -# purpose: echo timestamp in the form yyyymmddThh:mm:ss.mmm ZZZ -# example: 20181001T14:00:00.001 UTC +# purpose: echo timestamp in the form yyyy-mm-ddThh:mm:ss.nnnnnnZ +# example: 2018-10-01T14:00:00.000001Z function timestamp() { - local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S %N %s %Z' 2>&1`" + local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S.%NZ' 2>&1`" if [ ! "${timestamp/illegal/xyz}" = "${timestamp}" ]; then # old shell versions don't support %N or --utc - timestamp="`date -u '+%Y-%m-%dT%H:%M:%S 000000 %s %Z' 2>&1`" + timestamp="`date -u '+%Y-%m-%dT%H:%M:%S.000000Z' 2>&1`" fi - local ymdhms="`echo $timestamp | awk '{ print $1 }'`" - # convert nano to milli - local milli="`echo $timestamp | awk '{ print $2 }' | sed 's/\(^...\).*/\1/'`" - local timezone="`echo $timestamp | awk '{ print $4 }'`" - echo "${ymdhms}.${milli} ${timezone}" + echo "${timestamp}" } function trace() { diff --git a/operator/src/main/java/oracle/kubernetes/operator/logging/LoggingFormatter.java b/operator/src/main/java/oracle/kubernetes/operator/logging/LoggingFormatter.java index 4da357eef12..8d1d1d35a39 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/logging/LoggingFormatter.java +++ b/operator/src/main/java/oracle/kubernetes/operator/logging/LoggingFormatter.java @@ -5,8 +5,9 @@ import java.io.PrintWriter; import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -39,14 +40,13 @@ public class LoggingFormatter extends Formatter { private static final String TIME_IN_MILLIS = "timeInMillis"; private static final String MESSAGE = "message"; private static final String EXCEPTION = "exception"; - private static final String DATE_FORMAT = "MM-dd-yyyy'T'HH:mm:ss.SSSZZ"; // For ApiException private static final String RESPONSE_CODE = "code"; private static final String RESPONSE_HEADERS = "headers"; private static final String RESPONSE_BODY = "body"; - private final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); + private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME; @Override public String format(LogRecord record) { @@ -107,7 +107,7 @@ public String format(LogRecord record) { String level = record.getLevel().getLocalizedName(); Map map = new LinkedHashMap<>(); long rawTime = record.getMillis(); - final String dateString = dateFormat.format(new Date(rawTime)); + final String dateString = DATE_FORMAT.format(OffsetDateTime.ofInstant(record.getInstant(), ZoneId.systemDefault())); long thread = Thread.currentThread().getId(); Fiber fiber = Fiber.getCurrentIfSet(); diff --git a/operator/src/main/java/oracle/kubernetes/operator/rest/BaseDebugLoggingFilter.java b/operator/src/main/java/oracle/kubernetes/operator/rest/BaseDebugLoggingFilter.java index d7723ce435e..c906865ce86 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/rest/BaseDebugLoggingFilter.java +++ b/operator/src/main/java/oracle/kubernetes/operator/rest/BaseDebugLoggingFilter.java @@ -3,9 +3,9 @@ package oracle.kubernetes.operator.rest; -import java.text.SimpleDateFormat; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; import java.util.ArrayList; -import java.util.Date; import java.util.List; import jakarta.ws.rs.container.ContainerRequestContext; @@ -24,12 +24,10 @@ public abstract class BaseDebugLoggingFilter { protected static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator"); protected static final String FILTER_REQUEST_START_TIME = "FILTER_REQUEST_START_TIME"; protected static final String FILTER_REQUEST_ENTITY = "FILTER_REQUEST_ENTITY"; - private static final String DATE_FORMAT = - "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; // ISO 8610, includes time zone + private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ISO_OFFSET_DATE_TIME; - protected static String formatTime(long time) { - // construct a new SimpleDataFormat each time since it is not thread safe: - return new SimpleDateFormat(DATE_FORMAT).format(new Date(time)); + protected static String formatTime(TemporalAccessor time) { + return DATE_FORMAT.format(time); } protected String formatEntity(MediaType type, String entityAsString) { diff --git a/operator/src/main/java/oracle/kubernetes/operator/rest/RequestDebugLoggingFilter.java b/operator/src/main/java/oracle/kubernetes/operator/rest/RequestDebugLoggingFilter.java index 0e53ed42886..b66939787a9 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/rest/RequestDebugLoggingFilter.java +++ b/operator/src/main/java/oracle/kubernetes/operator/rest/RequestDebugLoggingFilter.java @@ -7,6 +7,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; +import java.time.OffsetDateTime; import javax.annotation.Priority; import jakarta.ws.rs.container.ContainerRequestContext; @@ -38,7 +39,7 @@ public void filter(ContainerRequestContext req) { try { // cache the start time and request body so that the response filter // can log them too - long start = System.currentTimeMillis(); + OffsetDateTime start = OffsetDateTime.now(); req.setProperty(FILTER_REQUEST_START_TIME, start); Object reqEntity = getRequestEntity(req); if (reqEntity != null) { diff --git a/operator/src/main/java/oracle/kubernetes/operator/rest/ResponseDebugLoggingFilter.java b/operator/src/main/java/oracle/kubernetes/operator/rest/ResponseDebugLoggingFilter.java index a8ce88a654d..69d5cc8859c 100644 --- a/operator/src/main/java/oracle/kubernetes/operator/rest/ResponseDebugLoggingFilter.java +++ b/operator/src/main/java/oracle/kubernetes/operator/rest/ResponseDebugLoggingFilter.java @@ -4,6 +4,8 @@ package oracle.kubernetes.operator.rest; import java.io.InputStream; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; import javax.annotation.Priority; import jakarta.ws.rs.container.ContainerRequestContext; @@ -38,9 +40,9 @@ public void filter(ContainerRequestContext req, ContainerResponseContext res) { LOGGER.fine("method=" + req.getMethod()); Object prop = req.getProperty(FILTER_REQUEST_START_TIME); if (prop != null) { - long start = (Long) prop; - long end = System.currentTimeMillis(); - long duration = end - start; + OffsetDateTime start = (OffsetDateTime) prop; + OffsetDateTime end = OffsetDateTime.now(); + long duration = start.until(end, ChronoUnit.MILLIS); LOGGER.fine("start=" + formatTime(start)); LOGGER.fine("duration=" + duration + " ms"); } diff --git a/operator/src/main/resources/scripts/utils.py b/operator/src/main/resources/scripts/utils.py index e92be31ab48..d6810b4a15d 100644 --- a/operator/src/main/resources/scripts/utils.py +++ b/operator/src/main/resources/scripts/utils.py @@ -8,9 +8,9 @@ # 'ERROR' is converted to 'SEVERE' # Unknown logLevels are converted to 'FINE'. # -# This matches format of bash utils.sh trace, and rougly matches the operator's log format. +# This matches format of bash utils.sh trace and the operator's log format. # -# Sample output: @[2018-09-28T17:23:55.335 UTC][introspectDomain.py:614][FINE] Domain introspection complete. +# Sample output: @[2018-09-28T17:23:55.335000Z][introspectDomain.py:614][FINE] Domain introspection complete. # # Importing this file when it's not in sys.path of the calling script: # @@ -52,8 +52,8 @@ def traceInner(logLevel,object): } # use FINE as logLevel if logLevel is not a known type logLevel=switcher.get(logLevel.upper(),'FINE') - print("@[%d-%.2d-%.2dT%.2d:%.2d:%.2d.%.3d UTC][%s:%s][%s] %s" - % (dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,dt.microsecond/1000, + print("@[%d-%.2d-%.2dT%.2d:%.2d:%.2d.%.6dZ][%s:%s][%s] %s" + % (dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second,dt.microsecond, filename,lineno,logLevel,object)) def trace(arg1,arg2='SENTINEL'): diff --git a/operator/src/main/resources/scripts/utils_base.sh b/operator/src/main/resources/scripts/utils_base.sh index 3586b727ea1..7247be9b007 100644 --- a/operator/src/main/resources/scripts/utils_base.sh +++ b/operator/src/main/resources/scripts/utils_base.sh @@ -33,17 +33,17 @@ # # examples: # trace "Situation normal." -# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] Situation normal. +# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] Situation normal. # # trace INFO "Situation normal." -# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][INFO] Situation normal. +# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][INFO] Situation normal. # # trace "Info: Situation normal." -# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][INFO] Info: Situation normal. +# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][INFO] Info: Situation normal. # # ls 2>&1 | tracePipe FINE "ls output: " -# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] ls output: file1 -# @[2018-09-28T18:10:52.417 UTC][myscript.sh:91][FINE] ls output: file2 +# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] ls output: file1 +# @[2018-09-28T18:10:52.417000Z][myscript.sh:91][FINE] ls output: file2 # # Set TRACE_INCLUDE_FILE env var to false to suppress file name and line number. # @@ -167,21 +167,15 @@ function traceDirs() { } # timestamp -# purpose: echo timestamp in the form yyyymmddThh:mm:ss.mmm ZZZ -# example: 20181001T14:00:00.001 UTC +# purpose: echo timestamp in the form yyyy-mm-ddThh:mm:ss.nnnnnnZ +# example: 2018-10-01T14:00:00.000001Z function timestamp() { - local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S %N %s %Z' 2>&1`" + local timestamp="`date --utc '+%Y-%m-%dT%H:%M:%S.%NZ' 2>&1`" if [ ! "${timestamp/illegal/xyz}" = "${timestamp}" ]; then # old shell versions don't support %N or --utc - timestamp="`date -u '+%Y-%m-%dT%H:%M:%S 000000 %s %Z' 2>&1`" + timestamp="`date -u '+%Y-%m-%dT%H:%M:%S.000000Z' 2>&1`" fi - local ymdhms="`echo $timestamp | awk '{ print $1 }'`" - # convert nano to milli - local milli="`echo $timestamp | awk '{ print $2 }' | sed 's/\(^...\).*/\1/'`" - local secs_since_epoch="`echo $timestamp | awk '{ print $3 }'`" - local millis_since_opoch="${secs_since_epoch}${milli}" - local timezone="`echo $timestamp | awk '{ print $4 }'`" - echo "${ymdhms}.${milli} ${timezone}" + echo "${timestamp}" } # @@ -193,9 +187,9 @@ function timestamp() { # (Pass '-q' to suppress FINE tracing.) # # sample: checkEnv HOST NOTSET1 USER NOTSET2 -# @[2018-10-05T22:48:04.368 UTC][FINE] HOST='esscupcakes' -# @[2018-10-05T22:48:04.393 UTC][FINE] USER='friendly' -# @[2018-10-05T22:48:04.415 UTC][SEVERE] The following env vars are missing or empty: NOTSET1 NOTSET2 +# @[2018-10-05T22:48:04.368000Z][FINE] HOST='esscupcakes' +# @[2018-10-05T22:48:04.393000Z][FINE] USER='friendly' +# @[2018-10-05T22:48:04.415000Z][SEVERE] The following env vars are missing or empty: NOTSET1 NOTSET2 # function checkEnv() { local do_fine="true" diff --git a/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java b/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java index 0f49324422d..e9c528c5a5e 100644 --- a/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java +++ b/operator/src/test/java/oracle/kubernetes/operator/DomainProcessorTest.java @@ -1045,7 +1045,7 @@ private void getMIIOnlineUpdateIntrospectResult(DomainConditionType domainCondit + "\n" + ">>> EOF\n" + "\n" - + "@[2018-10-04T21:07:06.864 UTC][introspectDomain.py:105] Printing file " + + "@[2018-10-04T21:07:06.864000Z][introspectDomain.py:105] Printing file " + "/u01/introspect/domain1/userKeyNodeManager.secure\n" + "\n" + ">>> /u01/introspect/domain1/userKeyNodeManager.secure\n" @@ -1058,7 +1058,7 @@ private void getMIIOnlineUpdateIntrospectResult(DomainConditionType domainCondit + "\n" + ">>> EOF\n" + "\n" - + "@[2018-10-04T21:07:06.867 UTC][introspectDomain.py:105] Printing file " + + "@[2018-10-04T21:07:06.867000Z][introspectDomain.py:105] Printing file " + "/u01/introspect/domain1/topology.yaml\n" + "\n" + ">>> /u01/introspect/domain1/topology.yaml\n" diff --git a/operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectionTestUtils.java b/operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectionTestUtils.java index 0a1998c89d9..9f574889726 100644 --- a/operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectionTestUtils.java +++ b/operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectionTestUtils.java @@ -32,7 +32,7 @@ public class IntrospectionTestUtils { + "\n" + ">>> EOF\n" + "\n" - + "@[2018-10-04T21:07:06.864 UTC][introspectDomain.py:105] Printing file " + + "@[2018-10-04T21:07:06.864000Z][introspectDomain.py:105] Printing file " + "/u01/introspect/domain1/userKeyNodeManager.secure\n" + "\n" + ">>> /u01/introspect/domain1/userKeyNodeManager.secure\n" @@ -40,7 +40,7 @@ public class IntrospectionTestUtils { + "\n" + ">>> EOF\n" + "\n" - + "@[2018-10-04T21:07:06.867 UTC][introspectDomain.py:105] Printing file " + + "@[2018-10-04T21:07:06.867000Z][introspectDomain.py:105] Printing file " + "/u01/introspect/domain1/topology.yaml\n" + "\n" + ">>> /u01/introspect/domain1/topology.yaml\n"