Skip to content

Commit d681bc6

Browse files
committed
added mysql db replacing Oracle DB
1 parent 0a33c08 commit d681bc6

File tree

5 files changed

+79
-22
lines changed

5 files changed

+79
-22
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class BaseTest {
5252
private static String resultDir = "";
5353
private static String userProjectsDir = "";
5454
private static String projectRoot = "";
55+
protected static String sitconfigDir = "";
5556
private static String username = "weblogic";
5657
private static String password = "welcome1";
5758
private static int maxIterationsPod = 50;
@@ -114,6 +115,7 @@ public static void initialize(String appPropsFile) throws Exception {
114115
resultDir = resultRoot + "/acceptance_test_tmp";
115116
userProjectsDir = resultDir + "/user-projects";
116117
projectRoot = System.getProperty("user.dir") + "/..";
118+
sitconfigDir = resultRoot + "/configoverridefiles";
117119

118120
// BRANCH_NAME var is used in Jenkins job
119121
if (System.getenv("BRANCH_NAME") != null) {
@@ -157,12 +159,16 @@ public static void initialize(String appPropsFile) throws Exception {
157159
"/usr/local/packages/aime/ias/run_as_root \"chmod 777 "
158160
+ pvRoot
159161
+ "/acceptance_test_pv\"");
162+
logger.info("Creating " + sitconfigDir);
163+
TestUtils.exec("/usr/local/packages/aime/ias/run_as_root \"mkdir -p " + sitconfigDir + "\"");
164+
TestUtils.exec("/usr/local/packages/aime/ias/run_as_root \"chmod 777 " + sitconfigDir + "\"");
160165
}
161166

162167
// create resultRoot, PVRoot, etc
163168
Files.createDirectories(Paths.get(resultRoot));
164169
Files.createDirectories(Paths.get(resultDir));
165170
Files.createDirectories(Paths.get(userProjectsDir));
171+
Files.createDirectories(Paths.get(sitconfigDir));
166172

167173
// create file handler
168174
FileHandler fh = new FileHandler(resultDir + "/java_test_suite.out");

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

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
import static oracle.kubernetes.operator.BaseTest.initialize;
77
import static oracle.kubernetes.operator.BaseTest.logger;
88

9+
import java.io.IOException;
10+
import java.nio.charset.Charset;
11+
import java.nio.charset.StandardCharsets;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.nio.file.Paths;
15+
import java.nio.file.StandardOpenOption;
916
import java.util.*;
1017
import java.util.logging.Level;
1118
import oracle.kubernetes.operator.utils.Domain;
@@ -27,7 +34,9 @@ public class ITSitConfig extends BaseTest {
2734
private static final String DOMAINUID = "customsitconfigdomain";
2835
private static final String ADMINPORT = "30710";
2936
private static final int T3CHANNELPORT = 30091;
30-
private static String fqdn = "";
37+
private static final String MYSQL_DB_PORT = "31306";
38+
private static String fqdn;
39+
private static String JDBC_URL;
3140

3241
private static Domain domain = null;
3342
private static Operator operator1;
@@ -50,6 +59,10 @@ public static void staticPrepare() throws Exception {
5059
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
5160
}
5261
TESTSCRIPTDIR = BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/";
62+
manageMySqlDB(TESTSCRIPTDIR + "/sitconfig/mysql/mysql-dbservices.yml", "create");
63+
fqdn = TestUtils.getHostName();
64+
JDBC_URL = "jdbc:mysql://" + fqdn + ":" + MYSQL_DB_PORT + "/";
65+
copySitConfigFiles();
5366
domain = createSitConfigDomain();
5467
Assert.assertNotNull(domain);
5568
ADMINPODNAME = domain.getDomainUid() + "-" + domain.getAdminServerName();
@@ -63,7 +76,6 @@ public static void staticPrepare() throws Exception {
6376
"runSitConfigTests.sh",
6477
ADMINPODNAME,
6578
domain.getDomainNS());
66-
fqdn = TestUtils.getHostName();
6779
}
6880
}
6981

@@ -81,6 +93,7 @@ public static void staticUnPrepare() throws Exception {
8193

8294
destroySitConfigDomain();
8395
tearDown();
96+
manageMySqlDB(TESTSCRIPTDIR + "/sitconfig/mysql-dbservices.yml", "delete");
8497
logger.info("SUCCESS");
8598
}
8699
}
@@ -128,7 +141,7 @@ public void testCustomSitConfigOverridesForJdbc() throws Exception {
128141
String stdout =
129142
callShellScriptByExecToPod(
130143
"runSitConfigTests.sh",
131-
fqdn + " " + T3CHANNELPORT + " weblogic welcome1 " + testMethod,
144+
fqdn + " " + T3CHANNELPORT + " weblogic welcome1 " + testMethod + " " + JDBC_URL,
132145
ADMINPODNAME,
133146
domain.getDomainNS());
134147
Assert.assertFalse(stdout.toLowerCase().contains("error"));
@@ -188,8 +201,7 @@ private static Domain createSitConfigDomain() throws Exception {
188201
// load input yaml to map and add configOverrides
189202
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAINONPV_WLST_YAML);
190203
domainMap.put("configOverrides", "sitconfigcm");
191-
domainMap.put(
192-
"configOverridesFile", "/integration-tests/src/test/resources/sitconfig/configoverrides");
204+
domainMap.put("configOverridesFile", sitconfigDir);
193205
domainMap.put("domainUID", DOMAINUID);
194206
domainMap.put("adminNodePort", new Integer(ADMINPORT));
195207
domainMap.put("t3ChannelPort", new Integer(T3CHANNELPORT));
@@ -199,7 +211,6 @@ private static Domain createSitConfigDomain() throws Exception {
199211
domainMap.put(
200212
"javaOptions",
201213
"-Dweblogic.debug.DebugSituationalConfig=true -Dweblogic.debug.DebugSituationalConfigDumpXml=true");
202-
203214
domain = TestUtils.createDomain(domainMap);
204215
domain.verifyDomainCreated();
205216
return domain;
@@ -234,4 +245,48 @@ private static String callShellScriptByExecToPod(
234245
logger.log(Level.INFO, result.stdout().trim());
235246
return result.stdout().trim();
236247
}
248+
249+
/**
250+
* create mysql crd
251+
*
252+
* @throws Exception
253+
*/
254+
public static void manageMySqlDB(String dbYaml, String task) throws Exception {
255+
StringBuffer cmd = new StringBuffer("kubectl " + task + " -f ");
256+
cmd.append(dbYaml);
257+
logger.info("Running " + cmd);
258+
ExecResult result = ExecCommand.exec(cmd.toString());
259+
if (result.exitValue() != 0) {
260+
logger.log(Level.INFO, result.stdout().trim());
261+
throw new RuntimeException(
262+
"FAILURE: command "
263+
+ cmd
264+
+ " failed, returned "
265+
+ result.stdout()
266+
+ "\n"
267+
+ result.stderr());
268+
}
269+
String outputStr = result.stdout().trim();
270+
logger.info("Command returned " + outputStr);
271+
}
272+
273+
private static void copySitConfigFiles() throws IOException {
274+
String src_dir = TESTSCRIPTDIR + "/sitconfig/configoverrides";
275+
String dst_dir = sitconfigDir;
276+
String files[] = {
277+
"config.xml",
278+
"jdbc-JdbcTestDataSource-0.xml",
279+
"diagnostics-WLDF-MODULE-0.xml",
280+
"jms-ClusterJmsSystemResource.xml",
281+
"version.txt"
282+
};
283+
for (String file : files) {
284+
Path path = Paths.get(src_dir, file);
285+
Charset charset = StandardCharsets.UTF_8;
286+
String content = new String(Files.readAllBytes(path), charset);
287+
content = content.replaceAll("JDBC_URL", JDBC_URL);
288+
path = Paths.get(dst_dir, file);
289+
Files.write(path, content.getBytes(charset), StandardOpenOption.TRUNCATE_EXISTING);
290+
}
291+
}
237292
}

integration-tests/src/test/resources/sitconfig/configoverrides/jdbc-JdbcTestDataSource-0.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<jdbc:inactive-connection-timeout-seconds jdbcf:combine-mode="add">120</jdbc:inactive-connection-timeout-seconds>
1313
</jdbc:jdbc-connection-pool-params>
1414
<jdbc:jdbc-driver-params>
15-
<jdbc:url jdbcf:combine-mode="replace">jdbc:oracle:thin:@//slc11smq.us.oracle.com:1583/w18ys12c.us.oracle.com</jdbc:url>
15+
<jdbc:url jdbcf:combine-mode="replace">JDBC_URL</jdbc:url>
1616
<jdbc:driver-name>oracle.jdbc.OracleDriver</jdbc:driver-name>
1717
<jdbc:properties>
1818
<jdbc:property>

integration-tests/src/test/resources/sitconfig/java/SitConfigTests.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public static void main(String args[]) throws Exception {
8383
test.verifyT3ChannelPublicPort(30091);
8484
}
8585
if (testName.equals("testCustomSitConfigOverridesForJdbc")) {
86-
test.testSystemResourcesJDBCAttributeChange("JdbcTestDataSource-0");
86+
String JDBC_URL = args[5];
87+
test.testSystemResourcesJDBCAttributeChange("JdbcTestDataSource-0", JDBC_URL);
8788
}
8889

8990
if (testName.equals("testSystemResourcesJDBCAttributeChangeSecret")) {
@@ -268,15 +269,12 @@ private ServerMBean getServerMBean() {
268269
return serverMBean;
269270
}
270271

271-
public void testSystemResourcesJDBCAttributeChange(String jdbcResourceName) {
272+
public void testSystemResourcesJDBCAttributeChange(String jdbcResourceName, String dsUrl) {
272273
int initialCapacity = 2;
273274
int maxCapacity = 12;
274275
boolean testConnectionsonReserve = true;
275276
int harvestMaxCount = 7;
276277
int inactiveConnectionTimeoutSeconds = 120;
277-
String dsUrl = "jdbc:oracle:thin:@//slc11smq.us.oracle.com:1583/w18ys12c.us.oracle.com";
278-
String dbInstanceName = "w18ys12c";
279-
String dbHostName = "slc11smq";
280278

281279
println("Verifying the configuration changes made by sit config file");
282280

@@ -314,13 +312,8 @@ public void testSystemResourcesJDBCAttributeChange(String jdbcResourceName) {
314312
try {
315313
Connection connection = dataSource.getConnection();
316314
Statement stmt = connection.createStatement();
317-
ResultSet rs = stmt.executeQuery("SELECT * FROM v$instance");
318-
while (rs.next()) {
319-
println("INSTANCE_NAME:" + rs.getString("INSTANCE_NAME"));
320-
assert dbInstanceName.equals(rs.getString("INSTANCE_NAME"));
321-
println("HOST_NAME:" + rs.getString("HOST_NAME"));
322-
assert dbHostName.equals(rs.getString("HOST_NAME"));
323-
}
315+
int createSchema = stmt.executeUpdate("CREATE SCHEMA `mysqldb` ;");
316+
assert createSchema == 0 : "create schema failed";
324317
} catch (SQLException ex) {
325318
Logger.getLogger(SitConfigTests.class.getName()).log(Level.SEVERE, null, ex);
326319
}

integration-tests/src/test/resources/sitconfig/scripts/create-domain-auto-custom-sit-config20.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def createDataSource(dsName, dsJNDI, dsUrl, dsUser, dsPassword, dsTarget):
103103

104104
cd('JDBCConnectionPoolParams/NO_NAME_0')
105105
set('TestTableName', 'SQL SELECT 1 FROM DUAL')
106-
#set('InitialCapacity', 1)
107-
#set('MinCapacity', 3)
106+
set('InitialCapacity', 0)
107+
set('MinCapacity', 0)
108108

109109
# This python script is used to create a WebLogic domain
110110

@@ -125,6 +125,9 @@ def createDataSource(dsName, dsJNDI, dsUrl, dsUser, dsPassword, dsTarget):
125125
domain_logs = getEnvVar("DOMAIN_LOGS_DIR")
126126
script_dir = getEnvVar("CREATE_DOMAIN_SCRIPT_DIR")
127127
production_mode_enabled = getEnvVar("PRODUCTION_MODE_ENABLED")
128+
jdbc_url = 'jdbc:mysql://HOSTNAME:NOPORT/'
129+
jdbc_user = 'user'
130+
jdbc_password = 'password'
128131

129132
# Read the domain secrets from the common python file
130133
execfile('%s/read-domain-secret.py' % script_dir)
@@ -227,7 +230,7 @@ def createDataSource(dsName, dsJNDI, dsUrl, dsUser, dsPassword, dsTarget):
227230

228231
print('Done setting attributes for Dynamic Cluster: %s' % cluster_name);
229232

230-
createDataSource('JdbcTestDataSource-0', 'jdbc/JdbcTestDataSource-0', 'jdbc:oracle:thin:@//slcai724.us.oracle.com:1583/w03ys12c', 'j2ee', 'j2ee', admin_server_name)
233+
createDataSource('JdbcTestDataSource-0', 'jdbc/JdbcTestDataSource-0', jdbc_url, jdbc_user, jdbc_password, admin_server_name)
231234
createJMSSystemResource(cluster_name)
232235
createWLDFSystemResource("WLDF-MODULE-0", admin_server_name)
233236

0 commit comments

Comments
 (0)