1 23 24 31 package com.sun.enterprise.admin.event; 32 33 import java.util.ArrayList ; 34 import java.util.HashMap ; 35 import java.util.Iterator ; 36 import java.util.Map ; 37 import java.util.Set ; 38 import java.util.StringTokenizer ; 39 import java.util.logging.Level ; 40 import java.util.logging.Logger ; 41 import java.util.regex.Matcher ; 42 import java.util.regex.Pattern ; 43 44 import com.sun.enterprise.admin.common.constant.AdminConstants; 45 import com.sun.enterprise.admin.server.core.channel.AdminChannel; 46 import com.sun.enterprise.admin.server.core.channel.RMIClient; 47 import com.sun.enterprise.config.ConfigContext; 48 import com.sun.enterprise.config.ConfigAdd; 49 import com.sun.enterprise.config.ConfigBean; 50 import com.sun.enterprise.config.ConfigChange; 51 import com.sun.enterprise.config.ConfigDelete; 52 import com.sun.enterprise.config.ConfigException; 53 import com.sun.enterprise.config.ConfigSet; 54 import com.sun.enterprise.config.ConfigUpdate; 55 import com.sun.enterprise.config.impl.ConfigUpdateImpl; 56 import com.sun.enterprise.config.serverbeans.ServerTags; 57 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 58 59 import com.sun.enterprise.util.i18n.StringManager; 61 62 102 public class AdminEventCache { 103 104 107 static Logger logger = Logger.getLogger(AdminConstants.kLoggerName); 108 109 112 private static final transient HashMap instanceCacheMap = new HashMap (); 113 114 117 private String instanceName; 118 119 122 private ArrayList cache; 123 124 127 private boolean restartNeeded = false; 128 129 132 private long tsRestartNeededSince; 133 134 139 private ConfigContext adminConfigContext; 140 141 146 AdminEventCache(String instanceName) { 147 this.instanceName = instanceName; 148 cache = new ArrayList (); 149 RMIClient channel = AdminChannel.getRMIClient(instanceName); 150 if (channel.isRestartNeeded()) { 151 setRestartNeededTrue(false); 152 } 153 } 154 155 160 public synchronized static AdminEventCache getInstance( 161 String instanceName) { 162 AdminEventCache aec = 163 (AdminEventCache)instanceCacheMap.get(instanceName); 164 if (aec == null) { 165 aec = new AdminEventCache(instanceName); 166 instanceCacheMap.put(instanceName, aec); 167 } 168 return aec; 169 } 170 171 174 public void setAdminConfigContext(ConfigContext ctx) { 175 adminConfigContext = ctx; 176 } 177 178 184 ArrayList getCachedEvents() { 185 return cache; 186 } 187 188 193 public synchronized ArrayList getAndResetCachedEvents() { 194 ArrayList saved = cache; 195 cache = new ArrayList (); 196 return saved; 197 } 198 199 204 public void addEvent(AdminEvent event) { 205 cache.add(event); 206 } 207 208 213 public void addEvents(ArrayList eventList) { 214 cache.addAll(eventList); 215 } 216 217 222 public void removeEvent(AdminEvent event) { 223 cache.remove(event); 224 } 225 226 241 public synchronized void processConfigChangeList(ArrayList changeList, 242 boolean initOrObjFilesChanged, boolean mimeFileChanged) { 243 ConfigChangeEvent dfltEvent = null; 244 boolean dfltEventCached = false; 245 Iterator iter = cache.iterator(); 246 while (iter.hasNext()) { 247 Object obj = iter.next(); 248 if (obj instanceof ConfigChangeEvent) { 249 dfltEvent = (ConfigChangeEvent)obj; 250 dfltEventCached = true; 251 break; 252 } 253 } 254 if (initOrObjFilesChanged || mimeFileChanged) { 255 if (dfltEvent == null) { 256 dfltEvent = new ConfigChangeEvent(instanceName, null); 257 } 258 dfltEvent.setWebCoreReconfigNeeded(true); 259 } 260 if (initOrObjFilesChanged) { 261 if (dfltEvent == null) { 262 dfltEvent = new ConfigChangeEvent(instanceName, null); 263 } 264 dfltEvent.setInitOrObjConfChanged(true); 265 } 266 if (changeList != null && !changeList.isEmpty()) { 267 iter = changeList.iterator(); 268 while (iter.hasNext()) { 269 ConfigChange change = (ConfigChange)iter.next(); 270 if (change != null) { 271 doChangeBucketing(change, dfltEvent, changeList); 272 } 273 } 274 } 275 if (( dfltEvent != null) && (!dfltEventCached) ){ 276 cache.add(dfltEvent); 277 } 278 purgeNopEvents(); 279 } 280 281 289 private void doChangeBucketing(ConfigChange change, 290 ConfigChangeEvent dflt, ArrayList changeList) { 291 logger.log(Level.FINE, PROCESS_CHANGE, change); 292 if (change == null || change.getXPath() == null) { 293 logger.log(Level.FINE, CHANGE_NULL, change); 294 return; 295 } 296 boolean processed = false; 297 315 if (( dflt != null) && (!processed)) { 316 dflt.addConfigChange(change); 317 if (!dflt.isWebCoreReconfigNeeded()) { 318 setWebCoreReconfig(change, dflt); 319 } 320 } 321 } 322 323 330 private boolean processLogLevelChangeEvent(ConfigChange change) { 331 return processLevelChangeEvent(change, 332 new LogLevelChangeProcessor(this)); 333 } 334 335 343 private boolean processMonitoringLevelChangeEvent(ConfigChange change) { 344 return processLevelChangeEvent(change, 345 new MonitoringLevelChangeProcessor(this)); 346 } 347 348 355 private boolean processLevelChangeEvent(ConfigChange change, 356 LevelChangeProcessor processor) { 357 ConfigUpdate update = convertToConfigUpdate(change); 360 if (update == null) { 361 return false; 362 } 363 String xpath = cleanXPath(update.getXPath()); 364 if (!processor.isRelevant(xpath)) { 365 return false; 366 } 367 Set attrs = update.getAttributeSet(); 368 if (attrs == null) { 369 logger.log(Level.FINEST, "admin.event.null_updated_attrs", 370 update.getXPath()); 371 return false; 372 } 373 Iterator iter = attrs.iterator(); 374 while (iter.hasNext()) { 375 String compName = (String )iter.next(); 376 String oldValue = update.getOldValue(compName); 377 String newValue = update.getNewValue(compName); 378 AdminEvent event = processor.createEvent(compName, oldValue, 379 newValue); 380 cache.add(event); 381 ConfigUpdate upd = new ConfigUpdateImpl(xpath, compName, oldValue, 382 newValue); 383 event.addConfigChange(upd); 384 } 385 return true; 386 } 387 388 398 private boolean processResourceChangeEvent(ConfigChange change) { 399 String xpath = cleanXPath(change.getXPath()); 400 boolean processed = false; 401 if (isResourceXPath(xpath)) { 402 String actionCode = null; 403 if (change instanceof ConfigUpdate) { 404 ConfigUpdate update = (ConfigUpdate)change; 405 String enableStr = update.getNewValue(ServerTags.ENABLED); 406 if (enableStr != null) { 407 if (getServerXmlBooleanValue(enableStr)) { 408 actionCode = ResourceDeployEvent.ENABLE; 409 } else { 410 actionCode = ResourceDeployEvent.DISABLE; 411 } 412 } else { 413 actionCode = ResourceDeployEvent.REDEPLOY; 414 } 415 } else if (change instanceof ConfigAdd) { 416 boolean isMap = xpath.indexOf(ServerTags.SECURITY_MAP) != -1; 420 if (isPropertyXPath(xpath) || isMap) { 421 actionCode = ResourceDeployEvent.REDEPLOY; 422 } else { 423 actionCode = ResourceDeployEvent.DEPLOY; 424 } 425 } else if (change instanceof ConfigDelete) { 426 boolean isMap = xpath.indexOf(ServerTags.SECURITY_MAP) != -1; 429 if (isPropertyXPath(xpath) || isMap) { 430 actionCode = ResourceDeployEvent.REDEPLOY; 431 } else { 432 actionCode = ResourceDeployEvent.UNDEPLOY; 433 } 434 } else if (change instanceof ConfigSet) { 435 actionCode = ResourceDeployEvent.REDEPLOY; 438 } else { 439 String msg = localStrings.getString( "admin.event.unknown_configchange_for_resources"); 441 throw new IllegalStateException ( msg ); 442 } 443 String resType = getResourceType(xpath); 444 String resName = getResourceName(xpath); 445 ResourceDeployEvent resEvent = 446 findResourceDeployEvent(resType, resName); 447 if (resEvent == null) { 448 resEvent = new ResourceDeployEvent(instanceName, resName, 449 resType, actionCode); 450 cache.add(resEvent); 451 } else { 452 if (isActionValidForCache(actionCode)) { 453 resEvent.setNewAction(actionCode); 454 } else { 455 } 459 } 460 resEvent.addConfigChange(change); 461 processed = true; 462 } 463 return processed; 464 } 465 466 472 private boolean isResourceXPath(String xpath) { 473 String xpathLcase = xpath.toLowerCase(); 474 if (xpathLcase.startsWith(RES_PFX)) { 475 return true; 476 } 477 return false; 478 } 479 480 485 private boolean isPropertyXPath(String xpath) { 486 return AdminEventCache.matchRegex(PROPERTY_REGEX, xpath); 487 } 488 489 494 private boolean isLogLevelXPath(String xpath) { 495 return (LOG_LEVEL_XPATH.equalsIgnoreCase(xpath)); 496 } 497 498 504 private boolean isMonitoringLevelXPath(String xpath) { 505 return (MONITORING_LEVEL_XPATH.equalsIgnoreCase(xpath)); 506 } 507 508 514 private boolean isAppRefXPath(String xpath) { 515 if (xpath == null) { 516 return false; 517 } 518 String serverXPath = ServerXPathHelper.getServerIdXpath(instanceName); 519 String appRefXPath = serverXPath + ServerXPathHelper.XPATH_SEPARATOR 520 + ServerTags.APPLICATION_REF; 521 return xpath.startsWith(appRefXPath); 522 } 523 524 530 private boolean isResRefXPath(String xpath) { 531 if (xpath == null) { 532 return false; 533 } 534 String serverXPath = ServerXPathHelper.getServerIdXpath(instanceName); 535 String resRefXPath = serverXPath + ServerXPathHelper.XPATH_SEPARATOR 536 + ServerTags.RESOURCE_REF; 537 return xpath.startsWith(resRefXPath); 538 } 539 540 546 private static String getAppRefXPath(String instance, String appName) { 547 return ServerXPathHelper.getServerIdXpath(instance) 548 + ServerXPathHelper.XPATH_SEPARATOR 549 + ServerTags.APPLICATION_REF + "[@" 550 + ServerTags.REF + "='" + appName + "']"; 551 } 552 553 559 private String getResourceType(String xpath) { 560 String resType = "unknown"; 561 String xpathLcase = xpath.toLowerCase(); 562 if (xpathLcase.startsWith(ServerXPathHelper.XPATH_CUSTOM_RESOURCE)) { 563 resType = ResourceDeployEvent.RES_TYPE_CUSTOM; 564 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_JNDI_RESOURCE)) { 565 resType = ResourceDeployEvent.RES_TYPE_EXTERNAL_JNDI; 566 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_JDBC_CONNECTION_POOL)) { 567 resType = ResourceDeployEvent.RES_TYPE_JCP; 568 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_JDBC_RESOURCE)) { 569 resType = ResourceDeployEvent.RES_TYPE_JDBC; 570 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_MAIL_RESOURCE)) { 571 resType = ResourceDeployEvent.RES_TYPE_MAIL; 572 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_PM_FACTORY_RESOURCE)) { 573 resType = ResourceDeployEvent.RES_TYPE_PMF; 574 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_ADMIN_OBJECT_RESOURCE)) { 575 resType = ResourceDeployEvent.RES_TYPE_AOR; 576 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_CONNECTOR_CONNECTION_POOL)) { 577 resType = ResourceDeployEvent.RES_TYPE_CCP; 578 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_CONNECTOR_RESOURCE)) { 579 resType = ResourceDeployEvent.RES_TYPE_CR; 580 } else if (xpathLcase.startsWith(ServerXPathHelper.XPATH_RESOURCE_ADAPTER_CONFIG)) { 581 resType = ResourceDeployEvent.RES_TYPE_RAC; 582 } 583 584 return resType; 585 } 586 587 592 private String getResourceName(String xpath) { 593 return getXPathToken(xpath, 1); 594 } 595 596 613 private String getXPathToken(String xpath, int numToDiscard) { 614 StringTokenizer tok = new StringTokenizer (xpath, "'"); 615 if (tok.countTokens() <= numToDiscard) { 616 Object [] params = new Object [] {xpath, 617 new Integer (numToDiscard + 1), 618 new Integer (tok.countTokens())}; 619 logger.log(Level.FINE, INVALID_XPATH_TOKENIZATION, params); 620 String msg = localStrings.getString( 621 "admin.event.invalid_xpath_tokenization", params ); 622 throw new IllegalArgumentException (msg); 623 } 624 for (int i = numToDiscard; i > 0; i--) { 625 String discard = tok.nextToken(); 626 } 627 return tok.nextToken(); 628 } 629 630 642 private boolean processOtherDeployEvent(ConfigChange change) { 643 String xpath = cleanXPath(change.getXPath()); 644 String xpathLcase = xpath.toLowerCase(); 645 boolean processed = false; 646 String componentType = null; 647 String moduleType = null; 648 if (xpathLcase.startsWith(APP_PFX)) { 649 componentType = BaseDeployEvent.APPLICATION; 650 } else if (xpathLcase.startsWith(EJB_PFX)) { 651 componentType = BaseDeployEvent.MODULE; 652 moduleType = ModuleDeployEvent.TYPE_EJBMODULE; 653 } else if (xpathLcase.startsWith(WEB_PFX)) { 654 componentType = BaseDeployEvent.MODULE; 655 moduleType = ModuleDeployEvent.TYPE_WEBMODULE; 656 } else if (xpathLcase.startsWith(RAR_PFX)) { 657 componentType = BaseDeployEvent.MODULE; 658 moduleType = ModuleDeployEvent.TYPE_CONNECTOR; 659 } else if (xpathLcase.startsWith(ACC_PFX)) { 660 componentType = BaseDeployEvent.MODULE; 661 moduleType = ModuleDeployEvent.TYPE_APPCLIENT; 662 } else { 663 return false; 664 } 665 String componentName = getResourceName(xpath); 666 BaseDeployEvent theEvent = null; 667 if (BaseDeployEvent.APPLICATION.equals(componentType)) { 668 theEvent = findApplicationDeployEvent(componentName); 669 } else { 670 theEvent = findModuleDeployEvent(moduleType, componentName); 671 } 672 if (theEvent == null) { 673 String actionCode = null; 674 if (change instanceof ConfigUpdate) { 675 688 } else if (change instanceof ConfigAdd) { 689 actionCode = BaseDeployEvent.DEPLOY; 690 } else if (change instanceof ConfigDelete) { 691 actionCode = BaseDeployEvent.UNDEPLOY; 692 } else { 693 String msg = localStrings.getString( "admin.event.handle_add_delete_set_configchange" ); 694 throw new IllegalStateException ( msg ); 695 } 696 if (actionCode != null) { 697 if (BaseDeployEvent.APPLICATION.equals(componentType)) { 698 theEvent = new ApplicationDeployEvent(instanceName, 699 componentName, actionCode); 700 } else { 701 theEvent = new ModuleDeployEvent(instanceName, componentName, 702 moduleType, actionCode); 703 } 704 cache.add(theEvent); 705 processed = true; 706 } 707 } else { processed = true; 712 } 713 theEvent.addConfigChange(change); 714 return processed; 715 } 716 717 725 private boolean processResourceReference(ConfigChange change, 726 ArrayList changeList) { 727 return processReference(change, changeList, new ResRefProcessor(this)); 728 } 729 730 738 private boolean processApplicationReference(ConfigChange change, 739 ArrayList changeList) { 740 return processReference(change, changeList, new AppRefProcessor(this)); 741 } 742 743 755 private boolean processReference(ConfigChange change, ArrayList changeList, 756 RefProcessor processor) { 757 String xpath = cleanXPath(change.getXPath()); 758 if (!processor.isRelevant(xpath)) { 759 return false; 760 } 761 String refName = processor.getRefName(xpath); 762 processor.initRefTypeXPathMap(refName); 763 String refType = processor.getRefType(refName, changeList); 764 if (refType == null) { 765 return false; 767 } 768 return processor.process(refName, refType, change); 769 } 770 771 778 private void setWebCoreReconfig(ConfigChange change, 779 ConfigChangeEvent dflt) { 780 String xpath = cleanXPath(change.getXPath()); 781 if (isWebCoreXPath(xpath)) { 782 dflt.setWebCoreReconfigNeeded(true); 783 } 784 return; 785 } 786 787 793 private boolean isWebCoreXPath(String xpath) { 794 boolean webCoreXPath = false; 795 if (xpath == null) { 796 return webCoreXPath; 797 } else { 798 xpath = xpath.toLowerCase(); 799 } 800 if (xpath.startsWith(HTTP_SERVICE) || xpath.startsWith(WEB_CONTAINER)) { 801 webCoreXPath = true; 802 } 803 return webCoreXPath; 804 } 805 806 811 public static boolean getServerXmlBooleanValue(String xmlValue) { 812 boolean retval = false; 813 if (xmlValue == null) { 814 return retval; 815 } 816 if (xmlValue.equalsIgnoreCase("true") 817 || xmlValue.equalsIgnoreCase("yes") 818 || xmlValue.equalsIgnoreCase("on") 819 || xmlValue.equalsIgnoreCase("1")) { 820 retval = true; 821 } 822 return retval; 823 } 824 825 829 private ConfigUpdate convertToConfigUpdate(ConfigChange change) { 830 ConfigUpdate update = null; 831 if (change instanceof ConfigUpdate) { 832 update = (ConfigUpdate)change; 833 } 834 return update; 835 } 836 837 846 public void cacheResourceChange(String resourceType, String resourceName, 847 String actionCode) { 848 if (!isActionValidForCache(actionCode)) { 852 String msg = localStrings.getString( "admin.event.invalid_action", actionCode ); 853 throw new IllegalArgumentException ( msg ); 854 } 855 ResourceDeployEvent resEvent = findResourceDeployEvent(resourceType, 856 resourceName); 857 if (resEvent == null) { 858 resEvent = new ResourceDeployEvent(instanceName, resourceName, 859 resourceType, actionCode); 860 cache.add(resEvent); 861 } else { 862 resEvent.setNewAction(actionCode); 863 } 864 } 865 866 873 private boolean isActionValidForCache(String deployAction) { 874 boolean valid = false; 875 if (deployAction != null) { 876 if (deployAction.equals(BaseDeployEvent.DEPLOY) 877 || deployAction.equals(BaseDeployEvent.UNDEPLOY) 878 || deployAction.equals(BaseDeployEvent.REDEPLOY)) { 879 valid = true; 880 } 881 } 882 return valid; 883 } 884 885 896 public static void populateConfigChange(ConfigContext ctx, AdminEvent event) { 897 if (event instanceof ApplicationDeployEvent) { 898 populateApplicationConfigChange(ctx, (ApplicationDeployEvent)event); 899 } else if (event instanceof ModuleDeployEvent) { 900 populateModuleConfigChange(ctx, (ModuleDeployEvent)event); 901 } else { 902 String msg = localStrings.getString( "admin.event.unsupported_populateconfigchange", event.getClass().getName() ); 903 throw new UnsupportedOperationException ( msg ); 904 } 905 } 906 907 913 private static void populateApplicationConfigChange(ConfigContext ctx, 914 ApplicationDeployEvent event) { 915 String xpath = ServerXPathHelper.getAppIdXpathExpression( 916 event.getApplicationName()); 917 xpath = cleanXPath(xpath); 918 event.addConfigChange(extractConfigChanges(ctx, xpath)); 919 String refXPath = getAppRefXPath(event.getInstanceName(), 921 event.getApplicationName()); 922 event.addConfigChange(extractConfigChanges(ctx, refXPath)); 923 } 924 925 933 private static void populateModuleConfigChange(ConfigContext ctx, 934 ModuleDeployEvent event) { 935 String moduleType = event.getModuleType(); 936 String moduleName = event.getModuleName(); 937 String xpath = null; 938 if (event.TYPE_WEBMODULE.equals(moduleType)) { 939 xpath = ServerXPathHelper.getWebModuleIdXpathExpression(moduleName); 940 } else if (event.TYPE_EJBMODULE.equals(moduleType)) { 941 xpath = ServerXPathHelper.getEjbModuleIdXpathExpression(moduleName); 942 } else if (event.TYPE_CONNECTOR.equals(moduleType)) { 943 xpath = ServerXPathHelper.getConnectorModuleIdXpathExpression( 944 moduleName); 945 } else if (event.TYPE_APPCLIENT.equals(moduleType)) { 946 xpath = ServerXPathHelper.getAppClientModuleIdXpathExpression( 947 moduleName); 948 } else { 949 String msg = localStrings.getString( "admin.event.invalid_module_type" , moduleType ); 950 throw new IllegalArgumentException ( msg ); 951 } 952 xpath = cleanXPath(xpath); 953 event.addConfigChange(extractConfigChanges(ctx, xpath)); 954 String refXPath = getAppRefXPath(event.getInstanceName(), moduleName); 956 event.addConfigChange(extractConfigChanges(ctx, refXPath)); 957 } 958 959 967 private static ArrayList extractConfigChanges(ConfigContext configContext, 968 String xpath) { 969 if (configContext == null) { 970 String msg = localStrings.getString( "admin.event.null_config_context" ); 971 throw new IllegalArgumentException ( msg ); 972 } 973 ArrayList myChanges = new ArrayList (); 974 ArrayList allChanges = configContext.getConfigChangeList(); 975 if (allChanges == null) { 976 String msg = localStrings.getString( "admin.event.null_config_changes_in_configcontext" ); 977 throw new IllegalStateException ( msg ); 978 } 979 logger.log(Level.FINE, EXTRACT_CHANGE, xpath); 980 Iterator iter = allChanges.iterator(); 981 while (iter.hasNext()) { 982 ConfigChange change = (ConfigChange)iter.next(); 983 logger.log(Level.FINE, PROCESS_CHANGE, change); 984 String changeXPath = null; 985 if (change != null) { 986 changeXPath = cleanXPath(change.getXPath()); 987 logger.log(Level.FINEST, CONFIG_CHANGE_XPATH, changeXPath); 988 } 989 if (change == null || changeXPath == null) { 990 logger.log(Level.FINE, CHANGE_NULL, change); 991 continue; 992 } 993 if (changeXPath.equals(xpath)) { 994 myChanges.add(change); 996 } else { 997 } 999 } 1000 iter = myChanges.iterator(); 1001 while (iter.hasNext()) { 1002 configContext.removeConfigChange((ConfigChange)iter.next()); 1003 } 1004 return myChanges; 1005 } 1006 1007 1013 private static String cleanXPath(String xpath) { 1014 if (xpath == null) { 1015 return xpath; 1016 } 1017 return xpath.replaceAll("/{2,}", "/"); 1018 } 1019 1020 1026 private static boolean matchRegex(String regex, String str) { 1027 Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); 1028 Matcher matcher = pattern.matcher(str); 1029 return matcher.matches(); 1030 } 1031 1032 1042 private ResourceDeployEvent findResourceDeployEvent(String resType, 1043 String resName) { 1044 if (resType == null || resName == null) { 1045 String msg = localStrings.getString( "admin.event.null_resource_type_or_name", resType, resName ); 1046 throw new IllegalArgumentException ( msg ); 1047 } 1048 ResourceDeployEvent resEvent = null; 1049 Iterator iter = cache.iterator(); 1050 while (iter.hasNext()) { 1051 AdminEvent event = (AdminEvent)iter.next(); 1052 if (event instanceof ResourceDeployEvent) { 1053 resEvent = (ResourceDeployEvent)event; 1054 if (resType.equals(resEvent.getResourceType()) 1055 && resName.equals(resEvent.getResourceName())) { 1056 break; 1057 } else { 1058 resEvent = null; 1059 } 1060 } 1061 } 1062 return resEvent; 1063 } 1064 1065 1073 private ApplicationDeployEvent findApplicationDeployEvent(String appName) { 1074 if (appName == null) { 1075 String msg = localStrings.getString( "admin.event.null_application_name" ); 1076 throw new IllegalArgumentException ( msg ); 1077 } 1078 ApplicationDeployEvent appEvent = null; 1079 Iterator iter = cache.iterator(); 1080 while (iter.hasNext()) { 1081 AdminEvent event = (AdminEvent)iter.next(); 1082 if (event instanceof ApplicationDeployEvent) { 1083 appEvent = (ApplicationDeployEvent)event; 1084 if (appName.equals(appEvent.getApplicationName())) { 1085 break; 1086 } else { 1087 appEvent = null; 1088 } 1089 } 1090 } 1091 return appEvent; 1092 } 1093 1094 1104 private ModuleDeployEvent findModuleDeployEvent(String modType, 1105 String modName) { 1106 if (modType == null || modName == null) { 1107 String msg = localStrings.getString( "admin.event.null_module_type_or_name", modType, modName ); 1108 throw new IllegalArgumentException ( msg ); 1109 } 1110 ModuleDeployEvent modEvent = null; 1111 Iterator iter = cache.iterator(); 1112 while (iter.hasNext()) { 1113 AdminEvent event = (AdminEvent)iter.next(); 1114 if (event instanceof ModuleDeployEvent) { 1115 modEvent = (ModuleDeployEvent)event; 1116 if (modEvent.getModuleType().equals(modType) 1117 && modEvent.getModuleName().equals(modName)) { 1118 break; 1119 } else { 1120 modEvent = null; 1121 } 1122 } 1123 } 1124 return modEvent; 1125 } 1126 1127 1130 private void purgeNopEvents() { 1131 Iterator iter = cache.iterator(); 1132 while (iter.hasNext()) { 1133 AdminEvent event = (AdminEvent)iter.next(); 1134 if (event.isNoOp()) { 1135 logger.log(Level.FINE, PURGE_NOOP, event); 1136 iter.remove(); 1137 } 1138 } 1139 } 1140 1141 1145 public void setRestartNeeded(boolean flag) { 1146 if (flag) { 1147 if (!restartNeeded) { 1148 setRestartNeededTrue(true); 1149 } 1150 } else { 1151 restartNeeded = false; 1152 } 1153 } 1154 1155 1162 private void setRestartNeededTrue(boolean notifyInstance) { 1163 restartNeeded = true; 1164 tsRestartNeededSince = System.currentTimeMillis(); 1165 if (notifyInstance) { 1166 RMIClient channel = AdminChannel.getRMIClient(instanceName); 1167 channel.setRestartNeeded(true); 1168 } 1169 } 1170 1171 1174 public boolean isInstanceRestartNeeded() { 1175 if (restartNeeded) { 1176 RMIClient channel = AdminChannel.getRMIClient(instanceName); 1177 boolean alreadyRestarted = 1178 channel.hasRestartedSince(tsRestartNeededSince); 1179 if (alreadyRestarted) { 1180 restartNeeded = false; 1181 } 1182 } 1183 return restartNeeded; 1184 } 1185 1186 private final static String RES_PFX = ServerXPathHelper.XPATH_RESOURCES; 1187 private final static String APP_PFX = ServerXPathHelper.XPATH_J2EE_APPLICATION; 1188 private final static String WEB_PFX = ServerXPathHelper.XPATH_WEB_MODULE; 1189 private final static String EJB_PFX = ServerXPathHelper.XPATH_EJB_MODULE; 1190 private final static String RAR_PFX = ServerXPathHelper.XPATH_CONNECTOR_MODULE; 1191 private final static String ACC_PFX = ServerXPathHelper.XPATH_APPCLIENT_MODULE; 1192 1193 private final static String HTTP_SERVICE = ServerXPathHelper.XPATH_HTTP_SERVICE; 1194 private final static String WEB_CONTAINER = ServerXPathHelper.XPATH_WEB_CONTAINER; 1195 1196 private final static String PROPERTY_REGEX = ServerXPathHelper.XPATH_DOMAIN 1197 + ServerXPathHelper.XPATH_SEPARATOR + "{1,}" + ".*" 1198 + ServerXPathHelper.XPATH_SEPARATOR + "{1,}" 1199 + ServerTags.ELEMENT_PROPERTY + ".*"; 1200 1201 private final static String LOG_LEVEL_XPATH = 1202 ServerXPathHelper.XPATH_CONFIG + ServerXPathHelper.XPATH_SEPARATOR 1203 + ServerTags.LOG_SERVICE + ServerXPathHelper.XPATH_SEPARATOR 1204 + ServerTags.MODULE_LOG_LEVELS; 1205 1206 private final static String MONITORING_LEVEL_XPATH = 1207 ServerXPathHelper.XPATH_CONFIG + ServerXPathHelper.XPATH_SEPARATOR 1208 + ServerTags.MONITORING_SERVICE + ServerXPathHelper.XPATH_SEPARATOR 1209 + ServerTags.MODULE_MONITORING_LEVELS; 1210 1211 private final static String PROCESS_CHANGE = "event.process_change"; 1212 private final static String CHANGE_NULL = "event.change_null"; 1213 private final static String EXTRACT_CHANGE = "event.extract_change"; 1214 private final static String CONFIG_CHANGE_XPATH = "event.config_change_xpath"; 1215 private final static String PURGE_NOOP = "event.purge_noop"; 1216 private final static String NULL_UPDATED_ATTRS = "event.null_updated_attrs"; 1217 private final static String INVALID_XPATH_TOKENIZATION = 1218 "event.invalid_xpath_tokenization"; 1219 1220 private static StringManager localStrings = 1222 StringManager.getManager( AdminEventCache.class ); 1223 1224 1231 abstract class LevelChangeProcessor { 1232 AdminEventCache eventCache; 1233 1234 LevelChangeProcessor(AdminEventCache cache) { 1235 eventCache = cache; 1236 } 1237 1238 abstract boolean isRelevant(String xpath); 1239 1240 abstract AdminEvent createEvent(String componentName, String oldValue, 1241 String newValue); 1242 } 1243 1244 1247 class LogLevelChangeProcessor extends LevelChangeProcessor { 1248 LogLevelChangeProcessor(AdminEventCache cache) { 1249 super(cache); 1250 } 1251 1252 boolean isRelevant(String xpath) { 1253 return eventCache.isLogLevelXPath(xpath); 1254 } 1255 1256 AdminEvent createEvent(String componentName, String oldValue, 1257 String newValue) { 1258 LogLevelChangeEvent event = new LogLevelChangeEvent( 1259 eventCache.instanceName); 1260 event.setModuleName(componentName); 1261 event.setOldLogLevel(oldValue); 1262 event.setNewLogLevel(newValue); 1263 return event; 1264 } 1265 } 1266 1267 1270 class MonitoringLevelChangeProcessor extends LevelChangeProcessor { 1271 MonitoringLevelChangeProcessor(AdminEventCache cache) { 1272 super(cache); 1273 } 1274 1275 boolean isRelevant(String xpath) { 1276 return eventCache.isMonitoringLevelXPath(xpath); 1277 } 1278 1279 AdminEvent createEvent(String componentName, String oldValue, 1280 String newValue) { 1281 MonitoringLevelChangeEvent event = new MonitoringLevelChangeEvent( 1282 eventCache.instanceName); 1283 event.setComponentName(componentName); 1284 event.setOldMonitoringLevel(oldValue); 1285 event.setNewMonitoringLevel(newValue); 1286 return event; 1287 } 1288 } 1289 1290 1297 abstract class RefProcessor { 1298 AdminEventCache adminEventCache; 1299 Map refTypeXPathMap = new HashMap (); 1300 boolean resEnabled; 1301 1302 RefProcessor(AdminEventCache cache) { 1303 adminEventCache = cache; 1304 } 1305 1306 1310 abstract boolean isRelevant(String xpath); 1311 1312 1326 abstract boolean process(String refName, String refType, 1327 ConfigChange change); 1328 1329 1332 String getRefName(String xpath) { 1333 return adminEventCache.getXPathToken(xpath, 3); 1334 } 1335 1336 1339 String getRefType(String refName, ArrayList allChanges) { 1340 String refType = getRefTypeFromConfig(refName); 1343 if (refType == null) { 1344 refType = getRefTypeFromChanges(refName, allChanges); 1346 } 1347 return refType; 1348 } 1349 1350 1353 String getRefTypeFromConfig(String refName) { 1354 ConfigContext ctx = adminEventCache.adminConfigContext; 1355 if (ctx == null) { 1356 return null; 1357 } 1358 String refType = null; 1359 Iterator iter = refTypeXPathMap.entrySet().iterator(); 1360 while (iter.hasNext()) { 1361 Map.Entry entry = (Map.Entry )iter.next(); 1362 String xpath = (String )entry.getValue(); 1363 ConfigBean bean = null; 1364 try { 1365 bean = ctx.exactLookup(xpath); 1366 } catch (ConfigException ce) { 1367 } 1370 if (bean != null) { 1371 refType = (String )entry.getKey(); 1372 resEnabled = getEnabledState(bean); 1373 break; 1374 } 1375 } 1376 return refType; 1377 } 1378 1379 1384 String getRefTypeFromChanges(String refName, ArrayList allChanges) { 1385 if (allChanges == null) { 1386 return null; 1387 } 1388 String refType = null; 1389 Iterator iter = allChanges.iterator(); 1390 while (iter.hasNext()) { 1391 ConfigChange change = (ConfigChange)iter.next(); 1392 String xpath = adminEventCache.cleanXPath(change.getXPath()); 1393 Iterator iter2 = refTypeXPathMap.entrySet().iterator(); 1394 while (iter2.hasNext()) { 1395 Map.Entry entry = (Map.Entry )iter2.next(); 1396 String xpath2 = (String )entry.getValue(); 1397 if (xpath != null && xpath.equals(xpath2)) { 1398 refType = (String )entry.getKey(); 1399 if (change instanceof ConfigAdd) { 1400 ConfigBean b = ((ConfigAdd)change).getConfigBean(); 1401 resEnabled = getEnabledState(b); 1402 } else { 1403 resEnabled = false; 1406 } 1407 break; 1408 } 1409 } 1410 if (refType != null) { 1411 break; 1412 } 1413 } 1414 return refType; 1415 } 1416 1417 1422 boolean getEnabledState(ConfigBean bean) { 1423 String enabledStr = null; 1424 try { 1425 enabledStr = bean.getAttributeValue(ServerTags.ENABLED); 1426 } catch (IllegalArgumentException iae) { 1427 enabledStr = "true"; 1429 } 1430 return adminEventCache.getServerXmlBooleanValue(enabledStr); 1431 } 1432 1433 1438 String getActionCode(ConfigChange change) { 1439 String actionCode = null; 1440 if (change instanceof ConfigUpdate) { 1441 ConfigUpdate update = (ConfigUpdate)change; 1442 String enableStr = update.getNewValue(ServerTags.ENABLED); 1443 if (enableStr != null) { 1444 boolean enabled = 1445 adminEventCache.getServerXmlBooleanValue( 1446 enableStr); 1447 if (enabled && resEnabled) { 1448 actionCode = BaseDeployEvent.ENABLE; 1449 } else if (enabled && !resEnabled) { 1450 actionCode = BaseDeployEvent.REDEPLOY; 1451 } else { 1452 actionCode = BaseDeployEvent.DISABLE; 1453 } 1454 } else { 1455 actionCode = BaseDeployEvent.REDEPLOY; 1456 } 1457 } else if (change instanceof ConfigAdd) { 1458 actionCode = BaseDeployEvent.DEPLOY; 1459 } else if (change instanceof ConfigDelete) { 1460 actionCode = BaseDeployEvent.UNDEPLOY; 1461 } else if (change instanceof ConfigSet) { 1462 actionCode = BaseDeployEvent.REDEPLOY; 1464 } else { 1465 String msg = localStrings.getString( 1467 "admin.event.unknown_configchange_for_resources"); 1468 throw new IllegalStateException ( msg ); 1469 } 1470 return actionCode; 1471 } 1472 1473 1477 abstract void initRefTypeXPathMap(String refName); 1478 1479 } 1480 1481 1484 class AppRefProcessor extends RefProcessor { 1485 AppRefProcessor(AdminEventCache cache) { 1486 super(cache); 1487 } 1488 1489 boolean isRelevant(String xpath) { 1490 return adminEventCache.isAppRefXPath(xpath); 1491 } 1492 1493 1496 boolean process(String refName, String refType, ConfigChange change) { 1497 String compType = null; 1498 String modType = null; 1499 if (BaseDeployEvent.APPLICATION.equals(refType)) { 1500 compType = BaseDeployEvent.APPLICATION; 1501 } else if ((ModuleDeployEvent.TYPE_WEBMODULE.equals(refType)) 1502 || (ModuleDeployEvent.TYPE_EJBMODULE.equals(refType)) 1503 || (ModuleDeployEvent.TYPE_CONNECTOR.equals(refType)) 1504 || (ModuleDeployEvent.TYPE_APPCLIENT.equals(refType))) { 1505 compType = BaseDeployEvent.MODULE; 1506 modType = refType; 1507 } else { 1508 return false; 1510 } 1511 AdminEvent theEvent = null; 1512 if (BaseDeployEvent.APPLICATION.equals(compType)) { 1513 theEvent = adminEventCache.findApplicationDeployEvent(refName); 1514 } else { 1515 theEvent = adminEventCache.findModuleDeployEvent( 1516 modType, refName); 1517 } 1518 if (theEvent == null) { 1519 String actionCode = getActionCode(change); 1520 if(BaseDeployEvent.ENABLE.equals(actionCode) || 1523 BaseDeployEvent.DISABLE.equals(actionCode) || 1524 BaseDeployEvent.REDEPLOY.equals(actionCode)) 1525 return false; 1526 if (BaseDeployEvent.APPLICATION.equals(compType)) { 1527 theEvent = new ApplicationDeployEvent( 1528 adminEventCache.instanceName, refName, 1529 actionCode); 1530 } else { 1531 theEvent = new ModuleDeployEvent( 1532 adminEventCache.instanceName, refName, 1533 modType, actionCode); 1534 } 1535 cache.add(theEvent); 1536 } 1537 theEvent.addConfigChange(change); 1538 return true; 1539 } 1540 1541 1547 void initRefTypeXPathMap(String refName) { 1548 refTypeXPathMap.put( 1549 BaseDeployEvent.APPLICATION, 1550 ServerXPathHelper.getAppIdXpathExpression(refName)); 1551 refTypeXPathMap.put( 1552 ModuleDeployEvent.TYPE_WEBMODULE, 1553 ServerXPathHelper.getWebModuleIdXpathExpression(refName)); 1554 refTypeXPathMap.put( 1555 ModuleDeployEvent.TYPE_EJBMODULE, 1556 ServerXPathHelper.getEjbModuleIdXpathExpression(refName)); 1557 refTypeXPathMap.put( 1558 ModuleDeployEvent.TYPE_CONNECTOR, 1559 ServerXPathHelper.getConnectorModuleIdXpathExpression( 1560 refName)); 1561 refTypeXPathMap.put( 1562 ModuleDeployEvent.TYPE_APPCLIENT, 1563 ServerXPathHelper.getAppClientModuleIdXpathExpression( 1564 refName)); 1565 } 1566 } 1567 1568 1571 class ResRefProcessor extends RefProcessor { 1572 ResRefProcessor(AdminEventCache cache) { 1573 super(cache); 1574 } 1575 1576 boolean isRelevant(String xpath) { 1577 return adminEventCache.isResRefXPath(xpath); 1578 } 1579 1580 1583 boolean process(String refName, String refType, ConfigChange change) { 1584 ResourceDeployEvent event = 1585 findResourceDeployEvent(refType, refName); 1586 if (event == null) { 1587 String actionCode = getActionCode(change); 1588 event = new ResourceDeployEvent(adminEventCache.instanceName, 1589 refName, refType, actionCode); 1590 cache.add(event); 1591 } 1592 event.addConfigChange(change); 1593 return true; 1594 } 1595 1596 1599 void initRefTypeXPathMap(String refName) { 1600 refTypeXPathMap.put( 1601 ResourceDeployEvent.RES_TYPE_CUSTOM, 1602 ServerXPathHelper.getCustomResourceIdXpath(refName)); 1603 refTypeXPathMap.put( 1604 ResourceDeployEvent.RES_TYPE_EXTERNAL_JNDI, 1605 ServerXPathHelper.getJNDIResourceIdXpath(refName)); 1606 refTypeXPathMap.put( 1607 ResourceDeployEvent.RES_TYPE_JCP, 1608 ServerXPathHelper.getJDBCConnectionPoolIdXpath(refName)); 1609 refTypeXPathMap.put( 1610 ResourceDeployEvent.RES_TYPE_JDBC, 1611 ServerXPathHelper.getJDBCResourceIdXpath(refName)); 1612 refTypeXPathMap.put( 1613 ResourceDeployEvent.RES_TYPE_MAIL, 1614 ServerXPathHelper.getMailResourceIdXpath(refName)); 1615 refTypeXPathMap.put( 1616 ResourceDeployEvent.RES_TYPE_PMF, 1617 ServerXPathHelper.getPMFactoryResourceIdXpath(refName)); 1618 refTypeXPathMap.put( 1619 ResourceDeployEvent.RES_TYPE_AOR, 1620 ServerXPathHelper.getAbsoluteIdXpathExpression( 1621 ServerXPathHelper.XPATH_ADMIN_OBJECT_RESOURCE, 1622 ServerTags.JNDI_NAME, refName)); 1623 refTypeXPathMap.put( 1624 ResourceDeployEvent.RES_TYPE_CCP, 1625 ServerXPathHelper.getAbsoluteIdXpathExpression( 1626 ServerXPathHelper.XPATH_CONNECTOR_CONNECTION_POOL, 1627 ServerTags.NAME, refName)); 1628 refTypeXPathMap.put( 1629 ResourceDeployEvent.RES_TYPE_CR, 1630 ServerXPathHelper.getAbsoluteIdXpathExpression( 1631 ServerXPathHelper.XPATH_CONNECTOR_RESOURCE, 1632 ServerTags.JNDI_NAME, refName)); 1633 refTypeXPathMap.put( 1634 ResourceDeployEvent.RES_TYPE_RAC, 1635 ServerXPathHelper.getAbsoluteIdXpathExpression( 1636 ServerXPathHelper.XPATH_RESOURCE_ADAPTER_CONFIG, 1637 ServerTags.NAME, refName)); 1638 } 1639 } 1640} 1641 | Popular Tags |