Skip to content

Commit a7bdd9a

Browse files
authored
JIRA-WDT-392 Store merged, resolved model at the location specified in environment variable (#545)
1 parent 0dfcd5a commit a7bdd9a

File tree

8 files changed

+75
-26
lines changed

8 files changed

+75
-26
lines changed

core/src/main/python/create.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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.
@@ -423,6 +423,8 @@ def main(args):
423423
cla_helper.clean_up_temp_files()
424424
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
425425

426+
cla_helper.persist_model(model_context, model)
427+
426428
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
427429
alias_helper = AliasHelper(aliases, __logger, ExceptionType.CREATE)
428430
validate_model(model, model_context, aliases)

core/src/main/python/deploy.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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.
@@ -412,6 +412,8 @@ def main(args):
412412
cla_helper.clean_up_temp_files()
413413
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
414414

415+
cla_helper.persist_model(model_context, model_dictionary)
416+
415417
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
416418
validate_model(model_dictionary, model_context, aliases)
417419

core/src/main/python/update.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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 updateDomain tool.
@@ -198,9 +198,6 @@ def __update(model, model_context, aliases):
198198
else:
199199
ret_code = __update_offline(model, model_context, aliases)
200200

201-
if os.environ.has_key('__WLSDEPLOY_STORE_MODEL__'):
202-
model_helper.persist_model(model_context, model)
203-
204201
return ret_code
205202

206203
def __update_online(model, model_context, aliases):
@@ -423,6 +420,8 @@ def main(args):
423420
cla_helper.clean_up_temp_files()
424421
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
425422

423+
cla_helper.persist_model(model_context, model_dictionary)
424+
426425
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
427426
validate_model(model_dictionary, model_context, aliases)
428427

core/src/main/python/validate.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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 WLS Deploy tooling entry point for the validateModel tool.
66
"""
7+
import copy
78
import os
89
import sys
910
from java.util.logging import Level
@@ -25,6 +26,7 @@
2526
from wlsdeploy.tool.validate.validator import Validator
2627
from wlsdeploy.util import cla_helper
2728
from wlsdeploy.util import tool_exit
29+
from wlsdeploy.util import variables
2830
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2931
from wlsdeploy.util.weblogic_helper import WebLogicHelper
3032

@@ -176,6 +178,12 @@ def __perform_model_file_validation(model_file_name, model_context):
176178
model_validator = Validator(model_context, logger=__logger)
177179
variable_map = model_validator.load_variables(model_context.get_variable_file())
178180
model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map)
181+
182+
if cla_helper.check_persist_model():
183+
persist_model_dict = copy.deepcopy(model_dictionary)
184+
variables.substitute(persist_model_dict, variable_map, model_context)
185+
cla_helper.persist_model(model_context, persist_model_dict)
186+
179187
model_validator.validate_in_standalone_mode(model_dictionary, variable_map,
180188
model_context.get_archive_file_name())
181189
except TranslateException, te:

core/src/main/python/wlsdeploy/tool/create/domain_creator.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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
import os
@@ -347,8 +347,6 @@ def __create_domain(self):
347347
self.library_helper.extract_classpath_libraries()
348348
self.library_helper.install_domain_scripts()
349349
self.wlsroles_helper.process_roles()
350-
if os.environ.has_key('__WLSDEPLOY_STORE_MODEL__'):
351-
model_helper.persist_model(self.model_context, self.model)
352350

353351
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
354352
return

core/src/main/python/wlsdeploy/util/cla_helper.py

+51-5
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
"""
2-
Copyright (c) 2019, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2019, 2020, 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
Utility CLS methods shared by multiple tools.
66
"""
7+
import os
8+
9+
from java.io import File
710
from java.io import IOException
811
from java.lang import IllegalArgumentException
912
from java.lang import String
1013
from oracle.weblogic.deploy.util import FileUtils
11-
from oracle.weblogic.deploy.util import VariableException
1214
from oracle.weblogic.deploy.util import TranslateException
15+
from oracle.weblogic.deploy.util import VariableException
1316
from oracle.weblogic.deploy.validate import ValidateException
17+
18+
import oracle.weblogic.deploy.util.PyOrderedDict as OrderedDict
1419
from wlsdeploy.exception import exception_helper
1520
from wlsdeploy.logging.platform_logger import PlatformLogger
1621
from wlsdeploy.tool.util import filter_helper
1722
from wlsdeploy.tool.util.archive_helper import ArchiveHelper
1823
from wlsdeploy.tool.validate.validator import Validator
1924
from wlsdeploy.util import cla_utils
25+
from wlsdeploy.util import getcreds
2026
from wlsdeploy.util import model_helper
27+
from wlsdeploy.util import model_translator, path_utils
2128
from wlsdeploy.util import tool_exit
22-
from wlsdeploy.util import getcreds
2329
from wlsdeploy.util import variables
2430
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2531
from wlsdeploy.util.model_translator import FileToPython
2632

27-
import oracle.weblogic.deploy.util.PyOrderedDict as OrderedDict
28-
2933
__logger = PlatformLogger('wlsdeploy.util')
3034
_class_name = 'cla_helper'
3135

36+
_store_environment_variable = '__WLSDEPLOY_STORE_MODEL__'
37+
3238
__tmp_model_dir = None
3339

3440

@@ -240,6 +246,8 @@ def load_model(program_name, model_context, aliases, filter_type, wlst_mode):
240246
clean_up_temp_files()
241247
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
242248

249+
persist_model(model_context, model_dictionary)
250+
243251
validate_model(program_name, model_dictionary, model_context, aliases, wlst_mode)
244252

245253
if filter_helper.apply_filters(model_dictionary, filter_type):
@@ -352,3 +360,41 @@ def _get_merge_match_key(key, variable_map):
352360
if model_helper.is_delete_name(match_key):
353361
match_key = model_helper.get_delete_item_name(match_key)
354362
return match_key
363+
364+
365+
def persist_model(model_context, model_dictionary):
366+
"""
367+
If environment variable __WLSDEPLOY_STORE_MODEL__ is set, save the specified model.
368+
If the variable's value starts with a slash, save to that file, otherwise use a default location.
369+
:param model_context: the model context
370+
:param model_dictionary: the model to be saved
371+
"""
372+
_method_name = 'persist_model'
373+
374+
if check_persist_model():
375+
store_value = os.environ.get(_store_environment_variable)
376+
377+
if store_value.startswith('/') or store_value.startswith('\\'):
378+
file_path = store_value
379+
elif model_context.get_domain_home() is not None:
380+
file_path = model_context.get_domain_home() + os.sep + 'wlsdeploy' + os.sep + 'domain_model.json'
381+
else:
382+
file_dir = FileUtils.createTempDirectory('wlsdeploy')
383+
file_path = File(file_dir, 'domain_model.json').getAbsolutePath()
384+
385+
__logger.info('WLSDPLY-01650', file_path, class_name=_class_name, method_name=_method_name)
386+
387+
persist_dir = path_utils.get_parent_directory(file_path)
388+
if not os.path.exists(persist_dir):
389+
os.makedirs(persist_dir)
390+
391+
model_file = FileUtils.getCanonicalFile(File(file_path))
392+
model_translator.PythonToFile(model_dictionary).write_to_file(model_file.getAbsolutePath())
393+
394+
395+
def check_persist_model():
396+
"""
397+
Determine if the model should be persisted, based on the environment variable __WLSDEPLOY_STORE_MODEL__
398+
:return: True if the model should be persisted
399+
"""
400+
return os.environ.has_key(_store_environment_variable)

core/src/main/python/wlsdeploy/util/model.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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
This module serves as a wrapper for the model dictionary.
@@ -165,12 +165,3 @@ def get_model_top_level_keys():
165165
:return: a list of the known top-level model element keys
166166
"""
167167
return list(KNOWN_TOPLEVEL_MODEL_SECTIONS)
168-
169-
170-
def persist_model(model_context, model):
171-
base_dir = model_context.get_domain_home() + os.sep + 'wlsdeploy'
172-
if not os.path.exists(base_dir):
173-
os.makedirs(base_dir)
174-
fh = open(base_dir + os.sep + 'domain_model.json', 'w')
175-
fh.write(str(model.get_model()))
176-
fh.close()

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
22
# The Universal Permissive License (UPL), Version 1.0
33
#
44
#
@@ -268,6 +268,9 @@ WLSDPLY-01635=Specified Model Variable Injector File {0} is not a valid file : {
268268
WLSDPLY-01636=Specified Model Variable Keywords File {0} is not a valid file : {1}
269269
WLSDPLY-01637=Specified domain resource file {0} is not a valid file: {1}
270270

271+
# wlsdeploy/util/cla_helper.py
272+
WLSDPLY-01650=Saving the model to file {0}
273+
271274
# wlsdeploy/util/enum.py
272275
WLSDPLY-01700=The value {0} is not a valid value of the Enum type {1}
273276

0 commit comments

Comments
 (0)