1 23 package com.sun.enterprise.admin.event; 24 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.StringTokenizer ; 28 import com.sun.enterprise.server.ApplicationServer; 29 import com.sun.enterprise.server.Constants; 30 import com.sun.enterprise.config.serverbeans.Resources; 31 import com.sun.enterprise.config.serverbeans.Domain; 32 import com.sun.enterprise.config.serverbeans.ServerTags; 33 import com.sun.enterprise.config.ConfigException; 34 import com.sun.enterprise.config.ConfigContext; 35 import com.sun.enterprise.config.ConfigBean; 36 37 43 public class EventBuilder { 44 45 54 public ResourceDeployEvent createResourceDeployEvent(String action, 55 String resName) throws ConfigException { 56 57 EventStack stack = EventContext.getEventStackFromThreadLocal(); 58 59 return createResourceDeployEvent(action, resName, 60 stack.getConfigContext(), 61 (ArrayList )stack.getConfigChangeList(), 62 stack.getTarget()); 63 } 64 65 76 public ResourceDeployEvent createResourceDeployEvent(String action, 77 String resName, ConfigContext ctx, ArrayList configChanges, 78 String target) throws ConfigException { 79 80 String instName = 82 ApplicationServer.getServerContext().getInstanceName(); 83 84 String resType = getResourceTypeByName(ctx, resName, target); 86 87 ResourceDeployEvent rde = new ResourceDeployEvent(instName, 89 resName, resType, action); 90 rde.setTargetDestination(target); 91 92 DependencyResolver dr = new DependencyResolver(ctx, target); 94 rde.addDependentConfigChange( 95 dr.resolveResources(resName, action, resType) ); 96 97 rde.addConfigChange( configChanges ); 98 99 101 return rde; 102 } 103 104 112 protected static String getResourceTypeByName(ConfigContext ctx, 113 String resName, String target) throws ConfigException { 114 115 String type = getTypeFromTarget(target); 116 if (type == null) { 117 type = getResourceType(ctx, resName, true); 118 } 119 120 return convertResourceType(type); 121 } 122 123 132 static String getResourceType(ConfigContext ctx, String id, 133 boolean includePool) throws ConfigException { 134 135 Resources root = ((Domain)ctx.getRootConfigBean()).getResources(); 136 137 ConfigBean res = root.getJdbcResourceByJndiName(id); 138 if ( res != null ) { 139 return Resources.JDBC_RESOURCE; 140 } 141 142 res = root.getMailResourceByJndiName(id); 143 if ( res != null ) { 144 return Resources.MAIL_RESOURCE; 145 } 146 147 res = root.getCustomResourceByJndiName(id); 148 if ( res != null ) { 149 return Resources.CUSTOM_RESOURCE; 150 } 151 152 res = root.getExternalJndiResourceByJndiName(id); 153 if ( res != null ) { 154 return Resources.EXTERNAL_JNDI_RESOURCE; 155 } 156 157 res = root.getPersistenceManagerFactoryResourceByJndiName(id); 158 if ( res != null) { 159 return Resources.PERSISTENCE_MANAGER_FACTORY_RESOURCE; 160 } 161 162 res = root.getAdminObjectResourceByJndiName(id); 163 if ( res != null ) { 164 return Resources.ADMIN_OBJECT_RESOURCE; 165 } 166 167 res = root.getConnectorResourceByJndiName(id); 168 if ( res != null ) { 169 return Resources.CONNECTOR_RESOURCE; 170 } 171 172 res = root.getResourceAdapterConfigByResourceAdapterName(id); 173 if ( res != null ) { 174 return Resources.RESOURCE_ADAPTER_CONFIG; 175 } 176 177 if (includePool) { 178 res = root.getJdbcConnectionPoolByName(id); 179 if ( res != null ) { 180 return Resources.JDBC_CONNECTION_POOL; 181 } 182 183 res = root.getConnectorConnectionPoolByName(id); 184 if ( res != null ) { 185 return Resources.CONNECTOR_CONNECTION_POOL; 186 } 187 } 188 189 return null; 190 } 191 192 200 public void addResourceDeployEvent(String action, String target, 201 String resName) throws ConfigException { 202 203 EventStack stack = EventContext.getEventStackFromThreadLocal(); 204 ConfigContext ctx = stack.getConfigContext(); 205 stack.setTarget(target); 206 stack.setConfigChangeList( ctx.getConfigChangeList()); 207 208 ResourceDeployEvent event = createResourceDeployEvent(action, resName); 209 EventContext.addEvent(event); 210 } 211 212 222 public LogLevelChangeEvent createLogLevelChangeEvent(ConfigContext ctx, 223 String target, String newLogLevel, String moduleName) 224 throws ConfigException { 225 226 String instName = 228 ApplicationServer.getServerContext().getInstanceName(); 229 230 LogLevelChangeEvent lde = new LogLevelChangeEvent(instName); 232 lde.setTargetDestination(target); 233 234 237 239 lde.setModuleName(moduleName); 241 lde.setNewLogLevel(newLogLevel); 242 return lde; 243 } 244 245 278 public ApplicationDeployEvent createApplicationDeployEvent(String action, 279 String appName) throws ConfigException { 280 281 return createApplicationDeployEvent(action, appName, false); 282 } 283 284 298 public ApplicationDeployEvent createApplicationDeployEvent(String action, 299 String appName, boolean cascade) throws ConfigException { 300 301 return createApplicationDeployEvent(action, appName, cascade, false); 302 } 303 304 319 public ApplicationDeployEvent createApplicationDeployEvent(String action, 320 String appName, boolean cascade, boolean forceDeploy) 321 throws ConfigException { 322 return createApplicationDeployEvent(action, appName, cascade, 323 forceDeploy, Constants.LOAD_UNSET); 324 } 325 326 342 public ApplicationDeployEvent createApplicationDeployEvent(String action, 343 String appName, boolean cascade, boolean forceDeploy, 344 int loadUnloadAction) throws ConfigException { 345 EventStack stack = EventContext.getEventStackFromThreadLocal(); 346 String target = stack.getTarget(); 347 assert(target != null); 348 349 String instName = 351 ApplicationServer.getServerContext().getInstanceName(); 352 353 ApplicationDeployEvent ade = new ApplicationDeployEvent(instName, 354 appName, action, cascade, forceDeploy, loadUnloadAction); 355 356 ade.setTargetDestination(target); 357 358 DependencyResolver dr = 360 new DependencyResolver(stack.getConfigContext(), target); 361 ade.addDependentConfigChange(dr.resolveApplications(appName, action)); 362 363 ade.addConfigChange( (ArrayList ) stack.getConfigChangeList() ); 364 365 return ade; 366 } 367 368 381 public ModuleDeployEvent createModuleDeployEvent(String action, 382 String moduleName, String moduleType) 383 throws ConfigException { 384 385 return createModuleDeployEvent(action, moduleName, moduleType, false); 386 } 387 388 403 public ModuleDeployEvent createModuleDeployEvent(String action, 404 String moduleName, String moduleType, boolean cascade) 405 throws ConfigException { 406 407 return createModuleDeployEvent(action, moduleName, moduleType, 408 cascade, false); 409 } 410 411 427 public ModuleDeployEvent createModuleDeployEvent(String action, 428 String moduleName, String moduleType, boolean cascade, 429 boolean forceDeploy) throws ConfigException { 430 EventStack stack = EventContext.getEventStackFromThreadLocal(); 431 String target = stack.getTarget(); 432 assert(target != null); 433 434 String instName = 435 ApplicationServer.getServerContext().getInstanceName(); 436 437 ModuleDeployEvent mde = 438 new ModuleDeployEvent(instName, moduleName, moduleType, 439 action, cascade); 440 mde.setTargetDestination(target); 441 442 443 mde.setForceDeploy(forceDeploy); 445 446 DependencyResolver dr = 448 new DependencyResolver(stack.getConfigContext(), target); 449 mde.addDependentConfigChange(dr.resolveApplications(moduleName,action)); 450 mde.addConfigChange( (ArrayList ) stack.getConfigChangeList() ); 451 452 return mde; 453 } 454 455 463 public ConfigChangeEvent createConfigChangeEvent(String target, 464 ArrayList configChangeList) throws ConfigException { 465 466 String instName = 467 ApplicationServer.getServerContext().getInstanceName(); 468 469 ConfigChangeEvent cce = 470 new ConfigChangeEvent(instName, configChangeList); 471 cce.setTargetDestination(target); 472 return cce; 473 } 474 475 486 public MonitoringEvent createMonitoringEvent(ConfigContext ctx, 487 String target, String component, String action, Object command) 488 throws ConfigException { 489 490 String instName = 491 ApplicationServer.getServerContext().getInstanceName(); 492 MonitoringEvent me = 493 new MonitoringEvent(instName, component, action, command); 494 me.setTargetDestination(target); 495 496 return me; 497 } 498 499 509 public MonitoringLevelChangeEvent createMonitoringLevelChangeEvent( 510 ConfigContext ctx, String target, String component, 511 String monitoringLevel) throws ConfigException { 512 513 String instName = 514 ApplicationServer.getServerContext().getInstanceName(); 515 516 MonitoringLevelChangeEvent mle = 517 new MonitoringLevelChangeEvent(instName); 518 mle.setTargetDestination(target); 519 520 return mle; 521 } 522 523 529 protected static String convertResourceType(String type) { 530 533 if (type==null) { 534 return null; 535 } else { 536 type = type.trim(); 537 } 538 539 if ( type.equals(ServerTags.CUSTOM_RESOURCE) 540 || type.equals(Resources.CUSTOM_RESOURCE) ) { 541 return ResourceDeployEvent.RES_TYPE_CUSTOM; 542 } 543 if ( type.equals(ServerTags.EXTERNAL_JNDI_RESOURCE) 544 || type.equals(Resources.EXTERNAL_JNDI_RESOURCE) ) { 545 return ResourceDeployEvent.RES_TYPE_EXTERNAL_JNDI; 546 } 547 if ( type.equals(ServerTags.JDBC_RESOURCE) 548 || type.equals(Resources.JDBC_RESOURCE) ) { 549 return ResourceDeployEvent.RES_TYPE_JDBC; 550 } 551 if ( type.equals(ServerTags.MAIL_RESOURCE) 552 || type.equals(Resources.MAIL_RESOURCE) ) { 553 return ResourceDeployEvent.RES_TYPE_MAIL; 554 } 555 if ( type.equals(ServerTags.PERSISTENCE_MANAGER_FACTORY_RESOURCE) 556 || type.equals(Resources.PERSISTENCE_MANAGER_FACTORY_RESOURCE)) { 557 558 return ResourceDeployEvent.RES_TYPE_PMF; 559 } 560 if ( type.equals(ServerTags.ADMIN_OBJECT_RESOURCE) 561 || type.equals(Resources.ADMIN_OBJECT_RESOURCE) ) { 562 return ResourceDeployEvent.RES_TYPE_AOR; 563 } 564 if ( type.equals(ServerTags.CONNECTOR_RESOURCE) 565 || type.equals(Resources.CONNECTOR_RESOURCE) ) { 566 return ResourceDeployEvent.RES_TYPE_CR; 567 } 568 if ( type.equals(ServerTags.RESOURCE_ADAPTER_CONFIG) 569 || type.equals(Resources.RESOURCE_ADAPTER_CONFIG) ) { 570 return ResourceDeployEvent.RES_TYPE_RAC; 571 } 572 if ( type.equals(ServerTags.JDBC_CONNECTION_POOL) 573 || type.equals(Resources.JDBC_CONNECTION_POOL) ) { 574 return ResourceDeployEvent.RES_TYPE_JCP; 575 } 576 if ( type.equals(ServerTags.CONNECTOR_CONNECTION_POOL) 577 || type.equals(Resources.CONNECTOR_CONNECTION_POOL) ) { 578 return ResourceDeployEvent.RES_TYPE_CCP; 579 } 580 581 return type; } 583 584 595 public BaseDeployEvent createModAppDeployEvent(String action, 596 String name, ConfigContext ctx, ArrayList configChanges, 597 String target) throws ConfigException { 598 599 String instName = 601 ApplicationServer.getServerContext().getInstanceName(); 602 603 BaseDeployEvent event=getAppOrModuleEvent(instName, ctx, name, action); 604 event.setTargetDestination(target); 605 606 DependencyResolver dr = new DependencyResolver(ctx, target); 608 event.addDependentConfigChange(dr.resolveApplications(name,action)); 609 event.addConfigChange( configChanges ); 610 611 return event; 612 } 613 614 624 public static BaseDeployEvent resolveModAppDeployEventType( 625 BaseDeployEvent eventToResolve, ConfigContext ctx) 626 throws ConfigException { 627 628 String instName = eventToResolve.getInstanceName(); 630 String name = eventToResolve.getJ2EEComponentName(); 631 String action = eventToResolve.getAction(); 632 633 BaseDeployEvent event=getAppOrModuleEvent(instName, ctx, name, action); 634 event.setCascade(eventToResolve.getCascade()); 635 event.setEventId(eventToResolve.getEventId()); 636 637 if (eventToResolve.getDependentChangeList()!=null) { 638 event.addDependentConfigChange( 639 eventToResolve.getDependentChangeList()); 640 } 641 642 if (eventToResolve.getConfigChangeList()!=null) { 643 event.addConfigChange(eventToResolve.getConfigChangeList()); 644 } 645 646 if (eventToResolve.getTargetDestination()!=null) { 647 event.setTargetDestination(eventToResolve.getTargetDestination()); 648 } 649 650 return event; 651 } 652 653 665 private static BaseDeployEvent getAppOrModuleEvent(String instName, 666 ConfigContext ctx, String name, String action) 667 throws ConfigException { 668 669 String type = getAppOrModuleType(ctx, name); 670 671 if (type!=null) { 672 673 if (type.equals(BaseDeployEvent.APPLICATION)) { 674 return (BaseDeployEvent)new ApplicationDeployEvent(instName, 676 name, action); 677 } else { 678 return (BaseDeployEvent)new ModuleDeployEvent(instName, name, 680 type, action); 681 } 682 } else { return new BaseDeployEvent(instName, null, name, action); 684 } 685 } 686 687 696 private static String getAppOrModuleType(ConfigContext ctx, String name) 697 throws ConfigException { 698 699 701 ConfigBean[] beans = ((Domain)ctx.getRootConfigBean()). 702 getApplications().getAllChildBeans(); 703 ConfigBean bean = null; 704 if (beans!=null) { 705 for(int i=0; i<beans.length; i++) { 706 if(name.equals(beans[i].getAttributeValue("name"))) { 707 bean = beans[i]; 708 break; 709 } 710 } 711 } 712 713 if (bean==null) { 714 return null; 715 } 716 717 String type = null; 718 719 if (bean instanceof 720 com.sun.enterprise.config.serverbeans.J2eeApplication) { 721 type = BaseDeployEvent.APPLICATION; 722 } 723 724 if (bean instanceof 725 com.sun.enterprise.config.serverbeans.ConnectorModule) { 726 type = ModuleDeployEvent.TYPE_CONNECTOR; 727 } else if (bean instanceof 728 com.sun.enterprise.config.serverbeans.EjbModule) { 729 type = ModuleDeployEvent.TYPE_EJBMODULE; 730 } else if (bean instanceof 731 com.sun.enterprise.config.serverbeans.WebModule) { 732 type = ModuleDeployEvent.TYPE_WEBMODULE; 733 } else if (bean instanceof 734 com.sun.enterprise.config.serverbeans.AppclientModule) { 735 type = ModuleDeployEvent.TYPE_APPCLIENT; 736 } 737 738 return type; 739 } 740 741 748 static String getTypeFromTarget(String target) { 749 750 String type = null; 751 String msg = "\n NAZRUL Could not determine resource type for target " 752 + target; 753 754 try { 755 if (target != null) { 756 StringTokenizer st = new StringTokenizer (target, "|"); 757 int tokens = st.countTokens(); 758 if (tokens == 3) { 759 String prefix = st.nextToken(); 760 String name = st.nextToken(); 761 type = st.nextToken(); 762 } 763 } 764 } catch (Exception e) { } 765 766 return type; 767 } 768 } 769 | Popular Tags |