Skip to content

Commit d85fe2f

Browse files
committed
add custom sit config override test for t3 public address
1 parent 143cf4f commit d85fe2f

File tree

6 files changed

+310
-4
lines changed

6 files changed

+310
-4
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class ITOperator extends BaseTest {
4949
private static String domain9YamlFile = "domain9.yaml";
5050
private static String domain10YamlFile = "domain10.yaml";
5151
private static String domain11YamlFile = "domain11.yaml";
52+
private static String domain12YamlFile = "domain12.yaml";
5253

5354
// property file used to configure constants for integration tests
5455
private static String appPropsFile = "OperatorIT.properties";
@@ -490,6 +491,7 @@ public void testAutoSitConfigOverrides() throws Exception {
490491
domain11 = testDomainCreation(domain11YamlFile);
491492
domain11.verifyDomainCreated();
492493
testBasicUseCases(domain11);
494+
// testAdvancedUseCasesForADomain(operator1, domain11);
493495
testCompletedSuccessfully = true;
494496
logger.info("SUCCESS - testAutoSitConfigOverrides");
495497
} finally {
@@ -503,6 +505,47 @@ public void testAutoSitConfigOverrides() throws Exception {
503505
}
504506
}
505507

508+
@Test
509+
public void testCustomSitConfigOverrides() throws Exception {
510+
Assume.assumeFalse(QUICKTEST);
511+
logTestBegin("testCustomSitConfigOverrides");
512+
513+
if (operator1 == null) {
514+
operator1 = TestUtils.createOperator(op1YamlFile);
515+
}
516+
Domain domain12 = null;
517+
boolean testCompletedSuccessfully = false;
518+
String createDomainScriptDir =
519+
BaseTest.getProjectRoot() + "/integration-tests/src/test/resources/domain-home-on-pv";
520+
try {
521+
522+
// cp py
523+
Files.copy(
524+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
525+
new File(createDomainScriptDir + "/create-domain.py.bak").toPath(),
526+
StandardCopyOption.REPLACE_EXISTING);
527+
Files.copy(
528+
new File(createDomainScriptDir + "/create-domain-custom-sit-config.py").toPath(),
529+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
530+
StandardCopyOption.REPLACE_EXISTING);
531+
532+
domain12 = testDomainCreation(domain12YamlFile);
533+
domain12.verifyDomainCreated();
534+
testBasicUseCases(domain12);
535+
// testAdvancedUseCasesForADomain(operator1, domain11);
536+
testCompletedSuccessfully = true;
537+
logger.info("SUCCESS - testCustomSitConfigOverrides");
538+
} finally {
539+
Files.copy(
540+
new File(createDomainScriptDir + "/create-domain.py.bak").toPath(),
541+
new File(createDomainScriptDir + "/create-domain.py").toPath(),
542+
StandardCopyOption.REPLACE_EXISTING);
543+
if (domain12 != null && (JENKINS || testCompletedSuccessfully)) {
544+
domain12.destroy();
545+
}
546+
}
547+
}
548+
506549
private Domain testAdvancedUseCasesForADomain(Operator operator, Domain domain) throws Exception {
507550
if (!SMOKETEST) {
508551
testClusterScaling(operator, domain);

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

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.file.Files;
1111
import java.nio.file.Path;
1212
import java.nio.file.Paths;
13+
import java.nio.file.StandardOpenOption;
1314
import java.util.HashMap;
1415
import java.util.Map;
1516
import java.util.Objects;
@@ -668,11 +669,14 @@ private void generateInputYaml() throws Exception {
668669

669670
private void callCreateDomainScript(String outputDir) throws Exception {
670671
StringBuffer cmd = new StringBuffer(BaseTest.getProjectRoot());
672+
671673
cmd.append(
672674
"/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain.sh -i ")
673-
.append(generatedInputYamlFile)
674-
.append(" -e -v -o ")
675-
.append(outputDir);
675+
.append(generatedInputYamlFile);
676+
if (!domainMap.containsKey("configOverrides")) {
677+
cmd.append(" -e ");
678+
}
679+
cmd.append(" -v -o ").append(outputDir);
676680
logger.info("Running " + cmd);
677681
ExecResult result = ExecCommand.exec(cmd.toString(), true);
678682
if (result.exitValue() != 0) {
@@ -686,6 +690,37 @@ private void callCreateDomainScript(String outputDir) throws Exception {
686690
}
687691
String outputStr = result.stdout().trim();
688692
logger.info("Command returned " + outputStr);
693+
694+
// write configOverride and configOverrideSecrets to domain.yaml
695+
if (domainMap.containsKey("configOverrides")) {
696+
String contentToAppend =
697+
" configOverrides: "
698+
+ domainUid
699+
+ "-"
700+
+ domainMap.get("configOverrides")
701+
+ "\n"
702+
+ " configOverrideSecrets: [ \""
703+
+ domainUid
704+
+ "-t3publicaddress\" ]"
705+
+ "\n";
706+
707+
String domainYaml =
708+
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain.yaml";
709+
Files.write(Paths.get(domainYaml), contentToAppend.getBytes(), StandardOpenOption.APPEND);
710+
711+
String command = "kubectl create -f " + domainYaml;
712+
result = ExecCommand.exec(command);
713+
if (result.exitValue() != 0) {
714+
throw new RuntimeException(
715+
"FAILURE: command "
716+
+ cmd
717+
+ " failed, returned "
718+
+ result.stdout()
719+
+ "\n"
720+
+ result.stderr());
721+
}
722+
logger.info("Command returned " + result.stdout().trim());
723+
}
689724
}
690725

691726
private void createLoadBalancer() throws Exception {
@@ -790,7 +825,12 @@ private void callWebAppAndCheckForServerNameInResponse(
790825
ExecResult result = ExecCommand.exec(curlCmd.toString());
791826
if (result.exitValue() != 0) {
792827
throw new RuntimeException(
793-
"FAILURE: command " + curlCmd + " failed, returned " + result.stderr());
828+
"FAILURE: command "
829+
+ curlCmd
830+
+ " failed, returned "
831+
+ result.stderr()
832+
+ " \n "
833+
+ result.stdout());
794834
} else {
795835
logger.info("webapp invoked successfully");
796836
}
@@ -889,6 +929,56 @@ private void initialize(String inputYaml) throws Exception {
889929
}
890930
// remove null values if any attributes
891931
domainMap.values().removeIf(Objects::isNull);
932+
933+
// create config map and secret for custom sit config
934+
if (domainMap.get("configOverrides") != null) {
935+
// write hostname in config file for public address
936+
937+
String cmd =
938+
"kubectl -n "
939+
+ domainNS
940+
+ " create cm "
941+
+ domainUid
942+
+ "-"
943+
+ domainMap.get("configOverrides")
944+
+ " --from-file "
945+
+ BaseTest.getProjectRoot()
946+
+ "/integration-tests/src/test/resources/domain-home-on-pv/customsitconfig";
947+
ExecResult result = ExecCommand.exec(cmd);
948+
if (result.exitValue() != 0) {
949+
throw new RuntimeException(
950+
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
951+
}
952+
cmd =
953+
"kubectl -n "
954+
+ domainNS
955+
+ " label cm "
956+
+ domainUid
957+
+ "-"
958+
+ domainMap.get("configOverrides")
959+
+ " weblogic.domainUID="
960+
+ domainUid;
961+
result = ExecCommand.exec(cmd);
962+
if (result.exitValue() != 0) {
963+
throw new RuntimeException(
964+
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
965+
}
966+
// create secret for custom sit config t3 public address
967+
cmd =
968+
"kubectl -n "
969+
+ domainNS
970+
+ " create secret generic "
971+
+ domainUid
972+
+ "-"
973+
+ "t3publicaddress "
974+
+ " --from-literal=hostname="
975+
+ TestUtils.getHostName();
976+
result = ExecCommand.exec(cmd);
977+
if (result.exitValue() != 0) {
978+
throw new RuntimeException(
979+
"FAILURE: command " + cmd + " failed, returned " + result.stderr());
980+
}
981+
}
892982
}
893983

894984
private String getNodeHost() throws Exception {
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
def getEnvVar(var):
5+
val=os.environ.get(var)
6+
if val==None:
7+
print "ERROR: Env var ",var, " not set."
8+
sys.exit(1)
9+
return val
10+
11+
# This python script is used to create a WebLogic domain
12+
13+
domain_uid = getEnvVar("DOMAIN_UID")
14+
server_port = int(getEnvVar("MANAGED_SERVER_PORT"))
15+
domain_path = getEnvVar("DOMAIN_HOME")
16+
cluster_name = getEnvVar("CLUSTER_NAME")
17+
admin_server_name = getEnvVar("ADMIN_SERVER_NAME")
18+
admin_server_name_svc = getEnvVar("ADMIN_SERVER_NAME_SVC")
19+
admin_port = int(getEnvVar("ADMIN_PORT"))
20+
domain_name = getEnvVar("DOMAIN_NAME")
21+
t3_channel_port = int(getEnvVar("T3_CHANNEL_PORT"))
22+
t3_public_address = getEnvVar("T3_PUBLIC_ADDRESS")
23+
number_of_ms = int(getEnvVar("CONFIGURED_MANAGED_SERVER_COUNT"))
24+
cluster_type = getEnvVar("CLUSTER_TYPE")
25+
managed_server_name_base = getEnvVar("MANAGED_SERVER_NAME_BASE")
26+
managed_server_name_base_svc = getEnvVar("MANAGED_SERVER_NAME_BASE_SVC")
27+
domain_logs = getEnvVar("DOMAIN_LOGS_DIR")
28+
script_dir = getEnvVar("CREATE_DOMAIN_SCRIPT_DIR")
29+
production_mode_enabled = getEnvVar("PRODUCTION_MODE_ENABLED")
30+
31+
# Read the domain secrets from the common python file
32+
execfile('%s/read-domain-secret.py' % script_dir)
33+
34+
print('domain_path : [%s]' % domain_path);
35+
print('domain_name : [%s]' % domain_name);
36+
print('admin_server_name : [%s]' % admin_server_name);
37+
print('admin_username : [%s]' % admin_username);
38+
print('admin_port : [%s]' % admin_port);
39+
print('cluster_name : [%s]' % cluster_name);
40+
print('server_port : [%s]' % server_port);
41+
# Open default domain template
42+
# ============================
43+
readTemplate("/u01/oracle/wlserver/common/templates/wls/wls.jar")
44+
45+
set('Name', domain_name)
46+
setOption('DomainName', domain_name)
47+
48+
# Configure the Administration Server
49+
# ===================================
50+
cd('/Servers/AdminServer')
51+
# Give incorrect listenaddress, introspector overrides with sit-config
52+
set('ListenAddress', '')
53+
set('ListenPort', admin_port)
54+
set('Name', admin_server_name)
55+
56+
create('T3Channel', 'NetworkAccessPoint')
57+
cd('/Servers/%s/NetworkAccessPoints/T3Channel' % admin_server_name)
58+
set('PublicPort', t3_channel_port)
59+
set('PublicAddress', 'junkvalue')
60+
# Give incorrect listenaddress, introspector overrides with sit-config
61+
set('ListenAddress', '')
62+
set('ListenPort', t3_channel_port)
63+
64+
cd('/Servers/%s' % admin_server_name)
65+
create(admin_server_name,'Log')
66+
cd('/Servers/%s/Log/%s' % (admin_server_name, admin_server_name))
67+
# Give incorrect filelog, introspector overrides with sit-config
68+
set('FileName', 'dirdoesnotexist')
69+
70+
71+
72+
# Set the admin user's username and password
73+
# ==========================================
74+
cd('/Security/%s/User/weblogic' % domain_name)
75+
cmo.setName(admin_username)
76+
cmo.setPassword(admin_password)
77+
78+
# Write the domain and close the domain template
79+
# ==============================================
80+
setOption('OverwriteDomain', 'true')
81+
82+
# Create a cluster
83+
# ======================
84+
cd('/')
85+
cl=create(cluster_name, 'Cluster')
86+
87+
if cluster_type == "CONFIGURED":
88+
89+
# Create managed servers
90+
for index in range(0, number_of_ms):
91+
cd('/')
92+
93+
msIndex = index+1
94+
name = '%s%s' % (managed_server_name_base, msIndex)
95+
name_svc = '%s%s' % (managed_server_name_base_svc, msIndex)
96+
97+
create(name, 'Server')
98+
cd('/Servers/%s/' % name )
99+
print('managed server name is %s' % name);
100+
set('ListenAddress', '%s-%s' % (domain_uid, name_svc))
101+
set('ListenPort', server_port)
102+
set('NumOfRetriesBeforeMSIMode', 0)
103+
set('RetryIntervalBeforeMSIMode', 1)
104+
set('Cluster', cluster_name)
105+
106+
else:
107+
print('Configuring Dynamic Cluster %s' % cluster_name)
108+
109+
templateName = cluster_name + "-template"
110+
print('Creating Server Template: %s' % templateName)
111+
st1=create(templateName, 'ServerTemplate')
112+
print('Done creating Server Template: %s' % templateName)
113+
cd('/ServerTemplates/%s' % templateName)
114+
cmo.setListenPort(server_port)
115+
cmo.setListenAddress('%s-%s${id}' % (domain_uid, managed_server_name_base_svc))
116+
cmo.setCluster(cl)
117+
print('Done setting attributes for Server Template: %s' % templateName);
118+
119+
120+
cd('/Clusters/%s' % cluster_name)
121+
create(cluster_name, 'DynamicServers')
122+
cd('DynamicServers/%s' % cluster_name)
123+
set('ServerTemplate', st1)
124+
set('ServerNamePrefix', managed_server_name_base)
125+
set('DynamicClusterSize', number_of_ms)
126+
set('MaxDynamicClusterSize', number_of_ms)
127+
set('CalculatedListenPorts', false)
128+
set('Id', 1)
129+
130+
print('Done setting attributes for Dynamic Cluster: %s' % cluster_name);
131+
132+
# Write Domain
133+
# ============
134+
writeDomain(domain_path)
135+
closeTemplate()
136+
print 'Domain Created'
137+
138+
# Update Domain
139+
readDomain(domain_path)
140+
cd('/')
141+
if production_mode_enabled == "true":
142+
cmo.setProductionModeEnabled(true)
143+
else:
144+
cmo.setProductionModeEnabled(false)
145+
updateDomain()
146+
closeDomain()
147+
print 'Domain Updated'
148+
print 'Done'
149+
150+
# Exit WLST
151+
# =========
152+
exit()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<domain xmlns="http://xmlns.oracle.com/weblogic/domain" xmlns:f="http://xmlns.oracle.com/weblogic/domain-fragment" xmlns:s="http://xmlns.oracle.com/weblogic/situational-config">
2+
<server>
3+
<name>admin-server</name>
4+
<network-access-point>
5+
<name>T3Channel</name>
6+
<public-address f:combine-mode="replace">slc11vit.us.oracle.com</public-address>
7+
</network-access-point>
8+
</server>
9+
</domain>
10+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
domainUID: domain12
5+
namespace: default
6+
configuredManagedServerCount: 4
7+
initialManagedServerReplicas: 2
8+
exposeAdminT3Channel: true
9+
exposeAdminNodePort: true
10+
configOverrides: domain12-sitconfigcm

0 commit comments

Comments
 (0)