From 1afc4da10249c55c34ac0025170955f07459bbae Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Sun, 5 Mar 2023 10:15:54 -0600 Subject: [PATCH 1/2] correcting wallet handling across multiple archives to process the wallets in the right order --- .../deploy/util/WLSDeployArchive.java | 37 +++++++++++++++++++ .../wlsdeploy/tool/util/archive_helper.py | 37 ++++++++++++------- .../3.0/content/release-notes/_index.md | 1 + 3 files changed, 61 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index c53c30f4b9..f3a12bfd7d 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -13,9 +13,12 @@ import java.net.URL; import java.nio.file.Files; import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Set; import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.zip.ZipEntry; @@ -3698,6 +3701,40 @@ public int removeFileStoreDirectory(String fileStoreName, boolean silent) // database wallet methods // /////////////////////////////////////////////////////////////////////////////////////////////// + /** + * Get the list of database wallet names from the archive. + * + * @return the list of wallet names + * @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive + */ + public List getDatabaseWalletNames() throws WLSDeployArchiveIOException { + final String METHOD = "getDatabaseWalletNames"; + LOGGER.entering(CLASS, METHOD); + + // This is ugly because of the deprecated atpwallet location. + Set results = new HashSet<>(); + List zipEntries = getZipFile().listZipEntries(); + int prefixLength = ARCHIVE_DB_WALLETS_DIR.length() + 1; + for (String zipEntry : zipEntries) { + if (zipEntry.startsWith(OLD_ARCHIVE_ATP_WALLET_PATH)) { + LOGGER.finer("Adding deprecated atpwallet as {0}",DEFAULT_RCU_WALLET_NAME); + results.add(DEFAULT_RCU_WALLET_NAME); + } else if (zipEntry.startsWith(ARCHIVE_DB_WALLETS_DIR)) { + // skip over the wlsdeploy/dbWallets/ entry + if (zipEntry.length() <= prefixLength) { + continue; + } + + int walletNameDirectorySeparatorIndex = zipEntry.indexOf(ZIP_SEP, prefixLength); + String walletName = zipEntry.substring(prefixLength, walletNameDirectorySeparatorIndex); + LOGGER.finer("Adding wallet {0}", walletName); + results.add(walletName); + } + } + LOGGER.exiting(CLASS, METHOD, results); + return new ArrayList<>(results); + } + /** * Add a database wallet to the archive. * diff --git a/core/src/main/python/wlsdeploy/tool/util/archive_helper.py b/core/src/main/python/wlsdeploy/tool/util/archive_helper.py index 7acd296aea..72299e739c 100644 --- a/core/src/main/python/wlsdeploy/tool/util/archive_helper.py +++ b/core/src/main/python/wlsdeploy/tool/util/archive_helper.py @@ -384,14 +384,17 @@ def extract_database_wallet(self, wallet_name=WLSDeployArchive.DEFAULT_RCU_WALLE :raises: BundleAwareException of the appropriate type: if an error occurs """ _method_name = 'extract_database_wallet' - self.__logger.entering(class_name=self.__class_name, method_name=_method_name) + self.__logger.entering(wallet_name, class_name=self.__class_name, method_name=_method_name) resulting_wallet_path = None - for archive_file in self.__archive_files[::-1]: + for archive_file in self.__archive_files: wallet_path = archive_file.extractDatabaseWallet(self.__domain_home, wallet_name) # Allow iteration to continue through all archive files but # make sure to store off the path for a wallet that was extracted. # + self.__logger.finer('extract wallet {0} from archive file {1} returned wallet path {2}', + wallet_name, archive_file.getArchiveFileName(), wallet_path, + class_name=self.__class_name, method_name=_method_name) if wallet_path is not None: # If multiple archives contain the same named wallet, they # will all have the same path. @@ -402,19 +405,25 @@ def extract_database_wallet(self, wallet_name=WLSDeployArchive.DEFAULT_RCU_WALLE return resulting_wallet_path def extract_all_database_wallets(self): + _method_name = 'extract_all_database_wallets' + self.__logger.entering(class_name=self.__class_name, method_name=_method_name) + + # extract_database_wallet() loops through the archive files so just collect + # the list of wallet names from the archive files and then loop through that list. + wallet_names = sets.Set() for archive_file in self.__archive_files: - archive_entries = archive_file.getArchiveEntries() - wallet_names = sets.Set() - for entry in archive_entries: - if entry.startswith(WLSDeployArchive.ARCHIVE_DB_WALLETS_DIR): - if os.path.isdir(entry): - wallet_names.add(os.path.basename(entry)) - else: - name = os.path.basename(os.path.dirname(entry)) - wallet_names.add(name) - for wallet_name in wallet_names: - self.extract_database_wallet(wallet_name) + self.__logger.finer('processing archive_file {0}', archive_file.getArchiveFileName(), + class_name=self.__class_name, method_name=_method_name) + archive_wallet_names = archive_file.getDatabaseWalletNames() + wallet_names.update(archive_wallet_names) + + for wallet_name in wallet_names: + self.__logger.finer('extracting database wallet {0}', wallet_name, + class_name=self.__class_name, method_name=_method_name) + self.extract_database_wallet(wallet_name) + + self.__logger.exiting(class_name=self.__class_name, method_name=_method_name) def extract_opss_wallet(self): """ @@ -426,7 +435,7 @@ def extract_opss_wallet(self): self.__logger.entering(class_name=self.__class_name, method_name=_method_name) resulting_wallet_path = None - for archive_file in self.__archive_files[::-1]: + for archive_file in self.__archive_files: wallet_path = archive_file.extractOPSSWallet(self.__domain_home) # Allow iteration to continue through all archive files but # make sure to store off the path for a wallet that was extracted. diff --git a/documentation/3.0/content/release-notes/_index.md b/documentation/3.0/content/release-notes/_index.md index 177c1323bb..5f90b33593 100644 --- a/documentation/3.0/content/release-notes/_index.md +++ b/documentation/3.0/content/release-notes/_index.md @@ -22,6 +22,7 @@ None #### Bug Fixes - #1405: Corrected some issues with the Windows shell scripts where they were not properly handling paths with spaces. - #1409: Corrected a bug where a wallet deprecation message was still being logged as a warning. +- #1411: Corrected a bug where wallet extraction handling with multiple archive files was happening in the wrong order. #### Known Issues 1. When running `discoverDomain` with the `-remote` flag, there are several MBeans that are not being properly handled that From 7275d6a32a87505483578027cae013e837f95cbc Mon Sep 17 00:00:00 2001 From: Robert Patrick Date: Sun, 5 Mar 2023 11:10:01 -0600 Subject: [PATCH 2/2] enhancing error handling --- .../oracle/weblogic/deploy/util/WLSDeployArchive.java | 8 ++++++++ .../weblogic/deploy/messages/wlsdeploy_rb.properties | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java index f3a12bfd7d..1bb678273f 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java @@ -3726,11 +3726,19 @@ public List getDatabaseWalletNames() throws WLSDeployArchiveIOException } int walletNameDirectorySeparatorIndex = zipEntry.indexOf(ZIP_SEP, prefixLength); + if (walletNameDirectorySeparatorIndex == -1) { + WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01460", + getArchiveFileName(), zipEntry); + LOGGER.throwing(CLASS, METHOD, ex); + throw ex; + } String walletName = zipEntry.substring(prefixLength, walletNameDirectorySeparatorIndex); + LOGGER.finer("Adding wallet {0}", walletName); results.add(walletName); } } + LOGGER.exiting(CLASS, METHOD, results); return new ArrayList<>(results); } 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 6bda3696bd..d5ac78c885 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 @@ -234,7 +234,7 @@ WLSDPLY-01456=Failed to remove File Store {0} from archive file {1} because the WLSDPLY-01457=Failed to remove database wallet {0} from archive file {1} because the archive file did not contain {2}. WLSDPLY-01458=Failed to remove OPSS wallet from archive file {0} because the archive file did not contain {1}. WLSDPLY-01459=Failed to add RCU Wallet to archive because the archive file {0} already contains an RCU wallet with {1} entries. - +WLSDPLY-01460=Failed to get the database wallet names from archive file {0} because the archive contains an invalid database wallet entry at {1} # oracle.weblogic.deploy.util.WLSDeployZipFile.java WLSDPLY-01500=The zip file {0} has the saved entry {1}