-
Notifications
You must be signed in to change notification settings - Fork 90
Wdt 1112 appfileoverrides #1149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0d69afa
copy correct location into plan.xml
CarolynRountree 7559491
Merge branch 'main' into WDT-1112-appfileoverrides
CarolynRountree 2f55f41
remote paths fixed
CarolynRountree 1048129
fix non-remote names
CarolynRountree 0f3c814
fix code smells for sonar
CarolynRountree 1172333
fix code smells for sonar
CarolynRountree 3e633b7
requested fixes
CarolynRountree 3bcc34c
remove some duplicate lines
CarolynRountree d6d10bb
fixes for PR requests
CarolynRountree ddfb493
fixes for PR requests
CarolynRountree 0252195
fix broken system test
CarolynRountree File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,12 @@ public class WLSDeployArchive { | |
*/ | ||
public static final String ARCHIVE_APPS_TARGET_DIR = WLSDPLY_ARCHIVE_BINARY_DIR + "/applications"; | ||
|
||
/** | ||
* Top-level archive subdirectory where the applications are stored and the subdirectory to which | ||
* they will be extracted. This is for structured applications found under /app | ||
*/ | ||
public static final String ARCHIVE_APPS_FOLD_TARGET_DIR = WLSDPLY_ARCHIVE_BINARY_DIR + "/application_folder"; | ||
|
||
/** | ||
* Top-level archive subdirectory where the shared libraries are stored and the subdirectory to | ||
* which they will be extracted. | ||
|
@@ -573,6 +579,17 @@ public String getApplicationArchivePath(String appPath) { | |
return getArchiveName(ARCHIVE_APPS_TARGET_DIR, appPath); | ||
} | ||
|
||
/** | ||
* Get the archive path for the application in a well-formed application directory | ||
* @param appPath name of the application path | ||
* @return archive path for use in the model | ||
*/ | ||
public String getApplicationDirectoryArchivePath(String appName, String appPath) { | ||
File zipAppPath = new File(appPath).getParentFile(); | ||
File zipAppFile = new File(appPath); | ||
return ARCHIVE_APPS_FOLD_TARGET_DIR + "/" + appName + "/" + zipAppPath.getName() + "/" + zipAppFile.getName(); | ||
} | ||
|
||
/** | ||
* This method adds an application to the archive. If an application with the same name already exists, this | ||
* method assumes that the new one also needs to be added so it changes the name to prevent conflicts by adding | ||
|
@@ -590,13 +607,41 @@ public String addApplication(String appPath) throws WLSDeployArchiveIOException | |
LOGGER.entering(CLASS, METHOD, appPath); | ||
|
||
File filePath = new File(appPath); | ||
|
||
validateExistingFile(filePath, "appPath", getArchiveFileName(), METHOD, true); | ||
|
||
String newName = addItemToZip(ARCHIVE_APPS_TARGET_DIR, filePath); | ||
LOGGER.exiting(CLASS, METHOD, newName); | ||
return newName; | ||
} | ||
|
||
public String addApplicationFolder(String appName, String appPath) | ||
throws WLSDeployArchiveIOException { | ||
final String METHOD = "addApplicationFolder"; | ||
LOGGER.entering(CLASS, METHOD, appName, appPath); | ||
File zipPath = new File(appPath); | ||
if (zipPath.getParentFile() != null) | ||
{ | ||
CarolynRountree marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
zipPath = zipPath.getParentFile(); | ||
} | ||
String firstprefix = ARCHIVE_APPS_FOLD_TARGET_DIR + "/" + appName + "/" + zipPath.getName(); | ||
String newName = walkDownFolders(firstprefix, zipPath); | ||
LOGGER.exiting(CLASS, METHOD, newName); | ||
return newName; | ||
} | ||
|
||
public String addApplicationPlanFolder(String appName, String planDir) | ||
throws WLSDeployArchiveIOException { | ||
final String METHOD = "addApplicationPathFolder"; | ||
LOGGER.entering(CLASS, METHOD, appName, planDir); | ||
File zipPlan = new File(planDir); | ||
String zipprefix = ARCHIVE_APPS_FOLD_TARGET_DIR + "/" + appName + "/" + zipPlan.getName(); | ||
CarolynRountree marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
String newName = walkDownFolders(zipprefix, zipPlan); | ||
|
||
LOGGER.exiting(CLASS, METHOD, newName); | ||
return zipprefix; | ||
} | ||
|
||
/** | ||
* Get the list of application names in the archive. | ||
* | ||
|
@@ -671,11 +716,13 @@ public void extractApplication(String applicationPath, File domainHome) throws W | |
validateExistingDirectory(domainHome, "domainHome", getArchiveFileName(), METHOD); | ||
|
||
String appPath = applicationPath; | ||
if (!applicationPath.startsWith(ARCHIVE_APPS_TARGET_DIR)) { | ||
if (!applicationPath.startsWith(ARCHIVE_APPS_FOLD_TARGET_DIR) && | ||
!applicationPath.startsWith(ARCHIVE_APPS_TARGET_DIR)) { | ||
|
||
appPath = ARCHIVE_APPS_TARGET_DIR + ZIP_SEP + applicationPath; | ||
} | ||
extractFileFromZip(appPath, domainHome); | ||
LOGGER.exiting(CLASS, METHOD); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -1007,6 +1054,18 @@ public String getApplicationPlanArchivePath(String planFile) { | |
return getArchiveName(ARCHIVE_APPS_TARGET_DIR, planFile); | ||
} | ||
|
||
/** | ||
* Get the archive path of a well formed plan directory in app directory, | ||
* | ||
* @param appName The application name of the app directory | ||
* @param planDir The deployment plan file directory | ||
* @return Archive path for use in the model | ||
*/ | ||
public String getApplicationPlanDirArchivePath(String appName, String planDir) { | ||
File zipPath = new File(planDir); | ||
return ARCHIVE_APPS_FOLD_TARGET_DIR + "/" + appName + "/" + zipPath.getName(); | ||
} | ||
|
||
/** | ||
* Adds an application's deployment plan file to the archive. | ||
* | ||
|
@@ -1441,7 +1500,6 @@ protected String addItemToZip(String zipPathPrefix, File itemToAdd, boolean useF | |
|
||
LOGGER.entering(CLASS, METHOD, zipPathPrefix, itemToAdd.getAbsolutePath(), useFileNameInEntryPath); | ||
String newName = getArchiveName(zipPathPrefix, itemToAdd.getName(), useFileNameInEntryPath); | ||
|
||
if (itemToAdd.isDirectory()) { | ||
if (!newName.endsWith(ZIP_SEP)) { | ||
newName += ZIP_SEP; | ||
|
@@ -1819,4 +1877,17 @@ private static FileInputStream getFileInputStream(File f, String itemName, Strin | |
return inputStream; | ||
} | ||
|
||
private String walkDownFolders(String zipprefix, File zipPath) throws WLSDeployArchiveIOException { | ||
String newSourceName = null; | ||
if (zipPath != null) { | ||
for (File item : zipPath.listFiles()) { | ||
newSourceName = addItemToZip(zipprefix, item); | ||
if (item.isDirectory()) { | ||
walkDownFolders(zipprefix + "/" + item.getName(), item); | ||
} | ||
} | ||
} | ||
return newSourceName; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,18 @@ | |
import os | ||
from java.io import File | ||
from java.io import IOException | ||
from java.io import FileOutputStream | ||
from java.security import NoSuchAlgorithmException | ||
from javax.xml.parsers import DocumentBuilderFactory | ||
from javax.xml.transform import OutputKeys | ||
from javax.xml.transform import TransformerFactory | ||
from javax.xml.transform.dom import DOMSource | ||
from javax.xml.transform.stream import StreamResult | ||
|
||
import oracle.weblogic.deploy.util.FileUtils as FileUtils | ||
import oracle.weblogic.deploy.util.PyOrderedDict as OrderedDict | ||
from oracle.weblogic.deploy.util import WLSDeployArchive | ||
|
||
from wlsdeploy.aliases import alias_utils | ||
from wlsdeploy.aliases import model_constants | ||
from wlsdeploy.aliases.location_context import LocationContext | ||
|
@@ -21,6 +29,7 @@ | |
from wlsdeploy.aliases.model_constants import DEPLOYMENT_ORDER | ||
from wlsdeploy.aliases.model_constants import LIBRARY | ||
from wlsdeploy.aliases.model_constants import PARTITION | ||
from wlsdeploy.aliases.model_constants import PLAN_DIR | ||
from wlsdeploy.aliases.model_constants import PLAN_PATH | ||
from wlsdeploy.aliases.model_constants import PLAN_STAGING_MODE | ||
from wlsdeploy.aliases.model_constants import RESOURCES | ||
|
@@ -183,6 +192,7 @@ def __add_applications(self): | |
self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name) | ||
raise ex | ||
|
||
|
||
application_name = \ | ||
self.version_helper.get_application_versioned_name(app_source_path, application_name) | ||
|
||
|
@@ -193,6 +203,11 @@ def __add_applications(self): | |
deployer_utils.create_and_cd(application_location, existing_applications, self.aliases) | ||
self._set_attributes_and_add_subfolders(application_location, application) | ||
application_location.remove_name_token(application_token) | ||
|
||
if app_source_path.startswith(WLSDeployArchive.ARCHIVE_APPS_FOLD_TARGET_DIR): | ||
plan_dir = dictionary_utils.get_element(application, PLAN_DIR) | ||
self._fix_plan_file(plan_dir) | ||
|
||
self.logger.exiting(class_name=self._class_name, method_name=_method_name) | ||
|
||
def __online_deploy_apps_and_libs(self, base_location): | ||
|
@@ -628,6 +643,10 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, s | |
if param in app_dict: | ||
self.model_context.replace_tokens(APPLICATION, app, param, app_dict) | ||
|
||
if param == SOURCE_PATH and param.startswith(WLSDeployArchive.ARCHIVE_APPS_FOLD_TARGET_DIR): | ||
plan_dir = dictionary_utils.get_element(app, PLAN_DIR) | ||
self._fix_plan_file(plan_dir) | ||
|
||
if model_helper.is_delete_name(app): | ||
if self.__verify_delete_versioned_app(app, existing_apps, 'app'): | ||
# remove the !app from the model | ||
|
@@ -933,7 +952,6 @@ def __deploy_model_applications(self, model_apps, app_location, deployed_applist | |
path = app_dict[uses_path_tokens_attribute_name] | ||
if deployer_utils.is_path_into_archive(path): | ||
self.__extract_source_path_from_archive(path, APPLICATION, app_name) | ||
|
||
location.add_name_token(token_name, app_name) | ||
resource_group_template_name, resource_group_name, partition_name = \ | ||
self.__get_mt_names_from_location(location) | ||
|
@@ -1105,6 +1123,32 @@ def __get_deployment_ordering(self, apps): | |
class_name=self._class_name, method_name=_method_name) | ||
return result_deploy_order | ||
|
||
def _fix_plan_file(self, plan_dir): | ||
#self.archive_helper.extract_directory(plan_dir) | ||
plan_file = os.path.join(self.model_context.get_domain_home(), plan_dir, "plan.xml") | ||
dbf = DocumentBuilderFactory.newInstance() | ||
db = dbf.newDocumentBuilder() | ||
document = db.parse(File(plan_file)) | ||
document.normalizeDocument() | ||
elements = document.getElementsByTagName("config-root") | ||
|
||
if elements is not None and elements.getLength() > 0: | ||
element = elements.item(0) | ||
element.setNodeValue(plan_dir) | ||
element.setTextContent(plan_dir) | ||
# document.appendChild(element) | ||
|
||
|
||
#new_element.setAttribute("config-root") | ||
ostream = FileOutputStream(plan_file) | ||
transformer_factory = TransformerFactory.newInstance() | ||
transformer = transformer_factory.newTransformer() | ||
transformer.setOutputProperty(OutputKeys.INDENT, "yes") | ||
transformer.setOutputProperty(OutputKeys.STANDALONE, "no") | ||
source = DOMSource(document) | ||
result = StreamResult(ostream) | ||
|
||
transformer.transform(source, result) | ||
|
||
def __start_all_apps(self, deployed_app_list, base_location): | ||
|
||
temp_app_dict = OrderedDict() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.