diff --git a/core/src/main/python/create.py b/core/src/main/python/create.py index efa927aaf7..9c19f1f777 100644 --- a/core/src/main/python/create.py +++ b/core/src/main/python/create.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2017, 2020, 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. @@ -423,6 +423,8 @@ def main(args): cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) + cla_helper.persist_model(model_context, model) + aliases = Aliases(model_context, wlst_mode=__wlst_mode) alias_helper = AliasHelper(aliases, __logger, ExceptionType.CREATE) validate_model(model, model_context, aliases) diff --git a/core/src/main/python/deploy.py b/core/src/main/python/deploy.py index 3892f5661b..2e97906301 100644 --- a/core/src/main/python/deploy.py +++ b/core/src/main/python/deploy.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2017, 2020, 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. @@ -412,6 +412,8 @@ def main(args): cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) + cla_helper.persist_model(model_context, model_dictionary) + aliases = Aliases(model_context, wlst_mode=__wlst_mode) validate_model(model_dictionary, model_context, aliases) diff --git a/core/src/main/python/update.py b/core/src/main/python/update.py index 863699e8f9..8745b4afeb 100644 --- a/core/src/main/python/update.py +++ b/core/src/main/python/update.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2017, 2020, 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 updateDomain tool. @@ -198,9 +198,6 @@ def __update(model, model_context, aliases): else: ret_code = __update_offline(model, model_context, aliases) - if os.environ.has_key('__WLSDEPLOY_STORE_MODEL__'): - model_helper.persist_model(model_context, model) - return ret_code def __update_online(model, model_context, aliases): @@ -423,6 +420,8 @@ def main(args): cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) + cla_helper.persist_model(model_context, model_dictionary) + aliases = Aliases(model_context, wlst_mode=__wlst_mode) validate_model(model_dictionary, model_context, aliases) diff --git a/core/src/main/python/validate.py b/core/src/main/python/validate.py index 59cb0706bf..cfc2f6d43d 100644 --- a/core/src/main/python/validate.py +++ b/core/src/main/python/validate.py @@ -1,9 +1,10 @@ """ -Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2017, 2020, 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 WLS Deploy tooling entry point for the validateModel tool. """ +import copy import os import sys from java.util.logging import Level @@ -25,6 +26,7 @@ from wlsdeploy.tool.validate.validator import Validator from wlsdeploy.util import cla_helper from wlsdeploy.util import tool_exit +from wlsdeploy.util import variables from wlsdeploy.util.cla_utils import CommandLineArgUtil from wlsdeploy.util.weblogic_helper import WebLogicHelper @@ -176,6 +178,12 @@ def __perform_model_file_validation(model_file_name, model_context): model_validator = Validator(model_context, logger=__logger) variable_map = model_validator.load_variables(model_context.get_variable_file()) model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map) + + if cla_helper.check_persist_model(): + persist_model_dict = copy.deepcopy(model_dictionary) + variables.substitute(persist_model_dict, variable_map, model_context) + cla_helper.persist_model(model_context, persist_model_dict) + model_validator.validate_in_standalone_mode(model_dictionary, variable_map, model_context.get_archive_file_name()) except TranslateException, te: diff --git a/core/src/main/python/wlsdeploy/tool/create/domain_creator.py b/core/src/main/python/wlsdeploy/tool/create/domain_creator.py index 9721888093..fc59626cd6 100644 --- a/core/src/main/python/wlsdeploy/tool/create/domain_creator.py +++ b/core/src/main/python/wlsdeploy/tool/create/domain_creator.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ import os @@ -347,8 +347,6 @@ def __create_domain(self): self.library_helper.extract_classpath_libraries() self.library_helper.install_domain_scripts() self.wlsroles_helper.process_roles() - if os.environ.has_key('__WLSDEPLOY_STORE_MODEL__'): - model_helper.persist_model(self.model_context, self.model) self.logger.exiting(class_name=self.__class_name, method_name=_method_name) return diff --git a/core/src/main/python/wlsdeploy/util/cla_helper.py b/core/src/main/python/wlsdeploy/util/cla_helper.py index ec6daa0633..f616d4d6f4 100644 --- a/core/src/main/python/wlsdeploy/util/cla_helper.py +++ b/core/src/main/python/wlsdeploy/util/cla_helper.py @@ -1,34 +1,40 @@ """ -Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. Utility CLS methods shared by multiple tools. """ +import os + +from java.io import File from java.io import IOException from java.lang import IllegalArgumentException from java.lang import String from oracle.weblogic.deploy.util import FileUtils -from oracle.weblogic.deploy.util import VariableException from oracle.weblogic.deploy.util import TranslateException +from oracle.weblogic.deploy.util import VariableException from oracle.weblogic.deploy.validate import ValidateException + +import oracle.weblogic.deploy.util.PyOrderedDict as OrderedDict from wlsdeploy.exception import exception_helper from wlsdeploy.logging.platform_logger import PlatformLogger from wlsdeploy.tool.util import filter_helper from wlsdeploy.tool.util.archive_helper import ArchiveHelper from wlsdeploy.tool.validate.validator import Validator from wlsdeploy.util import cla_utils +from wlsdeploy.util import getcreds from wlsdeploy.util import model_helper +from wlsdeploy.util import model_translator, path_utils from wlsdeploy.util import tool_exit -from wlsdeploy.util import getcreds from wlsdeploy.util import variables from wlsdeploy.util.cla_utils import CommandLineArgUtil from wlsdeploy.util.model_translator import FileToPython -import oracle.weblogic.deploy.util.PyOrderedDict as OrderedDict - __logger = PlatformLogger('wlsdeploy.util') _class_name = 'cla_helper' +_store_environment_variable = '__WLSDEPLOY_STORE_MODEL__' + __tmp_model_dir = None @@ -240,6 +246,8 @@ def load_model(program_name, model_context, aliases, filter_type, wlst_mode): clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) + persist_model(model_context, model_dictionary) + validate_model(program_name, model_dictionary, model_context, aliases, wlst_mode) if filter_helper.apply_filters(model_dictionary, filter_type): @@ -352,3 +360,41 @@ def _get_merge_match_key(key, variable_map): if model_helper.is_delete_name(match_key): match_key = model_helper.get_delete_item_name(match_key) return match_key + + +def persist_model(model_context, model_dictionary): + """ + If environment variable __WLSDEPLOY_STORE_MODEL__ is set, save the specified model. + If the variable's value starts with a slash, save to that file, otherwise use a default location. + :param model_context: the model context + :param model_dictionary: the model to be saved + """ + _method_name = 'persist_model' + + if check_persist_model(): + store_value = os.environ.get(_store_environment_variable) + + if store_value.startswith('/') or store_value.startswith('\\'): + file_path = store_value + elif model_context.get_domain_home() is not None: + file_path = model_context.get_domain_home() + os.sep + 'wlsdeploy' + os.sep + 'domain_model.json' + else: + file_dir = FileUtils.createTempDirectory('wlsdeploy') + file_path = File(file_dir, 'domain_model.json').getAbsolutePath() + + __logger.info('WLSDPLY-01650', file_path, class_name=_class_name, method_name=_method_name) + + persist_dir = path_utils.get_parent_directory(file_path) + if not os.path.exists(persist_dir): + os.makedirs(persist_dir) + + model_file = FileUtils.getCanonicalFile(File(file_path)) + model_translator.PythonToFile(model_dictionary).write_to_file(model_file.getAbsolutePath()) + + +def check_persist_model(): + """ + Determine if the model should be persisted, based on the environment variable __WLSDEPLOY_STORE_MODEL__ + :return: True if the model should be persisted + """ + return os.environ.has_key(_store_environment_variable) diff --git a/core/src/main/python/wlsdeploy/util/model.py b/core/src/main/python/wlsdeploy/util/model.py index 9e7cd9dcc1..b4fa21081f 100644 --- a/core/src/main/python/wlsdeploy/util/model.py +++ b/core/src/main/python/wlsdeploy/util/model.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. This module serves as a wrapper for the model dictionary. @@ -165,12 +165,3 @@ def get_model_top_level_keys(): :return: a list of the known top-level model element keys """ return list(KNOWN_TOPLEVEL_MODEL_SECTIONS) - - -def persist_model(model_context, model): - base_dir = model_context.get_domain_home() + os.sep + 'wlsdeploy' - if not os.path.exists(base_dir): - os.makedirs(base_dir) - fh = open(base_dir + os.sep + 'domain_model.json', 'w') - fh.write(str(model.get_model())) - fh.close() diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index 217fe17959..85f139110d 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -1,4 +1,4 @@ -# Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. +# Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. # The Universal Permissive License (UPL), Version 1.0 # # @@ -268,6 +268,9 @@ WLSDPLY-01635=Specified Model Variable Injector File {0} is not a valid file : { WLSDPLY-01636=Specified Model Variable Keywords File {0} is not a valid file : {1} WLSDPLY-01637=Specified domain resource file {0} is not a valid file: {1} +# wlsdeploy/util/cla_helper.py +WLSDPLY-01650=Saving the model to file {0} + # wlsdeploy/util/enum.py WLSDPLY-01700=The value {0} is not a valid value of the Enum type {1}