1 23 24 29 30 package com.sun.enterprise.deployment.backend; 31 32 import java.io.*; 33 import java.util.Set ; 34 import java.util.List ; 35 import java.util.logging.*; 36 import java.util.Properties ; 37 import javax.enterprise.deploy.shared.ModuleType ; 38 39 import com.sun.ejb.codegen.IASEJBCTimes; 40 import com.sun.enterprise.instance.ModuleEnvironment; 41 import com.sun.enterprise.instance.WebModulesManager; 42 import com.sun.enterprise.instance.InstanceEnvironment; 43 import com.sun.enterprise.instance.BaseManager; 44 import com.sun.enterprise.config.ConfigException; 45 import com.sun.enterprise.config.serverbeans.ServerTags; 46 import com.sun.enterprise.util.io.FileUtils; 47 import com.sun.enterprise.util.io.FileSource; 48 import com.sun.enterprise.util.zip.ZipItem; 49 import com.sun.enterprise.util.i18n.StringManager; 50 import com.sun.enterprise.server.Constants; 51 import com.sun.enterprise.loader.EJBClassPathUtils; 52 import com.sun.enterprise.deployment.Application; 53 import com.sun.enterprise.deployment.BundleDescriptor; 54 import com.sun.enterprise.deployment.WebServiceEndpoint; 55 import com.sun.enterprise.deployment.WebServicesDescriptor; 56 import com.sun.enterprise.deployment.WebService; 57 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 58 import com.sun.enterprise.deployment.deploy.shared.FileArchiveFactory; 59 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 60 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 61 import com.sun.enterprise.deployment.archivist.Archivist; 62 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils; 63 64 import com.sun.enterprise.tools.verifier.AppVerifier; 66 67 73 74 public abstract class ModuleDeployer extends Deployer 75 { 76 abstract protected BaseManager createConfigManager(InstanceEnvironment ienv, ModuleEnvironment menv) throws IASDeploymentException, ConfigException; 77 abstract protected void preDeploy() throws IASDeploymentException; 78 abstract protected void deploy() throws IASDeploymentException, ConfigException; 79 abstract protected void preRedeploy() throws IASDeploymentException, ConfigException; 80 81 83 protected ModuleDeployer(DeploymentRequest r) throws IASDeploymentException 84 { 85 super(r); 86 } 87 88 90 protected boolean needsStubs() 91 { 92 return false; 94 } 95 96 98 protected boolean needsJSPs() 99 { 100 return false; 102 } 103 104 106 protected final File getModuleDir() 107 { 108 return moduleDir; 109 } 110 111 113 public void doRequest() throws IASDeploymentException 114 { 115 doRequestPrepare(); 116 doRequestFinish(); 117 } 118 119 121 public void doRequestPrepare() throws IASDeploymentException 122 { 123 try 124 { 125 begin(); 126 } 127 catch(Exception e) 128 { 129 if(shouldRollback) 130 rollback(); 131 132 String msg = localStrings.getString( 133 "enterprise.deployment.backend.dorequest_exception"); 134 logger.log(Level.WARNING, msg, e); 135 throw new IASDeploymentException(msg, e); 136 } 137 } 138 139 141 public void doRequestFinish() throws IASDeploymentException 142 { 143 try 144 { 145 if(request.isDeploy()) 146 { 147 DeploymentStatus J2EECPhaseStatus = 149 request.getCurrentDeploymentStatus(); 150 151 beginFinish(); 152 preDeploy(); 153 154 DeploymentStatus runEJBCStatus = 157 new DeploymentStatus(J2EECPhaseStatus); 158 request.setCurrentDeploymentStatus( 159 runEJBCStatus); 160 deploy(); 161 register(); 162 163 DeploymentStatus postDeployStatus = 166 new DeploymentStatus(J2EECPhaseStatus); 167 request.setCurrentDeploymentStatus( 168 postDeployStatus); 169 postDeploy(); 170 171 generatePolicy(); 172 } 173 else if(request.isReDeploy()) 174 { 175 DeploymentStatus J2EECPhaseStatus = 177 request.getCurrentDeploymentStatus(); 178 179 beginFinish(); 180 preRedeploy(); 181 182 DeploymentStatus runEJBCStatus = 185 new DeploymentStatus(J2EECPhaseStatus); 186 request.setCurrentDeploymentStatus( 187 runEJBCStatus); 188 redeploy(); 189 register(); 190 191 DeploymentStatus postDeployStatus = 194 new DeploymentStatus(J2EECPhaseStatus); 195 request.setCurrentDeploymentStatus( 196 postDeployStatus); 197 postRedeploy(); 198 199 generatePolicy(); 200 } 201 else if(request.isUnDeploy()) 202 { 203 beginFinish(); 204 preundeploy(); 205 undeploy(); 206 removePolicy(); 207 } 208 else 209 { 210 String msg = localStrings.getString( 211 "enterprise.deployment.backend.unknown_deployment_command" ); 212 throw new IASDeploymentException( msg ); 213 } 214 } 215 catch(Exception e) 216 { 217 if(shouldRollback) 218 rollback(); 219 220 String msg = localStrings.getString( 221 "enterprise.deployment.backend.dorequest_exception"); 222 logger.log(Level.FINE, msg, e); 223 if (e instanceof IASDeploymentException) { 224 throw (IASDeploymentException) e; 225 } else { 226 throw new IASDeploymentException(msg, e); 227 } 228 } 229 finally 230 { 231 finish(); 232 } 233 } 234 235 protected final void begin() throws IASDeploymentException 238 { 239 super.begin(); 240 241 243 InstanceEnvironment instanceEnv = getInstanceEnv(); 244 moduleEnv = request.getModuleEnv(); 245 moduleName = request.getName(); 246 247 249 if(moduleEnv == null) 250 { 251 String msg = localStrings.getString("enterprise.deployment.backend.null_moduleenvironment"); 252 throw new IASDeploymentException(msg); 253 } 254 255 try 256 { 257 moduleEnv.verify(); 258 modulesMgr = createConfigManager(instanceEnv, moduleEnv); 259 setDeployCommand(); 260 261 if(request.isReDeploy()) 262 { 263 originalModuleDir = new File(DeploymentServiceUtils.getLocation(moduleName, request.getType())); 264 unregister(); 265 removePolicy(); 266 } 267 } 268 catch(Exception e) 269 { 270 throw new IASDeploymentException(e); 271 } 272 273 shouldRollback = true; 274 275 } 278 279 281 284 private void beginFinish() throws IASDeploymentException 285 { 286 setDirs(); 287 } 288 289 291 private void setDirs() throws IASDeploymentException 292 { 293 assert modulesMgr != null; 294 assert moduleName != null; 295 assert moduleEnv != null; 296 297 if(request.isDeploy()) 298 setDirsDeploy(); 299 else if(request.isReDeploy()) 300 setDirsReDeploy(); 301 else if(request.isUnDeploy()) 302 setDirsUnDeploy(); 303 else 304 { 305 String msg = localStrings.getString( 306 "enterprise.deployment.backend.deployment_type_error" ); 307 throw new IASDeploymentException( msg ); 308 } 309 310 request.setDeployedDirectory(moduleDir); 311 request.setJSPDirectory(jspDir); 312 request.setStubsDirectory(stubsDir); 313 request.setGeneratedXMLDirectory(xmlDir); 314 } 315 316 319 protected List getModuleClasspath(Archivist archivist, 320 AbstractArchive archive) throws IASDeploymentException { 321 try { 322 String location = request.getDeployedDirectory().getAbsolutePath(); 323 return EJBClassPathUtils.getModuleClasspath(request.getName(), location, this.getManager()); 324 } catch(Exception e) { 325 throw new IASDeploymentException(e); 326 } 327 } 328 329 331 private void setDirsDeploy() throws IASDeploymentException 332 { 333 if(isRegistered()) 334 { 335 String msg = localStrings.getString( 336 "enterprise.deployment.backend.deploy_error_module_exists" ); 337 throw new IASDeploymentException( msg ); 338 } 339 xmlDir = new File(moduleEnv.getModuleGeneratedXMLPath()); 340 jwsDir = new File(moduleEnv.getJavaWebStartPath()); 341 342 if(needsStubs()) 343 { 344 stubsDir = new File(moduleEnv.getModuleStubPath()); 345 } 346 else 347 stubsDir = null; 348 349 if(needsJSPs()) 350 { 351 assert (modulesMgr instanceof WebModulesManager); 352 jspDir = new File(moduleEnv.getModuleJSPPath()); 353 } 354 if(isArchive()) 355 { 356 File parent = new File(getInstanceEnv().getModuleRepositoryPath()); 357 moduleDir = new File(parent, moduleName); 358 moduleDir.mkdirs(); 359 } 360 else if(isDirectory()) 361 { 362 FileSource fileSource = request.getFileSource(); 363 364 if(fileSource == null || !fileSource.exists()) 365 { 366 String msg = localStrings.getString( 367 "enterprise.deployment.backend.file_source_does_not_exist", 368 fileSource ); 369 throw new IASDeploymentException( msg ); 370 } 371 372 moduleDir = fileSource.getFile(); 373 374 if(!FileUtils.safeIsDirectory(moduleDir)) 375 { 376 String msg = localStrings.getString( 377 "enterprise.deployment.backend.deployment_directory_does_not_exist", 378 moduleDir.getPath() ); 379 throw new IASDeploymentException( msg ); 380 } 381 } 382 else 383 { 384 String msg = localStrings.getString( 385 "enterprise.deployment.backend.deployment_not_dir_or_archive" ); 386 throw new IASDeploymentException( msg ); 387 } 388 } 389 390 394 protected Application loadDescriptors() throws IASDeploymentException { 395 Application app = super.loadDescriptors(); 396 (new com.sun.enterprise.webservice.WsUtil()).genWSInfo(app, request); 397 return app; 398 } 399 400 402 private void setDirsUnDeploy() throws IASDeploymentException 403 { 404 try 406 { 407 if(!isRegistered()) 408 { 409 String msg = localStrings.getString( 410 "enterprise.deployment.backend.undeploy_error_module_not_registered" ); 411 throw new IASDeploymentException( msg ); 412 } 413 414 moduleDir = new File(DeploymentServiceUtils.getLocation(moduleName, request.getType())); 415 xmlDir = new File(modulesMgr.getGeneratedXMLLocation(moduleName)); 416 jwsDir = new File(moduleEnv.getJavaWebStartPath()); 417 stubsDir = null; 418 jspDir = null; 419 420 if(needsStubs()) 421 stubsDir = new File(modulesMgr.getStubLocation(moduleName)); 422 if(needsJSPs()) 423 { 424 assert (modulesMgr instanceof WebModulesManager); 425 WebModulesManager mgr = (WebModulesManager)modulesMgr; 426 jspDir = new File(mgr.getJSPLocation(moduleName)); 427 } 428 } 429 catch(Exception e) 430 { 431 String msg = localStrings.getString( 432 "enterprise.deployment.backend.error_getting_module_directory", 433 e ); 434 throw new IASDeploymentException( msg ); 435 } 436 } 437 438 440 private void setDirsReDeploy() throws IASDeploymentException 441 { 442 if(!wasReg) 443 { 444 String msg = localStrings.getString( 445 "enterprise.deployment.backend.redeploy_error_module_not_registered" ); 446 throw new IASDeploymentException( msg ); 447 } 448 449 xmlDir = new File(modulesMgr.getGeneratedXMLLocation(moduleName)); 450 jwsDir = new File(moduleEnv.getJavaWebStartPath()); 451 452 stubsDir = null; 454 jspDir = null; 455 456 if(needsStubs()) { 457 stubsDir = new File(modulesMgr.getStubLocation(moduleName)); 458 } 459 if(needsJSPs()) 460 { 461 assert (modulesMgr instanceof WebModulesManager); 462 WebModulesManager mgr = (WebModulesManager)modulesMgr; 463 jspDir = new File(mgr.getJSPLocation(moduleName)); 464 } 465 466 if(isArchive()) 467 { 468 if(!FileUtils.safeIsDirectory(originalModuleDir)) 470 { 471 String msg = localStrings.getString( 472 "enterprise.deployment.backend.modulesmanager_error_getting_module_location", 473 moduleName ); 474 throw new IASDeploymentException(msg); 475 } 476 477 moduleDir = originalModuleDir; 478 oldModuleDir = new File(moduleDir.getAbsolutePath() + "_old"); 479 480 481 482 FileUtils.whack(oldModuleDir); 484 485 486 moduleDirWasRenamed = FileUtils.renameFile(moduleDir,oldModuleDir); 489 490 491 if(!moduleDirWasRenamed) 492 493 494 { 495 String msg = localStrings.getString("enterprise.deployment.backend.directory_rename_error", 496 moduleDir.getAbsolutePath(), oldModuleDir.getAbsolutePath()); 497 throw new IASDeploymentException(msg); 498 } 499 } 500 else if(isDirectory()) 501 { 502 FileSource fileSource = request.getFileSource(); 503 504 if(!fileSource.exists()) 505 { 506 String msg = localStrings.getString( 507 "enterprise.deployment.backend.file_source_does_not_exist", 508 fileSource ); 509 throw new IASDeploymentException( msg ); 510 } 511 512 assert fileSource.isDirectory(); 513 moduleDir = fileSource.getFile(); 514 515 oldModuleDir = new File(moduleEnv.getModuleBackupPath()); 516 517 if (!FileUtils.safeIsDirectory(oldModuleDir)) 518 { 519 oldModuleDir = null; 520 } 521 } 522 else 523 { 524 String msg = localStrings.getString( 525 "enterprise.deployment.backend.redeployment_not_dir_or_archive" ); 526 throw new IASDeploymentException( msg ); 527 } 528 529 moduleDir.mkdirs(); 530 } 531 532 536 public void cleanup_internal() 537 { 538 try 539 { 540 if(request.isUnDeploy()) 541 { 542 if(isMaybeCMPDropTables) 543 dropTables(); 544 545 liquidate(); 546 } 547 548 else if(request.isReDeploy() && isArchive() && oldModuleDir != null) 551 { 552 FileUtils.whack(oldModuleDir); 553 } 554 555 } 557 catch(Exception e) 558 { 559 logger.warning("Exception caught and ignored in cleanup_internal()"); 560 } 561 } 562 563 564 566 protected void liquidate() throws IASDeploymentException, ConfigException 567 { 568 assert !request.isReDeploy(); assert moduleDir != null; 570 571 boolean shouldDeleteModuleFiles = false; 572 573 if(request.isDeploy() && isArchive()) 574 { 575 shouldDeleteModuleFiles = true; 576 } 577 else if(request.isUnDeploy() && !(DeploymentServiceUtils.isDirectoryDeployed(request.getName(), request.getType()) || request.isReload()) ) 578 { 579 shouldDeleteModuleFiles = true; 580 } 581 582 if(shouldDeleteModuleFiles) 583 { 584 if(FileUtils.safeIsDirectory(moduleDir)) 585 { 586 FileUtils.whack(moduleDir); 587 logger.fine("Deleted module Directory: " + moduleDir.getPath()); 588 } 589 else 590 { 591 logger.warning("Can't delete module Directory -- it isn't a directory: " 592 + FileUtils.safeGetCanonicalPath(moduleDir)); 593 } 594 } 595 else 596 { 597 logger.fine("Did NOT delete module Directory (Directory-Deployment): " + moduleDir.getPath()); 598 } 599 600 DeleteOrKeepFailedStubs(stubsDir); 601 602 if(FileUtils.safeIsDirectory(jspDir)) 603 { 604 FileUtils.whack(jspDir); 605 } 606 607 if(FileUtils.safeIsDirectory(xmlDir)) 608 { 609 FileUtils.whack(xmlDir); 610 } 611 if(FileUtils.safeIsDirectory(jwsDir)) 612 { 613 FileUtils.whack(jwsDir); 614 } 615 } 616 617 619 620 protected void preundeploy() throws IASDeploymentException, ConfigException 621 { 622 624 if(getRequest().isMaybeCMPDropTables()) 625 { 626 isMaybeCMPDropTables = true; 627 } 628 } 629 630 632 private void undeploy() throws IASDeploymentException, ConfigException 633 { 634 if(!isRegistered()) 635 { 636 String msg = localStrings.getString( 637 "enterprise.deployment.backend.undeploy_error_module_not_registered" ); 638 throw new IASDeploymentException( msg ); 639 } 640 641 try 642 { 643 unregister(); 644 } 645 catch(ConfigException e) 646 { 647 String msg = localStrings.getString( 648 "enterprise.deployment.backend.config_exception_on_remove", 649 moduleName, e ); 650 throw new IASDeploymentException( msg, e); 651 } 652 } 653 654 656 private void rollbackUndeploy() throws ConfigException 657 { 658 } 661 662 664 protected void postDeploy() throws IASDeploymentException, ConfigException 665 { 666 Properties optionalAttributes = request.getOptionalAttributes(); 668 if (optionalAttributes == null) { 669 optionalAttributes = new Properties (); 670 } 671 String resourceType = getResourceType(moduleDir); 672 if(resourceType != null) { 673 optionalAttributes.setProperty(ServerTags.OBJECT_TYPE, 674 resourceType); 675 } 676 677 handlePostDeployEvent(); 678 } 679 680 684 protected void handlePostDeployEvent() throws IASDeploymentException 685 { 686 DeploymentEventInfo info = getEventInfo(); 687 DeploymentEvent ev = new DeploymentEvent( 688 DeploymentEventType.POST_DEPLOY, info); 689 DeploymentEventManager.notifyDeploymentEvent(ev); 690 691 } 692 693 697 protected DeploymentEventInfo getEventInfo() throws IASDeploymentException 698 { 699 return new DeploymentEventInfo(moduleDir, stubsDir, oldStubsDir, 700 request.getDescriptor(), getRequest()); 701 } 702 703 705 protected final void rollbackDeploy() throws IASDeploymentException 706 { 707 try 710 { 711 if(wasRegisteredThisSession) 712 { 713 unregister(); 716 } 717 718 liquidate(); 719 } 720 catch(ConfigException e) 721 { 722 } 724 } 725 726 728 protected final void redeploy() throws IASDeploymentException, ConfigException 729 { 730 deploy(); } 732 733 735 private void rollback() 736 { 737 740 try 741 { 742 if(request.isDeploy()) 743 rollbackDeploy(); 744 else if(request.isReDeploy()) 745 { 746 if(request.isArchive()) 749 rollbackRedeploy(); 750 else 751 request.setReRegisterOnFailure(false); 752 } 753 else if(request.isUnDeploy()) 754 rollbackUndeploy(); 755 } 756 catch(Throwable t) 757 { 758 } 760 } 761 762 764 protected void register() throws IASDeploymentException, ConfigException 765 { 766 modulesMgr.registerDescriptor(moduleName, request.getDescriptor()); 767 wasRegisteredThisSession = true; 768 } 769 770 772 protected void liquidateModuleDirAndStubsDirIfTheyHappenToExist() throws IASDeploymentException 773 { 774 if(request.isArchive() && FileUtils.safeIsDirectory(moduleDir)) 775 { 776 FileUtils.whack(moduleDir); 777 778 if(FileUtils.safeIsDirectory(moduleDir)) 779 { 780 String msg = localStrings.getString( 781 "enterprise.deployment.backend.deploy_error_dir_is_locked", 782 "Module", moduleDir.getAbsolutePath()); 783 throw new IASDeploymentException( msg ); 784 } 785 } 786 787 788 if(FileUtils.safeIsDirectory(stubsDir)) 789 { 790 FileUtils.whack(stubsDir); 791 792 if(FileUtils.safeIsDirectory(stubsDir)) 793 { 794 String msg = localStrings.getString( 795 "enterprise.deployment.backend.deploy_error_dir_is_locked", 796 "Stubs", stubsDir.getAbsolutePath()); 797 throw new IASDeploymentException( msg ); 798 } 799 } 800 801 if(FileUtils.safeIsDirectory(jspDir)) 802 { 803 FileUtils.whack(jspDir); 804 805 if(FileUtils.safeIsDirectory(jspDir)) 806 { 807 String msg = localStrings.getString( 808 "enterprise.deployment.backend.deploy_error_dir_is_locked", 809 "JSP", jspDir.getAbsolutePath()); 810 throw new IASDeploymentException( msg ); 811 } 812 } 813 814 if(FileUtils.safeIsDirectory(xmlDir)) 815 { 816 FileUtils.whack(xmlDir); 817 818 if(FileUtils.safeIsDirectory(xmlDir)) 819 { 820 String msg = localStrings.getString( 821 "enterprise.deployment.backend.deploy_error_dir_is_locked", 822 "XML", xmlDir.getAbsolutePath()); 823 throw new IASDeploymentException( msg ); 824 } 825 } 826 if(FileUtils.safeIsDirectory(jwsDir)) 827 { 828 FileUtils.whack(jwsDir); 829 830 if(FileUtils.safeIsDirectory(jwsDir)) 831 { 832 String msg = localStrings.getString( 833 "enterprise.deployment.backend.deploy_error_dir_is_locked", 834 "JWS", jwsDir.getAbsolutePath()); 835 throw new IASDeploymentException( msg ); 836 } 837 } 838 } 839 840 842 protected void setOldDirs() throws IASDeploymentException 843 { 844 assert moduleDir != null; 845 assert moduleEnv != null; 846 assert request.isReDeploy(); 848 850 if(needsStubs() && stubsDir != null && stubsDir.exists() && stubsDir.isDirectory()) 851 { 852 oldStubsDir = new File(stubsDir.getPath() + "_old"); 853 854 if(oldStubsDir.exists()) 855 { 856 858 FileUtils.whack(oldStubsDir); 859 } 860 861 if(!FileUtils.renameFile(stubsDir,oldStubsDir)) 862 { 863 String msg = localStrings.getString( 864 "enterprise.deployment.backend.directory_rename_error", 865 stubsDir.getPath(), oldStubsDir.getPath() ); 866 throw new IASDeploymentException( msg ); 867 } 868 } 869 870 if(needsJSPs() && FileUtils.safeIsDirectory(jspDir)) 871 { 872 oldJSPDir = new File(jspDir.getPath() + "_old"); 873 874 if(oldJSPDir.exists()) 875 { 876 878 FileUtils.whack(oldJSPDir); 879 } 880 881 if(!FileUtils.renameFile(jspDir,oldJSPDir)) 882 { 883 String msg = localStrings.getString( 884 "enterprise.deployment.backend.directory_rename_error", 885 jspDir.getPath(), oldJSPDir.getPath() ); 886 throw new IASDeploymentException( msg ); 887 } 888 } 889 890 if(FileUtils.safeIsDirectory(xmlDir)) 891 { 892 oldXMLDir = new File(xmlDir.getPath() + "_old"); 893 894 if(oldXMLDir.exists()) 895 { 896 898 FileUtils.whack(oldXMLDir); 899 } 900 901 if(!FileUtils.renameFile(xmlDir,oldXMLDir)) 902 { 903 String msg = localStrings.getString( 904 "enterprise.deployment.backend.directory_rename_error", 905 xmlDir.getPath(), oldXMLDir.getPath() ); 906 throw new IASDeploymentException( msg ); 907 } 908 } 909 if (FileUtils.safeIsDirectory(jwsDir)) { 910 if (jwsDir.list().length > 0) { 912 DeploymentStatus jwsStatus = new DeploymentStatus( 913 request.getCurrentDeploymentStatus()); 914 jwsStatus.setStageStatus(DeploymentStatus.WARNING); 915 jwsStatus.setStageStatusMessage(localStrings.getString( 916 "enterprise.deployment.backend.jws_redeploy", 917 jwsDir.getPath())); 918 } 919 920 oldJWSDir = new File(jwsDir.getPath() + "_old"); 921 922 if(oldJWSDir.exists()) 923 { 924 FileUtils.whack(oldJWSDir); 927 } 928 929 if(!FileUtils.renameFile(jwsDir, oldJWSDir)) 930 { 931 String msg = localStrings.getString( 932 "enterprise.deployment.backend.directory_rename_error", 933 jwsDir.getPath(), oldJWSDir.getPath() ); 934 throw new IASDeploymentException( msg ); 935 } 936 937 } 938 } 939 940 942 protected boolean isRegistered() throws IASDeploymentException 943 { 944 return DeploymentServiceUtils.isRegistered(moduleName, request.getType()); 945 } 946 947 protected boolean isSystem() throws IASDeploymentException 949 { 950 try 951 { 952 boolean isSystem; 953 isSystem = DeploymentServiceUtils.isSystem(moduleName, request.getType()); 954 boolean guardSystemApp = !(Boolean.valueOf(System.getProperty(Constants.ALLOW_SYSAPP_DEPLOYMENT, "false")).booleanValue()); 955 if(isSystem && guardSystemApp) 956 return true; 957 else 958 return false; 959 }catch(Exception e) 960 { 961 throw new IASDeploymentException(e); 962 } 963 } 964 965 967 protected void setShared(boolean what) throws ConfigException 968 { 969 975 } 977 978 980 981 protected void unregister() throws ConfigException 982 { 983 modulesMgr.unregisterDescriptor(moduleName); 984 } 985 986 988 protected void postRedeploy() throws IASDeploymentException, ConfigException 989 { 990 handlePostDeployEvent(); 991 992 if(FileUtils.safeIsDirectory(oldStubsDir)) 993 { 994 FileUtils.whack(oldStubsDir); 995 } 996 997 if(FileUtils.safeIsDirectory(oldJSPDir)) 998 { 999 FileUtils.whack(oldJSPDir); 1000 } 1001 1002 if(FileUtils.safeIsDirectory(oldXMLDir)) 1003 { 1004 FileUtils.whack(oldXMLDir); 1005 } 1006 1007 if(FileUtils.safeIsDirectory(oldJWSDir)) 1008 { 1009 FileUtils.whack(oldJWSDir); 1010 } 1011 } 1012 1013 1014 1016 protected void rollbackRedeploy() throws IASDeploymentException 1017 { 1018 if(isArchive() && wasModuleDirRenamed()) 1019 { 1020 if(FileUtils.safeIsDirectory(moduleDir)) 1021 FileUtils.whack(moduleDir); 1022 1023 if(FileUtils.safeIsDirectory(oldModuleDir)) 1024 oldModuleDir.renameTo(moduleDir); 1025 } 1026 1027 if(FileUtils.safeIsDirectory(oldStubsDir)) 1028 { 1029 DeleteOrKeepFailedStubs(stubsDir); 1030 oldStubsDir.renameTo(stubsDir); 1031 } 1032 1033 if(FileUtils.safeIsDirectory(jspDir)) 1034 FileUtils.whack(jspDir); 1035 1036 if(FileUtils.safeIsDirectory(oldJSPDir)) 1037 oldJSPDir.renameTo(jspDir); 1038 1039 if(FileUtils.safeIsDirectory(xmlDir)) 1040 FileUtils.whack(xmlDir); 1041 1042 if(FileUtils.safeIsDirectory(oldXMLDir)) 1043 oldJSPDir.renameTo(xmlDir); 1044 1045 if(FileUtils.safeIsDirectory(oldJWSDir)) 1046 oldJWSDir.renameTo(jwsDir); 1047 1048 try 1049 { 1050 register(); 1051 1052 } 1053 catch(Exception e) 1054 { 1055 throw new IASDeploymentException(e); 1056 } 1057 } 1058 1059 1060 1061 1063 protected final boolean wasModuleDirRenamed() 1064 { 1065 1070 return moduleDirWasRenamed; 1071 } 1072 1073 1080 protected void runVerifier() throws IASDeploymentException 1081 { 1082 if (request.isVerifying()) { 1083 try { 1084 String archive = request.getDeployedDirectory().getCanonicalPath(); 1085 File jspOutDir = (request.getPrecompileJSP())? jspDir:null; 1086 new AppVerifier().verify(request.getDescriptor(), 1087 (new FileArchiveFactory()).openArchive(archive), 1088 request.getCompleteClasspath(), 1089 jspOutDir); 1090 } catch (Exception e) { 1091 String msg = localStrings.getString( 1092 "enterprise.deployment.backend.verifier_error"); 1093 throw new IASDeploymentException(msg); 1094 } 1095 } 1096 } 1097 1098 1100 private void setDeployCommand() throws IASDeploymentException 1101 { 1102 boolean isReg = isRegistered(); 1103 boolean isSystem = false; 1104 wasReg = isReg; 1105 1106 if(isReg) 1107 { 1108 isSystem = isSystem(); 1109 } 1110 1111 if(request.isUnDeploy()) 1112 { 1113 if(!isReg) 1114 { 1115 String msg = localStrings.getString( 1116 "enterprise.deployment.backend.undeploy_error_module_not_registered" ); 1117 throw new IASDeploymentException( msg ); 1118 } 1119 else if(isSystem) 1120 { 1121 String msg = localStrings.getString( 1122 "enterprise.deployment.backend.undeploy_error_module_is_a_system_resource" ); 1123 throw new IASDeploymentException( msg ); 1124 } 1125 } 1126 1127 else if(request.isDeploy()) 1128 { 1129 if(isReg) 1130 { 1131 if(isSystem) 1132 { 1133 String msg = localStrings.getString( 1134 "enterprise.deployment.backend.redeploy_error_module_is_a_system_resource" ); 1135 throw new IASDeploymentException( msg ); 1136 } 1137 1138 if(request.isForced()) 1141 { 1142 request.setCommand(DeploymentCommand.REDEPLOY); 1143 } 1144 else 1145 { 1146 String msg = localStrings.getString( 1147 "enterprise.deployment.backend.deploy_error_module_exists" ); 1148 throw new IASDeploymentException( msg ); 1149 } 1150 } 1151 else 1152 { 1153 checkRegisteredAnywhereElse(moduleName); 1159 } 1160 } 1161 } 1162 1163 1166 protected ZipItem[] runEJBC() throws IASDeploymentException 1167 { 1168 ZipItem[] clientStubs = null; 1169 1170 try 1171 { 1172 1173 IASEJBCTimes timing = new IASEJBCTimes(); 1175 1176 EJBCompiler compiler = new EJBCompiler 1177 ( 1178 moduleName, 1179 moduleDir, 1180 oldModuleDir, 1181 stubsDir, 1182 oldStubsDir, 1183 getManager(), 1184 request, 1185 timing 1186 ); 1187 1188 clientStubs = compiler.compile(); 1190 1191 addEJBCTime(timing); 1193 1194 } catch (Exception e) 1195 { 1196 logger.log( Level.WARNING, 1197 "enterprise.deployment_ejbc_error", e ); 1198 String msg = localStrings.getString( 1199 "enterprise.deployment.backend.ejbc_error" ); 1200 throw new IASDeploymentException(msg, e); 1201 } 1202 1203 return clientStubs; 1205 } 1206 1207 1210 protected BaseManager getManager() 1211 { 1212 return modulesMgr; 1213 } 1214 1215 1217 1225 protected void dropTables() 1226 { 1227 assert isMaybeCMPDropTables; 1229 try 1230 { 1231 Application moduleDD; 1232 if (FileUtils.safeIsDirectory(xmlDir)) { 1233 moduleDD = 1234 DeploymentUtils.getModuleDescriptor(xmlDir.getAbsolutePath()); 1235 FileArchive archive = new FileArchive(); 1236 archive.open(moduleDir.getAbsolutePath()); 1237 try { 1238 ApplicationArchivist. 1239 readPersistenceDeploymentDescriptorsRecursively( 1240 archive, moduleDD); 1241 } finally { 1242 archive.close(); 1243 } 1244 } else { 1245 moduleDD = 1246 DeploymentUtils.getModuleDescriptor(moduleDir.getAbsolutePath()); 1247 } 1248 moduleDD.setRegistrationName(moduleName); 1249 1250 DeploymentEventInfo info = new DeploymentEventInfo(moduleDir, stubsDir, oldStubsDir, moduleDD, request); 1251 1252 DeploymentEvent ev = new DeploymentEvent(DeploymentEventType.PRE_UNDEPLOY, info); 1253 DeploymentEventManager.notifyDeploymentEvent(ev); 1254 } 1255 catch(Throwable t) 1256 { 1257 logger.log( Level.WARNING, 1259 1260 "enterprise.deployment_pre_undeploy_event_error", t); 1261 } 1262 } 1263 1264 public void removePolicy() throws IASDeploymentException { 1265 } 1267 1268 1270 protected BaseManager modulesMgr = null; 1271 protected String moduleName = null; 1272 protected File moduleDir = null; 1273 protected File stubsDir = null; 1274 protected File jspDir = null; 1275 protected File xmlDir = null; 1276 protected File jwsDir = null; 1277 protected File originalModuleDir = null; 1278 protected String originalContextRoot = null; 1279 protected File oldModuleDir = null; 1280 protected File oldStubsDir = null; 1281 protected File oldJSPDir = null; 1282 protected File oldXMLDir = null; 1283 protected File oldJWSDir = null; 1284 protected ModuleEnvironment moduleEnv = null; 1285 protected String oldRegisteredLocation = null; 1286 protected boolean isMaybeCMPDropTables = false; 1287 private boolean wasReg = false; 1288 private boolean wasRegisteredThisSession = false; 1289 private boolean shouldRollback = false; 1290 private boolean moduleDirWasRenamed = false; 1291 private static StringManager localStrings = StringManager.getManager( ModuleDeployer.class ); 1292} 1293 | Popular Tags |