// specified.
if (packages.size() != 1) {
log
.warn("Request to update a VDB file contained multiple packages: " //$NON-NLS-1$
+ packages);
DeployPackagesResponse response = new DeployPackagesResponse(
ContentResponseResult.FAILURE);
response
.setOverallRequestErrorMessage("When updating a VDB, only one VDB can be updated at a time."); //$NON-NLS-1$
return response;
}
ResourcePackageDetails packageDetails = packages.iterator().next();
log.debug("Updating VDB file '" + this.deploymentFile + "' using [" //$NON-NLS-1$ //$NON-NLS-2$
+ packageDetails + "]..."); //$NON-NLS-1$
log.debug("Writing new VDB bits to temporary file..."); //$NON-NLS-1$
File tempFile;
try {
tempFile = writeNewAppBitsToTempFile(contentServices,
packageDetails);
} catch (Exception e) {
return failApplicationDeployment(
"Error writing new application bits to temporary file - cause: " //$NON-NLS-1$
+ e, packageDetails);
}
log.debug("Wrote new VDB bits to temporary file '" + tempFile //$NON-NLS-1$
+ "'."); //$NON-NLS-1$
boolean deployExploded = this.deploymentFile.isDirectory();
// Backup the original app file/dir to <filename>.rej.
File backupOfOriginalFile = new File(this.deploymentFile.getPath()
+ BACKUP_FILE_EXTENSION);
log.debug("Backing up existing VDB '" + this.deploymentFile //$NON-NLS-1$
+ "' to '" + backupOfOriginalFile + "'..."); //$NON-NLS-1$ //$NON-NLS-2$
try {
if (backupOfOriginalFile.exists())
FileUtils.forceDelete(backupOfOriginalFile);
if (this.deploymentFile.isDirectory())
FileUtils.copyDirectory(this.deploymentFile,
backupOfOriginalFile, true);
else
FileUtils.copyFile(this.deploymentFile, backupOfOriginalFile,
true);
} catch (Exception e) {
throw new RuntimeException("Failed to backup existing EAR/WAR '" //$NON-NLS-1$
+ this.deploymentFile + "' to '" + backupOfOriginalFile //$NON-NLS-1$
+ "'."); //$NON-NLS-1$
}
// Now stop the original app.
try {
DeploymentManager deploymentManager = getConnection()
.getDeploymentManager();
DeploymentProgress progress = deploymentManager
.stop(this.deploymentUrl);
DeploymentUtils.run(progress);
} catch (Exception e) {
throw new RuntimeException("Failed to stop deployment [" //$NON-NLS-1$
+ this.deploymentUrl + "].", e); //$NON-NLS-1$
}
// And then remove it (this will delete the physical file/dir from the
// deploy dir).
try {
DeploymentManager deploymentManager = getConnection()
.getDeploymentManager();
DeploymentProgress progress = deploymentManager
.remove(this.deploymentUrl);
DeploymentUtils.run(progress);
} catch (Exception e) {
throw new RuntimeException("Failed to remove deployment [" //$NON-NLS-1$
+ this.deploymentUrl + "].", e); //$NON-NLS-1$
}
// Deploy away!
log.debug("Deploying '" + tempFile + "'..."); //$NON-NLS-1$ //$NON-NLS-2$
DeploymentManager deploymentManager = getConnection()
.getDeploymentManager();
try {
DeploymentUtils.deployArchive(deploymentManager, tempFile,
deployExploded);
} catch (Exception e) {
// Deploy failed - rollback to the original app file...
log.debug("Redeploy failed - rolling back to original archive...", //$NON-NLS-1$
e);
String errorMessage = ThrowableUtil.getAllMessages(e);
try {
// Delete the new app, which failed to deploy.
FileUtils.forceDelete(this.deploymentFile);
// Need to re-deploy the original file - this generally should
// succeed.
DeploymentUtils.deployArchive(deploymentManager,
backupOfOriginalFile, deployExploded);
errorMessage += " ***** ROLLED BACK TO ORIGINAL APPLICATION FILE. *****"; //$NON-NLS-1$
} catch (Exception e1) {
log.debug("Rollback failed!", e1); //$NON-NLS-1$
errorMessage += " ***** FAILED TO ROLLBACK TO ORIGINAL APPLICATION FILE. *****: " //$NON-NLS-1$
+ ThrowableUtil.getAllMessages(e1);
}
log.info("Failed to update VDB file '" + this.deploymentFile //$NON-NLS-1$
+ "' using [" + packageDetails + "]."); //$NON-NLS-1$ //$NON-NLS-2$
return failApplicationDeployment(errorMessage, packageDetails);
}
// Deploy was successful!
deleteBackupOfOriginalFile(backupOfOriginalFile);
persistApplicationVersion(packageDetails, this.deploymentFile);
DeployPackagesResponse response = new DeployPackagesResponse(
ContentResponseResult.SUCCESS);
DeployIndividualPackageResponse packageResponse = new DeployIndividualPackageResponse(
packageDetails.getKey(), ContentResponseResult.SUCCESS);
response.addPackageResponse(packageResponse);
log.debug("Updated VDB file '" + this.deploymentFile //$NON-NLS-1$
+ "' successfully - returning response [" + response + "]..."); //$NON-NLS-1$ //$NON-NLS-2$
return response;