Skip to content

Commit 546b4a1

Browse files
authored
Merge pull request #643 from oracle/target-namespace2
Check for recently added target namespaces more freequently
2 parents 66cddd5 + 2680053 commit 546b4a1

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.concurrent.ThreadFactory;
3030
import java.util.concurrent.TimeUnit;
3131
import java.util.concurrent.atomic.AtomicBoolean;
32+
import java.util.concurrent.atomic.AtomicReference;
3233
import oracle.kubernetes.operator.calls.CallResponse;
3334
import oracle.kubernetes.operator.helpers.CRDHelper;
3435
import oracle.kubernetes.operator.helpers.CallBuilder;
@@ -57,6 +58,7 @@
5758
import oracle.kubernetes.operator.work.ThreadFactorySingleton;
5859
import oracle.kubernetes.weblogic.domain.v2.Domain;
5960
import oracle.kubernetes.weblogic.domain.v2.DomainList;
61+
import org.joda.time.DateTime;
6062

6163
/** A Kubernetes Operator for WebLogic. */
6264
public class Main {
@@ -126,6 +128,8 @@ public Thread newThread(Runnable r) {
126128
static final Map<String, PodWatcher> podWatchers = new ConcurrentHashMap<>();
127129

128130
private static final String operatorNamespace = getOperatorNamespace();
131+
private static final AtomicReference<DateTime> lastFullRecheck =
132+
new AtomicReference<>(DateTime.now());
129133

130134
private static String principal;
131135
private static RestServer restServer = null;
@@ -215,7 +219,7 @@ private static void completeBegin() {
215219
startRestServer(principal, isNamespaceStopping.keySet());
216220

217221
// start periodic retry and recheck
218-
int recheckInterval = tuningAndConfig.getMainTuning().domainPresenceRecheckIntervalSeconds;
222+
int recheckInterval = tuningAndConfig.getMainTuning().targetNamespaceRecheckIntervalSeconds;
219223
engine
220224
.getExecutor()
221225
.scheduleWithFixedDelay(
@@ -335,7 +339,17 @@ private static Runnable recheckDomains() {
335339
namespacesToStop.removeAll(targetNamespaces);
336340
stopNamespaces(namespacesToStop);
337341

338-
runSteps(new StartNamespacesStep(targetNamespaces));
342+
Collection<String> namespacesToStart = targetNamespaces;
343+
int recheckInterval = tuningAndConfig.getMainTuning().domainPresenceRecheckIntervalSeconds;
344+
DateTime now = DateTime.now();
345+
if (lastFullRecheck.get().plusSeconds(recheckInterval).isBefore(now)) {
346+
lastFullRecheck.set(now);
347+
} else {
348+
namespacesToStart = new TreeSet<>(targetNamespaces);
349+
namespacesToStart.removeAll(isNamespaceStarted.keySet());
350+
}
351+
352+
if (!namespacesToStart.isEmpty()) runSteps(new StartNamespacesStep(namespacesToStart));
339353
};
340354
}
341355

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static TuningParameters getInstance() {
2222
public static class MainTuning {
2323
public final int domainPresenceFailureRetrySeconds;
2424
public final int domainPresenceRecheckIntervalSeconds;
25+
public final int targetNamespaceRecheckIntervalSeconds;
2526
public final int statusUpdateTimeoutSeconds;
2627
public final int unchangedCountToDelayStatusRecheck;
2728
public final long initialShortDelay;
@@ -30,12 +31,14 @@ public static class MainTuning {
3031
public MainTuning(
3132
int domainPresenceFailureRetrySeconds,
3233
int domainPresenceRecheckIntervalSeconds,
34+
int targetNamespaceRecheckIntervalSeconds,
3335
int statusUpdateTimeoutSeconds,
3436
int unchangedCountToDelayStatusRecheck,
3537
long initialShortDelay,
3638
long eventualLongDelay) {
3739
this.domainPresenceFailureRetrySeconds = domainPresenceFailureRetrySeconds;
3840
this.domainPresenceRecheckIntervalSeconds = domainPresenceRecheckIntervalSeconds;
41+
this.targetNamespaceRecheckIntervalSeconds = targetNamespaceRecheckIntervalSeconds;
3942
this.statusUpdateTimeoutSeconds = statusUpdateTimeoutSeconds;
4043
this.unchangedCountToDelayStatusRecheck = unchangedCountToDelayStatusRecheck;
4144
this.initialShortDelay = initialShortDelay;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private void update() {
5353
new MainTuning(
5454
(int) readTuningParameter("domainPresenceFailureRetrySeconds", 10),
5555
(int) readTuningParameter("domainPresenceRecheckIntervalSeconds", 120),
56+
(int) readTuningParameter("targetNamespaceRecheckIntervalSeconds", 3),
5657
(int) readTuningParameter("statusUpdateTimeoutSeconds", 10),
5758
(int) readTuningParameter("statusUpdateUnchangedCountToDelayStatusRecheck", 10),
5859
readTuningParameter("statusUpdateInitialShortDelay", 3),

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44

55
package oracle.kubernetes.operator.helpers;
66

7-
import static java.nio.file.StandardWatchEventKinds.*;
8-
97
import java.io.File;
108
import java.io.IOException;
11-
import java.nio.file.FileSystems;
129
import java.nio.file.Files;
13-
import java.nio.file.WatchEvent;
14-
import java.nio.file.WatchKey;
15-
import java.nio.file.WatchService;
1610
import java.util.Collection;
1711
import java.util.HashSet;
18-
import java.util.List;
1912
import java.util.Map;
2013
import java.util.Set;
2114
import java.util.concurrent.ScheduledExecutorService;
@@ -35,7 +28,6 @@ public class ConfigMapConsumer implements Map<String, String> {
3528
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
3629

3730
private final File mountPointDir;
38-
private final WatchService watcher;
3931
private final ScheduledExecutorService threadPool;
4032
private final AtomicReference<ScheduledFuture<?>> future = new AtomicReference<>(null);
4133
private final Runnable onUpdate;
@@ -45,10 +37,8 @@ public ConfigMapConsumer(
4537
throws IOException {
4638
this.threadPool = executorService;
4739
this.mountPointDir = new File(mountPoint);
48-
this.watcher = FileSystems.getDefault().newWatchService();
4940
this.onUpdate = onUpdate;
5041
if (mountPointDir.exists()) {
51-
mountPointDir.toPath().register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
5242
schedule();
5343
}
5444
}
@@ -60,20 +50,7 @@ private void schedule() {
6050
future.getAndSet(
6151
threadPool.scheduleWithFixedDelay(
6252
() -> {
63-
// wait for key to be signaled
64-
WatchKey key;
65-
try {
66-
key = watcher.take();
67-
} catch (InterruptedException x) {
68-
return;
69-
}
70-
List<WatchEvent<?>> events = key.pollEvents();
71-
if (events != null && !events.isEmpty()) {
72-
onUpdate.run();
73-
schedule();
74-
return;
75-
}
76-
key.reset();
53+
onUpdate.run();
7754
},
7855
initialDelay,
7956
delay,

0 commit comments

Comments
 (0)