From f172808bf79d75dde70642f8a4b8599dd0ba6263 Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Thu, 19 Jan 2023 19:14:43 -0600 Subject: [PATCH 1/4] Fix problem where the custom coherence cluster configuration file is created at the wrong location. --- .../tool/deploy/common_resources_deployer.py | 32 +++++++++++++++++-- .../wlsdeploy/tool/util/attribute_setter.py | 21 +++++++++++- .../CoherenceClusterSystemResource.json | 4 +-- .../deploy/messages/wlsdeploy_rb.properties | 1 + 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py b/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py index 3f4c12bfd..6b9287d10 100644 --- a/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py +++ b/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py @@ -22,10 +22,14 @@ from wlsdeploy.aliases.model_constants import SINGLETON_SERVICE from wlsdeploy.aliases.model_constants import SYSTEM_COMPONENT from wlsdeploy.aliases.model_constants import MIME_MAPPING_FILE +from wlsdeploy.aliases.model_constants import COHERENCE_RESOURCE +from wlsdeploy.aliases.model_constants import COHERENCE_CUSTOM_CLUSTER_CONFIGURATION + from wlsdeploy.aliases.wlst_modes import WlstModes from wlsdeploy.tool.deploy.deployer import Deployer from wlsdeploy.util import dictionary_utils - +from wlsdeploy.exception import exception_helper +import os, shutil class CommonResourcesDeployer(Deployer): """ @@ -169,8 +173,30 @@ def add_coherence_clusters(self, parent_dict, location): :param parent_dict: the dictionary possibly containing coherence cluster elements :param location: the location to deploy the elements """ - file_stores = dictionary_utils.get_dictionary_element(parent_dict, COHERENCE_CLUSTER_SYSTEM_RESOURCE) - self._add_named_elements(COHERENCE_CLUSTER_SYSTEM_RESOURCE, file_stores, location) + coherence_clusters = dictionary_utils.get_dictionary_element(parent_dict, COHERENCE_CLUSTER_SYSTEM_RESOURCE) + self._add_named_elements(COHERENCE_CLUSTER_SYSTEM_RESOURCE, coherence_clusters, location) + + self._make_coh_cluster_custom_config_available(coherence_clusters) + + def _make_coh_cluster_custom_config_available(self, coherence_clusters): + # The coherence cluster custom configuration file must be within the config/coherence/ + # + _method_name = '_make_coh_cluster_custom_config_available' + try: + domain_home = self.model_context.get_domain_home() + for coherence_cluster in coherence_clusters: + new_path = os.path.join(domain_home, 'config', 'coherence', coherence_cluster) + if not os.path.exists(new_path): + os.mkdir(new_path) + extracted_config_filepath = os.path.join(domain_home, + coherence_clusters[coherence_cluster][COHERENCE_RESOURCE][COHERENCE_CUSTOM_CLUSTER_CONFIGURATION]) + if os.path.exists(extracted_config_filepath): + shutil.copy(extracted_config_filepath, new_path) + os.remove(extracted_config_filepath) + except Exception, e: + ex = exception_helper.create_deploy_exception('WLSDPLY-09406', e.getLocalizedMessage()) + self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name) + raise ex def add_webapp_container(self, parent_dict, location): """ diff --git a/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py b/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py index 334430cf4..ce29409c9 100644 --- a/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py +++ b/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py @@ -2,6 +2,7 @@ Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ +import os from javax.management import ObjectName from org.python.modules import jarray @@ -78,7 +79,8 @@ from wlsdeploy.util import model_helper import wlsdeploy.util.unicode_helper as str_helper from wlsdeploy.util.weblogic_helper import WebLogicHelper - +from oracle.weblogic.deploy.util.WLSDeployArchive import ARCHIVE_COHERENCE_TARGET_DIR +from oracle.weblogic.deploy.util.WLSDeployArchive import WLSDPLY_ARCHIVE_BINARY_DIR class AttributeSetter(object): """ @@ -662,6 +664,22 @@ def set_encrypted(self, location, key, value, wlst_value): self.__weblogic_helper.encrypt(str_helper.to_string(value), self.__model_context.get_domain_home()) self.set_attribute(location, key, encrypted_value, wlst_merge_value=wlst_value) + def set_coherence_cluster_custom_config_file(self, location, key, value, wlst_value): + """ + Set the coherence cluster custom config file attribute correctly. If the path starts with archive entry + location, then it should be set to coherence// + :param location: location + :param key: this should be CustomClusterConfigurationFileName + :param value: path of the config file + :param wlst_value: the existing value of the attribute from WLST + :raises BundleAwareException of the specified type: if an error occurs + """ + + if value.startswith(ARCHIVE_COHERENCE_TARGET_DIR + os.sep): + # plus 1 for the file separator + value = value[len(WLSDPLY_ARCHIVE_BINARY_DIR + os.sep):] + self.set_attribute(location, key, value, wlst_merge_value=wlst_value) + # # public set_attribute convenience methods # @@ -1048,3 +1066,4 @@ def __merge_existing_items(self, items, existing_value, location, key): result.append(item) return result + diff --git a/core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/CoherenceClusterSystemResource.json b/core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/CoherenceClusterSystemResource.json index 6c2964d41..d48a31ac1 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/CoherenceClusterSystemResource.json +++ b/core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/CoherenceClusterSystemResource.json @@ -245,7 +245,7 @@ }, "attributes": { "CustomClusterConfigurationFileLastUpdatedTimestamp": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CustomClusterConfigurationFileLastUpdatedTimestamp", "wlst_path": "WP001", "default_value": 0, "wlst_type": "long", "access": "${:RO}" } ], - "CustomClusterConfigurationFileName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CustomClusterConfigurationFileName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "access": "${:RO}", "uses_path_tokens": "true" } ], + "CustomClusterConfigurationFileName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CustomClusterConfigurationFileName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "access": "${:RO}", "set_method": "MBEAN.set_coherence_cluster_custom_config_file", "uses_path_tokens": "true" } ], "Version": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "Version", "wlst_path": "WP001", "default_value": null, "wlst_type": "string"} ] }, "wlst_attributes_path": "WP001", @@ -277,7 +277,7 @@ "attributes": { "CompatibilityName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CompatibilityName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ], "ClusterHosts": [ {"version": "[12.2.1.1,)", "wlst_mode": "online", "wlst_name": "ClusterHosts", "wlst_path": "WP001", "default_value": null, "wlst_type": "jarray", "preferred_model_type": "delimited_string", "get_method": "GET", "access": "RO" } ], - "CustomClusterConfigurationFileName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CustomClusterConfigurationFileName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "access": "RO", "uses_path_tokens": "true" } ], + "CustomClusterConfigurationFileName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CustomClusterConfigurationFileName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "set_method": "MBEAN.set_coherence_cluster_custom_config_file", "access": "RO", "uses_path_tokens": "true" } ], "CustomConfigFileLastUpdatedTime": [ {"version": "[12.2.1.1,)", "wlst_mode": "both", "wlst_name": "CustomConfigFileLastUpdatedTime", "wlst_path": "WP001", "default_value": 0, "wlst_type": "long", "access": "RO"} ], "DeploymentOrder": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "DeploymentOrder", "wlst_path": "WP001", "default_value": 100, "wlst_type": "integer" } ], "DeploymentPrincipalName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "DeploymentPrincipalName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ], diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index d062f6217..3fe465f22 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -1173,6 +1173,7 @@ WLSDPLY-09402=Failed to create directory for FileStore {0} because the location WLSDPLY-09403=Created FileStore {0} directory {1} WLSDPLY-09404=Failed to create directory for FileStore {0} at location {1} WLSDPLY-09405={0} resources in the model are not configured in online mode +WLSDPLY-09406=Failed to move coherence cluster custom config file {0} # wlsdeploy/tool/deploy/jms_resources_deployer.py WLSDPLY-09500=Creating placeholder for Template {0} From 7bdd4fc81e7fb00887c3aa4dfcf706d2e5924255 Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Fri, 20 Jan 2023 08:14:43 -0600 Subject: [PATCH 2/4] refactoring --- .../tool/deploy/common_resources_deployer.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py b/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py index 6b9287d10..8308dad62 100644 --- a/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py +++ b/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py @@ -24,6 +24,7 @@ from wlsdeploy.aliases.model_constants import MIME_MAPPING_FILE from wlsdeploy.aliases.model_constants import COHERENCE_RESOURCE from wlsdeploy.aliases.model_constants import COHERENCE_CUSTOM_CLUSTER_CONFIGURATION +from oracle.weblogic.deploy.util.WLSDeployArchive import ARCHIVE_COHERENCE_TARGET_DIR from wlsdeploy.aliases.wlst_modes import WlstModes from wlsdeploy.tool.deploy.deployer import Deployer @@ -180,19 +181,27 @@ def add_coherence_clusters(self, parent_dict, location): def _make_coh_cluster_custom_config_available(self, coherence_clusters): # The coherence cluster custom configuration file must be within the config/coherence/ - # + # We will copy the config file over, at this point the model's attribute value is still the original value + _method_name = '_make_coh_cluster_custom_config_available' try: domain_home = self.model_context.get_domain_home() for coherence_cluster in coherence_clusters: - new_path = os.path.join(domain_home, 'config', 'coherence', coherence_cluster) - if not os.path.exists(new_path): - os.mkdir(new_path) - extracted_config_filepath = os.path.join(domain_home, - coherence_clusters[coherence_cluster][COHERENCE_RESOURCE][COHERENCE_CUSTOM_CLUSTER_CONFIGURATION]) - if os.path.exists(extracted_config_filepath): - shutil.copy(extracted_config_filepath, new_path) - os.remove(extracted_config_filepath) + coh_cluster_config_path = os.path.join(domain_home, 'config', 'coherence', coherence_cluster) + if not os.path.exists(coh_cluster_config_path): + os.mkdir(coh_cluster_config_path) + path = coherence_clusters[coherence_cluster][COHERENCE_RESOURCE][COHERENCE_CUSTOM_CLUSTER_CONFIGURATION] + if path.startswith(ARCHIVE_COHERENCE_TARGET_DIR): + # this is the extracted path from the archive + config_filepath = os.path.join(domain_home, path) + else: + # absolute path + config_filepath = path + + if os.path.exists(config_filepath): + shutil.copy(config_filepath, coh_cluster_config_path) + if path.startswith(ARCHIVE_COHERENCE_TARGET_DIR): + os.remove(config_filepath) except Exception, e: ex = exception_helper.create_deploy_exception('WLSDPLY-09406', e.getLocalizedMessage()) self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name) From e6905acf7cff1d73f8ffdfa86e687b70c3ebcbbb Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Fri, 20 Jan 2023 10:07:02 -0600 Subject: [PATCH 3/4] refactor --- .../wlsdeploy/aliases/model_constants.py | 3 +- .../tool/deploy/common_resources_deployer.py | 37 ++++++++++++++----- .../wlsdeploy/tool/util/attribute_setter.py | 2 +- .../CoherenceClusterSystemResource.json | 2 +- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/core/src/main/python/wlsdeploy/aliases/model_constants.py b/core/src/main/python/wlsdeploy/aliases/model_constants.py index e882f596f..975bacdeb 100644 --- a/core/src/main/python/wlsdeploy/aliases/model_constants.py +++ b/core/src/main/python/wlsdeploy/aliases/model_constants.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. +Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ @@ -72,6 +72,7 @@ COHERENCE_SNAPSHOT_DIRECTORY = 'SnapshotDirectory' COHERENCE_SOCKET_ADDRESS = 'CoherenceSocketAddress' COHERENCE_TRASH_DIRECTORY = 'TrashDirectory' +COHERENCE_USE_CUSTOM_CLUSTER_CONFIG = 'UsingCustomClusterConfigurationFile' COHERENCE_WELL_KNOWN_ADDRESSES = 'CoherenceClusterWellKnownAddresses' COHERENCE_WELL_KNOWN_ADDRESS = 'CoherenceClusterWellKnownAddress' CONFIGURATION_PROPERTY = 'ConfigurationProperty' diff --git a/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py b/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py index 8308dad62..e62a51f9d 100644 --- a/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py +++ b/core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates. All rights reserved. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ @@ -24,6 +24,7 @@ from wlsdeploy.aliases.model_constants import MIME_MAPPING_FILE from wlsdeploy.aliases.model_constants import COHERENCE_RESOURCE from wlsdeploy.aliases.model_constants import COHERENCE_CUSTOM_CLUSTER_CONFIGURATION +from wlsdeploy.aliases.model_constants import COHERENCE_USE_CUSTOM_CLUSTER_CONFIG from oracle.weblogic.deploy.util.WLSDeployArchive import ARCHIVE_COHERENCE_TARGET_DIR from wlsdeploy.aliases.wlst_modes import WlstModes @@ -187,25 +188,41 @@ def _make_coh_cluster_custom_config_available(self, coherence_clusters): try: domain_home = self.model_context.get_domain_home() for coherence_cluster in coherence_clusters: + cluster = coherence_clusters[coherence_cluster] + use_custom_config = dictionary_utils.get_dictionary_element(cluster, + COHERENCE_USE_CUSTOM_CLUSTER_CONFIG) + + if use_custom_config: + self._copy_custom_config_file_to_destination(cluster, coherence_cluster, domain_home) + else: + continue + + except Exception, e: + ex = exception_helper.create_deploy_exception('WLSDPLY-09406', e) + self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name) + raise ex + + def _copy_custom_config_file_to_destination(self, cluster, coherence_cluster, domain_home): + coh_resource = dictionary_utils.get_dictionary_element(cluster, COHERENCE_RESOURCE) + if coh_resource: + custom_path = dictionary_utils.get_dictionary_element(coh_resource, + COHERENCE_CUSTOM_CLUSTER_CONFIGURATION) + + if custom_path is not None: coh_cluster_config_path = os.path.join(domain_home, 'config', 'coherence', coherence_cluster) if not os.path.exists(coh_cluster_config_path): os.mkdir(coh_cluster_config_path) - path = coherence_clusters[coherence_cluster][COHERENCE_RESOURCE][COHERENCE_CUSTOM_CLUSTER_CONFIGURATION] - if path.startswith(ARCHIVE_COHERENCE_TARGET_DIR): + if custom_path.startswith(ARCHIVE_COHERENCE_TARGET_DIR): # this is the extracted path from the archive - config_filepath = os.path.join(domain_home, path) + config_filepath = os.path.join(domain_home, custom_path) else: # absolute path - config_filepath = path + config_filepath = custom_path if os.path.exists(config_filepath): shutil.copy(config_filepath, coh_cluster_config_path) - if path.startswith(ARCHIVE_COHERENCE_TARGET_DIR): + if custom_path.startswith(ARCHIVE_COHERENCE_TARGET_DIR): os.remove(config_filepath) - except Exception, e: - ex = exception_helper.create_deploy_exception('WLSDPLY-09406', e.getLocalizedMessage()) - self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name) - raise ex def add_webapp_container(self, parent_dict, location): """ diff --git a/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py b/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py index ce29409c9..74373fefc 100644 --- a/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py +++ b/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved. +Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates. All rights reserved. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ import os diff --git a/core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/CoherenceClusterSystemResource.json b/core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/CoherenceClusterSystemResource.json index d48a31ac1..467edd87e 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/CoherenceClusterSystemResource.json +++ b/core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/CoherenceClusterSystemResource.json @@ -277,7 +277,7 @@ "attributes": { "CompatibilityName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CompatibilityName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ], "ClusterHosts": [ {"version": "[12.2.1.1,)", "wlst_mode": "online", "wlst_name": "ClusterHosts", "wlst_path": "WP001", "default_value": null, "wlst_type": "jarray", "preferred_model_type": "delimited_string", "get_method": "GET", "access": "RO" } ], - "CustomClusterConfigurationFileName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CustomClusterConfigurationFileName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "set_method": "MBEAN.set_coherence_cluster_custom_config_file", "access": "RO", "uses_path_tokens": "true" } ], + "CustomClusterConfigurationFileName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "CustomClusterConfigurationFileName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "access": "RO", "uses_path_tokens": "true" } ], "CustomConfigFileLastUpdatedTime": [ {"version": "[12.2.1.1,)", "wlst_mode": "both", "wlst_name": "CustomConfigFileLastUpdatedTime", "wlst_path": "WP001", "default_value": 0, "wlst_type": "long", "access": "RO"} ], "DeploymentOrder": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "DeploymentOrder", "wlst_path": "WP001", "default_value": 100, "wlst_type": "integer" } ], "DeploymentPrincipalName": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "DeploymentPrincipalName", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ], From aac4dab15add8001630269b5f8908e8805bd6a56 Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Fri, 20 Jan 2023 10:55:51 -0600 Subject: [PATCH 4/4] Fix path value if it is absolute --- .../python/wlsdeploy/tool/util/attribute_setter.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py b/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py index 74373fefc..d627ac90c 100644 --- a/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py +++ b/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py @@ -674,10 +674,16 @@ def set_coherence_cluster_custom_config_file(self, location, key, value, wlst_va :param wlst_value: the existing value of the attribute from WLST :raises BundleAwareException of the specified type: if an error occurs """ + if value is not None: + if value.startswith(ARCHIVE_COHERENCE_TARGET_DIR + os.sep): + # change from /wlsdeploy/coherence// --> coherence// + value = value[len(WLSDPLY_ARCHIVE_BINARY_DIR + os.sep):] + else: + # The file will be copied to the $DOMAIN/config/coherence/ + # changing the attribute value to the pattern coherence// + cluster_name = location.get_name_for_token('COHERENCECLUSTER') + value = 'coherence/%s/%s' % (cluster_name, os.path.basename(value)) - if value.startswith(ARCHIVE_COHERENCE_TARGET_DIR + os.sep): - # plus 1 for the file separator - value = value[len(WLSDPLY_ARCHIVE_BINARY_DIR + os.sep):] self.set_attribute(location, key, value, wlst_merge_value=wlst_value) #