if (LOG.isDebugEnabled()) {
LOG.debug("Removing " + getResourceDescription() + " with component " + toString(managedComponent) + "...");
}
ManagementView managementView = getConnection().getManagementView();
managementView.removeComponent(managedComponent);
ManagedDeployment parentDeployment = managedComponent.getDeployment();
if (parentDeployment.getComponents().size() > 1 || !parentDeployment.getChildren().isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Redeploying parent deployment '" + parentDeployment.getName()
+ "' in order to complete removal of component " + toString(managedComponent) + "...");
}
DeploymentProgress progress = deploymentManager.redeploy(parentDeployment.getName());
DeploymentStatus status = DeploymentUtils.run(progress);
if (status.isFailed()) {
LOG.error("Failed to redeploy parent deployment '" + parentDeployment.getName()
+ "during removal of component " + toString(managedComponent)
+ " - removal may not persist when the app server is restarted.", status.getFailure());
}
} else {
//this is the last component of the deployment and nothing would be left there after
//the component was removed. Let's just undeploy it in addition to removing the component.
//This will make sure that the deployment doesn't leave behind any defunct config files, etc.
if (LOG.isDebugEnabled()) {
LOG.debug("Undeploying parent deployment '" + parentDeployment.getName()
+ "' in order to complete removal of component " + toString(managedComponent) + "...");
}
parentDeployment = managementView.getDeployment(parentDeployment.getName());
DeploymentProgress progress = deploymentManager.remove(parentDeployment.getName());
DeploymentStatus status = DeploymentUtils.run(progress);
if (status.isFailed()) {
LOG.error("Failed to undeploy parent deployment '" + parentDeployment.getName()
+ "during removal of component " + toString(managedComponent)
+ " - removal may not persist when the app server is restarted.", status.getFailure());
}
}