Skip to content

Commit ff26633

Browse files
committed
Pass in additional env vars that are needed by WDT
1 parent 136e95c commit ff26633

File tree

3 files changed

+84
-40
lines changed

3 files changed

+84
-40
lines changed

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

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

55
package oracle.kubernetes.operator;
66

7+
import java.util.HashMap;
78
import java.util.Map;
89
import oracle.kubernetes.operator.utils.Domain;
910
import oracle.kubernetes.operator.utils.Operator;
@@ -15,18 +16,15 @@
1516
import org.junit.FixMethodOrder;
1617
import org.junit.Test;
1718
import org.junit.runners.MethodSorters;
19+
1820
/**
19-
* Simple JUnit test file used for testing Operator.
20-
*
21-
* <p>This test is used for testing pods being restarted by some properties change.
21+
* This class contains Coherence relates integraiton tests.
2222
*/
2323
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
2424
public class ITCoherenceTests extends BaseTest {
2525

2626
private static Domain domain = null;
27-
private static Operator operator1;
28-
29-
private static final String testAppName = "coherence-proxy-client";
27+
private static Operator operator1 = null;
3028

3129
private static final String PROXY_CLIENT_SCRIPT = "buildRunProxyClient.sh";
3230
private static final String PROXY_CLIENT_APP_NAME = "coherence-proxy-client";
@@ -37,8 +35,7 @@ public class ITCoherenceTests extends BaseTest {
3735
/**
3836
* This method gets called only once before any of the test methods are executed. It does the
3937
* initialization of the integration test properties defined in OperatorIT.properties and setting
40-
* the resultRoot, pvRoot and projectRoot attributes. Create Operator1 and domainOnPVUsingWLST
41-
* with admin server and 1 managed server if they are not running
38+
* the resultRoot, pvRoot and projectRoot attributes. Also, create the operator.
4239
*
4340
* @throws Exception
4441
*/
@@ -47,22 +44,20 @@ public static void staticPrepare() throws Exception {
4744
// initialize test properties and create the directories
4845
if (!QUICKTEST) {
4946
initialize(APP_PROPS_FILE);
50-
51-
if (operator1 == null) {
52-
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
53-
}
47+
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
5448
}
5549
}
5650

5751
/**
58-
* Releases k8s cluster lease, archives result, pv directories
52+
* Releases k8s cluster lease, archives result, pv directories and destroy the operator
5953
*
6054
* @throws Exception
6155
*/
6256
@AfterClass
6357
public static void staticUnPrepare() throws Exception {
6458
if (!QUICKTEST) {
6559
tearDown(new Object() {}.getClass().getEnclosingClass().getSimpleName());
60+
operator1.destroy();
6661
}
6762
}
6863

@@ -88,11 +83,10 @@ public void testRollingRestart() throws Exception {
8883
}
8984

9085
/**
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.
86+
* Copy the shell script file and all coherence app files over to the admin pod.
87+
* Then run the script to build the proxy client and run the proxy test.
9388
*
9489
* @param cacheOp - cache operation
95-
* @throws Exception exception
9690
*/
9791
private static void copyAndExecuteProxyClientInPod(String cacheOp) {
9892
try {
@@ -159,21 +153,25 @@ private void restartDomainByChangingEnvProperty() throws Exception {
159153
"\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\"");
160154
}
161155

162-
private static void destroyDomain() throws Exception {
163-
if (domain != null) {
164-
domain.destroy();
165-
}
166-
}
167-
156+
/**
157+
* Create the domain
158+
*
159+
* @return
160+
* @throws Exception
161+
*/
168162
private Domain createDomain() throws Exception {
169163

170-
// System.getenv().put("CUSTOM_WDT_ARCHIVE", "/Users/pmackin/archive-proxy.zip");
164+
// TODO - Don't hardcode the archive location
165+
Map<String, String> envMap = new HashMap();
166+
envMap.put("CUSTOM_WDT_ARCHIVE", "/Users/pmackin/archive-proxy.zip");
171167

172168
// create domain
173169
Domain domain = null;
174170
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAININIMAGE_WDT_YAML);
175171
domainMap.put("namespace", "test1");
176172
domainMap.put("domainUID", "coh");
173+
domainMap.put("additionalEnvMap", envMap);
174+
177175
domainMap.put(
178176
"customWdtTemplate",
179177
BaseTest.getProjectRoot()
@@ -182,4 +180,16 @@ private Domain createDomain() throws Exception {
182180
domain.verifyDomainCreated();
183181
return domain;
184182
}
183+
184+
/**
185+
* Destroy the domain
186+
*
187+
* @throws Exception
188+
*/
189+
private static void destroyDomain() throws Exception {
190+
if (domain != null) {
191+
domain.destroy();
192+
}
193+
}
194+
185195
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class Domain {
7777
private String imageName;
7878
private boolean voyager;
7979
private boolean createDomainResource = true;
80-
80+
8181
public Domain() throws Exception {
8282
domainMap = new HashMap<>();
8383
}
@@ -95,7 +95,7 @@ public Domain(String inputYaml, boolean createDomainResource) throws Exception {
9595
public Domain(Map<String, Object> inputDomainMap) throws Exception {
9696
this(inputDomainMap, true);
9797
}
98-
98+
9999
public Domain(Map<String, Object> inputDomainMap, boolean createDomainResource) throws Exception {
100100
initialize(inputDomainMap);
101101
this.createDomainResource = createDomainResource;
@@ -1242,8 +1242,11 @@ protected void callCreateDomainScript(String outputDir) throws Exception {
12421242
// as samples only support DYNAMIC cluster or copy config cluster topology for domain in image
12431243
changeClusterTypeInCreateDomainJobTemplate();
12441244

1245+
// Get the map of any additional environment vars, or null
1246+
Map<String, String> additionalEnvMap = (Map<String, String>)domainMap.get("additionalEnvMap");;
1247+
12451248
logger.info("Running " + createDomainScriptCmd);
1246-
ExecResult result = ExecCommand.exec(createDomainScriptCmd, true);
1249+
ExecResult result = ExecCommand.exec(createDomainScriptCmd, true, additionalEnvMap);
12471250
if (result.exitValue() != 0) {
12481251
throw new RuntimeException(
12491252
"FAILURE: command "

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

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,44 @@
44

55
package oracle.kubernetes.operator.utils;
66

7+
import com.google.common.io.ByteStreams;
78
import java.io.BufferedReader;
89
import java.io.ByteArrayInputStream;
910
import java.io.ByteArrayOutputStream;
1011
import java.io.IOException;
1112
import java.io.InputStream;
1213
import java.io.InputStreamReader;
1314
import java.io.OutputStream;
15+
import java.util.HashMap;
16+
import java.util.Map;
1417
import java.util.stream.Collectors;
1518

16-
import com.google.common.io.ByteStreams;
17-
18-
/**
19-
* Class for executing shell commands from java.
20-
*/
19+
/** Class for executing shell commands from java. */
2120
public class ExecCommand {
2221

2322
public static ExecResult exec(String command) throws Exception {
24-
return exec(command, false);
23+
return exec(command, false, null);
2524
}
2625

2726
public static ExecResult exec(String command, boolean isRedirectToOut) throws Exception {
28-
Process p = Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", command});
27+
return exec(command, isRedirectToOut, null);
28+
}
29+
30+
public static ExecResult exec(String command, boolean isRedirectToOut, Map<String,String> additionalEnvMap)
31+
throws Exception {
32+
33+
Process p = null;
34+
if (additionalEnvMap == null) {
35+
p = Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", command});
36+
} else {
37+
// Combine new env vars with existing ones and generate a string array with those values
38+
// If the 2 maps have a dup key then the additional env map entry will replace the existing.
39+
Map<String, String> combinedEnvMap = new HashMap();
40+
combinedEnvMap.putAll(System.getenv());
41+
combinedEnvMap.putAll(additionalEnvMap);
42+
String[] envParams = generateNameValueArrayFromMap(combinedEnvMap);
43+
p = Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", command}, envParams);
44+
}
2945

3046
InputStreamWrapper in = new SimpleInputStreamWrapper(p.getInputStream());
3147
Thread out = null;
@@ -38,13 +54,14 @@ public static ExecResult exec(String command, boolean isRedirectToOut) throws Ex
3854
// this makes sense because CopyingOutputStream is an InputStreamWrapper
3955
in = copyOut;
4056
out =
41-
new Thread(() -> {
42-
try {
43-
ByteStreams.copy(i, copyOut);
44-
} catch (IOException ex) {
45-
ex.printStackTrace();
46-
}
47-
});
57+
new Thread(
58+
() -> {
59+
try {
60+
ByteStreams.copy(i, copyOut);
61+
} catch (IOException ex) {
62+
ex.printStackTrace();
63+
}
64+
});
4865
out.start();
4966
}
5067

@@ -58,6 +75,20 @@ public static ExecResult exec(String command, boolean isRedirectToOut) throws Ex
5875
}
5976
}
6077

78+
/**
79+
* Generate a string array of name=value items, one for each env map entry.
80+
* @return
81+
*/
82+
private static String[] generateNameValueArrayFromMap(Map<String, String> map) {
83+
int mapSize = map.size();
84+
String[] strArrary = new String[mapSize];
85+
int i = 0;
86+
for (Map.Entry<String,String> entry : map.entrySet()) {
87+
strArrary[i++] = entry.getKey() + "=" + entry.getValue();
88+
}
89+
return strArrary;
90+
}
91+
6192
private static String read(InputStream is) throws Exception {
6293
return new BufferedReader(new InputStreamReader(is)).lines().collect(Collectors.joining("\n"));
6394
}

0 commit comments

Comments
 (0)