Skip to content

Commit dd735b0

Browse files
initial version for lifecycle-java-integ-test
1 parent 5778723 commit dd735b0

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,63 @@ private Domain testAdvancedUseCasesForADomain(Operator operator, Domain domain)
589589
return domain;
590590
}
591591

592+
/**
593+
* Create Operator1 and domainOnPVUsingWLST with admin server and 1 managed server if they are not
594+
* running. After verifying the domain is created properly. Change some properties on domain
595+
* resources that would cause servers to be restarted and verify that server are indeed restarted.
596+
* The properties tested here are: env: "-Dweblogic.StdoutDebugEnabled=false"-->
597+
* "-Dweblogic.StdoutDebugEnabled=false"
598+
*
599+
* @throws Exception
600+
*/
601+
@Test
602+
public void testServerRestartByDomainOnPVUsingWLST() throws Exception {
603+
Assume.assumeFalse(QUICKTEST);
604+
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
605+
logTestBegin(testMethodName);
606+
607+
logger.info("Checking if operator1 and domain are running, if not creating");
608+
if (operator1 == null) {
609+
operator1 = TestUtils.createOperator(operator1File);
610+
}
611+
612+
Domain domain = null;
613+
boolean testCompletedSuccessfully = false;
614+
try {
615+
// load input yaml to map and add configOverrides
616+
Map<String, Object> domainMap = TestUtils.loadYaml(domainonpvwlstFile);
617+
domainMap.put("domainUID", "domainlifecycle");
618+
domainMap.put("adminNodePort", new Integer("30707"));
619+
domainMap.put("t3ChannelPort", new Integer("30081"));
620+
domainMap.put("initialManagedServerReplicas", new Integer("1"));
621+
622+
logger.info("Creating Domain domain& verifing the domain creation");
623+
domain = TestUtils.createDomain(domainMap);
624+
domain.verifyDomainCreated();
625+
// TODO add some comments
626+
domain.testDomainServerRestart(
627+
"\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\"");
628+
logger.info(
629+
"About to testServerPodRestart for Domain: "
630+
+ domainMap.get("domainUID")
631+
+ " for the env property: StdoutDebugEnabled=true");
632+
633+
} finally {
634+
String domainUidsToBeDeleted = "";
635+
636+
if (domain != null && (JENKINS || testCompletedSuccessfully)) {
637+
domainUidsToBeDeleted = domain.getDomainUid();
638+
}
639+
640+
/* if (!domainUidsToBeDeleted.equals("")) {
641+
logger.info("About to delete domains: " + domainUidsToBeDeleted);
642+
TestUtils.deleteWeblogicDomainResources(domainUidsToBeDeleted);
643+
TestUtils.verifyAfterDeletion(domain);
644+
}*/
645+
}
646+
logger.info("SUCCESS - " + testMethodName);
647+
}
648+
592649
private void testBasicUseCases(Domain domain) throws Exception {
593650
testAdminT3Channel(domain);
594651
testAdminServerExternalService(domain);

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,84 @@ private void createPV() throws Exception {
844844
new PersistentVolume("/scratch/acceptance_test_pv/persistentVolume-" + domainUid, pvMap);
845845
}
846846

847+
public void testDomainServerRestart(String oldPropertyString, String newPropertyString)
848+
throws Exception {
849+
logger.info("Inside testDomainServerPodRestart");
850+
boolean result = false;
851+
result =
852+
TestUtils.findFileContainString(
853+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml",
854+
newPropertyString);
855+
logger.info("The search result for " + newPropertyString + " is: " + result); // TODO
856+
if (!result) {
857+
TestUtils.createNewYamlFile(
858+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml",
859+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml",
860+
oldPropertyString,
861+
newPropertyString);
862+
logger.info(
863+
"Done - generate new domain.yaml for "
864+
+ domainUid
865+
+ " oldProperty: "
866+
+ oldPropertyString
867+
+ " newProperty: "
868+
+ newPropertyString);
869+
870+
// kubectl apply the new generated domain yaml file with changed property
871+
StringBuffer command = new StringBuffer();
872+
command
873+
.append("kubectl apply -f ")
874+
.append(
875+
BaseTest.getUserProjectsDir()
876+
+ "/weblogic-domains/"
877+
+ domainUid
878+
+ "/domain_new.yaml");
879+
logger.info("kubectl execut with command: " + command.toString());
880+
ExecResult exeResult = ExecCommand.exec(command.toString());
881+
if (exeResult.exitValue() != 0) {
882+
throw new RuntimeException(
883+
"FAILED: command to get domain " + command + " failed with " + exeResult.stderr());
884+
}
885+
if (!exeResult.stdout().contains(domainUid))
886+
throw new RuntimeException("FAILURE: domain not found, exiting!");
887+
888+
// verify the servers in the domain are being restarted in a sequence
889+
logger.info(
890+
"Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Terminating");
891+
TestUtils.checkPodTerminating(domainUid + "-" + adminServerName, domainNS);
892+
Thread.sleep(10 * 1000);
893+
logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Running");
894+
TestUtils.checkPodCreated(domainUid + "-" + adminServerName, domainNS);
895+
Thread.sleep(10 * 1000);
896+
897+
if (domainMap.get("serverStartPolicy") == null
898+
|| (domainMap.get("serverStartPolicy") != null
899+
&& !domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY"))) {
900+
// check managed server pods
901+
for (int i = 1; i <= initialManagedServerReplicas; i++) {
902+
logger.info(
903+
"Checking if managed pod("
904+
+ domainUid
905+
+ "-"
906+
+ managedServerNameBase
907+
+ i
908+
+ ") is Terminating");
909+
TestUtils.checkPodTerminating(domainUid + "-" + managedServerNameBase + i, domainNS);
910+
Thread.sleep(10 * 1000);
911+
logger.info(
912+
"Checking if managed pod("
913+
+ domainUid
914+
+ "-"
915+
+ managedServerNameBase
916+
+ i
917+
+ ") is Running");
918+
TestUtils.checkPodCreated(domainUid + "-" + managedServerNameBase + i, domainNS);
919+
}
920+
}
921+
}
922+
logger.info("Done - testDomainServerPodRestart");
923+
}
924+
847925
private void createSecret() throws Exception {
848926
Secret secret =
849927
new Secret(

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
package oracle.kubernetes.operator.utils;
66

7+
import java.io.*;
8+
import java.io.BufferedReader;
79
import java.io.File;
810
import java.io.FileInputStream;
11+
import java.io.FileReader;
912
import java.io.FileWriter;
1013
import java.io.InputStream;
14+
import java.nio.file.Files;
15+
import java.nio.file.Paths;
16+
import java.nio.file.StandardCopyOption;
1117
import java.security.KeyStore;
1218
import java.util.HashMap;
1319
import java.util.Map;
1420
import java.util.Properties;
21+
import java.util.Scanner;
1522
import java.util.logging.Logger;
1623
import javax.ws.rs.client.Client;
1724
import javax.ws.rs.client.ClientBuilder;
@@ -54,6 +61,16 @@ public static void checkPodCreated(String podName, String domainNS) throws Excep
5461
checkCmdInLoop(cmd.toString(), "Running", podName);
5562
}
5663

64+
/** @param cmd - kubectl get pod <podname> -n namespace */
65+
public static void checkPodTerminating(String podName, String domainNS) throws Exception {
66+
67+
StringBuffer cmd = new StringBuffer();
68+
cmd.append("kubectl get pod ").append(podName).append(" -n ").append(domainNS);
69+
70+
// check for admin pod
71+
checkCmdInLoop(cmd.toString(), "Terminating", podName);
72+
}
73+
5774
/**
5875
* @param cmd - kubectl get service <servicename> -n namespace
5976
* @throws Exception
@@ -988,4 +1005,62 @@ private static void checkCmdInLoopForDelete(String cmd, String matchStr, String
9881005
}
9891006
}
9901007
}
1008+
1009+
// create yaml file with changed property
1010+
public static void createNewYamlFile(
1011+
String inputYamlFile, String generatedYamlFile, String oldString, String newString)
1012+
throws Exception {
1013+
logger.info("Creating new " + generatedYamlFile);
1014+
1015+
// copy input template file and modify it
1016+
Files.copy(
1017+
new File(inputYamlFile).toPath(),
1018+
Paths.get(generatedYamlFile),
1019+
StandardCopyOption.REPLACE_EXISTING);
1020+
1021+
// read each line in input domain file and replace with intended changed property
1022+
BufferedReader reader = new BufferedReader(new FileReader(generatedYamlFile));
1023+
String line = "";
1024+
StringBuffer changedLines = new StringBuffer();
1025+
boolean isLineChanged = false;
1026+
while ((line = reader.readLine()) != null) {
1027+
if (line.contains(oldString)) {
1028+
String changedLine = line.replace(line.substring(line.indexOf(oldString)), newString);
1029+
changedLines.append(changedLine).append("\n");
1030+
isLineChanged = true;
1031+
}
1032+
1033+
if (!isLineChanged) {
1034+
changedLines.append(line).append("\n");
1035+
}
1036+
isLineChanged = false;
1037+
}
1038+
reader.close();
1039+
// writing to the file
1040+
Files.write(Paths.get(generatedYamlFile), changedLines.toString().getBytes());
1041+
logger.info("Done - generate the new yaml file ");
1042+
}
1043+
1044+
public static boolean findFileContainString(String inputYamlFile, String searchString)
1045+
throws Exception {
1046+
logger.info("Search File " + inputYamlFile + " Search String: " + searchString);
1047+
boolean result = false;
1048+
File file = new File(inputYamlFile);
1049+
Scanner in = null;
1050+
try {
1051+
in = new Scanner(new FileReader(file));
1052+
while (in.hasNextLine() && !result) {
1053+
result = in.nextLine().indexOf(searchString) >= 0;
1054+
}
1055+
} catch (IOException e) {
1056+
e.printStackTrace();
1057+
} finally {
1058+
try {
1059+
in.close();
1060+
} catch (Exception e) {
1061+
/* ignore */
1062+
}
1063+
}
1064+
return result;
1065+
}
9911066
}

0 commit comments

Comments
 (0)