Skip to content

Commit a10912d

Browse files
committed
Merge branch 'server-template-kystore-fix' into 'main'
fixing missing method for discovering server/template keystores See merge request weblogic-cloud/weblogic-deploy-tooling!1795
2 parents 574c1c8 + ea08653 commit a10912d

File tree

7 files changed

+189
-21
lines changed

7 files changed

+189
-21
lines changed

core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/add/AddServerTemplateKeystoreCommand.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException;
1010
import oracle.weblogic.deploy.tool.archive_helper.CommandResponse;
1111
import oracle.weblogic.deploy.util.ExitCode;
12-
import oracle.weblogic.deploy.util.WLSDeployArchive;
1312
import oracle.weblogic.deploy.util.WLSDeployArchiveIOException;
1413
import picocli.CommandLine.Command;
1514
import picocli.CommandLine.Option;
@@ -52,14 +51,13 @@ public CommandResponse call() throws Exception {
5251
File sourceFile;
5352
try {
5453
sourceFile = initializeOptions(this.sourcePath);
55-
WLSDeployArchive.ArchiveEntryType archiveType = WLSDeployArchive.ArchiveEntryType.SERVER_TEMPLATE_KEYSTORE;
5654

5755
String resultName;
5856
if (this.overwrite) {
59-
resultName =
60-
this.archive.replaceSegregatedFile(archiveType, this.serverTemplateName, sourceFile.getName(), sourceFile.getPath());
57+
resultName = this.archive.replaceServerTemplateKeyStoreFile(this.serverTemplateName,
58+
sourceFile.getName(), sourceFile.getPath());
6159
} else {
62-
resultName = this.archive.addSegregatedFile(archiveType, this.serverTemplateName, sourceFile.getPath());
60+
resultName = this.archive.addServerTemplateKeyStoreFile(this.serverTemplateName, sourceFile.getPath());
6361
}
6462
response = new CommandResponse(ExitCode.OK, resultName);
6563
} catch (ArchiveHelperException ex) {

core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/extract/ExtractServerTemplateKeystoreCommand.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException;
1010
import oracle.weblogic.deploy.tool.archive_helper.CommandResponse;
1111
import oracle.weblogic.deploy.util.ExitCode;
12-
import oracle.weblogic.deploy.util.WLSDeployArchive;
1312
import oracle.weblogic.deploy.util.WLSDeployArchiveIOException;
1413
import picocli.CommandLine.Command;
1514
import picocli.CommandLine.Option;
@@ -51,8 +50,7 @@ public CommandResponse call() throws Exception {
5150
try {
5251
initializeOptions();
5352

54-
WLSDeployArchive.ArchiveEntryType archiveType = WLSDeployArchive.ArchiveEntryType.SERVER_TEMPLATE_KEYSTORE;
55-
this.archive.extractSegregatedFile(archiveType, this.serverTemplateName, this.name, this.targetDirectory);
53+
this.archive.extractServerTemplateKeystore(this.serverTemplateName, this.name, this.targetDirectory);
5654
response = new CommandResponse(ExitCode.OK, "WLSDPLY-30065", TYPE, this.name, this.serverTemplateName,
5755
this.archiveFilePath, this.targetDirectory.getPath());
5856
} catch (ArchiveHelperException ex) {

core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/list/ListServerTemplateKeystoreCommand.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public CommandResponse call() throws Exception {
4242
final String METHOD = "call";
4343
LOGGER.entering(CLASS, METHOD);
4444

45-
CommandResponse response = listType(SERVER_TEMPLATE_KEYSTORE, "server template keystore", this.serverTemplateName, this.name);
45+
CommandResponse response = listType(SERVER_TEMPLATE_KEYSTORE, "server template keystore",
46+
this.serverTemplateName, this.name);
4647

4748
LOGGER.exiting(CLASS, METHOD, response);
4849
return response;

core/src/main/java/oracle/weblogic/deploy/tool/archive_helper/remove/RemoveServerTemplateKeystoreCommand.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import oracle.weblogic.deploy.tool.archive_helper.ArchiveHelperException;
1010
import oracle.weblogic.deploy.tool.archive_helper.CommandResponse;
1111
import oracle.weblogic.deploy.util.ExitCode;
12-
import oracle.weblogic.deploy.util.WLSDeployArchive;
1312
import oracle.weblogic.deploy.util.WLSDeployArchiveIOException;
1413
import picocli.CommandLine.Command;
1514
import picocli.CommandLine.Option;
@@ -49,12 +48,11 @@ public CommandResponse call() throws Exception {
4948
try {
5049
initializeOptions();
5150

52-
WLSDeployArchive.ArchiveEntryType archiveType = WLSDeployArchive.ArchiveEntryType.SERVER_TEMPLATE_KEYSTORE;
5351
int entriesRemoved;
5452
if (this.force) {
55-
entriesRemoved = this.archive.removeSegregatedFile(archiveType, this.serverTemplateName, this.name, true);
53+
entriesRemoved = this.archive.removeServerTemplateKeystore(this.serverTemplateName, this.name, true);
5654
} else {
57-
entriesRemoved = this.archive.removeSegregatedFile(archiveType, this.serverTemplateName, this.name);
55+
entriesRemoved = this.archive.removeServerTemplateKeystore(this.serverTemplateName, this.name);
5856
}
5957
response = new CommandResponse(ExitCode.OK, "WLSDPLY-30067", TYPE, this.serverTemplateName, this.name,
6058
entriesRemoved, this.archiveFilePath);

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

+175-6
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ public int removeScript(String scriptPath, boolean silent) throws WLSDeployArchi
29932993
* @param keystoreFile the file to add
29942994
* @return the new location of the file to use in the model
29952995
* @throws WLSDeployArchiveIOException if an error occurs while archiving the file
2996-
* @throws IllegalArgumentException if the file does not exist or the clusterName is empty or null
2996+
* @throws IllegalArgumentException if the file does not exist or the serverTemplateName is empty or null
29972997
*/
29982998
public String addServerKeyStoreFile(String serverName, String keystoreFile) throws WLSDeployArchiveIOException {
29992999
final String METHOD = "addServerKeyStoreFile";
@@ -3147,6 +3147,175 @@ public int removeServerKeystore(String serverName, String keystoreName, boolean
31473147
return result;
31483148
}
31493149

3150+
///////////////////////////////////////////////////////////////////////////////////////////////
3151+
// server template keystore methods //
3152+
///////////////////////////////////////////////////////////////////////////////////////////////
3153+
3154+
/**
3155+
* Add a Server template keystore file to the server's directory in the archive.
3156+
*
3157+
* @param serverTemplateName the Server name used to segregate the directories
3158+
* @param keystoreFile the file to add
3159+
* @return the new location of the file to use in the model
3160+
* @throws WLSDeployArchiveIOException if an error occurs while archiving the file
3161+
* @throws IllegalArgumentException if the file does not exist or the serverTemplateName
3162+
* is empty or null
3163+
*/
3164+
public String addServerTemplateKeyStoreFile(String serverTemplateName, String keystoreFile)
3165+
throws WLSDeployArchiveIOException {
3166+
final String METHOD = "addServerTemplateKeyStoreFile";
3167+
LOGGER.entering(CLASS, METHOD, serverTemplateName, keystoreFile);
3168+
3169+
File filePath = new File(keystoreFile);
3170+
validateNonEmptyString(serverTemplateName, "serverTemplateName", METHOD);
3171+
validateExistingFile(filePath, "keyStoreFile", getArchiveFileName(), METHOD);
3172+
3173+
String newName =
3174+
addItemToZip(ARCHIVE_SERVER_TEMPLATE_TARGET_DIR + ZIP_SEP + serverTemplateName, filePath);
3175+
3176+
LOGGER.exiting(CLASS, METHOD, newName);
3177+
return newName;
3178+
}
3179+
3180+
/**
3181+
* Replace a Server template keystore in the archive.
3182+
*
3183+
* @param serverTemplateName the server template name used to segregate directories, or null if the keystorePath
3184+
* is includes the server name already (e.g., myserver/keystore.jks or
3185+
* wlsdeploy/servers/myserver/keystore.jks)
3186+
* @param keystorePath the keystore name (e.g., keystore.jks) or an archive path
3187+
* (e.g., mytemplate/keystore.jks or wlsdeploy/serverTemplates/mytemplate/keystore.jks)
3188+
* @param sourceLocation the file system location of the new keystore file to replace the existing one
3189+
* @return the archive path of the new server template keystore file
3190+
* @throws WLSDeployArchiveIOException if an IOException occurred while reading or writing changes
3191+
* @throws IllegalArgumentException if the file or directory passed in does not exist
3192+
*/
3193+
public String replaceServerTemplateKeyStoreFile(String serverTemplateName, String keystorePath, String sourceLocation)
3194+
throws WLSDeployArchiveIOException {
3195+
final String METHOD = "replaceServerTemplateKeyStoreFile";
3196+
LOGGER.entering(CLASS, METHOD, serverTemplateName, keystorePath, sourceLocation);
3197+
3198+
String archivePath = null;
3199+
String computedTemplateName = serverTemplateName;
3200+
if (keystorePath.startsWith(ARCHIVE_SERVER_TEMPLATE_TARGET_DIR + ZIP_SEP)) {
3201+
archivePath = keystorePath;
3202+
computedTemplateName = getSegregationNameFromSegregatedArchivePath(serverTemplateName, keystorePath);
3203+
} else if (!StringUtils.isEmpty(serverTemplateName)) {
3204+
if (keystorePath.startsWith(serverTemplateName + ZIP_SEP)) {
3205+
archivePath = ARCHIVE_SERVER_TEMPLATE_TARGET_DIR + ZIP_SEP + keystorePath;
3206+
} else {
3207+
archivePath = ARCHIVE_SERVER_TEMPLATE_TARGET_DIR + ZIP_SEP + serverTemplateName + ZIP_SEP + keystorePath;
3208+
}
3209+
}
3210+
3211+
if (StringUtils.isEmpty(computedTemplateName)) {
3212+
WLSDeployArchiveIOException ex =
3213+
new WLSDeployArchiveIOException("WLSDPLY-01478", keystorePath, sourceLocation);
3214+
LOGGER.throwing(CLASS, METHOD, ex);
3215+
throw ex;
3216+
}
3217+
3218+
// If we get here, archivePath should never be null!
3219+
//
3220+
getZipFile().removeZipEntry(archivePath);
3221+
String newName = addServerTemplateKeyStoreFile(computedTemplateName, sourceLocation);
3222+
3223+
LOGGER.exiting(CLASS, METHOD, newName);
3224+
return newName;
3225+
}
3226+
3227+
/**
3228+
* Extract the named server template's keystore file to the domain home location.
3229+
*
3230+
* @param serverTemplateName the name of the server template used to segregate the keystore
3231+
* @param keystoreName the name of the keystore file
3232+
* @param domainHome the existing directory location to write the file
3233+
* @throws WLSDeployArchiveIOException if an IOException occurred while reading the archive or writing the file
3234+
* @throws IllegalArgumentException if the domainHome directory does not exist or
3235+
* the serverTemplateName or keystoreName is empty
3236+
*/
3237+
public void extractServerTemplateKeystore(String serverTemplateName, String keystoreName, File domainHome)
3238+
throws WLSDeployArchiveIOException {
3239+
final String METHOD = "extractServerTemplateKeystore";
3240+
LOGGER.entering(CLASS, METHOD, serverTemplateName, keystoreName, domainHome);
3241+
3242+
validateNonEmptyString(serverTemplateName, "serverTemplateName", METHOD);
3243+
validateNonEmptyString(keystoreName, "keystoreName", METHOD);
3244+
validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD);
3245+
3246+
String archivePath;
3247+
if (keystoreName.startsWith(ARCHIVE_SERVER_TEMPLATE_TARGET_DIR + ZIP_SEP)) {
3248+
archivePath = keystoreName;
3249+
} else if (keystoreName.startsWith(serverTemplateName + ZIP_SEP)) {
3250+
archivePath = ARCHIVE_SERVER_TEMPLATE_TARGET_DIR + ZIP_SEP + keystoreName;
3251+
} else {
3252+
archivePath = ARCHIVE_SERVER_TEMPLATE_TARGET_DIR + ZIP_SEP + serverTemplateName + ZIP_SEP + keystoreName;
3253+
}
3254+
3255+
extractFileFromZip(archivePath, domainHome);
3256+
3257+
LOGGER.exiting(CLASS, METHOD);
3258+
}
3259+
3260+
/**
3261+
* Remove the named server template's keystore file from the archive file. If this is the only entry
3262+
* in the archive file directory, the directory entry will also be removed, if present.
3263+
*
3264+
* @param serverTemplateName the name of the server used to segregate the keystore
3265+
* @param keystoreName the name of the keystore file
3266+
* @return the number of zip entries removed from the archive
3267+
* @throws WLSDeployArchiveIOException if the server's keystore file is not present or an IOException
3268+
* occurred while reading the archive or writing the file
3269+
* @throws IllegalArgumentException if the serverTemplateName or keystoreName is null or empty
3270+
*/
3271+
public int removeServerTemplateKeystore(String serverTemplateName, String keystoreName)
3272+
throws WLSDeployArchiveIOException {
3273+
return removeServerTemplateKeystore(serverTemplateName, keystoreName, false);
3274+
}
3275+
3276+
/**
3277+
* Remove the named server template's keystore file from the archive file. If this is the only entry
3278+
* in the archive file directory, the directory entry will also be removed, if present.
3279+
*
3280+
* @param serverTemplateName the name of the server used to segregate the keystore
3281+
* @param keystoreName the name of the keystore file
3282+
* @param silent If false, a WLSDeployArchiveIOException is thrown is the named item does not exist
3283+
* @return the number of zip entries removed from the archive
3284+
* @throws WLSDeployArchiveIOException if the server's keystore file is not present (and silent = false) or
3285+
* an IOException occurred while reading the archive or writing the file
3286+
* @throws IllegalArgumentException if the serverTemplateName or keystoreName is null or empty
3287+
*/
3288+
public int removeServerTemplateKeystore(String serverTemplateName, String keystoreName, boolean silent)
3289+
throws WLSDeployArchiveIOException {
3290+
final String METHOD = "removeServerTemplateKeystore";
3291+
LOGGER.entering(CLASS, METHOD, serverTemplateName, keystoreName, silent);
3292+
3293+
validateNonEmptyString(serverTemplateName, "serverTemplateName", METHOD);
3294+
validateNonEmptyString(keystoreName, "keystoreName", METHOD);
3295+
3296+
String parentDir = ARCHIVE_SERVER_TEMPLATE_TARGET_DIR + ZIP_SEP + serverTemplateName;
3297+
String archivePath = parentDir + ZIP_SEP + keystoreName;
3298+
3299+
List<String> zipEntries =
3300+
getSegregatedArchiveEntries(ArchiveEntryType.SERVER_TEMPLATE_KEYSTORE, serverTemplateName, keystoreName);
3301+
3302+
if (!silent && zipEntries.isEmpty()) {
3303+
WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01479", serverTemplateName,
3304+
keystoreName, getArchiveFileName(), archivePath);
3305+
LOGGER.throwing(CLASS, METHOD, ex);
3306+
throw ex;
3307+
}
3308+
3309+
int result = zipEntries.size();
3310+
for (String zipEntry : zipEntries) {
3311+
getZipFile().removeZipEntry(zipEntry);
3312+
}
3313+
result += removeEmptyDirs(parentDir);
3314+
3315+
LOGGER.exiting(CLASS, METHOD, result);
3316+
return result;
3317+
}
3318+
31503319
///////////////////////////////////////////////////////////////////////////////////////////////
31513320
// node manager keystore methods //
31523321
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -3400,16 +3569,16 @@ public int removeMimeMappingFile(String mimeMappingPath, boolean silent)
34003569
validateNonEmptyString(mimeMappingPath, "mimeMappingPath", METHOD);
34013570

34023571
String archivePath;
3403-
String keystoreName;
3572+
String mimeFileName;
34043573
if (mimeMappingPath.startsWith(ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP)) {
34053574
archivePath = mimeMappingPath;
3406-
keystoreName = getNameFromPath(mimeMappingPath, ARCHIVE_CONFIG_TARGET_DIR.length() + 2);
3575+
mimeFileName = getNameFromPath(mimeMappingPath, ARCHIVE_CONFIG_TARGET_DIR.length() + 2);
34073576
} else {
34083577
archivePath = ARCHIVE_CONFIG_TARGET_DIR + ZIP_SEP + mimeMappingPath;
3409-
keystoreName = mimeMappingPath;
3578+
mimeFileName = mimeMappingPath;
34103579
}
34113580

3412-
List<String> zipEntries = getArchiveEntries(ArchiveEntryType.MIME_MAPPING, keystoreName);
3581+
List<String> zipEntries = getArchiveEntries(ArchiveEntryType.MIME_MAPPING, mimeFileName);
34133582

34143583
if (!silent && zipEntries.isEmpty()) {
34153584
WLSDeployArchiveIOException ex = new WLSDeployArchiveIOException("WLSDPLY-01452", mimeMappingPath,
@@ -5572,7 +5741,7 @@ protected static FileOrDirectoryType getFileType(ArchiveEntryType type) {
55725741
LOGGER.entering(CLASS, METHOD, type);
55735742

55745743
FileOrDirectoryType result;
5575-
switch(type) {
5744+
switch (type) {
55765745
case COHERENCE:
55775746
case COHERENCE_PERSISTENCE_DIR:
55785747
case DB_WALLET:

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,15 @@ def _add_server_keystore_file_to_archive(self, attribute_name, server_type, serv
970970
self.add_to_remote_map(file_path, new_name, archive_type.name())
971971
elif not self._model_context.is_skip_archive():
972972
try:
973-
974973
if self._model_context.is_ssh():
975974
file_path = self.download_deployment_from_remote_server(file_path, self.download_temporary_dir,
976975
"keyStoreFile-%s" % server_name)
977976

978977
archive_file = self._model_context.get_archive_file()
979-
new_name = archive_file.addArchiveTypeEntryFile(archive_type, server_name, file_path)
978+
if server_type == model_constants.SERVER_TEMPLATE:
979+
new_name = archive_file.addServerTemplateKeyStoreFile(server_name, file_path)
980+
else:
981+
new_name = archive_file.addServerKeyStoreFile(server_name, file_path)
980982
except IllegalArgumentException, iae:
981983
_logger.warning('WLSDPLY-06624', attribute_name, file_path, server_type, server_name,
982984
iae.getLocalizedMessage(), class_name=_class_name, method_name=_method_name, error=iae)

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

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ WLSDPLY-01474=Failed to read content for XACML role or path {0} at archive locat
267267
WLSDPLY-01475=Failed to read content for XACML policy or path {0} at archive location {1} in archive file {2} because the archive location does not exist.
268268
WLSDPLY-01476=Could not determine a valid archive path with an empty entry name and target path {0} to replace {1} file with {2}
269269
WLSDPLY-01477=Failed to remove {0} file {1} from archive file {2} because the archive file did not contain {3}
270+
WLSDPLY-01478=Could not determine a valid archive path with an empty server template name and keystore path {0} to replace the server template key store file with {1}
271+
WLSDPLY-01479=Failed to remove server template {0} keystore {1} from archive file {2} because the archive file did not contain {3}.
270272

271273
# oracle.weblogic.deploy.util.WLSDeployZipFile.java
272274
WLSDPLY-01500=The zip file {0} has the saved entry {1}

0 commit comments

Comments
 (0)