Skip to content

Commit fc909e3

Browse files
CarolynRountreeddsharpe
authored andcommitted
Wdt#457 capture user override scripts (#466)
* Change attribute in domainInfo not found in dictionary from SEVERE to INFO to allow user customization * Collect user override scripts into archive and install into the domain
1 parent b34d11a commit fc909e3

File tree

11 files changed

+193
-6
lines changed

11 files changed

+193
-6
lines changed

core/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<dependency>
3333
<groupId>org.python</groupId>
3434
<artifactId>jython</artifactId>
35+
<version>2.2.1</version>
3536
<scope>provided</scope>
3637
</dependency>
3738
<dependency>

core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java

+60
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public class WLSDeployArchive {
7171
*/
7272
public static final String ARCHIVE_CPLIB_TARGET_DIR = WLSDPLY_ARCHIVE_BINARY_DIR + "/classpathLibraries";
7373

74+
/**
75+
* Top-level archive subdirectory where the $DOMAIN_HOME/bin scripts are stored.
76+
*/
77+
public static final String ARCHIVE_DOM_BIN_TARGET_DIR = WLSDPLY_ARCHIVE_BINARY_DIR + "/domainBin";
7478
/**
7579
* Top-level archive subdirectory where the FileStore directories are stored and the subdirectory
7680
* to which they will be extracted.
@@ -714,6 +718,62 @@ public void extractDomainLibLibrary(String archivePath, File extractToLocation)
714718
LOGGER.exiting(CLASS, METHOD);
715719
}
716720

721+
/**
722+
* Adds a $DOMAIN_HOME/bin script to the archive. If a script with the same name already exists, this method
723+
* assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding a
724+
* numeric value onto the file's basename (e.g., myscript(1).cmd, myscript(2).cmd).
725+
*
726+
* @param domainBinPath - File representing the actual path of the script file in the file system
727+
* @return the relative path where the script is stored within the archive
728+
* @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes
729+
* @throws IllegalArgumentException if the file or directory passed in does not exist
730+
*/
731+
public String addDomainBinScript(File domainBinPath) throws WLSDeployArchiveIOException {
732+
final String METHOD = "addDomainBinScript";
733+
734+
LOGGER.entering(CLASS, METHOD, domainBinPath);
735+
validateExistingFile(domainBinPath, "domainBinPath", getArchiveFileName(), METHOD);
736+
737+
String newName = addItemToZip(ARCHIVE_DOM_BIN_TARGET_DIR, domainBinPath);
738+
LOGGER.exiting(CLASS, METHOD, newName);
739+
return newName;
740+
}
741+
742+
/**
743+
* Get the list of $DOMAIN_HOME/bin script names in the archive.
744+
*
745+
* @return the list of $DOMAIN_HOME/bin script names
746+
* @throws WLSDeployArchiveIOException if an error occurs reading the archive
747+
*/
748+
public List<String> listDomainBinScripts() throws WLSDeployArchiveIOException {
749+
final String METHOD = "listDomainBinScripts";
750+
751+
LOGGER.entering(CLASS, METHOD);
752+
List<String> result = getZipFile().listZipEntries(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP);
753+
// Remove the top-level directory entry from the list...
754+
result.remove(ARCHIVE_DOM_BIN_TARGET_DIR + ZIP_SEP);
755+
LOGGER.exiting(CLASS, METHOD, result);
756+
return result;
757+
}
758+
759+
/**
760+
* Extract the specified domain bin user script to the specified location (e.g., $DOMAIN_HOME/bin).
761+
*
762+
* @param archivePath the path of the script within the archive
763+
* @param extractToLocation the location to write the file
764+
* @throws WLSDeployArchiveIOException if an IOException occurred while extracting or writing the file
765+
* @throws IllegalArgumentException if the file or directory passed in does not exist
766+
*/
767+
public void extractDomainBinScript(String archivePath, File extractToLocation) throws WLSDeployArchiveIOException {
768+
final String METHOD = "extractDomainBinScript";
769+
770+
LOGGER.entering(CLASS, METHOD, archivePath, extractToLocation);
771+
validateNonEmptyString(archivePath, "archivePath", METHOD);
772+
validateExistingDirectory(extractToLocation, "extractToLocation", getArchiveFileName(), METHOD);
773+
774+
extractFileFromZip(archivePath, ARCHIVE_DOM_BIN_TARGET_DIR, "", extractToLocation);
775+
LOGGER.exiting(CLASS, METHOD);
776+
}
717777
/**
718778
* This method adds a classpath library to the archive. If a library with the same name already exists, this
719779
* method assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding

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

+1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class AliasEntries(object):
181181
'AdminUserName': 'string',
182182
'AdminPassword': 'password',
183183
'ServerStartMode': 'string',
184+
'domainBin': 'list',
184185
'domainLibraries': 'list',
185186
# A map of Server Group names to the list of servers/clusters to which they should
186187
# be targeted. The ServerGroup must appear in the domain typedef definition. If

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

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
DOMAIN_NAME = 'Name'
9595
DOMAIN_INFO = 'domainInfo'
9696
DOMAIN_LIBRARIES = 'domainLibraries'
97+
DOMAIN_SCRIPTS = 'domainBin'
9798
DYNAMIC_SERVERS = 'DynamicServers'
9899
EMBEDDED_LDAP = 'EmbeddedLDAP'
99100
ERROR_DESTINATION = 'ErrorDestination'

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

+1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def __create_domain(self):
345345

346346
self.library_helper.install_domain_libraries()
347347
self.library_helper.extract_classpath_libraries()
348+
self.library_helper.install_domain_scripts()
348349
self.wlsroles_helper.process_roles()
349350
if os.environ.has_key('__WLSDEPLOY_STORE_MODEL__'):
350351
model_helper.persist_model(self.model_context, self.model)

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

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def update(self):
140140

141141
self.library_helper.install_domain_libraries()
142142
self.library_helper.extract_classpath_libraries()
143+
self.library_helper.install_domain_scripts()
143144

144145
def _process_section(self, folder_dict, folder_list, key, location):
145146
if key in folder_dict:

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

+36
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
Copyright (c) 2017, 2019, 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
"""
5+
import glob
56
import os
67

78
from java.io import File
89

910
from oracle.weblogic.deploy.util import WLSDeployArchiveIOException
11+
from oracle.weblogic.deploy.util import FileUtils
1012

1113
from wlsdeploy.aliases import model_constants
1214
from wlsdeploy.aliases.wlst_modes import WlstModes
@@ -40,6 +42,8 @@ def discover(self):
4042
_logger.entering(class_name=_class_name, method_name=_method_name)
4143
model_top_folder_name, result = self.get_domain_libs()
4244
discoverer.add_to_model_if_not_empty(self._dictionary, model_top_folder_name, result)
45+
model_top_folder_name, result = self.get_user_env_scripts()
46+
discoverer.add_to_model_if_not_empty(self._dictionary, model_top_folder_name, result)
4347
_logger.exiting(class_name=_class_name, method_name=_method_name)
4448
return self._dictionary
4549

@@ -73,3 +77,35 @@ def get_domain_libs(self):
7377

7478
_logger.exiting(class_name=_class_name, method_name=_method_name, result=entries)
7579
return model_constants.DOMAIN_LIBRARIES, entries
80+
81+
def get_user_env_scripts(self):
82+
"""
83+
Look for the user overrides scripts run in setDomainEnv in the domain bin directory
84+
:raise: DiscoverException: an unexpected exception occurred writing a jar file to the archive file
85+
"""
86+
_method_name = 'get_user_env_scripts'
87+
_logger.entering(class_name=_class_name, method_name=_method_name)
88+
archive_file = self._model_context.get_archive_file()
89+
domain_bin = self._convert_path('bin')
90+
entries = []
91+
if os.path.isdir(domain_bin):
92+
search_directory = FileUtils.fixupFileSeparatorsForJython(os.path.join(domain_bin, "setUserOverrides*.*"))
93+
_logger.finer('WLSDPLY-06425', search_directory, class_name=_class_name, method_name=_method_name)
94+
file_list = glob.glob(search_directory)
95+
if file_list:
96+
_logger.finer('WLSDPLY-06423', domain_bin, class_name=_class_name, method_name=_method_name)
97+
for entry in file_list:
98+
try:
99+
updated_name = archive_file.addDomainBinScript(File(entry))
100+
except WLSDeployArchiveIOException, wioe:
101+
de = exception_helper.create_discover_exception('WLSDPLY-06426', entry,
102+
wioe.getLocalizedMessage())
103+
_logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
104+
raise de
105+
106+
entries.append(updated_name)
107+
_logger.finer('WLSDPLY-06424', entry, updated_name, class_name=_class_name,
108+
method_name=_method_name)
109+
110+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=entries)
111+
return model_constants.DOMAIN_SCRIPTS, entries

core/src/main/python/wlsdeploy/tool/util/archive_helper.py

+26
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,32 @@ def extract_classpath_libraries(self):
280280
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name, result=count)
281281
return count
282282

283+
def extract_domain_bin_script(self, script_path):
284+
"""
285+
Extract the specified domain bin script to the $DOMAIN_HOME/bin directory.
286+
:param script_path: the domain bin path and script into the archive file
287+
:raises: BundleAwareException of the appropriate type: if an error occurs
288+
"""
289+
_method_name = 'extract_domain_bin_script'
290+
291+
self.__logger.entering(script_path, class_name=self.__class_name, method_name=_method_name)
292+
try:
293+
archive = self._find_archive_for_path(script_path)
294+
if archive is not None:
295+
archive.extractDomainBinScript(script_path, File(self.__domain_home, 'bin'))
296+
else:
297+
ex = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-19308',
298+
script_path, self.__archive_files_text)
299+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
300+
raise ex
301+
except (WLSDeployArchiveIOException, IllegalArgumentException), e:
302+
ex = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-19309', script_path,
303+
self.__archive_files_text, e.getLocalizedMessage(), error=e)
304+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
305+
raise ex
306+
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name)
307+
return
308+
283309
def get_archive_entries(self):
284310
"""
285311
Get the entries from all the archives.

core/src/main/python/wlsdeploy/tool/util/library_helper.py

+49
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from oracle.weblogic.deploy.util import WLSDeployArchive
77
from shutil import copy
88

9+
from wlsdeploy.aliases.model_constants import DOMAIN_SCRIPTS
910
from wlsdeploy.aliases.model_constants import DOMAIN_LIBRARIES
1011
from wlsdeploy.exception import exception_helper
1112
from wlsdeploy.tool.util.alias_helper import AliasHelper
@@ -86,6 +87,37 @@ def extract_classpath_libraries(self):
8687
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
8788
return
8889

90+
def install_domain_scripts(self):
91+
"""
92+
Extract the scripts from domain bin listed in the model, if any, to the <DOMAIN_HOME>/bin directory.
93+
:raises: BundleAwareException of the specified type: if an error occurs
94+
"""
95+
_method_name = 'install_domain_scripts'
96+
97+
self.logger.entering(self.domain_home, class_name=self.__class_name, method_name=_method_name)
98+
domain_info_dict = self.model.get_model_domain_info()
99+
if DOMAIN_SCRIPTS not in domain_info_dict or len(domain_info_dict[DOMAIN_SCRIPTS]) == 0:
100+
self.logger.info('WLSDPLY-12241', class_name=self.__class_name, method_name=_method_name)
101+
elif DOMAIN_SCRIPTS in domain_info_dict:
102+
domain_scripts = dictionary_utils.get_dictionary_element(domain_info_dict, DOMAIN_SCRIPTS)
103+
if self.archive_helper is None:
104+
ex = exception_helper.create_create_exception('WLSDPLY-12250', domain_scripts)
105+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
106+
raise ex
107+
108+
for domain_script in domain_scripts:
109+
if WLSDeployArchive.isPathIntoArchive(domain_script):
110+
self.logger.info('WLSDPLY-12251', domain_script, self.domain_home,
111+
class_name=self.__class_name, method_name=_method_name)
112+
self.archive_helper.extract_domain_bin_script(domain_script)
113+
else:
114+
self.logger.info('WLSDPLY-12252', domain_script, self.domain_home,
115+
class_name=self.__class_name, method_name=_method_name)
116+
self._copy_domain_bin(domain_script)
117+
118+
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
119+
return
120+
89121
def _copy_domain_library(self, domain_lib):
90122
"""
91123
Copy the specified domain library to the domain's lib directory.
@@ -102,3 +134,20 @@ def _copy_domain_library(self, domain_lib):
102134
ex = exception_helper.create_create_exception('WLSDPLY-12234', source_path, target_dir)
103135
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
104136
raise ex
137+
138+
def _copy_domain_bin(self, domain_bin):
139+
"""
140+
Copy the specified domain user script to the domain's bin directory.
141+
:raises: BundleAwareException of the specified type: if an error occurs
142+
"""
143+
_method_name = '_copy_domain_bin'
144+
145+
source_path = File(domain_bin).getAbsolutePath()
146+
target_dir = File(self.domain_home, 'bin').getPath()
147+
148+
try:
149+
copy(str(source_path), str(target_dir))
150+
except IOError:
151+
ex = exception_helper.create_create_exception('WLSDPLY-12253', source_path, target_dir)
152+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
153+
raise ex

core/src/main/python/wlsdeploy/tool/validate/validator.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from wlsdeploy.util.enum import Enum
3131
from wlsdeploy.util.weblogic_helper import WebLogicHelper
3232

33+
from wlsdeploy.aliases.model_constants import DOMAIN_SCRIPTS
3334
from wlsdeploy.aliases.model_constants import DOMAIN_LIBRARIES
3435
from wlsdeploy.aliases.model_constants import MODEL_LIST_DELIMITER
3536
from wlsdeploy.aliases.model_constants import NAME
@@ -400,7 +401,7 @@ def __validate_domain_info_section(self, model_section_key, model_dict):
400401
if section_dict_key in valid_attr_infos:
401402
# section_dict_key is an attribute under the model section, and
402403
# also in valid_attr_infos.
403-
if section_dict_key == DOMAIN_LIBRARIES:
404+
if section_dict_key in [DOMAIN_LIBRARIES, DOMAIN_SCRIPTS]:
404405
self.__validate_path_tokens_attribute(section_dict_key, section_dict_value, model_folder_path)
405406

406407
elif section_dict_key == SERVER_GROUP_TARGETING_LIMITS:
@@ -415,10 +416,10 @@ def __validate_domain_info_section(self, model_section_key, model_dict):
415416
path_tokens_attr_keys, model_folder_path, validation_location)
416417
else:
417418
# section_dict_key is not an attribute allowed under the model
418-
# section, so record this as a validate ERROR in the validate
419-
# results.
420-
self._logger.severe('WLSDPLY-05029', section_dict_key, model_folder_path, valid_attr_infos.keys(),
421-
class_name=_class_name, method_name=_method_name)
419+
# section. Do not record this as an ERROR as this could be custom
420+
# information that the user has written a filter to extract
421+
self._logger.info('WLSDPLY-05029', section_dict_key, model_folder_path, valid_attr_infos.keys(),
422+
class_name=_class_name, method_name=_method_name)
422423

423424
def __validate_model_section(self, model_section_key, model_dict, valid_section_folders):
424425
_method_name = '__validate_model_section'

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

+11-1
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ WLSDPLY-06402=Add application {0} deployment plan {1} to archive file
609609
WLSDPLY-06420=Add the java archive files from the domain library {0} to the archive file
610610
WLSDPLY-06421=Unexpected exception occurred writing the domain library file {0} to the archive : {1}
611611
WLSDPLY-06422=Add domain lib file {0} to the archive file and entry {1] to the model domain info section
612+
WLSDPLY-06423=Add the user override env script files from the domain bin location {0} to the archive file
613+
WLSDPLY-06424=Add user override script {0} to the archive file and entry {1] to the model domain info section
614+
WLSDPLY-06425=Look for user env override scripts using search pattern {0}
615+
WLSDPLY-06426=Unexpected exception occurred writing the domain bin user overrides file {0} to the archive : {1}
612616

613617
# global_resources_discoverer.py
614618
WLSDPLY-06440=Discover Global Resources from the domain
@@ -1121,9 +1125,9 @@ WLSDPLY-12235=Installing domain library {0} to lib directory of {1}
11211125
WLSDPLY-12236=Target the JRF resources to the clusters with dynamic servers {0}
11221126
WLSDPLY-12237=Target the resources for server groups {0} to cluster {1} with dynamic server members
11231127
WLSDPLY-12238=Unable to target non-JRF template server groups for domain type {0} to dynamic cluster(s).
1124-
11251128
WLSDPLY-12239=Found server groups {0} for cluster {1}
11261129
WLSDPLY-12240=Server group targeting limits {0} found in model
1130+
WLSDPLY-12241=The model did not specify any domain scripts to install
11271131
WLSDPLY-12242=The assignment of servers to server groups map is {0}
11281132
WLSDPLY-12243=Server group list found for {0} in domainInfo : {1}
11291133
WLSDPLY-12244=Targeting JRF resources to a dynamic cluster(s), {0}, for a Restricted JRF domain type is not valid \
@@ -1134,6 +1138,10 @@ WLSDPLY-12247=WebLogic does not support targeting resources to dynamic servers.
11341138
will be targeted to the dynamic cluster using the applyJRF function.
11351139
WLSDPLY-12248=The server group(s) {0} will not be targeted to the Admin server or a configured manage server
11361140
WLSDPLY-12249=RCUDBInfo section is specified in the model but the domain type used is not JRF, RCU processing skipped
1141+
WLSDPLY-12250=Domain bin ({0}) specified in the model but the archive file name was not provided
1142+
WLSDPLY-12251=Installing domain script {0} from archive to bin directory of {1}
1143+
WLSDPLY-12252=Copying domain script {0} to bin directory of {1}
1144+
WLSDPLY-12253=Unable to copy domain user script {0} to directory {1}
11371145

11381146
# domain_typedef.py
11391147
WLSDPLY-12300={0} got the domain type {1} but the domain type definition file {2} was not valid: {3}
@@ -1341,6 +1349,8 @@ WLSDPLY-19304=Unable to compute hash for entry {0} in archive file {1}: {2}
13411349
WLSDPLY-19305=Failed to extract domain library {0} because it does not exist in archive file {1}
13421350
WLSDPLY-19306=Unable to extract domain library {0} from archive file {1}: {2}
13431351
WLSDPLY-19307=Unable to extract classpath libraries from archive file {0} to domain directory {1}: {2}
1352+
WLSDPLY-19308=Failed to extract script to domain bin {0} because it does not exist in archive file {1}
1353+
WLSDPLY-19309=Unable to extract from domain bin {0} from archive file {1}: {2}
13441354

13451355
# wlsdeploy/tool/util/topology_helper.py
13461356
WLSDPLY-19400=Creating placeholder for server template {0}

0 commit comments

Comments
 (0)