Skip to content

Commit fedcece

Browse files
committed
Review comments and minor cleanup.
1 parent f07b126 commit fedcece

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public interface ProcessingConstants {
2727

2828
String DOMAIN_TOPOLOGY = "domainTopology";
2929
String JOB_POD_NAME = "jobPodName";
30-
String JOB_IMAGE_NAME = "jobImageName";
3130
String DOMAIN_INTROSPECTOR_JOB = "domainIntrospectorJob";
3231
String DOMAIN_INTROSPECTOR_LOG_RESULT = "domainIntrospectorLogResult";
3332
String DOMAIN_INTROSPECT_REQUESTED = "domainIntrospectRequested";

operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.BufferedReader;
77
import java.io.IOException;
88
import java.io.StringReader;
9+
import java.time.OffsetDateTime;
910
import java.util.ArrayList;
1011
import java.util.Collection;
1112
import java.util.Collections;
@@ -49,6 +50,7 @@
4950
import org.yaml.snakeyaml.Yaml;
5051

5152
import static java.lang.System.lineSeparator;
53+
import static java.time.temporal.ChronoUnit.MILLIS;
5254
import static oracle.kubernetes.operator.DomainStatusUpdater.BAD_TOPOLOGY;
5355
import static oracle.kubernetes.operator.IntrospectorConfigMapConstants.DOMAINZIP_HASH;
5456
import static oracle.kubernetes.operator.IntrospectorConfigMapConstants.DOMAIN_INPUTS_HASH;
@@ -508,7 +510,7 @@ public NextAction apply(Packet packet) {
508510
}
509511

510512
private long timeSinceJobStart(Packet packet) {
511-
return System.currentTimeMillis() - ((Long) packet.get(JobHelper.START_TIME));
513+
return ((OffsetDateTime)packet.get(JobHelper.START_TIME)).until(OffsetDateTime.now(), MILLIS);
512514
}
513515
}
514516

operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package oracle.kubernetes.operator.helpers;
55

6+
import java.time.OffsetDateTime;
67
import java.util.ArrayList;
78
import java.util.Collections;
89
import java.util.List;
@@ -50,6 +51,7 @@
5051
import oracle.kubernetes.weblogic.domain.model.ManagedServer;
5152
import oracle.kubernetes.weblogic.domain.model.ServerEnvVars;
5253

54+
import static java.time.temporal.ChronoUnit.SECONDS;
5355
import static oracle.kubernetes.operator.DomainSourceType.FromModel;
5456
import static oracle.kubernetes.operator.DomainStatusUpdater.INSPECTING_DOMAIN_PROGRESS_REASON;
5557
import static oracle.kubernetes.operator.DomainStatusUpdater.createProgressingStartedEventStep;
@@ -96,7 +98,7 @@ private static boolean runIntrospector(Packet packet, DomainPresenceInfo info) {
9698
LOGGER.fine("isModelInImageUpdate: " + isModelInImageUpdate(packet, info));
9799
return topology == null
98100
|| isBringingUpNewDomain(packet, info)
99-
|| introspectionRequested(packet)
101+
|| isIntrospectionRequestedAndRemove(packet)
100102
|| isModelInImageUpdate(packet, info)
101103
|| isIntrospectVersionChanged(packet, info);
102104
}
@@ -105,7 +107,7 @@ private static boolean isBringingUpNewDomain(Packet packet, DomainPresenceInfo i
105107
return runningServersCount(info) == 0 && creatingServers(info) && isGenerationChanged(packet, info);
106108
}
107109

108-
private static boolean introspectionRequested(Packet packet) {
110+
private static boolean isIntrospectionRequestedAndRemove(Packet packet) {
109111
return packet.remove(ProcessingConstants.DOMAIN_INTROSPECT_REQUESTED) != null;
110112
}
111113

@@ -399,7 +401,7 @@ public NextAction apply(Packet packet) {
399401
if (runIntrospector(packet, info)) {
400402
JobStepContext context = new DomainIntrospectorJobStepContext(packet);
401403

402-
packet.putIfAbsent(START_TIME, System.currentTimeMillis());
404+
packet.putIfAbsent(START_TIME, OffsetDateTime.now());
403405

404406
return doNext(
405407
Step.chain(
@@ -455,7 +457,7 @@ public NextAction onSuccess(Packet packet, CallResponse callResponse) {
455457

456458
if (job != null) {
457459
packet.putIfAbsent(START_TIME, Optional.ofNullable(job.getMetadata())
458-
.map(m -> m.getCreationTimestamp()).map(t -> t.toInstant().toEpochMilli()).orElse(0L));
460+
.map(m -> m.getCreationTimestamp()).orElse(OffsetDateTime.now()));
459461
return doNext(Step.chain(
460462
createProgressingStartedEventStep(info, INSPECTING_DOMAIN_PROGRESS_REASON, true, null),
461463
readDomainIntrospectorPodLogStep(null),
@@ -465,7 +467,7 @@ public NextAction onSuccess(Packet packet, CallResponse callResponse) {
465467
new DomainProcessorImpl.IntrospectionRequestStep(info),
466468
createDomainIntrospectorJobStep(getNext())), packet);
467469
} else {
468-
packet.putIfAbsent(START_TIME, System.currentTimeMillis());
470+
packet.putIfAbsent(START_TIME, OffsetDateTime.now());
469471
return doNext(Step.chain(
470472
ConfigMapHelper.readExistingIntrospectorConfigMap(namespace, info.getDomainUid()),
471473
createDomainIntrospectorJobStep(getNext())), packet);
@@ -543,7 +545,10 @@ public NextAction onSuccess(Packet packet, CallResponse<String> callResponse) {
543545
}
544546
//Introspector job is incomplete, update domain status and terminate processing
545547
Step nextStep = null;
546-
if (System.currentTimeMillis() > getJobLazyDeletionTime(domainIntrospectorJob)) {
548+
int retryIntervalSeconds = TuningParameters.getInstance().getMainTuning().domainPresenceRecheckIntervalSeconds;
549+
550+
if (OffsetDateTime.now().isAfter(
551+
getJobCreationTime(domainIntrospectorJob).plus(retryIntervalSeconds, SECONDS))) {
547552
//Introspector job is incomplete and current time is greater than the lazy deletion time for the job,
548553
//update the domain status and execute the next step
549554
nextStep = getNext();
@@ -560,11 +565,9 @@ public NextAction onSuccess(Packet packet, CallResponse<String> callResponse) {
560565
return doNext(packet);
561566
}
562567

563-
private Long getJobLazyDeletionTime(V1Job domainIntrospectorJob) {
564-
int retryIntervalSeconds = TuningParameters.getInstance().getMainTuning().domainPresenceRecheckIntervalSeconds;
568+
private OffsetDateTime getJobCreationTime(V1Job domainIntrospectorJob) {
565569
return Optional.ofNullable(domainIntrospectorJob.getMetadata())
566-
.map(m -> m.getCreationTimestamp()).map(t -> t.toInstant().toEpochMilli()).orElse(0L)
567-
+ (retryIntervalSeconds * 1000L);
570+
.map(m -> m.getCreationTimestamp()).orElse(OffsetDateTime.now());
568571
}
569572

570573
private boolean isNotComplete(V1Job domainIntrospectorJob) {

operator/src/test/java/oracle/kubernetes/operator/helpers/IntrospectorConfigMapTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
package oracle.kubernetes.operator.helpers;
55

6+
import java.time.Instant;
7+
import java.time.OffsetDateTime;
8+
import java.time.ZoneId;
69
import java.util.ArrayList;
710
import java.util.Arrays;
811
import java.util.Collections;
@@ -91,7 +94,8 @@ public void setUp() throws Exception {
9194

9295
testSupport.defineResources(domain);
9396
testSupport.addDomainPresenceInfo(info);
94-
testSupport.addToPacket(JobHelper.START_TIME, System.currentTimeMillis() - 10);
97+
testSupport.addToPacket(JobHelper.START_TIME,
98+
OffsetDateTime.ofInstant(Instant.now().minusMillis(10L), ZoneId.systemDefault()));
9599
}
96100

97101
@AfterEach

0 commit comments

Comments
 (0)