Skip to content

Commit 22668e7

Browse files
committed
remove direct access to the clusters array
1 parent 4754297 commit 22668e7

File tree

2 files changed

+24
-46
lines changed

2 files changed

+24
-46
lines changed

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

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import oracle.kubernetes.operator.wlsconfig.WlsServerConfig;
2222
import oracle.kubernetes.weblogic.domain.model.Domain;
2323
import oracle.kubernetes.weblogic.domain.model.ServerSpec;
24-
import org.joda.time.DateTime;
2524

2625
/**
2726
* Operator's mapping between custom resource Domain and runtime details about that domain,
@@ -39,8 +38,6 @@ public class DomainPresenceInfo {
3938
private final ConcurrentMap<String, ServerKubernetesObjects> servers = new ConcurrentHashMap<>();
4039
private final ConcurrentMap<String, V1Service> clusters = new ConcurrentHashMap<>();
4140

42-
private DateTime lastCompletionTime;
43-
4441
/**
4542
* Create presence for a domain.
4643
*
@@ -102,26 +99,26 @@ private V1Service getNewerCurrentOrNull(V1Service service, V1Service event) {
10299
}
103100

104101
void removeClusterService(String clusterName) {
105-
getClusters().remove(clusterName);
102+
clusters.remove(clusterName);
106103
}
107104

108105
V1Service getClusterService(String clusterName) {
109-
return getClusters().get(clusterName);
106+
return clusters.get(clusterName);
110107
}
111108

112109
void setClusterService(String clusterName, V1Service service) {
113-
getClusters().put(clusterName, service);
110+
clusters.put(clusterName, service);
114111
}
115112

116113
void setClusterServiceFromEvent(String clusterName, V1Service event) {
117114
if (clusterName == null) return;
118115

119-
getClusters().compute(clusterName, (k, s) -> getNewerService(s, event));
116+
clusters.compute(clusterName, (k, s) -> getNewerService(s, event));
120117
}
121118

122119
boolean deleteClusterServiceFromEvent(String clusterName, V1Service event) {
123120
return removeIfPresentAnd(
124-
getClusters(),
121+
clusters,
125122
clusterName,
126123
s -> !KubernetesUtils.isFirstNewer(getMetadata(s), getMetadata(event)));
127124
}
@@ -181,30 +178,20 @@ public void setPopulated(boolean populated) {
181178
isPopulated.set(populated);
182179
}
183180

184-
public void resetFailureCount() {
181+
private void resetFailureCount() {
185182
retryCount.set(0);
186183
}
187184

188185
public int incrementAndGetFailureCount() {
189186
return retryCount.incrementAndGet();
190187
}
191188

192-
public int getRetryCount() {
189+
int getRetryCount() {
193190
return retryCount.get();
194191
}
195192

196-
/**
197-
* Last completion time.
198-
*
199-
* @return Last completion time
200-
*/
201-
public DateTime getLastCompletionTime() {
202-
return lastCompletionTime;
203-
}
204-
205193
/** Sets the last completion time to now. */
206194
public void complete() {
207-
this.lastCompletionTime = new DateTime();
208195
resetFailureCount();
209196
}
210197

@@ -253,15 +240,6 @@ public ConcurrentMap<String, ServerKubernetesObjects> getServers() {
253240
return servers;
254241
}
255242

256-
/**
257-
* Map from cluster name to Service objects.
258-
*
259-
* @return Cluster object map
260-
*/
261-
public ConcurrentMap<String, V1Service> getClusters() {
262-
return clusters;
263-
}
264-
265243
/**
266244
* Server startup info.
267245
*

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,31 @@ public void onAddEventWithNoRecordedClusterService_addIt() {
130130

131131
processor.dispatchServiceWatch(event);
132132

133-
assertThat(info.getClusters().get(CLUSTER), sameInstance(newService));
133+
assertThat(info.getClusterService(CLUSTER), sameInstance(newService));
134134
}
135135

136136
@Test
137137
public void onAddEventWithNewerClusterService_replaceCurrentValue() {
138138
V1Service currentService = createClusterService();
139139
V1Service newerService = createClusterService();
140-
info.getClusters().put(CLUSTER, currentService);
140+
info.setClusterService(CLUSTER, currentService);
141141
Watch.Response<V1Service> event = WatchEvent.createAddedEvent(newerService).toWatchResponse();
142142

143143
processor.dispatchServiceWatch(event);
144144

145-
assertThat(info.getClusters().get(CLUSTER), sameInstance(newerService));
145+
assertThat(info.getClusterService(CLUSTER), sameInstance(newerService));
146146
}
147147

148148
@Test
149149
public void onAddEventWithOlderClusterService_keepCurrentValue() {
150150
V1Service olderService = createClusterService();
151151
V1Service currentService = createClusterService();
152-
info.getClusters().put(CLUSTER, currentService);
152+
info.setClusterService(CLUSTER, currentService);
153153
Watch.Response<V1Service> event = WatchEvent.createAddedEvent(olderService).toWatchResponse();
154154

155155
processor.dispatchServiceWatch(event);
156156

157-
assertThat(info.getClusters().get(CLUSTER), sameInstance(currentService));
157+
assertThat(info.getClusterService(CLUSTER), sameInstance(currentService));
158158
}
159159

160160
@Test
@@ -164,31 +164,31 @@ public void onModifyEventWithNoRecordedClusterService_addIt() {
164164

165165
processor.dispatchServiceWatch(event);
166166

167-
assertThat(info.getClusters().get(CLUSTER), sameInstance(service1));
167+
assertThat(info.getClusterService(CLUSTER), sameInstance(service1));
168168
}
169169

170170
@Test
171171
public void onModifyEventWithNewerClusterService_replaceCurrentValue() {
172172
V1Service currentService = createClusterService();
173173
V1Service newService = createClusterService();
174-
info.getClusters().put(CLUSTER, currentService);
174+
info.setClusterService(CLUSTER, currentService);
175175
Watch.Response<V1Service> event = WatchEvent.createModifiedEvent(newService).toWatchResponse();
176176

177177
processor.dispatchServiceWatch(event);
178178

179-
assertThat(info.getClusters().get(CLUSTER), sameInstance(newService));
179+
assertThat(info.getClusterService(CLUSTER), sameInstance(newService));
180180
}
181181

182182
@Test
183183
public void onModifyEventWithOlderClusterService_keepCurrentValue() {
184184
V1Service oldService = createClusterService();
185185
V1Service currentService = createClusterService();
186-
info.getClusters().put(CLUSTER, currentService);
186+
info.setClusterService(CLUSTER, currentService);
187187
Watch.Response<V1Service> event = WatchEvent.createModifiedEvent(oldService).toWatchResponse();
188188

189189
processor.dispatchServiceWatch(event);
190190

191-
assertThat(info.getClusters().get(CLUSTER), sameInstance(currentService));
191+
assertThat(info.getClusterService(CLUSTER), sameInstance(currentService));
192192
}
193193

194194
@Test
@@ -198,43 +198,43 @@ public void onDeleteEventWithNoRecordedClusterService_ignoreIt() {
198198

199199
processor.dispatchServiceWatch(event);
200200

201-
assertThat(info.getClusters().get(CLUSTER), nullValue());
201+
assertThat(info.getClusterService(CLUSTER), nullValue());
202202
}
203203

204204
@Test
205205
public void onDeleteEventWithOlderClusterService_keepCurrentValue() {
206206
V1Service oldService = createClusterService();
207207
V1Service currentService = createClusterService();
208-
info.getClusters().put(CLUSTER, currentService);
208+
info.setClusterService(CLUSTER, currentService);
209209
Watch.Response<V1Service> event = WatchEvent.createDeleteEvent(oldService).toWatchResponse();
210210

211211
processor.dispatchServiceWatch(event);
212212

213-
assertThat(info.getClusters().get(CLUSTER), sameInstance(currentService));
213+
assertThat(info.getClusterService(CLUSTER), sameInstance(currentService));
214214
}
215215

216216
@Test
217217
public void onDeleteEventWithSameClusterService_removeIt() {
218218
V1Service currentService = createClusterService();
219-
info.getClusters().put(CLUSTER, currentService);
219+
info.setClusterService(CLUSTER, currentService);
220220
Watch.Response<V1Service> event =
221221
WatchEvent.createDeleteEvent(currentService).toWatchResponse();
222222

223223
processor.dispatchServiceWatch(event);
224224

225-
assertThat(info.getClusters().get(CLUSTER), nullValue());
225+
assertThat(info.getClusterService(CLUSTER), nullValue());
226226
}
227227

228228
@Test
229229
public void onDeleteEventWithNewerClusterService_removeIt() {
230230
V1Service currentService = createClusterService();
231231
V1Service newerService = createClusterService();
232-
info.getClusters().put(CLUSTER, currentService);
232+
info.setClusterService(CLUSTER, currentService);
233233
Watch.Response<V1Service> event = WatchEvent.createDeleteEvent(newerService).toWatchResponse();
234234

235235
processor.dispatchServiceWatch(event);
236236

237-
assertThat(info.getClusters().get(CLUSTER), nullValue());
237+
assertThat(info.getClusterService(CLUSTER), nullValue());
238238
}
239239

240240
@Test

0 commit comments

Comments
 (0)