KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > handlers > ManagementRulesHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.admingui.handlers;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Properties JavaDoc;
29 import java.util.TreeSet JavaDoc;
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 JavaDoc;
43
44 import javax.management.MBeanException JavaDoc;
45 import javax.management.ObjectName JavaDoc;
46 import javax.management.AttributeList JavaDoc;
47 import javax.management.Attribute JavaDoc;
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 JavaDoc;
68 import java.util.Enumeration JavaDoc;
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 JavaDoc PROPERTY_NOTIFICATION_TYPE="type";
77    
78    
79     public void loadManagementRulesTable(RequestContext ctx, HandlerContext handlerCtx) {
80         
81 // CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
82
// CCActionTableModelInterface model = ccDesc.getModel();
83
CCActionTableModelInterface model = (CCActionTableModelInterface)handlerCtx.getInputValue("tableModel");
84         ((DefaultModel)model).clear();
85         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
86         String JavaDoc methodName = (String JavaDoc) handlerCtx.getInputValue("methodName");
87         String JavaDoc eventObjectName = (String JavaDoc) handlerCtx.getInputValue("eventObjectName");
88          
89         try{
90             model.setRowSelectionType("multiple");
91             model.beforeFirst();
92             ObjectName JavaDoc[] rules = (ObjectName JavaDoc[] ) MBeanUtil.invoke(objectName, methodName, null, null);
93             
94             for(int i=0; i< rules.length; i++){
95                 model.appendRow();
96                 String JavaDoc ruleName= rules[i].getKeyProperty("name");
97                 model.setValue("name", ruleName);
98                 model.setValue("ruleObjectName", rules[i]);
99                 String JavaDoc enabled = (String JavaDoc) MBeanUtil.getAttribute( rules[i], "enabled");
100                 model.setValue("status", "true".equals(enabled)? Util.getMessage("common.Enabled") : Util.getMessage("common.Disabled"));
101                 String JavaDoc eventType = (String JavaDoc) MBeanUtil.getAttribute(eventObjectName+ruleName, "type");
102                 model.setValue("eventType", eventType);
103                 
104                 
105             }
106             
107         }catch(Exception JavaDoc 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 // ((DefaultModel)model).dumpValues(System.out);
117

118         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
119         String JavaDoc deleteMethod = (String JavaDoc) 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 JavaDoc ruleObjectName = (String JavaDoc) model.getValue("ruleObjectName");
129                     ObjectName JavaDoc objN = new ObjectName JavaDoc(ruleObjectName);
130                     String JavaDoc params[]={objN.getKeyProperty("name")};
131                     String JavaDoc types[] = {"java.lang.String"};
132                     MBeanUtil.invoke(objectName, deleteMethod, params, types);
133                     model.setRowSelected(false);
134                 }
135             }
136         }catch(Exception JavaDoc 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 // ((DefaultModel)model).dumpValues(System.out);
146

147         String JavaDoc enabled = (String JavaDoc) 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 JavaDoc ruleObjectName = (String JavaDoc) model.getValue("ruleObjectName");
155                      MBeanUtil.setAttribute(ruleObjectName, new Attribute JavaDoc("enabled", enabled));
156                      model.setRowSelected(false);
157                 }
158             }
159         }catch(Exception JavaDoc 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         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
167
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 JavaDoc 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         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
194
SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
195         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
196         Object JavaDoc[] params = {Boolean.FALSE};
197         String JavaDoc[] types = {"boolean"};
198         List JavaDoc<String JavaDoc> actionBeansList = (List JavaDoc) MBeanUtil.invoke(objectName, "getAllActionMBeans", params, types);
199         if (actionBeansList == null)
200             return;
201         
202         OptionList optionList = new OptionList();
203         optionList.add(" ", "");
204         for (String JavaDoc actionBeans : actionBeansList) {
205             optionList.add(actionBeans, actionBeans);
206         }
207         dropDownChild.setOptions(optionList);
208         
209         String JavaDoc initialValue = (String JavaDoc)handlerCtx.getInputValue("initialValue");
210         if (initialValue == null || initialValue.length() == 0) {
211             //dropDownChild.setLabelForNoneSelected(" ");
212
} 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          //set Initial value, this is special case since multiple loggers may be selected.
227
List JavaDoc <Attribute JavaDoc> eventProperties = (List JavaDoc) handlerCtx.getInputValue("eventProperties");
228          if (eventProperties == null || eventProperties.size() < 1){
229              return;
230          }
231          String JavaDoc loggers = null;
232          for(Attribute JavaDoc attr : eventProperties){
233              if (PROPERTY_LOG_LOGGERNAME.equals(attr.getName())){
234                  loggers = (String JavaDoc) attr.getValue();
235                  break;
236              }
237          }
238          if (loggers != null){
239              String JavaDoc[] 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 JavaDoc ruleObjectName = (String JavaDoc)handlerCtx.getInputValue("ruleObjectName");
259         ObjectName JavaDoc eventObjectName = (ObjectName JavaDoc) MBeanUtil.invoke(ruleObjectName, "getEvent", null, null);
260         String JavaDoc eventType = (String JavaDoc)MBeanUtil.getAttribute(eventObjectName, "type");
261         String JavaDoc editPage = null;
262         
263         if (EVENT_TIMER.equals(eventType)){
264             editPage = "managementRuleTimerEdit";
265         }else
266         if (EVENT_MONITOR.equals(eventType)){
267                 String JavaDoc type = (String JavaDoc) MBeanUtil.invoke(eventObjectName, "getPropertyValue",
268                                 new Object JavaDoc[]{PROPERTY_MONITOR_TYPE},
269                                 new String JavaDoc[]{"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 JavaDoc out="";
302         String JavaDoc eventSelected = (String JavaDoc)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 JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
337     HttpSession JavaDoc session = RequestManager.getSession();
338         String JavaDoc step1ModelName = (String JavaDoc) handlerCtx.getInputValue("step1Model");
339         String JavaDoc step2ModelName = (String JavaDoc) handlerCtx.getInputValue("step2Model");
340         
341         DefaultModel step1Model = (DefaultModel)(session.getValue(step1ModelName));
342         DefaultModel step2Model = (DefaultModel)(session.getValue(step2ModelName));
343         String JavaDoc ruleName = (String JavaDoc)step1Model.getValue("Name");
344         Boolean JavaDoc ruleEnabled = new Boolean JavaDoc((String JavaDoc)step1Model.getValue("enabled"));
345         String JavaDoc ruleDesc = (String JavaDoc)step1Model.getValue("ruleDesc");
346         String JavaDoc eventType = (String JavaDoc)step1Model.getValue("eventType");
347         String JavaDoc eventLevel = (String JavaDoc)step1Model.getValue("eventLogLevel");
348         Boolean JavaDoc eventRecordEvent = new Boolean JavaDoc((String JavaDoc)step1Model.getValue("recordEvent"));
349         
350         //Every step 2 model will have these 2 elements.
351
String JavaDoc eventDesc = (String JavaDoc)step2Model.getValue("eventDesc");
352         String JavaDoc actionMbean = (String JavaDoc)step2Model.getValue("actions");
353         if(Util.isEmpty(actionMbean))
354             actionMbean=null;
355         
356         Properties JavaDoc eventProps = null;
357         //Get specific property for each eventtype
358
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 JavaDoc[] params = { ruleName, ruleEnabled, ruleDesc,
385                 eventType, eventLevel, eventRecordEvent, eventDesc, eventProps,
386                 actionMbean};
387         String JavaDoc[]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 JavaDoc props, String JavaDoc name, String JavaDoc value){
398         if (!Util.isEmpty(value)){
399             props.setProperty(name, value);
400         }
401     }
402     
403     private Properties JavaDoc getLogProperties(DefaultModel model){
404         
405         Object JavaDoc loggers = (Object JavaDoc) model.getValues("logger");
406         String JavaDoc allLogger = "";
407     if (loggers != null) {
408         int len = ((Object JavaDoc[])loggers).length;
409         for (int count=0; count<len; count++) {
410         String JavaDoc val = (String JavaDoc) (((Object JavaDoc[])loggers)[count]);
411         if ((val == null) || (val.toString().trim().length() == 0)) {
412             continue;
413         }
414         allLogger=allLogger+","+val;
415         }
416     }
417         
418         String JavaDoc logLevel = (String JavaDoc) model.getValue("logLevel");
419         Properties JavaDoc props = new Properties JavaDoc();
420         setProp(props, PROPERTY_LOG_LOGGERNAME, allLogger);
421         setProp(props, PROPERTY_LOG_LEVEL, logLevel);
422         return props;
423     }
424     
425     private Properties JavaDoc getClusterProperties(DefaultModel model){
426         
427         String JavaDoc clusterEventName = (String JavaDoc) model.getValue("clusterEventName");
428         String JavaDoc clusterEventServerName = (String JavaDoc) model.getValue("clusterEventServerName");
429         Properties JavaDoc props = new Properties JavaDoc();
430         setProp(props, PROPERTY_CLUSTER_NAME, clusterEventName);
431         setProp(props, PROPERTY_CLUSTER_SERVERNAME, clusterEventServerName);
432         return props;
433     }
434     
435     private Properties JavaDoc getNotificationProperties(DefaultModel model){
436         
437         Properties JavaDoc props = new Properties JavaDoc();
438         String JavaDoc selected = (String JavaDoc) model.getValue("sourceRB");
439         if ("predefinedMBean".equals(selected)){
440             String JavaDoc sourceMbean = (String JavaDoc) model.getValue("sourceMbean");
441             setProp(props, PROPERTY_NOTIFICATION_SOURCEMBEAN, sourceMbean);
442            
443         }else{
444             String JavaDoc sourceObjectName = (String JavaDoc) model.getValue("sourceObjectName");
445             setProp(props, PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME, sourceObjectName);
446         }
447         String JavaDoc type = (String JavaDoc) model.getValue("notificationType");
448         setProp(props, PROPERTY_NOTIFICATION_TYPE, type);
449         return props;
450     }
451       
452         
453     private Properties JavaDoc getLifeCycleProperties(DefaultModel model){
454         
455         String JavaDoc lifeCycleName = (String JavaDoc) model.getValue("lifeCycleName");
456         Properties JavaDoc props = new Properties JavaDoc();
457         setProp(props, PROPERTY_LIFECYCLE_NAME, lifeCycleName);
458         return props;
459     }
460     
461     
462     private Properties JavaDoc getTraceProperties(DefaultModel model){
463         Properties JavaDoc props = new Properties JavaDoc();
464         setProp(props, PROPERTY_TRACE_NAME, (String JavaDoc) model.getValue("traceName"));
465         return props;
466     }
467     
468      
469     private Properties JavaDoc getTimerProperties(DefaultModel model){
470         Properties JavaDoc props = new Properties JavaDoc();
471         setProp(props, PROPERTY_TIMER_DATESTRING, (String JavaDoc) model.getValue("dateString"));
472         setProp(props, PROPERTY_TIMER_PATTERN, (String JavaDoc) model.getValue("pattern"));
473         setProp(props, PROPERTY_TIMER_PERIOD, (String JavaDoc) model.getValue("period"));
474         setProp(props, PROPERTY_TIMER_NUMBER_OF_OCCURRENCES, (String JavaDoc) model.getValue("occurrence"));
475         setProp(props, PROPERTY_TIMER_MESSAGE, (String JavaDoc) model.getValue("message"));
476         setProp(props, PROPERTY_TIMER_PATTERN, (String JavaDoc) model.getValue("pattern"));
477         return props;
478     }
479     
480     
481     
482     private Properties JavaDoc getMonitorProperties(DefaultModel model){
483         Properties JavaDoc props = new Properties JavaDoc();
484         
485         setProp(props, PROPERTY_MONITOR_OBSERVED_OBJ, (String JavaDoc) model.getValue("observedObject"));
486         setProp(props, PROPERTY_MONITOR_OBSERVED_ATTRIBUTE, (String JavaDoc) model.getValue("observedAttr"));
487         setProp(props, PROPERTY_MONITOR_GRANULARITY_PERIOD, (String JavaDoc) model.getValue("period"));
488         
489         String JavaDoc monitorType = (String JavaDoc) 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 JavaDoc) model.getValue("gaugeNumberType"));
494             setProp(props, PROPERTY_MONITOR_DIFFERENCEMODE, (String JavaDoc) model.getValue("gaugeDiff"));
495             setProp(props, PROPERTY_MONITOR_HIGH_THRESHOLD, (String JavaDoc) model.getValue("gaugeHighThreshold"));
496             setProp(props, PROPERTY_MONITOR_LOW_THRESHOLD, (String JavaDoc) model.getValue("gaugeLowThreshold"));
497         }else
498         if(PROPERTY_MONITOR_COUNTER.equals(monitorType)){
499             setProp(props, PROPERTY_MONITOR_NUMBERTYPE, (String JavaDoc) model.getValue("countNumberType"));
500             setProp(props, PROPERTY_MONITOR_DIFFERENCEMODE, (String JavaDoc) model.getValue("countDiff"));
501             setProp(props, PROPERTY_MONITOR_INIT_THRESHOLD, (String JavaDoc) model.getValue("initThreshold"));
502             setProp(props, PROPERTY_MONITOR_OFFSET, (String JavaDoc) model.getValue("offset"));
503             setProp(props, PROPERTY_MONITOR_MODULUS, (String JavaDoc) model.getValue("modulus"));
504         }else
505         if(PROPERTY_MONITOR_STRING.equals(monitorType)){
506             String JavaDoc compare = (String JavaDoc) 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 JavaDoc) model.getValue("strValue"));
513         }
514         return props;
515     }
516     
517     
518             
519     public void getCommonAttributesForRules(RequestContext ctx, HandlerContext handlerCtx) {
520         
521         String JavaDoc ruleObjectName = (String JavaDoc) handlerCtx.getInputValue("ruleObjectName");
522         String JavaDoc eventObjectName = (String JavaDoc) handlerCtx.getInputValue("eventObjectName");
523         
524         handlerCtx.setOutputValue("ruleEnabled", (String JavaDoc) MBeanUtil.getAttribute( ruleObjectName, "enabled"));
525         handlerCtx.setOutputValue("ruleDesc", (String JavaDoc) MBeanUtil.getAttribute( ruleObjectName, "description"));
526         String JavaDoc eventType = (String JavaDoc) MBeanUtil.getAttribute( eventObjectName, "type");
527         handlerCtx.setOutputValue("eventType", eventType);
528         handlerCtx.setOutputValue("recordEvent", (String JavaDoc) MBeanUtil.getAttribute( eventObjectName, "record-event"));
529         handlerCtx.setOutputValue("eventLogLevel", (String JavaDoc) MBeanUtil.getAttribute( eventObjectName, "level"));
530         handlerCtx.setOutputValue("eventDesc", (String JavaDoc) MBeanUtil.getAttribute( eventObjectName, "description"));
531         
532         ObjectName JavaDoc actionObjectName = getActionObjectName(ruleObjectName);
533         if (actionObjectName != null){
534             String JavaDoc actionMbeanName = (String JavaDoc) MBeanUtil.getAttribute(actionObjectName, "action-mbean-name");
535             if (!Util.isEmpty(actionMbeanName)){
536                 handlerCtx.setOutputValue("action", actionMbeanName);
537             }
538         }
539             
540         AttributeList JavaDoc attrs = (AttributeList JavaDoc) 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 JavaDoc <Attribute JavaDoc> attrs){
550         boolean mbean = false;
551         for(Attribute JavaDoc attr : attrs){
552             String JavaDoc name = (String JavaDoc) attr.getName();
553             String JavaDoc value = (String JavaDoc) attr.getValue();
554             if (PROPERTY_NOTIFICATION_SOURCEMBEAN.equals(name)){
555                 mbean = true;
556                 break;
557             }
558         }
559         if(mbean){
560             attrs.add( new Attribute JavaDoc("sourceRB","predefinedMBean"));
561         }else
562             attrs.add( new Attribute JavaDoc("sourceRB","userdefinedObjName"));
563     }
564     
565      public void getEventPropertyList(RequestContext ctx, HandlerContext handlerCtx) {
566          
567          String JavaDoc eventObjectName = (String JavaDoc) handlerCtx.getInputValue("eventObjectName");
568          String JavaDoc eventType = (String JavaDoc) MBeanUtil.getAttribute(eventObjectName, "type");
569          
570          /* We can't use the API because the order of the attributes must be match later on with the value we need to set.
571           *
572           *
573          String rulesObjectName = (String) handlerCtx.getInputValue("rulesObjectName");
574          Object[] params = {eventType};
575          String[] types={"java.lang.String"};
576          List list = (List) MBeanUtil.invoke(rulesObjectName, "getEventProperties", params, types);
577          handlerCtx.setOutputValue("propertyNameList", list);
578           */

579          
580          ArrayList JavaDoc list = new ArrayList JavaDoc();
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 JavaDoc type = (String JavaDoc) MBeanUtil.invoke(eventObjectName, "getPropertyValue",
614                                 new Object JavaDoc[]{PROPERTY_MONITOR_TYPE},
615                                 new String JavaDoc[]{"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 JavaDoc eventObjectName = (String JavaDoc) handlerCtx.getInputValue("eventObjectName");
641          String JavaDoc type = (String JavaDoc) MBeanUtil.invoke(eventObjectName, "getPropertyValue",
642                                 new Object JavaDoc[]{PROPERTY_MONITOR_TYPE},
643                                 new String JavaDoc[]{"java.lang.String"});
644             
645          handlerCtx.setOutputValue("mtype", translatedMonitorType(type));
646      }
647      
648      
649      private String JavaDoc translatedMonitorType(String JavaDoc type){
650          String JavaDoc 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 JavaDoc ruleObjectName = (String JavaDoc) handlerCtx.getInputValue("ruleObjectName");
668          String JavaDoc actionMbeanName = (String JavaDoc) handlerCtx.getInputValue("actionMbeanName");
669          ObjectName JavaDoc 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 JavaDoc origActionMbeanName = (String JavaDoc) 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 JavaDoc attrs = new AttributeList JavaDoc();
687          attrs.add(new Attribute JavaDoc("action-mbean-name", actionMbeanName));
688          Object JavaDoc params[] = {attrs };
689          String JavaDoc types[] = {"javax.management.AttributeList" };
690          MBeanUtil.invoke(ruleObjectName, "createAction", params, types );
691          
692      }
693     
694      //For Save in Editing
695
public void setLogEventProperties(RequestContext ctx, HandlerContext handlerCtx) {
696          String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
697          Object JavaDoc[] loggers= (Object JavaDoc[]) handlerCtx.getInputValue("logger");
698          String JavaDoc logLevel = (String JavaDoc) handlerCtx.getInputValue("logLevel");
699          
700          String JavaDoc allLogger = null;
701          if (loggers != null) {
702         int len = ((Object JavaDoc[])loggers).length;
703         for (int count=0; count<len; count++) {
704         String JavaDoc val = (String JavaDoc) (((Object JavaDoc[])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 JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
719          String JavaDoc lifeCycleName = (String JavaDoc) handlerCtx.getInputValue("lifeCycleName");
720          setPropertyWithValue(objectName,PROPERTY_LIFECYCLE_NAME, lifeCycleName );
721      }
722      
723      
724      public void setTraceEventProperties(RequestContext ctx, HandlerContext handlerCtx) {
725          String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
726          String JavaDoc traceName = (String JavaDoc) handlerCtx.getInputValue("traceName");
727          setPropertyWithValue(objectName,PROPERTY_TRACE_NAME, traceName );
728      }
729      
730       public void setClusterEventProperties(RequestContext ctx, HandlerContext handlerCtx) {
731          String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
732          String JavaDoc clusterEventName = (String JavaDoc) handlerCtx.getInputValue("clusterEventName");
733          String JavaDoc clusterEventServerName = (String JavaDoc) 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 JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
742          
743         setPropertyWithValue(objectName,PROPERTY_TIMER_DATESTRING, (String JavaDoc) handlerCtx.getInputValue("dateString") );
744         setPropertyWithValue(objectName,PROPERTY_TIMER_PATTERN, (String JavaDoc) handlerCtx.getInputValue("pattern") );
745         setPropertyWithValue(objectName,PROPERTY_TIMER_PERIOD, (String JavaDoc) handlerCtx.getInputValue("period") );
746         setPropertyWithValue(objectName,PROPERTY_TIMER_NUMBER_OF_OCCURRENCES, (String JavaDoc) handlerCtx.getInputValue("occurrence") );
747         setPropertyWithValue(objectName,PROPERTY_TIMER_MESSAGE, (String JavaDoc) handlerCtx.getInputValue("message") );
748      }
749       
750       
751      public void setMonitorEventGaugeProperties(RequestContext ctx, HandlerContext handlerCtx) {
752         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
753         setPropertyWithValue(objectName,PROPERTY_MONITOR_GRANULARITY_PERIOD, (String JavaDoc) handlerCtx.getInputValue("period"));
754         setPropertyWithValue(objectName,PROPERTY_MONITOR_NUMBERTYPE, (String JavaDoc) handlerCtx.getInputValue("gaugeNumberType") );
755         setPropertyWithValue(objectName,PROPERTY_MONITOR_DIFFERENCEMODE, (String JavaDoc) handlerCtx.getInputValue("gaugeDiff") );
756         setPropertyWithValue(objectName,PROPERTY_MONITOR_LOW_THRESHOLD, (String JavaDoc) handlerCtx.getInputValue("gaugeLowThreshold") );
757         setPropertyWithValue(objectName,PROPERTY_MONITOR_HIGH_THRESHOLD, (String JavaDoc) handlerCtx.getInputValue("gaugeHighThreshold") );
758      }
759      
760      
761      public void setMonitorEventCountProperties(RequestContext ctx, HandlerContext handlerCtx) {
762          
763         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
764         setPropertyWithValue(objectName,PROPERTY_MONITOR_GRANULARITY_PERIOD, (String JavaDoc) handlerCtx.getInputValue("period"));
765         setPropertyWithValue(objectName,PROPERTY_MONITOR_NUMBERTYPE, (String JavaDoc) handlerCtx.getInputValue("countNumberType") );
766         setPropertyWithValue(objectName,PROPERTY_MONITOR_DIFFERENCEMODE, (String JavaDoc) handlerCtx.getInputValue("countDiff") );
767         setPropertyWithValue(objectName,PROPERTY_MONITOR_INIT_THRESHOLD, (String JavaDoc) handlerCtx.getInputValue("initThreshold") );
768         setPropertyWithValue(objectName,PROPERTY_MONITOR_OFFSET, (String JavaDoc) handlerCtx.getInputValue("offset") );
769         setPropertyWithValue(objectName,PROPERTY_MONITOR_MODULUS, (String JavaDoc) handlerCtx.getInputValue("modulus") );
770      }
771      
772      
773      public void setMonitorEventStringProperties(RequestContext ctx, HandlerContext handlerCtx) {
774         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
775         setPropertyWithValue(objectName,PROPERTY_MONITOR_GRANULARITY_PERIOD, (String JavaDoc) handlerCtx.getInputValue("period"));
776         setPropertyWithValue(objectName,PROPERTY_MONITOR_STRING_NOTIFY, (String JavaDoc) handlerCtx.getInputValue("compare") );
777         setPropertyWithValue(objectName,PROPERTY_MONITOR_STRING_TO_COMPARE, (String JavaDoc) handlerCtx.getInputValue("strValue") );
778      }
779      
780      public void setNotificationEventProperties(RequestContext ctx, HandlerContext handlerCtx) {
781         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
782         String JavaDoc sourceRB = (String JavaDoc) handlerCtx.getInputValue("sourceRB");
783         if ("predefinedMBean".equals(sourceRB)){
784             setPropertyWithValue(objectName,PROPERTY_NOTIFICATION_SOURCEMBEAN, (String JavaDoc) handlerCtx.getInputValue("sourceMbean") );
785         }else{
786             setPropertyWithValue(objectName,PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME, (String JavaDoc) handlerCtx.getInputValue("sourceObjectName") );
787         }
788         setPropertyWithValue(objectName, PROPERTY_NOTIFICATION_TYPE, (String JavaDoc) handlerCtx.getInputValue("notificationType") ); //TODO need to get from Constants
789
}
790         
791       
792       private void setPropertyWithValue(String JavaDoc objectName, String JavaDoc name, String JavaDoc value){
793          Object JavaDoc params[] = {new Attribute JavaDoc(name, value)};
794          String JavaDoc types[] = {"javax.management.Attribute"};
795          String JavaDoc origValue = "";
796          try{
797              Object JavaDoc pp[] = {name};
798              String JavaDoc tt[]= {"java.lang.String"};
799              origValue = (String JavaDoc) MBeanUtil.invoke(objectName, "getPropertyValue", pp, tt);
800              if (origValue == null) origValue="";
801         }catch(Exception JavaDoc ex) {
802             //ignore exception thrown when period never specified before.
803
}
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 JavaDoc getActionObjectName( String JavaDoc ruleObjectName){
822          try {
823             ObjectName JavaDoc actionObjectName = (ObjectName JavaDoc) MBeanUtil.invoke(ruleObjectName, "getAction", null, null);
824             return actionObjectName;
825         }catch(Exception JavaDoc ex){
826             //backend will throw a MBeanConfigInstanceNotFoundException if the action element doesn't exist. action element is optional.
827
//just ignore this since action element is optional.
828
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         // the child can be dropdown or radiobutton
840
populateDropDownEventProperties(handlerCtx, EVENT_MONITOR, PROPERTY_MONITOR_NUMBERTYPE );
841      }
842      
843      public void populateNotificationSourceMbean(RequestContext ctx, HandlerContext handlerCtx) {
844         // the child can be dropdown or radiobutton
845
populateDropDownEventProperties(handlerCtx, EVENT_NOTIFICATION, PROPERTY_NOTIFICATION_SOURCEMBEAN );
846      }
847      
848      
849       private void populateDropDownEventProperties(HandlerContext handlerCtx, String JavaDoc eventType, String JavaDoc propertyName){
850           
851         // the child can be dropdown or radiobutton
852
SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
853         String JavaDoc initialValue = (String JavaDoc)handlerCtx.getInputValue("initialValue");
854         String JavaDoc rulesObjectName = (String JavaDoc)handlerCtx.getInputValue("rulesObjectName");
855         
856         Object JavaDoc params[] = { eventType, propertyName };
857         String JavaDoc types[] = { "java.lang.String", "java.lang.String" };
858         
859         List JavaDoc <String JavaDoc> list = (List JavaDoc) MBeanUtil.invoke(rulesObjectName, "getEventPropertyValues", params, types);
860         if (list == null) return;
861         
862         TreeSet JavaDoc <String JavaDoc> tset = new TreeSet JavaDoc(list); //sorting
863

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 JavaDoc 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