Skip to content

Commit bc9e3db

Browse files
committed
use patching to scale clusters
1 parent d9a8a76 commit bc9e3db

File tree

2 files changed

+5
-83
lines changed

2 files changed

+5
-83
lines changed

operator/src/main/java/oracle/kubernetes/operator/rest/RestBackendImpl.java

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import oracle.kubernetes.operator.helpers.AuthorizationProxy.Resource;
3030
import oracle.kubernetes.operator.helpers.AuthorizationProxy.Scope;
3131
import oracle.kubernetes.operator.helpers.CallBuilder;
32-
import oracle.kubernetes.operator.helpers.ConflictRetry;
3332
import oracle.kubernetes.operator.logging.LoggingFacade;
3433
import oracle.kubernetes.operator.logging.LoggingFactory;
3534
import oracle.kubernetes.operator.logging.MessageKeys;
@@ -73,11 +72,6 @@ public class RestBackendImpl implements RestBackend {
7372
LOGGER.exiting();
7473
}
7574

76-
private void authorize(String domainUID, String cluster, Operation operation) {
77-
// TBD - should cluster atz be different than domain atz?
78-
authorize(domainUID, operation);
79-
}
80-
8175
private void authorize(String domainUID, Operation operation) {
8276
LOGGER.entering(domainUID, operation);
8377
boolean authorized;
@@ -211,7 +205,7 @@ public Set<String> getClusters(String domainUID) {
211205
@Override
212206
public boolean isCluster(String domainUID, String cluster) {
213207
LOGGER.entering(domainUID, cluster);
214-
authorize(domainUID, cluster, Operation.list);
208+
authorize(domainUID, Operation.list);
215209
boolean result = getClusters(domainUID).contains(cluster);
216210
LOGGER.exiting(result);
217211
return result;
@@ -226,25 +220,14 @@ public void scaleCluster(String domainUID, String cluster, int managedServerCoun
226220
Status.BAD_REQUEST, MessageKeys.INVALID_MANAGE_SERVER_COUNT, managedServerCount);
227221
}
228222

229-
authorize(domainUID, cluster, Operation.update);
223+
authorize(domainUID, Operation.update);
230224

231225
List<Domain> domains = getDomainsList();
232226
Domain domain = findDomain(domainUID, domains);
233227

234-
String namespace = getNamespace(domainUID, domains);
235-
236228
verifyWLSConfiguredClusterCapacity(domain, cluster, managedServerCount);
237229

238-
/*/
239230
patchDomain(domain, cluster, managedServerCount);
240-
/*/
241-
if (updateReplicasForDomain(domain, cluster, managedServerCount)) {
242-
overwriteDomain(
243-
namespace,
244-
domain,
245-
() -> getDomainForConflictRetry(domainUID, cluster, managedServerCount));
246-
}
247-
/**/
248231
LOGGER.exiting();
249232
}
250233

@@ -276,39 +259,6 @@ private int getClusterIndex(Domain domain, String cluster) {
276259
return -1;
277260
}
278261

279-
private boolean updateReplicasForDomain(Domain domain, String cluster, int newReplicaCount) {
280-
if (newReplicaCount != domain.getReplicaCount(cluster)) {
281-
domain.setReplicaCount(cluster, newReplicaCount);
282-
return true;
283-
}
284-
return false;
285-
}
286-
287-
private void overwriteDomain(
288-
String namespace, final Domain domain, ConflictRetry<Domain> conflictRetry) {
289-
try {
290-
// Write out the Domain with updated replica values
291-
// TODO: Can we patch instead of replace?
292-
new CallBuilder()
293-
.replaceDomainWithConflictRetry(domain.getDomainUID(), namespace, domain, conflictRetry);
294-
} catch (ApiException e) {
295-
LOGGER.finer(
296-
String.format(
297-
"Unexpected exception when updating Domain %s in namespace %s",
298-
domain.getDomainUID(), namespace),
299-
e);
300-
throw new WebApplicationException(e.getMessage());
301-
}
302-
}
303-
304-
Domain getDomainForConflictRetry(String domainUid, String cluster, int newReplicaCount) {
305-
Domain domain = findDomain(domainUid, getDomainsList());
306-
if (updateReplicasForDomain(domain, cluster, newReplicaCount)) {
307-
return domain;
308-
}
309-
return null;
310-
}
311-
312262
private void verifyWLSConfiguredClusterCapacity(
313263
Domain domain, String cluster, int requestedSize) {
314264
// Query WebLogic Admin Server for current configured WebLogic Cluster size
@@ -336,11 +286,11 @@ private Map<String, WlsClusterConfig> getWLSConfiguredClusters(String domainUID)
336286
return getWlsDomainConfig(domainUID).getClusterConfigs();
337287
}
338288

339-
static interface TopologyRetriever {
340-
public WlsDomainConfig getWlsDomainConfig(String ns, String domainUID);
289+
interface TopologyRetriever {
290+
WlsDomainConfig getWlsDomainConfig(String ns, String domainUID);
341291
}
342292

343-
static final TopologyRetriever INSTANCE =
293+
private static final TopologyRetriever INSTANCE =
344294
(String ns, String domainUID) -> {
345295
Scan s = ScanCache.INSTANCE.lookupScan(ns, domainUID);
346296
if (s != null) {

operator/src/test/java/oracle/kubernetes/operator/rest/RestBackendImplTest.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -160,34 +160,6 @@ public void whenReplaceDomainReturnsError_scaleClusterThrowsException() {
160160
restBackend.scaleCluster(NAME2, "cluster1", 3);
161161
}
162162

163-
@Test
164-
public void getDomainForConflictRetry_returnsBeforeDomain() {
165-
configureDomain().withDefaultReplicaCount(2);
166-
167-
assertThat(
168-
((RestBackendImpl) restBackend)
169-
.getDomainForConflictRetry(NAME1, "cluster1", REPLICA_LIMIT)
170-
.getReplicaCount("cluster-1"),
171-
equalTo(2));
172-
}
173-
174-
@Test
175-
public void getDomainForConflictRetry_ifSameReplicaCount_returnsNull() {
176-
configureDomain().withDefaultReplicaCount(REPLICA_LIMIT);
177-
178-
assertThat(
179-
((RestBackendImpl) restBackend).getDomainForConflictRetry(NAME1, "cluster1", REPLICA_LIMIT),
180-
nullValue());
181-
}
182-
183-
@Test(expected = WebApplicationException.class)
184-
public void getDomainForConflictRetry_ifDomainNotFound_throws() {
185-
configureDomain().withDefaultReplicaCount(2);
186-
187-
((RestBackendImpl) restBackend)
188-
.getDomainForConflictRetry("noSuchUID", "cluster1", REPLICA_LIMIT);
189-
}
190-
191163
@Test
192164
public void verify_getWlsDomainConfig_returnsWlsDomainConfig() {
193165
WlsDomainConfig wlsDomainConfig = ((RestBackendImpl) restBackend).getWlsDomainConfig(NAME1);

0 commit comments

Comments
 (0)