4
4
package com .oracle .weblogic .imagetool .cli .menu ;
5
5
6
6
import java .io .File ;
7
- import java .io .FileInputStream ;
8
7
import java .io .IOException ;
9
8
import java .nio .file .Files ;
10
9
import java .nio .file .Path ;
13
12
import java .time .Instant ;
14
13
import java .util .ArrayList ;
15
14
import java .util .HashSet ;
16
- import java .util .LinkedList ;
17
15
import java .util .List ;
18
16
import java .util .Properties ;
19
17
import java .util .Set ;
20
- import java .util .logging .Level ;
21
- import java .util .stream .Collectors ;
22
18
23
19
import com .oracle .weblogic .imagetool .api .model .CommandResponse ;
24
- import com .oracle .weblogic .imagetool .api .model .DomainType ;
25
20
import com .oracle .weblogic .imagetool .api .model .InstallerType ;
26
21
import com .oracle .weblogic .imagetool .api .model .WLSInstallerType ;
27
22
import com .oracle .weblogic .imagetool .impl .InstallerFile ;
28
23
import com .oracle .weblogic .imagetool .logging .LoggingFacade ;
29
24
import com .oracle .weblogic .imagetool .logging .LoggingFactory ;
30
25
import com .oracle .weblogic .imagetool .util .ARUUtil ;
31
26
import com .oracle .weblogic .imagetool .util .Constants ;
32
- import com .oracle .weblogic .imagetool .util .HttpUtil ;
33
27
import com .oracle .weblogic .imagetool .util .Utils ;
34
28
import com .oracle .weblogic .imagetool .util .ValidationResult ;
35
29
import picocli .CommandLine .Command ;
@@ -80,12 +74,7 @@ public CommandResponse call() throws Exception {
80
74
Utils .copyResourceAsFile ("/probe-env/test-create-env.sh" ,
81
75
tmpDir + File .separator + "test-env.sh" , true );
82
76
83
- List <String > imageEnvCmd = Utils .getDockerRunCmd (tmpDir , fromImage , "test-env.sh" );
84
- Properties baseImageProperties = Utils .runDockerCommand (imageEnvCmd );
85
- if (logger .isLoggable (Level .FINE )) {
86
- baseImageProperties .keySet ().forEach (x -> logger .fine ("ENV(" + fromImage + "): "
87
- + x + "=" + baseImageProperties .getProperty (x .toString ())));
88
- }
77
+ Properties baseImageProperties = Utils .getBaseImageProperties (fromImage , tmpDir );
89
78
90
79
boolean ohAlreadyExists = baseImageProperties .getProperty ("WLS_VERSION" , null ) != null ;
91
80
@@ -144,34 +133,6 @@ public CommandResponse call() throws Exception {
144
133
+ Duration .between (startTime , endTime ).getSeconds () + "s. image tag: " + imageTag );
145
134
}
146
135
147
- /**
148
- * Builds a list of build args to pass on to docker with the required installer files.
149
- * Also, creates links to installer files instead of copying over to build context dir.
150
- *
151
- * @param tmpDir build context directory
152
- * @return list of strings
153
- * @throws Exception in case of error
154
- */
155
- private List <String > handleInstallerFiles (String tmpDir ) throws Exception {
156
-
157
- logger .entering (tmpDir );
158
- List <String > retVal = new LinkedList <>();
159
- List <InstallerFile > requiredInstallers = gatherRequiredInstallers ();
160
- for (InstallerFile installerFile : requiredInstallers ) {
161
- String targetFilePath = installerFile .resolve (cacheStore );
162
- logger .finer ("copying targetFilePath: {0}" , targetFilePath );
163
- String filename = new File (targetFilePath ).getName ();
164
- try {
165
- Files .copy (Paths .get (targetFilePath ), Paths .get (tmpDir , filename ));
166
- retVal .addAll (installerFile .getBuildArg (filename ));
167
- } catch (Exception ee ) {
168
- ee .printStackTrace ();
169
- }
170
- }
171
- logger .exiting (retVal );
172
- return retVal ;
173
- }
174
-
175
136
@ Override
176
137
List <String > handlePatchFiles (String tmpDir , Path tmpPatchesDir ) throws Exception {
177
138
logger .finer ("Entering CreateImage.handlePatchFiles: " + tmpDir );
@@ -209,110 +170,16 @@ List<String> handlePatchFiles(String tmpDir, Path tmpPatchesDir) throws Exceptio
209
170
return super .handlePatchFiles (tmpDir , tmpPatchesDir );
210
171
}
211
172
212
- /**
213
- * Checks whether the user requested a domain to be created with WDT.
214
- * If so, returns the required build args to pass to docker and creates required file links to pass
215
- * the model, archive, variables file to build process
216
- *
217
- * @param tmpDir the tmp directory which is passed to docker as the build context directory
218
- * @return list of build args
219
- * @throws IOException in case of error
220
- */
221
- private List <String > handleWdtArgsIfRequired (String tmpDir ) throws IOException {
222
- logger .finer ("Entering CreateImage.handleWdtArgsIfRequired: " + tmpDir );
223
- List <String > retVal = new LinkedList <>();
224
- if (wdtModelPath != null ) {
225
- String [] modelFiles = wdtModelPath .toString ().split ("," );
226
- List <String > modelList = new ArrayList <>();
227
-
228
- for (String modelFile : modelFiles ) {
229
- Path modelFilePath = Paths .get (modelFile );
230
- if (Files .isRegularFile (modelFilePath )) {
231
- String modelFilename = modelFilePath .getFileName ().toString ();
232
- Files .copy (modelFilePath , Paths .get (tmpDir , modelFilename ));
233
- modelList .add (modelFilename );
234
- } else {
235
- throw new IOException ("WDT model file " + modelFile + " not found" );
236
- }
237
- }
238
- dockerfileOptions .setWdtModels (modelList );
239
-
240
- if (wdtDomainType != DomainType .WLS ) {
241
- if (installerType != WLSInstallerType .FMW ) {
242
- throw new IOException ("FMW installer is required for JRF domain" );
243
- }
244
- retVal .add (Constants .BUILD_ARG );
245
- retVal .add ("DOMAIN_TYPE=" + wdtDomainType );
246
- if (runRcu ) {
247
- retVal .add (Constants .BUILD_ARG );
248
- retVal .add ("RCU_RUN_FLAG=" + "-run_rcu" );
249
- }
250
- }
251
- dockerfileOptions .setWdtEnabled ();
252
-
253
- if (wdtArchivePath != null && Files .isRegularFile (wdtArchivePath )) {
254
- String wdtArchiveFilename = wdtArchivePath .getFileName ().toString ();
255
- Files .copy (wdtArchivePath , Paths .get (tmpDir , wdtArchiveFilename ));
256
- retVal .add (Constants .BUILD_ARG );
257
- retVal .add ("WDT_ARCHIVE=" + wdtArchiveFilename );
258
- }
259
- if (wdtDomainHome != null ) {
260
- retVal .add (Constants .BUILD_ARG );
261
- retVal .add ("DOMAIN_HOME=" + wdtDomainHome );
262
- }
263
-
264
- if (wdtVariablesPath != null && Files .isRegularFile (wdtVariablesPath )) {
265
- String wdtVariableFilename = wdtVariablesPath .getFileName ().toString ();
266
- Files .copy (wdtVariablesPath , Paths .get (tmpDir , wdtVariableFilename ));
267
- retVal .add (Constants .BUILD_ARG );
268
- retVal .add ("WDT_VARIABLE=" + wdtVariableFilename );
269
- retVal .addAll (getWdtRequiredBuildArgs (wdtVariablesPath ));
270
- }
271
- }
272
- logger .finer ("Exiting CreateImage.handleWdtArgsIfRequired: " );
273
- return retVal ;
274
- }
275
-
276
- /**
277
- * Certain environment variables need to be set in docker images for WDT domains to work.
278
- *
279
- * @param wdtVariablesPath wdt variables file path.
280
- * @return list of build args
281
- * @throws IOException in case of error
282
- */
283
- private List <String > getWdtRequiredBuildArgs (Path wdtVariablesPath ) throws IOException {
284
- logger .finer ("Entering CreateImage.getWdtRequiredBuildArgs: " + wdtVariablesPath .toAbsolutePath ().toString ());
285
- List <String > retVal = new LinkedList <>();
286
- Properties variableProps = new Properties ();
287
- variableProps .load (new FileInputStream (wdtVariablesPath .toFile ()));
288
- List <Object > matchingKeys = variableProps .keySet ().stream ().filter (
289
- x -> variableProps .getProperty (((String ) x )) != null
290
- && Constants .REQD_WDT_BUILD_ARGS .contains (((String ) x ).toUpperCase ())
291
- ).collect (Collectors .toList ());
292
- matchingKeys .forEach (x -> {
293
- retVal .add (Constants .BUILD_ARG );
294
- retVal .add (((String ) x ).toUpperCase () + "=" + variableProps .getProperty ((String ) x ));
295
- });
296
- logger .finer ("Exiting CreateImage.getWdtRequiredBuildArgs: " );
297
- return retVal ;
298
- }
299
-
300
173
/**
301
174
* Builds a list of {@link InstallerFile} objects based on user input which are processed.
302
175
* to download the required install artifacts
303
176
*
304
177
* @return list of InstallerFile
305
178
* @throws Exception in case of error
306
179
*/
307
- private List <InstallerFile > gatherRequiredInstallers () throws Exception {
180
+ protected List <InstallerFile > gatherRequiredInstallers () throws Exception {
308
181
logger .entering ();
309
- List <InstallerFile > retVal = new LinkedList <>();
310
- if (wdtModelPath != null ) {
311
- logger .finer ("IMG-0001" , InstallerType .WDT , wdtVersion );
312
- InstallerFile wdtInstaller = new InstallerFile (useCache , InstallerType .WDT , wdtVersion , null , null );
313
- retVal .add (wdtInstaller );
314
- addWdtUrl (wdtInstaller .getKey ());
315
- }
182
+ List <InstallerFile > retVal = super .gatherRequiredInstallers ();
316
183
logger .finer ("IMG-0001" , installerType , installerVersion );
317
184
retVal .add (new InstallerFile (useCache , InstallerType .fromValue (installerType .toString ()), installerVersion ,
318
185
userId , password ));
@@ -324,32 +191,6 @@ private List<InstallerFile> gatherRequiredInstallers() throws Exception {
324
191
return retVal ;
325
192
}
326
193
327
- /**
328
- * Parses wdtVersion and constructs the url to download WDT and adds the url to cache.
329
- *
330
- * @param wdtKey key in the format wdt_0.17
331
- * @throws Exception in case of error
332
- */
333
- private void addWdtUrl (String wdtKey ) throws Exception {
334
- logger .entering (wdtKey );
335
- String wdtUrlKey = wdtKey + "_url" ;
336
- if (cacheStore .getValueFromCache (wdtKey ) == null ) {
337
- if (userId == null || password == null ) {
338
- throw new Exception ("CachePolicy prohibits download. Add the required wdt installer to cache" );
339
- }
340
- List <String > wdtTags = HttpUtil .getWDTTags ();
341
- String tagToMatch = "latest" .equalsIgnoreCase (wdtVersion ) ? wdtTags .get (0 ) :
342
- "weblogic-deploy-tooling-" + wdtVersion ;
343
- if (wdtTags .contains (tagToMatch )) {
344
- String downloadLink = String .format (Constants .WDT_URL_FORMAT , tagToMatch );
345
- logger .info ("IMG-0007" , downloadLink );
346
- cacheStore .addToCache (wdtUrlKey , downloadLink );
347
- } else {
348
- throw new Exception ("Couldn't find WDT download url for version:" + wdtVersion );
349
- }
350
- }
351
- logger .exiting ();
352
- }
353
194
354
195
/**
355
196
* Copies response files required for wls install to the tmp directory which provides docker build context.
@@ -373,23 +214,23 @@ private void copyResponseFilesToDir(String dirPath) throws IOException {
373
214
374
215
@ Option (
375
216
names = {"--type" },
376
- description = "Installer type. default : ${DEFAULT-VALUE}. supported values: ${COMPLETION-CANDIDATES}" ,
217
+ description = "Installer type. Default : ${DEFAULT-VALUE}. Supported values: ${COMPLETION-CANDIDATES}" ,
377
218
required = true ,
378
219
defaultValue = "wls"
379
220
)
380
221
private WLSInstallerType installerType ;
381
222
382
223
@ Option (
383
224
names = {"--version" },
384
- description = "Installer version. default : ${DEFAULT-VALUE}" ,
225
+ description = "Installer version. Default : ${DEFAULT-VALUE}" ,
385
226
required = true ,
386
227
defaultValue = Constants .DEFAULT_WLS_VERSION
387
228
)
388
229
private String installerVersion ;
389
230
390
231
@ Option (
391
232
names = {"--jdkVersion" },
392
- description = "Version of server jdk to install. default : ${DEFAULT-VALUE}" ,
233
+ description = "Version of server jdk to install. Default : ${DEFAULT-VALUE}" ,
393
234
required = true ,
394
235
defaultValue = Constants .DEFAULT_JDK_VERSION
395
236
)
@@ -401,63 +242,13 @@ private void copyResponseFilesToDir(String dirPath) throws IOException {
401
242
)
402
243
private String fromImage ;
403
244
404
- @ Option (
405
- names = {"--wdtModel" },
406
- description = "path to the wdt model file to create domain with"
407
- )
408
- private Path wdtModelPath ;
409
-
410
- @ Option (
411
- names = {"--wdtArchive" },
412
- description = "path to wdt archive file used by wdt model"
413
- )
414
- private Path wdtArchivePath ;
415
-
416
- @ Option (
417
- names = {"--wdtVariables" },
418
- description = "path to wdt variables file used by wdt model"
419
- )
420
- private Path wdtVariablesPath ;
421
-
422
- @ Option (
423
- names = {"--wdtVersion" },
424
- description = "wdt version to create the domain" ,
425
- defaultValue = "latest"
426
- )
427
- private String wdtVersion ;
428
-
429
- @ Option (
430
- names = {"--wdtDomainType" },
431
- description = "type of domain to create. default: ${DEFAULT-VALUE}. supported values: "
432
- + "${COMPLETION-CANDIDATES}" ,
433
- defaultValue = "wls" ,
434
- required = true
435
- )
436
- private DomainType wdtDomainType ;
437
-
438
- @ Option (
439
- names = "--wdtRunRCU" ,
440
- description = "whether to run rcu to create the required database schemas"
441
- )
442
- private boolean runRcu = false ;
443
-
444
-
445
- @ Option (
446
- names = {"--wdtDomainHome" },
447
- description = "pass to the -domain_home for wdt" ,
448
- defaultValue = "/u01/domains/base_domain"
449
- )
450
- private String wdtDomainHome ;
451
-
452
-
453
245
@ Option (
454
246
names = {"--opatchBugNumber" },
455
247
description = "use this opatch patch bug number" ,
456
248
defaultValue = "28186730"
457
249
)
458
250
private String opatchBugNumber ;
459
251
460
-
461
252
@ Option (
462
253
names = {"--installerResponseFile" },
463
254
description = "path to a response file. Override the default responses for the Oracle installer"
0 commit comments