64
64
import static oracle .weblogic .kubernetes .utils .CommonPatchTestUtils .patchServerStartPolicy ;
65
65
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkClusterReplicaCountMatches ;
66
66
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodDeleted ;
67
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodDoesNotExist ;
67
68
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodInitializing ;
68
69
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
69
70
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createConfigMapAndVerify ;
89
90
* managed server. The replica count is set to 1 and serverStartPolicy is set
90
91
* to IF_NEEDED at managed server level.
91
92
*/
92
-
93
93
@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
94
94
@ DisplayName ("ServerStartPolicy attribute in different levels in a MII domain" )
95
95
@ IntegrationTest
@@ -104,6 +104,8 @@ class ItServerStartPolicy {
104
104
public static final String START_CLUSTER_SCRIPT = "startCluster.sh" ;
105
105
public static final String STOP_DOMAIN_SCRIPT = "stopDomain.sh" ;
106
106
public static final String START_DOMAIN_SCRIPT = "startDomain.sh" ;
107
+ public static final String SCALE_CLUSTER_SCRIPT = "scaleCluster.sh" ;
108
+ public static final String STATUS_CLUSTER_SCRIPT = "clusterStatus.sh" ;
107
109
public static final String managedServerNamePrefix = "managed-server" ;
108
110
public static final String CLUSTER_1 = "cluster-1" ;
109
111
public static final String CLUSTER_2 = "cluster-2" ;
@@ -1130,6 +1132,131 @@ public void testRestartingMSWithExplicitServerStartStateWhileVaryingReplicaCount
1130
1132
logger .info ("managed server " + serverName + " restarted successfully." );
1131
1133
}
1132
1134
1135
+ /**
1136
+ * Scale the configured cluster using the sample script scaleCluster.sh script
1137
+ * Verify that server(s) in the configured cluster are scaled up and in RUNNING state.
1138
+ * Verify that server(s) in the dynamic cluster are not affected.
1139
+ * Restore the env using the sample script stopServer.sh.
1140
+ */
1141
+ @ Order (19 )
1142
+ @ Test
1143
+ @ DisplayName ("Scale the configured cluster with scaleCluster.sh script" )
1144
+ public void testConfigClusterScale () {
1145
+ int newReplicaCount = 2 ;
1146
+ String configServerName = "config-cluster-server" + newReplicaCount ;
1147
+ String configServerPodName = domainUid + "-" + configServerName ;
1148
+ String dynamicServerPodName = domainUid + "-managed-server" + newReplicaCount ;
1149
+
1150
+ // use clusterStatus.sh to make sure the server-to-be-test doesn't exist
1151
+ // String regex matches below
1152
+ // cluster min max goal current ready
1153
+ // clusterName 1 5 1 1 1
1154
+ String regex = ".*" + CLUSTER_1 + "(\\ s+)1(\\ s+)5(\\ s+)1(\\ s+)1(\\ s+)1" ;
1155
+ scalingClusters (CLUSTER_1 , dynamicServerPodName , replicaCount , regex , false );
1156
+ // String regex matches below
1157
+ // cluster min max goal current ready
1158
+ // clusterName 0 2 1 1 1
1159
+ regex = ".*" + CLUSTER_2 + "(\\ s+)0(\\ s+)2(\\ s+)1(\\ s+)1(\\ s+)1" ;
1160
+ scalingClusters (CLUSTER_2 , configServerPodName , replicaCount , regex , false );
1161
+
1162
+ // use scaleCluster.sh to scale a dynamic cluster and
1163
+ // use clusterStatus.sh to verify scaling results
1164
+ // String regex matches below
1165
+ // cluster min max goal current ready
1166
+ // clusterName 0 2 2 2 2
1167
+ regex = ".*" + CLUSTER_2 + "(\\ s+)0(\\ s+)2(\\ s+)2(\\ s+)2(\\ s+)2" ;
1168
+ scalingClusters (CLUSTER_2 , configServerPodName , newReplicaCount , regex , true );
1169
+
1170
+ // check managed server from other cluster are not affected
1171
+ logger .info ("Check dynamic managed server pods are not affected" );
1172
+ assertDoesNotThrow (() -> assertTrue (checkClusterReplicaCountMatches (CLUSTER_1 ,
1173
+ domainUid , domainNamespace , replicaCount )));
1174
+ checkPodDoesNotExist (dynamicServerPodName , domainUid , domainNamespace );
1175
+
1176
+ // use clusterStatus.sh to restore test env
1177
+ // String regex matches below
1178
+ // cluster min max goal current ready
1179
+ // clusterName 0 2 1 1 1
1180
+ regex = ".*" + CLUSTER_2 + "(\\ s+)0(\\ s+)2(\\ s+)1(\\ s+)1(\\ s+)1" ;
1181
+ scalingClusters (CLUSTER_2 , configServerPodName , replicaCount , regex , false );
1182
+ }
1183
+
1184
+ /**
1185
+ * Scale the dynamic cluster using the sample script scaleCluster.sh script
1186
+ * Verify that server(s) in the dynamic cluster are scaled up and in RUNNING state.
1187
+ * Verify that server(s) in the configured cluster are not affected.
1188
+ * Restore the env using the sample script stopServer.sh.
1189
+ */
1190
+ @ Order (20 )
1191
+ @ Test
1192
+ @ DisplayName ("Scale the dynamic cluster with scaleCluster.sh script" )
1193
+ public void testDynamicClusterScale () {
1194
+ int newReplicaCount = 2 ;
1195
+ String dynamicServerName = "managed-server" + newReplicaCount ;
1196
+ String dynamicServerPodName = domainUid + "-" + dynamicServerName ;
1197
+ String configServerPodName = domainUid + "-config-cluster-server" + newReplicaCount ;
1198
+
1199
+ // use clusterStatus.sh to make sure the server-to-be-test doesn't exist
1200
+ // String regex matches below
1201
+ // cluster min max goal current ready
1202
+ // clusterName 1 5 1 1 1
1203
+ String regex = ".*" + CLUSTER_1 + "(\\ s+)1(\\ s+)5(\\ s+)1(\\ s+)1(\\ s+)1" ;
1204
+ scalingClusters (CLUSTER_1 , dynamicServerPodName , replicaCount , regex , false );
1205
+ // String regex matches below
1206
+ // cluster min max goal current ready
1207
+ // clusterName 0 2 1 1 1
1208
+ regex = ".*" + CLUSTER_2 + "(\\ s+)0(\\ s+)2(\\ s+)1(\\ s+)1(\\ s+)1" ;
1209
+ scalingClusters (CLUSTER_2 , configServerPodName , replicaCount , regex , false );
1210
+
1211
+ // use scaleCluster.sh to scale a dynamic cluster and
1212
+ // use clusterStatus.sh to verify scaling results
1213
+ // String regex matches below
1214
+ // cluster min max goal current ready
1215
+ // clusterName 1 5 2 2 2
1216
+ regex = ".*" + CLUSTER_1 + "(\\ s+)1(\\ s+)5(\\ s+)2(\\ s+)2(\\ s+)2" ;
1217
+ scalingClusters (CLUSTER_1 , dynamicServerPodName , newReplicaCount , regex , true );
1218
+
1219
+ // check managed server from other cluster are not affected
1220
+ logger .info ("Check configured managed server pods are not affected" );
1221
+ assertDoesNotThrow (() -> assertTrue (checkClusterReplicaCountMatches (CLUSTER_2 ,
1222
+ domainUid , domainNamespace , replicaCount )));
1223
+ checkPodDoesNotExist (configServerPodName , domainUid , domainNamespace );
1224
+
1225
+ // use clusterStatus.sh to restore test env
1226
+ // String regex matches below
1227
+ // cluster min max goal current ready
1228
+ // clusterName 1 5 1 1 1
1229
+ regex = ".*" + CLUSTER_1 + "(\\ s+)1(\\ s+)5(\\ s+)1(\\ s+)1(\\ s+)1" ;
1230
+ scalingClusters (CLUSTER_1 , dynamicServerPodName , replicaCount , regex , false );
1231
+ }
1232
+
1233
+ private void scalingClusters (String clusterName , String serverPodName , int replicaNum ,
1234
+ String regex , boolean checkPodExist ) {
1235
+ // use scaleCluster.sh to scale a given cluster
1236
+ logger .info ("Scale cluster {0} using the script scaleCluster.sh" , clusterName );
1237
+ String result = assertDoesNotThrow (() ->
1238
+ executeLifecycleScript (SCALE_CLUSTER_SCRIPT , CLUSTER_LIFECYCLE , clusterName , " -r " + replicaNum , false ),
1239
+ String .format ("Failed to run %s" , SCALE_CLUSTER_SCRIPT ));
1240
+
1241
+ if (checkPodExist ) {
1242
+ checkPodReadyAndServiceExists (serverPodName , domainUid , domainNamespace );
1243
+ } else {
1244
+ checkPodDoesNotExist (serverPodName , domainUid , domainNamespace );
1245
+ }
1246
+
1247
+ // verify that scaleCluster.sh does scale to a required replica number
1248
+ assertDoesNotThrow (() -> assertTrue (checkClusterReplicaCountMatches (clusterName ,
1249
+ domainUid , domainNamespace , replicaNum )));
1250
+
1251
+ // use clusterStatus.sh to verify scaling results
1252
+ result = assertDoesNotThrow (() ->
1253
+ executeLifecycleScript (STATUS_CLUSTER_SCRIPT , CLUSTER_LIFECYCLE , clusterName ),
1254
+ String .format ("Failed to run %s" , STATUS_CLUSTER_SCRIPT ));
1255
+
1256
+ assertTrue (verifyExecuteResult (result , regex ), "The script should scale the given cluster: " + clusterName );
1257
+ logger .info ("The cluster {0} scaled successfully." , clusterName );
1258
+ }
1259
+
1133
1260
private static void createDomainSecret (String secretName , String username , String password , String domNamespace ) {
1134
1261
Map <String , String > secretMap = new HashMap <>();
1135
1262
secretMap .put ("username" , username );
@@ -1284,6 +1411,7 @@ private String executeLifecycleScript(String script,
1284
1411
boolean checkResult ,
1285
1412
String ... args ) {
1286
1413
String domainName = (args .length == 0 ) ? domainUid : args [0 ];
1414
+
1287
1415
CommandParams params ;
1288
1416
String commonParameters = " -d " + domainName + " -n " + domainNamespace ;
1289
1417
params = new CommandParams ().defaults ();
@@ -1292,6 +1420,10 @@ private String executeLifecycleScript(String script,
1292
1420
+ Paths .get (domainLifecycleSamplePath .toString (), "/" + script ).toString ()
1293
1421
+ commonParameters + " -s " + entityName + " " + extraParams );
1294
1422
} else if (scriptType .equals (CLUSTER_LIFECYCLE )) {
1423
+ if (extraParams .contains ("-r" )) {
1424
+ commonParameters += " " + extraParams ;
1425
+ }
1426
+
1295
1427
params .command ("sh "
1296
1428
+ Paths .get (domainLifecycleSamplePath .toString (), "/" + script ).toString ()
1297
1429
+ commonParameters + " -c " + entityName );
0 commit comments