Skip to content

Commit bb47365

Browse files
authored
v8o: Add a testcase to use auxilary image in MII domain (#4086)
1 parent 7257d59 commit bb47365

File tree

2 files changed

+243
-26
lines changed

2 files changed

+243
-26
lines changed

integration-tests/src/test/java/oracle/verrazzano/weblogic/kubernetes/ItVzMiiDomain.java

Lines changed: 234 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
package oracle.verrazzano.weblogic.kubernetes;
55

6+
import java.util.ArrayList;
67
import java.util.Arrays;
8+
import java.util.Collections;
79
import java.util.HashMap;
810
import java.util.List;
911
import java.util.Map;
@@ -25,6 +27,9 @@
2527
import oracle.verrazzano.weblogic.WorkloadSpec;
2628
import oracle.verrazzano.weblogic.kubernetes.annotations.VzIntegrationTest;
2729
import oracle.weblogic.domain.DomainResource;
30+
import oracle.weblogic.kubernetes.actions.impl.primitive.Command;
31+
import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams;
32+
import oracle.weblogic.kubernetes.actions.impl.primitive.WitParams;
2833
import oracle.weblogic.kubernetes.annotations.Namespaces;
2934
import oracle.weblogic.kubernetes.logging.LoggingFacade;
3035
import org.junit.jupiter.api.BeforeAll;
@@ -33,16 +38,32 @@
3338
import org.junit.jupiter.api.Test;
3439

3540
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
41+
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE;
3642
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
43+
import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE;
44+
import static oracle.weblogic.kubernetes.TestConstants.MII_AUXILIARY_IMAGE_NAME;
45+
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME;
3746
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
3847
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
48+
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_WDT_MODEL_FILE;
3949
import static oracle.weblogic.kubernetes.TestConstants.TEST_IMAGES_REPO_SECRET_NAME;
50+
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TO_USE_IN_SPEC;
51+
import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR;
52+
import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
53+
import static oracle.weblogic.kubernetes.actions.TestActions.buildAppArchive;
54+
import static oracle.weblogic.kubernetes.actions.TestActions.defaultAppParams;
4055
import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.createApplication;
4156
import static oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes.createComponent;
57+
import static oracle.weblogic.kubernetes.utils.AuxiliaryImageUtils.createAndPushAuxiliaryImage;
58+
import static oracle.weblogic.kubernetes.utils.AuxiliaryImageUtils.createPushAuxiliaryImageWithDomainConfig;
59+
import static oracle.weblogic.kubernetes.utils.ClusterUtils.createClusterResourceAndAddReferenceToDomain;
4260
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createDomainResource;
61+
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createDomainResourceWithAuxiliaryImage;
4362
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
63+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
4464
import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret;
4565
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
66+
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretsForImageRepos;
4667
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
4768
import static oracle.weblogic.kubernetes.utils.VerrazzanoUtils.getIstioHost;
4869
import static oracle.weblogic.kubernetes.utils.VerrazzanoUtils.getLoadbalancerAddress;
@@ -53,29 +74,30 @@
5374
import static org.junit.jupiter.api.Assertions.assertTrue;
5475

5576
// Test to create model in image domain and verify the domain started successfully
56-
5777
@DisplayName("Test to a create model in image domain and start the domain in verrazzano")
5878
@VzIntegrationTest
5979
@Tag("v8o")
6080
class ItVzMiiDomain {
61-
81+
6282
private static String domainNamespace = null;
83+
private static String auxDomainNamespace = null;
6384
private final String domainUid = "domain1";
6485
private static LoggingFacade logger = null;
65-
6686

6787
/**
6888
* Label domain namespace.
69-
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the
70-
JUnit engine parameter resolution mechanism
89+
*
90+
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the JUnit engine parameter resolution
91+
* mechanism
7192
*/
7293
@BeforeAll
73-
public static void initAll(@Namespaces(1) List<String> namespaces) throws Exception {
94+
public static void initAll(@Namespaces(2) List<String> namespaces) throws Exception {
7495
logger = getLogger();
7596
logger.info("Getting unique namespace for Domain");
7697
assertNotNull(namespaces.get(0), "Namespace list is null");
7798
domainNamespace = namespaces.get(0);
78-
setLabelToNamespace(domainNamespace);
99+
auxDomainNamespace = namespaces.get(1);
100+
setLabelToNamespace(Arrays.asList(domainNamespace, auxDomainNamespace));
79101
}
80102

81103
/**
@@ -98,17 +120,17 @@ void testCreateVzMiiDomain() {
98120
logger.info("Create secret for admin credentials");
99121
String adminSecretName = "weblogic-credentials";
100122
createSecretWithUsernamePassword(adminSecretName, domainNamespace,
101-
ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);
123+
ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);
102124

103125
// create encryption secret
104126
logger.info("Create encryption secret");
105127
String encryptionSecretName = "encryptionsecret";
106128
createSecretWithUsernamePassword(encryptionSecretName, domainNamespace,
107-
"weblogicenc", "weblogicenc");
129+
"weblogicenc", "weblogicenc");
108130

109131
// create cluster object
110132
String clusterName = "cluster-1";
111-
133+
112134
DomainResource domain = createDomainResource(domainUid, domainNamespace,
113135
MII_BASIC_IMAGE_NAME + ":" + MII_BASIC_IMAGE_TAG,
114136
adminSecretName, new String[]{TEST_IMAGES_REPO_SECRET_NAME},
@@ -126,11 +148,11 @@ void testCreateVzMiiDomain() {
126148
.kind("VerrazzanoWebLogicWorkload")
127149
.spec(new WorkloadSpec()
128150
.template(domain))));
129-
151+
130152
Map<String, String> keyValueMap = new HashMap<>();
131-
keyValueMap.put("version", "v1.0.0");
153+
keyValueMap.put("version", "v1.0.0");
132154
keyValueMap.put("description", "My vz wls application");
133-
155+
134156
ApplicationConfiguration application = new ApplicationConfiguration()
135157
.apiVersion("core.oam.dev/v1alpha2")
136158
.kind("ApplicationConfiguration")
@@ -164,12 +186,12 @@ void testCreateVzMiiDomain() {
164186
.destination(new Destination()
165187
.host(domainUid + "-cluster-" + clusterName)
166188
.port(8001)))))))))));
167-
189+
168190
logger.info(Yaml.dump(component));
169191
logger.info(Yaml.dump(application));
170-
192+
171193
logger.info("Deploying components");
172-
assertDoesNotThrow(() -> createComponent(component));
194+
assertDoesNotThrow(() -> createComponent(component));
173195
logger.info("Deploying application");
174196
assertDoesNotThrow(() -> createApplication(application));
175197

@@ -183,7 +205,7 @@ void testCreateVzMiiDomain() {
183205
managedServerPrefix + i, domainNamespace);
184206
checkPodReadyAndServiceExists(managedServerPrefix + i, domainUid, domainNamespace);
185207
}
186-
208+
187209
// get istio gateway host and loadbalancer address
188210
String host = getIstioHost(domainNamespace);
189211
String address = getLoadbalancerAddress();
@@ -197,7 +219,202 @@ void testCreateVzMiiDomain() {
197219
message = "Hello World, you have reached server managed-server";
198220
String appUrl = "https://" + host + "/sample-war/index.jsp --resolve " + host + ":443:" + address;
199221
assertTrue(verifyVzApplicationAccess(appUrl, message), "Failed to get access to sample application");
222+
223+
}
224+
225+
/**
226+
* Create a WebLogic domain VerrazzanoWebLogicWorkload component in verrazzano with auxilary images.
227+
*/
228+
@Test
229+
@DisplayName("Verrazzano mii domain with auxilary image")
230+
void testVzMiiAuxilaryImage() {
231+
String auxDomainUid = "aux-domain";
232+
String miiAuxiliaryImage1Tag = "image1" + MII_BASIC_IMAGE_TAG;
233+
String miiAuxiliaryImage1 = MII_AUXILIARY_IMAGE_NAME + ":" + miiAuxiliaryImage1Tag;
234+
String miiAuxiliaryImage2Tag = "image2" + MII_BASIC_IMAGE_TAG;
235+
String miiAuxiliaryImage2 = MII_AUXILIARY_IMAGE_NAME + ":" + miiAuxiliaryImage2Tag;
200236

237+
final int replicaCount = 2;
238+
final String adminServerPodName = auxDomainUid + "-" + ADMIN_SERVER_NAME_BASE;
239+
final String managedServerPrefix = auxDomainUid + "-" + MANAGED_SERVER_NAME_BASE;
240+
241+
String adminSecretName = "weblogic-credentials";
242+
String encryptionSecretName = "encryptionsecret";
243+
244+
// create secret for admin credentials
245+
logger.info("Create secret for admin credentials");
246+
createSecretWithUsernamePassword(adminSecretName, auxDomainNamespace,
247+
ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT);
248+
249+
// create encryption secret
250+
logger.info("Create encryption secret");
251+
createSecretWithUsernamePassword(encryptionSecretName, auxDomainNamespace,
252+
"weblogicenc", "weblogicenc");
253+
254+
// build app
255+
assertTrue(buildAppArchive(defaultAppParams()
256+
.srcDirList(Collections.singletonList(MII_BASIC_APP_NAME))
257+
.appName(MII_BASIC_APP_NAME)),
258+
String.format("Failed to create app archive for %s", MII_BASIC_APP_NAME));
259+
260+
// image1 with model files for domain config, ds, app and wdt install files
261+
List<String> archiveList = Collections.singletonList(ARCHIVE_DIR + "/" + MII_BASIC_APP_NAME + ".zip");
262+
263+
List<String> modelList = new ArrayList<>();
264+
modelList.add(MODEL_DIR + "/" + MII_BASIC_WDT_MODEL_FILE);
265+
modelList.add(MODEL_DIR + "/multi-model-one-ds.20.yaml");
266+
createPushAuxiliaryImageWithDomainConfig(MII_AUXILIARY_IMAGE_NAME, miiAuxiliaryImage1Tag, archiveList, modelList);
267+
// image2 with model files for jms config
268+
modelList = new ArrayList<>();
269+
modelList.add(MODEL_DIR + "/model.jms2.yaml");
270+
WitParams witParams
271+
= new WitParams()
272+
.modelImageName(MII_AUXILIARY_IMAGE_NAME)
273+
.modelImageTag(miiAuxiliaryImage2Tag)
274+
.wdtModelOnly(true)
275+
.modelFiles(modelList)
276+
.wdtVersion("NONE");
277+
createAndPushAuxiliaryImage(MII_AUXILIARY_IMAGE_NAME, miiAuxiliaryImage2Tag, witParams);
278+
279+
// admin/managed server name here should match with model yaml
280+
String auxiliaryImagePath = "/auxiliary";
281+
String clusterName = "cluster-1";
282+
283+
// create domain custom resource using 2 auxiliary images
284+
logger.info("Creating domain custom resource with domainUid {0} and auxiliary images {1} {2}",
285+
auxDomainUid, miiAuxiliaryImage1, miiAuxiliaryImage2);
286+
DomainResource domainCR = createDomainResourceWithAuxiliaryImage(
287+
auxDomainUid, auxDomainNamespace, WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName,
288+
createSecretsForImageRepos(auxDomainNamespace), encryptionSecretName, auxiliaryImagePath,
289+
miiAuxiliaryImage1, miiAuxiliaryImage2);
290+
291+
domainCR = createClusterResourceAndAddReferenceToDomain(
292+
auxDomainUid + "-" + clusterName, clusterName, auxDomainNamespace, domainCR, replicaCount);
293+
294+
Component component = new Component()
295+
.apiVersion("core.oam.dev/v1alpha2")
296+
.kind("Component")
297+
.metadata(new V1ObjectMeta()
298+
.name(auxDomainUid)
299+
.namespace(auxDomainNamespace))
300+
.spec(new ComponentSpec()
301+
.workLoad(new Workload()
302+
.apiVersion("oam.verrazzano.io/v1alpha1")
303+
.kind("VerrazzanoWebLogicWorkload")
304+
.spec(new WorkloadSpec()
305+
.template(domainCR))));
306+
307+
Map<String, String> keyValueMap = new HashMap<>();
308+
keyValueMap.put("version", "v1.0.0");
309+
keyValueMap.put("description", "My vz wls application");
310+
311+
ApplicationConfiguration application = new ApplicationConfiguration()
312+
.apiVersion("core.oam.dev/v1alpha2")
313+
.kind("ApplicationConfiguration")
314+
.metadata(new V1ObjectMeta()
315+
.name("myvzauxdomain")
316+
.namespace(auxDomainNamespace)
317+
.annotations(keyValueMap))
318+
.spec(new ApplicationConfigurationSpec()
319+
.components(Arrays.asList(new Components()
320+
.componentName(auxDomainUid)
321+
.traits(Arrays.asList(new IngressTraits()
322+
.trait(new IngressTrait()
323+
.apiVersion("oam.verrazzano.io/v1alpha1")
324+
.kind("IngressTrait")
325+
.metadata(new V1ObjectMeta()
326+
.name("myauxdomain-ingress")
327+
.namespace(auxDomainNamespace))
328+
.spec(new IngressTraitSpec()
329+
.ingressRules(Arrays.asList(
330+
new IngressRule()
331+
.paths(Arrays.asList(new Path()
332+
.path("/console")
333+
.pathType("Prefix")))
334+
.destination(new Destination()
335+
.host(adminServerPodName)
336+
.port(7001)),
337+
new IngressRule()
338+
.paths(Arrays.asList(new Path()
339+
.path("/management")
340+
.pathType("Prefix")))
341+
.destination(new Destination()
342+
.host(adminServerPodName)
343+
.port(7001)),
344+
new IngressRule()
345+
.paths(Arrays.asList(new Path()
346+
.path("/sample-war")
347+
.pathType("Prefix")))
348+
.destination(new Destination()
349+
.host(auxDomainUid + "-cluster-" + clusterName)
350+
.port(8001)))))))))));
351+
352+
logger.info(Yaml.dump(component));
353+
logger.info(Yaml.dump(application));
354+
355+
logger.info("Deploying components");
356+
assertDoesNotThrow(() -> createComponent(component));
357+
logger.info("Deploying application");
358+
assertDoesNotThrow(() -> createApplication(application));
359+
360+
// check admin server pod is ready
361+
logger.info("Wait for admin server pod {0} to be ready in namespace {1}",
362+
adminServerPodName, auxDomainNamespace);
363+
checkPodReadyAndServiceExists(adminServerPodName, auxDomainUid, auxDomainNamespace);
364+
// check managed server pods are ready
365+
for (int i = 1; i <= replicaCount; i++) {
366+
logger.info("Wait for managed server pod {0} to be ready in namespace {1}",
367+
managedServerPrefix + i, auxDomainNamespace);
368+
checkPodReadyAndServiceExists(managedServerPrefix + i, auxDomainUid, auxDomainNamespace);
369+
}
370+
371+
// get istio gateway host and loadbalancer address
372+
String host = getIstioHost(auxDomainNamespace);
373+
String address = getLoadbalancerAddress();
374+
375+
// verify WebLogic console page is accessible through istio/loadbalancer
376+
String message = "Oracle WebLogic Server Administration Console";
377+
String consoleUrl = "https://" + host + "/console/login/LoginForm.jsp --resolve " + host + ":443:" + address;
378+
assertTrue(verifyVzApplicationAccess(consoleUrl, message), "Failed to get WebLogic administration console");
379+
380+
// verify sample running in cluster is accessible through istio/loadbalancer
381+
message = "Hello World, you have reached server managed-server";
382+
String appUrl = "https://" + host + "/sample-war/index.jsp --resolve " + host + ":443:" + address;
383+
assertTrue(verifyVzApplicationAccess(appUrl, message), "Failed to get access to sample application");
384+
385+
// check configuration for JMS
386+
testUntil(
387+
() -> checkSystemResourceConfiguration(auxDomainNamespace, "JMSSystemResources",
388+
"TestClusterJmsModule2", "200"),
389+
logger,
390+
"Checking for TestClusterJmsModule2 in JMSSystemResources resourceName exists");
391+
logger.info("Found the TestClusterJmsModule2 configuration");
392+
201393
}
202394

395+
private static boolean checkSystemResourceConfiguration(String namespace, String resourcesType,
396+
String resourcesName, String expectedStatusCode) {
397+
// get istio gateway host and loadbalancer address
398+
String host = getIstioHost(namespace);
399+
String address = getLoadbalancerAddress();
400+
401+
StringBuffer curlString = new StringBuffer("status=$(curl -k --user ");
402+
curlString.append(ADMIN_USERNAME_DEFAULT + ":" + ADMIN_PASSWORD_DEFAULT)
403+
.append(" https://" + host)
404+
.append("/management/weblogic/latest/domainConfig")
405+
.append("/")
406+
.append(resourcesType)
407+
.append("/")
408+
.append(resourcesName)
409+
.append("/ --resolve " + host + ":443:" + address)
410+
.append(" --silent --show-error ")
411+
.append(" -o /dev/null ")
412+
.append(" -w %{http_code});")
413+
.append("echo ${status}");
414+
logger.info("checkSystemResource: curl command {0}", new String(curlString));
415+
return Command
416+
.withParams(new CommandParams()
417+
.command(curlString.toString()))
418+
.executeAndVerify(expectedStatusCode);
419+
}
203420
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
package oracle.weblogic.kubernetes.utils;
55

6+
import java.util.List;
67
import java.util.Map;
78
import java.util.concurrent.TimeUnit;
89

910
import io.kubernetes.client.openapi.ApiException;
1011
import io.kubernetes.client.openapi.models.V1Namespace;
11-
import io.kubernetes.client.util.Yaml;
1212
import oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes;
1313
import oracle.weblogic.kubernetes.logging.LoggingFacade;
1414

@@ -30,21 +30,21 @@ public class VerrazzanoUtils {
3030
/**
3131
* set labels to domain namespace for the WKO to manage it through namespace label selection strategy.
3232
*
33-
* @param domainNS domain namespace to label
33+
* @param namespaces list of domain namespace to label
3434
* @throws ApiException throws exception when label cannot be set
3535
*/
36-
public static void setLabelToNamespace(String domainNS) throws ApiException {
36+
public static void setLabelToNamespace(List<String> namespaces) throws ApiException {
3737
//add label to domain namespace
3838
assertDoesNotThrow(() -> TimeUnit.MINUTES.sleep(1));
3939
Map<String, String> labels = new java.util.HashMap<>();
4040
labels.put("verrazzano-managed", "true");
4141
labels.put("istio-injection", "enabled");
42-
V1Namespace namespaceObject = assertDoesNotThrow(() -> Kubernetes.getNamespace(domainNS));
43-
logger.info(Yaml.dump(namespaceObject));
44-
assertNotNull(namespaceObject, "Can't find namespace with name " + domainNS);
45-
namespaceObject.getMetadata().setLabels(labels);
46-
assertDoesNotThrow(() -> replaceNamespace(namespaceObject));
47-
logger.info(Yaml.dump(Kubernetes.getNamespace(domainNS)));
42+
for (String namespace : namespaces) {
43+
V1Namespace namespaceObject = assertDoesNotThrow(() -> Kubernetes.getNamespace(namespace));
44+
assertNotNull(namespaceObject, "Can't find namespace with name " + namespace);
45+
namespaceObject.getMetadata().setLabels(labels);
46+
assertDoesNotThrow(() -> replaceNamespace(namespaceObject));
47+
}
4848
}
4949

5050
/**

0 commit comments

Comments
 (0)