Skip to content

Commit 8f90428

Browse files
committed
samples for JRF support in 2.2
1 parent d461d8e commit 8f90428

File tree

11 files changed

+1199
-0
lines changed

11 files changed

+1199
-0
lines changed

kubernetes/samples/scripts/common/utility.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ function createFiles {
363363
sed -i -e "s:%DOMAIN_ROOT_DIR%:${domainPVMountPath}:g" ${createJobOutput}
364364
sed -i -e "s:%CREATE_DOMAIN_SCRIPT_DIR%:${createDomainScriptsMountPath}:g" ${createJobOutput}
365365
sed -i -e "s:%CREATE_DOMAIN_SCRIPT%:${createDomainScriptName}:g" ${createJobOutput}
366+
# extra entries for FMW Infra domains
367+
sed -i -e "s:%RCU_CREDENTIALS_SECRET_NAME%:${rcuCredentialsSecret}:g" ${createJobOutput}
368+
sed -i -e "s:%CUSTOM_RCUPREFIX%:${rcuSchemaPrefix}:g" ${createJobOutput}
369+
sed -i -e "s|%CUSTOM_CONNECTION_STRING%|${rcuDatabaseURL}|g" ${createJobOutput}
366370

367371
# Generate the yaml to create the kubernetes job that will delete the weblogic domain_home folder
368372
echo Generating ${deleteJobOutput}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
#
5+
6+
function exitIfError {
7+
if [ "$1" != "0" ]; then
8+
echo "$2"
9+
exit $1
10+
fi
11+
}
12+
13+
# Include common utility functions
14+
source ${CREATE_DOMAIN_SCRIPT_DIR}/utility.sh
15+
16+
# Verify the script to create the domain exists
17+
script=${CREATE_DOMAIN_SCRIPT_DIR}/create-domain-script.sh
18+
19+
checkCreateDomainScript $script
20+
checkDomainSecret
21+
prepareDomainHomeDir
22+
23+
# Execute the script to create the domain
24+
source $script
25+
exitIfError $? "ERROR: $script failed."
26+
27+
# DON'T REMOVE THIS
28+
# This script has to contain this log message.
29+
# It is used to determine if the job is really completed.
30+
echo "Successfully Completed"
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
#
2+
# Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
3+
#
4+
#Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
5+
#
6+
7+
import os
8+
import sys
9+
10+
import com.oracle.cie.domain.script.jython.WLSTException as WLSTException
11+
12+
class Infra12213Provisioner:
13+
14+
MACHINES = {
15+
'machine1' : {
16+
'NMType': 'SSL',
17+
'ListenAddress': 'localhost',
18+
'ListenPort': 5658
19+
}
20+
}
21+
22+
JRF_12213_TEMPLATES = {
23+
'baseTemplate' : '@@ORACLE_HOME@@/wlserver/common/templates/wls/wls.jar',
24+
'extensionTemplates' : [
25+
'@@ORACLE_HOME@@/oracle_common/common/templates/wls/oracle.jrf_template.jar',
26+
'@@ORACLE_HOME@@/oracle_common/common/templates/wls/oracle.jrf.ws.async_template.jar',
27+
'@@ORACLE_HOME@@/oracle_common/common/templates/wls/oracle.wsmpm_template.jar',
28+
'@@ORACLE_HOME@@/oracle_common/common/templates/wls/oracle.ums_template.jar',
29+
'@@ORACLE_HOME@@/em/common/templates/wls/oracle.em_wls_template.jar'
30+
],
31+
'serverGroupsToTarget' : [ 'JRF-MAN-SVR', 'WSMPM-MAN-SVR' ]
32+
}
33+
34+
def __init__(self, oracleHome, javaHome, domainParentDir, adminListenPort, adminName, managedNameBase, managedServerPort, prodMode, managedCount, clusterName):
35+
self.oracleHome = self.validateDirectory(oracleHome)
36+
self.javaHome = self.validateDirectory(javaHome)
37+
self.domainParentDir = self.validateDirectory(domainParentDir, create=True)
38+
return
39+
40+
def createInfraDomain(self, domainName, user, password, db, dbPrefix, dbPassword, adminListenPort, adminName, managedNameBase, managedServerPort, prodMode, managedCount, clusterName):
41+
domainHome = self.createBaseDomain(domainName, user, password, adminListenPort, adminName, managedNameBase, managedServerPort, prodMode, managedCount, clusterName)
42+
self.extendDomain(domainHome, db, dbPrefix, dbPassword)
43+
44+
def createBaseDomain(self, domainName, user, password, adminListenPort, adminName, managedNameBase, managedServerPort, prodMode, managedCount, clusterName):
45+
baseTemplate = self.replaceTokens(self.JRF_12213_TEMPLATES['baseTemplate'])
46+
47+
readTemplate(baseTemplate)
48+
setOption('DomainName', domainName)
49+
setOption('JavaHome', self.javaHome)
50+
if (prodMode == 'true'):
51+
setOption('ServerStartMode', 'prod')
52+
else:
53+
setOption('ServerStartMode', 'dev')
54+
set('Name', domainName)
55+
56+
admin_port = int(adminListenPort)
57+
ms_port = int(managedServerPort)
58+
ms_count = int(managedCount)
59+
60+
# Create Admin Server
61+
# =======================
62+
print 'Creating Admin Server...'
63+
cd('/Servers/AdminServer')
64+
#set('ListenAddress', '%s-%s' % (domain_uid, admin_server_name_svc))
65+
set('ListenPort', admin_port)
66+
set('Name', adminName)
67+
68+
# Define the user password for weblogic
69+
# =====================================
70+
cd('/Security/' + domainName + '/User/weblogic')
71+
set('Name', user)
72+
set('Password', password)
73+
74+
# Create a cluster
75+
# ======================
76+
print 'Creating cluster...'
77+
cd('/')
78+
cl=create(clusterName, 'Cluster')
79+
80+
# Create managed servers
81+
for index in range(0, ms_count):
82+
cd('/')
83+
msIndex = index+1
84+
cd('/')
85+
name = '%s%s' % (managedNameBase, msIndex)
86+
create(name, 'Server')
87+
cd('/Servers/%s/' % name )
88+
print('managed server name is %s' % name);
89+
set('ListenPort', ms_port)
90+
set('NumOfRetriesBeforeMSIMode', 0)
91+
set('RetryIntervalBeforeMSIMode', 1)
92+
set('Cluster', clusterName)
93+
94+
# Create Node Manager
95+
# =======================
96+
print 'Creating Node Managers...'
97+
for machine in self.MACHINES:
98+
cd('/')
99+
create(machine, 'Machine')
100+
cd('Machine/' + machine)
101+
create(machine, 'NodeManager')
102+
cd('NodeManager/' + machine)
103+
for param in self.MACHINES[machine]:
104+
set(param, self.MACHINES[machine][param])
105+
106+
107+
setOption('OverwriteDomain', 'true')
108+
domainHome = self.domainParentDir + '/' + domainName
109+
print 'Will create Base domain at ' + domainHome
110+
111+
print 'Writing base domain...'
112+
writeDomain(domainHome)
113+
closeTemplate()
114+
print 'Base domain created at ' + domainHome
115+
return domainHome
116+
117+
118+
def extendDomain(self, domainHome, db, dbPrefix, dbPassword):
119+
print 'Extending domain at ' + domainHome
120+
print 'Database ' + db
121+
readDomain(domainHome)
122+
setOption('AppDir', self.domainParentDir + '/applications')
123+
124+
print 'Applying JRF templates...'
125+
for extensionTemplate in self.JRF_12213_TEMPLATES['extensionTemplates']:
126+
addTemplate(self.replaceTokens(extensionTemplate))
127+
128+
print 'Extension Templates added'
129+
130+
print 'Configuring the Service Table DataSource...'
131+
fmwDb = 'jdbc:oracle:thin:@' + db
132+
print 'fmwDatabase ' + fmwDb
133+
cd('/JDBCSystemResource/LocalSvcTblDataSource/JdbcResource/LocalSvcTblDataSource')
134+
cd('JDBCDriverParams/NO_NAME_0')
135+
set('DriverName', 'oracle.jdbc.OracleDriver')
136+
set('URL', fmwDb)
137+
set('PasswordEncrypted', dbPassword)
138+
139+
stbUser = dbPrefix + '_STB'
140+
cd('Properties/NO_NAME_0/Property/user')
141+
set('Value', stbUser)
142+
143+
print 'Getting Database Defaults...'
144+
getDatabaseDefaults()
145+
146+
print 'Targeting Server Groups...'
147+
managedName= '%s%s' % (managedNameBase, 1)
148+
print "Set CoherenceClusterSystemResource to defaultCoherenceCluster for server:" + managedName
149+
serverGroupsToTarget = list(self.JRF_12213_TEMPLATES['serverGroupsToTarget'])
150+
cd('/')
151+
setServerGroups(managedName, serverGroupsToTarget)
152+
print "Set CoherenceClusterSystemResource to defaultCoherenceCluster for server:" + managedName
153+
cd('/Servers/' + managedName)
154+
set('CoherenceClusterSystemResource', 'defaultCoherenceCluster')
155+
156+
print 'Targeting Cluster ...'
157+
cd('/')
158+
print "Set CoherenceClusterSystemResource to defaultCoherenceCluster for cluster:" + clusterName
159+
cd('/Cluster/' + clusterName)
160+
set('CoherenceClusterSystemResource', 'defaultCoherenceCluster')
161+
print "Set WLS clusters as target of defaultCoherenceCluster:" + clusterName
162+
cd('/CoherenceClusterSystemResource/defaultCoherenceCluster')
163+
set('Target', clusterName)
164+
165+
print 'Preparing to update domain...'
166+
updateDomain()
167+
print 'Domain updated successfully'
168+
closeDomain()
169+
return
170+
171+
172+
###########################################################################
173+
# Helper Methods #
174+
###########################################################################
175+
176+
def validateDirectory(self, dirName, create=False):
177+
directory = os.path.realpath(dirName)
178+
if not os.path.exists(directory):
179+
if create:
180+
os.makedirs(directory)
181+
else:
182+
message = 'Directory ' + directory + ' does not exist'
183+
raise WLSTException(message)
184+
elif not os.path.isdir(directory):
185+
message = 'Directory ' + directory + ' is not a directory'
186+
raise WLSTException(message)
187+
return self.fixupPath(directory)
188+
189+
190+
def fixupPath(self, path):
191+
result = path
192+
if path is not None:
193+
result = path.replace('\\', '/')
194+
return result
195+
196+
197+
def replaceTokens(self, path):
198+
result = path
199+
if path is not None:
200+
result = path.replace('@@ORACLE_HOME@@', oracleHome)
201+
return result
202+
203+
204+
#############################
205+
# Entry point to the script #
206+
#############################
207+
208+
def usage():
209+
print sys.argv[0] + ' -oh <oracle_home> -jh <java_home> -parent <domain_parent_dir> -name <domain-name> ' + \
210+
'-user <domain-user> -password <domain-password> ' + \
211+
'-rcuDb <rcu-database> -rcuPrefix <rcu-prefix> -rcuSchemaPwd <rcu-schema-password> ' \
212+
'-adminListenPort <adminListenPort> -adminName <adminName> ' \
213+
'-managedNameBase <managedNameBase> -managedServerPort <managedServerPort> -prodMode <prodMode> ' \
214+
'-managedServerCount <managedCount> -clusterName <clusterName>'
215+
sys.exit(0)
216+
217+
# Uncomment for Debug only
218+
print str(sys.argv[0]) + " called with the following sys.argv array:"
219+
for index, arg in enumerate(sys.argv):
220+
print "sys.argv[" + str(index) + "] = " + str(sys.argv[index])
221+
222+
if len(sys.argv) < 16:
223+
usage()
224+
225+
#oracleHome will be passed by command line parameter -oh.
226+
oracleHome = None
227+
#javaHome will be passed by command line parameter -jh.
228+
javaHome = None
229+
#domainParentDir will be passed by command line parameter -parent.
230+
domainParentDir = None
231+
#domainUser is hard-coded to weblogic. You can change to other name of your choice. Command line paramter -user.
232+
domainUser = 'weblogic'
233+
#domainPassword will be passed by Command line parameter -password.
234+
#domainPassword = 'welcome1'
235+
domainPassword = None
236+
#rcuDb will be passed by command line parameter -rcuDb.
237+
rcuDb = None
238+
#change rcuSchemaPrefix to your infra schema prefix. Command line parameter -rcuPrefix.
239+
rcuSchemaPrefix = 'DEV12'
240+
#change rcuSchemaPassword to your infra schema password. Command line parameter -rcuSchemaPwd.
241+
#rcuSchemaPassword = 'welcome1'
242+
rcuSchemaPassword = None
243+
244+
i = 1
245+
while i < len(sys.argv):
246+
if sys.argv[i] == '-oh':
247+
oracleHome = sys.argv[i + 1]
248+
i += 2
249+
elif sys.argv[i] == '-jh':
250+
javaHome = sys.argv[i + 1]
251+
i += 2
252+
elif sys.argv[i] == '-parent':
253+
domainParentDir = sys.argv[i + 1]
254+
i += 2
255+
elif sys.argv[i] == '-name':
256+
domainName = sys.argv[i + 1]
257+
i += 2
258+
elif sys.argv[i] == '-user':
259+
domainUser = sys.argv[i + 1]
260+
i += 2
261+
elif sys.argv[i] == '-password':
262+
domainPassword = sys.argv[i + 1]
263+
i += 2
264+
elif sys.argv[i] == '-rcuDb':
265+
rcuDb = sys.argv[i + 1]
266+
i += 2
267+
elif sys.argv[i] == '-rcuPrefix':
268+
rcuSchemaPrefix = sys.argv[i + 1]
269+
i += 2
270+
elif sys.argv[i] == '-rcuSchemaPwd':
271+
rcuSchemaPassword = sys.argv[i + 1]
272+
i += 2
273+
elif sys.argv[i] == '-adminListenPort':
274+
adminListenPort = sys.argv[i + 1]
275+
i += 2
276+
elif sys.argv[i] == '-adminName':
277+
adminName = sys.argv[i + 1]
278+
i += 2
279+
elif sys.argv[i] == '-managedNameBase':
280+
managedNameBase = sys.argv[i + 1]
281+
i += 2
282+
elif sys.argv[i] == '-managedServerPort':
283+
managedServerPort = sys.argv[i + 1]
284+
i += 2
285+
elif sys.argv[i] == '-prodMode':
286+
prodMode = sys.argv[i + 1]
287+
i += 2
288+
elif sys.argv[i] == '-managedServerCount':
289+
managedCount = sys.argv[i + 1]
290+
i += 2
291+
elif sys.argv[i] == '-clusterName':
292+
clusterName = sys.argv[i + 1]
293+
i += 2
294+
else:
295+
print 'Unexpected argument switch at position ' + str(i) + ': ' + str(sys.argv[i])
296+
usage()
297+
sys.exit(1)
298+
299+
provisioner = Infra12213Provisioner(oracleHome, javaHome, domainParentDir, adminListenPort, adminName, managedNameBase, managedServerPort, prodMode, managedCount, clusterName)
300+
provisioner.createInfraDomain(domainName, domainUser, domainPassword, rcuDb, rcuSchemaPrefix, rcuSchemaPassword, adminListenPort, adminName, managedNameBase, managedServerPort, prodMode, managedCount, clusterName)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
5+
#
6+
# Report an error and fail the job
7+
# $1 - text of error
8+
function fail {
9+
echo ERROR: $1
10+
exit 1
11+
}
12+
13+
#
14+
# Create a folder
15+
# $1 - path of folder to create
16+
function createFolder {
17+
mkdir -m 777 -p $1
18+
if [ ! -d $1 ]; then
19+
fail "Unable to create folder $1"
20+
fi
21+
}
22+
23+
function checkCreateDomainScript {
24+
if [ -f $1 ]; then
25+
echo The domain will be created using the script $1
26+
else
27+
fail "Could not locate the domain creation script ${1}"
28+
fi
29+
}
30+
31+
function checkDomainSecret {
32+
33+
# Validate the domain secrets exist before proceeding.
34+
if [ ! -f /weblogic-operator/secrets/username ]; then
35+
fail "The domain secret /weblogic-operator/secrets/username was not found"
36+
fi
37+
if [ ! -f /weblogic-operator/secrets/password ]; then
38+
fail "The domain secret /weblogic-operator/secrets/password was not found"
39+
fi
40+
}
41+
42+
function prepareDomainHomeDir {
43+
# Do not proceed if the domain already exists
44+
local domainFolder=${DOMAIN_HOME_DIR}
45+
if [ -d ${domainFolder} ]; then
46+
fail "The create domain job will not overwrite an existing domain. The domain folder ${domainFolder} already exists"
47+
fi
48+
49+
# Create the base folders
50+
createFolder ${DOMAIN_ROOT_DIR}/domains
51+
createFolder ${DOMAIN_LOGS_DIR}
52+
createFolder ${DOMAIN_ROOT_DIR}/applications
53+
createFolder ${DOMAIN_ROOT_DIR}/stores
54+
}
55+

0 commit comments

Comments
 (0)