Skip to content

Commit 1dd5514

Browse files
authored
Merge pull request #184 from oracle/issue#181-directory-name-can-be-different
Issue#181 directory name can be different
2 parents 19fa013 + c3a0579 commit 1dd5514

File tree

6 files changed

+85
-12
lines changed

6 files changed

+85
-12
lines changed

core/src/main/python/create.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@
5353

5454
__required_arguments = [
5555
CommandLineArgUtil.ORACLE_HOME_SWITCH,
56-
CommandLineArgUtil.DOMAIN_PARENT_SWITCH,
5756
CommandLineArgUtil.DOMAIN_TYPE_SWITCH
5857
]
5958

6059
__optional_arguments = [
6160
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
61+
CommandLineArgUtil.DOMAIN_HOME_SWITCH,
62+
CommandLineArgUtil.DOMAIN_PARENT_SWITCH,
6263
CommandLineArgUtil.JAVA_HOME_SWITCH,
6364
CommandLineArgUtil.MODEL_FILE_SWITCH,
6465
CommandLineArgUtil.RUN_RCU_SWITCH,
@@ -79,10 +80,11 @@ def __process_args(args):
7980
:raises CLAException: if an error occurs while validating and processing the command-line arguments
8081
"""
8182
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
82-
required_arg_map, optional_arg_map = cla_util.process_args(args)
83+
required_arg_map, optional_arg_map = cla_util.process_args(args, True)
8384

8485
__verify_required_args_present(required_arg_map)
8586
__process_java_home_arg(optional_arg_map)
87+
__process_domain_location_args(optional_arg_map)
8688
__process_model_args(optional_arg_map)
8789

8890
#
@@ -141,6 +143,29 @@ def __process_java_home_arg(optional_arg_map):
141143
return
142144

143145

146+
def __process_domain_location_args(optional_arg_map):
147+
"""
148+
Verify that either the domain_home or domain_parent was specified, and not both.
149+
Their values were already checked in the process_args call.
150+
:param optional_arg_map: the optional arguments map
151+
:raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
152+
"""
153+
_method_name = '__process_domain_location_args'
154+
global __tmp_model_dir
155+
156+
has_home = CommandLineArgUtil.DOMAIN_HOME_SWITCH in optional_arg_map
157+
has_parent = CommandLineArgUtil.DOMAIN_PARENT_SWITCH in optional_arg_map
158+
159+
if (has_home and has_parent) or (not has_home and not has_parent):
160+
ex = exception_helper.create_cla_exception('WLSDPLY-20025', _program_name,
161+
CommandLineArgUtil.DOMAIN_PARENT_SWITCH,
162+
CommandLineArgUtil.DOMAIN_HOME_SWITCH)
163+
ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
164+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
165+
raise ex
166+
return
167+
168+
144169
def __process_model_args(optional_arg_map):
145170
"""
146171
Verify that either the model_file or archive_file was provided and exists.

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ def __init__(self, model_dictionary, model_context, aliases):
9191
self._domain_name = self._topology[DOMAIN_NAME]
9292
else:
9393
self._domain_name = DEFAULT_WLS_DOMAIN_NAME
94-
self._domain_home = os.path.join(self.model_context.get_domain_parent_dir(), self._domain_name)
94+
95+
# if domain home specified on command line, set it here, otherwise append domain name to domain parent
96+
model_domain_home = self.model_context.get_domain_home()
97+
if model_domain_home:
98+
self._domain_home = model_domain_home
99+
else:
100+
self._domain_home = os.path.join(self.model_context.get_domain_parent_dir(), self._domain_name)
95101

96102
if ADMIN_SERVER_NAME in self._topology:
97103
self._admin_server_name = self._topology[ADMIN_SERVER_NAME]
@@ -712,7 +718,11 @@ def __set_app_dir(self):
712718
self.logger.fine('WLSDPLY-12225', model_helper.get_model_domain_info_key(), APP_DIR, app_dir,
713719
class_name=self.__class_name, method_name=_method_name)
714720
else:
715-
app_dir = os.path.join(self.model_context.get_domain_parent_dir(), 'applications')
721+
app_parent = self.model_context.get_domain_parent_dir()
722+
if not app_parent:
723+
app_parent = os.path.dirname(self.model_context.get_domain_home())
724+
725+
app_dir = os.path.join(app_parent, 'applications')
716726
self.logger.fine('WLSDPLY-12226', model_helper.get_model_domain_info_key(), APP_DIR, app_dir,
717727
class_name=self.__class_name, method_name=_method_name)
718728

@@ -730,6 +740,9 @@ def __set_domain_name(self):
730740
if self.__default_domain_name is None or len(self.__default_domain_name) == 0:
731741
self.__default_domain_name = DEFAULT_WLS_DOMAIN_NAME
732742

743+
# set this option, in case domain name is different from domain directory name
744+
self.wlst_helper.set_option_if_needed('DomainName', self._domain_name)
745+
733746
if self._domain_name != self.__default_domain_name:
734747
#
735748
# We cannot use the aliases for the Server Name attribute since we

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

+26-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Module that handles command-line argument parsing and common validation.
66
"""
7+
import os
78
import java.io.File as JFile
89
import java.lang.IllegalArgumentException as JIllegalArgumentException
910
import java.net.URI as JURI
@@ -94,11 +95,12 @@ def __init__(self, program_name, required_args, optional_args):
9495
self._optional_result = {}
9596
return
9697

97-
def process_args(self, args):
98+
def process_args(self, args, for_domain_create=False):
9899
"""
99100
This method parses the command-line arguments and returns dictionaries of the required and optional args.
100101
101102
:param args: sys.argv
103+
:param for_domain_create: true if validating for domain creation
102104
:return: the required and optional argument dictionaries
103105
:raises CLAException: if argument processing encounters a usage or validation exception
104106
"""
@@ -147,7 +149,10 @@ def process_args(self, args):
147149
elif self.is_domain_home_key(key):
148150
idx += 1
149151
if idx < args_len:
150-
full_path = self._validate_domain_home_arg(args[idx])
152+
if for_domain_create:
153+
full_path = self._validate_domain_home_arg_for_create(args[idx])
154+
else:
155+
full_path = self._validate_domain_home_arg(args[idx])
151156
self._add_arg(key, full_path, True)
152157
else:
153158
ex = self._get_out_of_args_exception(key)
@@ -450,8 +455,7 @@ def is_domain_home_key(self, key):
450455
return self.DOMAIN_HOME_SWITCH == key
451456

452457
#
453-
# The domain home arg is only used by discover and deploy so it must be a valid domain home.
454-
# The create domain operation should use the domain parent arg.
458+
# The domain home arg used by discover and deploy must be a valid domain home.
455459
#
456460
def _validate_domain_home_arg(self, value):
457461
method_name = '_validate_domain_home_arg'
@@ -477,6 +481,24 @@ def _validate_domain_home_arg(self, value):
477481

478482
return dh.getAbsolutePath()
479483

484+
#
485+
# The domain home arg used by create must be the child of a valid, writable directory.
486+
#
487+
def _validate_domain_home_arg_for_create(self, value):
488+
method_name = '_validate_domain_home_arg_for_create'
489+
490+
try:
491+
parent_dir = os.path.dirname(value)
492+
JFileUtils.validateWritableDirectory(parent_dir)
493+
except JIllegalArgumentException, iae:
494+
ex = exception_helper.create_cla_exception('WLSDPLY-01606', value, iae.getLocalizedMessage(), error=iae)
495+
ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
496+
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
497+
raise ex
498+
499+
home_dir = JFile(value)
500+
return home_dir.getAbsolutePath()
501+
480502
def get_domain_parent_key(self):
481503
return self.DOMAIN_PARENT_SWITCH
482504

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

+1
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ WLSDPLY-20021=Filter path {0} does not exist
12251225
WLSDPLY-20022=Error loading filter path {0}
12261226
WLSDPLY-20023={0} unable to add model file {1} to archive as {2}: {3}
12271227
WLSDPLY-20024={0} failed to persist the model to the archive file {1}: {2}
1228+
WLSDPLY-20025=For {0}, specify the {1} or {2} argument, but not both
12281229

12291230
# Common messages used for tool exit and clean-up
12301231
WLSDPLY-21000={0} Messages:

installer/src/main/bin/createDomain.cmd

+8-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ GOTO exit_script
323323
ECHO.
324324
ECHO Usage: %~nx0 [-help] [-use_encryption] [-run_rcu]
325325
ECHO -oracle_home ^<oracle-home^>
326-
ECHO -domain_parent ^<domain-parent^>
326+
ECHO [-domain_parent ^<domain-parent^> ^| -domain_home ^<domain-home^>]
327327
ECHO -domain_type ^<domain-type^>
328328
ECHO [-java_home ^<java-home^>]
329329
ECHO [-archive_file ^<archive-file^>]
@@ -337,7 +337,13 @@ ECHO.
337337
ECHO where:
338338
ECHO oracle-home - the existing Oracle Home directory for the domain.
339339
ECHO.
340-
ECHO domain-parent - the directory where the domain should be created.
340+
ECHO domain-parent - the parent directory where the domain should be created.
341+
ECHO The domain name from the model will be appended to this
342+
ECHO location to become the domain home.
343+
ECHO.
344+
ECHO domain-home - the full directory where the domain should be created.
345+
ECHO This is used in cases where the domain name is different
346+
ECHO from the domain home directory name.
341347
ECHO.
342348
ECHO domain-type - the type of domain (e.g., WLS, JRF). This controls
343349
ECHO the domain templates and template resource targeting.

installer/src/main/bin/createDomain.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ usage() {
5353
echo ""
5454
echo "Usage: $1 [-help] [-use_encryption] [-run_rcu]"
5555
echo " -oracle_home <oracle-home>"
56-
echo " -domain_parent <domain-parent>"
56+
echo " [-domain_parent <domain-parent> | -domain_home <domain-home>]"
5757
echo " -domain_type <domain-type>"
5858
echo " [-java_home <java-home>]"
5959
echo " [-archive_file <archive-file>]"
@@ -67,7 +67,13 @@ usage() {
6767
echo " where:"
6868
echo " oracle-home - the existing Oracle Home directory for the domain."
6969
echo ""
70-
echo " domain-parent - the directory where the domain should be created."
70+
echo " domain-parent - the parent directory where the domain should be created."
71+
echo " The domain name from the model will be appended to this"
72+
echo " location to become the domain home."
73+
echo ""
74+
echo " domain-home - the full directory where the domain should be created."
75+
echo " This is used in cases where the domain name is different"
76+
echo " from the domain home directory name."
7177
echo ""
7278
echo " domain-type - the type of domain (e.g., WLS, JRF). This controls"
7379
echo " the domain templates and template resource targeting."

0 commit comments

Comments
 (0)