Skip to content

Commit 5068198

Browse files
committed
Merge Pod unit testing changes
2 parents a26f757 + 61ae5e8 commit 5068198

File tree

6 files changed

+846
-257
lines changed

6 files changed

+846
-257
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public class Main {
115115
static {
116116
container.getComponents().put(
117117
ProcessingConstants.MAIN_COMPONENT_NAME,
118-
Component.createFor(tuningAndConfig, callBuilderFactory));
118+
Component.createFor(tuningAndConfig, TuningParameters.class, callBuilderFactory));
119119
}
120120

121121
private static final ConcurrentMap<String, Boolean> initialized = new ConcurrentHashMap<>();
Lines changed: 10 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2-
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3-
41
package oracle.kubernetes.operator;
52

63
import java.io.IOException;
4+
import java.util.Map;
75
import java.util.concurrent.ThreadFactory;
8-
import java.util.concurrent.locks.ReadWriteLock;
9-
import java.util.concurrent.locks.ReentrantReadWriteLock;
10-
11-
import oracle.kubernetes.operator.helpers.ConfigMapConsumer;
12-
import oracle.kubernetes.operator.logging.LoggingFacade;
13-
import oracle.kubernetes.operator.logging.LoggingFactory;
14-
import oracle.kubernetes.operator.logging.MessageKeys;
156

16-
public class TuningParameters extends ConfigMapConsumer {
17-
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
18-
private static TuningParameters INSTANCE = null;
7+
public interface TuningParameters extends Map<String, String> {
198

20-
private final ReadWriteLock lock = new ReentrantReadWriteLock();
21-
private MainTuning main = null;
22-
private CallBuilderTuning callBuilder = null;
23-
private WatchTuning watch = null;
24-
private PodTuning pod = null;
9+
public static TuningParameters initializeInstance(
10+
ThreadFactory factory, String mountPoint) throws IOException {
11+
return TuningParametersImpl.initializeInstance(factory, mountPoint);
12+
}
2513

2614
public static class MainTuning {
2715
public final int statusUpdateTimeoutSeconds;
@@ -78,95 +66,8 @@ public PodTuning(int readinessProbeInitialDelaySeconds, int readinessProbeTimeou
7866
}
7967
}
8068

81-
public synchronized static TuningParameters initializeInstance(
82-
ThreadFactory factory, String mountPoint) throws IOException {
83-
if (INSTANCE == null) {
84-
INSTANCE = new TuningParameters(factory, mountPoint);
85-
return INSTANCE;
86-
}
87-
throw new IllegalStateException();
88-
}
89-
90-
private TuningParameters(ThreadFactory factory, String mountPoint) throws IOException {
91-
super(factory, mountPoint, () -> {
92-
updateTuningParameters();
93-
});
94-
update();
95-
}
96-
97-
public static void updateTuningParameters() {
98-
INSTANCE.update();
99-
}
100-
101-
private void update() {
102-
LOGGER.info(MessageKeys.TUNING_PARAMETERS);
103-
104-
MainTuning main = new MainTuning(
105-
(int) readTuningParameter("statusUpdateTimeoutSeconds", 10),
106-
(int) readTuningParameter("statueUpdateUnchangedCountToDelayStatusRecheck", 10),
107-
readTuningParameter("statusUpdateInitialShortDelay", 3),
108-
readTuningParameter("statusUpdateEventualLongDelay", 30));
109-
110-
CallBuilderTuning callBuilder = new CallBuilderTuning(
111-
(int) readTuningParameter("callRequestLimit", 500),
112-
(int) readTuningParameter("callMaxRetryCount", 5),
113-
(int) readTuningParameter("callTimeoutSeconds", 10));
114-
115-
WatchTuning watch = new WatchTuning(
116-
(int) readTuningParameter("watchLifetime", 45));
117-
118-
PodTuning pod = new PodTuning(
119-
(int) readTuningParameter("readinessProbeInitialDelaySeconds", 2),
120-
(int) readTuningParameter("readinessProbeTimeoutSeconds", 5),
121-
(int) readTuningParameter("readinessProbeTimeoutSeconds", 5),
122-
(int) readTuningParameter("livenessProbeInitialDelaySeconds", 10),
123-
(int) readTuningParameter("livenessProbeTimeoutSeconds", 5),
124-
(int) readTuningParameter("livenessProbePeriodSeconds", 10));
125-
126-
lock.writeLock().lock();
127-
try {
128-
this.main = main;
129-
this.callBuilder = callBuilder;
130-
this.watch = watch;
131-
this.pod = pod;
132-
} finally {
133-
lock.writeLock().unlock();
134-
}
135-
}
136-
137-
public MainTuning getMainTuning() {
138-
lock.readLock().lock();
139-
try {
140-
return main;
141-
} finally {
142-
lock.readLock().unlock();
143-
}
144-
}
145-
146-
public CallBuilderTuning getCallBuilderTuning() {
147-
lock.readLock().lock();
148-
try {
149-
return callBuilder;
150-
} finally {
151-
lock.readLock().unlock();
152-
}
153-
}
154-
155-
public WatchTuning getWatchTuning() {
156-
lock.readLock().lock();
157-
try {
158-
return watch;
159-
} finally {
160-
lock.readLock().unlock();
161-
}
162-
}
163-
164-
public PodTuning getPodTuning() {
165-
lock.readLock().lock();
166-
try {
167-
return pod;
168-
} finally {
169-
lock.readLock().unlock();
170-
}
171-
}
69+
public MainTuning getMainTuning();
70+
public CallBuilderTuning getCallBuilderTuning();
71+
public WatchTuning getWatchTuning();
72+
public PodTuning getPodTuning();
17273
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.operator;
5+
6+
import java.io.IOException;
7+
import java.util.concurrent.ThreadFactory;
8+
import java.util.concurrent.locks.ReadWriteLock;
9+
import java.util.concurrent.locks.ReentrantReadWriteLock;
10+
11+
import oracle.kubernetes.operator.helpers.ConfigMapConsumer;
12+
import oracle.kubernetes.operator.logging.LoggingFacade;
13+
import oracle.kubernetes.operator.logging.LoggingFactory;
14+
import oracle.kubernetes.operator.logging.MessageKeys;
15+
16+
public class TuningParametersImpl extends ConfigMapConsumer implements TuningParameters {
17+
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
18+
private static TuningParametersImpl INSTANCE = null;
19+
20+
private final ReadWriteLock lock = new ReentrantReadWriteLock();
21+
private MainTuning main = null;
22+
private CallBuilderTuning callBuilder = null;
23+
private WatchTuning watch = null;
24+
private PodTuning pod = null;
25+
26+
public synchronized static TuningParameters initializeInstance(
27+
ThreadFactory factory, String mountPoint) throws IOException {
28+
if (INSTANCE == null) {
29+
INSTANCE = new TuningParametersImpl(factory, mountPoint);
30+
return INSTANCE;
31+
}
32+
throw new IllegalStateException();
33+
}
34+
35+
private TuningParametersImpl(ThreadFactory factory, String mountPoint) throws IOException {
36+
super(factory, mountPoint, () -> {
37+
updateTuningParameters();
38+
});
39+
update();
40+
}
41+
42+
public static void updateTuningParameters() {
43+
INSTANCE.update();
44+
}
45+
46+
private void update() {
47+
LOGGER.info(MessageKeys.TUNING_PARAMETERS);
48+
49+
MainTuning main = new MainTuning(
50+
(int) readTuningParameter("statusUpdateTimeoutSeconds", 10),
51+
(int) readTuningParameter("statueUpdateUnchangedCountToDelayStatusRecheck", 10),
52+
readTuningParameter("statusUpdateInitialShortDelay", 3),
53+
readTuningParameter("statusUpdateEventualLongDelay", 30));
54+
55+
CallBuilderTuning callBuilder = new CallBuilderTuning(
56+
(int) readTuningParameter("callRequestLimit", 500),
57+
(int) readTuningParameter("callMaxRetryCount", 5),
58+
(int) readTuningParameter("callTimeoutSeconds", 10));
59+
60+
WatchTuning watch = new WatchTuning(
61+
(int) readTuningParameter("watchLifetime", 45));
62+
63+
PodTuning pod = new PodTuning(
64+
(int) readTuningParameter("readinessProbeInitialDelaySeconds", 2),
65+
(int) readTuningParameter("readinessProbeTimeoutSeconds", 5),
66+
(int) readTuningParameter("readinessProbePeriodSeconds", 5),
67+
(int) readTuningParameter("livenessProbeInitialDelaySeconds", 10),
68+
(int) readTuningParameter("livenessProbeTimeoutSeconds", 5),
69+
(int) readTuningParameter("livenessProbePeriodSeconds", 10));
70+
71+
lock.writeLock().lock();
72+
try {
73+
this.main = main;
74+
this.callBuilder = callBuilder;
75+
this.watch = watch;
76+
this.pod = pod;
77+
} finally {
78+
lock.writeLock().unlock();
79+
}
80+
}
81+
82+
@Override
83+
public MainTuning getMainTuning() {
84+
lock.readLock().lock();
85+
try {
86+
return main;
87+
} finally {
88+
lock.readLock().unlock();
89+
}
90+
}
91+
92+
@Override
93+
public CallBuilderTuning getCallBuilderTuning() {
94+
lock.readLock().lock();
95+
try {
96+
return callBuilder;
97+
} finally {
98+
lock.readLock().unlock();
99+
}
100+
}
101+
102+
@Override
103+
public WatchTuning getWatchTuning() {
104+
lock.readLock().lock();
105+
try {
106+
return watch;
107+
} finally {
108+
lock.readLock().unlock();
109+
}
110+
}
111+
112+
@Override
113+
public PodTuning getPodTuning() {
114+
lock.readLock().lock();
115+
try {
116+
return pod;
117+
} finally {
118+
lock.readLock().unlock();
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)