Skip to content

Commit aa15e81

Browse files
authored
Merge pull request #603 from oracle/schema-fix3
Use lists for clusters and managedServers so that JSON schema is clearer
2 parents 6a06c9f + 7e961c2 commit aa15e81

File tree

8 files changed

+35
-49
lines changed

8 files changed

+35
-49
lines changed

kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/domain-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ spec:
5252
# clusters is used to configure the desired behavior for starting member servers of a cluster.
5353
# If you use this entry, then the rules will be applied to ALL servers that are members of the named clusters.
5454
clusters:
55-
%CLUSTER_NAME%:
55+
- clusterName: %CLUSTER_NAME%
5656
serverStartState: "RUNNING"
5757
replicas: %INITIAL_MANAGED_SERVER_REPLICAS%
5858
# The number of managed servers to start from clusters not listed in clusters

kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/domain-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ spec:
6161
# clusters is used to configure the desired behavior for starting member servers of a cluster.
6262
# If you use this entry, then the rules will be applied to ALL servers that are members of the named clusters.
6363
clusters:
64-
%CLUSTER_NAME%:
64+
- clusterName: %CLUSTER_NAME%
6565
replicas: %INITIAL_MANAGED_SERVER_REPLICAS%
6666
# The number of managed servers to start for unlisted clusters
6767
# replicas: 1

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ public class DomainSpec extends BaseConfiguration {
164164
* @since 2.0
165165
*/
166166
@Description("Configuration for the managed servers")
167-
private Map<String, ManagedServer> managedServers = new HashMap<>();
167+
private List<ManagedServer> managedServers = new ArrayList<>();
168168

169169
/**
170170
* The configured clusters.
171171
*
172172
* @since 2.0
173173
*/
174174
@Description("Configuration for the clusters")
175-
protected Map<String, Cluster> clusters = new HashMap<>();
175+
protected List<Cluster> clusters = new ArrayList<>();
176176

177177
/**
178178
* Adds a Cluster to the DomainSpec
@@ -181,7 +181,7 @@ public class DomainSpec extends BaseConfiguration {
181181
* @return
182182
*/
183183
public DomainSpec withCluster(Cluster cluster) {
184-
clusters.put(cluster.getClusterName(), cluster);
184+
clusters.add(cluster);
185185
return this;
186186
}
187187

@@ -551,12 +551,22 @@ public boolean equals(Object other) {
551551
return builder.isEquals();
552552
}
553553

554-
private Server getServer(String serverName) {
555-
return managedServers.get(serverName);
554+
ManagedServer getManagedServer(String serverName) {
555+
if (serverName != null) {
556+
for (ManagedServer s : managedServers) {
557+
if (serverName.equals(s.getServerName())) return s;
558+
}
559+
}
560+
return null;
556561
}
557562

558-
private Cluster getCluster(String clusterName) {
559-
return clusters.get(clusterName);
563+
Cluster getCluster(String clusterName) {
564+
if (clusterName != null) {
565+
for (Cluster c : clusters) {
566+
if (clusterName.equals(c.getClusterName())) return c;
567+
}
568+
}
569+
return null;
560570
}
561571

562572
private int getReplicaCountFor(Cluster cluster) {
@@ -585,11 +595,11 @@ private void setAdminServer(AdminServer adminServer) {
585595
this.adminServer = adminServer;
586596
}
587597

588-
public Map<String, ManagedServer> getManagedServers() {
598+
public List<ManagedServer> getManagedServers() {
589599
return managedServers;
590600
}
591601

592-
public Map<String, Cluster> getClusters() {
602+
public List<Cluster> getClusters() {
593603
return clusters;
594604
}
595605

@@ -603,7 +613,7 @@ public ServerSpec getAdminServerSpec() {
603613
public ServerSpec getServerSpec(String serverName, String clusterName) {
604614
return new ManagedServerSpecV2Impl(
605615
DomainSpec.this,
606-
getServer(serverName),
616+
getManagedServer(serverName),
607617
getCluster(clusterName),
608618
getClusterLimit(clusterName));
609619
}
@@ -669,7 +679,7 @@ private Cluster getOrCreateCluster(String clusterName) {
669679

670680
private Cluster createClusterWithName(String clusterName) {
671681
Cluster cluster = new Cluster().withClusterName(clusterName);
672-
clusters.put(clusterName, cluster);
682+
clusters.add(cluster);
673683
return cluster;
674684
}
675685
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ public ServerConfigurator configureServer(@Nonnull String serverName) {
166166
}
167167

168168
private Server getOrCreateManagedServer(@Nonnull String serverName) {
169-
ManagedServer server = getDomainSpec().getManagedServers().get(serverName);
169+
ManagedServer server = getDomainSpec().getManagedServer(serverName);
170170
if (server != null) {
171-
server.setServerName(serverName);
172171
return server;
173172
}
174173

@@ -177,7 +176,7 @@ private Server getOrCreateManagedServer(@Nonnull String serverName) {
177176

178177
private Server createManagedServer(String serverName) {
179178
ManagedServer server = new ManagedServer().withServerName(serverName);
180-
getDomainSpec().getManagedServers().put(serverName, server);
179+
getDomainSpec().getManagedServers().add(server);
181180
return server;
182181
}
183182

@@ -342,9 +341,8 @@ public ClusterConfigurator configureCluster(@Nonnull String clusterName) {
342341
}
343342

344343
private Cluster getOrCreateCluster(@Nonnull String clusterName) {
345-
Cluster cluster = getDomainSpec().getClusters().get(clusterName);
344+
Cluster cluster = getDomainSpec().getCluster(clusterName);
346345
if (cluster != null) {
347-
cluster.setClusterName(clusterName);
348346
return cluster;
349347
}
350348

@@ -353,7 +351,7 @@ private Cluster getOrCreateCluster(@Nonnull String clusterName) {
353351

354352
private Cluster createCluster(@Nonnull String clusterName) {
355353
Cluster cluster = new Cluster().withClusterName(clusterName);
356-
getDomainSpec().getClusters().put(clusterName, cluster);
354+
getDomainSpec().getClusters().add(cluster);
357355
return cluster;
358356
}
359357

model/src/test/resources/oracle/kubernetes/weblogic/domain/v2/domain-sample-2.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ spec:
1111
# Identify which Secret contains the WebLogic Admin credentials
1212
adminSecret:
1313
name: admin-secret
14-
# The name of the Admin Server
15-
asName: admin
16-
# The Admin Server's ListenPort
17-
asPort: 8001
18-
# The WebLogic Domain Name
19-
20-
domainName: base_domain
2114
# The domainUID must be unique across the entire Kubernetes Cluster. Each WebLogic Domain must
2215
# have its own unique domainUID. This does not have to be the same as the Domain Name. It is allowed
2316
# to have multiple Domains with the same Domain Name, but they MUST have different domainUID's.
@@ -68,7 +61,7 @@ spec:
6861
path: /other/path
6962

7063
clusters:
71-
cluster1:
64+
- clusterName: cluster1
7265
serverPod:
7366
readinessProbe:
7467
initialDelaySeconds: 10
@@ -107,7 +100,7 @@ spec:
107100
user: weblogic
108101

109102
managedServers:
110-
server2:
103+
- serverName: server2
111104
serverPod:
112105
livenessProbe:
113106
periodSeconds: 18

model/src/test/resources/oracle/kubernetes/weblogic/domain/v2/domain-sample-3.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ spec:
1111
# Identify which Secret contains the WebLogic Admin credentials
1212
adminSecret:
1313
name: admin-secret
14-
# The name of the Admin Server
15-
asName: admin
16-
# The Admin Server's ListenPort
17-
asPort: 8001
18-
1914
adminServer:
2015
# the T3 endpoints to export. Each entry is an endpoint name,
2116
# optionally with labels and annotations to be added to the generated external channel service.
@@ -38,8 +33,6 @@ spec:
3833
testKey3: testValue3
3934
longer: shorter
4035
restartVersion: "1"
41-
42-
domainName: base_domain
4336
# The domainUID must be unique across the entire Kubernetes Cluster. Each WebLogic Domain must
4437
# have its own unique domainUID. This does not have to be the same as the Domain Name. It is allowed
4538
# to have multiple Domains with the same Domain Name, but they MUST have different domainUID's.

model/src/test/resources/oracle/kubernetes/weblogic/domain/v2/domain-sample.yaml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ spec:
1111
# Identify which Secret contains the WebLogic Admin credentials
1212
adminSecret:
1313
name: admin-secret
14-
# The name of the Admin Server
15-
asName: admin
16-
# The Admin Server's ListenPort
17-
asPort: 8001
18-
# The WebLogic Domain Name
19-
20-
domainName: base_domain
2114
# The domainUID must be unique across the entire Kubernetes Cluster. Each WebLogic Domain must
2215
# have its own unique domainUID. This does not have to be the same as the Domain Name. It is allowed
2316
# to have multiple Domains with the same Domain Name, but they MUST have different domainUID's.
@@ -84,7 +77,7 @@ spec:
8477

8578
# list of configurations per named server.
8679
managedServers:
87-
server1:
80+
- serverName: server1
8881
# an (optional) list of environment variable to be set on the server
8982
serverPod:
9083
env:
@@ -99,13 +92,13 @@ spec:
9992
memory: "32Mi"
10093
limits:
10194
memory: "256Mi"
102-
server2:
95+
- serverName: server2
10396
serverStartState: ADMIN
10497
restartVersion: "3"
10598

10699
# If you use this entry, then the rules will be applied to ALL servers that are members of the named clusters.
107100
clusters:
108-
cluster2:
101+
- clusterName: cluster2
109102
desiredState: "RUNNING"
110103
replicas: 5
111104
serverPod:

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import io.kubernetes.client.models.V1PodList;
1212
import java.util.ArrayList;
1313
import java.util.List;
14-
import java.util.Map;
1514
import oracle.kubernetes.operator.JobWatcher;
1615
import oracle.kubernetes.operator.LabelConstants;
1716
import oracle.kubernetes.operator.ProcessingConstants;
@@ -153,11 +152,11 @@ private static int runningServersCount(DomainPresenceInfo info) {
153152
private static boolean creatingServers(DomainPresenceInfo info) {
154153
Domain dom = info.getDomain();
155154
DomainSpec spec = dom.getSpec();
156-
Map<String, Cluster> clusters = spec.getClusters();
157-
Map<String, ManagedServer> servers = spec.getManagedServers();
155+
List<Cluster> clusters = spec.getClusters();
156+
List<ManagedServer> servers = spec.getManagedServers();
158157

159158
// Are we starting a cluster?
160-
for (Cluster cluster : clusters.values()) {
159+
for (Cluster cluster : clusters) {
161160
int replicaCount = cluster.getReplicas();
162161
LOGGER.fine("creatingServers replicaCount: " + replicaCount + " for cluster: " + cluster);
163162
if (replicaCount > 0) {

0 commit comments

Comments
 (0)