|
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 | 1 | package oracle.kubernetes.operator;
|
5 | 2 |
|
6 | 3 | import java.io.IOException;
|
| 4 | +import java.util.Map; |
7 | 5 | 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 | 6 |
|
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> { |
19 | 8 |
|
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 | + } |
25 | 13 |
|
26 | 14 | public static class MainTuning {
|
27 | 15 | public final int statusUpdateTimeoutSeconds;
|
@@ -78,95 +66,8 @@ public PodTuning(int readinessProbeInitialDelaySeconds, int readinessProbeTimeou
|
78 | 66 | }
|
79 | 67 | }
|
80 | 68 |
|
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(); |
172 | 73 | }
|
0 commit comments