public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
{
DeploymentControllerContext deploymentControllerContext = (DeploymentControllerContext)context;
String stageName = toState.getStateString();
DeploymentContext deploymentContext = deploymentControllerContext.getDeploymentContext();
try
{
List<Deployer> theDeployers = getDeployersList(stageName);
if (log.isTraceEnabled())
log.trace("Deployers for " + stageName + " " + theDeployers);
if (theDeployers.isEmpty() == false)
{
int i = 0;
try
{
while (i < theDeployers.size())
{
Deployer deployer = theDeployers.get(i);
if (deployer.isParentFirst())
doInstallParentFirst(deployer, deploymentContext);
else
doInstallParentLast(deployer, deploymentContext);
++i;
}
}
catch (Throwable t)
{
deploymentContext.setState(DeploymentState.ERROR);
deploymentContext.setProblem(t);
// Unwind the previous deployments
for (int j = i - 1; j >= 0; --j)
{
Deployer deployer = theDeployers.get(j);
if (deployer.isParentFirst())
doUninstallParentLast(deployer, deploymentContext, true, true);
else
doUninstallParentFirst(deployer, deploymentContext, true, true);
}
// It can happen that subdeployments are not processed if the parent fails immediately
// so there is no callback to undeploy when nothing was done
setState(deploymentContext, DeploymentState.UNDEPLOYED, DeploymentState.DEPLOYING);
throw t;
}
}
}
finally
{
if (ControllerState.INSTALLED.equals(toState) && DeploymentState.DEPLOYING.equals(deploymentContext.getState()))
{
log.debug("Fully Deployed " + context.getName());
setState(deploymentContext, DeploymentState.DEPLOYED, null);
}
}