Skip to content

Commit df51ec5

Browse files
Allow discover to run without required archive file (#828)
* Allow discover to run without required archive file * Add -skip_archive CLA for discover
1 parent eb9f0ce commit df51ec5

File tree

8 files changed

+205
-87
lines changed

8 files changed

+205
-87
lines changed

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

Lines changed: 131 additions & 61 deletions
Large diffs are not rendered by default.

core/src/main/python/discover.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
The entry point for the discoverDomain tool.
@@ -62,13 +62,14 @@
6262

6363
__required_arguments = [
6464
CommandLineArgUtil.ORACLE_HOME_SWITCH,
65-
CommandLineArgUtil.DOMAIN_HOME_SWITCH,
66-
CommandLineArgUtil.ARCHIVE_FILE_SWITCH
65+
CommandLineArgUtil.DOMAIN_HOME_SWITCH
6766
]
6867

6968
__optional_arguments = [
7069
# Used by shell script to locate WLST
7170
CommandLineArgUtil.MODEL_FILE_SWITCH,
71+
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
72+
CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH,
7273
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
7374
CommandLineArgUtil.JAVA_HOME_SWITCH,
7475
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
@@ -94,35 +95,56 @@ def __process_args(args):
9495

9596
__wlst_mode = cla_helper.process_online_args(argument_map)
9697
target_configuration_helper.process_target_arguments(argument_map)
98+
__process_model_archive_args(argument_map)
9799
__process_archive_filename_arg(argument_map)
98100
__process_variable_filename_arg(argument_map)
99101
__process_java_home(argument_map)
100102

101103
return model_context_helper.create_context(_program_name, argument_map)
102104

103105

104-
def __process_archive_filename_arg(required_arg_map):
106+
def __process_model_archive_args(argument_map):
107+
"""
108+
Verify that model file and/or archive file is in the argument map
109+
:param argument_map: containing the CLA arguments
110+
"""
111+
_method_name = '__process_model_archive_args'
112+
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH not in argument_map:
113+
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH not in argument_map:
114+
ex = exception_helper.create_cla_exception('WLSDPLY-06028')
115+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
116+
raise ex
117+
if CommandLineArgUtil.MODEL_FILE_SWITCH not in argument_map:
118+
ex = exception_helper.create_cla_exception('WLSDPLY-06029')
119+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
120+
raise ex
121+
122+
123+
def __process_archive_filename_arg(argument_map):
105124
"""
106125
Validate the archive file name and load the archive file object.
107-
:param required_arg_map: the required arguments map
126+
:param argument_map: the optional arguments map
108127
:raises CLAException: if a validation error occurs while loading the archive file object
109128
"""
110129
_method_name = '__process_archive_filename_arg'
111130

112-
archive_file_name = required_arg_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
113-
archive_dir_name = path_utils.get_parent_directory(archive_file_name)
114-
if os.path.exists(archive_dir_name) is False:
115-
ex = exception_helper.create_cla_exception('WLSDPLY-06026', archive_file_name)
116-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
117-
raise ex
118-
try:
119-
archive_file = WLSDeployArchive(archive_file_name)
120-
except (IllegalArgumentException, IllegalStateException), ie:
121-
ex = exception_helper.create_cla_exception('WLSDPLY-06013', _program_name, archive_file_name,
122-
ie.getLocalizedMessage(), error=ie)
123-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
124-
raise ex
125-
required_arg_map[CommandLineArgUtil.ARCHIVE_FILE] = archive_file
131+
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map:
132+
archive_file = WLSDeployArchive.noArchiveFile()
133+
else:
134+
archive_file_name = argument_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
135+
archive_dir_name = path_utils.get_parent_directory(archive_file_name)
136+
if os.path.exists(archive_dir_name) is False:
137+
ex = exception_helper.create_cla_exception('WLSDPLY-06026', archive_file_name)
138+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
139+
raise ex
140+
try:
141+
archive_file = WLSDeployArchive(archive_file_name)
142+
except (IllegalArgumentException, IllegalStateException), ie:
143+
ex = exception_helper.create_cla_exception('WLSDPLY-06013', _program_name, archive_file_name,
144+
ie.getLocalizedMessage(), error=ie)
145+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
146+
raise ex
147+
argument_map[CommandLineArgUtil.ARCHIVE_FILE] = archive_file
126148
return
127149

128150

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
Module that handles command-line argument parsing and common validation.
@@ -46,6 +46,7 @@ class CommandLineArgUtil(object):
4646
# phony arg used as a key to store the password
4747
ADMIN_PASS_SWITCH = '-admin_pass'
4848
ARCHIVE_FILE_SWITCH = '-archive_file'
49+
SKIP_ARCHIVE_FILE_SWITCH = '-skip_archive'
4950
MODEL_FILE_SWITCH = '-model_file'
5051
DISCARD_CURRENT_EDIT_SWITCH = '-discard_current_edit'
5152
OPSS_WALLET_SWITCH = '-opss_wallet'
@@ -95,6 +96,7 @@ class CommandLineArgUtil(object):
9596
ENCRYPT_MANUAL_SWITCH,
9697
FOLDERS_ONLY_SWITCH,
9798
MODEL_SAMPLE_SWITCH,
99+
SKIP_ARCHIVE_FILE_SWITCH,
98100
RECURSIVE_SWITCH,
99101
CANCEL_CHANGES_IF_RESTART_REQ_SWITCH,
100102
RUN_RCU_SWITCH,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ WLSDPLY-06025=Variable file was provided. Model password attributes will be repl
536536
values put into the variable file.
537537
WLSDPLY-06026=Target directory for archive file argument {0} does not exist
538538
WLSDPLY-06027=JAVA_HOME {0} is not a valid location: {1}
539+
WLSDPLY-06028=Archive file name is required for discover tool unless -skip_archive argument is used.
540+
WLSDPLY-06029=Model file name is required for discover tool when -skip_archive argument is used.
539541

540542
# discoverer.py
541543
WLSDPLY-06100=Find attributes at location {0}

core/src/test/java/oracle/weblogic/deploy/util/WLSDeployArchiveTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, 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
*/
55
package oracle.weblogic.deploy.util;
@@ -100,6 +100,15 @@ public void testAddDirectory() throws Exception {
100100
archive.close();
101101
}
102102

103+
@Test
104+
public void testAddDirectoryNoArchive() throws Exception {
105+
WLSDeployArchive archive = WLSDeployArchive.noArchiveFile();
106+
File file = new File(APP_DIR_TO_ADD);
107+
String appName = archive.addApplication(file);
108+
Assert.assertEquals("unexpected app name: " + appName, file.getPath(), appName);
109+
archive.close();
110+
}
111+
103112
@Test
104113
public void testIsAFile() throws Exception {
105114
WLSDeployArchive archive = new WLSDeployArchive(APPS_ARCHIVE_FILE_NAME);
@@ -136,4 +145,10 @@ public void testClearAllBinariesWithEmptyZip() throws Exception {
136145
Assert.assertFalse("expected appName to be not empty", StringUtils.isEmpty(appName));
137146
archive.close();
138147
}
148+
149+
@Test
150+
public void testClearAllBinariesNoArchive() throws Exception {
151+
WLSDeployArchive archive = WLSDeployArchive.noArchiveFile();
152+
archive.removeAllBinaries();
153+
}
139154
}

installer/src/main/bin/discoverDomain.cmd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@rem **************************************************************************
33
@rem discoverDomain.cmd
44
@rem
5-
@rem Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
5+
@rem Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates. All rights reserved.
66
@rem Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
77
@rem
88
@rem NAME
@@ -72,7 +72,8 @@ if "%SHOW_USAGE%" == "false" (
7272
ECHO.
7373
ECHO Usage: %SCRIPT_NAME% [-oracle_home ^<oracle_home^>]
7474
ECHO -domain_home ^<domain_home^>
75-
ECHO -archive_file ^<archive_file^>
75+
ECHO [-archive_file ^<archive_file^>]
76+
ECHO [-skip_archive]
7677
ECHO [-model_file ^<model_file^>]
7778
ECHO [-variable_file ^<variable_file^>]
7879
ECHO [-domain_type ^<domain_type^>]
@@ -92,7 +93,9 @@ ECHO variable is set.
9293
ECHO.
9394
ECHO domain_home - the domain home directory
9495
ECHO.
95-
ECHO archive_file - the path to the archive file to create
96+
ECHO archive_file - the path to the archive file
97+
ECHO.
98+
ECHO skip_archive - do not generate an archive file. The archive_file option will be ignored.
9699
ECHO.
97100
ECHO model_file - the location to write the model file,
98101
ECHO the default is to write it inside the archive

installer/src/main/bin/discoverDomain.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# *****************************************************************************
33
# discoverDomain.sh
44
#
5-
# Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
5+
# Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates. All rights reserved.
66
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
77
#
88
# NAME
@@ -35,7 +35,8 @@ usage() {
3535
echo "Usage: $1 [-help]"
3636
echo " [-oracle_home <oracle_home>]"
3737
echo " -domain_home <domain_home>"
38-
echo " -archive_file <archive_file>"
38+
echo " [-archive_file <archive_file>]"
39+
echo " [-skip_archive]"
3940
echo " [-model_file <model_file>]"
4041
echo " [-variable_file <variable_file>]"
4142
echo " [-domain_type <domain_type>]"
@@ -57,6 +58,8 @@ usage() {
5758
echo ""
5859
echo " archive_file - the path to the archive file to use"
5960
echo ""
61+
echo " skip_archive - Do not generate the archive file. The archive file command will be ignored"
62+
echo ""
6063
echo " model_file - the location of the model file to use; "
6164
echo " the default is to get the model from the archive"
6265
echo ""

site/discover.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ When creating the archive, the tool will try to gather all binaries, scripts, an
1212

1313
1. Any binaries referenced from the `ORACLE_HOME` will not be gathered, as they are assumed to exist in any target domain to which model-driven operations will be applied. Doing this is key to allowing the model to be WebLogic Server version independent.
1414
2. In its current form, the Discover Domain Tool will only gather binaries and scripts that are accessible from the local machine. Warnings will be generated for any binaries or scripts that cannot be found but the configuration for those binaries will still be collected, where possible. It is the user's responsibility to add those missing files to the archive in the appropriate locations and edit the the model, as needed, to point to those files inside the archive using the relative path inside the archive (for example, `wlsdeploy/applications/myapp.ear`).
15+
3. You can you run the discover tool without generating an archive file if you wish to inspect the model file. A create or update domain requires a valid archive file for any binaries, scripts or directories that will be installed into the domain.
1516

1617
You can customize what is generated in the model for password attributes by providing a variable file location and name. This file is a text properties file which will contain a key=value for each password found in the model. The key is a unique token name for a password attribute, and the value is the replacement value; in this case, an empty string. The attribute in the model is injected with the token name and property field notation. For example, `@@PROP:AdminUserName@@` or `@@PROP:JDBCSystemResource.<Name>.JdbcResource.JDBCDriverParams.PasswordEncrypted@@`.
1718

0 commit comments

Comments
 (0)