Skip to content

Commit 2e63d60

Browse files
remove wlstModule usage and compress 3 wlst helper classes into 1 (#528)
* remove wlstModule usage and compress 3 wlst helper classes into 1 * fix for method arguments missed in first rount * another jrf related method mismatch * encrypt and variable_inject fixes
1 parent bb060e3 commit 2e63d60

28 files changed

+1660
-2736
lines changed

core/src/main/python/create.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@
4040
from wlsdeploy.tool.util import model_context_helper
4141
from wlsdeploy.tool.util.alias_helper import AliasHelper
4242
from wlsdeploy.tool.util.archive_helper import ArchiveHelper
43+
from wlsdeploy.tool.util.wlst_helper import WlstHelper
44+
from wlsdeploy.tool.util import wlst_helper
4345
from wlsdeploy.tool.validate.validator import Validator
4446
from wlsdeploy.util import cla_helper
4547
from wlsdeploy.util import getcreds
4648
from wlsdeploy.util import tool_exit
4749
from wlsdeploy.util import variables
48-
from wlsdeploy.util import wlst_extended
49-
from wlsdeploy.util import wlst_helper
5050
from wlsdeploy.util.cla_utils import CommandLineArgUtil
5151
from wlsdeploy.util.cla_utils import TOOL_TYPE_CREATE
5252
from wlsdeploy.util.weblogic_helper import WebLogicHelper
5353
from wlsdeploy.tool.create import atp_helper
5454

55-
wlst_extended.wlst_functions = globals()
55+
wlst_helper.wlst_functions = globals()
5656

5757
_program_name = CREATE_DOMAIN
5858

@@ -379,7 +379,7 @@ def main(args):
379379
for index, arg in enumerate(args):
380380
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
381381

382-
wlst_helper.silence()
382+
WlstHelper(ExceptionType.CREATE).silence()
383383

384384
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
385385

core/src/main/python/deploy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 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
55
The entry point for the deployApps tool.
@@ -33,24 +33,24 @@
3333
from wlsdeploy.tool.util import filter_helper
3434
from wlsdeploy.tool.util import model_context_helper
3535
from wlsdeploy.tool.util.string_output_stream import StringOutputStream
36+
from wlsdeploy.tool.util import wlst_helper
3637
from wlsdeploy.tool.util.wlst_helper import WlstHelper
3738
from wlsdeploy.util import cla_helper
3839
from wlsdeploy.util import getcreds
3940
from wlsdeploy.util import tool_exit
4041
from wlsdeploy.util import variables
41-
from wlsdeploy.util import wlst_extended
4242
from wlsdeploy.util.cla_utils import CommandLineArgUtil
4343
from wlsdeploy.util.model import Model
4444
from wlsdeploy.util.weblogic_helper import WebLogicHelper
4545

46-
wlst_extended.wlst_functions = globals()
46+
wlst_helper.wlst_functions = globals()
4747

4848

4949
_program_name = 'deployApps'
5050
_class_name = 'deploy'
5151
__logger = PlatformLogger('wlsdeploy.deploy')
5252
__wls_helper = WebLogicHelper(__logger)
53-
__wlst_helper = WlstHelper(__logger, ExceptionType.DEPLOY)
53+
__wlst_helper = WlstHelper(ExceptionType.DEPLOY)
5454
__wlst_mode = WlstModes.OFFLINE
5555

5656
__required_arguments = [

core/src/main/python/discover.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
from wlsdeploy.aliases.wlst_modes import WlstModes
3333
from wlsdeploy.exception import exception_helper
34+
from wlsdeploy.exception.expection_types import ExceptionType
3435
from wlsdeploy.logging.platform_logger import PlatformLogger
3536
from wlsdeploy.tool.discover import discoverer
3637
from wlsdeploy.tool.discover.deployments_discoverer import DeploymentsDiscoverer
@@ -41,18 +42,18 @@
4142
from wlsdeploy.tool.util import filter_helper
4243
from wlsdeploy.tool.util import model_context_helper
4344
from wlsdeploy.tool.util.variable_injector import VariableInjector
45+
from wlsdeploy.tool.util import wlst_helper
46+
from wlsdeploy.tool.util.wlst_helper import WlstHelper
4447
from wlsdeploy.tool.validate.validator import Validator
4548
from wlsdeploy.util import getcreds
4649
from wlsdeploy.util import model_translator
4750
from wlsdeploy.util import path_utils
4851
from wlsdeploy.util import tool_exit
49-
from wlsdeploy.util import wlst_extended
50-
from wlsdeploy.util import wlst_helper
5152
from wlsdeploy.util.cla_utils import CommandLineArgUtil
5253
from wlsdeploy.util.model import Model
5354
from wlsdeploy.util.weblogic_helper import WebLogicHelper
5455

55-
wlst_extended.wlst_functions = globals()
56+
wlst_helper.wlst_functions = globals()
5657

5758
_program_name = 'discoverDomain'
5859
_class_name = 'discover'
@@ -216,19 +217,23 @@ def __process_java_home(optional_arg_map):
216217
__logger.info('WLSDPLY-06027', java_home_name, iae.getLocalizedMessage(),
217218
class_name=_class_name, method_name=_method_name)
218219

219-
def __discover(model_context, aliases, injector):
220+
221+
def __discover(model_context, aliases, injector, helper):
220222
"""
221223
Populate the model from the domain.
222224
:param model_context: the model context
225+
:param aliases: aliases instance for discover
226+
:param injector: variable injector instance
227+
:param helper: wlst_helper instance
223228
:return: the fully-populated model
224229
:raises DiscoverException: if an error occurred while discover the domain
225230
"""
226231
_method_name = '__discover'
227232
model = Model()
228233
base_location = LocationContext()
229-
__connect_to_domain(model_context)
234+
__connect_to_domain(model_context, helper)
230235
try:
231-
_add_domain_name(base_location, aliases)
236+
_add_domain_name(base_location, aliases, helper)
232237
DomainInfoDiscoverer(model_context, model.get_model_domain_info(), base_location, wlst_mode=__wlst_mode,
233238
aliases=aliases, variable_injector=injector).discover()
234239
TopologyDiscoverer(model_context, model.get_model_topology(), base_location, wlst_mode=__wlst_mode,
@@ -247,15 +252,15 @@ def __discover(model_context, aliases, injector):
247252
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
248253
raise ex
249254

250-
__disconnect_domain()
255+
__disconnect_domain(helper)
251256
return model
252257

253258

254-
def _add_domain_name(location, aliases):
259+
def _add_domain_name(location, aliases, helper):
255260
_method_name = '_get_domain_name'
256261
try:
257-
wlst_helper.cd('/')
258-
domain_name = wlst_helper.get(model_constants.DOMAIN_NAME)
262+
helper.cd('/')
263+
domain_name = helper.get(model_constants.DOMAIN_NAME)
259264
except PyWLSTException, pe:
260265
de = exception_helper.create_discover_exception('WLSDPLY-06020', pe.getLocalizedMessage())
261266
__logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
@@ -281,19 +286,20 @@ def __discover_multi_tenant(model, model_context, base_location, aliases, inject
281286
return
282287

283288

284-
def __connect_to_domain(model_context):
289+
def __connect_to_domain(model_context, helper):
285290
"""
286291
Connects WLST to the domain by either connecting to the Admin Server or reading the domain from disk.
287292
:param model_context: the model context
293+
:param helper: wlst helper instance
288294
:raises DiscoverException: if a WLST error occurs while connecting to or reading the domain
289295
"""
290296
_method_name = '__connect_to_domain'
291297

292298
__logger.entering(class_name=_class_name, method_name=_method_name)
293299
if __wlst_mode == WlstModes.ONLINE:
294300
try:
295-
wlst_helper.connect(model_context.get_admin_user(), model_context.get_admin_password(),
296-
model_context.get_admin_url())
301+
helper.connect(model_context.get_admin_user(), model_context.get_admin_password(),
302+
model_context.get_admin_url())
297303
except PyWLSTException, wlst_ex:
298304
ex = exception_helper.create_discover_exception('WLSDPLY-06001', model_context.get_admin_url(),
299305
model_context.get_admin_user(),
@@ -302,7 +308,7 @@ def __connect_to_domain(model_context):
302308
raise ex
303309
else:
304310
try:
305-
wlst_helper.read_domain(model_context.get_domain_home())
311+
helper.read_domain(model_context.get_domain_home())
306312
except PyWLSTException, wlst_ex:
307313
wls_version = WebLogicHelper(__logger).get_actual_weblogic_version()
308314
ex = exception_helper.create_discover_exception('WLSDPLY-06002', model_context.get_domain_home(),
@@ -354,25 +360,26 @@ def __close_archive(model_context):
354360
return
355361

356362

357-
def __disconnect_domain():
363+
def __disconnect_domain(helper):
358364
"""
359365
Disconnects WLST from the domain by either disconnecting from the Admin Server or closing the domain read from disk.
366+
:param helper: wlst_helper instance
360367
:raises DiscoverException: if a WLST error occurred while disconnecting or closing the domain
361368
"""
362369
_method_name = '__disconnect_domain'
363370

364371
__logger.entering(class_name=_class_name, method_name=_method_name)
365372
if __wlst_mode == WlstModes.ONLINE:
366373
try:
367-
wlst_helper.disconnect()
374+
helper.disconnect()
368375
except PyWLSTException, wlst_ex:
369376
ex = exception_helper.create_discover_exception('WLSDPLY-06006',
370377
wlst_ex.getLocalizedMessage(), error=wlst_ex)
371378
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
372379
raise ex
373380
else:
374381
try:
375-
wlst_helper.close_domain()
382+
helper.close_domain()
376383
except PyWLSTException, wlst_ex:
377384
ex = exception_helper.create_discover_exception('WLSDPLY-06007',
378385
wlst_ex.getLocalizedMessage(), error=wlst_ex)
@@ -494,7 +501,8 @@ def main(args):
494501
for index, arg in enumerate(args):
495502
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
496503

497-
wlst_helper.silence()
504+
helper = WlstHelper(ExceptionType.DISCOVER)
505+
helper.silence()
498506

499507
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
500508

@@ -528,7 +536,7 @@ def main(args):
528536
else:
529537
__logger.info('WLSDPLY-06024', class_name=_class_name, method_name=_method_name)
530538
try:
531-
model = __discover(model_context, aliases, discover_injector)
539+
model = __discover(model_context, aliases, discover_injector, helper)
532540
except DiscoverException, ex:
533541
__logger.severe('WLSDPLY-06011', _program_name, model_context.get_domain_name(),
534542
model_context.get_domain_home(), ex.getLocalizedMessage(),

core/src/main/python/encrypt.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 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
55
The main module for the WLSDeploy tool to encrypt passwords.
@@ -30,12 +30,14 @@
3030
from wlsdeploy.tool.util.alias_helper import AliasHelper
3131
from wlsdeploy.util import getcreds
3232
from wlsdeploy.util import variables as variable_helper
33-
from wlsdeploy.util import wlst_helper
33+
from wlsdeploy.tool.util import wlst_helper
34+
from wlsdeploy.tool.util.wlst_helper import WlstHelper
3435
from wlsdeploy.util.cla_utils import CommandLineArgUtil
3536
from wlsdeploy.util.model_context import ModelContext
3637
from wlsdeploy.util.model_translator import FileToPython
3738
from wlsdeploy.util.model_translator import PythonToFile
3839

40+
wlst_helper.wlst_functions = globals()
3941

4042
_program_name = 'encryptModel'
4143
_class_name = 'encrypt'
@@ -279,7 +281,7 @@ def main(args):
279281
for index, arg in enumerate(args):
280282
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
281283

282-
wlst_helper.silence()
284+
WlstHelper(ExceptionType.ENCRYPTION).silence()
283285
exit_code = _process_request(args)
284286
__logger.exiting(class_name=_class_name, method_name=_method_name, result=exit_code)
285287
sys.exit(exit_code)

core/src/main/python/update.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 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
55
The entry point for the updateDomain tool.
@@ -33,25 +33,25 @@
3333
from wlsdeploy.tool.validate.validator import Validator
3434
from wlsdeploy.tool.util import filter_helper
3535
from wlsdeploy.tool.util import model_context_helper
36+
from wlsdeploy.tool.util import wlst_helper
3637
from wlsdeploy.tool.util.wlst_helper import WlstHelper
3738
from wlsdeploy.tool.util.string_output_stream import StringOutputStream
3839
from wlsdeploy.util import cla_helper
3940
from wlsdeploy.util import getcreds
4041
from wlsdeploy.util import tool_exit
4142
from wlsdeploy.util import variables
42-
from wlsdeploy.util import wlst_extended
4343
from wlsdeploy.util.cla_utils import CommandLineArgUtil
4444
from wlsdeploy.util.model import Model
4545
from wlsdeploy.util.weblogic_helper import WebLogicHelper
4646
from wlsdeploy.util import model as model_helper
4747

48-
wlst_extended.wlst_functions = globals()
48+
wlst_helper.wlst_functions = globals()
4949

5050
_program_name = UPDATE_DOMAIN
5151
_class_name = 'update'
5252
__logger = PlatformLogger('wlsdeploy.update')
5353
__wls_helper = WebLogicHelper(__logger)
54-
__wlst_helper = WlstHelper(__logger, ExceptionType.DEPLOY)
54+
__wlst_helper = WlstHelper(ExceptionType.DEPLOY)
5555
__wlst_mode = WlstModes.OFFLINE
5656

5757
__required_arguments = [

core/src/main/python/variable_inject.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
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
55
The entry point for the discoverDomain tool.
@@ -23,10 +23,11 @@
2323
import wlsdeploy.tool.util.variable_injector as variable_injector
2424
from wlsdeploy.aliases.wlst_modes import WlstModes
2525
from wlsdeploy.exception import exception_helper
26+
from wlsdeploy.exception.expection_types import ExceptionType
2627
from wlsdeploy.logging.platform_logger import PlatformLogger
2728
from wlsdeploy.tool.util import model_context_helper
2829
from wlsdeploy.tool.util.variable_injector import VariableInjector
29-
from wlsdeploy.util import wlst_helper
30+
from wlsdeploy.tool.util.wlst_helper import WlstHelper
3031
from wlsdeploy.util import model_translator
3132
from wlsdeploy.util.cla_utils import CommandLineArgUtil
3233
from wlsdeploy.util.model import Model
@@ -271,8 +272,6 @@ def main(args):
271272
for index, arg in enumerate(args):
272273
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
273274

274-
wlst_helper.silence()
275-
276275
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
277276

278277
model_context = None

core/src/main/python/wlsdeploy/exception/exception_helper.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 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
"""
55
import sys
@@ -46,6 +46,12 @@
4646
ExceptionType.YAML: 'create_yaml_exception'
4747
}
4848

49+
50+
def get_exception_class(exception_type):
51+
ex = create_exception(exception_type, 'Find the class')
52+
return ex.getClass()
53+
54+
4955
def create_exception(exception_type, key, *args, **kwargs):
5056
"""
5157
Create an exception of the specified type.
@@ -124,6 +130,7 @@ def create_deploy_exception(key, *args, **kwargs):
124130
ex = DeployException(key)
125131
return ex
126132

133+
127134
def create_discover_exception(key, *args, **kwargs):
128135
"""
129136
Create a DiscoverException from a message id, list of message parameters and Throwable error.
@@ -366,6 +373,7 @@ def create_encryption_exception(key, *args, **kwargs):
366373
ex = JEncryptionException(key)
367374
return ex
368375

376+
369377
def convert_error_to_exception():
370378
"""
371379
Convert a Python built-in error to a proper bundle-aware Java exception

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, model, model_context, aliases, exception_type=ExceptionType.C
3434
self.aliases = aliases
3535
self._exception_type = exception_type
3636
self.alias_helper = AliasHelper(self.aliases, self.logger, exception_type)
37-
self.wlst_helper = WlstHelper(self.logger, exception_type)
37+
self.wlst_helper = WlstHelper(exception_type)
3838
self.model = Model(model)
3939
self.model_context = model_context
4040
self.wls_helper = WebLogicHelper(self.logger)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2019, 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
"""
55
from java.lang import IllegalArgumentException
@@ -28,7 +28,7 @@ def __init__(self, aliases, logger, model_context, exception_type):
2828
self.exception_type = exception_type
2929
self.alias_helper = AliasHelper(aliases, self.logger, self.exception_type)
3030
self.weblogic_helper = WebLogicHelper(self.logger)
31-
self.wlst_helper = WlstHelper(self.logger, self.exception_type)
31+
self.wlst_helper = WlstHelper(self.exception_type)
3232

3333
def update_security_folder(self, location, model_type, model_subtype, model_name, model_nodes):
3434
"""

0 commit comments

Comments
 (0)