Skip to content

removing option to store model in archive file #1334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 6 additions & 106 deletions core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
* Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
package oracle.weblogic.deploy.util;
Expand Down Expand Up @@ -188,7 +188,7 @@ public WLSDeployArchive(String archiveFileName) {
}

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

/**
* Adds the model file into the archive.
*
* @param model the model file to add
* @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes
* @throws IllegalArgumentException if the model is null, does not exist, or is not a file
*/
public void addModel(File model) throws WLSDeployArchiveIOException {
final String METHOD = "addModel";

LOGGER.entering(CLASS, METHOD, model);
validateExistingFile(model, "model", getArchiveFileName(), METHOD);
getZipFile().removeZipEntries(ARCHIVE_MODEL_TARGET_DIR);
addItemToZip(ARCHIVE_MODEL_TARGET_DIR, model);
LOGGER.exiting(CLASS, METHOD);
}

/**
* Adds the model file into the archive using the specified model file name.
*
* @param model the file containing the model
* @param modelFileName the file name to use
* @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes
* @throws IllegalArgumentException if the model is null, does not exist, or is not a file
*/
public void addModel(File model, String modelFileName) throws WLSDeployArchiveIOException {
final String METHOD = "addModel";

LOGGER.entering(CLASS, METHOD, model, modelFileName);
validateExistingFile(model, "model", getArchiveFileName(), METHOD);
getZipFile().removeZipEntries(ARCHIVE_MODEL_TARGET_DIR);
addItemToZip(ARCHIVE_MODEL_TARGET_DIR, model, modelFileName);
LOGGER.exiting(CLASS, METHOD);
}

/**
* Extracts the model, if any, from the existing archive.
*
* @param modelDirectory the directory where to place the extracted model
* @return the model file or null, if no model exists
* @throws WLSDeployArchiveIOException if an error occurs
* @throws IllegalArgumentException if the modelDirectory is null, does not exist, or is not a directory
*/
public File extractModel(File modelDirectory) throws WLSDeployArchiveIOException {
final String METHOD = "extractModel";

LOGGER.entering(CLASS, METHOD, modelDirectory);
validateExistingDirectory(modelDirectory, "modelDirectory", getArchiveFileName(), METHOD);

extractDirectoryFromZip(ARCHIVE_MODEL_TARGET_DIR, modelDirectory);

File modelFile = null;
File resultDirectory = new File(modelDirectory, ARCHIVE_MODEL_TARGET_DIR);
if (resultDirectory.exists()) {
try {
modelFile = FileUtils.getModelFile(resultDirectory);
} catch (IllegalArgumentException | IllegalStateException ex) {
WLSDeployArchiveIOException wsdioe =
new WLSDeployArchiveIOException("WLSDPLY-01400", ex, resultDirectory.getAbsolutePath(),
ex.getLocalizedMessage());
LOGGER.throwing(CLASS, METHOD, wsdioe);
throw wsdioe;
}
}
LOGGER.exiting(CLASS, METHOD, modelFile);
return modelFile;
}

/**
* Determines whether the archive contains a model file.
*
* @return true if the archive contains a model file, false otherwise
* @throws WLSDeployArchiveIOException if an error occurs while reading the archive
*/
public boolean containsModel() throws WLSDeployArchiveIOException {
final String METHOD = "containsModel";

LOGGER.entering(CLASS, METHOD);
List<String> modelDirContents = getZipFile().listZipEntries(ARCHIVE_MODEL_TARGET_DIR + ZIP_SEP);
// Remove the top-level directory entry from the list, if it exists...
modelDirContents.remove(ARCHIVE_MODEL_TARGET_DIR + ZIP_SEP);

boolean result;
if (modelDirContents.isEmpty()) {
result = false;
} else {
try {
String modelEntryName = FileUtils.getModelFileName(modelDirContents, getZipFile().getFileName());
result = !StringUtils.isEmpty(modelEntryName);
} catch (IllegalArgumentException iae) {
WLSDeployArchiveIOException wsdioe =
new WLSDeployArchiveIOException("WLSDPLY-01401", iae, iae.getLocalizedMessage());
LOGGER.throwing(CLASS, METHOD, wsdioe);
throw wsdioe;
}
}
LOGGER.exiting(CLASS, METHOD, result);
return result;
}

/**
* Get the list of entries in the archive file.
*
Expand All @@ -343,7 +243,7 @@ public List<String> getArchiveEntries() throws WLSDeployArchiveIOException {
}

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

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

/**
* Determines whether or not the provided path is a directory or a file in a directory
* Determines whether the provided path is a directory or a file in a directory
* in the archive file.
*
* @param path the path into the archive file to test
Expand Down Expand Up @@ -454,7 +354,7 @@ public String extractDirectory(String path, File extractToLocation) throws WLSDe
*
* @param path the path into the archive file to extract
* @param extractToLocation the base directory to which to write the extracted file or directory
* @param stripLeadingPathDirectories whether or not to strip the leading directories
* @param stripLeadingPathDirectories whether to strip the leading directories
* when writing to the target location
* @return the canonical extracted file name
* @throws WLSDeployArchiveIOException if an error occurs reading the archive or writing the file
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/python/create.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

The main module for the WLSDeploy tool to create empty domains.
Expand Down Expand Up @@ -55,6 +55,7 @@
__version = WebLogicHelper(__logger).get_actual_weblogic_version()

__required_arguments = [
CommandLineArgUtil.MODEL_FILE_SWITCH,
CommandLineArgUtil.ORACLE_HOME_SWITCH
]

Expand All @@ -64,7 +65,6 @@
CommandLineArgUtil.DOMAIN_PARENT_SWITCH,
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
CommandLineArgUtil.JAVA_HOME_SWITCH,
CommandLineArgUtil.MODEL_FILE_SWITCH,
CommandLineArgUtil.RUN_RCU_SWITCH,
CommandLineArgUtil.RCU_SYS_PASS_SWITCH,
CommandLineArgUtil.RCU_DB_SWITCH,
Expand Down Expand Up @@ -98,7 +98,7 @@ def __process_args(args):

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

#
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/python/deploy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

The entry point for the deployApps tool.
Expand Down Expand Up @@ -42,14 +42,14 @@

__required_arguments = [
CommandLineArgUtil.ORACLE_HOME_SWITCH,
CommandLineArgUtil.DOMAIN_HOME_SWITCH
CommandLineArgUtil.DOMAIN_HOME_SWITCH,
CommandLineArgUtil.MODEL_FILE_SWITCH
]

__optional_arguments = [
# Used by shell script to locate WLST
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
CommandLineArgUtil.MODEL_FILE_SWITCH,
CommandLineArgUtil.PREVIOUS_MODEL_FILE_SWITCH,
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
CommandLineArgUtil.ADMIN_URL_SWITCH,
Expand Down Expand Up @@ -80,7 +80,7 @@ def __process_args(args):
argument_map = cla_util.process_args(args)

cla_helper.validate_optional_archive(_program_name, argument_map)
cla_helper.validate_model_present(_program_name, argument_map)
cla_helper.validate_required_model(_program_name, argument_map)
cla_helper.validate_variable_file_exists(_program_name, argument_map)

__wlst_mode = cla_helper.process_online_args(argument_map)
Expand Down
91 changes: 29 additions & 62 deletions core/src/main/python/discover.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

The entry point for the discoverDomain tool.
Expand Down Expand Up @@ -68,12 +68,12 @@

__required_arguments = [
CommandLineArgUtil.ORACLE_HOME_SWITCH,
CommandLineArgUtil.DOMAIN_HOME_SWITCH
CommandLineArgUtil.DOMAIN_HOME_SWITCH,
CommandLineArgUtil.MODEL_FILE_SWITCH
]

__optional_arguments = [
# Used by shell script to locate WLST
CommandLineArgUtil.MODEL_FILE_SWITCH,
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH,
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
Expand Down Expand Up @@ -104,7 +104,7 @@ def __process_args(args):

__wlst_mode = cla_helper.process_online_args(argument_map)
target_configuration_helper.process_target_arguments(argument_map)
__process_model_archive_args(argument_map)
__process_model_arg(argument_map)
__process_archive_filename_arg(argument_map)
__process_variable_filename_arg(argument_map)
__process_java_home(argument_map)
Expand All @@ -113,22 +113,20 @@ def __process_args(args):
return model_context_helper.create_context(_program_name, argument_map)


def __process_model_archive_args(argument_map):
def __process_model_arg(argument_map):
"""
Verify that model file and/or archive file is in the argument map
Verify that specified model file's parent directory exists.
:param argument_map: containing the CLA arguments
"""
_method_name = '__process_model_archive_args'
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH not in argument_map:
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH not in argument_map and \
CommandLineArgUtil.REMOTE_SWITCH not in argument_map:
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR, 'WLSDPLY-06028')
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
if CommandLineArgUtil.MODEL_FILE_SWITCH not in argument_map:
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR, 'WLSDPLY-06029')
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
_method_name = '__process_model_arg'

model_file_name = argument_map[CommandLineArgUtil.MODEL_FILE_SWITCH]
model_dir_name = path_utils.get_parent_directory(model_file_name)
if os.path.exists(model_dir_name) is False:
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
'WLSDPLY-06037', model_file_name)
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex


def __process_archive_filename_arg(argument_map):
Expand All @@ -139,12 +137,19 @@ def __process_archive_filename_arg(argument_map):
"""
_method_name = '__process_archive_filename_arg'

if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map or CommandLineArgUtil.REMOTE_SWITCH in argument_map:
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in argument_map:
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
'WLSDPLY-06033')
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH not in argument_map:
archive_file = None
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH not in argument_map and \
CommandLineArgUtil.REMOTE_SWITCH not in argument_map:
ex = exception_helper.create_cla_exception(ExitCode.USAGE_ERROR, 'WLSDPLY-06028')
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
elif CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map or\
CommandLineArgUtil.REMOTE_SWITCH in argument_map:
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
'WLSDPLY-06033')
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
else:
archive_file_name = argument_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
archive_dir_name = path_utils.get_parent_directory(archive_file_name)
Expand Down Expand Up @@ -412,7 +417,7 @@ def __disconnect_domain(helper):

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

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

add_to_archive = False
model_file_name = model_context.get_model_file()
if model_file_name is None:
if model_context.skip_archive() or model_context.is_remote():
ex = exception_helper.create_discover_exception('WLSDPLY-06032')
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
add_to_archive = True
try:
domain_name = model_context.get_domain_name()
model_file = File.createTempFile(domain_name, '.yaml').getCanonicalFile()
model_file_name = model_context.get_domain_name() + '.yaml'
except (IllegalArgumentException, IOException), ie:
ex = exception_helper.create_discover_exception('WLSDPLY-06008', ie.getLocalizedMessage(), error=ie)
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
else:
model_file = FileUtils.getCanonicalFile(File(model_file_name))

try:
model_translator.PythonToFile(model.get_model()).write_to_file(model_file.getAbsolutePath())
except TranslateException, ex:
# Jython 2.2.1 does not support finally so use this like a finally block...
if add_to_archive and not model_file.delete():
model_file.deleteOnExit()
raise ex

if add_to_archive:
try:
archive_file = model_context.get_archive_file()
archive_file.addModel(model_file, model_file_name)
if not model_file.delete():
model_file.deleteOnExit()
except (WLSDeployArchiveIOException, IllegalArgumentException), arch_ex:
ex = exception_helper.create_discover_exception('WLSDPLY-20023', model_file.getAbsolutePath(),
model_file_name, arch_ex.getLocalizedMessage(),
error=arch_ex)
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
if not model_file.delete():
model_file.deleteOnExit()
raise ex
model_file = FileUtils.getCanonicalFile(File(model_file_name))
model_translator.PythonToFile(model.get_model()).write_to_file(model_file.getAbsolutePath())

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

Expand Down
Loading