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 3f4c12bfd..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. """ @@ -22,10 +22,16 @@ 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.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 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 +175,54 @@ 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/ + # 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: + 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) + if custom_path.startswith(ARCHIVE_COHERENCE_TARGET_DIR): + # this is the extracted path from the archive + config_filepath = os.path.join(domain_home, custom_path) + else: + # absolute path + config_filepath = custom_path + + if os.path.exists(config_filepath): + shutil.copy(config_filepath, coh_cluster_config_path) + if custom_path.startswith(ARCHIVE_COHERENCE_TARGET_DIR): + os.remove(config_filepath) 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..d627ac90c 100644 --- a/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py +++ b/core/src/main/python/wlsdeploy/tool/util/attribute_setter.py @@ -1,7 +1,8 @@ """ -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 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,28 @@ 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 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)) + + self.set_attribute(location, key, value, wlst_merge_value=wlst_value) + # # public set_attribute convenience methods # @@ -1048,3 +1072,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..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 @@ -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", "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}