Skip to content

Commit eb1a7ab

Browse files
committed
Bring back the source code to use serverStartPolicy to shutdown a server jenkins-ignore
1 parent 1f3ca45 commit eb1a7ab

File tree

2 files changed

+66
-85
lines changed

2 files changed

+66
-85
lines changed

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

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.regex.Matcher;
1010
import java.util.regex.Pattern;
1111
import oracle.kubernetes.operator.utils.Domain;
12-
import oracle.kubernetes.operator.utils.ExecCommand;
1312
import oracle.kubernetes.operator.utils.ExecResult;
1413
import oracle.kubernetes.operator.utils.Operator;
1514
import oracle.kubernetes.operator.utils.TestUtils;
@@ -30,11 +29,8 @@
3029
public class ITSessionMigration extends BaseTest {
3130
private static final String testAppName = "httpsessionreptestapp";
3231
private static final String scriptName = "buildDeployAppInPod.sh";
33-
3432
private static Map<String, String> httpAttrMap;
35-
3633
private static String httpHeaderFile;
37-
3834
private static Operator operator;
3935
private static Domain domain;
4036

@@ -70,7 +66,6 @@ public static void staticPrepare() throws Exception {
7066
}
7167

7268
httpHeaderFile = BaseTest.getResultDir() + "/headers";
73-
7469
httpAttrMap = new HashMap<String, String>();
7570
httpAttrMap.put("sessioncreatetime", "(.*)sessioncreatetime>(.*)</sessioncreatetime(.*)");
7671
httpAttrMap.put("sessionid", "(.*)sessionid>(.*)</sessionid(.*)");
@@ -133,7 +128,7 @@ public void testRepickPrimary() throws Exception {
133128
String sessCreateTime1 = getHttpResponseAttribute(result.stdout(), sessCreateTime);
134129

135130
// Stop primary server
136-
stopPrimaryServer(primaryServName1);
131+
domain.shutdownManagedServerUsingServerStartPolicy(primaryServName1);
137132

138133
// Send the second HTTP request using HTTP header/sessionID info save before
139134
result = getHTTPResponse(testAppPath, " -b ");
@@ -151,6 +146,7 @@ public void testRepickPrimary() throws Exception {
151146
primaryServName1.trim().equals(primaryServName2.trim()));
152147

153148
// Restore test env
149+
domain.restartManagedServerUsingServerStartPolicy(primaryServName1);
154150
TestUtils.checkPodReady(domainUid + "-" + primaryServName1, domainNS);
155151

156152
logger.info(
@@ -189,7 +185,7 @@ public void testHttpSessionMigr() throws Exception {
189185
String countattribute1 = getHttpResponseAttribute(result.stdout(), count);
190186

191187
// Stop primary server
192-
stopPrimaryServer(primaryServName1);
188+
domain.shutdownManagedServerUsingServerStartPolicy(primaryServName1);
193189

194190
// Send the second HTTP request using HTTP header/sessionID info save before
195191
result = getHTTPResponse(webServiceGetUrl, " -b ");
@@ -209,6 +205,7 @@ public void testHttpSessionMigr() throws Exception {
209205
"HTTP session state is NOT migrated!", countattribute1.equals(countattribute2));
210206

211207
// Restore test env
208+
domain.restartManagedServerUsingServerStartPolicy(primaryServName1);
212209
TestUtils.checkPodReady(domainUid + "-" + primaryServName1, domainNS);
213210

214211
logger.info("SUCCESS - " + testMethodName + ". HTTP session state is migrated!");
@@ -226,45 +223,11 @@ private ExecResult getHTTPResponse(String webServiceURL, String headerOption) th
226223
String curlCmd = buildWebServiceUrl(webServiceURL, headerOption + httpHeaderFile);
227224
logger.info("Send a HTTP request: " + curlCmd);
228225

229-
ExecResult result = ExecCommand.exec(curlCmd);
230-
231-
if (result.exitValue() != 0) {
232-
throw new Exception(
233-
"FAILURE: command "
234-
+ curlCmd
235-
+ " failed, returned "
236-
+ result.stderr()
237-
+ "\n "
238-
+ result.stdout());
239-
}
226+
ExecResult result = TestUtils.exec(curlCmd);
240227

241228
return result;
242229
}
243230

244-
/**
245-
* Stop the primary server
246-
*
247-
* @param primaryServerName - weblogic primary server name
248-
* @throws Exception
249-
*/
250-
private void stopPrimaryServer(String primaryServerName) throws Exception {
251-
Map<String, Object> domainMap = domain.getDomainMap();
252-
String domainNS = domainMap.get("namespace").toString();
253-
String domainUid = domain.getDomainUid();
254-
255-
// stop primary server
256-
String msPodName = domainUid + "-" + primaryServerName;
257-
String cmd = "kubectl delete po/" + msPodName + " -n " + domainNS;
258-
logger.info("Stop managed server <" + msPodName + "> using command:\n" + cmd);
259-
260-
ExecResult result = ExecCommand.exec(cmd);
261-
if (result.exitValue() != 0) {
262-
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
263-
}
264-
265-
logger.info(result.stdout());
266-
}
267-
268231
/**
269232
* Get the value of a HTTP attribute
270233
*
@@ -274,11 +237,8 @@ private void stopPrimaryServer(String primaryServerName) throws Exception {
274237
*/
275238
private String getHttpResponseAttribute(String httpResponseString, String attribute)
276239
throws Exception {
277-
278240
String attrPatn = httpAttrMap.get(attribute);
279-
280241
Assume.assumeNotNull(attrPatn);
281-
282242
String httpAttribute = null;
283243

284244
Pattern pattern = Pattern.compile(attrPatn);
@@ -316,28 +276,4 @@ private String buildWebServiceUrl(String curlURLPath, String paramToAppend) thro
316276

317277
return webServiceUrl.toString();
318278
}
319-
320-
/**
321-
* Execute a given curl command and verify the results
322-
*
323-
* @param curlCmd - a curl command to execute
324-
* @throws Exception
325-
*/
326-
private ExecResult execCurlCmd(String curlCmd) throws Exception {
327-
logger.info("curl command to exec is:\n" + curlCmd);
328-
329-
ExecResult result = ExecCommand.exec(curlCmd);
330-
331-
if (result.exitValue() != 0) {
332-
throw new Exception(
333-
"FAILURE: command "
334-
+ curlCmd
335-
+ " failed, returned "
336-
+ result.stderr()
337-
+ "\n "
338-
+ result.stdout());
339-
}
340-
341-
return result;
342-
}
343279
}

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

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,7 @@ public int getLoadBalancerWebPort() {
17881788
/**
17891789
* Shut down a ms by setting serverStartPolicy to NEVER
17901790
*
1791+
* @param msName - a managed server name to be stopped
17911792
* @throws Exception
17921793
*/
17931794
public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Exception {
@@ -1801,20 +1802,14 @@ public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Ex
18011802
+ "\",\"serverStartPolicy\":\"NEVER\"}]}}' --type merge";
18021803

18031804
logger.info("command to shutdown managed server <" + msName + "> is: " + cmd);
1804-
1805-
ExecResult result = ExecCommand.exec(cmd);
1806-
if (result.exitValue() != 0) {
1807-
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
1808-
}
1809-
String output = result.stdout().trim();
1810-
logger.info("output from shutting down managed server:\n" + output);
1811-
1805+
TestUtils.exec(cmd);
18121806
TestUtils.checkPodDeleted(domainUid + "-" + msName, domainNS);
18131807
}
18141808

18151809
/**
18161810
* Restart a ms by setting serverStartPolicy to IF_NEEDED
18171811
*
1812+
* @param msName - a managed server name to be started
18181813
* @throws Exception
18191814
*/
18201815
public void restartManagedServerUsingServerStartPolicy(String msName) throws Exception {
@@ -1828,14 +1823,7 @@ public void restartManagedServerUsingServerStartPolicy(String msName) throws Exc
18281823
+ "\",\"serverStartPolicy\":\"IF_NEEDED\"}]}}' --type merge";
18291824

18301825
logger.info("command to restart managed server <" + msName + "> is: " + cmd);
1831-
1832-
ExecResult result = ExecCommand.exec(cmd);
1833-
if (result.exitValue() != 0) {
1834-
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
1835-
}
1836-
String output = result.stdout().trim();
1837-
logger.info("output from restarting managed server:\n" + output);
1838-
1826+
TestUtils.exec(cmd);
18391827
TestUtils.checkPodCreated(domainUid + "-" + msName, domainNS);
18401828
TestUtils.checkPodReady(domainUid + "-" + msName, domainNS);
18411829
}
@@ -2033,4 +2021,61 @@ public boolean accept(File dir, String name) {
20332021
callShellScriptToBuildDeployAppInPod(
20342022
appName, scriptName, username, password, infoDirName, archiveExt);
20352023
}
2024+
2025+
/**
2026+
* Shut down a ms by setting serverStartPolicy to NEVER
2027+
*
2028+
* @param msName - a managed server name to be stopped
2029+
* @throws Exception
2030+
*/
2031+
/*
2032+
public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Exception {
2033+
String cmd =
2034+
"kubectl patch domain "
2035+
+ domainUid
2036+
+ " -n "
2037+
+ domainNS
2038+
+ " -p '{\"spec\":{\"managedServers\":[{\"serverName\":\""
2039+
+ msName
2040+
+ "\",\"serverStartPolicy\":\"NEVER\"}]}}' --type merge";
2041+
2042+
logger.info("command to shutdown managed server <" + msName + "> is: " + cmd);
2043+
ExecResult result = ExecCommand.exec(cmd);
2044+
if (result.exitValue() != 0) {
2045+
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
2046+
}
2047+
String output = result.stdout().trim();
2048+
logger.info("output from shutting down managed server:\n" + output);
2049+
2050+
TestUtils.checkPodDeleted(domainUid + "-" + msName, domainNS);
2051+
}
2052+
*/
2053+
/**
2054+
* Restart a ms by setting serverStartPolicy to IF_NEEDED
2055+
*
2056+
* @param msName - a managed server name to be started
2057+
* @throws Exception
2058+
*/
2059+
/*
2060+
public void restartManagedServerUsingServerStartPolicy(String msName) throws Exception {
2061+
String cmd =
2062+
"kubectl patch domain "
2063+
+ domainUid
2064+
+ " -n "
2065+
+ domainNS
2066+
+ " -p '{\"spec\":{\"managedServers\":[{\"serverName\":\""
2067+
+ msName
2068+
+ "\",\"serverStartPolicy\":\"IF_NEEDED\"}]}}' --type merge";
2069+
2070+
logger.info("command to restart managed server <" + msName + "> is: " + cmd);
2071+
ExecResult result = ExecCommand.exec(cmd);
2072+
if (result.exitValue() != 0) {
2073+
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
2074+
}
2075+
String output = result.stdout().trim();
2076+
logger.info("output from restarting managed server:\n" + output);
2077+
2078+
TestUtils.checkPodCreated(domainUid + "-" + msName, domainNS);
2079+
TestUtils.checkPodReady(domainUid + "-" + msName, domainNS);
2080+
}*/
20362081
}

0 commit comments

Comments
 (0)