public void runPhase(DeploymentPhaseContext phaseCtx) {
DeploymentStatus status = phaseCtx.getDeploymentStatus();
try {
//get the app directory on target's cache deleted
DeploymentRequest req = phaseCtx.getDeploymentRequest();
DeploymentTarget target = (DeploymentTarget)req.getTarget();
/*
*Remove the app ref and send the event unless this is part of a
*redeployment sequence of operations and the attributes for the app
*ref will not change as a result of the deployment, compared to
*their current values.
*/
ApplicationRef ref = ApplicationReferenceHelper.findCurrentAppRef(
deploymentCtx, target.getName(), req.getName());
boolean needToRemoveRef = true;
DeploymentContext.SavedApplicationRefInfo info = null;
if (req.isRedeployInProgress()) {
/*
*Save a pointer to the existing app ref for use during the later
*disassociate phase.
*/
String virtualServers = null;
Properties optionalAttrs = req.getOptionalAttributes();
if (optionalAttrs != null) {
virtualServers = (String) optionalAttrs.get(ServerTags.VIRTUAL_SERVERS);
}
if (virtualServers == null && ref.getVirtualServers() != null) {
// if user does not specify virtual server in a redeployment
// preserve the value from last deployment
virtualServers = ref.getVirtualServers();
// also set it in request so subsequent retrieval
// will get the proper value
if (req.getOptionalAttributes() == null) {
Properties optionalAttributes = new Properties();
req.setOptionalAttributes(optionalAttributes);
}
req.getOptionalAttributes().put(ServerTags.VIRTUAL_SERVERS,
virtualServers);
}
info = deploymentCtx.saveAppRef(
req.getName(), target.getName(), ref, req);
needToRemoveRef = info.isChanging();
}
sLogger.fine("DisassociationPhase for " + req.getName() + " on " + target.getName() +
"; isRedeployInProgress = " + req.isRedeployInProgress() +
", savedAppRefInfo is " + (info != null ? info.toString() : "<null>" ) + "need to remove = " + needToRemoveRef);
if (needToRemoveRef) {
sLogger.fine("DisassociationPhase removing app ref for " + req.getName() + " on " + target.getName());
target.removeAppReference(req.getName());
sendDisassociateEvent(req);
}
status.setStageStatus(DeploymentStatus.SUCCESS);
}catch(Throwable t){
status.setStageStatus(DeploymentStatus.FAILURE);