1 23 24 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 ; 51 import java.util.logging.Logger ; 52 53 57 public class AssociationPhase extends DeploymentPhase { 58 59 60 public static final Logger sLogger = DeploymentLogger.get(); 61 62 63 private static StringManager localStrings = 64 StringManager.getManager( AssociationPhase.class ); 65 66 70 public AssociationPhase(DeploymentContext deploymentCtx) 71 { 72 this.deploymentCtx = deploymentCtx; 73 this.name = ASSOCIATE; 74 } 75 76 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 String virtualServers = (String )req.getOptionalAttributes().get(ServerTags.VIRTUAL_SERVERS); 88 89 String 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 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 } catch(Throwable t){ 114 status.setStageStatus(DeploymentStatus.FAILURE); 115 status.setStageException(t); 116 status.setStageStatusMessage(t.getMessage()); 117 } 118 } 119 120 121 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 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 virtualServers = (String )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 159 private DeploymentEvent getPrePhaseEvent(DeploymentRequest req) 160 { 161 return new DeploymentEvent(DeploymentEventType.PRE_ASSOCIATE, new DeploymentEventInfo(req)); 162 } 163 164 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 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 appName = req.getName(); 190 String 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 t) { 202 DeploymentTargetException dte = 203 new DeploymentTargetException(t.getMessage()); 204 dte.initCause(t); 205 throw dte; 206 } 207 } 208 } 209 | Popular Tags |