Skip to content

Commit 5897708

Browse files
remove WeblogicHelper dependencies from aliases for aliastest (#838)
* remove WeblogicHelper dependencies from aliases for aliastest * clarify arguments on method * use WebLogicHelper only when needed
1 parent 462fe5e commit 5897708

File tree

5 files changed

+84
-66
lines changed

5 files changed

+84
-66
lines changed

core/src/main/python/wlsdeploy/aliases/alias_entries.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2021, 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 copy
@@ -68,7 +68,7 @@
6868
from wlsdeploy.exception import exception_helper
6969
from wlsdeploy.logging.platform_logger import PlatformLogger
7070
from wlsdeploy.util import dictionary_utils
71-
from wlsdeploy.util.weblogic_helper import WebLogicHelper
71+
from wlsdeploy.util import string_utils
7272

7373
_class_name = 'AliasEntries'
7474
_logger = PlatformLogger('wlsdeploy.aliases')
@@ -196,10 +196,10 @@ def __init__(self, wlst_mode=WlstModes.OFFLINE, wls_version=None):
196196
self._category_dict = {}
197197
self._wlst_mode = wlst_mode
198198
if wls_version is None:
199+
from wlsdeploy.util.weblogic_helper import WebLogicHelper
199200
self._wls_helper = WebLogicHelper(_logger)
200201
self._wls_version = self._wls_helper.get_actual_weblogic_version()
201202
else:
202-
self._wls_helper = WebLogicHelper(_logger, wls_version)
203203
self._wls_version = wls_version
204204

205205
return
@@ -242,9 +242,9 @@ def get_model_topology_subfolder_names(self):
242242
:return: a list of the folder names
243243
"""
244244
result = list(self.__topology_top_level_folders)
245-
if not self._wls_helper.is_weblogic_version_or_above('12.2.1'):
245+
if not string_utils.is_weblogic_version_or_above(self._wls_version, '12.2.1'):
246246
result.remove('VirtualTarget')
247-
if not self._wls_helper.is_weblogic_version_or_above('12.1.2'):
247+
if not string_utils.is_weblogic_version_or_above(self._wls_version, '12.1.2'):
248248
result.remove('RestfulManagementServices')
249249
result.remove('ServerTemplate')
250250
return result
@@ -255,13 +255,13 @@ def get_model_resources_subfolder_names(self):
255255
:return: a list of the folder names
256256
"""
257257
result = list(self.__resources_top_level_folders)
258-
if not self._wls_helper.is_weblogic_version_or_above('12.2.1'):
258+
if not string_utils.is_weblogic_version_or_above(self._wls_version, '12.2.1'):
259259
result.remove('Partition')
260260
result.remove('PartitionWorkManager')
261261
result.remove('ResourceGroup')
262262
result.remove('ResourceGroupTemplate')
263263
result.remove('ResourceManagement')
264-
if not self._wls_helper.is_weblogic_version_or_above('12.1.2'):
264+
if not string_utils.is_weblogic_version_or_above(self._wls_version, '12.1.2'):
265265
result.remove('CoherenceClusterSystemResource')
266266
return result
267267

@@ -356,7 +356,7 @@ def get_model_folder_path_for_location(self, location):
356356
my_loc.add_name_token(name_token, name)
357357
# dont include token in path for single-unpredictable
358358
if not self.is_location_child_folder_type(my_loc, ChildFoldersTypes.SINGLE):
359-
model_folder_path += '%s/' % name
359+
model_folder_path += '%s/' % name
360360
elif location_folder != location_folders[-1]:
361361
# Throw AliasException if name_token is missing
362362
# from any location folder, except the last one
@@ -581,12 +581,11 @@ def get_name_token_for_location(self, location):
581581
code, message = self.is_valid_model_folder_name_for_location(err_location, folder_name)
582582
if code == ValidationCodes.VERSION_INVALID:
583583
ex = exception_helper.create_alias_exception('WLSDPLY-08130', path,
584-
self._wls_helper.get_actual_weblogic_version(),
584+
self._wls_version,
585585
message)
586586
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
587587
raise ex
588-
ex = exception_helper.create_alias_exception('WLSDPLY-08131', path,
589-
self._wls_helper.get_actual_weblogic_version())
588+
ex = exception_helper.create_alias_exception('WLSDPLY-08131', path, self._wls_version)
590589
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
591590
raise ex
592591

@@ -833,7 +832,7 @@ def is_version_valid_location(self, location):
833832
if self.get_wlst_mbean_type_for_location(location) is None:
834833
model_folder_path = self.get_model_folder_path_for_location(location)
835834
message = exception_helper.get_message('WLSDPLY-08138', model_folder_path,
836-
self._wls_helper.get_weblogic_version())
835+
self._wls_version)
837836
code = ValidationCodes.VERSION_INVALID
838837

839838
_logger.exiting(class_name=_class_name, method_name=_method_name, result=[code, message])
@@ -1281,7 +1280,7 @@ def __is_version(self, path_name, alias_dict):
12811280
if dict_version_range:
12821281
try:
12831282
_logger.finer('WLSDPLY-08123', path_name, dict_version_range,
1284-
self._wls_helper.get_actual_weblogic_version(),
1283+
self._wls_version,
12851284
class_name=_class_name, method_name=_method_name)
12861285
is_version = self.__version_in_range(dict_version_range)
12871286

@@ -1295,7 +1294,7 @@ def __is_version(self, path_name, alias_dict):
12951294

12961295
if is_version:
12971296
_logger.finer('WLSDPLY-08125', path_name, dict_version_range,
1298-
self._wls_helper.get_actual_weblogic_version(),
1297+
self._wls_version,
12991298
class_name=_class_name, method_name=_method_name)
13001299

13011300
return is_version

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2021, 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
from java.lang import String
@@ -50,7 +50,6 @@
5050
from wlsdeploy.exception.expection_types import ExceptionType
5151
from wlsdeploy.logging.platform_logger import PlatformLogger
5252
from wlsdeploy.util import string_utils
53-
from wlsdeploy.util.weblogic_helper import WebLogicHelper
5453

5554

5655
class Aliases(object):
@@ -74,8 +73,9 @@ def __init__(self, model_context, wlst_mode=WlstModes.OFFLINE, wls_version=None,
7473
self._exception_type = exception_type
7574
self._logger = PlatformLogger('wlsdeploy.aliases')
7675

77-
self._wls_helper = WebLogicHelper(self._logger)
7876
if wls_version is None:
77+
from wlsdeploy.util.weblogic_helper import WebLogicHelper
78+
self._wls_helper = WebLogicHelper(self._logger)
7979
self._wls_version = self._wls_helper.wl_version_actual
8080
else:
8181
self._wls_version = wls_version

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
from wlsdeploy.util.target_configuration import CREDENTIALS_METHOD
2020
from wlsdeploy.util.target_configuration import CREDENTIALS_METHODS
2121
from wlsdeploy.util.target_configuration import TargetConfiguration
22-
from wlsdeploy.util.weblogic_helper import WebLogicHelper
2322

2423
# tool type may indicate variations in argument processing
2524
TOOL_TYPE_CREATE = "create"
2625
TOOL_TYPE_DEFAULT = "default"
2726
TOOL_TYPE_EXTRACT = "extract"
2827

2928

29+
3030
class CommandLineArgUtil(object):
3131
"""
3232
Class that handles command-line argument parsing and common validation.
@@ -422,6 +422,7 @@ def is_oracle_home_key(self, key):
422422
return self.ORACLE_HOME_SWITCH == key
423423

424424
def _validate_oracle_home_arg(self, value):
425+
from wlsdeploy.util.weblogic_helper import WebLogicHelper
425426
method_name = '_validate_oracle_home_arg'
426427

427428
try:
@@ -923,6 +924,7 @@ def is_target_version_switch(self, key):
923924
return self.TARGET_VERSION_SWITCH == key
924925

925926
def _validate_target_version_arg(self, value):
927+
from wlsdeploy.util.weblogic_helper import WebLogicHelper
926928
method_name = '_validate_target_version_arg'
927929

928930
# Try our best to determine if this is a legitimate WLS version number.

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2021, 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
This module provides string manipulation helper methods that are not found in the WLST version of Jython
66
"""
7+
import java.lang.String as JString
78
import java.util.Properties as Properties
89
import java.io.FileInputStream as FileInputStream
910
import java.io.IOException as IOException
@@ -15,6 +16,8 @@
1516
__logger = PlatformLogger('wlsdeploy.util')
1617
_class_name = 'string_utils'
1718

19+
STANDARD_VERSION_NUMBER_PLACES = 5
20+
1821

1922
def is_empty(text):
2023
"""
@@ -104,3 +107,56 @@ def load_properties(property_file, exception_type=None):
104107
prop_dict[key] = value
105108

106109
return prop_dict
110+
111+
112+
def is_weblogic_version_or_above(wls_version, str_version):
113+
"""
114+
Is the provided version number equal to or greater than the version encapsualted by this version instance
115+
:param wls_version: the string representation of the current weblogic version
116+
:param str_version: the string representation of the version to be compared to the weblogic version
117+
:return: True if the provided version is equal or greater than the version represented by the wls_version argument
118+
"""
119+
result = False
120+
array_version = str_version.split('.')
121+
array_wl_version = _get_wl_version_array(wls_version)
122+
123+
len_compare = len(array_wl_version)
124+
if len(array_version) < len_compare:
125+
len_compare = len(array_version)
126+
127+
idx = 0
128+
while idx < len_compare:
129+
compare_value = JString(array_version[idx]).compareTo(JString(array_wl_version[idx]))
130+
if compare_value < 0:
131+
result = True
132+
break
133+
elif compare_value > 0:
134+
result = False
135+
break
136+
elif idx + 1 == len_compare:
137+
result = True
138+
139+
idx += 1
140+
141+
return result
142+
143+
144+
# We need to pad the actual version number for comparison purposes so
145+
# that is is never shorter than the specified version. Otherwise,
146+
# actual version 12.2.1 will be considered to be equal to 12.2.1.1
147+
#
148+
def _get_wl_version_array(wl_version):
149+
"""
150+
Get the WebLogic version number padded to the standard number of digits.
151+
:param wl_version: WebLogic version number
152+
:return: the padded WebLogic version number
153+
"""
154+
result = wl_version.split('.')
155+
156+
if len(result) < STANDARD_VERSION_NUMBER_PLACES:
157+
index = len(result)
158+
while index < STANDARD_VERSION_NUMBER_PLACES:
159+
result.append('0')
160+
index += 1
161+
162+
return result

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

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2021, 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 java.lang.Exception as JException
6-
import java.lang.String as JString
76

87
import weblogic.management.provider.ManagementServiceClient as ManagementServiceClient
98
import weblogic.security.internal.SerializedSystemIni as SerializedSystemIni
@@ -16,11 +15,12 @@
1615
import os
1716
import re
1817

18+
1919
class WebLogicHelper(object):
2020
"""
2121
Helper functions for version-specific WebLogic operations.
2222
"""
23-
STANDARD_VERSION_NUMBER_PLACES = 5
23+
2424
MINIMUM_WEBLOGIC_VERSION = '10.3.6'
2525
_class_name = 'WebLogicHelper'
2626

@@ -228,27 +228,11 @@ def is_weblogic_version_or_above(self, str_version, use_actual_version=False):
228228
False (default), use version places up to the number represented by STANDARD_VERSION_NUMBER_PLACES
229229
:return: True if the provided version is equal or greater than the version represented by this helper instance
230230
"""
231-
result = False
232-
array_version = str_version.split('.')
233-
array_wl_version = self._get_wl_version_array(use_actual_version=use_actual_version)
234-
235-
len_compare = len(array_wl_version)
236-
if len(array_version) < len_compare:
237-
len_compare = len(array_version)
238-
239-
idx = 0
240-
while idx < len_compare:
241-
compare_value = JString(array_version[idx]).compareTo(JString(array_wl_version[idx]))
242-
if compare_value < 0:
243-
result = True
244-
break
245-
elif compare_value > 0:
246-
result = False
247-
break
248-
elif idx + 1 == len_compare:
249-
result = True
250-
251-
idx += 1
231+
if use_actual_version:
232+
wl_version = self.wl_version_actual
233+
else:
234+
wl_version = self.wl_version
235+
result = string_utils.is_weblogic_version_or_above(wl_version, str_version)
252236

253237
return result
254238

@@ -261,29 +245,6 @@ def get_bean_info_for_interface(self, interface_name):
261245
bean_access = ManagementServiceClient.getBeanInfoAccess()
262246
return bean_access.getBeanInfoForInterface(interface_name, False, '9.0.0.0')
263247

264-
# We need to pad the actual version number for comparison purposes so
265-
# that is is never shorter than the specified version. Otherwise,
266-
# actual version 12.2.1 will be considered to be equal to 12.2.1.1
267-
#
268-
def _get_wl_version_array(self, use_actual_version=False):
269-
"""
270-
Get the WebLogic version number padded to the standard number of digits.
271-
:param use_actual_version: whether to use the actual or supplied version of WebLogic
272-
:return: the padded WebLogic version number
273-
"""
274-
if use_actual_version:
275-
result = self.wl_version_actual.split('.')
276-
else:
277-
result = self.wl_version.split('.')
278-
279-
if len(result) < self.STANDARD_VERSION_NUMBER_PLACES:
280-
index = len(result)
281-
while index < self.STANDARD_VERSION_NUMBER_PLACES:
282-
result.append('0')
283-
index += 1
284-
285-
return result
286-
287248
def get_next_higher_order_version_number(self, version_number):
288249
"""
289250
Get the next higher order version number. For example, passing in '12.2.1.2' will return '12.2.1'.

0 commit comments

Comments
 (0)