Skip to content

Commit e01581e

Browse files
authored
Collect jdbc wallet (#1379)
* add wallet collection logic * undo unnecessary changes * refactor * fix bug * fix bug * add integration test * make sure wallet available when updating ds * restore integration tests * Fix npe * add error when wallet file not found * copyright change * add info for not trying to collect if remote * fix remote discovery and skip archive * fix problem where domain directory does not exist yet before extracting wallet * undo model change * fix compare test result * fix compare result * fix sonar issue * sonar fix * sonar code smell
1 parent 6dd85ed commit e01581e

File tree

10 files changed

+316
-9
lines changed

10 files changed

+316
-9
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ public int removeStructuredApplication(String appPath, boolean silent) throws WL
13941394
* @param shlibPath file name to find the name for
13951395
* @return name for model archive file name
13961396
*/
1397-
public String getSharedLibraryArchivePath(String shlibPath) {
1397+
public static String getSharedLibraryArchivePath(String shlibPath) {
13981398
return getArchiveName(ARCHIVE_SHLIBS_TARGET_DIR, shlibPath);
13991399
}
14001400

@@ -1718,7 +1718,7 @@ public int removeSharedLibraryDeploymentPlan(String planPath, boolean silent) th
17181718
* @param domainLibPath the file name to get the archive file name
17191719
* @return model ready archive file name
17201720
*/
1721-
public String getDomainLibArchiveName(String domainLibPath) {
1721+
public static String getDomainLibArchiveName(String domainLibPath) {
17221722
return getArchiveName(ARCHIVE_DOMLIB_TARGET_DIR, domainLibPath);
17231723
}
17241724

@@ -3718,6 +3718,16 @@ public String addDatabaseWallet(String walletName, String sourceLocation) throws
37183718
return newName;
37193719
}
37203720

3721+
/**
3722+
* Return the database wallet path of a file.
3723+
* @param walletName database wallet name
3724+
* @param fileLocation a file in the wallet
3725+
* @return path to the particular file in the database wallet
3726+
*/
3727+
public static String getDatabaseWalletArchivePath(String walletName, String fileLocation) {
3728+
return getArchiveName(ARCHIVE_DB_WALLETS_DIR + ZIP_SEP + walletName, fileLocation);
3729+
}
3730+
37213731
/**
37223732
* Add the RCU database wallet to the archive.
37233733
*

core/src/main/python/create.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,16 @@ def main(model_context):
320320
archive_helper = ArchiveHelper(archive_file_name, domain_path, __logger, ExceptionType.CREATE)
321321

322322
has_atp, has_ssl = validate_rcu_args_and_model(model_context, model_dictionary, archive_helper, aliases)
323-
# check if there is an atpwallet and extract in the domain dir
324-
# it is to support non JRF domain but user wants to use ATP database
325-
if has_atp and archive_helper:
326-
archive_helper.extract_database_wallet()
323+
324+
if archive_helper:
325+
domain_parent = model_context.get_domain_parent_dir()
326+
domain_home = model_context.get_domain_home()
327+
if domain_parent and domain_home is None:
328+
domain_home = os.path.join(domain_parent, model_dictionary[model_constants.TOPOLOGY]['Name'])
329+
if not os.path.exists(os.path.abspath(domain_home)):
330+
os.mkdir(os.path.abspath(domain_home))
331+
332+
archive_helper.extract_all_database_wallets()
327333

328334
creator = DomainCreator(model_dictionary, model_context, aliases)
329335
creator.create()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class DatasourceDeployer(Deployer):
1818

1919
def __init__(self, model, model_context, aliases, wlst_mode=WlstModes.OFFLINE):
2020
Deployer.__init__(self, model, model_context, aliases, wlst_mode)
21+
if not model_context.is_remote() and self.archive_helper:
22+
self.archive_helper.extract_all_database_wallets()
2123

2224
def add_data_sources(self, parent_dict, location):
2325
"""

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

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Copyright (c) 2017, 2023, 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 os.path
56
from java.lang import IllegalArgumentException
67

78
from oracle.weblogic.deploy.util import PyOrderedDict as OrderedDict
@@ -91,6 +92,7 @@ def get_datasources(self):
9192
location = LocationContext(self._base_location)
9293
location.append_location(model_top_folder_name)
9394
datasources = self._find_names_in_folder(location)
95+
collected_wallet = {}
9496
if datasources is not None:
9597
_logger.info('WLSDPLY-06340', len(datasources), class_name=_class_name, method_name=_method_name)
9698
typedef = self._model_context.get_domain_typedef()
@@ -112,11 +114,126 @@ def get_datasources(self):
112114
resource_result = result[datasource][model_second_folder]
113115
self._populate_model_parameters(resource_result, location)
114116
self._discover_subfolders(resource_result, location)
117+
self._collect_jdbc_driver_wallet(datasource, collected_wallet,
118+
result[datasource][model_constants.JDBC_RESOURCE][model_constants.JDBC_DRIVER_PARAMS])
115119
location.remove_name_token(name_token)
116120
location.pop_location()
117121
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
118122
return model_top_folder_name, result
119123

124+
def _collect_jdbc_driver_wallet(self, datasource, collected_wallet, driver_params):
125+
if not self._model_context.skip_archive() and model_constants.JDBC_DRIVER_PARAMS_PROPERTIES in driver_params:
126+
properties = driver_params[model_constants.JDBC_DRIVER_PARAMS_PROPERTIES]
127+
self._update_wallet_property_and_collect_files(collected_wallet, datasource, properties)
128+
129+
def _update_wallet_property_and_collect_files(self, collected_wallet, datasource, properties):
130+
_method_name = '_update_wallet_property_and_collect_files'
131+
for connection_property in [model_constants.DRIVER_PARAMS_KEYSTORE_PROPERTY,
132+
model_constants.DRIVER_PARAMS_TRUSTSTORE_PROPERTY,
133+
model_constants.DRIVER_PARAMS_NET_TNS_ADMIN]:
134+
if connection_property in properties:
135+
qualified_property_value = properties[connection_property]['Value']
136+
if qualified_property_value:
137+
if qualified_property_value.startswith(WLSDeployArchive.WLSDPLY_ARCHIVE_BINARY_DIR
138+
+ WLSDeployArchive.ZIP_SEP):
139+
qualified_property_value = os.path.join(self._model_context.get_domain_home()
140+
, qualified_property_value)
141+
if os.path.exists(qualified_property_value):
142+
fixed_path = self._add_wallet_directory_to_archive(datasource, collected_wallet,
143+
qualified_property_value)
144+
_logger.info('WLSDPLY-06367', connection_property, fixed_path,
145+
class_name=_class_name, method_name=_method_name)
146+
properties[connection_property]['Value'] = fixed_path
147+
else:
148+
_logger.severe('WLSDPLY-06370', datasource, connection_property,
149+
properties[connection_property]['Value'])
150+
de = exception_helper.create_discover_exception('WLSDPLY-06370', datasource,
151+
connection_property,
152+
properties[connection_property][
153+
'Value'])
154+
_logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
155+
raise de
156+
157+
def _add_wallet_directory_to_archive(self, datasource, collected_wallet_dictionary, property_value):
158+
# error if wallet parent path is at oracle home
159+
onprem_wallet_parent_path, wallet_name = self._get_wallet_name_and_path(datasource, property_value)
160+
161+
if self._model_context.is_remote():
162+
fixed_path = WLSDeployArchive.getDatabaseWalletArchivePath(wallet_name, property_value)
163+
self.add_to_remote_map(property_value, fixed_path,
164+
WLSDeployArchive.ArchiveEntryType.DB_WALLET.name())
165+
return fixed_path
166+
167+
onprem_wallet_dir_is_not_flat = self._is_on_prem_wallet_dir_flat(onprem_wallet_parent_path, property_value)
168+
archive_file = self._model_context.get_archive_file()
169+
170+
# keep track of the wallet name and from where it is collected
171+
# { <onprem_wallet_parentpath> : { 'wallet_name': <name>, 'path_into_archive': <wallet path into archive>,
172+
# },
173+
# .... }
174+
#
175+
if onprem_wallet_parent_path not in collected_wallet_dictionary:
176+
if onprem_wallet_dir_is_not_flat:
177+
# collect the specific file
178+
fixed_path = archive_file.addDatabaseWallet(wallet_name, os.path.abspath(property_value))
179+
path_into_archive = os.path.dirname(fixed_path)
180+
else:
181+
fixed_path = archive_file.addDatabaseWallet(wallet_name, onprem_wallet_parent_path)
182+
path_into_archive = fixed_path
183+
fixed_path = os.path.join(fixed_path, os.path.basename(property_value))
184+
185+
collected_wallet_dictionary[onprem_wallet_parent_path] = \
186+
{'wallet_name' : wallet_name, 'path_into_archive': path_into_archive}
187+
else:
188+
# if the directory has already been visited before
189+
# check for the wallet to see if the file has already been collected on prem and add only the file
190+
check_path = os.path.join(
191+
collected_wallet_dictionary[onprem_wallet_parent_path]['path_into_archive'],
192+
os.path.basename(property_value))
193+
if check_path not in archive_file.getArchiveEntries() and os.path.isfile(property_value):
194+
# only case is it is not flat directory if the particular file has not been collected before, add
195+
# it to the previous wallet
196+
fixed_path = archive_file.addDatabaseWallet(collected_wallet_dictionary[onprem_wallet_parent_path]['wallet_name'],
197+
os.path.abspath(property_value))
198+
else:
199+
# already in archive just figure out the path
200+
if (os.path.isdir(property_value)):
201+
fixed_path = collected_wallet_dictionary[onprem_wallet_parent_path]['path_into_archive']
202+
else:
203+
fixed_path = os.path.join(collected_wallet_dictionary[onprem_wallet_parent_path]['path_into_archive'],
204+
os.path.basename(property_value))
205+
206+
return fixed_path
207+
208+
def _get_wallet_name_and_path(self, datasource, property_value):
209+
_method_name = '_get_wallet_name_and_path'
210+
# fix up name just in case
211+
wallet_name = datasource.replace(' ', '').replace('(', '').replace(')', '')
212+
if os.path.isdir(property_value):
213+
onprem_wallet_parent_path = os.path.abspath(property_value)
214+
else:
215+
onprem_wallet_parent_path = os.path.dirname(os.path.abspath(property_value))
216+
if self._model_context.get_oracle_home() == onprem_wallet_parent_path:
217+
_logger.severe('WLSDPLY-06368', property_value, self._model_context.get_oracle_home())
218+
de = exception_helper.create_discover_exception('WLSDPLY-06368', property_value,
219+
self._model_context.get_oracle_home())
220+
_logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
221+
raise de
222+
return onprem_wallet_parent_path, wallet_name
223+
224+
def _is_on_prem_wallet_dir_flat(self, onprem_wallet_parent_path, property_value):
225+
# info if wallet parent is not flat and only collect the particular file and not the entire directory
226+
dir_list = os.listdir(onprem_wallet_parent_path)
227+
onprem_wallet_dir_is_not_flat = False
228+
for item in dir_list:
229+
if os.path.isdir(os.path.join(onprem_wallet_parent_path, item)):
230+
onprem_wallet_dir_is_not_flat = True
231+
break
232+
# put out info for user only particular file is collected and not the entire wallet directory
233+
if onprem_wallet_dir_is_not_flat:
234+
_logger.info('WLSDPLY-06369', property_value)
235+
return onprem_wallet_dir_is_not_flat
236+
120237
def get_foreign_jndi_providers(self):
121238
"""
122239
Discover Foreign JNDI providers from the domain.
@@ -224,7 +341,6 @@ def archive_file_store_directory(self, file_store_name, file_store_dictionary):
224341
file_store_dictionary[model_constants.DIRECTORY] = new_source_name
225342

226343
_logger.exiting(class_name=_class_name, method_name=_method_name)
227-
return
228344

229345
def get_jdbc_stores(self):
230346
"""

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Copyright (c) 2017, 2023, 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 os
5+
import os, sets
66
import shutil
77

88
from java.io import File
@@ -401,6 +401,21 @@ def extract_database_wallet(self, wallet_name=WLSDeployArchive.DEFAULT_RCU_WALLE
401401
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name, result=resulting_wallet_path)
402402
return resulting_wallet_path
403403

404+
def extract_all_database_wallets(self):
405+
406+
for archive_file in self.__archive_files:
407+
archive_entries = archive_file.getArchiveEntries()
408+
wallet_names = sets.Set()
409+
for entry in archive_entries:
410+
if entry.startswith(WLSDeployArchive.ARCHIVE_DB_WALLETS_DIR):
411+
if os.path.isdir(entry):
412+
wallet_names.add(os.path.basename(entry))
413+
else:
414+
name = os.path.basename(os.path.dirname(entry))
415+
wallet_names.add(name)
416+
for wallet_name in wallet_names:
417+
self.extract_database_wallet(wallet_name)
418+
404419
def extract_opss_wallet(self):
405420
"""
406421
Extract the and unzip the OPSS wallet, if present, and return the path to the wallet directory.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,15 @@ WLSDPLY-06363=Skipping {0} File Store {1}
740740
WLSDPLY-06364=Discovering {0} {1} elements
741741
WLSDPLY-06365=Adding {0} {1}
742742
WLSDPLY-06366={0} configuration for {1} {2} will not be discovered in online mode
743+
WLSDPLY-06367=Add JDBC Datasource DriverParams wallet based on property {0} into archive entry path {1}
744+
WLSDPLY-06368=Unable to collect wallet directory because the JDBC Datasource DriverParams connection property value {0} \
745+
is at ORACLE_HOME directory {1}.
746+
WLSDPLY-06369=Parent directory of JDBC Datasource DriverParams property value {0} is not a flat structure, only \
747+
individual file will be added to the wallet, other files that may exists in the original database wallet will not be \
748+
collected.
749+
WLSDPLY-06370=Datasource {0} JDBC Datasource DriverParams property {1} value {2} does not exist in the file system.
750+
WLSDPLY-06371=Remote discovery will not collect any JDBC Datasource DriverParams connection property that references \
751+
file or directory.
743752

744753
# deployments_discoverer.py
745754
WLSDPLY-06380=Discovering domain model deployments

integration-tests/system-test/src/test/java/oracle/weblogic/deploy/integration/BaseTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019, 2021, Oracle Corporation and/or its affiliates.
1+
// Copyright 2019, 2023, Oracle Corporation and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.deploy.integration;
@@ -33,6 +33,7 @@ public class BaseTest {
3333
protected static final String FS = File.separator;
3434
private static final String SAMPLE_ARCHIVE_FILE = "archive.zip";
3535
private static final String UPDATED_SAMPLE_ARCHIVE_FILE = "archive2.zip";
36+
private static final String WALLET_SAMPLE_ARCHIVE_FILE = "archive-jdbc.zip";
3637
private static final String WDT_ZIPFILE = "weblogic-deploy.zip";
3738
private static final String WDT_HOME_DIR = "weblogic-deploy";
3839
protected static final String SAMPLE_MODEL_FILE_PREFIX = "simple-topology";
@@ -49,6 +50,7 @@ public class BaseTest {
4950
protected static String validateModelScript = "";
5051
protected static String domainParentDir = "";
5152
protected static String prepareModelScript = "";
53+
protected static String archiveHelperScript = "";
5254
protected static final String ORACLE_DB_IMG = "phx.ocir.io/weblogick8s/database/enterprise";
5355
protected static final String ORACLE_DB_IMG_TAG = "12.2.0.1-slim";
5456
private static final String DB_CONTAINER_NAME = generateDatabaseContainerName();
@@ -90,6 +92,7 @@ protected static void initialize() {
9092
validateModelScript = getWDTScriptsHome() + FS + "validateModel.sh";
9193
compareModelScript = getWDTScriptsHome() + FS + "compareModel.sh";
9294
prepareModelScript = getWDTScriptsHome() + FS + "prepareModel.sh";
95+
archiveHelperScript = getWDTScriptsHome() + FS + "archiveHelper.sh";
9396

9497
domainParentDir = "." + FS + "target" + FS + "domains";
9598
}
@@ -208,6 +211,10 @@ protected static String getSampleArchiveFile() {
208211
return getTargetDir() + FS + SAMPLE_ARCHIVE_FILE;
209212
}
210213

214+
protected static String getSampleArchiveFileWithWallet() {
215+
return getTargetDir() + FS + WALLET_SAMPLE_ARCHIVE_FILE;
216+
}
217+
211218
protected static String getUpdatedSampleArchiveFile() {
212219
return getTargetDir() + FS + UPDATED_SAMPLE_ARCHIVE_FILE;
213220
}
@@ -216,6 +223,10 @@ protected static String getSampleModelFile(String suffix) {
216223
return getResourcePath() + FS + SAMPLE_MODEL_FILE_PREFIX + suffix + ".yaml";
217224
}
218225

226+
protected static String getSampleKeyStoreFile() {
227+
return getResourcePath() + FS + "cwallet.sso";
228+
}
229+
219230
protected static Path getInstallerTargetDir() {
220231
return Paths.get("..", "installer", "target");
221232
}

0 commit comments

Comments
 (0)