Skip to content

Store merged, resolved model at the location specified in environment variable #545

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 1 commit into from
Feb 18, 2020
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
4 changes: 3 additions & 1 deletion core/src/main/python/create.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/python/deploy.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions core/src/main/python/update.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 9 additions & 1 deletion core/src/main/python/validate.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/python/wlsdeploy/tool/create/domain_creator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
56 changes: 51 additions & 5 deletions core/src/main/python/wlsdeploy/util/cla_helper.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
11 changes: 1 addition & 10 deletions core/src/main/python/wlsdeploy/util/model.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
@@ -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
#
#
Expand Down Expand Up @@ -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}

Expand Down