1 23 24 32 33 package com.sun.enterprise.deployment.phasing; 34 35 import java.security.AccessControlContext ; 36 import java.security.AccessController ; 37 import java.security.Principal ; 38 import java.util.Iterator ; 39 import java.util.Properties ; 40 import java.io.File ; 41 import java.util.ArrayList ; 42 import java.util.List ; 43 import java.util.Map ; 44 import java.util.ResourceBundle ; 45 import java.util.logging.Level ; 46 import java.util.logging.LogManager ; 47 import java.util.logging.Logger ; 48 49 import javax.management.MBeanServer ; 50 import javax.management.ObjectName ; 51 import javax.management.MBeanException ; 52 import javax.management.InstanceNotFoundException ; 53 54 import com.sun.enterprise.admin.common.exception.ServerInstanceException; 55 import com.sun.enterprise.admin.common.MBeanServerFactory; 56 import com.sun.enterprise.admin.common.ObjectNames; 57 import com.sun.enterprise.admin.event.ApplicationDeployEvent; 58 import com.sun.enterprise.admin.event.BaseDeployEvent; 59 import com.sun.enterprise.admin.event.ModuleDeployEvent; 60 import com.sun.enterprise.admin.server.core.AdminService; 61 import com.sun.enterprise.admin.util.HostAndPort; 62 import com.sun.enterprise.appverification.factory.AppVerification; 63 import com.sun.enterprise.config.ConfigContext; 64 import com.sun.enterprise.config.ConfigException; 65 import com.sun.enterprise.config.serverbeans.ServerTags; 66 import com.sun.enterprise.deployment.archivist.Archivist; 67 import com.sun.enterprise.deployment.archivist.ArchivistFactory; 68 import com.sun.enterprise.deployment.backend.ClientJarMakerRegistry; 69 import com.sun.enterprise.deployment.backend.DeployableObjectType; 70 import com.sun.enterprise.deployment.backend.DeploymentCommand; 71 import com.sun.enterprise.deployment.backend.DeploymentLogger; 72 import com.sun.enterprise.deployment.backend.DeploymentRequest; 73 import com.sun.enterprise.deployment.backend.DeploymentRequestRegistry; 74 import com.sun.enterprise.deployment.backend.DeploymentStatus; 75 import com.sun.enterprise.deployment.backend.IASDeploymentException; 76 import com.sun.enterprise.deployment.deploy.shared.InputJarArchive; 77 import com.sun.enterprise.deployment.Descriptor; 78 import com.sun.enterprise.deployment.interfaces.DeploymentImplConstants; 79 import com.sun.enterprise.deployment.util.DeploymentProperties; 80 import com.sun.enterprise.instance.InstanceEnvironment; 81 import com.sun.enterprise.management.deploy.DeploymentCallback; 82 import com.sun.enterprise.server.ApplicationServer; 83 import com.sun.enterprise.util.i18n.StringManager; 84 import com.sun.logging.LogDomains; 85 import javax.security.auth.Subject ; 86 87 91 public class PEDeploymentService extends DeploymentService { 92 93 94 public static final Logger sLogger = DeploymentLogger.get(); 95 96 97 private static final Logger auditLogger = LogDomains.getLogger(LogDomains.DPLAUDIT_LOGGER); 98 99 100 private static final ResourceBundle auditBundle = auditLogger.getResourceBundle(); 101 102 103 private static StringManager localStrings = 104 StringManager.getManager( PEDeploymentService.class ); 105 106 107 protected DeploymentContext deploymentContext = null; 108 109 110 private List deployToDomainPhaseList = null; 111 112 113 private List undeployFromDomainPhaseList = null; 114 115 116 private List deployPhaseList = null; 117 118 119 private List undeployPhaseList = null; 120 121 122 private List associatePhaseList = null; 123 124 125 private List disassociatePhaseList = null; 126 127 private List stopPhaseList = null; 128 129 private List startPhaseList = null; 130 131 private static final String DISASSOCIATE_ACTION = localStrings.getString( 132 "enterprise.deployment.phasing.action.disassociate"); 133 private static final String REDEPLOY_ACTION = localStrings.getString( 134 "enterprise.deployment.phasing.action.redeploy"); 135 private static final String STOP_ACTION = localStrings.getString( 136 "enterprise.deployment.phasing.action.stop"); 137 private static final String UNDEPLOY_ACTION = localStrings.getString( 138 "enterprise.deployment.phasing.action.undeploy"); 139 140 144 public PEDeploymentService(ConfigContext configContext) 145 { 146 deploymentContext = new DeploymentContext(); 147 deploymentContext.setConfigContext(configContext); 148 initializePhases(); 149 } 150 151 154 protected List getDeployPhaseListForTarget(DeploymentRequest req) { 155 156 if (deployPhaseList != null) { 157 return deployPhaseList; 158 } 159 160 J2EECPhase j2eec = new J2EECPhase(deploymentContext); 162 AssociationPhase associate = new AssociationPhase(deploymentContext); 163 ResourceAdapterStartPhase raStart = 164 new ResourceAdapterStartPhase(deploymentContext); 165 ApplicationStartPhase appStart = 166 new ApplicationStartPhase(deploymentContext); 167 PreResCreationPhase preResCreation = 168 new PreResCreationPhase(deploymentContext); 169 PostResCreationPhase postResCreation = 170 new PostResCreationPhase(deploymentContext); 171 172 deployPhaseList = new ArrayList (); 174 deployPhaseList.add(j2eec); 175 deployPhaseList.add(associate); 176 deployPhaseList.add(preResCreation); 177 deployPhaseList.add(raStart); 178 deployPhaseList.add(postResCreation); 179 deployPhaseList.add(appStart); 180 return deployPhaseList; 181 } 182 183 188 private void initializePhases() 189 { 190 J2EECPhase j2eec = new J2EECPhase(deploymentContext); 191 AssociationPhase associate = new AssociationPhase(deploymentContext); 192 DisassociationPhase disassociate = new DisassociationPhase(deploymentContext); 193 UndeployFromDomainPhase undeploy = new UndeployFromDomainPhase(deploymentContext); 194 ResourceAdapterStartPhase raStart = 195 new ResourceAdapterStartPhase(deploymentContext); 196 ApplicationStartPhase appStart = 197 new ApplicationStartPhase(deploymentContext); 198 PreResCreationPhase preResCreation = 199 new PreResCreationPhase(deploymentContext); 200 PostResCreationPhase postResCreation = 201 new PostResCreationPhase(deploymentContext); 202 203 ResourceAdapterStopPhase raStop = 204 new ResourceAdapterStopPhase(deploymentContext); 205 ApplicationStopPhase appStop = 206 new ApplicationStopPhase(deploymentContext); 207 PreResDeletionPhase preResDeletion = 208 new PreResDeletionPhase(deploymentContext); 209 PostResDeletionPhase postResDeletion = 210 new PostResDeletionPhase(deploymentContext); 211 212 deployToDomainPhaseList = new ArrayList (); 214 deployToDomainPhaseList.add(preResDeletion); 216 deployToDomainPhaseList.add(postResDeletion); 217 deployToDomainPhaseList.add(j2eec); 218 deployToDomainPhaseList.add(preResCreation); 219 deployToDomainPhaseList.add(postResCreation); 220 221 associatePhaseList = new ArrayList (); 223 associatePhaseList.add(associate); 224 225 disassociatePhaseList = new ArrayList (); 227 disassociatePhaseList.add(disassociate); 228 229 undeployPhaseList = new ArrayList (); 231 undeployPhaseList.add(appStop); 232 undeployPhaseList.add(preResDeletion); 233 undeployPhaseList.add(raStop); 234 undeployPhaseList.add(postResDeletion); 235 undeployPhaseList.add(disassociate); 236 undeployPhaseList.add(undeploy); 237 238 undeployFromDomainPhaseList = new ArrayList (); 240 undeployFromDomainPhaseList.add(preResDeletion); 241 undeployFromDomainPhaseList.add(postResDeletion); 242 undeployFromDomainPhaseList.add(undeploy); 243 244 startPhaseList = new ArrayList (); 245 startPhaseList.add(preResCreation); 246 startPhaseList.add(raStart); 247 startPhaseList.add(postResCreation); 248 startPhaseList.add(appStart); 249 250 stopPhaseList = new ArrayList (); 251 stopPhaseList.add(appStop); 252 stopPhaseList.add(preResDeletion); 253 stopPhaseList.add(raStop); 254 stopPhaseList.add(postResDeletion); 255 } 256 257 258 private DeploymentStatus deploy(DeploymentRequest req, AuditInfo auditInfo) throws IASDeploymentException { 259 DeploymentStatus result = null; 261 if (req.getTarget() != null && 262 !req.getTarget().getName().equals("domain")) { 263 result = executePhases(req, getDeployPhaseListForTarget(req)); 264 } else { 266 result = executePhases(req, deployToDomainPhaseList); 267 } 268 if (auditInfo != null) { 269 auditInfo.reportEnd(result.getStatus()); 270 } 271 return result; 272 } 273 274 279 public DeploymentStatus deploy(DeploymentRequest req) throws IASDeploymentException 280 { 281 return deploy(req, createAuditInfoIfOn(req, AuditInfo.Operation.deploy)); 282 } 283 284 289 public DeploymentStatus undeploy(DeploymentRequest req) { 290 return undeploy(req, createAuditInfoIfOn(req, AuditInfo.Operation.undeploy)); 291 } 292 293 300 private DeploymentStatus undeploy(DeploymentRequest req, AuditInfo auditInfo) 301 { 302 DeploymentStatus result = null; 303 if (AppVerification.doInstrument()) { 306 AppVerification.getInstrumentLogger().handleChangeInDeployment(); 307 } 308 309 if (req.getTarget() != null) { 311 result = executePhases(req, undeployPhaseList); 312 } else { 314 result = executePhases(req, undeployFromDomainPhaseList); 315 } 316 if (auditInfo != null) { 317 auditInfo.reportEnd(result.getStatus()); 318 } 319 return result; 320 } 321 322 323 329 private DeploymentStatus associate(DeploymentRequest req, AuditInfo auditInfo) { 330 DeploymentStatus result = executePhases(req, associatePhaseList); 331 if (auditInfo != null) { 332 auditInfo.reportEnd(result.getStatus()); 333 } 334 return result; 335 } 336 337 341 public DeploymentStatus associate(DeploymentRequest req) 342 throws IASDeploymentException { 343 return associate(req, createAuditInfoIfOn(req, AuditInfo.Operation.associate)); 344 } 345 346 350 public DeploymentStatus associate(String targetName, 351 boolean enabled, String virtualServers, String referenceName) 352 throws IASDeploymentException { 353 try { 354 long startTime = System.currentTimeMillis(); 355 DeployableObjectType type = 357 DeploymentServiceUtils.getRegisteredType(referenceName); 358 359 final DeploymentTarget target = 360 DeploymentServiceUtils.getAndValidateDeploymentTarget( 361 targetName, referenceName, false); 362 363 InstanceEnvironment env = 364 ApplicationServer.getServerContext().getInstanceEnvironment(); 365 DeploymentRequest req = new DeploymentRequest( 366 env, 367 type, 368 DeploymentCommand.DEPLOY); 369 370 req.setName(referenceName); 371 req.setStartOnDeploy(enabled); 372 req.setTarget(target); 373 374 Properties optionalAttributes = new Properties (); 375 if(virtualServers!=null) { 376 optionalAttributes.put(ServerTags.VIRTUAL_SERVERS, 377 virtualServers); 378 } 379 req.setOptionalAttributes(optionalAttributes); 380 return associate(req, createAuditInfoIfOn(req, AuditInfo.Operation.associate, startTime)); 381 } catch(Exception e) { 382 if (e instanceof IASDeploymentException) { 383 throw (IASDeploymentException)e; 384 } 385 else { 386 throw new IASDeploymentException(e); 387 } 388 } 389 } 390 391 395 public DeploymentStatus associate(String targetName, 396 String referenceName, Map options) throws IASDeploymentException { 397 try { 398 long startTime = System.currentTimeMillis(); 399 DeployableObjectType type = 400 DeploymentServiceUtils.getRegisteredType(referenceName); 401 402 final DeploymentTarget target = 403 DeploymentServiceUtils.getAndValidateDeploymentTarget( 404 targetName, referenceName, false); 405 406 InstanceEnvironment env = 407 ApplicationServer.getServerContext().getInstanceEnvironment(); 408 DeploymentRequest req = new DeploymentRequest( 409 env, 410 type, 411 DeploymentCommand.DEPLOY); 412 413 DeploymentProperties dProps = new DeploymentProperties(options); 414 String virtualServers = dProps.getVirtualServers(); 415 boolean enabled = dProps.getEnable(); 416 417 req.setName(referenceName); 418 req.setStartOnDeploy(enabled); 419 req.setTarget(target); 420 DeploymentServiceUtils.setResourceOptionsInRequest(req, dProps); 421 422 Properties optionalAttributes = new Properties (); 423 if(virtualServers!=null) { 424 optionalAttributes.put(ServerTags.VIRTUAL_SERVERS, 425 virtualServers); 426 } 427 req.setOptionalAttributes(optionalAttributes); 428 429 return associate(req, createAuditInfoIfOn(req, AuditInfo.Operation.associate, startTime)); 430 431 } catch(Exception e) { 432 if (e instanceof IASDeploymentException) { 433 throw (IASDeploymentException)e; 434 } 435 else { 436 throw new IASDeploymentException(e); 437 } 438 } 439 } 440 441 private DeploymentStatus disassociate(DeploymentRequest req, AuditInfo auditInfo) 442 throws IASDeploymentException { 443 String moduleID = req.getName(); 444 DeployableObjectType type = req.getType(); 445 boolean isRegistered = 446 DeploymentServiceUtils.isRegistered(moduleID, type); 447 if (isRegistered) { 448 DeploymentServiceUtils.validate(moduleID,type,DISASSOCIATE_ACTION); 449 } 450 DeploymentStatus result = executePhases(req, disassociatePhaseList); 451 if (auditInfo != null) { 452 auditInfo.reportEnd(result.getStatus()); 453 } 454 return result; 455 } 456 457 461 public DeploymentStatus disassociate(DeploymentRequest req) 462 throws IASDeploymentException { 463 return disassociate(req, createAuditInfoIfOn(req, AuditInfo.Operation.disassociate)); 464 } 465 466 470 public DeploymentStatus disassociate(String targetName, 471 String referenceName) throws IASDeploymentException { 472 try { 473 long startTime = System.currentTimeMillis(); 474 DeployableObjectType type = 475 DeploymentServiceUtils.getRegisteredType(referenceName); 476 477 final DeploymentTarget target = 478 DeploymentServiceUtils.getAndValidateDeploymentTarget( 479 targetName, referenceName, true); 480 481 InstanceEnvironment env = 482 ApplicationServer.getServerContext().getInstanceEnvironment(); 483 DeploymentRequest req = new DeploymentRequest( 484 env, 485 type, 486 DeploymentCommand.UNDEPLOY); 487 488 req.setName(referenceName); 489 req.setTarget(target); 490 491 return disassociate(req, createAuditInfoIfOn(req, AuditInfo.Operation.disassociate, startTime)); 492 } catch(Exception e) { 493 if (e instanceof IASDeploymentException) { 494 throw (IASDeploymentException)e; 495 } 496 else { 497 throw new IASDeploymentException(e); 498 } 499 } 500 } 501 502 public DeploymentStatus disassociate(String targetName, 503 String referenceName, Map options) throws IASDeploymentException { 504 try { 505 long startTime = System.currentTimeMillis(); 506 DeployableObjectType type = 507 DeploymentServiceUtils.getRegisteredType(referenceName); 508 509 final DeploymentTarget target = 510 DeploymentServiceUtils.getAndValidateDeploymentTarget( 511 targetName, referenceName, true); 512 513 InstanceEnvironment env = 514 ApplicationServer.getServerContext().getInstanceEnvironment(); 515 DeploymentRequest req = new DeploymentRequest( 516 env, 517 type, 518 DeploymentCommand.UNDEPLOY); 519 520 req.setName(referenceName); 521 req.setTarget(target); 522 523 DeploymentProperties dProps = new DeploymentProperties(options); 524 req.setCascade(dProps.getCascade()); 525 req.setForced(dProps.getForce()); 526 DeploymentServiceUtils.setResourceOptionsInRequest(req, dProps); 527 528 return disassociate(req, createAuditInfoIfOn(req, AuditInfo.Operation.disassociate, startTime)); 529 } catch(Exception e) { 530 if (e instanceof IASDeploymentException) { 531 throw (IASDeploymentException)e; 532 } 533 else { 534 throw new IASDeploymentException(e); 535 } 536 } 537 } 538 539 private DeploymentStatus start(DeploymentRequest req, AuditInfo auditInfo) 540 { 541 DeploymentStatus result = executePhases(req, startPhaseList); 542 if (auditInfo != null) { 543 auditInfo.reportEnd(result.getStatus()); 544 } 545 return result; 546 } 547 548 public DeploymentStatus start(DeploymentRequest req) { 549 return start(req, createAuditInfoIfOn(req, AuditInfo.Operation.start)); 550 } 551 552 public DeploymentStatus start(String moduleID, String targetName, 553 Map options) throws IASDeploymentException { 554 try { 555 long startTime = System.currentTimeMillis(); 556 DeployableObjectType type = 557 DeploymentServiceUtils.getRegisteredType(moduleID); 558 559 final DeploymentTarget target = 560 DeploymentServiceUtils.getDeploymentTarget(targetName); 561 562 InstanceEnvironment env = 563 ApplicationServer.getServerContext().getInstanceEnvironment(); 564 DeploymentRequest req = new DeploymentRequest( 565 env, 566 type, 567 DeploymentCommand.DEPLOY); 568 569 int actionCode; 570 if(type.isAPP()) { 571 actionCode = BaseDeployEvent.APPLICATION_DEPLOYED; 572 } 573 else { 574 actionCode = BaseDeployEvent.MODULE_DEPLOYED; 575 } 576 577 req.setName(moduleID); 578 req.setActionCode(actionCode); 579 req.setTarget(target); 580 581 DeploymentProperties dProps = new DeploymentProperties(options); 582 req.setForced(dProps.getForce()); 583 DeploymentServiceUtils.setResourceOptionsInRequest(req, dProps); 584 585 return start(req, createAuditInfoIfOn(req, AuditInfo.Operation.start, startTime)); 586 } catch(Exception e) { 587 if (e instanceof IASDeploymentException) { 588 throw (IASDeploymentException)e; 589 } 590 else { 591 throw new IASDeploymentException(e); 592 } 593 } 594 } 595 596 private DeploymentStatus stop(DeploymentRequest req, AuditInfo auditInfo) 597 throws IASDeploymentException { 598 String moduleID = req.getName(); 599 DeployableObjectType type = req.getType(); 600 boolean isRegistered = 601 DeploymentServiceUtils.isRegistered(moduleID, type); 602 if (isRegistered) { 603 DeploymentServiceUtils.validate(moduleID,type,STOP_ACTION); 604 } 605 606 DeploymentStatus result = executePhases(req, stopPhaseList); 607 if (auditInfo != null) { 608 auditInfo.reportEnd(result.getStatus()); 609 } 610 return result; 611 } 612 613 public DeploymentStatus stop(DeploymentRequest req) 614 throws IASDeploymentException { 615 return stop(req, createAuditInfoIfOn(req, AuditInfo.Operation.stop)); 616 } 617 618 public DeploymentStatus stop(String moduleID, String targetName, 619 Map options) throws IASDeploymentException { 620 try { 621 long startTime = System.currentTimeMillis(); 622 DeployableObjectType type = 623 DeploymentServiceUtils.getRegisteredType(moduleID); 624 625 final DeploymentTarget target = 626 DeploymentServiceUtils.getDeploymentTarget(targetName); 627 628 InstanceEnvironment env = 629 ApplicationServer.getServerContext().getInstanceEnvironment(); 630 DeploymentRequest req = new DeploymentRequest( 631 env, 632 type, 633 DeploymentCommand.UNDEPLOY); 634 635 int actionCode; 636 if(type.isAPP()) { 637 actionCode = BaseDeployEvent.APPLICATION_UNDEPLOYED; 638 } 639 else { 640 actionCode = BaseDeployEvent.MODULE_UNDEPLOYED; 641 } 642 643 req.setName(moduleID); 644 req.setActionCode(actionCode); 645 req.setTarget(target); 646 647 DeploymentProperties dProps = new DeploymentProperties(options); 648 req.setCascade(dProps.getCascade()); 649 req.setForced(dProps.getForce()); 650 DeploymentServiceUtils.setResourceOptionsInRequest(req, dProps); 651 652 return stop(req, createAuditInfoIfOn(req, AuditInfo.Operation.stop, startTime)); 653 } catch(Exception e) { 654 if (e instanceof IASDeploymentException) { 655 throw (IASDeploymentException)e; 656 } 657 else { 658 throw new IASDeploymentException(e); 659 } 660 } 661 } 662 663 664 668 public DeploymentStatus deploy(File deployFile, File planFile, 669 String archiveName, String moduleID, DeploymentProperties dProps, 670 DeploymentCallback callback) throws IASDeploymentException { 671 try { 672 if (deployFile == null) { 673 throw new IASDeploymentException( 674 localStrings.getString("deployfile_not_specified")); 675 } 676 677 681 long startTime = System.currentTimeMillis(); 682 sLogger.log(Level.FINE, "mbean.begin_deploy", moduleID); 683 DeployableObjectType type = null; 684 if (dProps.getType() != null) { 685 type = DeploymentServiceUtils.getDeployableObjectType(dProps.getType()); 686 } else { 687 type = DeploymentServiceUtils.getTypeFromFile( 688 moduleID, deployFile.getAbsolutePath()); 689 } 690 691 InstanceEnvironment env = 692 ApplicationServer.getServerContext().getInstanceEnvironment(); 693 DeploymentRequest req = new DeploymentRequest( 694 env, 695 type, 696 DeploymentCommand.DEPLOY); 697 698 DeploymentRequestRegistry.getRegistry().addDeploymentRequest( 699 moduleID, req); 700 701 req.setName(moduleID); 702 boolean isRegistered = false; 703 isRegistered = DeploymentServiceUtils.isRegistered(moduleID, type); 704 706 if (isRegistered) { 707 DeploymentServiceUtils.validate(moduleID,type,REDEPLOY_ACTION); 708 } 709 710 req.setFileSource(deployFile); 711 req.setDeploymentPlan(planFile); 712 req.setForced(dProps.getForce()); 713 if(type.isWEB()) { 714 req.setDefaultContextRoot(dProps.getDefaultContextRoot( 715 archiveName)); 716 req.setContextRoot(dProps.getContextRoot()); 717 } 718 req.setVerifying(dProps.getVerify()); 719 req.setPrecompileJSP(dProps.getPrecompileJSP()); 720 req.setGenerateRMIStubs(dProps.getGenerateRMIStubs()); 721 req.setAvailabilityEnabled(dProps.getAvailabilityEnabled()); 722 req.setStartOnDeploy(dProps.getEnable()); 723 req.setDescription(dProps.getDescription()); 724 req.setLibraries(dProps.getLibraries()); 725 req.setJavaWebStartEnabled(dProps.getJavaWebStartEnabled()); 726 req.setDeploymentCallback(callback); 727 DeploymentServiceUtils.setResourceOptionsInRequest(req, dProps); 728 729 Properties optionalAttributes = new Properties (); 730 String virtualServers = dProps.getVirtualServers(); 731 if(virtualServers!=null) { 732 optionalAttributes.put(ServerTags.VIRTUAL_SERVERS, 733 virtualServers); 734 } 735 req.setOptionalAttributes(optionalAttributes); 736 737 req.addOptionalArguments(dProps.prune()); 738 DeploymentServiceUtils.setHostAndPort(req); 739 return deploy(req, createAuditInfoIfOn(req, AuditInfo.Operation.deploy, startTime)); 740 } catch(Exception e) { 741 sLogger.log(Level.WARNING, "mbean.deploy_failed", e); 742 if (e instanceof IASDeploymentException) { 743 throw (IASDeploymentException)e; 744 } 745 else { 746 throw new IASDeploymentException(e); 747 } 748 } 749 } 750 751 756 public DeploymentStatus undeploy(String mModuleID, 757 Map mParams) throws IASDeploymentException { 758 sLogger.log(Level.FINE, "mbean.begin_undeploy", mModuleID); 759 try { 760 764 long startTime = System.currentTimeMillis(); 765 DeployableObjectType objectType = 766 DeploymentServiceUtils.getRegisteredType(mModuleID); 767 768 DeploymentServiceUtils.checkAppReferencesBeforeUndeployFromDomain( 769 mModuleID); 770 771 DeploymentServiceUtils.validate(mModuleID, objectType, UNDEPLOY_ACTION); 772 773 if (objectType.isWEB()) { 774 DeploymentServiceUtils.checkWebModuleReferences(mModuleID); 775 } 776 777 InstanceEnvironment env = 778 ApplicationServer.getServerContext().getInstanceEnvironment(); 779 DeploymentRequest req = new DeploymentRequest(env, 780 objectType, DeploymentCommand.UNDEPLOY); 781 782 DeploymentRequestRegistry.getRegistry().addDeploymentRequest( 783 mModuleID, req); 784 785 DeploymentProperties dProps = 786 new DeploymentProperties(mParams); 787 req.setName(mModuleID); 788 req.setCascade(dProps.getCascade()); 789 790 DeploymentServiceUtils.setResourceOptionsInRequest(req, dProps); 791 792 req.addOptionalArguments(dProps.prune()); 793 return undeploy(req, createAuditInfoIfOn(req, AuditInfo.Operation.undeploy, startTime)); 794 } 795 catch(Exception e) { 796 String msg = localStrings.getString( 797 "enterprise.deployment.phasing.deploymentservice.undeploy.failed", 798 mModuleID, e.getLocalizedMessage()); 799 sLogger.log(Level.WARNING, msg); 800 if (e instanceof IASDeploymentException) { 801 throw (IASDeploymentException)e; 802 } 803 else { 804 IASDeploymentException ias = 805 new IASDeploymentException(e.getLocalizedMessage()); 806 ias.initCause(e); 807 throw ias; 808 } 809 } 810 } 811 812 public boolean quit(String moduleID) { 813 DeploymentRequest request = DeploymentRequestRegistry.getRegistry().getDeploymentRequest(moduleID); 814 if (request != null) { 815 request.setAbort(true); 816 return true; 817 } else { 818 return false; 819 } 820 } 821 822 825 public static String getClientJarPath(String moduleID) { 826 827 ClientJarMakerRegistry registry = ClientJarMakerRegistry.getInstance(); 829 830 if (registry.isRegistered(moduleID)) { 831 832 registry.waitForCompletion(moduleID); 834 } 835 836 return moduleID + DeploymentImplConstants.ClientJarSuffix; 837 838 } 839 840 853 protected DeploymentStatus executePhases(DeploymentRequest req, List phases) 854 { 855 try { 856 Descriptor.setBoundsChecking(true); 857 858 DeploymentStatus ds = new DeploymentStatus(); 860 ds.setStageDescription("Deployment"); 861 req.setCurrentDeploymentStatus(ds); 862 863 DeploymentPhaseContext phaseCtx[] = new DeploymentPhaseContext[phases.size()]; 864 for(int i=0 ; i < phases.size() ; i++) 865 { 866 try{ 867 DeploymentStatus phaseDs = new DeploymentStatus(ds); 869 870 phaseCtx[i] = ((DeploymentPhase)phases.get(i)).executePhase(req, phaseDs); 872 873 if (phaseDs.getStageStatus()<DeploymentStatus.WARNING) { 876 rollbackPhases(phases, phaseCtx, i-1); 877 return ds; 879 } 880 881 } catch(Throwable dpe) { 882 886 String msg = 887 localStrings.getString( "enterprise.deployment.phasing.deploymentservice.exception"); 888 sLogger.log(Level.SEVERE, msg ,dpe); 889 rollbackPhases(phases, phaseCtx, i-1); 890 891 ds.setStageStatus(DeploymentStatus.FAILURE); 894 if (dpe instanceof java.io.Serializable ) { 895 ds.setStageException(dpe); 896 } else { 897 sLogger.severe(localStrings.getString("enterprise.deployment.phasing.exception_notserializable", dpe.getClass())); 898 sLogger.severe(localStrings.getString("enterprise.deployment.phasing.exception_notforwarded", dpe.getMessage())); 899 } 900 ds.setStageException(dpe); 901 ds.setStageStatusMessage(dpe.getMessage()); 902 return ds; 903 } 904 } 905 return ds; 908 } finally { 909 req.done(); 910 } 911 } 912 913 916 private void rollbackPhases(List phases, DeploymentPhaseContext phaseCtx[], int index) { 917 for (int j=index; j>=0 ; j--) { 919 try { 920 ((DeploymentPhase)phases.get(j)).rollback(phaseCtx[j]); 921 } catch(Exception rollbackException) { 922 String msg = 924 localStrings.getString( "enterprise.deployment.phasing.deploymentservice.rollbackexception"); 925 sLogger.log(Level.INFO, msg ,rollbackException); 926 929 } 930 } 931 932 } 933 934 950 public String getModuleIDFromDD (File file) throws Exception { 951 Archivist source = ArchivistFactory.getArchivistForArchive(file); 952 InputJarArchive archive = new InputJarArchive(); 953 archive.open(file.getAbsolutePath()); 954 Descriptor descriptor = null; 955 String moduleID = null; 956 String displayName = null; 957 try { 958 descriptor = source.readStandardDeploymentDescriptor(archive); 959 } catch (Exception ex) {} 960 if (descriptor != null) { 961 displayName = descriptor.getDisplayName(); 962 } 963 if ((displayName != null) && (displayName.length() > 0)) { 964 moduleID = displayName; 965 } else { 966 moduleID = 968 (new DeploymentProperties()).getName(file.getAbsolutePath()); 969 } 970 971 moduleID = moduleID.replace(' ','_'); 972 973 moduleID = moduleID.replace('\\', '_').replace('/', '_'); 977 moduleID = moduleID.replace(':', '_').replace('*', '_'); 978 moduleID = moduleID.replace('?', '_').replace('"', '_'); 979 moduleID = moduleID.replace('<', '_').replace('>', '_'); 980 moduleID = moduleID.replace('|', '_'); 981 982 moduleID = moduleID.replace(',', '_').replace('=', '_'); 986 987 return moduleID; 988 } 989 990 996 private AuditInfo createAuditInfoIfOn(DeploymentRequest req, AuditInfo.Operation operation) { 997 return auditLogger.isLoggable(Level.INFO) ? new AuditInfo(req, operation, System.currentTimeMillis()) : null; 998 } 999 1000 1007 private AuditInfo createAuditInfoIfOn(DeploymentRequest req, AuditInfo.Operation operation, long startTime) { 1008 return auditLogger.isLoggable(Level.INFO) ? new AuditInfo(req, operation, startTime) : null; 1009 } 1010 1011 1015 private static class AuditInfo { 1016 1017 1018 private static final String START_MESSAGE_KEY = "audit.start.message"; 1019 private static final String END_MESSAGE_KEY = "audit.end.message"; 1020 1021 1026 enum Outcome {end(DeploymentStatus.SUCCESS), warning(DeploymentStatus.WARNING), fail(DeploymentStatus.FAILURE); 1027 private int deploymentStatus; 1028 1029 Outcome(int deploymentStatus) { 1030 this.deploymentStatus = deploymentStatus; 1031 } 1032 1033 private boolean matches(int deploymentStatus) { 1034 return (deploymentStatus == this.deploymentStatus); 1035 } 1036 1037 private String getAuditMessage() { 1038 return auditBundle.getString("audit.outcome." + toString()); 1039 } 1040 } 1041 1042 1046 enum Operation {deploy, undeploy, associate, disassociate, start, stop; 1047 private String getAuditMessage() { 1048 return auditBundle.getString("audit.operation." + toString()); 1049 1050 } 1051 1052 } 1053 1054 1055 private long startTime; 1056 1057 1058 private String principal; 1059 1060 1061 private DeploymentRequest request; 1062 1063 1066 private Operation operation; 1067 1068 1075 private AuditInfo(DeploymentRequest req, Operation operation, long startTime) { 1076 request = req; 1077 this.startTime = startTime; 1078 this.operation = operation; 1079 principal = "Unknown"; 1080 AccessControlContext acc = AccessController.getContext(); 1081 Subject subject = Subject.getSubject(acc); 1082 if (subject == null) { 1083 1084 } else { 1085 Iterator iter = subject.getPrincipals().iterator(); 1086 if (iter.hasNext()) { 1088 Principal p = (Principal ) iter.next(); 1089 principal = p.getName(); 1090 } 1091 } 1092 auditLogger.log(Level.INFO, START_MESSAGE_KEY, new String []{ principal, operation.getAuditMessage(), request.getName(), request.getType().toString() } ); 1093 } 1094 1095 1099 private void reportEnd(int deploymentStatus) { 1100 auditLogger.log(Level.INFO, END_MESSAGE_KEY, computeEndParameters(findOutcome(deploymentStatus))); 1101 } 1102 1103 private Outcome findOutcome(int deploymentStatus) { 1104 Outcome result = null; 1105 for (Outcome outcome : Outcome.values() ) { 1106 if (outcome.matches(deploymentStatus) ) { 1107 result = outcome; 1108 break; 1109 } 1110 } 1111 if (result == null) { 1112 throw new IllegalArgumentException ("Deployment status value of " + deploymentStatus + " could not be mapped to an audit outcome"); 1113 } 1114 return result; 1115 } 1116 1117 1121 private String [] computeEndParameters(Outcome outcome) { 1122 String [] result = new String [] 1123 {principal, 1124 operation.getAuditMessage(), 1125 outcome.getAuditMessage(), 1126 request.getName(), 1127 request.getType().toString(), 1128 String.valueOf(System.currentTimeMillis() - startTime) 1129 }; 1130 return result; 1131 } 1132 } 1133} 1134 | Popular Tags |