1 23 24 package com.sun.enterprise.tools.admingui.handlers; 25 26 import java.util.ArrayList ; 27 import java.util.List ; 28 import java.util.Properties ; 29 import java.util.TreeSet ; 30 31 import com.iplanet.jato.view.View; 32 import com.iplanet.jato.view.ViewBase; 33 import com.iplanet.jato.view.ViewBean; 34 import com.iplanet.jato.RequestContext; 35 import com.iplanet.jato.RequestManager; 36 import com.iplanet.jato.model.DefaultModel; 37 import com.iplanet.jato.model.Model; 38 import com.iplanet.jato.view.html.SelectableGroup; 39 import com.iplanet.jato.view.html.OptionList; 40 41 42 import javax.servlet.http.HttpSession ; 43 44 import javax.management.MBeanException ; 45 import javax.management.ObjectName ; 46 import javax.management.AttributeList ; 47 import javax.management.Attribute ; 48 49 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 50 import com.sun.enterprise.tools.guiframework.model.ModelManager; 51 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle; 52 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 53 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 54 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 55 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor; 56 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent; 57 import com.sun.web.ui.view.html.CCOption; 58 import com.sun.web.ui.view.html.CCOptionGroup; 59 import com.sun.web.ui.view.html.CCOptionSeparator; 60 61 import com.sun.web.ui.model.CCActionTableModelInterface; 62 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 63 import com.sun.enterprise.tools.admingui.util.Util; 64 import com.sun.enterprise.tools.admingui.ConfigProperties; 65 66 67 import java.util.logging.LogManager ; 68 import java.util.Enumeration ; 69 import com.sun.enterprise.config.serverbeans.Server; 70 import com.sun.enterprise.config.serverbeans.ServerHelper; 71 72 import static com.sun.enterprise.admin.selfmanagement.event.ManagementRuleConstants.*; 73 74 75 public class ManagementRulesHandler { 76 static final String PROPERTY_NOTIFICATION_TYPE="type"; 77 78 79 public void loadManagementRulesTable(RequestContext ctx, HandlerContext handlerCtx) { 80 81 CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel"); 84 ((DefaultModel)model).clear(); 85 String objectName = (String ) handlerCtx.getInputValue("objectName"); 86 String methodName = (String ) handlerCtx.getInputValue("methodName"); 87 String eventObjectName = (String ) handlerCtx.getInputValue("eventObjectName"); 88 89 try{ 90 model.setRowSelectionType("multiple"); 91 model.beforeFirst(); 92 ObjectName [] rules = (ObjectName [] ) MBeanUtil.invoke(objectName, methodName, null, null); 93 94 for(int i=0; i< rules.length; i++){ 95 model.appendRow(); 96 String ruleName= rules[i].getKeyProperty("name"); 97 model.setValue("name", ruleName); 98 model.setValue("ruleObjectName", rules[i]); 99 String enabled = (String ) MBeanUtil.getAttribute( rules[i], "enabled"); 100 model.setValue("status", "true".equals(enabled)? Util.getMessage("common.Enabled") : Util.getMessage("common.Disabled")); 101 String eventType = (String ) MBeanUtil.getAttribute(eventObjectName+ruleName, "type"); 102 model.setValue("eventType", eventType); 103 104 105 } 106 107 }catch(Exception ex){ 108 Util.logFINE(ex); 109 } 110 } 111 112 113 public void managementRulesDelete(RequestContext ctx, HandlerContext handlerCtx) { 114 115 CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel"); 116 118 String objectName = (String )handlerCtx.getInputValue("objectName"); 119 String deleteMethod = (String ) handlerCtx.getInputValue("deleteMethod"); 120 121 model.setRowSelectionType("multiple"); 122 try{ 123 model.beforeFirst(); 124 125 while(model.next()) { 126 boolean selected = model.isRowSelected(); 127 if (selected) { 128 String ruleObjectName = (String ) model.getValue("ruleObjectName"); 129 ObjectName objN = new ObjectName (ruleObjectName); 130 String params[]={objN.getKeyProperty("name")}; 131 String types[] = {"java.lang.String"}; 132 MBeanUtil.invoke(objectName, deleteMethod, params, types); 133 model.setRowSelected(false); 134 } 135 } 136 }catch(Exception ex) { 137 ex.printStackTrace(); 138 throw new FrameworkException("Unable to delete Management Rule:", ex); 139 } 140 } 141 142 public void managementRulesChangeStatus(RequestContext ctx, HandlerContext handlerCtx) { 143 144 CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel"); 145 147 String enabled = (String ) handlerCtx.getInputValue("enabled"); 148 model.setRowSelectionType("multiple"); 149 try{ 150 model.beforeFirst(); 151 while(model.next()) { 152 boolean selected = model.isRowSelected(); 153 if (selected) { 154 String ruleObjectName = (String ) model.getValue("ruleObjectName"); 155 MBeanUtil.setAttribute(ruleObjectName, new Attribute ("enabled", enabled)); 156 model.setRowSelected(false); 157 } 158 } 159 }catch(Exception ex) { 160 ex.printStackTrace(); 161 throw new FrameworkException("Unable to set enable status ", ex); 162 } 163 } 164 165 public void populateEventTypes(RequestContext ctx, HandlerContext handlerCtx) { 166 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 168 169 OptionList optionList = new OptionList(); 170 optionList.add("", ""); 171 172 optionList.add(EVENT_MONITOR, EVENT_MONITOR); 173 optionList.add(new CCOptionSeparator()); 174 optionList.add(EVENT_NOTIFICATION, EVENT_NOTIFICATION); 175 optionList.add(new CCOptionSeparator()); 176 CCOptionGroup og = new CCOptionGroup(Util.getMessage("managementRules.systemEvent"), "---"); 177 og.add(new CCOption(EVENT_LIFECYCLE, EVENT_LIFECYCLE)); 178 og.add(new CCOption(EVENT_LOG, EVENT_LOG)); 179 og.add(new CCOption(EVENT_TIMER , EVENT_TIMER)); 180 og.add(new CCOption(EVENT_TRACE ,EVENT_TRACE)); 181 182 Boolean isEE = ConfigProperties.getInstance().getTargetSupported(); 183 if (isEE.booleanValue()) 184 og.add(new CCOption(EVENT_CLUSTER , EVENT_CLUSTER)); 185 og.add(new CCOption(" " ,"")); 186 187 optionList.add(og); 188 dropDownChild.setOptions(optionList); 189 } 190 191 192 public void populateActions(RequestContext ctx, HandlerContext handlerCtx) { 193 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 195 String objectName = (String ) handlerCtx.getInputValue("objectName"); 196 Object [] params = {Boolean.FALSE}; 197 String [] types = {"boolean"}; 198 List <String > actionBeansList = (List ) MBeanUtil.invoke(objectName, "getAllActionMBeans", params, types); 199 if (actionBeansList == null) 200 return; 201 202 OptionList optionList = new OptionList(); 203 optionList.add(" ", ""); 204 for (String actionBeans : actionBeansList) { 205 optionList.add(actionBeans, actionBeans); 206 } 207 dropDownChild.setOptions(optionList); 208 209 String initialValue = (String )handlerCtx.getInputValue("initialValue"); 210 if (initialValue == null || initialValue.length() == 0) { 211 } else { 213 if (dropDownChild.getValue() == null) { 214 dropDownChild.setValue(initialValue); 215 } 216 } 217 } 218 219 public void populateLogLevels(RequestContext ctx, HandlerContext handlerCtx) { 220 populateDropDownEventProperties(handlerCtx, EVENT_LOG, PROPERTY_LOG_LEVEL ); 221 } 222 223 public void populateLogger(RequestContext ctx, HandlerContext handlerCtx) { 224 populateDropDownEventProperties(handlerCtx, EVENT_LOG, PROPERTY_LOG_LOGGERNAME ); 225 226 List <Attribute > eventProperties = (List ) handlerCtx.getInputValue("eventProperties"); 228 if (eventProperties == null || eventProperties.size() < 1){ 229 return; 230 } 231 String loggers = null; 232 for(Attribute attr : eventProperties){ 233 if (PROPERTY_LOG_LOGGERNAME.equals(attr.getName())){ 234 loggers = (String ) attr.getValue(); 235 break; 236 } 237 } 238 if (loggers != null){ 239 String [] eachRow = loggers.split(","); 240 if (eachRow != null & eachRow.length > 0){ 241 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 242 dropDownChild.setValues(eachRow); 243 } 244 } 245 } 246 247 248 public void populateLifeCycleNames(RequestContext ctx, HandlerContext handlerCtx) { 249 populateDropDownEventProperties(handlerCtx, EVENT_LIFECYCLE, PROPERTY_LIFECYCLE_NAME ); 250 } 251 252 253 public void populateTraceNames(RequestContext ctx, HandlerContext handlerCtx) { 254 populateDropDownEventProperties(handlerCtx, EVENT_TRACE, PROPERTY_TRACE_NAME ); 255 } 256 257 public void getEditPage(RequestContext ctx, HandlerContext handlerCtx) { 258 String ruleObjectName = (String )handlerCtx.getInputValue("ruleObjectName"); 259 ObjectName eventObjectName = (ObjectName ) MBeanUtil.invoke(ruleObjectName, "getEvent", null, null); 260 String eventType = (String )MBeanUtil.getAttribute(eventObjectName, "type"); 261 String editPage = null; 262 263 if (EVENT_TIMER.equals(eventType)){ 264 editPage = "managementRuleTimerEdit"; 265 }else 266 if (EVENT_MONITOR.equals(eventType)){ 267 String type = (String ) MBeanUtil.invoke(eventObjectName, "getPropertyValue", 268 new Object []{PROPERTY_MONITOR_TYPE}, 269 new String []{"java.lang.String"}); 270 if(PROPERTY_MONITOR_COUNTER.equals(type)){ 271 editPage = "managementRuleMonitorCountEdit"; 272 }else 273 if (PROPERTY_MONITOR_STRING.equals(type)){ 274 editPage = "managementRuleMonitorStringEdit"; 275 }else 276 editPage = "managementRuleMonitorGaugeEdit"; 277 }else 278 if (EVENT_CLUSTER.equals(eventType)){ 279 editPage = "managementRuleClusterEdit"; 280 }else 281 if (eventType.equals(EVENT_LOG) ){ 282 editPage = "managementRuleLogEdit"; 283 } 284 else 285 if (eventType.equals(EVENT_NOTIFICATION) ){ 286 editPage = "managementRuleNotificationEdit"; 287 } 288 else 289 if (eventType.equals(EVENT_TRACE) ){ 290 editPage = "managementRuleTraceEdit"; 291 } 292 else 293 if (EVENT_LIFECYCLE.equals(eventType)){ 294 editPage = "managementRuleLifeCycleEdit"; 295 } 296 handlerCtx.setOutputValue("editPage", editPage); 297 } 298 299 300 public void getNextCreationPage(RequestContext ctx, HandlerContext handlerCtx) { 301 String out=""; 302 String eventSelected = (String )handlerCtx.getInputValue("eventType"); 303 304 if (EVENT_TIMER.equals(eventSelected)){ 305 out = "managementRuleTimer"; 306 }else 307 if (EVENT_MONITOR.equals(eventSelected)){ 308 out = "managementRuleMonitor"; 309 }else 310 if (EVENT_CLUSTER.equals(eventSelected) ){ 311 out = "managementRuleCluster"; 312 }else 313 if (EVENT_LOG.equals(eventSelected) ){ 314 out = "managementRuleLog"; 315 } 316 else 317 if (EVENT_NOTIFICATION.equals(eventSelected)){ 318 out = "managementRuleNotification"; 319 } 320 else 321 if (EVENT_TRACE.equals(eventSelected)){ 322 out = "managementRuleTrace"; 323 } 324 else 325 if (EVENT_LIFECYCLE.equals(eventSelected)){ 326 out = "managementRuleLifeCycle"; 327 }else{ 328 throw new FrameworkException("Cannot determine the next step of New Management Rule. EventType not recognized"); 329 } 330 331 handlerCtx.setOutputValue("nextPage", out); 332 } 333 334 public void createManagementRule(RequestContext ctx, HandlerContext handlerCtx) { 335 336 String objectName = (String ) handlerCtx.getInputValue("objectName"); 337 HttpSession session = RequestManager.getSession(); 338 String step1ModelName = (String ) handlerCtx.getInputValue("step1Model"); 339 String step2ModelName = (String ) handlerCtx.getInputValue("step2Model"); 340 341 DefaultModel step1Model = (DefaultModel)(session.getValue(step1ModelName)); 342 DefaultModel step2Model = (DefaultModel)(session.getValue(step2ModelName)); 343 String ruleName = (String )step1Model.getValue("Name"); 344 Boolean ruleEnabled = new Boolean ((String )step1Model.getValue("enabled")); 345 String ruleDesc = (String )step1Model.getValue("ruleDesc"); 346 String eventType = (String )step1Model.getValue("eventType"); 347 String eventLevel = (String )step1Model.getValue("eventLogLevel"); 348 Boolean eventRecordEvent = new Boolean ((String )step1Model.getValue("recordEvent")); 349 350 String eventDesc = (String )step2Model.getValue("eventDesc"); 352 String actionMbean = (String )step2Model.getValue("actions"); 353 if(Util.isEmpty(actionMbean)) 354 actionMbean=null; 355 356 Properties eventProps = null; 357 if (EVENT_TIMER.equals(eventType)){ 359 eventProps = getTimerProperties(step2Model); 360 }else 361 if (EVENT_MONITOR.equals(eventType)){ 362 eventProps = getMonitorProperties(step2Model); 363 }else 364 if (EVENT_CLUSTER.equals(eventType) ){ 365 eventProps = getClusterProperties(step2Model); 366 }else 367 if (EVENT_LOG.equals(eventType) ){ 368 eventProps = getLogProperties(step2Model); 369 } 370 else 371 if (EVENT_NOTIFICATION.equals(eventType)){ 372 eventProps = getNotificationProperties(step2Model); 373 } 374 else 375 if (EVENT_TRACE.equals(eventType)){ 376 eventProps = getTraceProperties(step2Model); 377 } 378 else 379 if (EVENT_LIFECYCLE.equals(eventType)){ 380 eventProps = getLifeCycleProperties(step2Model); 381 } 382 383 384 Object [] params = { ruleName, ruleEnabled, ruleDesc, 385 eventType, eventLevel, eventRecordEvent, eventDesc, eventProps, 386 actionMbean}; 387 String []types = { 388 "java.lang.String", "java.lang.Boolean", "java.lang.String", 389 "java.lang.String", "java.lang.String", "java.lang.Boolean", "java.lang.String", "java.util.Properties", 390 "java.lang.String"}; 391 392 MBeanUtil.invoke(objectName, "createManagementRule", params, types); 393 394 } 395 396 397 private void setProp(Properties props, String name, String value){ 398 if (!Util.isEmpty(value)){ 399 props.setProperty(name, value); 400 } 401 } 402 403 private Properties getLogProperties(DefaultModel model){ 404 405 Object loggers = (Object ) model.getValues("logger"); 406 String allLogger = ""; 407 if (loggers != null) { 408 int len = ((Object [])loggers).length; 409 for (int count=0; count<len; count++) { 410 String val = (String ) (((Object [])loggers)[count]); 411 if ((val == null) || (val.toString().trim().length() == 0)) { 412 continue; 413 } 414 allLogger=allLogger+","+val; 415 } 416 } 417 418 String logLevel = (String ) model.getValue("logLevel"); 419 Properties props = new Properties (); 420 setProp(props, PROPERTY_LOG_LOGGERNAME, allLogger); 421 setProp(props, PROPERTY_LOG_LEVEL, logLevel); 422 return props; 423 } 424 425 private Properties getClusterProperties(DefaultModel model){ 426 427 String clusterEventName = (String ) model.getValue("clusterEventName"); 428 String clusterEventServerName = (String ) model.getValue("clusterEventServerName"); 429 Properties props = new Properties (); 430 setProp(props, PROPERTY_CLUSTER_NAME, clusterEventName); 431 setProp(props, PROPERTY_CLUSTER_SERVERNAME, clusterEventServerName); 432 return props; 433 } 434 435 private Properties getNotificationProperties(DefaultModel model){ 436 437 Properties props = new Properties (); 438 String selected = (String ) model.getValue("sourceRB"); 439 if ("predefinedMBean".equals(selected)){ 440 String sourceMbean = (String ) model.getValue("sourceMbean"); 441 setProp(props, PROPERTY_NOTIFICATION_SOURCEMBEAN, sourceMbean); 442 443 }else{ 444 String sourceObjectName = (String ) model.getValue("sourceObjectName"); 445 setProp(props, PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME, sourceObjectName); 446 } 447 String type = (String ) model.getValue("notificationType"); 448 setProp(props, PROPERTY_NOTIFICATION_TYPE, type); 449 return props; 450 } 451 452 453 private Properties getLifeCycleProperties(DefaultModel model){ 454 455 String lifeCycleName = (String ) model.getValue("lifeCycleName"); 456 Properties props = new Properties (); 457 setProp(props, PROPERTY_LIFECYCLE_NAME, lifeCycleName); 458 return props; 459 } 460 461 462 private Properties getTraceProperties(DefaultModel model){ 463 Properties props = new Properties (); 464 setProp(props, PROPERTY_TRACE_NAME, (String ) model.getValue("traceName")); 465 return props; 466 } 467 468 469 private Properties getTimerProperties(DefaultModel model){ 470 Properties props = new Properties (); 471 setProp(props, PROPERTY_TIMER_DATESTRING, (String ) model.getValue("dateString")); 472 setProp(props, PROPERTY_TIMER_PATTERN, (String ) model.getValue("pattern")); 473 setProp(props, PROPERTY_TIMER_PERIOD, (String ) model.getValue("period")); 474 setProp(props, PROPERTY_TIMER_NUMBER_OF_OCCURRENCES, (String ) model.getValue("occurrence")); 475 setProp(props, PROPERTY_TIMER_MESSAGE, (String ) model.getValue("message")); 476 setProp(props, PROPERTY_TIMER_PATTERN, (String ) model.getValue("pattern")); 477 return props; 478 } 479 480 481 482 private Properties getMonitorProperties(DefaultModel model){ 483 Properties props = new Properties (); 484 485 setProp(props, PROPERTY_MONITOR_OBSERVED_OBJ, (String ) model.getValue("observedObject")); 486 setProp(props, PROPERTY_MONITOR_OBSERVED_ATTRIBUTE, (String ) model.getValue("observedAttr")); 487 setProp(props, PROPERTY_MONITOR_GRANULARITY_PERIOD, (String ) model.getValue("period")); 488 489 String monitorType = (String ) model.getValue("monitorType"); 490 setProp(props, PROPERTY_MONITOR_TYPE, monitorType ); 491 492 if(PROPERTY_MONITOR_GAUGE.equals(monitorType)){ 493 setProp(props, PROPERTY_MONITOR_NUMBERTYPE, (String ) model.getValue("gaugeNumberType")); 494 setProp(props, PROPERTY_MONITOR_DIFFERENCEMODE, (String ) model.getValue("gaugeDiff")); 495 setProp(props, PROPERTY_MONITOR_HIGH_THRESHOLD, (String ) model.getValue("gaugeHighThreshold")); 496 setProp(props, PROPERTY_MONITOR_LOW_THRESHOLD, (String ) model.getValue("gaugeLowThreshold")); 497 }else 498 if(PROPERTY_MONITOR_COUNTER.equals(monitorType)){ 499 setProp(props, PROPERTY_MONITOR_NUMBERTYPE, (String ) model.getValue("countNumberType")); 500 setProp(props, PROPERTY_MONITOR_DIFFERENCEMODE, (String ) model.getValue("countDiff")); 501 setProp(props, PROPERTY_MONITOR_INIT_THRESHOLD, (String ) model.getValue("initThreshold")); 502 setProp(props, PROPERTY_MONITOR_OFFSET, (String ) model.getValue("offset")); 503 setProp(props, PROPERTY_MONITOR_MODULUS, (String ) model.getValue("modulus")); 504 }else 505 if(PROPERTY_MONITOR_STRING.equals(monitorType)){ 506 String compare = (String ) model.getValue("compare"); 507 if("notifymatch".equals(compare)) 508 setProp(props, PROPERTY_MONITOR_STRING_NOTIFY, PROPERTY_MONITOR_STRING_NOTIFY_MATCH); 509 else 510 setProp(props, PROPERTY_MONITOR_STRING_NOTIFY, PROPERTY_MONITOR_STRING_NOTIFY_DIFFER); 511 512 setProp(props, PROPERTY_MONITOR_STRING_TO_COMPARE, (String ) model.getValue("strValue")); 513 } 514 return props; 515 } 516 517 518 519 public void getCommonAttributesForRules(RequestContext ctx, HandlerContext handlerCtx) { 520 521 String ruleObjectName = (String ) handlerCtx.getInputValue("ruleObjectName"); 522 String eventObjectName = (String ) handlerCtx.getInputValue("eventObjectName"); 523 524 handlerCtx.setOutputValue("ruleEnabled", (String ) MBeanUtil.getAttribute( ruleObjectName, "enabled")); 525 handlerCtx.setOutputValue("ruleDesc", (String ) MBeanUtil.getAttribute( ruleObjectName, "description")); 526 String eventType = (String ) MBeanUtil.getAttribute( eventObjectName, "type"); 527 handlerCtx.setOutputValue("eventType", eventType); 528 handlerCtx.setOutputValue("recordEvent", (String ) MBeanUtil.getAttribute( eventObjectName, "record-event")); 529 handlerCtx.setOutputValue("eventLogLevel", (String ) MBeanUtil.getAttribute( eventObjectName, "level")); 530 handlerCtx.setOutputValue("eventDesc", (String ) MBeanUtil.getAttribute( eventObjectName, "description")); 531 532 ObjectName actionObjectName = getActionObjectName(ruleObjectName); 533 if (actionObjectName != null){ 534 String actionMbeanName = (String ) MBeanUtil.getAttribute(actionObjectName, "action-mbean-name"); 535 if (!Util.isEmpty(actionMbeanName)){ 536 handlerCtx.setOutputValue("action", actionMbeanName); 537 } 538 } 539 540 AttributeList attrs = (AttributeList ) MBeanUtil.invoke(eventObjectName, "getProperties", null, null); 541 542 if(EVENT_NOTIFICATION.equals(eventType)){ 543 setupNotificationProperties(attrs); 544 } 545 handlerCtx.setOutputValue("eventProperties", attrs); 546 } 547 548 549 private void setupNotificationProperties(List <Attribute > attrs){ 550 boolean mbean = false; 551 for(Attribute attr : attrs){ 552 String name = (String ) attr.getName(); 553 String value = (String ) attr.getValue(); 554 if (PROPERTY_NOTIFICATION_SOURCEMBEAN.equals(name)){ 555 mbean = true; 556 break; 557 } 558 } 559 if(mbean){ 560 attrs.add( new Attribute ("sourceRB","predefinedMBean")); 561 }else 562 attrs.add( new Attribute ("sourceRB","userdefinedObjName")); 563 } 564 565 public void getEventPropertyList(RequestContext ctx, HandlerContext handlerCtx) { 566 567 String eventObjectName = (String ) handlerCtx.getInputValue("eventObjectName"); 568 String eventType = (String ) MBeanUtil.getAttribute(eventObjectName, "type"); 569 570 579 580 ArrayList list = new ArrayList (); 581 if (EVENT_LOG.equals(eventType)){ 582 list.add(PROPERTY_LOG_LEVEL); 583 }else 584 if (EVENT_LIFECYCLE.equals(eventType)){ 585 list.add(PROPERTY_LIFECYCLE_NAME); 586 }else 587 if (EVENT_TRACE.equals(eventType)){ 588 list.add(PROPERTY_TRACE_NAME); 589 } else 590 if (EVENT_CLUSTER.equals(eventType)){ 591 list.add(PROPERTY_CLUSTER_NAME); 592 list.add(PROPERTY_CLUSTER_SERVERNAME); 593 } else 594 if (EVENT_TIMER.equals(eventType)){ 595 list.add(PROPERTY_TIMER_DATESTRING); 596 list.add(PROPERTY_TIMER_PATTERN); 597 list.add(PROPERTY_TIMER_PERIOD); 598 list.add(PROPERTY_TIMER_NUMBER_OF_OCCURRENCES); 599 list.add(PROPERTY_TIMER_MESSAGE); 600 }else 601 if (EVENT_NOTIFICATION.equals(eventType)){ 602 list.add("sourceRB"); 603 list.add(PROPERTY_NOTIFICATION_SOURCEMBEAN); 604 list.add(PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME); 605 list.add(PROPERTY_NOTIFICATION_TYPE); 606 }else 607 if (EVENT_MONITOR.equals(eventType)){ 608 609 list.add(PROPERTY_MONITOR_OBSERVED_OBJ); 610 list.add(PROPERTY_MONITOR_OBSERVED_ATTRIBUTE); 611 list.add(PROPERTY_MONITOR_GRANULARITY_PERIOD); 612 613 String type = (String ) MBeanUtil.invoke(eventObjectName, "getPropertyValue", 614 new Object []{PROPERTY_MONITOR_TYPE}, 615 new String []{"java.lang.String"}); 616 617 if(PROPERTY_MONITOR_COUNTER.equals(type)){ 618 list.add(PROPERTY_MONITOR_DIFFERENCEMODE); 619 list.add(PROPERTY_MONITOR_NUMBERTYPE); 620 list.add(PROPERTY_MONITOR_INIT_THRESHOLD); 621 list.add(PROPERTY_MONITOR_OFFSET); 622 list.add(PROPERTY_MONITOR_MODULUS); 623 }else 624 if (PROPERTY_MONITOR_STRING.equals(type)){ 625 list.add(PROPERTY_MONITOR_STRING_NOTIFY); 626 list.add(PROPERTY_MONITOR_STRING_TO_COMPARE); 627 }else 628 if (PROPERTY_MONITOR_GAUGE.equals(type)){ 629 list.add(PROPERTY_MONITOR_DIFFERENCEMODE); 630 list.add(PROPERTY_MONITOR_NUMBERTYPE); 631 list.add(PROPERTY_MONITOR_LOW_THRESHOLD); 632 list.add(PROPERTY_MONITOR_HIGH_THRESHOLD); 633 } 634 } 635 handlerCtx.setOutputValue("propertyNameList", list); 636 } 637 638 639 public void getTranslatedMonitorType(RequestContext ctx, HandlerContext handlerCtx) { 640 String eventObjectName = (String ) handlerCtx.getInputValue("eventObjectName"); 641 String type = (String ) MBeanUtil.invoke(eventObjectName, "getPropertyValue", 642 new Object []{PROPERTY_MONITOR_TYPE}, 643 new String []{"java.lang.String"}); 644 645 handlerCtx.setOutputValue("mtype", translatedMonitorType(type)); 646 } 647 648 649 private String translatedMonitorType(String type){ 650 String mtype = null; 651 652 if(PROPERTY_MONITOR_COUNTER.equals(type)){ 653 mtype = Util.getMessage("managementRule.Count"); 654 }else 655 if (PROPERTY_MONITOR_STRING.equals(type)){ 656 mtype = Util.getMessage("managementRule.String"); 657 }else 658 if (PROPERTY_MONITOR_GAUGE.equals(type)){ 659 mtype = Util.getMessage("managementRule.Gauge"); 660 } 661 return mtype; 662 } 663 664 665 public void changeAction(RequestContext ctx, HandlerContext handlerCtx) { 666 667 String ruleObjectName = (String ) handlerCtx.getInputValue("ruleObjectName"); 668 String actionMbeanName = (String ) handlerCtx.getInputValue("actionMbeanName"); 669 ObjectName actionObjectName = getActionObjectName(ruleObjectName); 670 671 672 if (Util.isEmpty(actionMbeanName)){ 673 if (actionObjectName != null) 674 MBeanUtil.invoke(ruleObjectName, "removeAction", null, null); 675 return; 676 } 677 678 if (actionObjectName != null){ 679 String origActionMbeanName = (String ) MBeanUtil.getAttribute(actionObjectName, "action-mbean-name"); 680 if (!actionMbeanName.equals(origActionMbeanName)){ 681 MBeanUtil.invoke(ruleObjectName, "removeAction", null, null); 682 }else{ 683 return; 684 } 685 } 686 AttributeList attrs = new AttributeList (); 687 attrs.add(new Attribute ("action-mbean-name", actionMbeanName)); 688 Object params[] = {attrs }; 689 String types[] = {"javax.management.AttributeList" }; 690 MBeanUtil.invoke(ruleObjectName, "createAction", params, types ); 691 692 } 693 694 public void setLogEventProperties(RequestContext ctx, HandlerContext handlerCtx) { 696 String objectName = (String ) handlerCtx.getInputValue("objectName"); 697 Object [] loggers= (Object []) handlerCtx.getInputValue("logger"); 698 String logLevel = (String ) handlerCtx.getInputValue("logLevel"); 699 700 String allLogger = null; 701 if (loggers != null) { 702 int len = ((Object [])loggers).length; 703 for (int count=0; count<len; count++) { 704 String val = (String ) (((Object [])loggers)[count]); 705 if ((val == null) || (val.toString().trim().length() == 0)) { 706 continue; 707 } 708 allLogger = (allLogger == null) ? val : allLogger+ ","+ val; 709 } 710 } 711 setPropertyWithValue(objectName,PROPERTY_LOG_LOGGERNAME, allLogger ); 712 setPropertyWithValue(objectName,PROPERTY_LOG_LEVEL, logLevel ); 713 714 } 715 716 717 public void setLifeCycleEventProperties(RequestContext ctx, HandlerContext handlerCtx) { 718 String objectName = (String ) handlerCtx.getInputValue("objectName"); 719 String lifeCycleName = (String ) handlerCtx.getInputValue("lifeCycleName"); 720 setPropertyWithValue(objectName,PROPERTY_LIFECYCLE_NAME, lifeCycleName ); 721 } 722 723 724 public void setTraceEventProperties(RequestContext ctx, HandlerContext handlerCtx) { 725 String objectName = (String ) handlerCtx.getInputValue("objectName"); 726 String traceName = (String ) handlerCtx.getInputValue("traceName"); 727 setPropertyWithValue(objectName,PROPERTY_TRACE_NAME, traceName ); 728 } 729 730 public void setClusterEventProperties(RequestContext ctx, HandlerContext handlerCtx) { 731 String objectName = (String ) handlerCtx.getInputValue("objectName"); 732 String clusterEventName = (String ) handlerCtx.getInputValue("clusterEventName"); 733 String clusterEventServerName = (String ) handlerCtx.getInputValue("clusterEventServerName"); 734 735 setPropertyWithValue(objectName,PROPERTY_CLUSTER_NAME, clusterEventName ); 736 setPropertyWithValue(objectName,PROPERTY_CLUSTER_SERVERNAME, clusterEventServerName ); 737 } 738 739 740 public void setTimerEventProperties(RequestContext ctx, HandlerContext handlerCtx) { 741 String objectName = (String ) handlerCtx.getInputValue("objectName"); 742 743 setPropertyWithValue(objectName,PROPERTY_TIMER_DATESTRING, (String ) handlerCtx.getInputValue("dateString") ); 744 setPropertyWithValue(objectName,PROPERTY_TIMER_PATTERN, (String ) handlerCtx.getInputValue("pattern") ); 745 setPropertyWithValue(objectName,PROPERTY_TIMER_PERIOD, (String ) handlerCtx.getInputValue("period") ); 746 setPropertyWithValue(objectName,PROPERTY_TIMER_NUMBER_OF_OCCURRENCES, (String ) handlerCtx.getInputValue("occurrence") ); 747 setPropertyWithValue(objectName,PROPERTY_TIMER_MESSAGE, (String ) handlerCtx.getInputValue("message") ); 748 } 749 750 751 public void setMonitorEventGaugeProperties(RequestContext ctx, HandlerContext handlerCtx) { 752 String objectName = (String ) handlerCtx.getInputValue("objectName"); 753 setPropertyWithValue(objectName,PROPERTY_MONITOR_GRANULARITY_PERIOD, (String ) handlerCtx.getInputValue("period")); 754 setPropertyWithValue(objectName,PROPERTY_MONITOR_NUMBERTYPE, (String ) handlerCtx.getInputValue("gaugeNumberType") ); 755 setPropertyWithValue(objectName,PROPERTY_MONITOR_DIFFERENCEMODE, (String ) handlerCtx.getInputValue("gaugeDiff") ); 756 setPropertyWithValue(objectName,PROPERTY_MONITOR_LOW_THRESHOLD, (String ) handlerCtx.getInputValue("gaugeLowThreshold") ); 757 setPropertyWithValue(objectName,PROPERTY_MONITOR_HIGH_THRESHOLD, (String ) handlerCtx.getInputValue("gaugeHighThreshold") ); 758 } 759 760 761 public void setMonitorEventCountProperties(RequestContext ctx, HandlerContext handlerCtx) { 762 763 String objectName = (String ) handlerCtx.getInputValue("objectName"); 764 setPropertyWithValue(objectName,PROPERTY_MONITOR_GRANULARITY_PERIOD, (String ) handlerCtx.getInputValue("period")); 765 setPropertyWithValue(objectName,PROPERTY_MONITOR_NUMBERTYPE, (String ) handlerCtx.getInputValue("countNumberType") ); 766 setPropertyWithValue(objectName,PROPERTY_MONITOR_DIFFERENCEMODE, (String ) handlerCtx.getInputValue("countDiff") ); 767 setPropertyWithValue(objectName,PROPERTY_MONITOR_INIT_THRESHOLD, (String ) handlerCtx.getInputValue("initThreshold") ); 768 setPropertyWithValue(objectName,PROPERTY_MONITOR_OFFSET, (String ) handlerCtx.getInputValue("offset") ); 769 setPropertyWithValue(objectName,PROPERTY_MONITOR_MODULUS, (String ) handlerCtx.getInputValue("modulus") ); 770 } 771 772 773 public void setMonitorEventStringProperties(RequestContext ctx, HandlerContext handlerCtx) { 774 String objectName = (String ) handlerCtx.getInputValue("objectName"); 775 setPropertyWithValue(objectName,PROPERTY_MONITOR_GRANULARITY_PERIOD, (String ) handlerCtx.getInputValue("period")); 776 setPropertyWithValue(objectName,PROPERTY_MONITOR_STRING_NOTIFY, (String ) handlerCtx.getInputValue("compare") ); 777 setPropertyWithValue(objectName,PROPERTY_MONITOR_STRING_TO_COMPARE, (String ) handlerCtx.getInputValue("strValue") ); 778 } 779 780 public void setNotificationEventProperties(RequestContext ctx, HandlerContext handlerCtx) { 781 String objectName = (String ) handlerCtx.getInputValue("objectName"); 782 String sourceRB = (String ) handlerCtx.getInputValue("sourceRB"); 783 if ("predefinedMBean".equals(sourceRB)){ 784 setPropertyWithValue(objectName,PROPERTY_NOTIFICATION_SOURCEMBEAN, (String ) handlerCtx.getInputValue("sourceMbean") ); 785 }else{ 786 setPropertyWithValue(objectName,PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME, (String ) handlerCtx.getInputValue("sourceObjectName") ); 787 } 788 setPropertyWithValue(objectName, PROPERTY_NOTIFICATION_TYPE, (String ) handlerCtx.getInputValue("notificationType") ); } 790 791 792 private void setPropertyWithValue(String objectName, String name, String value){ 793 Object params[] = {new Attribute (name, value)}; 794 String types[] = {"javax.management.Attribute"}; 795 String origValue = ""; 796 try{ 797 Object pp[] = {name}; 798 String tt[]= {"java.lang.String"}; 799 origValue = (String ) MBeanUtil.invoke(objectName, "getPropertyValue", pp, tt); 800 if (origValue == null) origValue=""; 801 }catch(Exception ex) { 802 } 804 if (! (Util.isEmpty(value) && Util.isEmpty(origValue))){ 805 if (!origValue.equals(value)) 806 MBeanUtil.invoke(objectName, "setProperty", params, types); 807 } 808 809 } 810 811 public void populateClusterEventName(RequestContext ctx, HandlerContext handlerCtx) { 812 populateDropDownEventProperties(handlerCtx, EVENT_CLUSTER, PROPERTY_CLUSTER_NAME ); 813 } 814 815 816 public void populateClusterEventServerName(RequestContext ctx, HandlerContext handlerCtx) { 817 populateDropDownEventProperties(handlerCtx, EVENT_CLUSTER, PROPERTY_CLUSTER_SERVERNAME ); 818 } 819 820 821 private ObjectName getActionObjectName( String ruleObjectName){ 822 try { 823 ObjectName actionObjectName = (ObjectName ) MBeanUtil.invoke(ruleObjectName, "getAction", null, null); 824 return actionObjectName; 825 }catch(Exception ex){ 826 return null; 829 } 830 } 831 832 833 public void populateMonitorType(RequestContext ctx, HandlerContext handlerCtx) { 834 populateDropDownEventProperties(handlerCtx, EVENT_MONITOR, PROPERTY_MONITOR_TYPE ); 835 } 836 837 838 public void populateGaugeNumberType(RequestContext ctx, HandlerContext handlerCtx) { 839 populateDropDownEventProperties(handlerCtx, EVENT_MONITOR, PROPERTY_MONITOR_NUMBERTYPE ); 841 } 842 843 public void populateNotificationSourceMbean(RequestContext ctx, HandlerContext handlerCtx) { 844 populateDropDownEventProperties(handlerCtx, EVENT_NOTIFICATION, PROPERTY_NOTIFICATION_SOURCEMBEAN ); 846 } 847 848 849 private void populateDropDownEventProperties(HandlerContext handlerCtx, String eventType, String propertyName){ 850 851 SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView(); 853 String initialValue = (String )handlerCtx.getInputValue("initialValue"); 854 String rulesObjectName = (String )handlerCtx.getInputValue("rulesObjectName"); 855 856 Object params[] = { eventType, propertyName }; 857 String types[] = { "java.lang.String", "java.lang.String" }; 858 859 List <String > list = (List ) MBeanUtil.invoke(rulesObjectName, "getEventPropertyValues", params, types); 860 if (list == null) return; 861 862 TreeSet <String > tset = new TreeSet (list); 864 OptionList optionList = new OptionList(); 865 866 if (propertyName.equals(PROPERTY_LOG_LOGGERNAME) || propertyName.equals(PROPERTY_CLUSTER_SERVERNAME)){ 867 optionList.add("*", "*"); 868 } 869 if (propertyName.equals(PROPERTY_NOTIFICATION_SOURCEMBEAN)){ 870 if(tset.size() < 1) 871 optionList.add(" ", ""); 872 } 873 874 for (String event : tset) { 875 if (Util.isEmpty(event)) 876 continue; 877 if (PROPERTY_MONITOR_TYPE.equals(propertyName)) 878 optionList.add(translatedMonitorType(event), event); 879 else 880 optionList.add(event, event); 881 } 882 883 dropDownChild.setOptions(optionList); 884 885 if (dropDownChild.getValue() == null && !Util.isEmpty(initialValue)) { 886 dropDownChild.setValue(initialValue); 887 } 888 } 889 890 } 891 | Popular Tags |