3
3
4
4
package oracle .weblogic .kubernetes ;
5
5
6
+ import java .io .File ;
7
+ import java .io .FileOutputStream ;
8
+ import java .nio .file .Path ;
9
+ import java .nio .file .Paths ;
10
+ import java .util .ArrayList ;
11
+ import java .util .Arrays ;
6
12
import java .util .List ;
13
+ import java .util .Properties ;
7
14
15
+ import io .kubernetes .client .openapi .models .V1Container ;
16
+ import io .kubernetes .client .openapi .models .V1EnvVar ;
17
+ import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
18
+ import io .kubernetes .client .openapi .models .V1ObjectMeta ;
19
+ import io .kubernetes .client .openapi .models .V1PersistentVolumeClaimVolumeSource ;
20
+ import io .kubernetes .client .openapi .models .V1SecretReference ;
21
+ import io .kubernetes .client .openapi .models .V1Volume ;
22
+ import io .kubernetes .client .openapi .models .V1VolumeMount ;
23
+ import oracle .weblogic .domain .AdminServer ;
24
+ import oracle .weblogic .domain .AdminService ;
25
+ import oracle .weblogic .domain .Channel ;
26
+ import oracle .weblogic .domain .Cluster ;
27
+ import oracle .weblogic .domain .Domain ;
28
+ import oracle .weblogic .domain .DomainSpec ;
29
+ import oracle .weblogic .domain .ServerPod ;
8
30
import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
9
31
import oracle .weblogic .kubernetes .annotations .Namespaces ;
10
32
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
33
+ import oracle .weblogic .kubernetes .utils .CommonTestUtils ;
11
34
import oracle .weblogic .kubernetes .utils .DbUtils ;
12
35
import org .awaitility .core .ConditionFactory ;
13
36
import org .junit .jupiter .api .BeforeAll ;
16
39
17
40
import static java .util .concurrent .TimeUnit .MINUTES ;
18
41
import static java .util .concurrent .TimeUnit .SECONDS ;
42
+ import static oracle .weblogic .kubernetes .TestConstants .ADMIN_PASSWORD_DEFAULT ;
43
+ import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
19
44
import static oracle .weblogic .kubernetes .TestConstants .DB_IMAGE_NAME ;
20
45
import static oracle .weblogic .kubernetes .TestConstants .DB_IMAGE_TAG ;
46
+ import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
21
47
import static oracle .weblogic .kubernetes .TestConstants .JRF_BASE_IMAGE_NAME ;
22
48
import static oracle .weblogic .kubernetes .TestConstants .JRF_BASE_IMAGE_TAG ;
49
+ import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
23
50
import static oracle .weblogic .kubernetes .TestConstants .KIND_REPO ;
51
+ import static oracle .weblogic .kubernetes .TestConstants .OCR_EMAIL ;
52
+ import static oracle .weblogic .kubernetes .TestConstants .OCR_PASSWORD ;
24
53
import static oracle .weblogic .kubernetes .TestConstants .OCR_REGISTRY ;
54
+ import static oracle .weblogic .kubernetes .TestConstants .OCR_SECRET_NAME ;
55
+ import static oracle .weblogic .kubernetes .TestConstants .OCR_USERNAME ;
56
+ import static oracle .weblogic .kubernetes .actions .ActionConstants .RESOURCE_DIR ;
57
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReady ;
58
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkServiceExists ;
59
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createDockerRegistrySecret ;
60
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createDomainAndVerify ;
61
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createSecretWithUsernamePassword ;
62
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .installAndVerifyOperator ;
25
63
import static oracle .weblogic .kubernetes .utils .TestUtils .getNextFreePort ;
26
64
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
27
65
import static org .awaitility .Awaitility .with ;
@@ -42,16 +80,21 @@ public class ItJrfDomainInPV {
42
80
private static final String RCUSCHEMAPREFIX = "jrfdomainpv" ;
43
81
private static final String ORACLEDBURLPREFIX = "oracledb." ;
44
82
private static final String ORACLEDBSUFFIX = ".svc.cluster.local:1521/devpdb.k8s" ;
45
-
83
+ private static final String RCUSYSUSERNAME = "sys" ;
84
+ private static final String RCUSYSPASSWORD = "Oradoc_db1" ;
85
+ private static final String RCUSCHEMAUSERNAME = "myrcuuser" ;
86
+ private static final String RCUSCHEMAPASSWORD = "Oradoc_db1" ;
46
87
47
88
private static String dbUrl = null ;
48
- private static int dbPort = getNextFreePort (30000 , 32767 );
49
-
50
89
private static String fmwImage = JRF_BASE_IMAGE_NAME + ":" + JRF_BASE_IMAGE_TAG ;
51
90
private static String dbImage = DB_IMAGE_NAME + ":" + DB_IMAGE_TAG ;
52
91
private static boolean isUseSecret = true ;
53
92
private static LoggingFacade logger = null ;
54
93
94
+ private final String domainUid = "jrfdomain-inpv" ;
95
+ private final String wlSecretName = domainUid + "-weblogic-credentials" ;
96
+ private final String rcuSecretName = domainUid + "-rcu-credentials" ;
97
+
55
98
// create standard, reusable retry/backoff policy
56
99
private static final ConditionFactory withStandardRetryPolicy
57
100
= with ().pollDelay (2 , SECONDS )
@@ -67,38 +110,33 @@ public class ItJrfDomainInPV {
67
110
* @param namespaces injected by JUnit
68
111
*/
69
112
@ BeforeAll
70
- public static void initAll (@ Namespaces (1 ) List <String > namespaces ) {
113
+ public static void initAll (@ Namespaces (3 ) List <String > namespaces ) {
114
+
71
115
logger = getLogger ();
72
116
logger .info ("Assign a unique namespace for DB and RCU" );
73
117
assertNotNull (namespaces .get (0 ), "Namespace is null" );
74
118
dbNamespace = namespaces .get (0 );
75
119
dbUrl = ORACLEDBURLPREFIX + dbNamespace + ORACLEDBSUFFIX ;
76
120
77
- /*
78
- TODO temporarily being commented out. Will be needed when JRF domain is added
79
- logger.info("Assign a unique namespace for DB and RCU");
121
+ logger .info ("Assign a unique namespace for operator" );
80
122
assertNotNull (namespaces .get (1 ), "Namespace is null" );
81
123
opNamespace = namespaces .get (1 );
82
124
83
125
logger .info ("Assign a unique namespace for JRF domain" );
84
126
assertNotNull (namespaces .get (2 ), "Namespace is null" );
85
127
jrfDomainNamespace = namespaces .get (2 );
86
128
87
- //TODO in the final version when JRF domain is added setupDBandRCUschema should be here
88
- //start DB and create RCU schema
89
- logger.info("Start DB and create RCU schema for namespace : {0} RCU prefix : {1} dbPort : {2} "
90
- + "dbUrl: {3} dbImage: {4} fmwImage: {5}", dbNamespace, RCUSCHEMAPREFIX, dbPort, dbUrl, dbImage, fmwImage );
129
+ final int dbPort = getNextFreePort ( 30000 , 32767 );
130
+ logger . info ( "Start DB and create RCU schema for namespace: {0}, RCU prefix: {1}, dbPort: {2} "
131
+ + "dbUrl: {3} dbImage : {4}, fmwImage : {5} isUseSecret : {6}" , dbNamespace , RCUSCHEMAPREFIX , dbPort , dbUrl ,
132
+ dbImage , fmwImage , isUseSecret );
91
133
assertDoesNotThrow (() -> DbUtils .setupDBandRCUschema (dbImage , fmwImage , RCUSCHEMAPREFIX , dbNamespace ,
92
- dbPort, dbUrl), String.format("Failed to create RCU schema for prefix %s in the namespace %s with "
93
- + "dbPort %s and dbUrl %s", RCUSCHEMAPREFIX, dbNamespace, dbPort, dbUrl));
94
-
134
+ dbPort , dbUrl , isUseSecret ), String .format ("Failed to create RCU schema for prefix %s in the namespace %s with "
135
+ + "dbPort %s and dbUrl %s" , RCUSCHEMAPREFIX , dbNamespace , dbPort , dbUrl , isUseSecret ));
95
136
96
137
// install operator and verify its running in ready state
97
- installAndVerifyOperator(opNamespace, jrftDomainNamespace );
138
+ installAndVerifyOperator (opNamespace , jrfDomainNamespace );
98
139
99
- */
100
-
101
- //determine if the tests are running in Kind cluster. if true use images from Kind registry
102
140
//determine if the tests are running in Kind cluster. if true use images from Kind registry
103
141
if (KIND_REPO != null ) {
104
142
dbImage = KIND_REPO + DB_IMAGE_NAME .substring (OCR_REGISTRY .length () + 1 )
@@ -116,21 +154,196 @@ public static void initAll(@Namespaces(1) List<String> namespaces) {
116
154
* Create a JRF domain using WLST in a persistent volume.
117
155
* Create a domain custom resource with domainHomeSourceType as PersistentVolume.
118
156
* Verify domain pods runs in ready state and services are created.
119
- * Verify login to WebLogic console is successful.
120
157
*/
121
158
@ Test
122
159
@ DisplayName ("Create JRF domain in PV using WLST script" )
123
160
public void testJrfDomainInPvUsingWlst () {
161
+ final String clusterName = "cluster-jrfdomain-inpv" ;
162
+ final String adminServerName = "wlst-admin-server" ;
163
+ final String adminServerPodName = domainUid + "-" + adminServerName ;
164
+ final String managedServerNameBase = "wlst-ms-" ;
165
+ final int managedServerPort = 8001 ;
166
+ final String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase ;
167
+ final int replicaCount = 2 ;
168
+ final int t3ChannelPort = getNextFreePort (30000 , 32767 );
169
+
170
+ final String pvName = domainUid + "-pv" ;
171
+ final String pvcName = domainUid + "-pvc" ;
172
+
173
+ // create pull secrets for jrfDomainNamespace when running in non Kind Kubernetes cluster
174
+ if (isUseSecret ) {
175
+ createDockerRegistrySecret (OCR_USERNAME , OCR_PASSWORD ,
176
+ OCR_EMAIL , OCR_REGISTRY , OCR_SECRET_NAME , jrfDomainNamespace );
177
+ }
178
+
179
+ // create JRF domain credential secret
180
+ createSecretWithUsernamePassword (wlSecretName , jrfDomainNamespace ,
181
+ ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT );
182
+
183
+ // create RCU credential secret
184
+ CommonTestUtils .createRcuSecretWithUsernamePassword (rcuSecretName , jrfDomainNamespace ,
185
+ RCUSCHEMAUSERNAME , RCUSCHEMAPASSWORD , RCUSYSUSERNAME , RCUSYSPASSWORD );
186
+
187
+ // create persistent volume and persistent volume claim for domain
188
+ CommonTestUtils .createPV (pvName , domainUid , this .getClass ().getSimpleName ());
189
+ CommonTestUtils .createPVC (pvName , pvcName , domainUid , jrfDomainNamespace );
190
+
191
+ // create a temporary WebLogic domain property file
192
+ File domainPropertiesFile = assertDoesNotThrow (() ->
193
+ File .createTempFile ("domain" , "properties" ),
194
+ "Failed to create domain properties file" );
195
+ Properties p = new Properties ();
196
+ p .setProperty ("oracleHome" , "/u01/oracle" ); //default $ORACLE_HOME
197
+ p .setProperty ("javaHome" , "/u01/jdk" ); //default $JAVA_HOME
198
+ p .setProperty ("domainParentDir" , "/shared/domains/" );
199
+ p .setProperty ("domainName" , domainUid );
200
+ p .setProperty ("domainUser" , ADMIN_USERNAME_DEFAULT );
201
+ p .setProperty ("domainPassword" , ADMIN_PASSWORD_DEFAULT );
202
+ p .setProperty ("rcuDb" , dbUrl );
203
+ p .setProperty ("rcuSchemaPrefix" , RCUSCHEMAPREFIX );
204
+ p .setProperty ("rcuSchemaPassword" , RCUSCHEMAPASSWORD );
205
+ p .setProperty ("adminListenPort" , "7001" );
206
+ p .setProperty ("adminName" , adminServerName );
207
+ p .setProperty ("managedNameBase" , managedServerNameBase );
208
+ p .setProperty ("managedServerPort" ,Integer .toString (managedServerPort ));
209
+ p .setProperty ("prodMode" , "true" );
210
+ p .setProperty ("managedCount" , "4" );
211
+ p .setProperty ("clusterName" , clusterName );
212
+ p .setProperty ("t3ChannelPublicAddress" , K8S_NODEPORT_HOST );
213
+ p .setProperty ("t3ChannelPort" , Integer .toString (t3ChannelPort ));
214
+ p .setProperty ("exposeAdminT3Channel" , "true" );
215
+
216
+ assertDoesNotThrow (() ->
217
+ p .store (new FileOutputStream (domainPropertiesFile ), "jrf wlst properties file" ),
218
+ "Failed to write domain properties file" );
219
+
220
+ // WLST script for creating domain
221
+ Path wlstScript = Paths .get (RESOURCE_DIR , "python-scripts" , "jrf-wlst-create-domain-onpv.py" );
222
+
223
+ // create configmap and domain on persistent volume using the WLST script and property file
224
+ createDomainOnPVUsingWlst (wlstScript , domainPropertiesFile .toPath (),
225
+ pvName , pvcName , jrfDomainNamespace );
226
+
227
+ // create a domain custom resource configuration object
228
+ logger .info ("Creating domain custom resource" );
229
+ Domain domain = new Domain ()
230
+ .apiVersion (DOMAIN_API_VERSION )
231
+ .kind ("Domain" )
232
+ .metadata (new V1ObjectMeta ()
233
+ .name (domainUid )
234
+ .namespace (jrfDomainNamespace ))
235
+ .spec (new DomainSpec ()
236
+ .domainUid (domainUid )
237
+ .domainHome ("/shared/domains/" + domainUid ) // point to domain home in pv
238
+ .domainHomeSourceType ("PersistentVolume" ) // set the domain home source type as pv
239
+ .image (fmwImage )
240
+ .imagePullPolicy ("IfNotPresent" )
241
+ .imagePullSecrets (isUseSecret ? Arrays .asList (
242
+ new V1LocalObjectReference ()
243
+ .name (OCR_SECRET_NAME ))
244
+ : null )
245
+ .webLogicCredentialsSecret (new V1SecretReference ()
246
+ .name (wlSecretName )
247
+ .namespace (jrfDomainNamespace ))
248
+ .includeServerOutInPodLog (true )
249
+ .logHomeEnabled (Boolean .TRUE )
250
+ .logHome ("/shared/logs/" + domainUid )
251
+ .dataHome ("" )
252
+ .serverStartPolicy ("IF_NEEDED" )
253
+ .serverPod (new ServerPod () //serverpod
254
+ .addEnvItem (new V1EnvVar ()
255
+ .name ("JAVA_OPTIONS" )
256
+ .value ("-Dweblogic.StdoutDebugEnabled=false" ))
257
+ .addEnvItem (new V1EnvVar ()
258
+ .name ("USER_MEM_ARGS" )
259
+ .value ("-Djava.security.egd=file:/dev/./urandom " ))
260
+ .addVolumesItem (new V1Volume ()
261
+ .name (pvName )
262
+ .persistentVolumeClaim (new V1PersistentVolumeClaimVolumeSource ()
263
+ .claimName (pvcName )))
264
+ .addVolumeMountsItem (new V1VolumeMount ()
265
+ .mountPath ("/shared" )
266
+ .name (pvName )))
267
+ .adminServer (new AdminServer () //admin server
268
+ .serverStartState ("RUNNING" )
269
+ .adminService (new AdminService ()
270
+ .addChannelsItem (new Channel ()
271
+ .channelName ("default" )
272
+ .nodePort (0 ))
273
+ .addChannelsItem (new Channel ()
274
+ .channelName ("T3Channel" )
275
+ .nodePort (t3ChannelPort ))))
276
+ .addClustersItem (new Cluster () //cluster
277
+ .clusterName (clusterName )
278
+ .replicas (replicaCount )
279
+ .serverStartState ("RUNNING" )));
280
+
281
+ // verify the domain custom resource is created
282
+ createDomainAndVerify (domain , jrfDomainNamespace );
283
+
284
+ // verify the admin server service created
285
+ checkServiceExists (adminServerPodName , jrfDomainNamespace );
286
+
287
+ // verify admin server pod is ready
288
+ checkPodReady (adminServerPodName , domainUid , jrfDomainNamespace );
289
+
290
+ // verify managed server services created
291
+ for (int i = 1 ; i <= replicaCount ; i ++) {
292
+ logger .info ("Checking managed server service {0} is created in namespace {1}" ,
293
+ managedServerPodNamePrefix + i , jrfDomainNamespace );
294
+ checkServiceExists (managedServerPodNamePrefix + i , jrfDomainNamespace );
295
+ }
296
+
297
+ // verify managed server pods are ready
298
+ for (int i = 1 ; i <= replicaCount ; i ++) {
299
+ logger .info ("Waiting for managed server pod {0} to be ready in namespace {1}" ,
300
+ managedServerPodNamePrefix + i , jrfDomainNamespace );
301
+ checkPodReady (managedServerPodNamePrefix + i , domainUid , jrfDomainNamespace );
302
+ }
124
303
125
- //TODO temporarily being here. Will be moved to BeforeAll when JRF domain is added
126
- logger .info ("Start DB and create RCU schema for namespace: {0} RCU prefix: {1} dbPort: {2} "
127
- + "dbUrl: {3} dbImage: {4} fmwImage: {5} isUseSecret: {6}" , dbNamespace , RCUSCHEMAPREFIX , dbPort , dbUrl ,
128
- dbImage , fmwImage , isUseSecret );
129
- assertDoesNotThrow (() -> DbUtils .setupDBandRCUschema (dbImage , fmwImage , RCUSCHEMAPREFIX , dbNamespace ,
130
- dbPort , dbUrl , isUseSecret ), String .format ("Failed to create RCU schema for prefix %s in the namespace %s with "
131
- + "dbPort %s and dbUrl %s" , RCUSCHEMAPREFIX , dbNamespace , dbPort , dbUrl , isUseSecret ));
132
304
}
133
305
306
+ /**
307
+ * Create a WebLogic domain on a persistent volume by doing the following.
308
+ * Create a configmap containing WLST script and property file.
309
+ * Create a Kubernetes job to create domain on persistent volume.
310
+ *
311
+ * @param wlstScriptFile python script file to create domain
312
+ * @param domainPropertiesFile properties file containing domain configuration
313
+ * @param pvName name of the persistent volume to create domain in
314
+ * @param pvcName name of the persistent volume claim
315
+ * @param namespace name of the domain namespace in which the job is created
316
+ */
317
+ private void createDomainOnPVUsingWlst (Path wlstScriptFile , Path domainPropertiesFile ,
318
+ String pvName , String pvcName , String namespace ) {
319
+
320
+ logger .info ("Preparing to run create domain job using WLST" );
321
+
322
+ List <Path > domainScriptFiles = new ArrayList <>();
323
+ domainScriptFiles .add (wlstScriptFile );
324
+ domainScriptFiles .add (domainPropertiesFile );
325
+
326
+ logger .info ("Creating a config map to hold domain creation scripts" );
327
+ String domainScriptConfigMapName = "create-domain-scripts-cm" ;
328
+ assertDoesNotThrow (
329
+ () -> CommonTestUtils .createConfigMapForDomainCreation (domainScriptConfigMapName , domainScriptFiles ,
330
+ namespace , this .getClass ().getSimpleName ()),
331
+ "Create configmap for domain creation failed" );
332
+
333
+ // create a V1Container with specific scripts and properties for creating domain
334
+ V1Container jobCreationContainer = new V1Container ()
335
+ .addCommandItem ("/bin/sh" )
336
+ .addArgsItem ("/u01/oracle/oracle_common/common/bin/wlst.sh" )
337
+ .addArgsItem ("/u01/weblogic/" + wlstScriptFile .getFileName ()) //wlst.sh script
338
+ .addArgsItem ("-skipWLSModuleScanning" )
339
+ .addArgsItem ("-loadProperties" )
340
+ .addArgsItem ("/u01/weblogic/" + domainPropertiesFile .getFileName ()); //domain property file
341
+
342
+ logger .info ("Running a Kubernetes job to create the domain" );
343
+ CommonTestUtils .createDomainJob (fmwImage , isUseSecret , pvName , pvcName , domainScriptConfigMapName ,
344
+ jrfDomainNamespace , jobCreationContainer );
345
+
346
+ }
134
347
135
348
}
136
349
0 commit comments