FileDocCategorySizeDatePackage
AssociationPhase.javaAPI DocGlassfish v2 API11474Fri May 04 22:34:36 BST 2007com.sun.enterprise.deployment.phasing

AssociationPhase

public class AssociationPhase extends DeploymentPhase
This class manages the association of an application or module with a target
author
Sandhya E

Fields Summary
public static final Logger
sLogger
Deployment Logger object for this class
private static com.sun.enterprise.util.i18n.StringManager
localStrings
string manager
Constructors Summary
public AssociationPhase(DeploymentContext deploymentCtx)
Creates a new instance of AssociationPhase

param
deploymentCtx context object for the deployment

   
                        
       
    
        this.deploymentCtx = deploymentCtx;        
        this.name = ASSOCIATE;
    
Methods Summary
private com.sun.enterprise.deployment.backend.DeploymentEventgetPostPhaseEvent(com.sun.enterprise.deployment.backend.DeploymentRequest req)
Event that will be broadcasted at the end of the phase

return
DeploymentEvent

        return new DeploymentEvent(DeploymentEventType.POST_ASSOCIATE, new DeploymentEventInfo(req));
    
private com.sun.enterprise.deployment.backend.DeploymentEventgetPrePhaseEvent(com.sun.enterprise.deployment.backend.DeploymentRequest req)
Event that will be broadcasted at the start of the phase

param
req Deployment request object
return
DeploymentEvent

        return new DeploymentEvent(DeploymentEventType.PRE_ASSOCIATE, new DeploymentEventInfo(req));
    
public voidprePhase(DeploymentPhaseContext phaseCtx)

        DeploymentRequest req = phaseCtx.getDeploymentRequest();
        DeploymentStatus status = phaseCtx.getDeploymentStatus();
        DeploymentTarget target = (DeploymentTarget)req.getTarget();

        try {
            // check context root uniqueness
            String virtualServers = (String)req.getOptionalAttributes().get(ServerTags.VIRTUAL_SERVERS);

            String contextRootInConflict = 
                ApplicationConfigHelper.checkContextRootUniqueness(
                    DeploymentServiceUtils.getConfigContext(), req.getName(), 
                    req.getTarget().getName(), virtualServers);
 
            if (contextRootInConflict != null) {
                throw new IASDeploymentException(localStrings.getString(
                    "duplicate_context_root",
                    contextRootInConflict, req.getName(), 
                    req.getTarget().getName()));
            }

            // only support directory deployment on DAS
            if (DeploymentServiceUtils.isDirectoryDeployed(req.getName(),
                req.getType())) {
                if (target != null && ServerHelper.isAServer(deploymentCtx.getConfigContext(), target.getTarget().getName()) && ServerHelper.isDAS(deploymentCtx.getConfigContext(), target.getTarget().getName())) {
                    return; 
                } else {
                    throw new IASDeploymentException(localStrings.getString(
                        "dir_deploy_not_support"));
                }
            }

            // FIXME: add the context root check here
        } catch(Throwable t){
            status.setStageStatus(DeploymentStatus.FAILURE);
            status.setStageException(t);
            status.setStageStatusMessage(t.getMessage());
        }
    
public voidrunPhase(DeploymentPhaseContext phaseCtx)
Phase specific execution logic will go in this method. Any phase implementing this class will provide its implementation for this method.

param
req Deployment request object
param
phaseCtx the DeploymentPhaseContext object

        try {
            DeploymentRequest req = phaseCtx.getDeploymentRequest();
            DeploymentTarget target = (DeploymentTarget)req.getTarget();
            if(target == null) {
                String msg = localStrings.getString("enterprise.deployment.phasing.association.targetnotspecified" );
                sLogger.log(Level.FINEST, msg);
                phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.WARNING);
                return;
            }
            prePhaseNotify(getPrePhaseEvent(req));
            String virtualServers = (String)req.getOptionalAttributes().get(ServerTags.VIRTUAL_SERVERS);

            /*
             *Add the app ref and send the event unless this is part of a 
             *redeployment sequence and the attributes for the app ref did not change 
             *as a result of the deployment, compared to their original values.
             */
            boolean needToAdd = true;
            DeploymentContext.SavedApplicationRefInfo savedAppRefInfo = null;
            
            if (req.isRedeployInProgress()) {
                /*
                 *Find the saved app ref info.
                 */
                savedAppRefInfo = 
                        deploymentCtx.removeSavedAppRef(req.getName(), target.getName());
                if (savedAppRefInfo != null) {
                    needToAdd = savedAppRefInfo.isChanging();
                }
            }
            sLogger.fine("AssociationPhase for " + req.getName() + " on " + target.getName() + 
                    "; isRedeployInProgress = " + req.isRedeployInProgress() +
                    ", savedAppRefInfo is " + (savedAppRefInfo != null ? savedAppRefInfo.toString() : "<null>" ) + "need to add = " + needToAdd);
            if (needToAdd) {
                sLogger.fine("AssociationPhase adding reference for " + req.getName() + " on " + target.getName());
                target.addAppReference(req.getName(), req.isStartOnDeploy(), virtualServers);
                /*
                 *See if there are saved non-default values for this app ref.
                 */
                if (savedAppRefInfo != null) {
                    /*
                     *Find the newly-created app ref. and assign the saved
                     *values.
                     */
                    ApplicationRef newAppRef = ApplicationReferenceHelper.findCurrentAppRef(
                            deploymentCtx,
                            target.getName(),
                            req.getName());
                    newAppRef.setLbEnabled(savedAppRefInfo.appRef().isLbEnabled());
                    newAppRef.setDisableTimeoutInMinutes(savedAppRefInfo.appRef().getDisableTimeoutInMinutes());
                }
                postPhaseNotify(getPostPhaseEvent(req));
                sendAssociateEvent(req);
            }
            
            phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.SUCCESS);
        } catch(DeploymentTargetException dte) {
            phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.FAILURE);
            phaseCtx.getDeploymentStatus().setStageException(dte.getCause());
            if (dte.getCause()!=null) {
                phaseCtx.getDeploymentStatus().setStageStatusMessage(dte.getCause().getMessage());
            }
        } catch(Throwable t) {
            phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.FAILURE);
            phaseCtx.getDeploymentStatus().setStageException(t);
            phaseCtx.getDeploymentStatus().setStageStatusMessage(t.getMessage());
        }
    
private voidsendAssociateEvent(com.sun.enterprise.deployment.backend.DeploymentRequest req)

        try {
            DeploymentTarget target = (DeploymentTarget)req.getTarget();
            
            String moduleType;
            
            if(req.isApplication()) {
                moduleType = null;
            }
            else {
                moduleType = DeploymentServiceUtils.getModuleTypeString(req.getType());
            }
            
            int eventType = com.sun.enterprise.admin.event.BaseDeployEvent.APPLICATION_REFERENCED;
            String appName = req.getName();
            String targetName = target.getTarget().getName();
            
           boolean success = DeploymentServiceUtils.multicastEvent(
                            eventType, 
                            appName, 
                            moduleType, 
                            false, 
                            true, 
                            targetName);
           
           sLogger.log(Level.FINE, "sendAssociateEvent: success=" + success);
        } catch(Throwable t) {
            DeploymentTargetException dte = 
                new DeploymentTargetException(t.getMessage());
            dte.initCause(t);
            throw dte;
        }