Skip to content

Commit b2c2536

Browse files
authored
Merge pull request #593 from oracle/schema-fix1
Support maxUnavailable
2 parents 6c61b47 + 464cb2c commit b2c2536

File tree

8 files changed

+88
-3
lines changed

8 files changed

+88
-3
lines changed

model/src/main/java/oracle/kubernetes/weblogic/domain/ClusterConfigurator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
public interface ClusterConfigurator {
1313
ClusterConfigurator withReplicas(int replicas);
1414

15+
ClusterConfigurator withMaxUnavailable(int maxUnavailable);
16+
1517
ClusterConfigurator withDesiredState(String state);
1618

1719
ClusterConfigurator withEnvironmentVariable(String name, String value);

model/src/main/java/oracle/kubernetes/weblogic/domain/EffectiveConfigurationFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public interface EffectiveConfigurationFactory {
2222

2323
void setReplicaCount(String clusterName, int replicaCount);
2424

25+
int getMaxUnavailable(String clusterName);
26+
2527
boolean isShuttingDown();
2628

2729
List<String> getExportedNetworkAccessPointNames();

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/Cluster.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public class Cluster extends BaseConfiguration {
2727
@Range(minimum = 0)
2828
private Integer replicas;
2929

30+
@Description(
31+
"The maximum number of cluster membrers that can be temporarily unavailable. Defaults to 1.")
32+
@Range(minimum = 1)
33+
private Integer maxUnavailable;
34+
3035
public String getClusterName() {
3136
return clusterName;
3237
}
@@ -48,12 +53,21 @@ public void setReplicas(Integer replicas) {
4853
this.replicas = replicas;
4954
}
5055

56+
public Integer getMaxUnavailable() {
57+
return maxUnavailable;
58+
}
59+
60+
public void setMaxUnavailable(Integer maxUnavailable) {
61+
this.maxUnavailable = maxUnavailable;
62+
}
63+
5164
@Override
5265
public String toString() {
5366
return new ToStringBuilder(this)
5467
.appendSuper(super.toString())
5568
.append("clusterName", clusterName)
5669
.append("replicas", replicas)
70+
.append("maxUnavailable", maxUnavailable)
5771
.toString();
5872
}
5973

@@ -69,6 +83,7 @@ public boolean equals(Object o) {
6983
.appendSuper(super.equals(o))
7084
.append(clusterName, cluster.clusterName)
7185
.append(replicas, cluster.replicas)
86+
.append(maxUnavailable, cluster.maxUnavailable)
7287
.isEquals();
7388
}
7489

@@ -78,6 +93,7 @@ public int hashCode() {
7893
.appendSuper(super.hashCode())
7994
.append(clusterName)
8095
.append(replicas)
96+
.append(maxUnavailable)
8197
.toHashCode();
8298
}
8399
}

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/Domain.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ public void setReplicaCount(String clusterName, int replicaLimit) {
219219
getEffectiveConfigurationFactory().setReplicaCount(clusterName, replicaLimit);
220220
}
221221

222+
/**
223+
* Returns the maximum number of unavailable replicas for the specified cluster.
224+
*
225+
* @param clusterName the name of the cluster
226+
* @return the result of applying any configurations for this value
227+
*/
228+
public int getMaxUnavailable(String clusterName) {
229+
return getEffectiveConfigurationFactory().getMaxUnavailable(clusterName);
230+
}
231+
232+
/**
233+
* Returns the minimum number of replicas for the specified cluster.
234+
*
235+
* @param clusterName the name of the cluster
236+
* @return the result of applying any configurations for this value
237+
*/
238+
public int getMinAvailable(String clusterName) {
239+
return Math.max(getReplicaCount(clusterName) - getMaxUnavailable(clusterName), 0);
240+
}
241+
222242
/**
223243
* DomainSpec is a description of a domain.
224244
*

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/DomainSpec.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,14 @@ private boolean hasReplicaCount(Cluster cluster) {
569569
return cluster != null && cluster.getReplicas() != null;
570570
}
571571

572+
private int getMaxUnavailableFor(Cluster cluster) {
573+
return hasMaxUnavailable(cluster) ? cluster.getMaxUnavailable() : 1;
574+
}
575+
576+
private boolean hasMaxUnavailable(Cluster cluster) {
577+
return cluster != null && cluster.getMaxUnavailable() != null;
578+
}
579+
572580
private AdminServer getAdminServer() {
573581
return Optional.ofNullable(adminServer).orElse(AdminServer.NULL_ADMIN_SERVER);
574582
}
@@ -619,6 +627,11 @@ public void setReplicaCount(String clusterName, int replicaCount) {
619627
getOrCreateCluster(clusterName).setReplicas(replicaCount);
620628
}
621629

630+
@Override
631+
public int getMaxUnavailable(String clusterName) {
632+
return getMaxUnavailableFor(getCluster(clusterName));
633+
}
634+
622635
@Override
623636
public List<String> getExportedNetworkAccessPointNames() {
624637
return getAdminServer().getExportedNetworkAccessPointNames();

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/DomainV2Configurator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ public ClusterConfigurator withReplicas(int replicas) {
375375
return this;
376376
}
377377

378+
@Override
379+
public ClusterConfigurator withMaxUnavailable(int maxUnavailable) {
380+
cluster.setMaxUnavailable(maxUnavailable);
381+
return this;
382+
}
383+
378384
@Override
379385
public ClusterConfigurator withDesiredState(String state) {
380386
cluster.setServerStartState(state);

model/src/test/java/oracle/kubernetes/weblogic/domain/DomainTestBase.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,34 @@ public void afterReplicaCountSetForCluster_canChangeIt() {
289289
assertThat(domain.getReplicaCount("cluster1"), equalTo(4));
290290
}
291291

292+
@Test
293+
public void afterReplicaCountMaxUnavailableSetForCluster_canReadMinAvailable() {
294+
configureCluster("cluster1").withReplicas(5).withMaxUnavailable(2);
295+
296+
assertThat(domain.getMinAvailable("cluster1"), equalTo(3));
297+
}
298+
299+
@Test
300+
public void afterReplicaCountSetForCluster_canReadMinAvailable() {
301+
configureCluster("cluster1").withReplicas(5);
302+
303+
assertThat(domain.getMinAvailable("cluster1"), equalTo(4));
304+
}
305+
306+
@Test
307+
public void afterReplicaCountMaxUnavailableSetForCluster_zeroMin() {
308+
configureCluster("cluster1").withReplicas(3).withMaxUnavailable(10);
309+
310+
assertThat(domain.getMinAvailable("cluster1"), equalTo(0));
311+
}
312+
313+
@Test
314+
public void afterMaxUnavailableSetForCluster_canReadIt() {
315+
configureCluster("cluster1").withMaxUnavailable(5);
316+
317+
assertThat(domain.getMaxUnavailable("cluster1"), equalTo(5));
318+
}
319+
292320
@Test
293321
public void whenServerNotConfigured_nodePortIsNull() {
294322
ServerSpec spec = domain.getServer(SERVER1, CLUSTER_NAME);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
public class RollingHelper {
3636
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
3737

38-
private static final int MINIMUM_FOR_CLUSTER = 2;
39-
4038
private RollingHelper() {}
4139

4240
/**
@@ -221,7 +219,7 @@ public NextAction apply(Packet packet) {
221219

222220
// then add as many as possible next() entries leaving at least minimum cluster
223221
// availability
224-
while (countReady-- > MINIMUM_FOR_CLUSTER) {
222+
while (countReady-- > dom.getMinAvailable(clusterName)) {
225223
current = it.next();
226224
serverConfig = (WlsServerConfig) current.packet.get(ProcessingConstants.SERVER_SCAN);
227225
servers.add(

0 commit comments

Comments
 (0)