KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > phasing > AssociationPhase


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AssociationPhase.java
26  *
27  * Created on May 20, 2003, 3:14 PM
28  * @author sandhyae
29  * <BR> <I>$Source: /cvs/glassfish/appserv-core/src/java/com/sun/enterprise/deployment/phasing/AssociationPhase.java,v $
30  *
31  */

32
33 package com.sun.enterprise.deployment.phasing;
34
35 import com.sun.enterprise.deployment.backend.IASDeploymentException;
36 import com.sun.enterprise.deployment.backend.DeploymentRequest;
37 import com.sun.enterprise.deployment.backend.DeploymentEventInfo;
38 import com.sun.enterprise.deployment.backend.DeploymentEvent;
39 import com.sun.enterprise.deployment.backend.DeploymentEventType;
40 import com.sun.enterprise.deployment.backend.DeployableObjectType;
41 import com.sun.enterprise.deployment.backend.DeploymentLogger;
42 import com.sun.enterprise.deployment.backend.DeploymentStatus;
43 import com.sun.enterprise.config.serverbeans.ServerTags;
44 import com.sun.enterprise.config.ConfigException;
45 import com.sun.enterprise.config.serverbeans.ServerHelper;
46 import com.sun.enterprise.config.serverbeans.ApplicationHelper;
47
48 import com.sun.enterprise.util.i18n.StringManager;
49
50 import java.util.logging.Level JavaDoc;
51 import java.util.logging.Logger JavaDoc;
52
53 /**
54  * This class manages the association of an application or module with a target
55  * @author Sandhya E
56  */

57 public class AssociationPhase extends DeploymentPhase {
58
59     /** Deployment Logger object for this class */
60     public static final Logger sLogger = DeploymentLogger.get();
61     
62     /** string manager */
63     private static StringManager localStrings =
64         StringManager.getManager( AssociationPhase.class );
65    
66     /**
67      * Creates a new instance of AssociationPhase
68      * @param deploymentCtx context object for the deployment
69      */

70     public AssociationPhase(DeploymentContext deploymentCtx)
71     {
72         this.deploymentCtx = deploymentCtx;
73         this.name = ASSOCIATE;
74     }
75
76     /**
77      *
78      */

79     public void prePhase(DeploymentPhaseContext phaseCtx)
80     {
81         DeploymentRequest req = phaseCtx.getDeploymentRequest();
82         DeploymentStatus status = phaseCtx.getDeploymentStatus();
83         DeploymentTarget target = (DeploymentTarget)req.getTarget();
84
85         try {
86             // check context root uniqueness
87
String JavaDoc virtualServers = (String JavaDoc)req.getOptionalAttributes().get(ServerTags.VIRTUAL_SERVERS);
88
89             String JavaDoc contextRootInConflict =
90                 ApplicationConfigHelper.checkContextRootUniqueness(
91                     DeploymentServiceUtils.getConfigContext(), req.getName(),
92                     req.getTarget().getName(), virtualServers);
93  
94             if (contextRootInConflict != null) {
95                 throw new IASDeploymentException(localStrings.getString(
96                     "duplicate_context_root",
97                     contextRootInConflict, req.getName(),
98                     req.getTarget().getName()));
99             }
100
101             // only support directory deployment on DAS
102
if (DeploymentServiceUtils.isDirectoryDeployed(req.getName(),
103                 req.getType())) {
104                 if (target != null && ServerHelper.isAServer(deploymentCtx.getConfigContext(), target.getTarget().getName()) && ServerHelper.isDAS(deploymentCtx.getConfigContext(), target.getTarget().getName())) {
105                     return;
106                 } else {
107                     throw new IASDeploymentException(localStrings.getString(
108                         "dir_deploy_not_support"));
109                 }
110             }
111
112             // FIXME: add the context root check here
113
} catch(Throwable JavaDoc t){
114             status.setStageStatus(DeploymentStatus.FAILURE);
115             status.setStageException(t);
116             status.setStageStatusMessage(t.getMessage());
117         }
118     }
119
120     
121     /**
122      * Phase specific execution logic will go in this method. Any phase implementing
123      * this class will provide its implementation for this method.
124      * @param req Deployment request object
125      * @param phaseCtx the DeploymentPhaseContext object
126      */

127     public void runPhase(DeploymentPhaseContext phaseCtx)
128     {
129         try {
130             DeploymentRequest req = phaseCtx.getDeploymentRequest();
131             DeploymentTarget target = (DeploymentTarget)req.getTarget();
132             if(target == null) {
133                 String JavaDoc msg = localStrings.getString("enterprise.deployment.phasing.association.targetnotspecified" );
134                 sLogger.log(Level.FINEST, msg);
135                 phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.WARNING);
136                 return;
137             }
138             prePhaseNotify(getPrePhaseEvent(req));
139             String JavaDoc virtualServers = (String JavaDoc)req.getOptionalAttributes().get(ServerTags.VIRTUAL_SERVERS);
140             target.addAppReference(req.getName(), req.isStartOnDeploy(), virtualServers);
141             postPhaseNotify(getPostPhaseEvent(req));
142             sendAssociateEvent(req);
143             phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.SUCCESS);
144         } catch(DeploymentTargetException dte) {
145             phaseCtx.getDeploymentStatus().setStageStatus(DeploymentStatus.FAILURE);
146             phaseCtx.getDeploymentStatus().setStageException(dte.getCause());
147             if (dte.getCause()!=null) {
148                 phaseCtx.getDeploymentStatus().setStageStatusMessage(dte.getCause().getMessage());
149             }
150         }
151     }
152     
153
154     /**
155      * Event that will be broadcasted at the start of the phase
156      * @param req Deployment request object
157      * @return DeploymentEvent
158      */

159     private DeploymentEvent getPrePhaseEvent(DeploymentRequest req)
160     {
161         return new DeploymentEvent(DeploymentEventType.PRE_ASSOCIATE, new DeploymentEventInfo(req));
162     }
163     
164     /**
165      * Event that will be broadcasted at the end of the phase
166      * @return DeploymentEvent
167      */

168     private DeploymentEvent getPostPhaseEvent(DeploymentRequest req)
169     {
170         return new DeploymentEvent(DeploymentEventType.POST_ASSOCIATE, new DeploymentEventInfo(req));
171     }
172
173
174     private void sendAssociateEvent(DeploymentRequest req ) throws
175         DeploymentTargetException {
176         try {
177             DeploymentTarget target = (DeploymentTarget)req.getTarget();
178             
179             String JavaDoc moduleType;
180             
181             if(req.isApplication()) {
182                 moduleType = null;
183             }
184             else {
185                 moduleType = DeploymentServiceUtils.getModuleTypeString(req.getType());
186             }
187             
188             int eventType = com.sun.enterprise.admin.event.BaseDeployEvent.APPLICATION_REFERENCED;
189             String JavaDoc appName = req.getName();
190             String JavaDoc targetName = target.getTarget().getName();
191             
192            boolean success = DeploymentServiceUtils.multicastEvent(
193                             eventType,
194                             appName,
195                             moduleType,
196                             false,
197                             true,
198                             targetName);
199            
200            sLogger.log(Level.FINE, "sendAssociateEvent: success=" + success);
201         } catch(Throwable JavaDoc t) {
202             DeploymentTargetException dte =
203                 new DeploymentTargetException(t.getMessage());
204             dte.initCause(t);
205             throw dte;
206         }
207     }
208 }
209
Popular Tags