Skip to content

Commit c620271

Browse files
authored
Add WKO retry improvement miscellaneous usescases (#3728)
* Add WKO retry improvement miscellaneous usescases
1 parent 77e08ef commit c620271

File tree

7 files changed

+818
-28
lines changed

7 files changed

+818
-28
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItRetryImprovementMisc.java

Lines changed: 508 additions & 0 deletions
Large diffs are not rendered by default.

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ public static boolean patchClusterCustomResource(String clusterName, String name
16661666
* @return response msg of patching cluster resource
16671667
*/
16681668
public static String patchClusterCustomResourceReturnResponse(String clusterName, String namespace,
1669-
V1Patch patch, String patchFormat) {
1669+
V1Patch patch, String patchFormat) {
16701670
String responseMsg;
16711671
// GenericKubernetesApi uses CustomObjectsApi calls
16721672
KubernetesApiResponse<ClusterResource> response = clusterCrdClient.patch(
@@ -1676,7 +1676,9 @@ public static String patchClusterCustomResourceReturnResponse(String clusterName
16761676
patch // patch data
16771677
);
16781678

1679-
String logmsg = "response code: " + response.getHttpStatusCode() + ". response message: "
1679+
String logmsg = "response code: " + response.getHttpStatusCode()
1680+
+ ". response status: " + response.getStatus() + "."
1681+
+ "response message: "
16801682
+ Optional.ofNullable(response.getStatus()).map(V1Status::getMessage).orElse("none")
16811683
+ " when patching " + clusterName + " in namespace "
16821684
+ namespace + " with " + patch + " using patch format: " + patchFormat;

integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,55 @@ public static Callable<Boolean> domainStatusConditionTypeHasExpectedStatus(Strin
733733
};
734734
}
735735

736+
/**
737+
* Check the domain status condition type has expected status.
738+
* @param domainUid uid of the domain
739+
* @param domainNamespace namespace of the domain
740+
* @param clusterName cluster name of the domain
741+
* @param conditionType the type name of condition, accepted value: Completed, Available, Failed and
742+
* ConfigChangesPendingRestart
743+
* @param expectedStatus expected status value, either True or False
744+
* @param domainVersion version of domain
745+
* @return true if the condition type has the expected status, false otherwise
746+
*/
747+
public static Callable<Boolean> domainStatusClustersConditionTypeHasExpectedStatus(String domainUid,
748+
String domainNamespace,
749+
String clusterName,
750+
String conditionType,
751+
String expectedStatus,
752+
String domainVersion) {
753+
LoggingFacade logger = getLogger();
754+
755+
return () -> {
756+
DomainResource domain =
757+
assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace, domainVersion));
758+
759+
if (domain != null && domain.getStatus() != null) {
760+
List<ClusterStatus> clusterStatusList = domain.getStatus().getClusters();
761+
logger.info(Yaml.dump(clusterStatusList));
762+
for (ClusterStatus clusterStatus : clusterStatusList) {
763+
if (clusterStatus.getClusterName() != null && clusterStatus.getClusterName().equals(clusterName)) {
764+
List<ClusterCondition> clusterConditions = clusterStatus.getConditions();
765+
for (ClusterCondition clusterCondition : clusterConditions) {
766+
if (clusterCondition.getType() != null && clusterCondition.getType().equalsIgnoreCase(conditionType)
767+
&& clusterCondition.getStatus() != null
768+
&& clusterCondition.getStatus().equalsIgnoreCase(expectedStatus)) {
769+
return true;
770+
}
771+
}
772+
}
773+
}
774+
} else {
775+
if (domain == null) {
776+
logger.info("domain is null");
777+
} else {
778+
logger.info("domain status is null");
779+
}
780+
}
781+
return false;
782+
};
783+
}
784+
736785
/**
737786
* Check the staus of the given server in domain status.
738787
*
@@ -1198,4 +1247,85 @@ public static Callable<Boolean> clusterExists(String clusterResName, String clus
11981247
public static Callable<Boolean> clusterDoesNotExist(String clusterResName, String clusterVersion, String namespace) {
11991248
return () -> !Cluster.doesClusterExist(clusterResName, clusterVersion, namespace);
12001249
}
1250+
1251+
/**
1252+
* Get the value of the domain status condition type.
1253+
* @param domainUid uid of the domain
1254+
* @param domainNamespace namespace of the domain
1255+
* @param conditionType the type name of condition, accepted value: Completed, Available, Failed and
1256+
* ConfigChangesPendingRestart
1257+
* @param domainVersion version of domain
1258+
* @return value of the status condition type, True or False
1259+
*/
1260+
public static String getDomainStatusConditionTypeValue(String domainUid,
1261+
String domainNamespace,
1262+
String conditionType,
1263+
String domainVersion) {
1264+
LoggingFacade logger = getLogger();
1265+
1266+
DomainResource domain =
1267+
assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace, domainVersion));
1268+
1269+
if (domain != null && domain.getStatus() != null) {
1270+
List<DomainCondition> domainConditionList = domain.getStatus().getConditions();
1271+
logger.info(Yaml.dump(domainConditionList));
1272+
for (DomainCondition domainCondition : domainConditionList) {
1273+
if (domainCondition.getType().equalsIgnoreCase(conditionType)) {
1274+
return domainCondition.getStatus();
1275+
}
1276+
}
1277+
} else {
1278+
if (domain == null) {
1279+
logger.info("domain is null");
1280+
} else {
1281+
logger.info("domain status is null");
1282+
}
1283+
}
1284+
return "";
1285+
}
1286+
1287+
/**
1288+
* Get the value of the domain status cluster condition type.
1289+
* @param domainUid uid of the domain
1290+
* @param domainNamespace namespace of the domain
1291+
* @param clusterName cluster name of the domain
1292+
* @param conditionType the type name of condition, accepted value: Completed, Available, Failed and
1293+
* ConfigChangesPendingRestart
1294+
* @param domainVersion version of domain
1295+
* @return true if the condition type has the expected status, false otherwise
1296+
*/
1297+
public static String getDomainStatusClustersConditionTypeValue(String domainUid,
1298+
String domainNamespace,
1299+
String clusterName,
1300+
String conditionType,
1301+
String domainVersion) {
1302+
LoggingFacade logger = getLogger();
1303+
1304+
1305+
DomainResource domain =
1306+
assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace, domainVersion));
1307+
1308+
if (domain != null && domain.getStatus() != null) {
1309+
List<ClusterStatus> clusterStatusList = domain.getStatus().getClusters();
1310+
logger.info(Yaml.dump(clusterStatusList));
1311+
for (ClusterStatus clusterStatus : clusterStatusList) {
1312+
if (clusterStatus.getClusterName() != null && clusterStatus.getClusterName().equals(clusterName)) {
1313+
List<ClusterCondition> clusterConditions = clusterStatus.getConditions();
1314+
for (ClusterCondition clusterCondition : clusterConditions) {
1315+
if (clusterCondition.getType() != null && clusterCondition.getType().equalsIgnoreCase(conditionType)
1316+
&& clusterCondition.getStatus() != null) {
1317+
return clusterCondition.getStatus();
1318+
}
1319+
}
1320+
}
1321+
}
1322+
} else {
1323+
if (domain == null) {
1324+
logger.info("domain is null");
1325+
} else {
1326+
logger.info("domain status is null");
1327+
}
1328+
}
1329+
return "";
1330+
}
12011331
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/ClusterUtils.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@
1414
import oracle.weblogic.kubernetes.actions.impl.primitive.Command;
1515
import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams;
1616
import oracle.weblogic.kubernetes.logging.LoggingFacade;
17+
import org.awaitility.core.ConditionFactory;
1718

1819
import static oracle.weblogic.kubernetes.TestConstants.CLUSTER_API_VERSION;
1920
import static oracle.weblogic.kubernetes.TestConstants.CLUSTER_VERSION;
21+
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_VERSION;
2022
import static oracle.weblogic.kubernetes.TestConstants.KUBERNETES_CLI;
2123
import static oracle.weblogic.kubernetes.actions.TestActions.createClusterCustomResource;
2224
import static oracle.weblogic.kubernetes.actions.TestActions.patchClusterCustomResource;
2325
import static oracle.weblogic.kubernetes.actions.impl.Cluster.listClusterCustomResources;
2426
import static oracle.weblogic.kubernetes.assertions.TestAssertions.clusterDoesNotExist;
2527
import static oracle.weblogic.kubernetes.assertions.TestAssertions.clusterExists;
28+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainStatusClustersConditionTypeHasExpectedStatus;
2629
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
2730
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getHostAndPort;
2831
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
32+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withLongRetryPolicy;
2933
import static oracle.weblogic.kubernetes.utils.OKDUtils.getRouteHost;
3034
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
3135
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -339,4 +343,80 @@ public static void startCluster(String clusterResource,
339343
V1Patch.PATCH_FORMAT_JSON_PATCH), "Failed to start cluster resource");
340344
}
341345

346+
/**
347+
* Check the domain status cluster condition has expected status value.
348+
* @param domainUid Uid of the domain
349+
* @param namespace namespace of the domain
350+
* @param clusterName cluster name of the domain
351+
* @param conditionType the type name of condition, accepted value: Completed, Available, Failed and
352+
* ConfigChangesPendingRestart
353+
* @param expectedStatus the expected value of the status, either True or False
354+
*/
355+
public static void checkDomainStatusClusterConditionTypeHasExpectedStatus(String domainUid,
356+
String namespace,
357+
String clusterName,
358+
String conditionType,
359+
String expectedStatus) {
360+
checkDomainStatusClusterConditionTypeHasExpectedStatus(domainUid, namespace, clusterName,
361+
conditionType, expectedStatus, DOMAIN_VERSION);
362+
}
363+
364+
365+
/**
366+
* Check the domain status cluster condition has expected status value.
367+
* @param domainUid Uid of the domain
368+
* @param namespace namespace of the domain
369+
* @param clusterName cluster name of the domain
370+
* @param conditionType the type name of condition, accepted value: Completed, Available, Failed and
371+
* ConfigChangesPendingRestart
372+
* @param expectedStatus the expected value of the status, either True or False
373+
* @param domainVersion version of domain
374+
*/
375+
public static void checkDomainStatusClusterConditionTypeHasExpectedStatus(String domainUid,
376+
String namespace,
377+
String clusterName,
378+
String conditionType,
379+
String expectedStatus,
380+
String domainVersion) {
381+
testUntil(
382+
withLongRetryPolicy,
383+
domainStatusClustersConditionTypeHasExpectedStatus(domainUid, namespace, clusterName, conditionType,
384+
expectedStatus, domainVersion),
385+
getLogger(),
386+
"domain [{0}] status cluster [{1}] condition type [{2}] has expected status [{3}]",
387+
domainUid,
388+
clusterName,
389+
conditionType,
390+
expectedStatus);
391+
}
392+
393+
/**
394+
* Check the domain status cluster condition has expected status value.
395+
* @param retryPolicy retry policy
396+
* @param domainUid Uid of the domain
397+
* @param namespace namespace of the domain
398+
* @param clusterName cluster name of the domain
399+
* @param conditionType the type name of condition, accepted value: Completed, Available, Failed and
400+
* ConfigChangesPendingRestart
401+
* @param expectedStatus the expected value of the status, either True or False
402+
* @param domainVersion version of domain
403+
*/
404+
public static void checkDomainStatusClusterConditionTypeHasExpectedStatus(ConditionFactory retryPolicy,
405+
String domainUid,
406+
String namespace,
407+
String clusterName,
408+
String conditionType,
409+
String expectedStatus,
410+
String domainVersion) {
411+
testUntil(
412+
retryPolicy,
413+
domainStatusClustersConditionTypeHasExpectedStatus(domainUid, namespace, clusterName, conditionType,
414+
expectedStatus, domainVersion),
415+
getLogger(),
416+
"domain [{0}] status cluster [{1}] condition type [{2}] has expected status [{3}]",
417+
domainUid,
418+
clusterName,
419+
conditionType,
420+
expectedStatus);
421+
}
342422
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonMiiTestUtils.java

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,62 @@ public static DomainResource createMiiDomainAndVerify(
191191
boolean setDataHome,
192192
String dataHome) {
193193

194+
LoggingFacade logger = getLogger();
195+
DomainResource domain =
196+
createMiiDomain(domainNamespace, domainUid, imageName, replicaCount, clusterNames, setDataHome, dataHome);
197+
198+
// check admin server pod is ready
199+
logger.info("Wait for admin server pod {0} to be ready in namespace {1}",
200+
adminServerPodName, domainNamespace);
201+
checkPodReady(adminServerPodName, domainUid, domainNamespace);
202+
203+
// check managed server pods are ready
204+
for (int i = 1; i <= replicaCount; i++) {
205+
logger.info("Wait for managed server pod {0} to be ready in namespace {1}",
206+
managedServerPrefix + i, domainNamespace);
207+
checkPodReady(managedServerPrefix + i, domainUid, domainNamespace);
208+
}
209+
210+
logger.info("Check admin service {0} is created in namespace {1}",
211+
adminServerPodName, domainNamespace);
212+
checkServiceExists(adminServerPodName, domainNamespace);
213+
214+
// check managed server services created
215+
for (int i = 1; i <= replicaCount; i++) {
216+
logger.info("Check managed server service {0} is created in namespace {1}",
217+
managedServerPrefix + i, domainNamespace);
218+
checkServiceExists(managedServerPrefix + i, domainNamespace);
219+
}
220+
221+
return domain;
222+
}
223+
224+
/**
225+
* Create a basic Kubernetes domain resource and verify the domain is created.
226+
*
227+
* @param domainNamespace Kubernetes namespace that the pod is running in
228+
* @param domainUid identifier of the domain
229+
* @param imageName name of the image including its tag
230+
* @param replicaCount number of managed servers to start
231+
* @param clusterNames names of clusters
232+
* @param setDataHome whether to set dataHome in the domain spec
233+
* @param dataHome dataHome override in the domain spec
234+
* @return DomainResource
235+
*/
236+
public static DomainResource createMiiDomain(
237+
String domainNamespace,
238+
String domainUid,
239+
String imageName,
240+
int replicaCount,
241+
List<String> clusterNames,
242+
boolean setDataHome,
243+
String dataHome) {
244+
194245
LoggingFacade logger = getLogger();
195246
// this secret is used only for non-kind cluster
196247
logger.info("Create the repo secret {0} to pull the image", TEST_IMAGES_REPO_SECRET_NAME);
197248
assertDoesNotThrow(() -> createTestRepoSecret(domainNamespace),
198-
String.format("createSecret failed for %s", TEST_IMAGES_REPO_SECRET_NAME));
249+
String.format("createSecret failed for %s", TEST_IMAGES_REPO_SECRET_NAME));
199250

200251
// create secret for admin credentials
201252
logger.info("Create secret for admin credentials");
@@ -239,32 +290,9 @@ public static DomainResource createMiiDomainAndVerify(
239290

240291
createDomainAndVerify(domain, domainNamespace);
241292

242-
// check admin server pod is ready
243-
logger.info("Wait for admin server pod {0} to be ready in namespace {1}",
244-
adminServerPodName, domainNamespace);
245-
checkPodReady(adminServerPodName, domainUid, domainNamespace);
246-
247-
// check managed server pods are ready
248-
for (int i = 1; i <= replicaCount; i++) {
249-
logger.info("Wait for managed server pod {0} to be ready in namespace {1}",
250-
managedServerPrefix + i, domainNamespace);
251-
checkPodReady(managedServerPrefix + i, domainUid, domainNamespace);
252-
}
253-
254-
logger.info("Check admin service {0} is created in namespace {1}",
255-
adminServerPodName, domainNamespace);
256-
checkServiceExists(adminServerPodName, domainNamespace);
257-
258-
// check managed server services created
259-
for (int i = 1; i <= replicaCount; i++) {
260-
logger.info("Check managed server service {0} is created in namespace {1}",
261-
managedServerPrefix + i, domainNamespace);
262-
checkServiceExists(managedServerPrefix + i, domainNamespace);
263-
}
264-
265293
return domain;
266294
}
267-
295+
268296
/**
269297
* Create a domain object for a Kubernetes domain custom resource using the basic model-in-image image.
270298
*
@@ -395,7 +423,8 @@ public static DomainResource createDomainResource(
395423
getLogger().info("!!!Cluster {0} in namespace {1} already exists, skipping...", clusterResName, domNamespace);
396424
} else {
397425
getLogger().info("Creating cluster {0} in namespace {1}", clusterResName, domNamespace);
398-
ClusterSpec spec = new ClusterSpec().withClusterName(clusterName).replicas(replicaCount);
426+
ClusterSpec spec =
427+
new ClusterSpec().withClusterName(clusterName).replicas(replicaCount).serverStartPolicy("IfNeeded");
399428
createClusterAndVerify(createClusterResource(clusterResName, domNamespace, spec));
400429
}
401430
// set cluster references

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonTestUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@
116116
*/
117117
public class CommonTestUtils {
118118

119+
/**
120+
* Create retry policy with parameters.
121+
* @param pollDelaySeconds poll delay in seconds
122+
* @param pollInterval poll interval in seconds
123+
* @param seconds max wait seconds
124+
* @return conditionFactory object of retry policy
125+
*/
126+
public static ConditionFactory createRetryPolicy(int pollDelaySeconds,
127+
int pollInterval,
128+
long seconds) {
129+
return with().pollDelay(pollDelaySeconds, SECONDS)
130+
.and().with().pollInterval(pollInterval, SECONDS)
131+
.atMost(seconds, SECONDS).await();
132+
}
133+
119134
private static ConditionFactory createStandardRetryPolicyWithAtMost(long minutes) {
120135
return with().pollDelay(2, SECONDS)
121136
.and().with().pollInterval(10, SECONDS)

0 commit comments

Comments
 (0)