Skip to content

Commit 8e7b6cc

Browse files
authored
Convert extractDomainResource and injectVariables to use Jython directly (#554)
* JIRA-WDT-387 Remove WLST silence command * JIRA-WDT-387 Remove WLST silence command, use some CLA helper methods * JIRA-WDT-387 Corrected comment * JIRA-WDT-387 Add check for -use_uncryption flag, clarify comments * JIRA-WDT-387 Use shared functions * JIRA-WDT-387 Use Jython shared functions, check for min JDK version * JIRA-WDT-387 Revised comments
1 parent b3a682c commit 8e7b6cc

File tree

8 files changed

+85
-1098
lines changed

8 files changed

+85
-1098
lines changed

core/src/main/python/extract_resource.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,20 @@
1616
# imports from local packages start here
1717
from wlsdeploy.aliases.aliases import Aliases
1818
from wlsdeploy.aliases.wlst_modes import WlstModes
19-
from wlsdeploy.exception.expection_types import ExceptionType
2019
from wlsdeploy.logging.platform_logger import PlatformLogger
2120
from wlsdeploy.tool.extract.domain_resource_extractor import DomainResourceExtractor
2221
from wlsdeploy.tool.util import model_context_helper
23-
from wlsdeploy.tool.util import wlst_helper
24-
from wlsdeploy.tool.util.wlst_helper import WlstHelper
2522
from wlsdeploy.util import cla_helper
2623
from wlsdeploy.util import tool_exit
2724
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2825
from wlsdeploy.util.cla_utils import TOOL_TYPE_EXTRACT
2926
from wlsdeploy.util.model import Model
3027
from wlsdeploy.util.weblogic_helper import WebLogicHelper
3128

32-
wlst_helper.wlst_functions = globals()
33-
3429
_program_name = 'extractDomainResource'
3530
_class_name = 'extract_resource'
3631
__logger = PlatformLogger('wlsdeploy.extract')
3732
__wls_helper = WebLogicHelper(__logger)
38-
__wlst_helper = WlstHelper(ExceptionType.DEPLOY)
3933
__wlst_mode = WlstModes.OFFLINE
4034

4135
__required_arguments = [
@@ -104,8 +98,6 @@ def main(args):
10498
for index, arg in enumerate(args):
10599
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
106100

107-
__wlst_helper.silence()
108-
109101
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
110102

111103
try:

core/src/main/python/variable_inject.py

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,28 @@
22
Copyright (c) 2018, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
5-
The entry point for the discoverDomain tool.
5+
The entry point for the injectVariables tool.
66
"""
77
import os
88
import sys
99

1010
from java.io import File
1111
from java.lang import IllegalArgumentException
12-
from java.lang import IllegalStateException
1312
from oracle.weblogic.deploy.util import CLAException
1413
from oracle.weblogic.deploy.util import FileUtils
1514
from oracle.weblogic.deploy.util import TranslateException
16-
from oracle.weblogic.deploy.util import WLSDeployArchive
1715
from oracle.weblogic.deploy.util import WLSDeployArchiveIOException
1816
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
1917

20-
2118
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
2219

2320
import wlsdeploy.tool.util.variable_injector as variable_injector
2421
from wlsdeploy.aliases.wlst_modes import WlstModes
2522
from wlsdeploy.exception import exception_helper
26-
from wlsdeploy.exception.expection_types import ExceptionType
2723
from wlsdeploy.logging.platform_logger import PlatformLogger
2824
from wlsdeploy.tool.util import model_context_helper
2925
from wlsdeploy.tool.util.variable_injector import VariableInjector
30-
from wlsdeploy.tool.util.wlst_helper import WlstHelper
31-
from wlsdeploy.util import model_translator
26+
from wlsdeploy.util import model_translator, cla_helper
3227
from wlsdeploy.util.cla_utils import CommandLineArgUtil
3328
from wlsdeploy.util.model import Model
3429
from wlsdeploy.util.model_translator import FileToPython
@@ -67,7 +62,10 @@ def __process_args(args):
6762
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
6863
required_arg_map, optional_arg_map = cla_util.process_args(args)
6964

70-
__process_model_args(optional_arg_map)
65+
cla_helper.verify_required_args_present(_program_name, __required_arguments, required_arg_map)
66+
67+
# determine if the model file was passed separately or requires extraction from the archive.
68+
cla_helper.validate_model_present(_program_name, optional_arg_map)
7169
__process_injector_file(optional_arg_map)
7270
__process_keywords_file(optional_arg_map)
7371
__process_properties_file(optional_arg_map)
@@ -77,76 +75,6 @@ def __process_args(args):
7775
return model_context_helper.create_context(_program_name, combined_arg_map)
7876

7977

80-
def __verify_required_args_present(required_arg_map):
81-
"""
82-
Verify that the required args are present.
83-
:param required_arg_map: the required arguments map
84-
:raises CLAException: if one or more of the required arguments are missing
85-
"""
86-
_method_name = '__verify_required_args_present'
87-
88-
for req_arg in __required_arguments:
89-
if req_arg not in required_arg_map:
90-
ex = exception_helper.create_cla_exception('WLSDPLY-20005', _program_name, req_arg)
91-
ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
92-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
93-
raise ex
94-
return
95-
96-
97-
def __process_model_args(optional_arg_map):
98-
"""
99-
Verify that either the model_file or archive_file was provided and exists.
100-
If the model_file was not provided, the archive_file must be provided and the indicated archive file
101-
must contain a model file. Extract the model file if the archive_file was provided.
102-
:param optional_arg_map: the optional arguments map
103-
:raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
104-
"""
105-
_method_name = '__process_model_args'
106-
global __tmp_model_dir
107-
108-
if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
109-
model_file_name = optional_arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH]
110-
111-
try:
112-
FileUtils.validateExistingFile(model_file_name)
113-
except IllegalArgumentException, iae:
114-
ex = exception_helper.create_cla_exception('WLSDPLY-20006', _program_name, model_file_name,
115-
iae.getLocalizedMessage(), error=iae)
116-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
117-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
118-
raise ex
119-
elif CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
120-
archive_file_name = optional_arg_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
121-
122-
try:
123-
archive_file = WLSDeployArchive(archive_file_name)
124-
contains_model = archive_file.containsModel()
125-
if not contains_model:
126-
ex = exception_helper.create_cla_exception('WLSDPLY-19603', archive_file_name)
127-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
128-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
129-
raise ex
130-
else:
131-
__tmp_model_dir = FileUtils.createTempDirectory(_program_name)
132-
tmp_model_file = \
133-
FileUtils.fixupFileSeparatorsForJython(archive_file.extractModel(__tmp_model_dir).getAbsolutePath())
134-
except (IllegalArgumentException, IllegalStateException, WLSDeployArchiveIOException), archex:
135-
ex = exception_helper.create_cla_exception('WLSDPLY-20010', _program_name, archive_file_name,
136-
archex.getLocalizedMessage(), error=archex)
137-
ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
138-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
139-
raise ex
140-
optional_arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = FileUtils.fixupFileSeparatorsForJython(tmp_model_file)
141-
else:
142-
ex = exception_helper.create_cla_exception('WLSDPLY-20015', _program_name, CommandLineArgUtil.MODEL_FILE_SWITCH,
143-
CommandLineArgUtil.ARCHIVE_FILE_SWITCH)
144-
ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
145-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
146-
raise ex
147-
return
148-
149-
15078
def __process_injector_file(optional_arg_map):
15179
_method_name = '__process_injector_file'
15280
if CommandLineArgUtil.VARIABLE_INJECTOR_FILE_SWITCH in optional_arg_map:

0 commit comments

Comments
 (0)