Skip to content

Commit 2440213

Browse files
removing option to store model in archive file (#1334)
* removing option to store model in archive file * updating copyrights * fixing busted test * addressing PR comments
1 parent 38af23d commit 2440213

File tree

16 files changed

+112
-403
lines changed

16 files changed

+112
-403
lines changed

core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java

Lines changed: 6 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
* Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.util;
@@ -188,7 +188,7 @@ public WLSDeployArchive(String archiveFileName) {
188188
}
189189

190190
/**
191-
* Determine whether or not the specified path string is a valid archive location.
191+
* Determine if the specified path string is a valid archive location.
192192
*
193193
* @param path the path
194194
* @return true if the path is relative and starts with the expected directory name, false otherwise
@@ -227,106 +227,6 @@ public String getArchiveFileName() {
227227
return getZipFile().getFileName();
228228
}
229229

230-
/**
231-
* Adds the model file into the archive.
232-
*
233-
* @param model the model file to add
234-
* @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes
235-
* @throws IllegalArgumentException if the model is null, does not exist, or is not a file
236-
*/
237-
public void addModel(File model) throws WLSDeployArchiveIOException {
238-
final String METHOD = "addModel";
239-
240-
LOGGER.entering(CLASS, METHOD, model);
241-
validateExistingFile(model, "model", getArchiveFileName(), METHOD);
242-
getZipFile().removeZipEntries(ARCHIVE_MODEL_TARGET_DIR);
243-
addItemToZip(ARCHIVE_MODEL_TARGET_DIR, model);
244-
LOGGER.exiting(CLASS, METHOD);
245-
}
246-
247-
/**
248-
* Adds the model file into the archive using the specified model file name.
249-
*
250-
* @param model the file containing the model
251-
* @param modelFileName the file name to use
252-
* @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes
253-
* @throws IllegalArgumentException if the model is null, does not exist, or is not a file
254-
*/
255-
public void addModel(File model, String modelFileName) throws WLSDeployArchiveIOException {
256-
final String METHOD = "addModel";
257-
258-
LOGGER.entering(CLASS, METHOD, model, modelFileName);
259-
validateExistingFile(model, "model", getArchiveFileName(), METHOD);
260-
getZipFile().removeZipEntries(ARCHIVE_MODEL_TARGET_DIR);
261-
addItemToZip(ARCHIVE_MODEL_TARGET_DIR, model, modelFileName);
262-
LOGGER.exiting(CLASS, METHOD);
263-
}
264-
265-
/**
266-
* Extracts the model, if any, from the existing archive.
267-
*
268-
* @param modelDirectory the directory where to place the extracted model
269-
* @return the model file or null, if no model exists
270-
* @throws WLSDeployArchiveIOException if an error occurs
271-
* @throws IllegalArgumentException if the modelDirectory is null, does not exist, or is not a directory
272-
*/
273-
public File extractModel(File modelDirectory) throws WLSDeployArchiveIOException {
274-
final String METHOD = "extractModel";
275-
276-
LOGGER.entering(CLASS, METHOD, modelDirectory);
277-
validateExistingDirectory(modelDirectory, "modelDirectory", getArchiveFileName(), METHOD);
278-
279-
extractDirectoryFromZip(ARCHIVE_MODEL_TARGET_DIR, modelDirectory);
280-
281-
File modelFile = null;
282-
File resultDirectory = new File(modelDirectory, ARCHIVE_MODEL_TARGET_DIR);
283-
if (resultDirectory.exists()) {
284-
try {
285-
modelFile = FileUtils.getModelFile(resultDirectory);
286-
} catch (IllegalArgumentException | IllegalStateException ex) {
287-
WLSDeployArchiveIOException wsdioe =
288-
new WLSDeployArchiveIOException("WLSDPLY-01400", ex, resultDirectory.getAbsolutePath(),
289-
ex.getLocalizedMessage());
290-
LOGGER.throwing(CLASS, METHOD, wsdioe);
291-
throw wsdioe;
292-
}
293-
}
294-
LOGGER.exiting(CLASS, METHOD, modelFile);
295-
return modelFile;
296-
}
297-
298-
/**
299-
* Determines whether the archive contains a model file.
300-
*
301-
* @return true if the archive contains a model file, false otherwise
302-
* @throws WLSDeployArchiveIOException if an error occurs while reading the archive
303-
*/
304-
public boolean containsModel() throws WLSDeployArchiveIOException {
305-
final String METHOD = "containsModel";
306-
307-
LOGGER.entering(CLASS, METHOD);
308-
List<String> modelDirContents = getZipFile().listZipEntries(ARCHIVE_MODEL_TARGET_DIR + ZIP_SEP);
309-
// Remove the top-level directory entry from the list, if it exists...
310-
modelDirContents.remove(ARCHIVE_MODEL_TARGET_DIR + ZIP_SEP);
311-
312-
boolean result;
313-
if (modelDirContents.isEmpty()) {
314-
result = false;
315-
} else {
316-
try {
317-
String modelEntryName = FileUtils.getModelFileName(modelDirContents, getZipFile().getFileName());
318-
result = !StringUtils.isEmpty(modelEntryName);
319-
} catch (IllegalArgumentException iae) {
320-
WLSDeployArchiveIOException wsdioe =
321-
new WLSDeployArchiveIOException("WLSDPLY-01401", iae, iae.getLocalizedMessage());
322-
LOGGER.throwing(CLASS, METHOD, wsdioe);
323-
throw wsdioe;
324-
}
325-
}
326-
LOGGER.exiting(CLASS, METHOD, result);
327-
return result;
328-
}
329-
330230
/**
331231
* Get the list of entries in the archive file.
332232
*
@@ -343,7 +243,7 @@ public List<String> getArchiveEntries() throws WLSDeployArchiveIOException {
343243
}
344244

345245
/**
346-
* Determines whether or not the archive contains the specified file or directory.
246+
* Determines whether the archive contains the specified file or directory.
347247
*
348248
* @param path the path into the archive file to test
349249
* @return true if the specified location was found int the archive, false otherwise
@@ -367,7 +267,7 @@ public boolean containsFile(String path) throws WLSDeployArchiveIOException {
367267
}
368268

369269
/**
370-
* Determines whether or not the provided path is a directory in the archive file.
270+
* Determines whether the provided path is a directory in the archive file.
371271
*
372272
* @param path the path into the archive file to test
373273
* @return true if the specified location was found in the archive file and is a directory
@@ -391,7 +291,7 @@ public boolean containsPath(String path) throws WLSDeployArchiveIOException {
391291
}
392292

393293
/**
394-
* Determines whether or not the provided path is a directory or a file in a directory
294+
* Determines whether the provided path is a directory or a file in a directory
395295
* in the archive file.
396296
*
397297
* @param path the path into the archive file to test
@@ -454,7 +354,7 @@ public String extractDirectory(String path, File extractToLocation) throws WLSDe
454354
*
455355
* @param path the path into the archive file to extract
456356
* @param extractToLocation the base directory to which to write the extracted file or directory
457-
* @param stripLeadingPathDirectories whether or not to strip the leading directories
357+
* @param stripLeadingPathDirectories whether to strip the leading directories
458358
* when writing to the target location
459359
* @return the canonical extracted file name
460360
* @throws WLSDeployArchiveIOException if an error occurs reading the archive or writing the file

core/src/main/python/create.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
The main module for the WLSDeploy tool to create empty domains.
@@ -55,6 +55,7 @@
5555
__version = WebLogicHelper(__logger).get_actual_weblogic_version()
5656

5757
__required_arguments = [
58+
CommandLineArgUtil.MODEL_FILE_SWITCH,
5859
CommandLineArgUtil.ORACLE_HOME_SWITCH
5960
]
6061

@@ -64,7 +65,6 @@
6465
CommandLineArgUtil.DOMAIN_PARENT_SWITCH,
6566
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
6667
CommandLineArgUtil.JAVA_HOME_SWITCH,
67-
CommandLineArgUtil.MODEL_FILE_SWITCH,
6868
CommandLineArgUtil.RUN_RCU_SWITCH,
6969
CommandLineArgUtil.RCU_SYS_PASS_SWITCH,
7070
CommandLineArgUtil.RCU_DB_SWITCH,
@@ -98,7 +98,7 @@ def __process_args(args):
9898

9999
# don't verify that the archive is valid until it is needed.
100100
# this requirement is specific to create, other tools will verify it.
101-
cla_helper.validate_model_present(_program_name, argument_map)
101+
cla_helper.validate_required_model(_program_name, argument_map)
102102
cla_helper.validate_variable_file_exists(_program_name, argument_map)
103103

104104
#

core/src/main/python/deploy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
The entry point for the deployApps tool.
@@ -42,14 +42,14 @@
4242

4343
__required_arguments = [
4444
CommandLineArgUtil.ORACLE_HOME_SWITCH,
45-
CommandLineArgUtil.DOMAIN_HOME_SWITCH
45+
CommandLineArgUtil.DOMAIN_HOME_SWITCH,
46+
CommandLineArgUtil.MODEL_FILE_SWITCH
4647
]
4748

4849
__optional_arguments = [
4950
# Used by shell script to locate WLST
5051
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
5152
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
52-
CommandLineArgUtil.MODEL_FILE_SWITCH,
5353
CommandLineArgUtil.PREVIOUS_MODEL_FILE_SWITCH,
5454
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
5555
CommandLineArgUtil.ADMIN_URL_SWITCH,
@@ -80,7 +80,7 @@ def __process_args(args):
8080
argument_map = cla_util.process_args(args)
8181

8282
cla_helper.validate_optional_archive(_program_name, argument_map)
83-
cla_helper.validate_model_present(_program_name, argument_map)
83+
cla_helper.validate_required_model(_program_name, argument_map)
8484
cla_helper.validate_variable_file_exists(_program_name, argument_map)
8585

8686
__wlst_mode = cla_helper.process_online_args(argument_map)

core/src/main/python/discover.py

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
The entry point for the discoverDomain tool.
@@ -68,12 +68,12 @@
6868

6969
__required_arguments = [
7070
CommandLineArgUtil.ORACLE_HOME_SWITCH,
71-
CommandLineArgUtil.DOMAIN_HOME_SWITCH
71+
CommandLineArgUtil.DOMAIN_HOME_SWITCH,
72+
CommandLineArgUtil.MODEL_FILE_SWITCH
7273
]
7374

7475
__optional_arguments = [
7576
# Used by shell script to locate WLST
76-
CommandLineArgUtil.MODEL_FILE_SWITCH,
7777
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
7878
CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH,
7979
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
@@ -104,7 +104,7 @@ def __process_args(args):
104104

105105
__wlst_mode = cla_helper.process_online_args(argument_map)
106106
target_configuration_helper.process_target_arguments(argument_map)
107-
__process_model_archive_args(argument_map)
107+
__process_model_arg(argument_map)
108108
__process_archive_filename_arg(argument_map)
109109
__process_variable_filename_arg(argument_map)
110110
__process_java_home(argument_map)
@@ -113,22 +113,20 @@ def __process_args(args):
113113
return model_context_helper.create_context(_program_name, argument_map)
114114

115115

116-
def __process_model_archive_args(argument_map):
116+
def __process_model_arg(argument_map):
117117
"""
118-
Verify that model file and/or archive file is in the argument map
118+
Verify that specified model file's parent directory exists.
119119
:param argument_map: containing the CLA arguments
120120
"""
121-
_method_name = '__process_model_archive_args'
122-
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH not in argument_map:
123-
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH not in argument_map and \
124-
CommandLineArgUtil.REMOTE_SWITCH not in argument_map:
125-
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR, 'WLSDPLY-06028')
126-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
127-
raise ex
128-
if CommandLineArgUtil.MODEL_FILE_SWITCH not in argument_map:
129-
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR, 'WLSDPLY-06029')
130-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
131-
raise ex
121+
_method_name = '__process_model_arg'
122+
123+
model_file_name = argument_map[CommandLineArgUtil.MODEL_FILE_SWITCH]
124+
model_dir_name = path_utils.get_parent_directory(model_file_name)
125+
if os.path.exists(model_dir_name) is False:
126+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
127+
'WLSDPLY-06037', model_file_name)
128+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
129+
raise ex
132130

133131

134132
def __process_archive_filename_arg(argument_map):
@@ -139,12 +137,19 @@ def __process_archive_filename_arg(argument_map):
139137
"""
140138
_method_name = '__process_archive_filename_arg'
141139

142-
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map or CommandLineArgUtil.REMOTE_SWITCH in argument_map:
143-
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in argument_map:
144-
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
145-
'WLSDPLY-06033')
140+
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH not in argument_map:
141+
archive_file = None
142+
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH not in argument_map and \
143+
CommandLineArgUtil.REMOTE_SWITCH not in argument_map:
144+
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR, 'WLSDPLY-06028')
146145
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
147146
raise ex
147+
elif CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map or\
148+
CommandLineArgUtil.REMOTE_SWITCH in argument_map:
149+
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
150+
'WLSDPLY-06033')
151+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
152+
raise ex
148153
else:
149154
archive_file_name = argument_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
150155
archive_dir_name = path_utils.get_parent_directory(archive_file_name)
@@ -412,7 +417,7 @@ def __disconnect_domain(helper):
412417

413418
def __persist_model(model, model_context):
414419
"""
415-
Save the model to the specified model file name or to the archive if the file name was not specified.
420+
Save the model to the specified model file name.
416421
:param model: the model to save
417422
:param model_context: the model context
418423
:raises DiscoverException: if an error occurs while create a temporary file for the model
@@ -423,47 +428,9 @@ def __persist_model(model, model_context):
423428

424429
__logger.entering(class_name=_class_name, method_name=_method_name)
425430

426-
add_to_archive = False
427431
model_file_name = model_context.get_model_file()
428-
if model_file_name is None:
429-
if model_context.skip_archive() or model_context.is_remote():
430-
ex = exception_helper.create_discover_exception('WLSDPLY-06032')
431-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
432-
raise ex
433-
add_to_archive = True
434-
try:
435-
domain_name = model_context.get_domain_name()
436-
model_file = File.createTempFile(domain_name, '.yaml').getCanonicalFile()
437-
model_file_name = model_context.get_domain_name() + '.yaml'
438-
except (IllegalArgumentException, IOException), ie:
439-
ex = exception_helper.create_discover_exception('WLSDPLY-06008', ie.getLocalizedMessage(), error=ie)
440-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
441-
raise ex
442-
else:
443-
model_file = FileUtils.getCanonicalFile(File(model_file_name))
444-
445-
try:
446-
model_translator.PythonToFile(model.get_model()).write_to_file(model_file.getAbsolutePath())
447-
except TranslateException, ex:
448-
# Jython 2.2.1 does not support finally so use this like a finally block...
449-
if add_to_archive and not model_file.delete():
450-
model_file.deleteOnExit()
451-
raise ex
452-
453-
if add_to_archive:
454-
try:
455-
archive_file = model_context.get_archive_file()
456-
archive_file.addModel(model_file, model_file_name)
457-
if not model_file.delete():
458-
model_file.deleteOnExit()
459-
except (WLSDeployArchiveIOException, IllegalArgumentException), arch_ex:
460-
ex = exception_helper.create_discover_exception('WLSDPLY-20023', model_file.getAbsolutePath(),
461-
model_file_name, arch_ex.getLocalizedMessage(),
462-
error=arch_ex)
463-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
464-
if not model_file.delete():
465-
model_file.deleteOnExit()
466-
raise ex
432+
model_file = FileUtils.getCanonicalFile(File(model_file_name))
433+
model_translator.PythonToFile(model.get_model()).write_to_file(model_file.getAbsolutePath())
467434

468435
__logger.exiting(class_name=_class_name, method_name=_method_name)
469436

0 commit comments

Comments
 (0)