1 23 24 32 33 package com.sun.enterprise.deployment.phasing; 34 35 import com.sun.appserv.management.deploy.DeploymentProgress; 36 import com.sun.appserv.management.deploy.DeploymentProgressImpl; 37 import com.sun.enterprise.admin.event.BaseDeployEvent; 38 import com.sun.enterprise.appverification.factory.AppVerification; 39 import com.sun.enterprise.deployment.Application; 40 import com.sun.enterprise.deployment.backend.DeployableObjectType; 41 import com.sun.enterprise.deployment.backend.Deployer; 42 import com.sun.enterprise.deployment.backend.DeployerFactory; 43 import com.sun.enterprise.deployment.backend.DeploymentEvent; 44 import com.sun.enterprise.deployment.backend.DeploymentEventInfo; 45 import com.sun.enterprise.deployment.backend.DeploymentEventType; 46 import com.sun.enterprise.deployment.backend.DeploymentLogger; 47 import com.sun.enterprise.deployment.backend.DeploymentRequest; 48 import com.sun.enterprise.deployment.backend.DeploymentStatus; 49 import com.sun.enterprise.deployment.backend.IASDeploymentException; 50 import com.sun.enterprise.deployment.BundleDescriptor; 51 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 52 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 53 import com.sun.enterprise.deployment.util.DeploymentProperties; 54 import com.sun.enterprise.deployment.util.ModuleDescriptor; 55 import com.sun.enterprise.deployment.WebBundleDescriptor; 56 import com.sun.enterprise.deployment.WebService; 57 import com.sun.enterprise.management.deploy.DeploymentCallback; 58 import com.sun.enterprise.util.i18n.StringManager; 59 import com.sun.enterprise.util.io.FileUtils; 60 import com.sun.enterprise.util.RelativePathResolver; 61 62 import java.io.File ; 63 import java.io.IOException ; 64 import java.util.Enumeration ; 65 import java.util.Iterator ; 66 import java.util.logging.Level ; 67 import java.util.logging.Logger ; 68 69 import javax.enterprise.deploy.shared.ModuleType ; 70 71 77 public class J2EECPhase extends DeploymentPhase { 78 79 80 public static final Logger sLogger = DeploymentLogger.get(); 81 82 83 private static StringManager localStrings = 84 StringManager.getManager( J2EECPhase.class ); 85 86 87 91 public J2EECPhase(DeploymentContext deploymentCtx) { 92 this.deploymentCtx = deploymentCtx; 93 this.name = J2EEC; 94 } 95 96 103 public void runPhase(DeploymentPhaseContext phaseCtx) 104 { 105 boolean wasUnRegistered = false; 106 String type = null; 107 boolean isApp = false; 108 boolean isRedeploy = false; 109 int actionCode = -1; 110 String targetName = null; 111 DeploymentTarget target = null; 112 DeploymentRequest req = phaseCtx.getDeploymentRequest(); 113 DeploymentStatus status = phaseCtx.getDeploymentStatus(); 114 115 Deployer deployer = null; 116 try { 117 DeploymentCallback callback = req.getDeploymentCallback(); 118 if (callback != null) { 119 int percent = 0; 120 DeploymentProgress progress = new DeploymentProgressImpl( 121 (byte)percent, "deployment started", null); 122 callback.deploymentProgress(progress); 123 } 124 125 req.setCurrentDeploymentStatus(status); 128 129 deployer = DeployerFactory.getDeployer(req); 130 131 if(req.isApplication()) 133 isApp = true; 134 135 deployer.doRequestPrepare(); 136 137 if(req.isReDeploy()) { 139 isRedeploy = true; 140 141 if (AppVerification.doInstrument()) { 144 AppVerification.getInstrumentLogger().handleChangeInDeployment(); 145 } 146 } 147 148 if(isRedeploy) { 149 target = (DeploymentTarget)req.getTarget(); 150 151 if(target != null && ! target.getName().equals("domain")) { 154 targetName = target.getName(); 155 156 if(isApp) { 157 type = null; 158 actionCode = BaseDeployEvent.APPLICATION_UNDEPLOYED; 159 } 160 else { 161 type = DeploymentServiceUtils.getModuleTypeString(req.getType()); 162 actionCode = BaseDeployEvent.MODULE_UNDEPLOYED; 163 } 164 DeploymentServiceUtils.multicastEvent(actionCode, req.getName(), type, req.getCascade(), req.isForced(), targetName); 165 wasUnRegistered = true; 166 } 167 } 168 169 deployer.doRequestFinish(); 170 171 DeploymentServiceUtils.checkAbort(req.getName()); 174 175 if(isRedeploy) { 177 DeploymentServiceUtils.updateConfig(req); 178 } else { 179 DeploymentServiceUtils.addToConfig(req); 180 } 181 182 ApplicationConfigHelper.resetAppContextRoots( 184 DeploymentServiceUtils.getConfigContext(), req.getName(), 185 true); 186 187 wasUnRegistered = false; 189 deployer.cleanup(); 190 191 status.setStageStatus(DeploymentStatus.SUCCESS); 193 194 sLogger.log(Level.INFO, "deployed with " + DeploymentProperties.MODULE_ID + " = " + req.getName()); 196 populateStatusProperties(status, req); 197 if (callback != null) { 198 int percent = 100; 199 DeploymentProgress progress2 = new DeploymentProgressImpl( 200 (byte)percent, "deployment finished", null); 201 callback.deploymentProgress(progress2); 202 } 203 204 } catch(Throwable t) { 205 String msg = 206 localStrings.getString("enterprise.deployment.phasing.j2eec.error" ); 207 208 try { 214 if (target == null) { 215 if (deployer != null) { 216 deployer.removePolicy(); 217 } 218 DeploymentServiceUtils.removeFromConfig(req.getName(), 219 req.getType()); 220 } 221 } catch (Exception eee){} 222 223 if(isRedeploy && wasUnRegistered && t instanceof IASDeploymentException && req.getReRegisterOnFailure()) { 224 if(isApp) 226 actionCode = BaseDeployEvent.APPLICATION_DEPLOYED; 227 else 228 actionCode = BaseDeployEvent.MODULE_DEPLOYED; 229 230 try { 231 DeploymentServiceUtils.multicastEvent(actionCode, req.getName(), type, req.getCascade(), req.isForced(), targetName); 232 } 233 catch(Throwable t2) { 234 msg += t2; 235 } 236 } 237 sLogger.log(Level.SEVERE, msg, t); 239 240 status.setStageStatus(DeploymentStatus.FAILURE); 242 if (t instanceof java.io.Serializable ) { 243 status.setStageException(t); 244 } else { 245 sLogger.severe(localStrings.getString("enterprise.deployment.phasing.exception_notserializable", t.getClass())); 246 sLogger.severe(localStrings.getString("enterprise.deployment.phasing.exception_notforwarded", t.getMessage())); 247 } 248 status.setStageStatusMessage(t.getMessage()); 249 } 250 } 251 252 257 protected DeploymentEvent getPrePhaseEvent(DeploymentEventInfo info) { 258 return new DeploymentEvent(DeploymentEventType.PRE_DEPLOY, info ); 260 } 261 262 266 protected DeploymentEvent getPostPhaseEvent(DeploymentEventInfo info) { 267 return new DeploymentEvent(DeploymentEventType.POST_DEPLOY, info); 269 } 270 271 275 private void populateStatusProperties( 276 DeploymentStatus status, DeploymentRequest request) 277 throws IOException , IASDeploymentException { 278 DeploymentStatus mainStatus = status.getMainStatus(); 279 populateModuleIDs(mainStatus, request); 280 if (request.getDescriptor() != null) { 281 populateWsdlFilesForPublish(mainStatus, request); 282 } 283 } 284 285 306 private void populateModuleIDs( 307 DeploymentStatus status, DeploymentRequest request) { 308 309 String sep = DeploymentStatus.KEY_SEPARATOR; 310 311 String key = DeploymentStatus.MODULE_ID; 313 String moduleID = request.getName(); 314 status.addProperty(key, moduleID); 316 key = com.sun.appserv.management.deploy.DeploymentStatus.MODULE_ID_KEY; 317 status.addProperty(key, moduleID); 319 key = moduleID + sep + DeploymentStatus.MODULE_TYPE; 320 ModuleType moduleType = request.getType().getModuleType(); 321 status.addProperty(key, String.valueOf(moduleType.getValue())); 323 Application app = request.getDescriptor(); 325 if (app!=null) { 326 if (!app.isVirtual()) { 327 int counter = 0; 328 for (Iterator it = app.getModules(); it.hasNext();) { 329 ModuleDescriptor md = (ModuleDescriptor) it.next(); 330 331 key = moduleID + sep + 332 DeploymentStatus.MODULE_ID + sep + 333 String.valueOf(counter); 334 String subModuleID = moduleID + "#" + md.getArchiveUri(); 335 status.addProperty(key, subModuleID); 337 key = subModuleID + sep + DeploymentStatus.MODULE_TYPE; 338 status.addProperty(key, String.valueOf(md.getModuleType().getValue())); 340 341 if (ModuleType.WAR.equals(md.getModuleType())) { 342 WebBundleDescriptor wbd = 343 (WebBundleDescriptor) md.getDescriptor(); 344 key = subModuleID + sep + DeploymentStatus.CONTEXT_ROOT; 345 status.addProperty(key, getContextRoot(wbd)); } 347 counter++; 348 } 349 350 key = moduleID + sep + DeploymentStatus.SUBMODULE_COUNT; 351 status.addProperty(key, String.valueOf(counter)); } else { BundleDescriptor bd = app.getStandaloneBundleDescriptor(); 354 if (ModuleType.WAR.equals(bd.getModuleType())) { 355 WebBundleDescriptor wbd = (WebBundleDescriptor) bd; 356 key = moduleID + sep + DeploymentStatus.CONTEXT_ROOT; 357 status.addProperty(key, getContextRoot(wbd)); } 359 } 360 } 361 } 362 363 366 private void populateWsdlFilesForPublish( 367 DeploymentStatus status, DeploymentRequest request) 368 throws IOException , IASDeploymentException { 369 370 ModuleType moduleType = request.getType().getModuleType(); 371 if (!(ModuleType.EAR.equals(moduleType) || 373 ModuleType.WAR.equals(moduleType) || 374 ModuleType.EJB.equals(moduleType))) { 375 return; 376 } 377 378 String sep = DeploymentStatus.KEY_SEPARATOR; 379 Application app = request.getDescriptor(); 380 String moduleID = request.getName(); 381 AbstractArchive moduleArchive = null; 382 String key = null; 383 String keyPrefix = null; 384 385 FileArchive archive = new FileArchive(); 386 archive.open(RelativePathResolver.resolvePath( 387 getGeneratedAppLocation(request))); 388 389 for (Iterator it = app.getWebServiceDescriptors().iterator(); 390 it.hasNext();) { 391 WebService webService = (WebService) it.next(); 392 if (!webService.hasFilePublishing()) { 394 continue; 395 } 396 397 String clientPublishURL = 399 webService.getClientPublishUrl().toExternalForm(); 400 if (app.isVirtual()) { keyPrefix = moduleID; 402 moduleArchive = archive; 403 } else { 404 ModuleDescriptor md = 405 webService.getBundleDescriptor().getModuleDescriptor(); 406 keyPrefix = moduleID + "#" + md.getArchiveUri(); 407 moduleArchive = archive.getEmbeddedArchive(md.getArchiveUri()); 408 } 409 410 key = keyPrefix + sep + DeploymentStatus.WSDL_PUBLISH_URL; 411 status.addProperty(key, clientPublishURL); 412 413 BundleDescriptor bundle = webService.getBundleDescriptor(); 416 Enumeration entries = moduleArchive.entries(bundle.getWsdlDir()); 417 418 int counter = 0; 425 while(entries.hasMoreElements()) { 426 String name = (String ) entries.nextElement(); 427 key = keyPrefix + sep + DeploymentStatus.WSDL_FILE_ENTRIES + 428 sep + String.valueOf(counter); 429 status.addProperty(key, stripWsdlDir(name,bundle)); 430 431 String wsdlFileLocation = 433 moduleArchive.getArchiveUri() + File.separator + 434 name.replace('/', File.separatorChar); 435 key = key + sep + DeploymentStatus.WSDL_LOCATION; 436 status.addProperty(key, wsdlFileLocation); 437 counter++; 438 } 439 key = keyPrefix + sep + DeploymentStatus.WSDL_FILE_ENTRIES 440 + sep + DeploymentStatus.COUNT; 441 status.addProperty(key, String.valueOf(counter)); 442 } 443 } 444 445 private String getContextRoot(WebBundleDescriptor wbd) { 446 String contextRoot = wbd.getContextRoot(); 447 if (!contextRoot.startsWith("/")) { 448 contextRoot = "/" + contextRoot; 449 } 450 return contextRoot; 451 } 452 453 private String getGeneratedAppLocation (DeploymentRequest request) 454 throws IASDeploymentException { 455 String xmlDir = request.getDescriptor().getGeneratedXMLDirectory(); 456 if (xmlDir == null || !FileUtils.safeIsDirectory(xmlDir)) { 458 xmlDir = DeploymentServiceUtils.getLocation( 459 request.getName(), request.getType()); 460 } 461 return xmlDir; 462 } 463 464 467 private String stripWsdlDir(String entry, BundleDescriptor bundle) { 468 String wsdlDir = bundle.getWsdlDir(); 469 return entry.substring(wsdlDir.length()+1); 470 } 471 } 472 | Popular Tags |