Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@
import oracle.weblogic.domain.Istio;
import oracle.weblogic.domain.Model;
import oracle.weblogic.domain.ServerPod;
import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams;
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
import oracle.weblogic.kubernetes.annotations.Namespaces;
import oracle.weblogic.kubernetes.logging.LoggingFacade;
import oracle.weblogic.kubernetes.utils.BuildApplication;
import oracle.weblogic.kubernetes.utils.ExecCommand;
import oracle.weblogic.kubernetes.utils.ExecResult;
import org.awaitility.core.ConditionFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE;
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_API_VERSION;
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
import static oracle.weblogic.kubernetes.TestConstants.MANAGED_SERVER_NAME_BASE;
Expand All @@ -46,6 +43,8 @@
import static oracle.weblogic.kubernetes.actions.TestActions.addLabelsToNamespace;
import static oracle.weblogic.kubernetes.actions.TestActions.createDomainCustomResource;
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.callWebAppAndWaitTillReady;
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createAndPushMiiImage;
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createMiiDomainWithIstioMultiClusters;
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists;
import static oracle.weblogic.kubernetes.utils.FileUtils.generateFileFromTemplate;
import static oracle.weblogic.kubernetes.utils.ImageUtils.createImageAndVerify;
Expand All @@ -58,7 +57,6 @@
import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity;
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
import static org.awaitility.Awaitility.with;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -76,25 +74,25 @@ class ItIstioManagedCoherence {

// constants for creating domain image using model in image
private static final String COHERENCE_MODEL_FILE = "coherence-managed-wdt-config.yaml";
private static final String MII_COHERENCE_MODEL_FILE = "coherence-managed-wdt-config-mii.yaml";
private static final String COHERENCE_MODEL_PROP = "coherence-managed-wdt-config.properties";
private static final String COHERENCE_IMAGE_NAME = "coherence-managed-image";

// constants for WebLogic domain
private static final String domainUid = "coherence-managed-domain";
private static final int NUMBER_OF_CLUSTERS = 2;
private static final String CLUSTER_NAME_PREFIX = "cluster-";
private static final int MANAGED_SERVER_PORT = 8001;
private static final int replicaCount = 2;
private static String adminServerPodName = domainUid + "-admin-server";
private static String cluster1Hostname = null;
private static String cluster2Hostname = null;
private static final String miiImageName = "mii-image";
private static final String miiDomainUid = "miidomain";

private static String opNamespace = null;
private static String domainNamespace = null;
private static ConditionFactory withStandardRetryPolicy = null;
private static String domainInImageNamespace = null;
private static String miiDomainNamespace = null;
private static String miiImage = null;
private static String encryptionSecretName = "encryptionsecret";

private static boolean enableValidatingWebhook = false;
private static HelmParams voyagerHelmParams = null;
private static LoggingFacade logger = null;

/**
Expand All @@ -108,36 +106,37 @@ class ItIstioManagedCoherence {
* JUnit engine parameter resolution mechanism
*/
@BeforeAll
public static void init(@Namespaces(2) List<String> namespaces) {
public static void init(@Namespaces(3) List<String> namespaces) {
logger = getLogger();
// create standard, reusable retry/backoff policy
withStandardRetryPolicy = with().pollDelay(2, SECONDS)
.and().with().pollInterval(10, SECONDS)
.atMost(5, MINUTES).await();

// get a new unique opNamespace
logger.info("Assigning a unique namespace for Operator");
assertNotNull(namespaces.get(0), "Namespace list is null");
opNamespace = namespaces.get(0);

// get a new unique domainNamespace
logger.info("Assigning a unique namespace for Domain");
// get a new unique namespace for domain-in-image domain
logger.info("Assigning a unique namespace for domain-in-image Domain");
assertNotNull(namespaces.get(1), "Namespace list is null");
domainNamespace = namespaces.get(1);
domainInImageNamespace = namespaces.get(1);

// get a new unique namespace for model-in-image domain
logger.info("Assigning a unique namespace for model-in-image Domain");
assertNotNull(namespaces.get(2), "Namespace list is null");
miiDomainNamespace = namespaces.get(2);


// Label the domain/operator namespace with istio-injection=enabled
Map<String, String> labelMap = new HashMap();
labelMap.put("istio-injection", "enabled");
assertDoesNotThrow(() -> addLabelsToNamespace(domainNamespace,labelMap));
assertDoesNotThrow(() -> addLabelsToNamespace(opNamespace,labelMap));
assertDoesNotThrow(() -> addLabelsToNamespace(domainInImageNamespace, labelMap));
assertDoesNotThrow(() -> addLabelsToNamespace(miiDomainNamespace, labelMap));
assertDoesNotThrow(() -> addLabelsToNamespace(opNamespace, labelMap));

// install and verify operator
installAndVerifyOperator(opNamespace, domainNamespace);
installAndVerifyOperator(opNamespace, domainInImageNamespace, miiDomainNamespace);

// build Coherence applications
Path distDir = BuildApplication.buildApplication(Paths.get(APP_DIR, COHERENCE_APP_NAME),
null, null, "builddir", domainNamespace);
null, null, "builddir", domainInImageNamespace);
Path coherenceAppGarPath = Paths.get(distDir.toString(), COHERENCE_APP_NAME + ".gar");
Path coherenceAppEarPath = Paths.get(distDir.toString(), COHERENCE_APP_NAME + ".ear");
assertTrue(coherenceAppGarPath.toFile().exists(), "Application archive is not available");
Expand All @@ -147,16 +146,17 @@ public static void init(@Namespaces(2) List<String> namespaces) {
}

/**
* Create domain with two clusters, cluster-1 and cluster-2.
* Create domain-in-image domain with two clusters, cluster-1 and cluster-2.
* Associate them with a Coherence cluster
* Deploy the EAR file to cluster-1 that has no storage enabled
* Deploy the GAR file to cluster-2 that has storage enabled
* Verify that data can be added and stored in the cache
* and can also be retrieved from cache.
*/
@Test
@DisplayName("Two cluster domain with a Coherence cluster with ISTIO and test interaction with cache data")
void testIstioMultiClusterCoherenceDomain() {
@DisplayName("Two cluster domain-in-image domain with a Coherence cluster with ISTIO and "
+ "test interaction with cache data")
void testIstioMultiClusterCoherenceDomainInImageDomain() {

// create a DomainHomeInImage image using WebLogic Image Tool
String domImage = createAndVerifyDomainImage();
Expand All @@ -166,9 +166,9 @@ void testIstioMultiClusterCoherenceDomain() {

String clusterService = domainUid + "-cluster-cluster-1";
Map<String, String> templateMap = new HashMap();
templateMap.put("NAMESPACE", domainNamespace);
templateMap.put("NAMESPACE", domainInImageNamespace);
templateMap.put("DUID", domainUid);
templateMap.put("ADMIN_SERVICE",adminServerPodName);
templateMap.put("ADMIN_SERVICE", adminServerPodName);
templateMap.put("CLUSTER_SERVICE", clusterService);

Path srcHttpFile = Paths.get(RESOURCE_DIR, "istio", "istio-coh-http-template.yaml");
Expand All @@ -195,52 +195,100 @@ void testIstioMultiClusterCoherenceDomain() {
assertTrue(testCompletedSuccessfully, "Test Coherence cache failed");
}


/**
* Create model-in-image domain with two clusters, cluster-1 and cluster-2.
* Associate them with a Coherence cluster
* Deploy the EAR file to cluster-1 that has no storage enabled
* Deploy the GAR file to cluster-2 that has storage enabled
* Verify that data can be added and stored in the cache
* and can also be retrieved from cache.
*/
@Test
@DisplayName("Two cluster mii domain with a Coherence cluster with ISTIO and test interaction with cache data")
void testIstioMultiClusterCoherenceMiiDomain() {

// create a model-in-image domain image using WebLogic Image Tool
miiImage = createAndPushMiiImage(miiImageName, MII_COHERENCE_MODEL_FILE, COHERENCE_APP_NAME, COHERENCE_MODEL_PROP);

// create and verify a two-clusters WebLogic domain with a Coherence cluster
createMiiDomainWithIstioMultiClusters(miiDomainUid, miiDomainNamespace, miiImage, NUMBER_OF_CLUSTERS, replicaCount);

Map<String, String> templateMap = new HashMap();
templateMap.put("NAMESPACE", miiDomainNamespace);
templateMap.put("DUID", miiDomainUid);
templateMap.put("ADMIN_SERVICE", miiDomainUid + "-" + ADMIN_SERVER_NAME_BASE);
templateMap.put("CLUSTER_SERVICE", miiDomainUid + "-cluster-cluster-1");

Path srcHttpFile = Paths.get(RESOURCE_DIR, "istio", "istio-coh-http-template.yaml");
Path targetHttpFile = assertDoesNotThrow(
() -> generateFileFromTemplate(srcHttpFile.toString(), "istio-http.yaml", templateMap));
logger.info("Generated Http VS/Gateway file path is {0}", targetHttpFile);

boolean deployRes = assertDoesNotThrow(
() -> deployHttpIstioGatewayAndVirtualservice(targetHttpFile));
assertTrue(deployRes, "Failed to deploy Http Istio Gateway/VirtualService");

int istioIngressPort = getIstioHttpIngressPort();
logger.info("Istio Ingress Port is {0}", istioIngressPort);

// Make sure ready app is accessible thru Istio Ingress Port
String curlCmd = "curl --silent --show-error --noproxy '*' http://" + K8S_NODEPORT_HOST + ":" + istioIngressPort
+ "/weblogic/ready --write-out %{http_code} -o /dev/null";
logger.info("Executing curl command {0}", curlCmd);
assertTrue(callWebAppAndWaitTillReady(curlCmd, 60));

// test adding data to the cache and retrieving them from the cache
boolean testCompletedSuccessfully = assertDoesNotThrow(()
-> coherenceCacheTest(istioIngressPort), "Test Coherence cache failed");
assertTrue(testCompletedSuccessfully, "Test Coherence cache failed");
}

private static String createAndVerifyDomainImage() {
// create image with model files
logger.info("Create image with model file and verify");
String domImage = createImageAndVerify(
COHERENCE_IMAGE_NAME, COHERENCE_MODEL_FILE,
COHERENCE_APP_NAME, COHERENCE_MODEL_PROP, domainUid);
COHERENCE_APP_NAME, COHERENCE_MODEL_PROP, domainUid);

// docker login and push image to docker registry if necessary
dockerLoginAndPushImageToRegistry(domImage);

// create docker registry secret to pull the image from registry
// this secret is used only for non-kind cluster
logger.info("Create docker registry secret in namespace {0}", domainNamespace);
createOcirRepoSecret(domainNamespace);
logger.info("Create docker registry secret in namespace {0}", domainInImageNamespace);
createOcirRepoSecret(domainInImageNamespace);
return domImage;
}

private static void createAndVerifyDomain(String domImage) {
// create secret for admin credentials
logger.info("Create secret for admin credentials");
String adminSecretName = "weblogic-credentials";
assertDoesNotThrow(() -> createSecretWithUsernamePassword(adminSecretName, domainNamespace,
assertDoesNotThrow(() -> createSecretWithUsernamePassword(adminSecretName, domainInImageNamespace,
"weblogic", "welcome1"),
String.format("create secret for admin credentials failed for %s", adminSecretName));

// create encryption secret
logger.info("Create encryption secret");
String encryptionSecretName = "encryptionsecret";
assertDoesNotThrow(() -> createSecretWithUsernamePassword(encryptionSecretName, domainNamespace,
assertDoesNotThrow(() -> createSecretWithUsernamePassword(encryptionSecretName, domainInImageNamespace,
"weblogicenc", "weblogicenc"),
String.format("create encryption secret failed for %s", encryptionSecretName));

// create domain and verify
logger.info("Create model in image domain {0} in namespace {1} using docker image {2}",
domainUid, domainNamespace, domImage);
domainUid, domainInImageNamespace, domImage);
createDomainCrAndVerify(adminSecretName, domImage);

// check that admin service exists in the domain namespace
logger.info("Checking that admin service {0} exists in namespace {1}",
adminServerPodName, domainNamespace);
checkServiceExists(adminServerPodName, domainNamespace);
adminServerPodName, domainInImageNamespace);
checkServiceExists(adminServerPodName, domainInImageNamespace);

// check that admin server pod is ready
logger.info("Checking that admin server pod {0} is ready in namespace {1}",
adminServerPodName, domainNamespace);
checkPodReady(adminServerPodName, domainUid, domainNamespace);
adminServerPodName, domainInImageNamespace);
checkPodReady(adminServerPodName, domainUid, domainInImageNamespace);

// check the readiness for the managed servers in each cluster
for (int i = 1; i <= NUMBER_OF_CLUSTERS; i++) {
Expand All @@ -250,13 +298,13 @@ private static void createAndVerifyDomain(String domImage) {

// check that the managed server service exists in the domain namespace
logger.info("Checking that managed server service {0} exists in namespace {1}",
managedServerPodName, domainNamespace);
checkServiceExists(managedServerPodName, domainNamespace);
managedServerPodName, domainInImageNamespace);
checkServiceExists(managedServerPodName, domainInImageNamespace);

// check that the managed server pod is ready
logger.info("Checking that managed server pod {0} is ready in namespace {1}",
managedServerPodName, domainNamespace);
checkPodReady(managedServerPodName, domainUid, domainNamespace);
managedServerPodName, domainInImageNamespace);
checkPodReady(managedServerPodName, domainUid, domainInImageNamespace);
}
}
}
Expand All @@ -277,7 +325,7 @@ private static void createDomainCrAndVerify(String adminSecretName, String domIm
.kind("Domain")
.metadata(new V1ObjectMeta()
.name(domainUid)
.namespace(domainNamespace))
.namespace(domainInImageNamespace))
.spec(new DomainSpec()
.domainUid(domainUid)
.domainHomeSourceType("Image")
Expand All @@ -286,7 +334,7 @@ private static void createDomainCrAndVerify(String adminSecretName, String domIm
.name(OCIR_SECRET_NAME))
.webLogicCredentialsSecret(new V1SecretReference()
.name(adminSecretName)
.namespace(domainNamespace))
.namespace(domainInImageNamespace))
.includeServerOutInPodLog(true)
.serverStartPolicy("IF_NEEDED")
.serverPod(new ServerPod()
Expand All @@ -308,12 +356,12 @@ private static void createDomainCrAndVerify(String adminSecretName, String domIm
.introspectorJobActiveDeadlineSeconds(300L)));
setPodAntiAffinity(domain);
logger.info("Create domain custom resource for domainUid {0} in namespace {1}",
domainUid, domainNamespace);
domainUid, domainInImageNamespace);
boolean domCreated = assertDoesNotThrow(() -> createDomainCustomResource(domain),
String.format("Create domain custom resource failed with ApiException for %s in namespace %s",
domainUid, domainNamespace));
domainUid, domainInImageNamespace));
assertTrue(domCreated, String.format("Create domain custom resource failed with ApiException "
+ "for %s in namespace %s", domainUid, domainNamespace));
+ "for %s in namespace %s", domainUid, domainInImageNamespace));
}

private boolean coherenceCacheTest(int ingressServiceNodePort) {
Expand Down Expand Up @@ -442,4 +490,5 @@ private ExecResult clearCache(String hostAndPort) {

return result;
}

}
Loading