1 23 24 31 package com.sun.enterprise.admin.event; 32 33 import java.util.ArrayList ; 34 import java.util.Set ; 35 import java.util.Iterator ; 36 import java.util.List ; 37 import java.lang.reflect.Method ; 38 39 import com.sun.enterprise.config.serverbeans.ServerTags; 40 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 41 import com.sun.enterprise.config.serverbeans.Applications; 42 import com.sun.enterprise.config.ConfigContext; 43 import com.sun.enterprise.config.ConfigChange; 44 import com.sun.enterprise.config.ConfigUpdate; 45 import com.sun.enterprise.config.impl.ConfigUpdateImpl; 46 import com.sun.enterprise.admin.target.TargetType; 47 48 51 public abstract class ElementChangeEventsFactory { 52 53 62 static ArrayList createEvents( 63 String event_type, String instanceName, 64 String element_type, 65 ArrayList changeList, ConfigContext ctx, 66 ArrayList globalChangeList) throws Exception 67 { 68 69 int action = ElementChangeHelper.getActionCodeForChanges(changeList); 70 if(action==ElementChangeEvent.ACTION_ELEMENT_UNDEFINED) 71 { 72 return null; } 74 75 ArrayList events = null; 76 AdminEvent event = null; 77 String element_xpath = ElementChangeHelper.getElementXPath(changeList); 78 String targetName = ElementChangeHelper.getConfigElementTargetName(element_xpath, ctx); 79 String element_id = ElementChangeHelper.getConfigElementPrimaryKey(element_xpath); 81 if (event_type.equals(ApplicationDeployEvent.eventType)) 85 { 86 if(APPLICATION_REF_TYPE_NAME.equals(element_type)) 87 { 88 try { 89 if(isMBeanReference(ctx, element_id, globalChangeList)) 90 { 91 event_type="com.sun.enterprise.admin.event.MBeanElementChangeEvent"; 92 events = buildSelfConstructingEvent(event_type, 94 instanceName, element_type, changeList, ctx); 95 if(events!=null && 96 (action==ElementChangeEvent.ACTION_ELEMENT_CREATE || 97 action==ElementChangeEvent.ACTION_ELEMENT_DELETE ) ) 98 { 99 100 String actionCode = 102 (action==ElementChangeEvent.ACTION_ELEMENT_CREATE)? 103 BaseDeployEvent.DEPLOY:BaseDeployEvent.UNDEPLOY; 104 for(int i=0; i<events.size(); i++ ) 105 { 106 AdminEvent ae = (AdminEvent)events.get(i); 107 String effective = ae.getEffectiveDestination(); 108 DependencyResolver dr = 109 new DependencyResolver(ctx, effective); 110 List list = dr.resolveApplications(element_id, actionCode); 111 ae.addDependentConfigChange(list); 112 } 113 } 114 } 115 } catch (Exception ce){ 116 events = null; 118 } 119 } 120 } 121 122 events = buildSelfConstructingEvent(event_type, 124 instanceName, element_type, changeList, ctx); 125 if(events!=null) 126 { 127 140 return events; 141 } 142 143 boolean bMustSetChangeList = true; if(event_type.equals(SecurityServiceEvent.eventType)) 146 { 147 event = (AdminEvent)createSecurityServiceEvent(instanceName, element_id, action); 148 } 149 else if(event_type.equals(AuditModuleEvent.eventType)) 150 { 151 event = (AdminEvent)createAuditModuleEvent(instanceName, element_id, action); 152 } 153 else if(event_type.equals(AuthRealmEvent.eventType)) 154 { 155 event = (AdminEvent)createAuthRealmEvent(instanceName, element_id, action); 156 } 157 else if(event_type.equals(LogLevelChangeEvent.eventType)) 158 { 159 events = createLogLevelEvents(instanceName, element_id, action, changeList); 160 bMustSetChangeList = false; 161 } 162 else if(event_type.equals(MonitoringLevelChangeEvent.eventType)) 163 { 164 events = createMonitoringLevelEvents(instanceName, element_id, action, changeList); 165 bMustSetChangeList = false; 166 } 167 else if(event_type.equals(ResourceDeployEvent.eventType)) 168 { 169 event = (AdminEvent)createResourceDeployEvent(instanceName, element_type, element_id, action, changeList, targetName, ctx); 170 bMustSetChangeList = false; 171 } 172 else if(event_type.equals(ModuleDeployEvent.eventType) || 173 event_type.equals(ApplicationDeployEvent.eventType)) 174 { 175 event = (AdminEvent)createModAppDeployEvent(instanceName, element_type, element_id, action, changeList, targetName, ctx); 176 bMustSetChangeList = false; 177 } 178 else 179 { 180 return null; 181 } 182 183 184 if( event!=null && (events==null || events.size()==0) ) 185 { 186 events = new ArrayList (); 187 events.add(event); 188 } 189 190 if( events==null || events.size()==0 ) 191 return null; 192 193 setTargetDestinationAndConfigChange(events, targetName, changeList, bMustSetChangeList); 195 196 return events; 198 } 199 200 static private ArrayList buildSelfConstructingEvent( 202 String event_type, 203 String instanceName, 204 String element_type, 205 ArrayList changeList, 206 ConfigContext ctx) throws Exception 207 { 208 try { 209 Class cl = Class.forName(event_type); 211 Method m = cl.getMethod("getEventInstances", new Class []{ 212 String .class, String .class, String .class, 213 ArrayList .class, ConfigContext.class}); 214 return (ArrayList )m.invoke(null, new Object []{event_type, instanceName, element_type, changeList, ctx}); 215 } catch (Exception e) { 216 if( !(e instanceof ClassNotFoundException ) && 217 !(e instanceof NoSuchMethodException ) ) 218 throw e; 219 } 220 return null; 221 } 222 223 static private boolean isMBeanReference( 225 ConfigContext ctx, 226 String element_id, 227 ArrayList globalChangeList) 228 { 229 String typeInDomain = null; 230 try { 231 typeInDomain = ApplicationHelper.getApplicationType(ctx, element_id); 232 } catch(Exception e) 233 { 234 } 235 if(typeInDomain!=null) 236 return Applications.MBEAN.equals(typeInDomain); 237 String toCompare = 240 "/" + ServerTags.MBEAN + 241 "[@" + ServerTags.NAME + "='" + element_id + "']"; 242 for(int i=0; i<globalChangeList.size(); i++) 243 { 244 ConfigChange change = (ConfigChange)globalChangeList.get(i); 245 String xpath; 246 if(change!=null && 247 (xpath=change.getXPath())!=null && 248 xpath.endsWith(toCompare)) 249 return true; 250 } 251 return false; 252 } 253 254 static private void setTargetDestinationAndConfigChange(ArrayList events, String targetName, ArrayList changeList, boolean bSetChanges) 256 { 257 if(events!=null) 258 { 259 for(int i=0; i<events.size(); i++) 260 { 261 AdminEvent event = (AdminEvent)events.get(i); 262 event.setTargetDestination(targetName); 263 if(bSetChanges && changeList!=null) 264 event.addConfigChange(changeList); 265 } 266 } 267 } 268 269 272 static private SecurityServiceEvent createSecurityServiceEvent(String instanceName, String id, int action) 276 { 277 if(action==ElementChangeEvent.ACTION_ELEMENT_CREATE) 279 action = SecurityServiceEvent.ACTION_CREATE; 280 else if(action==ElementChangeEvent.ACTION_ELEMENT_DELETE) 281 action = SecurityServiceEvent.ACTION_DELETE; 282 else if(action==ElementChangeEvent.ACTION_ELEMENT_UPDATE) 283 action = SecurityServiceEvent.ACTION_UPDATE; 284 return new SecurityServiceEvent(instanceName, action); 285 } 286 287 static private AuditModuleEvent createAuditModuleEvent(String instanceName, String id, int action) 291 { 292 if(action==ElementChangeEvent.ACTION_ELEMENT_CREATE) 294 action = AuditModuleEvent.ACTION_CREATE; 295 else if(action==ElementChangeEvent.ACTION_ELEMENT_DELETE) 296 action = AuditModuleEvent.ACTION_DELETE; 297 else if(action==ElementChangeEvent.ACTION_ELEMENT_UPDATE) 298 action = AuditModuleEvent.ACTION_UPDATE; 299 return new AuditModuleEvent(instanceName, id, action); 300 } 301 302 static private AuthRealmEvent createAuthRealmEvent(String instanceName, String id, int action) 306 { 307 if(action==ElementChangeEvent.ACTION_ELEMENT_CREATE) 309 action = AuthRealmEvent.ACTION_CREATE; 310 else if(action==ElementChangeEvent.ACTION_ELEMENT_DELETE) 311 action = AuthRealmEvent.ACTION_DELETE; 312 else if(action==ElementChangeEvent.ACTION_ELEMENT_UPDATE) 313 action = AuthRealmEvent.ACTION_UPDATE; 314 return new AuthRealmEvent(instanceName, id, action); 315 } 316 317 static private ArrayList createLogLevelEvents(String instanceName, String id, int action, ArrayList changeList) 321 { 322 ArrayList events = new ArrayList (); 323 for(int i=0; i<changeList.size(); i++) 324 { 325 Object chg = changeList.get(i); 326 327 if (ElementChangeHelper.isPropertyChange((ConfigChange)chg)) 328 { 329 LogLevelChangeEvent event=new LogLevelChangeEvent(instanceName); 331 332 event.setPropertyChanged(true); 334 335 String xpath = ((ConfigChange) chg).getXPath(); 337 event.setPropertyName( 338 ElementChangeHelper.getConfigElementPrimaryKey(xpath) ); 339 340 event.addConfigChange((ConfigChange)chg); 342 343 events.add(event); 345 } 346 } 347 348 if (action!=ElementChangeEvent.ACTION_ELEMENT_UPDATE) 349 return events; 350 351 for(int i=0; i<changeList.size(); i++) 352 { 353 Object chg = changeList.get(i); 354 if(!(chg instanceof ConfigUpdate) || 355 ElementChangeHelper.isPropertyChange((ConfigChange)chg)) 356 continue; ConfigUpdate update = (ConfigUpdate)chg; 358 Set attrs = update.getAttributeSet(); 359 if (attrs != null) 360 { 361 Iterator iter = attrs.iterator(); 362 while (iter.hasNext()) { 363 String compName = (String )iter.next(); 364 String oldValue = update.getOldValue(compName); 365 String newValue = update.getNewValue(compName); 366 LogLevelChangeEvent event = new LogLevelChangeEvent(instanceName); 367 event.setModuleName(compName); 368 event.setOldLogLevel(oldValue); 369 event.setNewLogLevel(newValue); 370 events.add(event); 371 ConfigUpdate upd = new ConfigUpdateImpl(update.getXPath(), 372 compName, oldValue,newValue); 373 event.addConfigChange(upd); 375 } 376 } 377 } 378 return events; 379 } 380 381 static private ArrayList createMonitoringLevelEvents(String instanceName, String id, int action, ArrayList changeList) 385 { 386 if (action!=ElementChangeEvent.ACTION_ELEMENT_UPDATE) 387 return null; 388 389 ArrayList events = new ArrayList (); 390 for(int i=0; i<changeList.size(); i++) 391 { 392 Object chg = changeList.get(i); 393 if(!(chg instanceof ConfigUpdate) || 394 ElementChangeHelper.isPropertyChange((ConfigChange)chg)) 395 continue; ConfigUpdate update = (ConfigUpdate)chg; 397 Set attrs = update.getAttributeSet(); 398 if (attrs != null) 399 { 400 Iterator iter = attrs.iterator(); 401 while (iter.hasNext()) { 402 String compName = (String )iter.next(); 403 String oldValue = update.getOldValue(compName); 404 String newValue = update.getNewValue(compName); 405 MonitoringLevelChangeEvent event = new MonitoringLevelChangeEvent(instanceName); 406 event.setComponentName(compName); 407 event.setOldMonitoringLevel(oldValue); 408 event.setNewMonitoringLevel(newValue); 409 events.add(event); 410 ConfigUpdate upd = new ConfigUpdateImpl(update.getXPath(), 411 compName, oldValue,newValue); 412 event.addConfigChange(upd); 413 } 414 } 415 } 416 return events; 417 } 418 419 static final String RESOURCE_REF_TYPE_NAME = ServerTags.RESOURCE_REF; 420 static final String APPLICATION_REF_TYPE_NAME = ServerTags.APPLICATION_REF; 421 static final String MBEAN_TYPE_NAME = ServerTags.MBEAN; 422 static private ResourceDeployEvent createResourceDeployEvent(String instanceName, 426 String elemType, String id, int action, ArrayList changeList, 427 String targetName, ConfigContext ctx) throws Exception 428 { 429 ResourceDeployEvent rde = null; 430 431 433 if(("security-map").equals(elemType)){ 434 String actionCode = null; 435 if(action==ElementChangeEvent.ACTION_ELEMENT_CREATE || 436 action==ElementChangeEvent.ACTION_ELEMENT_DELETE){ 437 438 actionCode=BaseDeployEvent.REDEPLOY; 439 440 String element_xpath = ElementChangeHelper.getElementXPath(changeList); 441 int endNewXpath = element_xpath.lastIndexOf("security-map"); 443 String new_element_xpath= element_xpath.substring(0,endNewXpath-1); 444 id = ElementChangeHelper.getConfigElementPrimaryKey(new_element_xpath); 445 } 446 447 EventBuilder builder = new EventBuilder(); 448 if(actionCode!=null) 449 rde = builder.createResourceDeployEvent(actionCode, id, 450 ctx, changeList, targetName); 451 return rde; 452 } 453 454 if(RESOURCE_REF_TYPE_NAME.equals(elemType)) 458 { 459 String actionCode = null; 460 if(action==ElementChangeEvent.ACTION_ELEMENT_CREATE) 462 { 463 actionCode = BaseDeployEvent.ADD_REFERENCE; 464 } 465 else if(action==ElementChangeEvent.ACTION_ELEMENT_DELETE) 466 { 467 actionCode = BaseDeployEvent.REMOVE_REFERENCE; 469 } 470 else if(action==ElementChangeEvent.ACTION_ELEMENT_UPDATE) 471 { 472 Boolean bEnabled = null; 473 if ( 474 (bEnabled=ElementChangeHelper.findEnabledChange(changeList))!=null) 475 { 476 actionCode = bEnabled.booleanValue()?BaseDeployEvent.ENABLE:BaseDeployEvent.DISABLE; 477 } 478 479 } 482 EventBuilder builder = new EventBuilder(); 483 if(actionCode!=null) 484 { 485 rde = builder.createResourceDeployEvent(actionCode, id, 486 ctx, changeList, targetName); 487 } 488 } else 489 { 493 String actionCode = null; 497 if(action==ElementChangeEvent.ACTION_ELEMENT_CREATE) 499 { 500 } 502 else if(action==ElementChangeEvent.ACTION_ELEMENT_DELETE) 503 { 504 } 506 else if(action==ElementChangeEvent.ACTION_ELEMENT_UPDATE) 507 { 508 Boolean bEnabled = null; 509 if (changeList.size()==1 && (bEnabled = ElementChangeHelper.findEnabledChange(changeList))!=null) 510 { 511 actionCode = bEnabled.booleanValue()?BaseDeployEvent.ENABLE:BaseDeployEvent.DISABLE; 512 } 513 else 514 actionCode = BaseDeployEvent.REDEPLOY; 515 } 516 EventBuilder builder = new EventBuilder(); 517 if(actionCode!=null) 518 rde = builder.createResourceDeployEvent(actionCode, id, 519 ctx, changeList, targetName); 520 } 521 return rde; 522 } 523 524 static private BaseDeployEvent createModAppDeployEvent(String instanceName, 528 String elemType, String id, int action, ArrayList changeList, 529 String targetName, ConfigContext ctx) throws Exception 530 { 531 BaseDeployEvent bde = null; 532 String actionCode = null; 533 if(APPLICATION_REF_TYPE_NAME.equals(elemType)) 534 { 535 if(action==ElementChangeEvent.ACTION_ELEMENT_CREATE) 539 { 540 } 542 else if(action==ElementChangeEvent.ACTION_ELEMENT_DELETE) 543 { 544 } 546 else if(action==ElementChangeEvent.ACTION_ELEMENT_UPDATE) 547 { 548 Boolean bEnabled = null; 549 if ( 550 (bEnabled=ElementChangeHelper.findEnabledChange(changeList))!=null) 551 { 552 actionCode = bEnabled.booleanValue()?BaseDeployEvent.ENABLE:BaseDeployEvent.DISABLE; 553 } 554 555 } 558 EventBuilder builder = new EventBuilder(); 559 if(actionCode!=null) 560 bde = builder.createModAppDeployEvent(actionCode, id, 561 ctx, changeList, targetName); 562 } 563 else 564 { 565 if(action==ElementChangeEvent.ACTION_ELEMENT_CREATE) 570 { 571 } 573 else if(action==ElementChangeEvent.ACTION_ELEMENT_DELETE) 574 { 575 } 577 else if(action==ElementChangeEvent.ACTION_ELEMENT_UPDATE) 578 { 579 Boolean bEnabled = null; 580 if (changeList.size()==1 && (bEnabled = ElementChangeHelper.findEnabledChange(changeList))!=null) 581 { 582 actionCode = bEnabled.booleanValue()?BaseDeployEvent.ENABLE:BaseDeployEvent.DISABLE; 583 } 584 else 585 actionCode = BaseDeployEvent.REDEPLOY; 586 } 587 EventBuilder builder = new EventBuilder(); 588 if(actionCode!=null) 589 bde = builder.createModAppDeployEvent(actionCode, id, 590 ctx, changeList, targetName); 591 } 592 return bde; 593 } 594 595 } 596 | Popular Tags |