* @throws Exception
*/
private static void deployAndStart(DeploymentManager deploymentManager,
URL contentURL, String archiveFileName) throws Exception {
DeploymentProgress progress = null;
DeploymentStatus distributeStatus;
Exception distributeFailure = null;
try {
progress = deploymentManager.distribute(archiveFileName, contentURL, true);
distributeStatus = run(progress);
if (distributeStatus.isFailed()) {
distributeFailure = (distributeStatus.getFailure() != null) ? distributeStatus.getFailure() :
new Exception("Distribute failed for unknown reason."); //$NON-NLS-1$
}
}
catch (Exception e) {
distributeFailure = e;
}
if (distributeFailure != null) {
throw new Exception("Failed to distribute '" + contentURL + "' to '" + archiveFileName + "' - cause: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ThrowableUtil.getAllMessages(distributeFailure));
}
// Now that we've successfully distributed the deployment, we need to start it.
String[] deploymentNames = progress.getDeploymentID().getRepositoryNames();
DeploymentStatus startStatus;
Exception startFailure = null;
try {
progress = deploymentManager.start(deploymentNames);
startStatus = run(progress);
if (startStatus.isFailed()) {
startFailure = (startStatus.getFailure() != null) ? startStatus.getFailure() :
new Exception("Start failed for unknown reason."); //$NON-NLS-1$
}
}
catch (Exception e) {
startFailure = e;
}
if (startFailure != null) {
LOG.error("Failed to start deployment " + Arrays.asList(deploymentNames) //$NON-NLS-1$
+ " during deployment of '" + archiveFileName + "'. Backing out the deployment...", startFailure); //$NON-NLS-1$ //$NON-NLS-2$
// If start failed, the app is invalid, so back out the deployment.
DeploymentStatus removeStatus;
Exception removeFailure = null;
try {
progress = deploymentManager.remove(deploymentNames);
removeStatus = run(progress);
if (removeStatus.isFailed()) {
removeFailure = (removeStatus.getFailure() != null) ? removeStatus.getFailure() :
new Exception("Remove failed for unknown reason."); //$NON-NLS-1$
}
}
catch (Exception e) {
removeFailure = e;