KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * ConnectorConnectionPoolHandlers.java
26  *
27  * Created on November 26, 2003, 2:35 PM
28  */

29
30 package com.sun.enterprise.tools.admingui.handlers;
31
32 import java.util.Properties JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Vector JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.Set JavaDoc;
38 import javax.management.ObjectName JavaDoc;
39 import javax.management.AttributeList JavaDoc;
40 import javax.management.Attribute JavaDoc;
41 import javax.management.j2ee.statistics.CountStatistic JavaDoc;
42 import javax.management.j2ee.statistics.TimeStatistic JavaDoc;
43
44
45 import com.iplanet.jato.RequestContext;
46 import com.iplanet.jato.RequestManager;
47 import com.iplanet.jato.view.View;
48 import com.iplanet.jato.view.ViewBase;
49 import com.sun.web.ui.model.CCActionTableModelInterface;
50 import com.iplanet.jato.view.ContainerView;
51 import com.iplanet.jato.view.ContainerViewBase;
52 import com.iplanet.jato.view.html.SelectableGroup;
53 import com.iplanet.jato.view.html.OptionList;
54 import com.iplanet.jato.model.DefaultModel;
55 import com.iplanet.jato.view.event.ChildContentDisplayEvent;
56 import com.sun.web.ui.model.CCActionTableModel;
57 import com.iplanet.jato.model.ModelControlException;
58 import com.iplanet.jato.view.html.*;
59 import com.iplanet.jato.util.NonSyncStringBuffer;
60
61 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent;
62 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
63 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
64 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
65 import com.sun.enterprise.tools.guiframework.view.DescriptorCCPageTitle;
66 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor;
67 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
68 import com.sun.enterprise.tools.guiframework.view.DescriptorCCActionTable;
69 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
70 import com.sun.enterprise.tools.admingui.util.Util;
71 import com.sun.enterprise.tools.admingui.util.AMXUtil;
72 import com.sun.appserv.management.j2ee.statistics.StringStatistic;
73 import com.sun.appserv.management.helper.LBConfigHelper;
74
75 import com.sun.enterprise.deployment.phasing.ApplicationConfigHelper;
76 import com.sun.enterprise.deployment.phasing.DeploymentServiceUtils;
77
78 import com.sun.appserv.management.monitor.statistics.LoadBalancerServerStats;
79 import com.sun.appserv.management.monitor.statistics.LoadBalancerContextRootStats;
80 import com.sun.appserv.management.base.QueryMgr;
81 import com.sun.appserv.management.config.LBConfig;
82
83
84 /**
85  *
86  */

87 public class LoadBalancerHandlers {
88
89     public void setLbProperties(RequestContext ctx, HandlerContext handlerCtx) {
90
91         String JavaDoc objectName = (String JavaDoc) handlerCtx.getInputValue("objectName");
92         String JavaDoc methodName = (String JavaDoc) handlerCtx.getInputValue("methodName");
93         AttributeList JavaDoc properties = (AttributeList JavaDoc)handlerCtx.getInputValue("properties");
94         if(properties == null){
95             properties = new AttributeList JavaDoc();
96         }
97         Object JavaDoc[] params = null;
98         String JavaDoc[] types = {"javax.management.Attribute"};
99
100         for (int i = 0; i < properties.size(); i++) {
101             Attribute JavaDoc attr = (Attribute JavaDoc)properties.get(i);
102                 try {
103                     MBeanUtil.invoke(objectName, methodName, new Object JavaDoc[] {attr}, types);
104                 }catch (Exception JavaDoc ex) {
105                     
106                     Util.logINFO("Could not set property for load balancer:"+ex.getMessage());
107                     
108                 }
109         }
110     }
111     
112     public void getLbProperties(RequestContext ctx, HandlerContext handlerCtx) {
113         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
114         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
115         String JavaDoc propName = (String JavaDoc)handlerCtx.getInputValue("propName");
116        String JavaDoc[] types = {"java.lang.String"};
117         String JavaDoc propValue = "";
118        try {
119             propValue = (String JavaDoc)MBeanUtil.invoke(objectName, methodName, new Object JavaDoc[] {propName}, types);
120         } catch (Exception JavaDoc ex) {
121             // ignore no property value
122
}
123         
124         handlerCtx.setOutputValue("value", propValue);
125         
126         
127     }
128     
129     public void getTargetList(RequestContext ctx, HandlerContext handlerCtx) {
130         ObjectName JavaDoc[] clusterNames = (ObjectName JavaDoc[])handlerCtx.getInputValue("clusterRefs");
131         ObjectName JavaDoc[] serverNames = (ObjectName JavaDoc[])handlerCtx.getInputValue("serverRefs");
132         String JavaDoc[] targets = null;
133         boolean serverList = false;
134         boolean clusterList = false;
135         if(serverNames != null && serverNames.length >0){
136             serverList = true;
137         }
138         if(clusterNames != null && clusterNames.length >0){
139             clusterList = true;
140         }
141         if(serverList && clusterList){
142             targets = new String JavaDoc[clusterNames.length+serverNames.length];
143             for (int i=0; clusterNames != null && i < clusterNames.length; i++) {
144                 targets[i] = clusterNames[i].getKeyProperty("ref");
145             }
146             
147             
148             for (int i=0; serverNames != null && i < serverNames.length; i++) {
149                 int start = clusterNames.length;
150                 targets[start+i] = serverNames[i].getKeyProperty("ref");
151             }
152             
153         } else if(serverList && !clusterList){
154             targets = new String JavaDoc[serverNames.length];
155             for (int i=0; serverNames != null && i < serverNames.length; i++) {
156                 targets[i] = serverNames[i].getKeyProperty("ref");
157             }
158             
159         } else if(!serverList && clusterList) {
160             targets = new String JavaDoc[clusterNames.length];
161             for (int i=0; clusterNames != null && i < clusterNames.length; i++) {
162                 targets[i] = clusterNames[i].getKeyProperty("ref");
163             }
164         }
165       
166     handlerCtx.setOutputValue("value", targets);
167         if(targets != null){
168             handlerCtx.setOutputValue("hasValue", "true");
169         }
170             
171     }
172    
173     public void createLBReferences(RequestContext ctx, HandlerContext handlerCtx) {
174         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
175         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
176         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
177         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
178         String JavaDoc[] refs = (String JavaDoc[])handlerCtx.getInputValue("refs");
179         if(targets != null){
180             for(int i = 0; i < targets.length; i++){
181                 boolean foundMatch = false;
182                 if(refs != null){
183                     for(int j = 0; j < refs.length; j++){
184                         //boolean foundMatch = false;
185
if(targets[i].equals(refs[j])) {
186                             foundMatch = true;
187                         }
188                     }
189                     
190                 }
191                 if(!foundMatch || refs == null) {
192                     if(isCluster(targets[i])) {
193                         String JavaDoc[] types= new String JavaDoc[]{"javax.management.AttributeList"};
194                         AttributeList JavaDoc attrList = new AttributeList JavaDoc();
195                         attrList.add(new Attribute JavaDoc("ref", targets[i]));
196                         Object JavaDoc params[] = {attrList};
197                         MBeanUtil.invoke(objectName, "createClusterRef", params, types);
198                     } else {
199                         String JavaDoc[] types= new String JavaDoc[]{"javax.management.AttributeList"};
200                         AttributeList JavaDoc attrList = new AttributeList JavaDoc();
201                         attrList.add(new Attribute JavaDoc("ref", targets[i]));
202                         Object JavaDoc params[] = {attrList};
203                         MBeanUtil.invoke(objectName, "createServerRef", params, types);
204                     }
205                 }
206                 
207             }
208         }
209     }
210     
211     public void deleteLBReferences(RequestContext ctx, HandlerContext handlerCtx) {
212         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
213         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
214         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
215         String JavaDoc[] deleteTargets = (String JavaDoc[])handlerCtx.getInputValue("availableTargets");
216         String JavaDoc[] types= new String JavaDoc[]{"java.lang.String"};
217         
218         if(deleteTargets != null) {
219             for (int i = 0; i < deleteTargets.length; i++) {
220                 Object JavaDoc params[] = {deleteTargets[i]};
221                 if(isCluster(deleteTargets[i])){
222                     
223                     MBeanUtil.invoke(objectName, methodName, params, types);
224                 } else {
225                     
226                     MBeanUtil.invoke(objectName, "removeServerRefByRef", params, types);
227                 }
228                 
229                 
230             }
231         }
232     }
233     
234    public void deleteClusterLBReferences(RequestContext ctx, HandlerContext handlerCtx) {
235         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
236         String JavaDoc cluster = (String JavaDoc)handlerCtx.getInputValue("cluster");
237         String JavaDoc[] lbs = (String JavaDoc[])handlerCtx.getInputValue("lbs");
238         String JavaDoc[] types= new String JavaDoc[]{"java.lang.String"};
239         if(lbs == null)
240             return;
241
242         for (int i = 0; i < lbs.length; i++) {
243             Object JavaDoc params[] = {cluster};
244             try {
245                 MBeanUtil.invoke("com.sun.appserv:type=lb-config,name="+lbs[i]+",category=config", methodName, params, types);
246             } catch (Exception JavaDoc ex) {
247                 throw new FrameworkException(
248                 "Error while deleting lb ref for '"+cluster+
249                 "'!", ex, handlerCtx.getViewDescriptor(),
250                 handlerCtx.getView());
251             }
252         }
253     }
254    
255    public void createLoadBalancer(RequestContext ctx, HandlerContext handlerCtx) {
256        String JavaDoc lbName = (String JavaDoc)handlerCtx.getInputValue("lbName");
257        Object JavaDoc refName = (Object JavaDoc)handlerCtx.getInputValue("refs");
258        String JavaDoc[] targets = {""};
259        if (refName instanceof String JavaDoc) {
260            String JavaDoc name = (String JavaDoc)refName;
261            targets[0] = name;
262        } else if(refName instanceof String JavaDoc[]) {
263            targets = (String JavaDoc[])refName;
264        }
265        
266        try {
267            Map JavaDoc params = null;
268            LBConfigHelper helper = new LBConfigHelper(AMXUtil.getDomainRoot());
269            helper.createLoadbalancer(lbName, true, targets, params);
270        } catch (Exception JavaDoc ex) {
271            if (Util.isLoggableFINE()) {
272                Util.logFINE(ex);
273            }
274        }
275    }
276
277     private boolean isCluster(String JavaDoc name) {
278         Object JavaDoc objName = null;
279         
280         String JavaDoc[] types= new String JavaDoc[]{"java.lang.String"};
281         Object JavaDoc params[] = {name};
282         try {
283             objName = MBeanUtil.invoke("com.sun.appserv:type=clusters,category=config", "getClusterByName", params, types);
284         } catch (Exception JavaDoc ex) {
285             // ignore
286
}
287         if(objName != null) {
288             return new Boolean JavaDoc("true").booleanValue();
289         } else {
290             return new Boolean JavaDoc("false").booleanValue();
291         }
292         
293     }
294     
295     public void isCluster(RequestContext ctx, HandlerContext handlerCtx) {
296         String JavaDoc name = (String JavaDoc)handlerCtx.getInputValue("serverName");
297         Object JavaDoc objName = null;
298         if (name != null ) {
299                 String JavaDoc[] types= new String JavaDoc[]{"java.lang.String"};
300                 Object JavaDoc params[] = {name};
301                 try {
302                     objName = MBeanUtil.invoke("com.sun.appserv:type=clusters,category=config", "getClusterByName", params, types);
303                 } catch (Exception JavaDoc ex) {
304                     // ignore
305
}
306                 if(objName != null) {
307                     handlerCtx.setOutputValue("isCluster", "true");
308                 } else {
309                     handlerCtx.setOutputValue("isCluster", "false");
310                 }
311                 
312            
313         }
314     }
315     
316     public void getAttributeForClusterRef(RequestContext ctx, HandlerContext handlerCtx) {
317         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
318         String JavaDoc cluster = (String JavaDoc)handlerCtx.getInputValue("clusterName");
319         String JavaDoc attrName = (String JavaDoc)handlerCtx.getInputValue("attrName");
320         String JavaDoc attrValue = "";
321         if (targets != null && attrName != null){
322             for (int i = 0; i < targets.length; i++) {
323                 attrValue = (String JavaDoc)MBeanUtil.getAttribute("com.sun.appserv:type=cluster-ref,ref="+cluster+",lb-config="+targets[i]+",category=config"
324                 , attrName);
325             }
326             
327             handlerCtx.setOutputValue("attrValue", attrValue);
328         }
329     }
330     
331     public void getAttributeForLB(RequestContext ctx, HandlerContext handlerCtx) {
332         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
333         String JavaDoc attrName = (String JavaDoc)handlerCtx.getInputValue("attrName");
334         if (attrName==null)
335             attrName="lb-config-name";
336         Object JavaDoc value = null;
337         value = MBeanUtil.getAttribute(objectName, attrName);
338         String JavaDoc result = null;
339         if (value != null) {
340             if (value instanceof String JavaDoc) {
341                 result = (String JavaDoc)value;
342             } else {
343                 result = value.toString();
344             }
345         }
346         handlerCtx.setOutputValue("attrValue", result);
347     
348
349     }
350     
351     public void setAttributeForLB(RequestContext ctx, HandlerContext handlerCtx) {
352         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
353         String JavaDoc cluster = (String JavaDoc)handlerCtx.getInputValue("clusterName");
354         String JavaDoc policy = (String JavaDoc)handlerCtx.getInputValue("policy");
355         String JavaDoc module = (String JavaDoc)handlerCtx.getInputValue("module");
356         if (targets != null && policy != null){
357             for (int i = 0; i < targets.length; i++) {
358                 MBeanUtil.setAttribute("com.sun.appserv:type=cluster-ref,ref="+cluster+",lb-config="+targets[i]+",category=config"
359                 , new Attribute JavaDoc("lb-policy", policy));
360                 if(module != null){
361                     MBeanUtil.setAttribute("com.sun.appserv:type=cluster-ref,ref="+cluster+",lb-config="+targets[i]+",category=config", new Attribute JavaDoc("lb-policy-module", module));
362                     
363                 }
364             }
365             
366             
367         }
368     }
369     
370     
371     public void setAttribute(RequestContext ctx, HandlerContext handlerCtx) {
372         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
373         if (objectName == null) {
374             throw new FrameworkException("LB Handler: setAttribute: Parameter 'objectName' not specified");
375         }
376         String JavaDoc propName = (String JavaDoc)handlerCtx.getInputValue("name");
377         if (propName == null) {
378             throw new FrameworkException("LB Handler: setAttribute: Parameter 'name' not specified");
379         }
380         String JavaDoc propValue = (String JavaDoc)handlerCtx.getInputValue("value");
381         if (propValue == null) {
382             throw new FrameworkException("LB Handler: setAttribute: Parameter 'value' not specified");
383         }
384         MBeanUtil.setAttribute(objectName, new Attribute JavaDoc(propName, propValue));
385         
386     }
387     
388     public void setConfigMonitoringEnabled(RequestContext ctx, HandlerContext handlerCtx) {
389         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
390         if (objectName == null) {
391             throw new FrameworkException("LB Handler: setConfigMonitoringEnabled: Parameter 'objectName' not specified");
392         }
393         String JavaDoc propName = (String JavaDoc)handlerCtx.getInputValue("name");
394         String JavaDoc propValue = (String JavaDoc)handlerCtx.getInputValue("value");
395         if (propValue == null) {
396             throw new FrameworkException("LB Handler: setConfigMonitoringEnabled: Parameter 'value' not specified");
397         }
398         
399         Set JavaDoc<LBConfig> lbConfigSet = null;
400         QueryMgr queryMgr = AMXUtil.getQueryMgr();
401         try {
402             lbConfigSet = queryMgr.queryPatternSet(new ObjectName JavaDoc(objectName));
403         } catch (javax.management.MalformedObjectNameException JavaDoc e) {
404             e.printStackTrace();
405         }
406         for(LBConfig lbconfig : lbConfigSet){
407             //should be only 1.
408
lbconfig.setMonitoringEnabled(new Boolean JavaDoc(propValue));
409         }
410     }
411     
412     
413    public String JavaDoc endEditTabsDisplay(RequestContext ctx, HandlerContext handlerCtx) {
414     if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
415         return null;
416     }
417     ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
418     String JavaDoc content = dispEvent.getContent();
419         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
420         String JavaDoc key2 = (String JavaDoc)handlerCtx.getInputValue("key2");
421         if (key==null)
422             key="editKeyValue";
423         if (key2==null)
424             key2="lbKey";
425         content = content.replaceAll(".PLACEHOLDER.",
426             "&"+ key + "=" + ctx.getRequest().getAttribute(key) +"&"+ key2 + "=" + ctx.getRequest().getAttribute(key2));
427         return content;
428     }
429    
430    public void saveHealthChecker(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException {
431        String JavaDoc lbConfigName = (String JavaDoc)handlerCtx.getInputValue("lbConfigName");
432        if (lbConfigName == null) {
433            throw new FrameworkException(
434            "lbConfigName not specified in saveHealthChecker.");
435        }
436        
437        String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
438        if (methodName == null) {
439            methodName="createHealthChecker";
440        }
441        
442        CCActionTableModelInterface model =
443        (CCActionTableModelInterface)handlerCtx.getInputValue("lbTargetsModel");
444        //((DefaultModel)model).clear();
445
//model.setRowSelectionType("multiple");
446

447        if (model == null) {
448            throw new FrameworkException("PropertiesHandler.getModel: Parameter 'propertiesModel' not specified");
449        }
450        //model.setRowSelectionType("multiple");
451
model.beforeFirst();
452        
453        while(model.next()) {
454            AttributeList JavaDoc attrs = new AttributeList JavaDoc();
455            String JavaDoc name = null;
456            Object JavaDoc objName = null;
457            String JavaDoc interval = "";
458            String JavaDoc timeout = "";
459            String JavaDoc url = "";
460            
461            interval = (String JavaDoc) model.getValue("interval");
462            timeout = (String JavaDoc) model.getValue("timeout");
463            url = (String JavaDoc) model.getValue("url");
464            name = (String JavaDoc)model.getValue("name");
465            String JavaDoc[] type = new String JavaDoc[]{"javax.management.AttributeList"};
466            
467            
468            if (!Util.isEmpty(interval)) {
469                attrs.add(new Attribute JavaDoc("interval-in-seconds", interval));
470                if(!Util.isEmpty(timeout))
471                    attrs.add(new Attribute JavaDoc("timeout-in-seconds", timeout));
472                if(!Util.isEmpty(interval))
473                    attrs.add(new Attribute JavaDoc("url", url));
474                if(!Util.isEmpty(name))
475               
476                if(!Util.isEmpty(url) && !Util.isEmpty(timeout)) {
477                    String JavaDoc objectName = null;
478                    String JavaDoc target = null;
479                    if(isCluster(name)) {
480                        objectName = "com.sun.appserv:type=cluster-ref,ref="+name+",lb-config="+lbConfigName+",category=config";
481                        target = "cluster";
482                        
483                    } else {
484                        objectName = "com.sun.appserv:type=server-ref,ref="+name+",lb-config="+lbConfigName+",category=config";
485                        target = "server";
486                        
487                    }
488                    Object JavaDoc[] params = new Object JavaDoc[]{attrs};
489
490                    String JavaDoc objectName2 = "com.sun.appserv:type=health-checker,"+target+"-ref="+name+",lb-config="+lbConfigName+",category=config";
491                    if (MBeanUtil.isValidMBean(objectName2)){
492                        try {
493                            MBeanUtil.setAttributes(objectName2, attrs);
494                        } catch (Exception JavaDoc ex) {
495                            throw new FrameworkException(
496                            "Error while setting attributes on MBean '"+objectName+
497                            "'!", ex, handlerCtx.getViewDescriptor(),
498                            handlerCtx.getView());
499                        }
500                    } else {
501                       MBeanUtil.invoke(objectName, methodName, params, type);
502                    }
503                }
504            }
505        }
506    }
507      
508    
509    public void saveInstanceWeight(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException {
510        CCActionTableModelInterface model =
511        (CCActionTableModelInterface)handlerCtx.getInputValue("lbTargetsModel");
512        //((DefaultModel)model).clear();
513
//model.setRowSelectionType("multiple");
514

515        if (model == null) {
516            throw new FrameworkException("PropertiesHandler.getModel: Parameter 'propertiesModel' not specified");
517        }
518        model.setRowSelectionType("multiple");
519        
520        model.beforeFirst();
521        
522        while(model.next()) {
523            String JavaDoc weight = "";
524            String JavaDoc name = "";
525            name = (String JavaDoc) model.getValue("name");
526            weight = (String JavaDoc) model.getValue("weight");
527            Attribute JavaDoc attr = null;
528            if(!Util.isEmpty(name) && !Util.isEmpty(weight)) {
529                attr = new Attribute JavaDoc("lb-weight", weight);
530                try {
531                    MBeanUtil.setAttribute("com.sun.appserv:type=server,name="+name+",category=config", attr);
532                } catch (Exception JavaDoc ex) {
533                    throw new FrameworkException(
534                    "Error while setting lb weight on '"+name+
535                    "'!", ex, handlerCtx.getViewDescriptor(),
536                    handlerCtx.getView());
537                }
538            }
539            
540        }
541    }
542
543     
544     public void getHealthChecker(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException {
545        String JavaDoc lbConfigName = (String JavaDoc)handlerCtx.getInputValue("lbConfigName");
546     if (lbConfigName == null) {
547         throw new FrameworkException(
548                 "lbConfigName not specified in saveHealthChecker.");
549     }
550         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
551          CCActionTableModelInterface model =
552             (CCActionTableModelInterface)handlerCtx.getInputValue("lbTargetsModel");
553
554         if (model == null) {
555             throw new FrameworkException("PropertiesHandler.getModel: Parameter 'propertiesModel' not specified");
556         }
557         //model.setRowSelectionType("multiple");
558
String JavaDoc Interval = "";
559         String JavaDoc Timeout = "";
560         String JavaDoc URL = "";
561         String JavaDoc name = null;
562
563         ((DefaultModel)model).clear();
564         model.beforeFirst();
565         //model.setRowSelectionType("multiple");
566
if (targets != null) {
567             for (int i = 0; i < targets.length; i++) {
568                 model.appendRow();
569                 //((CCActionTableModel)model).sort();
570
String JavaDoc target = null;
571                 if(isCluster(targets[i])) {
572                     target = "cluster";
573                 } else {
574                     target = "server";
575                     
576                 }
577                 String JavaDoc objectName = "com.sun.appserv:type=health-checker,"+target+"-ref="+targets[i]+",lb-config="+lbConfigName+",category=config";
578                 try {
579                     Interval = (String JavaDoc)MBeanUtil.getAttribute(objectName, "interval-in-seconds");
580                     Timeout = (String JavaDoc)MBeanUtil.getAttribute(objectName, "timeout-in-seconds");
581                     URL = (String JavaDoc)MBeanUtil.getAttribute(objectName, "url");
582                     if(!isEmpty(URL))
583                         model.setValue("url", URL);
584                     if(!isEmpty(Timeout))
585                         model.setValue("timeout", Timeout);
586                     if(!isEmpty(Interval))
587                         model.setValue("interval", Interval);
588                 } catch (Exception JavaDoc ex) {
589                     // ignore no health checker created
590
}
591                 if(!isEmpty(targets[i]))
592                     model.setValue("name", targets[i]);
593                 
594             }
595         }
596     }
597     
598     public void executeMethodOnInstance(RequestContext ctx, HandlerContext handlerCtx) {
599         // Executes the given method on the selected rows of the table.
600
//
601
View view = handlerCtx.getView(); // this return the CCButton
602
DescriptorContainerView descView =
603             (DescriptorContainerView)(((ViewBase)view).getParentViewBean());
604     ViewDescriptor vd = descView.getViewDescriptor();
605     String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue("tableChildName");
606     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
607     if(childName == null) {
608         throw new FrameworkException("executeMethod: childName not specified", vd, view);
609     }
610         
611     ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName);
612     if (tableDescriptor == null) {
613         throw new FrameworkException("executeMethod: tableDescriptor is null", vd, view);
614     }
615     if(!(tableDescriptor instanceof CCActionTableDescriptor)) {
616         throw new FrameworkException(
617                 "executeMethod: tableDescriptor is of wrong type", tableDescriptor, view);
618     }
619         CCActionTableModelInterface model =
620             ((CCActionTableDescriptor)tableDescriptor).getModel();
621     String JavaDoc method = (String JavaDoc)handlerCtx.getInputValue("method");
622         if (method == null) {
623         throw new FrameworkException("executeMethod: method name is null", vd, view);
624         }
625         
626     model.setRowSelectionType("multiple");
627         //String objectName = null;
628
String JavaDoc[] types = {"java.lang.String"};
629     try {
630         model.beforeFirst();
631         while(model.next()) {
632         if (model.isRowSelected()) {
633                     if(objectName == null)
634                         objectName = (String JavaDoc)model.getValue("objectName");
635                     if (objectName == null)
636                         continue; // should be an error.
637
String JavaDoc instanceName = (String JavaDoc) model.getValue("name");
638                     MBeanUtil.invoke(objectName, method, new Object JavaDoc[] {instanceName}, types);
639             model.setRowSelected(false);
640                 }
641             }
642     } catch (Exception JavaDoc ex) {
643         throw new FrameworkException("Error while invoking '" + method +
644                 "' on " + objectName, ex, tableDescriptor, view);
645         }
646     ContainerViewBase containerView =
647             (ContainerViewBase)(tableDescriptor.getView(ctx).getParent());
648     containerView.removeChild(tableDescriptor.getName());
649     ((DefaultModel)model).clear();
650     }
651     
652     public void getInstancesforQuiesce(RequestContext ctx, HandlerContext handlerCtx) {
653         // Executes the given method on the selected rows of the table.
654
//
655
View view = handlerCtx.getView(); // this return the CCButton
656
DescriptorContainerView descView =
657             (DescriptorContainerView)(((ViewBase)view).getParentViewBean());
658     ViewDescriptor vd = descView.getViewDescriptor();
659     String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue("tableChildName");
660     if(childName == null) {
661         throw new FrameworkException("executeMethod: childName not specified", vd, view);
662     }
663         
664     ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName);
665     if (tableDescriptor == null) {
666         throw new FrameworkException("executeMethod: tableDescriptor is null", vd, view);
667     }
668     if(!(tableDescriptor instanceof CCActionTableDescriptor)) {
669         throw new FrameworkException(
670                 "executeMethod: tableDescriptor is of wrong type", tableDescriptor, view);
671     }
672         CCActionTableModelInterface model =
673             ((CCActionTableDescriptor)tableDescriptor).getModel();
674        
675     model.setRowSelectionType("multiple");
676     try {
677         model.beforeFirst();
678             String JavaDoc instances = "";
679         while(model.next()) {
680                 if (model.isRowSelected()) {
681                     if(instances.equals("")) {
682                         instances += (String JavaDoc) model.getValue("name");
683                         
684                     } else {
685                         instances += "@"+(String JavaDoc) model.getValue("name");
686                     }
687                     model.setRowSelected(false);
688                 }
689             }
690             handlerCtx.setOutputValue("value", instances);
691     } catch (Exception JavaDoc ex) {
692         throw new FrameworkException("setQuiescevalues: error getting instance names from table");
693         }
694     ContainerViewBase containerView =
695             (ContainerViewBase)(tableDescriptor.getView(ctx).getParent());
696     containerView.removeChild(tableDescriptor.getName());
697     ((DefaultModel)model).clear();
698     }
699     
700     public void getLB(RequestContext ctx, HandlerContext handlerCtx) {
701         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
702         ObjectName JavaDoc[] lbs = (ObjectName JavaDoc[])handlerCtx.getInputValue("lbs");
703         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
704         if(key == null)
705             key = "name";
706         
707         if (targets != null && lbs != null) {
708             for (int i = 0; i < targets.length; i++) {
709                 String JavaDoc lbConfig = "";
710                 String JavaDoc name = "";
711                 for(int j = 0; j < lbs.length; j++){
712                     lbConfig = (String JavaDoc)MBeanUtil.getAttribute(lbs[j].toString(), "lb-config-name");
713                     if(targets[i].equals(lbConfig)) {
714                         name = lbs[j].getKeyProperty("name");
715                     }
716                     if(!name.equals("")){
717                         handlerCtx.setOutputValue("value", name);
718                         return;
719                     }
720                 }
721                 
722             }
723         }
724     }
725     
726     public void beginQuiesce(RequestContext ctx, HandlerContext handlerCtx) {
727         String JavaDoc instances = (String JavaDoc)handlerCtx.getInputValue("instances");
728         String JavaDoc lbName = (String JavaDoc)handlerCtx.getInputValue("lbName");
729         String JavaDoc cluster = (String JavaDoc)handlerCtx.getInputValue("clusterName");
730         String JavaDoc lbConfig = (String JavaDoc)handlerCtx.getInputValue("lbConfig");
731         String JavaDoc[] targets = null;
732         if (Util.isEmpty(instances)){
733             //this shouldn't happen. meaning nothing passed in.
734
}else{
735             targets = instances.split("@");
736             
737         }
738         if(targets != null) {
739             for(int i = 0; i< targets.length; i++){
740                 if(cluster != null) {
741                     MBeanUtil.setAttribute("com.sun.appserv:type=server-ref,ref="+targets[i]+",cluster="+cluster+",category=config", new Attribute JavaDoc("lb-enabled", false));
742                     
743                 } else {
744                     MBeanUtil.setAttribute("com.sun.appserv:type=server-ref,ref="+targets[i]+",lb-config="+lbConfig+",category=config", new Attribute JavaDoc("lb-enabled", false));
745                      
746                 }
747             }
748         }
749             
750     }
751     
752     public void stopInstances(RequestContext ctx, HandlerContext handlerCtx) {
753         String JavaDoc instances = (String JavaDoc)handlerCtx.getInputValue("instances");
754         String JavaDoc[] targets = null;
755         if (Util.isEmpty(instances)){
756             //this shouldn't happen. meaning nothing passed in.
757
}else{
758             targets = instances.split("@");
759         }
760         try {
761             
762             if(targets != null) {
763                 for(int i = 0; i< targets.length; i++){
764                     Boolean JavaDoc isRunning = null;
765                     isRunning = (Boolean JavaDoc)MBeanUtil.invoke("com.sun.appserv:type=server,name="+targets[i]+",category=config", "isRunning", null, null);
766                    if(isRunning.booleanValue()){
767                         MBeanUtil.invoke("com.sun.appserv:type=server,name="+targets[i]+",category=config", "stop", null, null);
768                     }
769                     
770                 }
771             }
772         } catch (Exception JavaDoc ex) {
773             throw new FrameworkException("Stop Instances: Error while stopping instances", ex, handlerCtx.getViewDescriptor(),
774                    handlerCtx.getView());
775         }
776         
777         
778     }
779     
780     // add a hidden variable for the highlight ID and include javascript
781
/*public String endExtraInstancesDisplay(RequestContext ctx, HandlerContext handlerCtx) {
782         ChildContentDisplayEvent ev = (ChildContentDisplayEvent)handlerCtx.getEvent();
783     View bean = handlerCtx.getView();
784
785     while (!(bean instanceof DescriptorContainerView)) {
786         // Should only happen once, if at all.
787         bean = bean.getParent();
788     }
789         // remember the current view (page) so we can go back to it when switching trees.
790         setCurrentView(ctx, bean);
791
792         NonSyncStringBuffer buff = new NonSyncStringBuffer(ev.getContent(), 512);
793         
794         String script = (String)handlerCtx.getInputValue("script") ;
795         if (script != null) {
796             buff.append("\n").append(script);
797     }
798
799         
800         buff.append("\n<input name=\"instances\" type=\"hidden\" value=\"")
801             .append("instance1").append("\">");
802         
803         return buff.toString();
804     }*/

805     
806     public String JavaDoc endDisplayLBTargetsInTable(RequestContext ctx, HandlerContext handlerCtx) {
807     if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
808         return null;
809     }
810     ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
811     String JavaDoc content = dispEvent.getContent();
812         String JavaDoc[] targets = (String JavaDoc[])handlerCtx.getInputValue("targets");
813         String JavaDoc key = (String JavaDoc)handlerCtx.getInputValue("key");
814         if(key == null)
815             key = "name";
816         
817         String JavaDoc hrefs = "";
818         if (targets != null) {
819             for (int i = 0; i < targets.length; i++) {
820                 if (i > 0)
821                     hrefs += "<br />";
822                 
823                 //String objectType = targets[i].getKeyProperty("type");
824
boolean isCluster = isCluster(targets[i]);
825                 String JavaDoc target = null;
826                 if(isCluster){
827                     target = "cluster";
828                 } else {
829                     target = "serverInstance";
830                 }
831
832
833                 String JavaDoc tmp = content.replaceFirst(".TARGETVALUE.",
834                     targets[i]+"&nextPage="+target);
835                 hrefs += tmp.replaceAll(".TARGETVALUE.",
836                     targets[i]);
837             }
838         }
839         return hrefs;
840     }
841     
842     public String JavaDoc endDisplayInstanceStatus(RequestContext ctx, HandlerContext handlerCtx) {
843         if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
844             return null;
845         }
846         ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
847         String JavaDoc content = dispEvent.getContent();
848         String JavaDoc instances = (String JavaDoc)handlerCtx.getInputValue("instances");
849         String JavaDoc lbName = (String JavaDoc)handlerCtx.getInputValue("lbName");
850         
851         String JavaDoc text = "";
852         String JavaDoc[] targets = null;
853         if (Util.isEmpty(instances)){
854             //this shouldn't happen. meaning nothing passed in.
855
}else{
856             //instances passed in will be in the form of name1@name2@name3, need to seperate it out
857
targets = instances.split("@");
858             
859             //the following line can be commented out when API is checked in.
860
//still have to figure out how to present the chart for more than 1 instance case.
861
//Map lbServerMonitorMap = LBConfigHelper.getInstanceAggregateStats(String names[0]) ;
862
}
863         if (targets != null && lbName != null) {
864             for (int i = 0; i < targets.length; i++) {
865                 if (i > 0)
866                     text += "<br />";
867                 
868                 String JavaDoc[] types= new String JavaDoc[]{"java.lang.String"};
869                 Object JavaDoc params[] = {targets[i]};
870                 String JavaDoc status = null;
871                 try {
872
873                     status = (String JavaDoc)MBeanUtil.invoke("amx:j2eeType=X-LoadBalancer,name="+lbName, "getStatus", params, types);
874                 } catch (Exception JavaDoc ex) {
875                    throw new FrameworkException("Error while getting instance: '"+lbName, ex, handlerCtx.getViewDescriptor(),
876                    handlerCtx.getView());
877                 }
878                 
879                 
880                 
881                 String JavaDoc tmp = content.replaceFirst(".TARGETVALUE.",
882                 targets[i]+": "+status);
883                 text += tmp.replaceAll(".TARGETVALUE.",
884                 targets[i]+": "+status);
885             }
886         }
887         
888         return text;
889     }
890     
891     public String JavaDoc endDisplayQuiesceTimeout(RequestContext ctx, HandlerContext handlerCtx) {
892         if (!(handlerCtx.getEvent() instanceof ChildContentDisplayEvent)) {
893             return null;
894         }
895         ChildContentDisplayEvent dispEvent = (ChildContentDisplayEvent)handlerCtx.getEvent();
896         String JavaDoc content = dispEvent.getContent();
897         String JavaDoc instances = (String JavaDoc)handlerCtx.getInputValue("instances");
898         String JavaDoc cluster = (String JavaDoc)handlerCtx.getInputValue("cluster");
899         String JavaDoc lbConfig = (String JavaDoc)handlerCtx.getInputValue("lbConfig");
900         String JavaDoc text = "";
901         String JavaDoc [] targets = null;
902         if (Util.isEmpty(instances)){
903             return "";
904         }else{
905             targets = instances.split("@");
906         }
907         
908         if(targets != null) {
909             for(int i = 0; i< targets.length; i++){
910                 if (i > 0)
911                     text += "<br />";
912                 String JavaDoc timeout = null;
913                 
914                 try {
915                     if(cluster != null) {
916                         timeout = (String JavaDoc)MBeanUtil.getAttribute("com.sun.appserv:type=server-ref,ref="+targets[i]+",cluster="+cluster+",category=config", "disable-timeout-in-minutes");
917                         
918                     } else {
919                         timeout = (String JavaDoc)MBeanUtil.getAttribute("com.sun.appserv:type=server-ref,ref="+targets[i]+",lb-config="+lbConfig+",category=config", "disable-timeout-in-minutes");
920                         
921                     }
922                 } catch (Exception JavaDoc ex) {
923                     throw new FrameworkException("Error while getting quiesce timeout: '"+targets[i], ex, handlerCtx.getViewDescriptor(),
924                     handlerCtx.getView());
925                 }
926                 String JavaDoc tmp = content.replaceFirst(".TARGETVALUE.",
927                 targets[i]+": "+timeout);
928                 text += tmp.replaceAll(".TARGETVALUE.",
929                 targets[i]+": "+timeout);
930                 
931             }
932             
933         }
934         return text;
935     }
936     
937     public void populateLbFilterMenu(RequestContext ctx, HandlerContext handlerCtx) {
938         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
939
String JavaDoc lbName = (String JavaDoc)handlerCtx.getInputValue("lbName");
940     if(lbName == null) {
941         throw new FrameworkException("populateFilterMenu: lbName not specified");
942     }
943         SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
944         OptionList optionList = new OptionList();
945         LBConfigHelper helper = new LBConfigHelper(AMXUtil.getDomainRoot());
946         String JavaDoc[] targets = helper.listTargets(lbName);
947         if (targets == null)
948             return;
949         OptionList dropDownMenuOptions = new OptionList(targets, targets); // label and values
950
dropDownChild.setOptions(dropDownMenuOptions);
951         if (targets.length > 0) {
952             dropDownChild.setValue(targets[0]);
953         }
954     }
955     
956    public void listTargets(RequestContext ctx, HandlerContext handlerCtx) {
957         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
958
String JavaDoc lbName = (String JavaDoc)handlerCtx.getInputValue("lbName");
959     if(lbName == null) {
960         throw new FrameworkException("listTargets: lbName not specified");
961     }
962         LBConfigHelper helper = new LBConfigHelper(AMXUtil.getDomainRoot());
963         String JavaDoc[] targets = helper.listTargets(lbName);
964         if (targets == null){
965             return;
966         }
967         for(int i = 0; i < targets.length; i++){
968         }
969         handlerCtx.setOutputValue("value", targets);
970         handlerCtx.setOutputValue("hasValue", "true");
971      
972     }
973    
974     
975     public void populateLbAppsFilterMenu(RequestContext ctx, HandlerContext handlerCtx) {
976         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
977
String JavaDoc lbName = (String JavaDoc)handlerCtx.getInputValue("lbName");
978         String JavaDoc target = (String JavaDoc)handlerCtx.getInputValue("target");
979         if(lbName == null) {
980             throw new FrameworkException("populateFilterAppsMenu: lbName not specified");
981         }
982         if(target == null) {
983             return;
984         }
985         SelectableGroup dropDownChild = (SelectableGroup) handlerCtx.getView();
986         OptionList optionList = new OptionList();
987         //context root is hard-coded-we are waiting for api(Harsha) to get context root
988
String JavaDoc[] targets = null;
989         boolean isCluster = true;
990         try {
991             targets = (String JavaDoc[])MBeanUtil.invoke("com.sun.appserv:type=cluster,name="+target+",category=config", "listApplicationReferencesAsString", null, null);
992         } catch (Exception JavaDoc ex) {
993             // ignore
994
isCluster = false;
995         }
996         if(!isCluster) {
997             try {
998                 targets = (String JavaDoc[])MBeanUtil.invoke("com.sun.appserv:type=server,name="+target+",category=config", "listApplicationReferencesAsString", null, null);
999             } catch (Exception JavaDoc ex) {
1000                // ignore
1001
isCluster = true;
1002            }
1003        }
1004        Vector JavaDoc ctxRootList = new Vector JavaDoc();
1005        for(int i = 0; i < targets.length; i++){
1006            String JavaDoc[] ctxRoot = null;
1007            try {
1008                ctxRoot = ApplicationConfigHelper.getAppContextRoots(DeploymentServiceUtils.getConfigContext(),targets[i]);
1009            } catch (Exception JavaDoc ex) {
1010               throw new FrameworkException(
1011                           "Error while getting context roots for '"+targets[i]+
1012                           "'!", ex, handlerCtx.getViewDescriptor(),
1013                           handlerCtx.getView());
1014            }
1015            if(ctxRoot != null){
1016                for(int j = 0; j < ctxRoot.length; j++){
1017                    ctxRootList.add(ctxRoot[j]);
1018                }
1019            }
1020            
1021        }
1022        String JavaDoc[] ctxroot = (String JavaDoc[])ctxRootList.toArray(new String JavaDoc[ctxRootList.size()]);
1023        OptionList dropDownMenuOptions = new OptionList(ctxroot, ctxroot); // label and values
1024
dropDownChild.setOptions(dropDownMenuOptions);
1025        if (ctxroot.length > 0) {
1026            dropDownChild.setValue(ctxroot[0]);
1027        }
1028    }
1029    
1030    
1031    public void loadInstanceStats(RequestContext ctx, HandlerContext handlerCtx){
1032        View view = handlerCtx.getView();
1033        ViewDescriptor desc = null;
1034        if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
1035            desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
1036        } else {
1037            DescriptorContainerView descView = (DescriptorContainerView)
1038            (((ViewBase)view).getParentViewBean());
1039            desc = descView.getViewDescriptor();
1040        }
1041        String JavaDoc lbName = (String JavaDoc)handlerCtx.getInputValue("lbName");
1042        if(lbName == null) {
1043            throw new FrameworkException("populateFilterMenu: lbName not specified");
1044        }
1045        String JavaDoc target = (String JavaDoc)handlerCtx.getInputValue("target");
1046        boolean allTargets = false;
1047        if(target == null) {
1048            allTargets = true;
1049        }
1050        CCActionTableModelInterface model =(CCActionTableModelInterface)handlerCtx.getInputValue("model");
1051        if (model == null) {
1052            throw new FrameworkException("loadInstanceStats: No Model Specified.",
1053            desc, handlerCtx.getView());
1054        }
1055        try {
1056            LBConfigHelper helper = new LBConfigHelper(AMXUtil.getDomainRoot());
1057            Map JavaDoc stats = helper.getInstanceStats(lbName, target, allTargets);
1058            if(stats == null)
1059                return;
1060            Set JavaDoc s = stats.keySet();
1061            Iterator JavaDoc iter = s.iterator();
1062           ((DefaultModel)model).clear();
1063            model.beforeFirst();
1064            //model.setRowSelectionType("multiple");
1065
while (iter.hasNext()) {
1066                Object JavaDoc key = iter.next();
1067                LoadBalancerServerStats oneRow = (LoadBalancerServerStats)stats.get(key);
1068                StringStatistic health = (StringStatistic)oneRow.getHealth();
1069                CountStatistic JavaDoc aReqs = (CountStatistic JavaDoc)oneRow.getNumberOfActiveRequests();
1070                CountStatistic JavaDoc tReqs = (CountStatistic JavaDoc)oneRow.getNumberOfActiveRequests();
1071                model.appendRow();
1072                model.setValue("target", key);
1073                model.setValue("health", health.getCurrent());
1074                model.setValue("activeReqs", aReqs.getCount());
1075                model.setValue("totalReqs", tReqs.getCount());
1076            }
1077        } catch (Exception JavaDoc ex) {
1078            // ignore
1079
return;
1080        }
1081        
1082    }
1083    
1084    public void loadAppStats(RequestContext ctx, HandlerContext handlerCtx){
1085        View view = handlerCtx.getView();
1086        ViewDescriptor desc = null;
1087        if (handlerCtx.getEvent() instanceof BeforeCreateEvent) {
1088            desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
1089        } else {
1090            DescriptorContainerView descView = (DescriptorContainerView)
1091            (((ViewBase)view).getParentViewBean());
1092            desc = descView.getViewDescriptor();
1093        }
1094        
1095        String JavaDoc lbName = (String JavaDoc)handlerCtx.getInputValue("lbName");
1096        String JavaDoc contextRoot = (String JavaDoc)handlerCtx.getInputValue("contextRoot");
1097        if(contextRoot != null && contextRoot.startsWith("/")) {
1098            String JavaDoc converted = contextRoot.substring(1, contextRoot.length());
1099            contextRoot = converted;
1100        }
1101        if(lbName == null) {
1102            throw new FrameworkException("loadAppStats: lbName not specified");
1103        }
1104        String JavaDoc target = (String JavaDoc)handlerCtx.getInputValue("target");
1105        boolean allTargets = false;
1106        if(target == null) {
1107            allTargets = true;
1108        }
1109        CCActionTableModelInterface model =(CCActionTableModelInterface)handlerCtx.getInputValue("model");
1110        if (model == null) {
1111            throw new FrameworkException("loadAppStats: No Model Specified.",
1112            desc, handlerCtx.getView());
1113        }
1114        try {
1115            LBConfigHelper helper = new LBConfigHelper(AMXUtil.getDomainRoot());
1116            Map JavaDoc stats = helper.getInstanceStats(lbName, contextRoot, target, allTargets);
1117            if(stats == null)
1118                return;
1119            Set JavaDoc s = stats.keySet();
1120            Iterator JavaDoc iter = s.iterator();
1121            ((DefaultModel)model).clear();
1122            model.beforeFirst();
1123            //model.setRowSelectionType("multiple");
1124
while (iter.hasNext()) {
1125                Object JavaDoc key = iter.next();
1126                LoadBalancerContextRootStats oneRow = (LoadBalancerContextRootStats)stats.get(key);
1127                TimeStatistic JavaDoc respTime = (TimeStatistic JavaDoc)oneRow.getResponseTime();
1128                CountStatistic JavaDoc avgRes = (CountStatistic JavaDoc)oneRow.getAverageResponseTime();
1129                CountStatistic JavaDoc failOvers = (CountStatistic JavaDoc)oneRow.getFailoverReqCount();
1130                CountStatistic JavaDoc errorPage = (CountStatistic JavaDoc)oneRow.getErrorRequestCount();
1131                CountStatistic JavaDoc url = (CountStatistic JavaDoc)oneRow.getIdempotentUrlAccessCount();
1132                CountStatistic JavaDoc activeReqs = (CountStatistic JavaDoc)oneRow.getActiveRequestCount();
1133                CountStatistic JavaDoc totalReqs = (CountStatistic JavaDoc)oneRow.getTotalRequestCount();
1134                model.appendRow();
1135                model.setValue("target", key);
1136                model.setValue("avgResponse", avgRes.getCount());
1137                model.setValue("failovers", failOvers.getCount());
1138                model.setValue("errorPage", errorPage.getCount());
1139                model.setValue("url", url.getCount());
1140                model.setValue("activeReqs", activeReqs.getCount());
1141                model.setValue("totalReqs", totalReqs.getCount());
1142                model.setValue("maxResponse", respTime.getMaxTime());
1143                model.setValue("minResponse", respTime.getMaxTime());
1144                //model.setValue(PROPERTY_VALUE, properties.get(key));
1145
}
1146        } catch (Exception JavaDoc ex) {
1147            // ignore
1148
return;
1149        }
1150        
1151        
1152    }
1153    
1154    public void deleteLoadBalancer(RequestContext ctx, HandlerContext handlerCtx) {
1155        View view = handlerCtx.getView();
1156        DescriptorContainerView descView = (DescriptorContainerView)(((ViewBase)view).getParentViewBean());
1157        ViewDescriptor vd = descView.getViewDescriptor();
1158        String JavaDoc childName = (String JavaDoc)handlerCtx.getInputValue("tableChildName");
1159        if(childName == null) {
1160            throw new FrameworkException("deleteHandler: childName not specified", vd, view);
1161        }
1162        
1163        ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName);
1164        if (tableDescriptor == null) {
1165            throw new FrameworkException("deleteHandler: tableDescriptor is null", vd, view);
1166        }
1167        if(!(tableDescriptor instanceof CCActionTableDescriptor)) {
1168            throw new FrameworkException("deleteHandler: tableDescriptor is of wrong type", tableDescriptor, view);
1169        }
1170        CCActionTableModelInterface model = ((CCActionTableDescriptor)tableDescriptor).getModel();
1171        
1172        String JavaDoc deleteKey = (String JavaDoc)handlerCtx.getInputValue("deleteKey");
1173        
1174        if (deleteKey == null) {
1175            throw new FrameworkException("No delete key specified", tableDescriptor, view);
1176        }
1177        model.setRowSelectionType("multiple");
1178        try {
1179            model.beforeFirst();
1180            // from the model, get the child that has the needed value...
1181
while(model.next()) {
1182                if (model.isRowSelected()) {
1183                    LBConfigHelper helper = new LBConfigHelper(AMXUtil.getDomainRoot());
1184                    helper.removeLoadbalancer(model.getValue(deleteKey).toString());
1185                    model.setRowSelected(false);
1186                }
1187            }
1188            ContainerViewBase containerView =
1189            (ContainerViewBase)(tableDescriptor.getView(ctx).getParent());
1190            containerView.removeChild(tableDescriptor.getName());
1191            ((DefaultModel)model).clear();
1192        } catch (Exception JavaDoc ex) {
1193            throw new FrameworkException("Error while deleting from: '"+
1194            tableDescriptor.getName()+"'", ex, tableDescriptor, view);
1195        }
1196
1197    }
1198    
1199            
1200    
1201        
1202    private static boolean isEmpty(String JavaDoc test) {
1203        return ((test == null) || "".equals(test));
1204    }
1205    
1206}
1207
Popular Tags