Skip to content

Commit 136e95c

Browse files
committed
Execute proxy client on the admin VM
1 parent 05a0885 commit 136e95c

File tree

9 files changed

+237
-97
lines changed

9 files changed

+237
-97
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ITCoherenceTests.java

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
package oracle.kubernetes.operator;
66

77
import java.util.Map;
8-
import oracle.kubernetes.operator.utils.CoherenceUtils;
98
import oracle.kubernetes.operator.utils.Domain;
10-
import oracle.kubernetes.operator.utils.K8sTestUtils;
119
import oracle.kubernetes.operator.utils.Operator;
1210
import oracle.kubernetes.operator.utils.TestUtils;
1311
import org.junit.AfterClass;
1412
import org.junit.Assert;
1513
import org.junit.Assume;
1614
import org.junit.BeforeClass;
1715
import org.junit.FixMethodOrder;
18-
import org.junit.Ignore;
1916
import org.junit.Test;
2017
import org.junit.runners.MethodSorters;
2118
/**
@@ -28,9 +25,14 @@ public class ITCoherenceTests extends BaseTest {
2825

2926
private static Domain domain = null;
3027
private static Operator operator1;
31-
private static String domainUid = "";
32-
private static String restartTmpDir = "";
33-
private static String originalYaml;
28+
29+
private static final String testAppName = "coherence-proxy-client";
30+
31+
private static final String PROXY_CLIENT_SCRIPT = "buildRunProxyClient.sh";
32+
private static final String PROXY_CLIENT_APP_NAME = "coherence-proxy-client";
33+
private static final String OP_CACHE_LOAD = "load";
34+
private static final String OP_CACHE_VALIDATE = "validate";
35+
private static final String PROXY_PORT = "9000";
3436

3537
/**
3638
* This method gets called only once before any of the test methods are executed. It does the
@@ -46,12 +48,6 @@ public static void staticPrepare() throws Exception {
4648
if (!QUICKTEST) {
4749
initialize(APP_PROPS_FILE);
4850

49-
// The default cmd loop sleep is too long and we could miss states like terminating. Change the
50-
// sleep and iterations
51-
//
52-
setWaitTimePod(2);
53-
setMaxIterationsPod(125);
54-
5551
if (operator1 == null) {
5652
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
5753
}
@@ -67,26 +63,80 @@ public static void staticPrepare() throws Exception {
6763
public static void staticUnPrepare() throws Exception {
6864
if (!QUICKTEST) {
6965
tearDown(new Object() {}.getClass().getEnclosingClass().getSimpleName());
70-
logger.info("SUCCESS");
7166
}
7267
}
7368

7469
@Test
7570
public void testRollingRestart() throws Exception {
76-
77-
CoherenceUtils utils = new CoherenceUtils();
71+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
72+
logTestBegin(testMethodName);
7873

7974
domain = createDomain();
8075
Assert.assertNotNull(domain);
8176

82-
utils.loadCache();
77+
try {
78+
copyAndExecuteProxyClientInPod(OP_CACHE_LOAD);
8379

84-
// Do the rolling restart
85-
testServerPodsRestartByChangingEnvProperty();
80+
// Do the rolling restart
81+
restartDomainByChangingEnvProperty();
8682

87-
utils.validateCache();
83+
copyAndExecuteProxyClientInPod(OP_CACHE_VALIDATE);
84+
} finally {
85+
destroyDomain();
86+
}
87+
logger.info("SUCCESS - " + testMethodName);
88+
}
8889

89-
destroyDomain();
90+
/**
91+
* Copy the shell script file and all App files over to the admin pod the run the script to build
92+
* the proxy client and run the proxy test.
93+
*
94+
* @param cacheOp - cache operation
95+
* @throws Exception exception
96+
*/
97+
private static void copyAndExecuteProxyClientInPod(String cacheOp) {
98+
try {
99+
final String adminServerPod = domain.getDomainUid() + "-" + domain.getAdminServerName();
100+
101+
final String domainNS = domain.getDomainNs();
102+
103+
// Use the proxy running on Managed Server 1, get the internal POD IP
104+
String podName = domain.getManagedSeverPodName(1);
105+
String ProxyIP = TestUtils.getPodIP(domainNS, "", podName);
106+
107+
String cohAppLocationOnHost = BaseTest.getAppLocationOnHost() + "/" + PROXY_CLIENT_APP_NAME;
108+
String cohAppLocationInPod = BaseTest.getAppLocationInPod() + "/" + PROXY_CLIENT_APP_NAME;
109+
final String cohScriptPathOnHost = cohAppLocationOnHost + "/" + PROXY_CLIENT_SCRIPT;
110+
final String cohScriptPathInPod = cohAppLocationInPod + "/" + PROXY_CLIENT_SCRIPT;
111+
final String successMarker = "CACHE-SUCCESS";
112+
113+
logger.info("Copying files to admin pod for App " + PROXY_CLIENT_APP_NAME);
114+
115+
// Create app dir in the admin pod
116+
StringBuffer mkdirCmd = new StringBuffer(" -- bash -c 'mkdir -p ");
117+
mkdirCmd.append(cohAppLocationInPod).append("'");
118+
TestUtils.kubectlexec(adminServerPod, domainNS, mkdirCmd.toString());
119+
120+
// Copy shell script to the pod
121+
TestUtils.copyFileViaCat(cohScriptPathOnHost, cohScriptPathInPod, adminServerPod, domainNS);
122+
123+
// Copy all App files to the admin pod
124+
TestUtils.copyAppFilesToPod(
125+
cohAppLocationOnHost, cohAppLocationInPod, adminServerPod, domainNS);
126+
127+
logger.info(
128+
"Executing script "
129+
+ PROXY_CLIENT_SCRIPT
130+
+ " for App "
131+
+ PROXY_CLIENT_APP_NAME
132+
+ " in the admin pod");
133+
134+
// Run the script to on the admin pod (note first arg is app directory is applocation in pod)
135+
domain.callShellScriptInAdminPod(
136+
successMarker, cohScriptPathInPod, cohAppLocationInPod, cacheOp, ProxyIP, PROXY_PORT);
137+
} catch (Exception e) {
138+
throw new RuntimeException(e);
139+
}
90140
}
91141

92142
/**
@@ -96,21 +146,17 @@ public void testRollingRestart() throws Exception {
96146
*
97147
* @throws Exception
98148
*/
99-
public void testServerPodsRestartByChangingEnvProperty() throws Exception {
149+
private void restartDomainByChangingEnvProperty() throws Exception {
100150

101-
Assume.assumeFalse(QUICKTEST);
102-
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
103-
logTestBegin(testMethodName);
104-
105-
logger.info(
106-
"About to verifyDomainServerPodRestart for Domain: "
107-
+ domain.getDomainUid()
108-
+ " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true");
151+
// The default cmd loop sleep is too long and we could miss states like terminating. Change
152+
// the
153+
// sleep and iterations
154+
//
155+
setWaitTimePod(2);
156+
setMaxIterationsPod(125);
109157

110158
domain.verifyDomainServerPodRestart(
111159
"\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\"");
112-
113-
logger.info("SUCCESS - " + testMethodName);
114160
}
115161

116162
private static void destroyDomain() throws Exception {
@@ -136,4 +182,4 @@ private Domain createDomain() throws Exception {
136182
domain.verifyDomainCreated();
137183
return domain;
138184
}
139-
}
185+
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,16 @@ public Map<String, Object> getDomainMap() {
709709
return domainMap;
710710
}
711711

712+
/**
713+
* Get the managed server pod name for a specific index
714+
*
715+
* @param index the managed server index
716+
* @return the managed server pod name
717+
*/
718+
public String getManagedSeverPodName(int index) {
719+
return domainUid + "-" + managedServerNameBase + index;
720+
}
721+
712722
/**
713723
* delete PVC and check PV status released when weblogicDomainStorageReclaimPolicy is Recycle.
714724
*
@@ -1152,7 +1162,7 @@ public void verifyManagedServersRestarted() throws Exception {
11521162
if (TestUtils.checkPodTerminatingNoWait(domainUid + "-" + podName, domainNS)) {
11531163
// Server is terminating, wait until server running then remove it from the list
11541164
logger.info("Managed server pod " + podName + " is terminating");
1155-
TestUtils.checkPodCreated(domainUid + "-" + adminServerName, domainNS);
1165+
TestUtils.checkPodCreated(domainUid + "-" + podName, domainNS);
11561166
TestUtils.checkPodReady(domainUid + "-" + podName, domainNS);
11571167
logger.info("Managed server pod " + podName + " has been recycled");
11581168
iter.remove();
@@ -1899,6 +1909,57 @@ public void callShellScriptToBuildDeployAppInPod(
18991909
}
19001910
}
19011911

1912+
1913+
/**
1914+
* Run the shell script in the admin pod.
1915+
*
1916+
* @param successMarker output string from script that indicates success
1917+
* @param scriptPathInPod - bash script path name in the pod
1918+
* @param args - optional args to add for script if needed
1919+
* @throws Exception exception
1920+
*/
1921+
public void callShellScriptInAdminPod(
1922+
String successMarker, String scriptPathInPod, String... args)
1923+
throws Exception {
1924+
1925+
StringBuffer cmdKubectlSh = new StringBuffer("kubectl -n ");
1926+
cmdKubectlSh
1927+
.append(domainNS)
1928+
.append(" exec -it ")
1929+
.append(domainUid)
1930+
.append("-")
1931+
.append(adminServerName)
1932+
.append(" -- bash -c 'chmod +x -R ")
1933+
.append(scriptPathInPod)
1934+
.append(" && sh ")
1935+
.append(scriptPathInPod)
1936+
.append(" ")
1937+
.append(String.join(" ", args).toString())
1938+
.append("'");
1939+
1940+
logger.info("Command to exec script file: " + cmdKubectlSh);
1941+
ExecResult result = ExecCommand.exec(cmdKubectlSh.toString());
1942+
1943+
String resultStr =
1944+
"Command= '"
1945+
+ cmdKubectlSh
1946+
+ "'"
1947+
+ ", exitValue="
1948+
+ result.exitValue()
1949+
+ ", stdout='"
1950+
+ result.stdout()
1951+
+ "'"
1952+
+ ", stderr='"
1953+
+ result.stderr()
1954+
+ "'";
1955+
1956+
// Look for positive success marker.
1957+
if (!resultStr.contains(successMarker)) {
1958+
throw new RuntimeException("FAILURE: Success marker not found after executing script" + scriptPathInPod + " in admin pod - " + resultStr);
1959+
}
1960+
}
1961+
1962+
19021963
/**
19031964
* create config map and label with domainUid and create secret used in custom situational
19041965
* configuration which contains hostname, db user, db password.
@@ -2019,4 +2080,5 @@ public boolean accept(File dir, String name) {
20192080
callShellScriptToBuildDeployAppInPod(
20202081
appName, scriptName, username, password, infoDirName, archiveExt);
20212082
}
2083+
20222084
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package oracle.kubernetes.operator.utils;
66

7+
import io.kubernetes.client.models.V1Pod;
78
import java.io.BufferedReader;
89
import java.io.File;
910
import java.io.FileInputStream;
@@ -30,6 +31,7 @@
3031
import javax.ws.rs.core.Response;
3132
import oracle.kubernetes.operator.BaseTest;
3233
import oracle.kubernetes.operator.utils.Operator.RestCertType;
34+
import org.bouncycastle.i18n.MissingEntryException;
3335
import org.glassfish.jersey.jsonp.JsonProcessingFeature;
3436
import org.yaml.snakeyaml.DumperOptions;
3537
import org.yaml.snakeyaml.Yaml;
@@ -430,6 +432,31 @@ public static String getPods(String namespace) throws Exception {
430432
return stdout;
431433
}
432434

435+
/**
436+
* Get the POD IP.
437+
*
438+
* @param namespace namespace of the POD
439+
* @param labelSelectors optional label selectors
440+
* @param podName pod name
441+
* @return podIP
442+
*/
443+
public static String getPodIP(String namespace, String labelSelectors, String podName)
444+
throws Exception {
445+
V1Pod pod = null;
446+
try {
447+
labelSelectors = labelSelectors == null ? "" : labelSelectors;
448+
pod = k8sTestUtils.getPod(namespace,"",podName);
449+
} catch (Exception e) {
450+
Exception re = new Exception("Exception getting Pod " + namespace + "/" + podName);
451+
re.initCause(e);
452+
throw re;
453+
}
454+
if (pod == null) {
455+
throw new Exception("Pod " + namespace + "/" + podName + "not found ");
456+
}
457+
return pod.getStatus().getPodIP();
458+
}
459+
433460
/**
434461
* First, kill the mgd server process in the container three times to cause the node manager to
435462
* mark the server 'failed not restartable'. This in turn is detected by the liveness probe, which
@@ -566,28 +593,28 @@ public static void copyAppFilesToPod(
566593
throws Exception {
567594
File appFileRoot = new File(appLocationOnHost);
568595
File[] appFileList = appFileRoot.listFiles();
569-
String fileLocationInPod = appLocationInPod;
570596

571597
if (appFileList == null) return;
572598

573599
for (File file : appFileList) {
574600
if (file.isDirectory()) {
601+
602+
// Create the directory on the pod
603+
String nestedDirOnPod = appLocationInPod + "/" + file.getName();
604+
StringBuffer mkdirCmd = new StringBuffer(" -- bash -c 'mkdir -p ").append(nestedDirOnPod).append("'");
605+
TestUtils.kubectlexec(podName, namespace, mkdirCmd.toString());
606+
575607
// Find dir recursively
576-
copyAppFilesToPod(file.getAbsolutePath(), appLocationInPod, podName, namespace);
608+
copyAppFilesToPod(file.getAbsolutePath(), nestedDirOnPod, podName, namespace);
577609
} else {
578610
logger.info("Copy file: " + file.getAbsoluteFile().toString() + " to the pod: " + podName);
579611

580612
String fileParent = file.getParentFile().getName();
581613
logger.fine("file Parent: " + fileParent);
582614

583-
if (!appLocationInPod.contains(fileParent)) {
584-
// Copy files in child dir of appLocationInPod
585-
fileLocationInPod = appLocationInPod + "/" + fileParent;
586-
}
587-
588615
StringBuffer copyFileCmd = new StringBuffer(" -- bash -c 'cat > ");
589616
copyFileCmd
590-
.append(fileLocationInPod)
617+
.append(appLocationInPod)
591618
.append("/")
592619
.append(file.getName())
593620
.append("' < ")

integration-tests/src/test/resources/apps/coherence-proxy-client/build.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3+
<!-- ================================================================================= -->
4+
<!-- Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved. -->
5+
<!-- Licensed under the Universal Permissive License v 1.0 as shown at -->
6+
<!-- http://oss.oracle.com/licenses/upl. -->
7+
<!-- ================================================================================= -->
8+
39
<!-- ====================================================================== -->
410
<!-- Ant build file (http://ant.apache.org/) for Ant 1.6.2 or above. -->
511
<!-- ====================================================================== -->

0 commit comments

Comments
 (0)