modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/DeploymentUnitType.java | 14 - modules/core/util/src/main/java/org/rhq/core/util/updater/DeploymentProperties.java | 20 ++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java | 5 modules/plugins/ant-bundle/src/main/java/org/rhq/plugins/ant/AntBundlePluginComponent.java | 97 +++++++--- 4 files changed, 104 insertions(+), 32 deletions(-)
New commits: commit f149eacf6233511341a81b1c6b67b8754217da2f Author: John Mazzitelli mazz@redhat.com Date: Mon Jan 24 17:33:08 2011 -0500
don't blindly remove the full deploy dir if we were told not to fully manage the deploy dir this is to support ear/war bundle deployment into a jboss-as deploy/ dir
diff --git a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/DeploymentUnitType.java b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/DeploymentUnitType.java index 162ba4d..189c420 100644 --- a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/DeploymentUnitType.java +++ b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/DeploymentUnitType.java @@ -102,6 +102,13 @@ public class DeploymentUnitType extends AbstractBundleType {
try { boolean dryRun = getProject().isDryRun(); + boolean willManageRootDir = Boolean.parseBoolean(this.manageRootDir); + File deployDir = getProject().getDeployDir(); + TemplateEngine templateEngine = createTemplateEngine(); + int deploymentId = getProject().getDeploymentId(); + DeploymentProperties deploymentProps = new DeploymentProperties(deploymentId, getProject().getBundleName(), + getProject().getBundleVersion(), getProject().getBundleDescription()); + deploymentProps.setManageRootDir(willManageRootDir);
if (this.preinstallTarget != null) { getProject().auditLog(AuditStatus.SUCCESS, "Pre-Install Started", "The pre install target will start", @@ -126,12 +133,6 @@ public class DeploymentUnitType extends AbstractBundleType { "The pre install target has finished", null, null); }
- int deploymentId = getProject().getDeploymentId(); - DeploymentProperties deploymentProps = new DeploymentProperties(deploymentId, getProject().getBundleName(), - getProject().getBundleVersion(), getProject().getBundleDescription()); - File deployDir = getProject().getDeployDir(); - TemplateEngine templateEngine = createTemplateEngine(); - boolean haveSomethingToDo = false; if (!this.files.isEmpty()) { haveSomethingToDo = true; @@ -154,7 +155,6 @@ public class DeploymentUnitType extends AbstractBundleType { "You must specify at least one file to deploy via nested file, archive, url-file, url-archive types in your recipe"); }
- boolean willManageRootDir = Boolean.parseBoolean(this.manageRootDir); if (willManageRootDir) { log("Managing the root directory of this deployment unit - unrelated files found will be removed", Project.MSG_VERBOSE); diff --git a/modules/core/util/src/main/java/org/rhq/core/util/updater/DeploymentProperties.java b/modules/core/util/src/main/java/org/rhq/core/util/updater/DeploymentProperties.java index c476988..3553413 100644 --- a/modules/core/util/src/main/java/org/rhq/core/util/updater/DeploymentProperties.java +++ b/modules/core/util/src/main/java/org/rhq/core/util/updater/DeploymentProperties.java @@ -34,11 +34,15 @@ import java.util.Properties; public class DeploymentProperties extends Properties { private static final long serialVersionUID = 1L;
+ // required properties that must always exist private static final String DEPLOYMENT_ID = "deployment.id"; private static final String BUNDLE_NAME = "bundle.name"; private static final String BUNDLE_VERSION = "bundle.version"; private static final String BUNDLE_DESCRIPTION = "bundle.description";
+ // optional properties + private static final String MANAGE_ROOT_DIR = "manage.root.dir"; + public static DeploymentProperties loadFromFile(File file) throws Exception { DeploymentProperties props = new DeploymentProperties(); FileInputStream is = new FileInputStream(file); @@ -190,4 +194,20 @@ public class DeploymentProperties extends Properties { setProperty(BUNDLE_DESCRIPTION, description); } } + + /** + * @return the flag to indicate if the entire root directory content is to be managed. + * If there is no property, this method returns a default of <code>true</code> + */ + public boolean getManageRootDir() { + String str = getProperty(MANAGE_ROOT_DIR); + if (str == null) { + return true; + } + return Boolean.parseBoolean(str); + } + + public void setManageRootDir(boolean willManageRootDir) { + setProperty(MANAGE_ROOT_DIR, Boolean.toString(willManageRootDir)); + } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java index 71d5e06..da52896 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/destination/BundleDestinationView.java @@ -218,8 +218,9 @@ public class BundleDestinationView extends LocatableVLayout implements Bookmarka CoreGUI.getMessageCenter().notify( new Message(MSG.view_bundle_dest_purgeSuccessful(destination.getName()), Message.Severity.Info)); - // Bundle destination is purged, go back to bundle destinations root view - CoreGUI.goToView(LinkManager.getBundleDestinationLink(bundle.getId(), 0), true); + // Bundle destination is purged, go back to bundle destination view + CoreGUI.goToView(LinkManager.getBundleDestinationLink(bundle.getId(), destination + .getId()), true); } }); } diff --git a/modules/plugins/ant-bundle/src/main/java/org/rhq/plugins/ant/AntBundlePluginComponent.java b/modules/plugins/ant-bundle/src/main/java/org/rhq/plugins/ant/AntBundlePluginComponent.java index 817b647..201d212 100644 --- a/modules/plugins/ant-bundle/src/main/java/org/rhq/plugins/ant/AntBundlePluginComponent.java +++ b/modules/plugins/ant-bundle/src/main/java/org/rhq/plugins/ant/AntBundlePluginComponent.java @@ -180,67 +180,118 @@ public class AntBundlePluginComponent implements ResourceComponent, BundleFacet String deployDirAbsolutePath = deployDir.getAbsolutePath(); BundleManagerProvider bundleManagerProvider = request.getBundleManagerProvider();
+ boolean manageAllDeployDir = true; + boolean errorPurgingDeployDirContent = false; + File metadataDirectoryToPurge = null; + // If the receipe copied file(s) outside of the deployment directory (external, raw files), they will still exist. // Let's get the metadata information that tells us if such files exist, and if so, remove them. + // Since we are iterating over the manage files anyway, let's also remove the files/subdirs under the deploy directory too. DeploymentsMetadata metadata = new DeploymentsMetadata(deployDir); if (metadata.isManaged()) { + metadataDirectoryToPurge = metadata.getMetadataDirectory(); + manageAllDeployDir = metadata.getCurrentDeploymentProperties().getManageRootDir(); int totalExternalFiles = 0; - ArrayList<String> deleteSuccesses = new ArrayList<String>(0); - ArrayList<String> deleteFailures = new ArrayList<String>(0); - FileHashcodeMap fileHashcodes = metadata.getCurrentDeploymentFileHashcodes(); - for (String filePath : fileHashcodes.keySet()) { + ArrayList<String> externalDeleteSuccesses = new ArrayList<String>(0); + ArrayList<String> externalDeleteFailures = new ArrayList<String>(0); + FileHashcodeMap deployDirFileHashcodes = metadata.getCurrentDeploymentFileHashcodes(); + for (String filePath : deployDirFileHashcodes.keySet()) { File file = new File(filePath); if (file.isAbsolute()) { totalExternalFiles++; if (file.exists()) { if (file.delete()) { - deleteSuccesses.add(filePath); + externalDeleteSuccesses.add(filePath); } else { - deleteFailures.add(filePath); + externalDeleteFailures.add(filePath); } } else { - deleteSuccesses.add(filePath); // someone already deleted it, consider it removed successfully + externalDeleteSuccesses.add(filePath); // someone already deleted it, consider it removed successfully + } + } else { + // a relative path means it is inside the deploy dir (i.e. its relative to deployDir). + // note that we only remove child directories and files that are direct children of the deploy dir itself; + // we do not purge the deploy dir itself, in case we are not managing the full deploy dir. + String parentDir = file.getParent(); + if (parentDir == null) { + // this file is directly in the deploy dir + file = new File(deployDir, filePath); + file.delete(); + } else { + // this file is under some subdirectory under the deploy dir - purge the subdirectory completely + file = new File(deployDir, parentDir); + FileUtil.purge(file, true); + } + if (file.exists()) { + errorPurgingDeployDirContent = true; } } } if (totalExternalFiles > 0) { - if (!deleteSuccesses.isEmpty()) { + if (!externalDeleteSuccesses.isEmpty()) { StringBuilder deleteSuccessesDetails = new StringBuilder(); - for (String path : deleteSuccesses) { + for (String path : externalDeleteSuccesses) { deleteSuccessesDetails.append(path).append("\n"); } bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", "External files were purged", - Category.AUDIT_MESSAGE, Status.SUCCESS, "[" + deleteSuccesses.size() + "] of [" + Category.AUDIT_MESSAGE, Status.SUCCESS, "[" + externalDeleteSuccesses.size() + "] of [" + totalExternalFiles + "] external files were purged. See attached details for the list", deleteSuccessesDetails.toString()); } - if (!deleteFailures.isEmpty()) { + if (!externalDeleteFailures.isEmpty()) { StringBuilder deleteFailuresDetails = new StringBuilder(); - for (String path : deleteFailures) { + for (String path : externalDeleteFailures) { deleteFailuresDetails.append(path).append("\n"); } bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", "External files failed to be purged", Category.AUDIT_MESSAGE, Status.FAILURE, "[" - + deleteFailures.size() + "] of [" + totalExternalFiles + + externalDeleteFailures.size() + "] of [" + totalExternalFiles + "] external files failed to be purged. See attached details for the list", deleteFailuresDetails.toString()); } } }
- // completely purge the deployment directory. - FileUtil.purge(deployDir, true); - - if (!deployDir.exists()) { - bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", - "The destination directory has been purged", Category.AUDIT_MESSAGE, Status.SUCCESS, - "Directory purged: " + deployDirAbsolutePath, null); + // if we are managing the full deploy dir, completely purge the deployment directory. + // otherwise, just report that we deleted what we were responsible for. + if (manageAllDeployDir) { + FileUtil.purge(deployDir, true); + if (!deployDir.exists()) { + bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", + "The destination directory has been purged", Category.AUDIT_MESSAGE, Status.SUCCESS, + "Directory purged: " + deployDirAbsolutePath, null); + } else { + bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", + "The destination directory failed to be purged", Category.AUDIT_MESSAGE, Status.FAILURE, + "The directory that failed to be purged: " + deployDirAbsolutePath, null); + } } else { - bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", - "The destination directory failed to be purged", Category.AUDIT_MESSAGE, Status.FAILURE, - "The directory that failed to be purged: " + deployDirAbsolutePath, null); + if (!errorPurgingDeployDirContent) { + bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", + "The managed bundle content was removed from the destination directory; " + + "other unmanaged content may still remain", Category.AUDIT_MESSAGE, Status.SUCCESS, + "Deploy Directory: " + deployDirAbsolutePath, null); + } else { + bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", + "Not all managed bundle content was able to be removed from the destination directory. " + + "That managed content along with other unmanaged content still remain", + Category.AUDIT_MESSAGE, Status.FAILURE, "Deploy Directory: " + deployDirAbsolutePath, null); + } + + // make sure we remove the metadata directory, too - since it may still have sensitive files that were backed up + if (metadataDirectoryToPurge != null) { + FileUtil.purge(metadataDirectoryToPurge, true); + if (metadataDirectoryToPurge.exists()) { + bundleManagerProvider.auditDeployment(deploymentToPurge, "Purge", + "Failed to purge the metadata directory from the destination directory. " + + "It may still contain backed up files from previous bundle deployments.", + Category.AUDIT_MESSAGE, Status.FAILURE, "Metadata Directory: " + + metadataDirectoryToPurge.getAbsolutePath(), null); + } + } } + } catch (Throwable t) { log.error("Failed to purge bundle [" + request + "]", t); result.setErrorMessage(t);
rhq-commits@lists.fedorahosted.org