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 )
0 commit comments