|
10 | 10 | import java.lang.annotation.RetentionPolicy; |
11 | 11 | import java.lang.annotation.Target; |
12 | 12 | import java.net.http.HttpResponse; |
| 13 | +import java.nio.file.Files; |
13 | 14 | import java.nio.file.Path; |
14 | 15 | import java.nio.file.Paths; |
15 | 16 | import java.time.OffsetDateTime; |
|
39 | 40 | import oracle.weblogic.domain.Domain; |
40 | 41 | import oracle.weblogic.domain.DomainSpec; |
41 | 42 | import oracle.weblogic.domain.ServerPod; |
| 43 | +import oracle.weblogic.kubernetes.actions.impl.primitive.Command; |
| 44 | +import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams; |
42 | 45 | import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams; |
43 | 46 | import oracle.weblogic.kubernetes.annotations.IntegrationTest; |
44 | 47 | import oracle.weblogic.kubernetes.annotations.Namespaces; |
|
61 | 64 | import org.junit.jupiter.api.extension.ExecutionCondition; |
62 | 65 | import org.junit.jupiter.api.extension.ExtendWith; |
63 | 66 | import org.junit.jupiter.api.extension.ExtensionContext; |
| 67 | +import org.junit.jupiter.params.ParameterizedTest; |
| 68 | +import org.junit.jupiter.params.provider.EmptySource; |
| 69 | +import org.junit.jupiter.params.provider.ValueSource; |
64 | 70 |
|
65 | 71 | import static java.util.concurrent.TimeUnit.MINUTES; |
66 | 72 | import static java.util.concurrent.TimeUnit.SECONDS; |
|
78 | 84 | import static oracle.weblogic.kubernetes.TestConstants.WLS_LATEST_IMAGE_TAG; |
79 | 85 | import static oracle.weblogic.kubernetes.TestConstants.WLS_UPDATE_IMAGE_TAG; |
80 | 86 | import static oracle.weblogic.kubernetes.actions.ActionConstants.APP_DIR; |
| 87 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.ITTESTS_DIR; |
81 | 88 | import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR; |
| 89 | +import static oracle.weblogic.kubernetes.actions.ActionConstants.WORK_DIR; |
82 | 90 | import static oracle.weblogic.kubernetes.actions.TestActions.deleteSecret; |
83 | 91 | import static oracle.weblogic.kubernetes.actions.TestActions.execCommand; |
84 | 92 | import static oracle.weblogic.kubernetes.actions.TestActions.getCurrentIntrospectVersion; |
|
121 | 129 | import static oracle.weblogic.kubernetes.utils.TestUtils.verifyServerCommunication; |
122 | 130 | import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger; |
123 | 131 | import static oracle.weblogic.kubernetes.utils.WLSTUtils.executeWLSTScript; |
| 132 | +import static org.apache.commons.io.FileUtils.copyDirectory; |
| 133 | +import static org.apache.commons.io.FileUtils.deleteDirectory; |
124 | 134 | import static org.assertj.core.api.Assertions.assertThat; |
125 | 135 | import static org.awaitility.Awaitility.with; |
126 | 136 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
127 | 137 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 138 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
128 | 139 | import static org.junit.jupiter.api.Assertions.assertNotEquals; |
129 | 140 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
130 | 141 | import static org.junit.jupiter.api.Assertions.assertTrue; |
@@ -152,6 +163,11 @@ public class ItIntrospectVersion { |
152 | 163 |
|
153 | 164 | private Map<String, OffsetDateTime> podsWithTimeStamps = null; |
154 | 165 |
|
| 166 | + private static final String INTROSPECT_DOMAIN_SCRIPT = "introspectDomain.sh"; |
| 167 | + private static final Path samplePath = Paths.get(ITTESTS_DIR, "../kubernetes/samples"); |
| 168 | + private static final Path tempSamplePath = Paths.get(WORK_DIR, "intros-sample-testing"); |
| 169 | + private static final Path domainLifecycleSamplePath = Paths.get(samplePath + "/scripts/domain-lifecycle"); |
| 170 | + |
155 | 171 | // create standard, reusable retry/backoff policy |
156 | 172 | private static final ConditionFactory withStandardRetryPolicy |
157 | 173 | = with().pollDelay(2, SECONDS) |
@@ -203,6 +219,7 @@ public static void initAll(@Namespaces(3) List<String> namespaces) { |
203 | 219 | "Application archive is not available"); |
204 | 220 | clusterViewAppPath = Paths.get(distDir.toString(), "clusterview.war"); |
205 | 221 |
|
| 222 | + setupSample(); |
206 | 223 | } |
207 | 224 |
|
208 | 225 | /** |
@@ -1023,6 +1040,66 @@ public void testDedicatedModeSameNamespaceScale() { |
1023 | 1040 | verifyIntrospectVersionLabelInPod(replicaCount); |
1024 | 1041 | } |
1025 | 1042 |
|
| 1043 | + /** |
| 1044 | + * Rerun a WebLogic domain's introspect job by explicitly initiating the introspection |
| 1045 | + * using the sample script introspectDomain.sh script. |
| 1046 | + * Test that after running introspectDomain.sh w/wo a introspectVersion value specified, |
| 1047 | + * the introspection is explicitly initiating and introspectVersion in the domain is changed. |
| 1048 | + * Use ParameterizedTest to test introspectVersion = "", "v1", "8v", "v.1" |
| 1049 | + * Verify the introspector pod is created and runs |
| 1050 | + * Verifies introspection is changed. |
| 1051 | + * Verifies accessing sample application in admin server works. |
| 1052 | + */ |
| 1053 | + @Order(7) |
| 1054 | + @ParameterizedTest |
| 1055 | + @EmptySource |
| 1056 | + @ValueSource(strings = {"v1", "8v", "v.1"}) |
| 1057 | + @DisplayName("Test to use sample scripts to explicitly initiate introspection") |
| 1058 | + public void testInitiateIntrospection(String introspectVersion) { |
| 1059 | + final String adminServerName = "admin-server"; |
| 1060 | + final String adminServerPodName = domainUid + "-" + adminServerName; |
| 1061 | + final String managedServerNameBase = "managed-server"; |
| 1062 | + String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase; |
| 1063 | + final int replicaCount = 3; |
| 1064 | + |
| 1065 | + // verify admin server pods are ready |
| 1066 | + checkPodReadyAndServiceExists(adminServerPodName, domainUid, introDomainNamespace); |
| 1067 | + // verify managed server pods are ready |
| 1068 | + for (int i = 1; i <= replicaCount; i++) { |
| 1069 | + logger.info("Checking managed server service {0} is created in namespace {1}", |
| 1070 | + managedServerPodNamePrefix + i, introDomainNamespace); |
| 1071 | + checkPodReadyAndServiceExists(managedServerPodNamePrefix + i, domainUid, introDomainNamespace); |
| 1072 | + } |
| 1073 | + |
| 1074 | + // get introspectVersion before running introspectDomain.sh |
| 1075 | + String introspectVersionBf = |
| 1076 | + assertDoesNotThrow(() -> getCurrentIntrospectVersion(domainUid, introDomainNamespace)); |
| 1077 | + |
| 1078 | + // use introspectDomain.sh to initiate introspection |
| 1079 | + logger.info("Initiate introspection with introspectDomain.sh script"); |
| 1080 | + String extraParam = (introspectVersion.isEmpty()) ? "" : " -i " + introspectVersion; |
| 1081 | + |
| 1082 | + assertDoesNotThrow(() -> executeLifecycleScript(INTROSPECT_DOMAIN_SCRIPT, extraParam), |
| 1083 | + String.format("Failed to run %s", INTROSPECT_DOMAIN_SCRIPT)); |
| 1084 | + |
| 1085 | + //verify the introspector pod is created and runs |
| 1086 | + String introspectPodNameBase = getIntrospectJobName(domainUid); |
| 1087 | + checkPodExists(introspectPodNameBase, domainUid, introDomainNamespace); |
| 1088 | + checkPodDoesNotExist(introspectPodNameBase, domainUid, introDomainNamespace); |
| 1089 | + |
| 1090 | + // get introspectVersion after running introspectDomain.sh |
| 1091 | + String introspectVersionAf = |
| 1092 | + assertDoesNotThrow(() -> getCurrentIntrospectVersion(domainUid, introDomainNamespace)); |
| 1093 | + |
| 1094 | + // verify that introspectVersion is changed after running introspectDomain.sh |
| 1095 | + assertFalse(introspectVersionBf.equals(introspectVersionAf), |
| 1096 | + "introspectVersion should change from " + introspectVersionBf + " to " + introspectVersionAf); |
| 1097 | + |
| 1098 | + // verify when a domain resource has spec.introspectVersion configured, |
| 1099 | + // after a cluster is scaled up, new server pods have the label "weblogic.introspectVersion" set as well. |
| 1100 | + verifyIntrospectVersionLabelInPod(replicaCount); |
| 1101 | + } |
| 1102 | + |
1026 | 1103 | /** |
1027 | 1104 | * Create a WebLogic domain on a persistent volume by doing the following. |
1028 | 1105 | * Create a configmap containing WLST script and property file. |
@@ -1192,4 +1269,31 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con |
1192 | 1269 | @interface AssumeWebLogicImage { |
1193 | 1270 | } |
1194 | 1271 |
|
| 1272 | + // copy samples directory to a temporary location |
| 1273 | + private static void setupSample() { |
| 1274 | + assertDoesNotThrow(() -> { |
| 1275 | + logger.info("Deleting and recreating {0}", tempSamplePath); |
| 1276 | + Files.createDirectories(tempSamplePath); |
| 1277 | + deleteDirectory(tempSamplePath.toFile()); |
| 1278 | + Files.createDirectories(tempSamplePath); |
| 1279 | + logger.info("Copying {0} to {1}", samplePath, tempSamplePath); |
| 1280 | + copyDirectory(samplePath.toFile(), tempSamplePath.toFile()); |
| 1281 | + }); |
| 1282 | + } |
| 1283 | + |
| 1284 | + // Function to execute domain lifecyle scripts |
| 1285 | + private String executeLifecycleScript(String script, String extraParams) { |
| 1286 | + String commonParameters = " -d " + domainUid + " -n " + introDomainNamespace + extraParams; |
| 1287 | + CommandParams params = new CommandParams().defaults(); |
| 1288 | + |
| 1289 | + params.command("sh " |
| 1290 | + + Paths.get(domainLifecycleSamplePath.toString(), "/" + script).toString() |
| 1291 | + + commonParameters); |
| 1292 | + |
| 1293 | + ExecResult execResult = Command.withParams(params).executeAndReturnResult(); |
| 1294 | + assertEquals(0, execResult.exitValue(), |
| 1295 | + String.format("Failed to execute script %s ", script)); |
| 1296 | + |
| 1297 | + return execResult.toString(); |
| 1298 | + } |
1195 | 1299 | } |
0 commit comments