Skip to content

Commit d2c1735

Browse files
committed
javadoc and refactoring
1 parent ce91911 commit d2c1735

File tree

2 files changed

+104
-80
lines changed

2 files changed

+104
-80
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 2019 Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

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

Lines changed: 103 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@ public class Domain {
5252
private String clusterName;
5353
private String clusterType;
5454
private String serverStartPolicy;
55-
private String weblogicDomainStorageReclaimPolicy;
56-
private String weblogicDomainStorageSize;
5755
private String loadBalancer = "TRAEFIK";
5856
private int loadBalancerWebPort = 30305;
5957
private String domainHomeImageBuildPath = "";
6058
private String userProjectsDir = "";
6159
private String projectRoot = "";
6260
private boolean ingressPerDomain = true;
6361

64-
private String createDomainScript = "";
65-
private String inputTemplateFile = "";
6662
private String generatedInputYamlFile;
6763

6864
private static int maxIterations = BaseTest.getMaxIterationsPod(); // 50 * 5 = 250 seconds
@@ -119,9 +115,7 @@ public void verifyPodsCreated() throws Exception {
119115
logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Running");
120116
TestUtils.checkPodCreated(domainUid + "-" + adminServerName, domainNS);
121117

122-
if (domainMap.get("serverStartPolicy") == null
123-
|| (domainMap.get("serverStartPolicy") != null
124-
&& !domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY"))) {
118+
if (!serverStartPolicy.equals("ADMIN_ONLY")) {
125119
// check managed server pods
126120
for (int i = 1; i <= initialManagedServerReplicas; i++) {
127121
logger.info(
@@ -155,9 +149,8 @@ public void verifyServicesCreated() throws Exception {
155149
+ "-external) is created");
156150
TestUtils.checkServiceCreated(domainUid + "-" + adminServerName + "-external", domainNS);
157151
}
158-
if (domainMap.get("serverStartPolicy") == null
159-
|| (domainMap.get("serverStartPolicy") != null
160-
&& !domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY"))) {
152+
153+
if (!serverStartPolicy.equals("ADMIN_ONLY")) {
161154
// check managed server services
162155
for (int i = 1; i <= initialManagedServerReplicas; i++) {
163156
logger.info(
@@ -181,18 +174,15 @@ public void verifyServersReady() throws Exception {
181174
// check admin pod
182175
logger.info("Checking if admin server is Running");
183176
TestUtils.checkPodReady(domainUid + "-" + adminServerName, domainNS);
184-
if (domainMap.get("serverStartPolicy") == null
185-
|| (domainMap.get("serverStartPolicy") != null
186-
&& !domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY"))) {
187177

178+
if (!serverStartPolicy.equals("ADMIN_ONLY")) {
188179
// check managed server pods
189180
for (int i = 1; i <= initialManagedServerReplicas; i++) {
190181
logger.info("Checking if managed server (" + managedServerNameBase + i + ") is Running");
191182
TestUtils.checkPodReady(domainUid + "-" + managedServerNameBase + i, domainNS);
192183
}
193-
}
194-
// check no additional servers are started
195-
if (domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY")) {
184+
} else {
185+
// check no additional servers are started
196186
initialManagedServerReplicas = 0;
197187
}
198188
String additionalManagedServer =
@@ -824,6 +814,12 @@ private int getAdminSericeLBNodePort() throws Exception {
824814
}
825815
}
826816

817+
/**
818+
* Create a map with attributes required to create PV and create PV dir by calling
819+
* PersistentVolume
820+
*
821+
* @throws Exception
822+
*/
827823
private void createPV() throws Exception {
828824

829825
Yaml yaml = new Yaml();
@@ -850,10 +846,6 @@ private void createPV() throws Exception {
850846
pvMap.put("weblogicDomainStorageSize", domainMap.get("weblogicDomainStorageSize"));
851847
}
852848
pvMap.put("namespace", domainNS);
853-
854-
weblogicDomainStorageReclaimPolicy = (String) pvMap.get("weblogicDomainStorageReclaimPolicy");
855-
weblogicDomainStorageSize = (String) pvMap.get("weblogicDomainStorageSize");
856-
857849
pvMap.put("weblogicDomainStorageNFSServer", TestUtils.getHostName());
858850

859851
// set pv path
@@ -946,9 +938,7 @@ public void verifyAdminServerRestarted() throws Exception {
946938
* @throws Exception
947939
*/
948940
public void verifyManagedServersRestarted() throws Exception {
949-
if (domainMap.get("serverStartPolicy") == null
950-
|| (domainMap.get("serverStartPolicy") != null
951-
&& !domainMap.get("serverStartPolicy").toString().trim().equals("ADMIN_ONLY"))) {
941+
if (!serverStartPolicy.equals("ADMIN_ONLY")) {
952942
// check managed server pods
953943
for (int i = 1; i <= initialManagedServerReplicas; i++) {
954944
logger.info(
@@ -972,6 +962,11 @@ public void verifyManagedServersRestarted() throws Exception {
972962
}
973963
}
974964

965+
/**
966+
* create secret
967+
*
968+
* @throws Exception
969+
*/
975970
private void createSecret() throws Exception {
976971
Secret secret =
977972
new Secret(
@@ -996,13 +991,25 @@ private void createSecret() throws Exception {
996991
}
997992
}
998993

994+
/**
995+
* Generate domain values yaml using the doamin map
996+
*
997+
* @throws Exception
998+
*/
999999
private void generateInputYaml() throws Exception {
10001000
Path parentDir =
10011001
Files.createDirectories(Paths.get(userProjectsDir + "/weblogic-domains/" + domainUid));
10021002
generatedInputYamlFile = parentDir + "/weblogic-domain-values.yaml";
10031003
TestUtils.createInputFile(domainMap, generatedInputYamlFile);
10041004
}
10051005

1006+
/**
1007+
* copy create-domain.py if domain Map contains, git clone docker-images for domain in image and
1008+
* call create-domain.sh script based on the domain type. Append configOverrides to domain.yaml.
1009+
*
1010+
* @param outputDir
1011+
* @throws Exception
1012+
*/
10061013
private void callCreateDomainScript(String outputDir) throws Exception {
10071014

10081015
// call different create domain script based on the domain type
@@ -1233,6 +1240,13 @@ private void callWebAppAndCheckForServerNameInResponse(
12331240
}
12341241
}
12351242

1243+
/**
1244+
* Reads the create-domain-inputs.yaml from samples and overrides with attribute in input domain
1245+
* map. Initializes the variables for the attributes in the map to be used later.
1246+
*
1247+
* @param inputDomainMap
1248+
* @throws Exception
1249+
*/
12361250
private void initialize(Map<String, Object> inputDomainMap) throws Exception {
12371251
domainMap = inputDomainMap;
12381252
this.userProjectsDir = BaseTest.getUserProjectsDir();
@@ -1281,8 +1295,8 @@ private void initialize(Map<String, Object> inputDomainMap) throws Exception {
12811295
exposeAdminNodePort = ((Boolean) domainMap.get("exposeAdminNodePort")).booleanValue();
12821296
t3ChannelPort = ((Integer) domainMap.get("t3ChannelPort")).intValue();
12831297
clusterName = (String) domainMap.get("clusterName");
1284-
clusterType = (String) domainMap.get("clusterType");
1285-
serverStartPolicy = (String) domainMap.get("serverStartPolicy");
1298+
clusterType = (String) domainMap.getOrDefault("clusterType", "DYNAMIC");
1299+
serverStartPolicy = ((String) domainMap.get("serverStartPolicy")).trim();
12861300

12871301
if (exposeAdminT3Channel) {
12881302
domainMap.put("t3PublicAddress", TestUtils.getHostName());
@@ -1329,58 +1343,7 @@ private void initialize(Map<String, Object> inputDomainMap) throws Exception {
13291343
domainMap.values().removeIf(Objects::isNull);
13301344

13311345
// create config map and secret for custom sit config
1332-
if ((domainMap.get("configOverrides") != null)
1333-
&& (domainMap.get("configOverridesFile") != null)) {
1334-
// write hostname in config file for public address
1335-
1336-
String configOverridesFile = domainMap.get("configOverridesFile").toString();
1337-
1338-
String cmd =
1339-
"kubectl -n "
1340-
+ domainNS
1341-
+ " create cm "
1342-
+ domainUid
1343-
+ "-"
1344-
+ domainMap.get("configOverrides")
1345-
+ " --from-file "
1346-
+ configOverridesFile;
1347-
ExecResult result = ExecCommand.exec(cmd);
1348-
if (result.exitValue() != 0) {
1349-
throw new RuntimeException(
1350-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
1351-
}
1352-
cmd =
1353-
"kubectl -n "
1354-
+ domainNS
1355-
+ " label cm "
1356-
+ domainUid
1357-
+ "-"
1358-
+ domainMap.get("configOverrides")
1359-
+ " weblogic.domainUID="
1360-
+ domainUid;
1361-
result = ExecCommand.exec(cmd);
1362-
if (result.exitValue() != 0) {
1363-
throw new RuntimeException(
1364-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
1365-
}
1366-
// create secret for custom sit config t3 public address
1367-
// create datasource secret for user and password
1368-
cmd =
1369-
"kubectl -n "
1370-
+ domainNS
1371-
+ " create secret generic "
1372-
+ domainUid
1373-
+ "-test-secrets"
1374-
+ " --from-literal=hostname="
1375-
+ TestUtils.getHostName()
1376-
+ " --from-literal=dbusername=root"
1377-
+ " --from-literal=dbpassword=root123";
1378-
result = ExecCommand.exec(cmd);
1379-
if (result.exitValue() != 0) {
1380-
throw new RuntimeException(
1381-
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
1382-
}
1383-
}
1346+
createConfigMapAndSecretForSitConfig();
13841347
}
13851348

13861349
private String getNodeHost() throws Exception {
@@ -1433,6 +1396,11 @@ private String getNodePort() throws Exception {
14331396
}
14341397
}
14351398

1399+
/**
1400+
* clone docker-images sample
1401+
*
1402+
* @throws Exception
1403+
*/
14361404
private void gitCloneDockerImagesSample() throws Exception {
14371405
if (!domainHomeImageBuildPath.isEmpty()) {
14381406
StringBuffer removeAndClone = new StringBuffer();
@@ -1466,6 +1434,11 @@ private void gitCloneDockerImagesSample() throws Exception {
14661434
}
14671435
}
14681436

1437+
/**
1438+
* append configOverrides to domain.yaml
1439+
*
1440+
* @throws Exception
1441+
*/
14691442
private void appendToDomainYamlAndCreate() throws Exception {
14701443
String contentToAppend =
14711444
" configOverrides: "
@@ -1584,8 +1557,7 @@ private void changeClusterTypeInCreateDomainJobTemplate() throws Exception {
15841557

15851558
// change CLUSTER_TYPE to CONFIGURED in create-domain-job-template.yaml for configured cluster
15861559
// as samples only support DYNAMIC cluster
1587-
if (domainMap.containsKey("clusterType")
1588-
&& domainMap.get("clusterType").toString().equalsIgnoreCase("CONFIGURED")) {
1560+
if (clusterType.equalsIgnoreCase("CONFIGURED")) {
15891561

15901562
// domain in image
15911563
if (domainMap.containsKey("domainHomeImageBase")
@@ -1604,4 +1576,56 @@ private void changeClusterTypeInCreateDomainJobTemplate() throws Exception {
16041576
}
16051577
}
16061578
}
1579+
1580+
/**
1581+
* create config map and secret for custom situational configuration
1582+
*
1583+
* @throws Exception
1584+
*/
1585+
private void createConfigMapAndSecretForSitConfig() throws Exception {
1586+
1587+
if ((domainMap.get("configOverrides") != null)
1588+
&& (domainMap.get("configOverridesFile") != null)) {
1589+
// write hostname in config file for public address
1590+
String configOverridesFile = domainMap.get("configOverridesFile").toString();
1591+
1592+
// create configmap
1593+
String cmd =
1594+
"kubectl -n "
1595+
+ domainNS
1596+
+ " create cm "
1597+
+ domainUid
1598+
+ "-"
1599+
+ domainMap.get("configOverrides")
1600+
+ " --from-file "
1601+
+ configOverridesFile;
1602+
TestUtils.exec(cmd);
1603+
1604+
// create label for configmap
1605+
cmd =
1606+
"kubectl -n "
1607+
+ domainNS
1608+
+ " label cm "
1609+
+ domainUid
1610+
+ "-"
1611+
+ domainMap.get("configOverrides")
1612+
+ " weblogic.domainUID="
1613+
+ domainUid;
1614+
TestUtils.exec(cmd);
1615+
1616+
// create secret for custom sit config t3 public address
1617+
// create datasource secret for user and password
1618+
cmd =
1619+
"kubectl -n "
1620+
+ domainNS
1621+
+ " create secret generic "
1622+
+ domainUid
1623+
+ "-test-secrets"
1624+
+ " --from-literal=hostname="
1625+
+ TestUtils.getHostName()
1626+
+ " --from-literal=dbusername=root"
1627+
+ " --from-literal=dbpassword=root123";
1628+
TestUtils.exec(cmd);
1629+
}
1630+
}
16071631
}

0 commit comments

Comments
 (0)