Skip to content

Commit 67178da

Browse files
fix the collection and extraction of foreign connection binding files (#650)
1 parent 6f30e28 commit 67178da

File tree

5 files changed

+102
-53
lines changed

5 files changed

+102
-53
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
KSS_KEYSTORE_TYPE = 'kss'
99
KSS_KEYSTORE_FILE_INDICATOR = 'kss:'
1010

11+
# names used within model attributes
12+
FILE_URI = 'file:///'
1113

1214
# names of model elements, alphabetically
1315

core/src/main/python/wlsdeploy/tool/deploy/deployer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def set_attributes(self, location, model_nodes, excludes=None):
178178
if key in attribute_names and not key_excluded:
179179
value = model_nodes[key]
180180
if key in uses_path_tokens_attribute_names:
181+
value = deployer_utils.extract_from_uri(self.model_context, value)
181182
self._extract_from_archive_if_needed(location, key, value)
182183

183184
wlst_merge_value = None
@@ -336,9 +337,10 @@ def _extract_from_archive_if_needed(self, location, key, value):
336337

337338
self.logger.entering(str(location), key, value, class_name=self._class_name, method_name=_method_name)
338339
result = False
339-
if deployer_utils.is_path_into_archive(value):
340+
short_value = deployer_utils.get_rel_path_from_uri(self.model_context, value)
341+
if deployer_utils.is_path_into_archive(short_value):
340342
if self.archive_helper is not None:
341-
result = self.__process_archive_entry(location, key, value)
343+
result = self.__process_archive_entry(location, key, short_value)
342344
else:
343345
path = self.alias_helper.get_model_folder_path(location)
344346
ex = exception_helper.create_deploy_exception('WLSDPLY-09110', key, path, value)

core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from sets import Set
66

77
from java.io import IOException
8+
from java.net import URI
89
from java.security import NoSuchAlgorithmException
910

1011
from oracle.weblogic.deploy.util import FileUtils
1112
from oracle.weblogic.deploy.util import PyWLSTException
1213
from oracle.weblogic.deploy.util import WLSDeployArchive
1314

15+
from wlsdeploy.aliases.model_constants import FILE_URI
1416
from wlsdeploy.aliases.wlst_modes import WlstModes
1517
from wlsdeploy.exception import exception_helper
1618
from wlsdeploy.exception.expection_types import ExceptionType
@@ -236,6 +238,39 @@ def ensure_no_uncommitted_changes_or_edit_sessions():
236238
return
237239

238240

241+
def extract_from_uri(model_context, path_value):
242+
"""
243+
If the MBean path attribute has a URI file scheme, look past the scheme and
244+
resolve any global tokens.
245+
246+
:param model_context: current context containing job information
247+
:param path_value: MBean attribute path
248+
:return: fully resolved URI path, or the path_value if not a URI scheme
249+
"""
250+
uri = URI(path_value)
251+
if uri.getScheme() == 'file':
252+
return FILE_URI + model_context.replace_token_string(uri.getPath()[1:])
253+
return path_value
254+
255+
256+
def get_rel_path_from_uri(model_context, path_value):
257+
"""
258+
If the MBean attribute is a URI. To extract it from the archive, need to make
259+
it into a relative path.
260+
:param model_context: current context containing run information
261+
:param path_value: the full value of the path attribute
262+
:return: The relative value of the path attribute
263+
"""
264+
uri = URI(path_value)
265+
if uri.getScheme() == 'file':
266+
value = model_context.tokenize_path(uri.getPath())
267+
if value.startswith(model_context.DOMAIN_HOME_TOKEN):
268+
# point past the token and first slash
269+
value = value[len(model_context.DOMAIN_HOME_TOKEN)+1:]
270+
return value
271+
return path_value
272+
273+
239274
def is_path_into_archive(path):
240275
"""
241276
Is the path specified a path into the archive file?

core/src/main/python/wlsdeploy/tool/discover/jms_resources_discoverer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from wlsdeploy.aliases import model_constants
1212
from wlsdeploy.aliases.location_context import LocationContext
13+
from wlsdeploy.aliases.model_constants import FILE_URI
1314
from wlsdeploy.aliases.wlst_modes import WlstModes
1415
from wlsdeploy.logging.platform_logger import PlatformLogger
1516
from wlsdeploy.tool.discover import discoverer
@@ -332,10 +333,12 @@ def _get_group_params(self, location):
332333
else:
333334
group_param_name = attributes[wlst_subdeployment]
334335
if group_param_name is None:
335-
_logger.warning('WLSDPLY-06486', folder_name, self._alias_helper.get_model_folder_path(location),
336+
_logger.warning('WLSDPLY-06486', folder_name,
337+
self._alias_helper.get_model_folder_path(location),
336338
class_name=_class_name, method_name=_method_name)
337339
else:
338-
_logger.finer('WLSDPLY-06487', group_param_name, self._alias_helper.get_model_folder_path(location),
340+
_logger.finer('WLSDPLY-06487', group_param_name,
341+
self._alias_helper.get_model_folder_path(location),
339342
class_name=_class_name, method_name=_method_name)
340343
subfolder_result[group_param_name] = OrderedDict()
341344
self._populate_model_parameters(subfolder_result[group_param_name], location)
@@ -401,6 +404,7 @@ def _add_foreign_server_binding(self, server_name, model_name, model_value):
401404
_logger.finer('WLSDPLY-06495', server_name, file_name, class_name=_class_name, method_name=_method_name)
402405
try:
403406
new_name = archive_file.addForeignServerFile(server_name, File(file_name))
407+
new_name = FILE_URI + self._model_context.tokenize_path(self._convert_path(new_name))
404408
_logger.info('WLSDPLY-06492', server_name, file_name, new_name, class_name=_class_name,
405409
method_name=_method_name)
406410
except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:

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

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import os
66
import tempfile
77

8+
import java.net.URI as URI
9+
810
from wlsdeploy.aliases.wlst_modes import WlstModes
911
from wlsdeploy.logging import platform_logger
1012
from wlsdeploy.util.cla_utils import CommandLineArgUtil
@@ -20,12 +22,12 @@ class ModelContext(object):
2022
"""
2123
_class_name = "ModelContext"
2224

23-
__ORACLE_HOME_TOKEN = '@@ORACLE_HOME@@'
24-
__WL_HOME_TOKEN = '@@WL_HOME@@'
25-
__DOMAIN_HOME_TOKEN = '@@DOMAIN_HOME@@'
26-
__JAVA_HOME_TOKEN = '@@JAVA_HOME@@'
27-
__CURRENT_DIRECTORY_TOKEN = '@@PWD@@'
28-
__TEMP_DIRECTORY_TOKEN = '@@TMP@@'
25+
ORACLE_HOME_TOKEN = '@@ORACLE_HOME@@'
26+
WL_HOME_TOKEN = '@@WL_HOME@@'
27+
DOMAIN_HOME_TOKEN = '@@DOMAIN_HOME@@'
28+
JAVA_HOME_TOKEN = '@@JAVA_HOME@@'
29+
CURRENT_DIRECTORY_TOKEN = '@@PWD@@'
30+
TEMP_DIRECTORY_TOKEN = '@@TMP@@'
2931

3032
def __init__(self, program_name, arg_map):
3133
"""
@@ -610,7 +612,8 @@ def replace_tokens_in_path(self, attribute_name, resource_dict):
610612
:param resource_dict: the dictionary to use to lookup and replace the attribute value
611613
"""
612614
separator = ':'
613-
path_elements = resource_dict[attribute_name].split(':')
615+
attribute_value = resource_dict[attribute_name]
616+
path_elements = attribute_value.split(':')
614617
semicolon_path_elements = resource_dict[attribute_name].split(';')
615618
if len(semicolon_path_elements) > len(path_elements):
616619
separator = ';'
@@ -634,12 +637,12 @@ def has_token_prefix(self, path):
634637
:param path: the path to check for token prefix
635638
:return: true if the path begins with a known prefix, false otherwise
636639
"""
637-
return path.startswith(self.__ORACLE_HOME_TOKEN) or \
638-
path.startswith(self.__WL_HOME_TOKEN) or \
639-
path.startswith(self.__DOMAIN_HOME_TOKEN) or \
640-
path.startswith(self.__JAVA_HOME_TOKEN) or \
641-
path.startswith(self.__CURRENT_DIRECTORY_TOKEN) or \
642-
path.startswith(self.__TEMP_DIRECTORY_TOKEN)
640+
return path.startswith(self.ORACLE_HOME_TOKEN) or \
641+
path.startswith(self.WL_HOME_TOKEN) or \
642+
path.startswith(self.DOMAIN_HOME_TOKEN) or \
643+
path.startswith(self.JAVA_HOME_TOKEN) or \
644+
path.startswith(self.CURRENT_DIRECTORY_TOKEN) or \
645+
path.startswith(self.TEMP_DIRECTORY_TOKEN)
643646

644647
def replace_tokens(self, resource_type, resource_name, attribute_name, resource_dict):
645648
"""
@@ -650,41 +653,44 @@ def replace_tokens(self, resource_type, resource_name, attribute_name, resource_
650653
:param resource_dict: the dictionary to use to lookup and replace the attribute value
651654
"""
652655
attribute_value = resource_dict[attribute_name]
653-
if attribute_value.startswith(self.__ORACLE_HOME_TOKEN):
656+
uri = URI(attribute_value)
657+
if uri.getScheme().startsWith('file'):
658+
attribute_value = uri.getPath()
659+
if attribute_value.startswith(self.ORACLE_HOME_TOKEN):
654660
message = "Replacing {0} in {1} {2} {3} with {4}"
655-
self._logger.fine(message, self.__ORACLE_HOME_TOKEN, resource_type, resource_name, attribute_name,
661+
self._logger.fine(message, self.ORACLE_HOME_TOKEN, resource_type, resource_name, attribute_name,
656662
self.get_oracle_home(), class_name=self._class_name, method_name='_replace_tokens')
657-
resource_dict[attribute_name] = attribute_value.replace(self.__ORACLE_HOME_TOKEN,
663+
resource_dict[attribute_name] = attribute_value.replace(self.ORACLE_HOME_TOKEN,
658664
self.get_oracle_home())
659-
elif attribute_value.startswith(self.__WL_HOME_TOKEN):
665+
elif attribute_value.startswith(self.WL_HOME_TOKEN):
660666
message = "Replacing {0} in {1} {2} {3} with {4}"
661-
self._logger.fine(message, self.__WL_HOME_TOKEN, resource_type, resource_name, attribute_name,
667+
self._logger.fine(message, self.WL_HOME_TOKEN, resource_type, resource_name, attribute_name,
662668
self.get_wl_home(), class_name=self._class_name, method_name='_replace_tokens')
663-
resource_dict[attribute_name] = attribute_value.replace(self.__WL_HOME_TOKEN, self.get_wl_home())
664-
elif attribute_value.startswith(self.__DOMAIN_HOME_TOKEN):
669+
resource_dict[attribute_name] = attribute_value.replace(self.WL_HOME_TOKEN, self.get_wl_home())
670+
elif attribute_value.startswith(self.DOMAIN_HOME_TOKEN):
665671
message = "Replacing {0} in {1} {2} {3} with {4}"
666-
self._logger.fine(message, self.__DOMAIN_HOME_TOKEN, resource_type, resource_name, attribute_name,
672+
self._logger.fine(message, self.DOMAIN_HOME_TOKEN, resource_type, resource_name, attribute_name,
667673
self.get_domain_home(), class_name=self._class_name, method_name='_replace_tokens')
668-
resource_dict[attribute_name] = attribute_value.replace(self.__DOMAIN_HOME_TOKEN,
674+
resource_dict[attribute_name] = attribute_value.replace(self.DOMAIN_HOME_TOKEN,
669675
self.get_domain_home())
670-
elif attribute_value.startswith(self.__JAVA_HOME_TOKEN):
676+
elif attribute_value.startswith(self.JAVA_HOME_TOKEN):
671677
message = "Replacing {0} in {1} {2} {3} with {4}"
672-
self._logger.fine(message, self.__JAVA_HOME_TOKEN, resource_type, resource_name, attribute_name,
678+
self._logger.fine(message, self.JAVA_HOME_TOKEN, resource_type, resource_name, attribute_name,
673679
self.get_domain_home(), class_name=self._class_name, method_name='_replace_tokens')
674-
resource_dict[attribute_name] = attribute_value.replace(self.__JAVA_HOME_TOKEN,
680+
resource_dict[attribute_name] = attribute_value.replace(self.JAVA_HOME_TOKEN,
675681
self.get_java_home())
676-
elif attribute_value.startswith(self.__CURRENT_DIRECTORY_TOKEN):
682+
elif attribute_value.startswith(self.CURRENT_DIRECTORY_TOKEN):
677683
cwd = path_utils.fixup_path(os.getcwd())
678684
message = "Replacing {0} in {1} {2} {3} with {4}"
679-
self._logger.fine(message, self.__CURRENT_DIRECTORY_TOKEN, resource_type, resource_name,
685+
self._logger.fine(message, self.CURRENT_DIRECTORY_TOKEN, resource_type, resource_name,
680686
attribute_name, cwd, class_name=self._class_name, method_name='_replace_tokens')
681-
resource_dict[attribute_name] = attribute_value.replace(self.__CURRENT_DIRECTORY_TOKEN, cwd)
682-
elif attribute_value.startswith(self.__TEMP_DIRECTORY_TOKEN):
687+
resource_dict[attribute_name] = attribute_value.replace(self.CURRENT_DIRECTORY_TOKEN, cwd)
688+
elif attribute_value.startswith(self.TEMP_DIRECTORY_TOKEN):
683689
temp_dir = path_utils.fixup_path(tempfile.gettempdir())
684690
message = "Replacing {0} in {1} {2} {3} with {4}"
685-
self._logger.fine(message, self.__TEMP_DIRECTORY_TOKEN, resource_type, resource_name, attribute_name,
691+
self._logger.fine(message, self.TEMP_DIRECTORY_TOKEN, resource_type, resource_name, attribute_name,
686692
temp_dir, class_name=self._class_name, method_name='_replace_tokens')
687-
resource_dict[attribute_name] = attribute_value.replace(self.__TEMP_DIRECTORY_TOKEN, temp_dir)
693+
resource_dict[attribute_name] = attribute_value.replace(self.TEMP_DIRECTORY_TOKEN, temp_dir)
688694

689695
return
690696

@@ -696,18 +702,18 @@ def replace_token_string(self, string_value):
696702
"""
697703
if string_value is None:
698704
result = None
699-
elif string_value.startswith(self.__ORACLE_HOME_TOKEN):
700-
result = _replace(string_value, self.__ORACLE_HOME_TOKEN, self.get_oracle_home())
701-
elif string_value.startswith(self.__WL_HOME_TOKEN):
702-
result = _replace(string_value, self.__WL_HOME_TOKEN, self.get_wl_home())
703-
elif string_value.startswith(self.__DOMAIN_HOME_TOKEN):
704-
result = _replace(string_value, self.__DOMAIN_HOME_TOKEN, self.get_domain_home())
705-
elif string_value.startswith(self.__JAVA_HOME_TOKEN):
706-
result = _replace(string_value, self.__JAVA_HOME_TOKEN, self.get_java_home())
707-
elif string_value.startswith(self.__CURRENT_DIRECTORY_TOKEN):
708-
result = _replace(string_value, self.__CURRENT_DIRECTORY_TOKEN, path_utils.fixup_path(os.getcwd()))
709-
elif string_value.startswith(self.__TEMP_DIRECTORY_TOKEN):
710-
result = _replace(string_value, self.__TEMP_DIRECTORY_TOKEN, path_utils.fixup_path(tempfile.gettempdir()))
705+
elif string_value.startswith(self.ORACLE_HOME_TOKEN):
706+
result = _replace(string_value, self.ORACLE_HOME_TOKEN, self.get_oracle_home())
707+
elif string_value.startswith(self.WL_HOME_TOKEN):
708+
result = _replace(string_value, self.WL_HOME_TOKEN, self.get_wl_home())
709+
elif string_value.startswith(self.DOMAIN_HOME_TOKEN):
710+
result = _replace(string_value, self.DOMAIN_HOME_TOKEN, self.get_domain_home())
711+
elif string_value.startswith(self.JAVA_HOME_TOKEN):
712+
result = _replace(string_value, self.JAVA_HOME_TOKEN, self.get_java_home())
713+
elif string_value.startswith(self.CURRENT_DIRECTORY_TOKEN):
714+
result = _replace(string_value, self.CURRENT_DIRECTORY_TOKEN, path_utils.fixup_path(os.getcwd()))
715+
elif string_value.startswith(self.TEMP_DIRECTORY_TOKEN):
716+
result = _replace(string_value, self.TEMP_DIRECTORY_TOKEN, path_utils.fixup_path(tempfile.gettempdir()))
711717
else:
712718
result = string_value
713719

@@ -733,17 +739,17 @@ def tokenize_path(self, path):
733739
result = my_path
734740
if not string_utils.is_empty(my_path):
735741
if wl_home is not None and my_path.startswith(wl_home):
736-
result = my_path.replace(wl_home, self.__WL_HOME_TOKEN)
742+
result = my_path.replace(wl_home, self.WL_HOME_TOKEN)
737743
elif domain_home is not None and my_path.startswith(domain_home):
738-
result = my_path.replace(domain_home, self.__DOMAIN_HOME_TOKEN)
744+
result = my_path.replace(domain_home, self.DOMAIN_HOME_TOKEN)
739745
elif oracle_home is not None and my_path.startswith(oracle_home):
740-
result = my_path.replace(oracle_home, self.__ORACLE_HOME_TOKEN)
746+
result = my_path.replace(oracle_home, self.ORACLE_HOME_TOKEN)
741747
elif java_home is not None and my_path.startswith(java_home):
742-
result = my_path.replace(java_home, self.__JAVA_HOME_TOKEN)
748+
result = my_path.replace(java_home, self.JAVA_HOME_TOKEN)
743749
elif my_path.startswith(cwd):
744-
result = my_path.replace(cwd, self.__CURRENT_DIRECTORY_TOKEN)
750+
result = my_path.replace(cwd, self.CURRENT_DIRECTORY_TOKEN)
745751
elif my_path.startswith(tmp_dir):
746-
result = my_path.replace(tmp_dir, self.__TEMP_DIRECTORY_TOKEN)
752+
result = my_path.replace(tmp_dir, self.TEMP_DIRECTORY_TOKEN)
747753

748754
return result
749755

0 commit comments

Comments
 (0)