KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > helper > LBConfigHelper


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  * $Header: /cvs/glassfish/admin-core/mbeanapi/src/java/com/sun/appserv/management/helper/LBConfigHelper.java
26  * $Revision: 1.0
27  * $Date: 2006/03/09 20:30:27 $
28  */

29 package com.sun.appserv.management.helper;
30
31 import java.io.FileNotFoundException JavaDoc;
32 import java.io.FileOutputStream JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Collection JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.List JavaDoc;
39 import java.util.Map JavaDoc;
40 import java.util.ResourceBundle JavaDoc;
41 import java.util.Set JavaDoc;
42 import java.util.HashSet JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.logging.Level JavaDoc;
45 import java.util.logging.Logger JavaDoc;
46 import javax.management.MBeanException JavaDoc;
47
48 import com.sun.appserv.management.DomainRoot;
49 import com.sun.appserv.management.config.ServerRefConfig;
50 import com.sun.appserv.management.config.ClusterRefConfig;
51 import com.sun.appserv.management.config.LBConfig;
52 import com.sun.appserv.management.config.LoadBalancerConfig;
53 import com.sun.appserv.management.config.DomainConfig;
54 import com.sun.appserv.management.config.ClusterConfig;
55 import com.sun.appserv.management.config.StandaloneServerConfig;
56 import com.sun.appserv.management.config.ClusteredServerConfig;
57 import com.sun.appserv.management.config.DeployedItemRefConfig;
58 import com.sun.appserv.management.config.J2EEApplicationConfig;
59 import com.sun.appserv.management.config.LBConfigKeys;
60 import com.sun.appserv.management.config.ObjectTypeValues;
61 import com.sun.appserv.management.config.ServerConfig;
62 import com.sun.appserv.management.ext.lb.LoadBalancer;
63 import com.sun.appserv.management.monitor.LoadBalancerApplicationMonitor;
64 import com.sun.appserv.management.monitor.LoadBalancerClusterMonitor;
65 import com.sun.appserv.management.monitor.LoadBalancerContextRootMonitor;
66 import com.sun.appserv.management.monitor.LoadBalancerMonitor;
67 import com.sun.appserv.management.monitor.LoadBalancerServerMonitor;
68 import com.sun.appserv.management.monitor.MonitoringRoot;
69 import com.sun.appserv.management.monitor.statistics.LoadBalancerContextRootStats;
70 import com.sun.appserv.management.monitor.statistics.LoadBalancerServerStats;
71 import com.sun.appserv.management.util.misc.Formatter;
72 import com.sun.appserv.management.util.misc.StringSourceBase;
73
74 /**
75  * Helper class for simplifying load balancer administration.
76  * @since AppServer 9.0
77  */

78 public final class LBConfigHelper {
79     
80     /**
81      * Public constructor
82      */

83     public LBConfigHelper(final DomainRoot domainRoot) {
84         mDomainConfig = domainRoot.getDomainConfig();
85         mDomainRoot = domainRoot;
86         mLogger = Logger.getLogger(domainRoot.getMBeanLoggerName());
87         resBundle = ResourceBundle.getBundle(this.getClass().getPackage().getName()+".LocalStrings");
88         formatter = new Formatter(new StringSourceBase());
89     }
90     
91     /**
92      * Returns a filtered LBConfig list given the name of the server reference
93      * @return Map of items, keyed by name.
94      * @see com.sun.appserv.management.config.LBConfig
95      */

96     public List JavaDoc<LBConfig> getLBConfigsForServer(String JavaDoc serverName) {
97         Map JavaDoc<String JavaDoc,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
98         List JavaDoc<LBConfig> list = new ArrayList JavaDoc<LBConfig>();
99         for(LBConfig config:lbconfigs.values()){
100             Map JavaDoc<String JavaDoc,ServerRefConfig> map = config.getServerRefConfigMap();
101             for(String JavaDoc name:map.keySet()){
102                 if(name.equals(serverName)){
103                     list.add(config);
104                 }
105             }
106         }
107         return list;
108     }
109     
110     /**
111      * Returns a filtered LBConfig list given the name of the cluster reference
112      * @return Map of items, keyed by name.
113      * @see com.sun.appserv.management.config.LBConfig
114      */

115     public List JavaDoc<LBConfig> getLBConfigsForCluster(String JavaDoc clusterName) {
116         Map JavaDoc<String JavaDoc,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
117         List JavaDoc<LBConfig> list = new ArrayList JavaDoc<LBConfig>();
118         for(LBConfig config:lbconfigs.values()){
119             Map JavaDoc<String JavaDoc,ClusterRefConfig> map = config.getClusterRefConfigMap();
120             for(String JavaDoc name:map.keySet()){
121                 if(name.equals(clusterName)){
122                     list.add(config);
123                 }
124             }
125         }
126         return list;
127     }
128     
129     /**
130      * Returns a filtered list of server references given the name of the load
131      * balancer config.
132      * @return Map of items, keyed by name.
133      * @see com.sun.appserv.management.config.LBConfig
134      */

135     public Map JavaDoc<String JavaDoc, ServerRefConfig> getServersInLBConfig(String JavaDoc lbConfigName) {
136         Map JavaDoc<String JavaDoc,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
137         LBConfig lbconfig = lbconfigs.get(lbConfigName);
138         return lbconfig.getServerRefConfigMap();
139     }
140     
141     /**
142      * Returns a filtered list of cluster references given the name of the load
143      * balancer config.
144      * @return Map of items, keyed by name.
145      * @see com.sun.appserv.management.config.LBConfig
146      */

147     public Map JavaDoc<String JavaDoc, ClusterRefConfig> getClustersInLBConfig(String JavaDoc lbConfigName) {
148         Map JavaDoc<String JavaDoc,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
149         LBConfig lbconfig = lbconfigs.get(lbConfigName);
150         return lbconfig.getClusterRefConfigMap();
151     }
152     
153     /**
154      * Lists all the standalone server instances and clusters in the domain.
155      *
156      * @return all the standalone server instances and clusters in the domain
157      */

158     public String JavaDoc[] listTargets() {
159         Set JavaDoc<String JavaDoc> targetSet = new HashSet JavaDoc<String JavaDoc>();
160         
161         Map JavaDoc<String JavaDoc,ClusterConfig> cConfigMap =
162                 mDomainConfig.getClusterConfigMap();
163         
164         if (cConfigMap != null) {
165             targetSet.addAll( cConfigMap.keySet());
166         }
167         Map JavaDoc<String JavaDoc,StandaloneServerConfig> ssConfigMap =
168                 mDomainConfig.getStandaloneServerConfigMap();
169         
170         if (ssConfigMap != null) {
171             targetSet.addAll( ssConfigMap.keySet());
172         }
173         
174         String JavaDoc[] targetArr = new String JavaDoc[targetSet.size()];
175         return (String JavaDoc[]) targetSet.toArray(targetArr);
176     }
177     
178     /**
179      * Lists all the standalone server instances and clusters in the load
180      * balancer.
181      *
182      * @param lbName Name of the load balancer
183      *
184      * @return all the standalone server instances and clusters in the load
185      * balancer
186      */

187     public String JavaDoc[] listTargets(final String JavaDoc lbName) {
188         
189         Set JavaDoc<String JavaDoc> targetSet = new HashSet JavaDoc<String JavaDoc>();
190         
191         Map JavaDoc<String JavaDoc, LoadBalancerConfig> lbMap =
192                 mDomainConfig.getLoadBalancerConfigMap();
193         
194         if (lbMap == null) {
195             return null;
196         }
197         
198         LoadBalancerConfig lb = (LoadBalancerConfig) lbMap.get(lbName);
199         if (lb == null) {
200             return null;
201         }
202         
203         String JavaDoc lbConfigName = lb.getLbConfigName();
204         Map JavaDoc<String JavaDoc, LBConfig> lbConfigMap = mDomainConfig.getLBConfigMap();
205         if ((lbConfigMap == null) || (lbConfigName == null) ){
206             return null;
207         }
208         LBConfig lbConfig = (LBConfig) lbConfigMap.get(lbConfigName);
209         if (lbConfig == null) {
210             return null;
211         }
212         Map JavaDoc<String JavaDoc,ClusterRefConfig> cRefMap =
213                 lbConfig.getClusterRefConfigMap();
214         
215         if ( cRefMap != null) {
216             targetSet.addAll(cRefMap.keySet());
217         }
218         Map JavaDoc<String JavaDoc,ServerRefConfig> sRefMap =
219                     lbConfig.getServerRefConfigMap();
220          
221         if ( sRefMap != null) {
222             targetSet.addAll(sRefMap.keySet());
223         }
224         
225         String JavaDoc [] targetArr = new String JavaDoc[targetSet.size()];
226         
227         return (String JavaDoc[]) targetSet.toArray(targetArr);
228         
229     }
230     
231     /**
232      * Creates a load balancer element ( and the necessary config)
233      *
234      *
235      * @param loadbalancerName Name of the load balancer
236      * @param autoApplyEnabled Auto apply enabled or not
237      * @param targets Standalone server instances or clusters
238      * @param params This is optional, loadbalancer
239      * configuration elemements. The valid
240      * keys are:
241      * <ul>
242      * <li>{@link LBConfigKeys#RESPONSE_TIMEOUT_IN_SECONDS_KEY}</li>
243      * <li>{@link LBConfigKeys#HTTPS_ROUTING_KEY}</li>
244      * <li>{@link LBConfigKeys#RELOAD_POLL_INTERVAL_IN_SECONDS_KEY}</li>
245      * <li>{@link LBConfigKeys#MONITORING_ENABLED_KEY}</li>
246      * <li>{@link LBConfigKeys#ROUTE_COOKIE_ENABLED_KEY}</li>
247      * </ul>
248      *
249      * @return {@link LoadBalancerConfig}
250      */

251     public LoadBalancerConfig createLoadbalancer(String JavaDoc loadbalancerName,
252             boolean autoApplyEnabled, String JavaDoc[] targets, Map JavaDoc<String JavaDoc,String JavaDoc> params) {
253         
254         // first create the lb-config element
255

256         if ( loadbalancerName == null ) {
257             throw new IllegalArgumentException JavaDoc(
258                     "loadbalancerName can not be null");
259         }
260         
261         //iniitialize lb-config name that we are going to use for this lb
262
String JavaDoc lbConfigName = loadbalancerName + LB_CONFIG_SUFFIX;
263         
264         //the following block tries to get a unique lb-config name
265
//get all the lb-configs
266
Map JavaDoc<String JavaDoc,LBConfig> lbconfigMap = mDomainConfig.getLBConfigMap();
267         if(lbconfigMap != null){
268             //keep appending a counter till there is no lb-config by that name
269
for(int i=1;lbconfigMap.get(lbConfigName) != null;i++){
270                 lbConfigName = loadbalancerName + LB_CONFIG_SUFFIX + "_" + i;
271             }
272         }
273         
274         //create the lb-config
275
LBConfig lbConfig = mDomainConfig.createLBConfig(lbConfigName, params);
276         
277         if ( targets != null) {
278             for (int idx =0; idx < targets.length; idx++) {
279                 String JavaDoc targetName = targets[idx];
280                 
281                 if ( isCluster(targetName)) {
282                     lbConfig.createClusterRefConfig(targetName, null);
283                 } else if ( isStandaloneServer( targetName)) {
284                     lbConfig.createServerRefConfig(targetName, null);
285                 }
286             }
287         }
288         
289         // now create the load-balancer element
290
return mDomainConfig.createLoadBalancerConfig(loadbalancerName,
291                 lbConfigName, autoApplyEnabled, null);
292     }
293     
294     /**
295      * Deletes a load balancer element ( and the necessary config, if nobody
296      * else is using this config)
297      */

298     public void removeLoadbalancer(String JavaDoc loadbalancerName) {
299
300         //get the load balancers map
301
Map JavaDoc<String JavaDoc, LoadBalancerConfig> lbMap =
302                 mDomainConfig.getLoadBalancerConfigMap();
303         if ( lbMap == null) {
304             return;
305         }
306         
307         //first get the lbConfigName
308
LoadBalancerConfig loadbalancerConfig = lbMap.get(loadbalancerName);
309         if(loadbalancerConfig == null){
310             return;
311         }
312         String JavaDoc lbConfigName = loadbalancerConfig .getLbConfigName();
313         
314         // now remove load-balancer element
315
mDomainConfig.removeLoadBalancerConfig(loadbalancerName);
316
317         //get the load balancers map again
318
lbMap = mDomainConfig.getLoadBalancerConfigMap();
319         if ( lbMap == null) {
320             return;
321         }
322         
323         // now remove lb-config, if nobody is using it
324
for(LoadBalancerConfig lbConfig : lbMap.values()){
325             if ( lbConfig.getLbConfigName().equals(lbConfigName)) {
326                 // this load-balancer element is still using it, just return
327
// else continue to check other elements
328
return;
329             }
330         }
331         
332         // no load-balancer element is using this lb-config, remove it
333
mDomainConfig.removeLBConfig(lbConfigName);
334     }
335     
336     
337     /**
338      * Disables load balancing for a server with a quiescing period specififed
339      * by the timeout .
340      *
341      * @param target target server whose load balancing has to be disabled
342      * @param timeout quiescing time
343      */

344     public void disableServer(String JavaDoc target, int timeout) {
345         setServerStatus(target,timeout,false);
346     }
347     
348     /**
349      * Enables a server for load balancing.
350      *
351      * @param target target server whose load balancing has to be enabled
352      */

353     public void enableServer(String JavaDoc target) {
354         setServerStatus(target, 0,true);
355     }
356     
357     /**
358      * Disables load balancing for a particular application in a server instance
359      * with a quiescing period specififed by the timeout .
360      *
361      * @param target target server where the application has been deployed
362      * @param appName application name.
363      * @param timeout quiescing time
364      */

365     public void disableApplication(String JavaDoc target, String JavaDoc appName, int timeout) {
366         setApplicationStatus(target, appName, timeout, false);
367     }
368     
369     /**
370      * Enables load balancing for a particular application in a server instance
371      *
372      * @param target target server where the application has been deployed
373      * @param appName application name.
374      */

375     public void enableApplication(String JavaDoc target, String JavaDoc appName) {
376         setApplicationStatus(target, appName, 0, true);
377     }
378     
379     /**
380      * This is a convenience method to fetch the stats for server instance(s)
381      * which are either standalone or clustered or both
382      * @param targetLoadBalancer Load Balancer for which stats are to be
383      * returned
384      * @param target Target cluster name. This is used if
385      * allTargets (next param) is false.
386      * @param allTargets list Monitors for all targets.
387      *
388      * @return Map of LoadBalancerServerStats and the fully qualified names
389      * of the servers i.e. clustername.servername or servername
390      */

391     public Map JavaDoc<String JavaDoc, LoadBalancerServerStats> getInstanceStats(
392             final String JavaDoc targetLoadBalancer, final String JavaDoc target, boolean allTargets) {
393         
394         if ( targetLoadBalancer == null )
395             throw new IllegalArgumentException JavaDoc(
396                     "Load Balancer Name can not be null");
397         if ( !allTargets && target == null )
398             throw new IllegalArgumentException JavaDoc(
399                     "Specify AllTargets or atleast one target");
400         
401         Map JavaDoc<String JavaDoc,LoadBalancerServerStats>
402                 loadBalancerServerStatsMap = new HashMap JavaDoc<String JavaDoc,LoadBalancerServerStats>();
403         
404         Map JavaDoc<String JavaDoc, LoadBalancerServerMonitor> instanceMonitorMap =
405                 getInstanceMonitors(targetLoadBalancer, target, allTargets);
406         
407         for (String JavaDoc serverFQName : instanceMonitorMap.keySet()) {
408             LoadBalancerServerMonitor loadBalancerServerMonitor =
409                     instanceMonitorMap.get(serverFQName);
410             LoadBalancerServerStats loadBalancerServerStats =
411                     loadBalancerServerMonitor.getLoadBalancerServerStats();
412             loadBalancerServerStatsMap.put(serverFQName, loadBalancerServerStats);
413         }
414         return loadBalancerServerStatsMap;
415     }
416     
417     /**
418      * This is a convenience method to fetch the stats for context roots
419      * for an application.
420      * @param targetLoadBalancer Load Balancer for which stats are to be
421      * returned
422      * @param target Target cluster name. This is used if
423      * allTargets (next param) is false.
424      * @param allTargets list Monitors for all targets.
425      *
426      * @return Map of LoadBalancerContextRootStats and the fully qualified names
427      * of the servers i.e. clustername.servername or servername
428      */

429     public Map JavaDoc<String JavaDoc, LoadBalancerContextRootStats> getInstanceStats(
430             final String JavaDoc targetLoadBalancer, final String JavaDoc contextRoot,
431             final String JavaDoc target, boolean allTargets) {
432         
433         if ( contextRoot == null )
434             throw new IllegalArgumentException JavaDoc("ContextRoot can not be null");
435         if ( targetLoadBalancer == null )
436             throw new IllegalArgumentException JavaDoc(
437                     "Load Balancer Name can not be null");
438         if ( !allTargets && target == null )
439             throw new IllegalArgumentException JavaDoc(
440                     "Specify AllTargets or atleast one target");
441         
442         Map JavaDoc<String JavaDoc,LoadBalancerContextRootStats>
443                 loadBalancerContextRootStatsMap = new HashMap JavaDoc<String JavaDoc,LoadBalancerContextRootStats>();
444         
445         Map JavaDoc<String JavaDoc, LoadBalancerServerMonitor> instanceMonitorMap =
446                 getInstanceMonitors(targetLoadBalancer, target, allTargets);
447         
448         for (String JavaDoc serverFQName : instanceMonitorMap.keySet()) {
449             LoadBalancerServerMonitor loadBalancerServerMonitor =
450                     instanceMonitorMap.get(serverFQName);
451             Map JavaDoc<String JavaDoc, LoadBalancerApplicationMonitor>
452                     loadBalancerApplicationMonitorMap =
453                     loadBalancerServerMonitor.getLoadBalancerApplicationMonitorMap();
454             for (String JavaDoc appName : loadBalancerApplicationMonitorMap.keySet()) {
455                 LoadBalancerApplicationMonitor loadBalancerApplicationMonitor =
456                         loadBalancerApplicationMonitorMap.get(appName);
457                 Map JavaDoc<String JavaDoc, LoadBalancerContextRootMonitor>
458                         loadBalancerContextRootMonitorMap =
459                         loadBalancerApplicationMonitor.getLoadBalancerContextRootMonitorMap();
460                 LoadBalancerContextRootMonitor loadBalancerContextRootMonitor =
461                         loadBalancerContextRootMonitorMap.get(contextRoot);
462                 loadBalancerContextRootStatsMap.put(
463                         serverFQName, (LoadBalancerContextRootStats)loadBalancerContextRootMonitor.getStats());
464             }
465         }
466         return loadBalancerContextRootStatsMap;
467     }
468     
469     /**
470      * This method supports the configure-http-lb-config CLI command. It creates a lb-config, cluster-ref, health-checker by using
471      * the given parameters.
472      * @param configName the name for the lb-config element that will be created
473      * @param target cluster-ref or server-ref parameter of lb-config
474      * @param options Map of option name and option value. The valid options are
475      * responsetimeout response-timeout-in-seconds attribute of lb-config
476      * httpsrouting https-routing parameter of lb-config
477      * reloadinterval reload-poll-interval-in-seconds parameter of lb-config
478      * monitor monitoring-enabled parameter of lb-config
479      * routecookie route-cookie-enabled parameter of lb-config
480      * filepath the path to the file where loadbalancer.xml will be exported
481      * healthcheckerurl url attribute of health-checker
482      * healthcheckerinterval interval-in-seconds parameter of health-checker
483      * healthcheckertimeout timeout-in-seconds parameter of health-checker
484      * @param filePath the path to the file where loadbalancer.xml will be exported
485      * @return the path to the newly written file
486      * @since AS 9.0
487      * @throws javax.management.MBeanException exception indicating the original cause of problm
488      */

489     public String JavaDoc configureHTTPLBConfig(String JavaDoc configName, String JavaDoc target,
490             Map JavaDoc<String JavaDoc,String JavaDoc> options, String JavaDoc filePath) throws MBeanException JavaDoc {
491         
492         String JavaDoc healthCheckerUrl = options.get(HEALTH_CHECKER_URL);
493         String JavaDoc healthCheckerInterval = options.get(HEALTH_CHECKER_INTERVAL);
494         String JavaDoc healthCheckerTimeout = options.get(HEALTH_CHECKER_TIMEOUT);
495         String JavaDoc lbPolicy = options.get(LB_POLICY);
496         String JavaDoc lbPolicyModule = options.get(LB_POLICY_MODULE);
497         boolean isCluster = isCluster(target);
498         Map JavaDoc<String JavaDoc,String JavaDoc> params = getParams(options);
499         Map JavaDoc<String JavaDoc,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
500         if(lbconfigs.get(configName)!=null){
501                 String JavaDoc msg = formatter.format(resBundle.getString("LbConfigExists"),
502                         configName);
503                 throw new MBeanException JavaDoc(new RuntimeException JavaDoc(msg));
504         }
505         if(!isCluster){
506             if((lbPolicy!=null) || (lbPolicyModule!=null)){
507                 //throw exception
508
String JavaDoc msg = formatter.format(resBundle.getString("NotCluster"),
509                         target);
510                 throw new MBeanException JavaDoc(new RuntimeException JavaDoc(msg));
511             }
512         }
513         //create the lb-config
514
LBConfig lbConfig = mDomainConfig.createLBConfig(configName, params);
515         
516         if(isCluster){
517             
518             //create the cluster-ref
519
ClusterRefConfig clusterRefConfig = lbConfig.createClusterRefConfig(target, null,null);
520             if(lbPolicy!=null){
521                 clusterRefConfig.setLBPolicy(lbPolicy);
522             }
523             if(lbPolicyModule!=null){
524                 clusterRefConfig.setLBPolicyModule(lbPolicyModule);
525             }
526             //create the health checker
527
clusterRefConfig.createHealthCheckerConfig(healthCheckerUrl,
528                     healthCheckerInterval, healthCheckerTimeout);
529             //lb-enable all the instances in the cluster
530
enableServer(target);
531         }else{
532             //create the server-ref
533
ServerRefConfig serverRefConfig = lbConfig.createServerRefConfig(target,null,true,true);
534             //create the health checker
535
serverRefConfig.createHealthCheckerConfig(healthCheckerUrl,
536                     healthCheckerInterval, healthCheckerTimeout);
537         }
538         //lb-enable all applications in the cluster
539
enableAllApplications(target);
540         if(filePath!=null){
541             // create a load-balancer element so that we can get loadbalancer.xml
542
LoadBalancer lb = createLoadBalancer(configName);
543             //get the loadbalancer.xml
544
String JavaDoc lbxml = lb.getLoadBalancerXML();
545             mDomainConfig.removeLoadBalancerConfig(configName+LB_SUFFIX);
546             //write it to the file.
547
return writeToFile(lbxml, filePath);
548         }
549         return null;
550     }
551     
552     /**
553      * Configures the lb-weight attribute of each instance with the corresponding weight. Corresponds to the CLI
554      * command configure-lb-weight
555      * @param clusterName name of the cluster
556      * @param instanceVsWeights Map of instance name Vs weight
557      */

558     public void configureLBWeight(String JavaDoc clusterName, Map JavaDoc instanceVsWeights) {
559         
560         //get ALL clustered <server> elements
561
Map JavaDoc<String JavaDoc,ClusterConfig> clusterConfigMap = mDomainConfig.getClusterConfigMap();
562         //get the cluster config for the given cluster
563
ClusterConfig clusterConfig = clusterConfigMap.get(clusterName);
564         if(clusterConfig == null)
565             throw new IllegalArgumentException JavaDoc(formatter.format(resBundle.getString("InvalidCluster"),clusterName));
566         //get the map of clustered server config
567
Map JavaDoc<String JavaDoc,ClusteredServerConfig> clusteredServerConfigMap = clusterConfig.getClusteredServerConfigMap();
568         //iterate through all the given weights and instances
569
for(Object JavaDoc instance:instanceVsWeights.keySet()){
570             //get the corresponding clustered server config for this instance
571
ClusteredServerConfig clusteredServerConfig = clusteredServerConfigMap.get(instance);
572             if(clusteredServerConfig == null)
573                 throw new IllegalArgumentException JavaDoc(formatter.format(resBundle.getString("InvalidInstance"),instance,clusterName));
574             //set the lb-weight
575
clusteredServerConfig.setLBWeight( instanceVsWeights.get(instance).toString());
576         }
577     }
578
579     /**
580      * Enables all user applications in the given target
581      * @param target The target for which all the applications have to be enabled
582      */

583     public void enableAllApplications(String JavaDoc target){
584         //get the server config for this target
585
Map JavaDoc<String JavaDoc,ServerConfig> serverConfigMap = mDomainConfig.getServerConfigMap();
586         ServerConfig serverConfig = serverConfigMap.get(target);
587         if(serverConfig != null){
588             //get all the deployed item config
589
Map JavaDoc<String JavaDoc,DeployedItemRefConfig> deployedItemRefConfigMap = serverConfig.getDeployedItemRefConfigMap();
590             //iterate through all the deployed items
591
for (DeployedItemRefConfig deployedItemRefConfig : deployedItemRefConfigMap.values()){
592                 //get the deployed app
593
J2EEApplicationConfig app = mDomainConfig.getJ2EEApplicationConfigMap().get(deployedItemRefConfig.getName());
594                 if(app == null) {
595                     continue;
596                 }
597                 //if the type is user, then only set the lb-enabled to true
598
if(app.getObjectType().equals(ObjectTypeValues.USER)) {
599                     deployedItemRefConfig.setLBEnabled(true);
600                 }
601             }
602         }
603     }
604
605     // PRIVATE METHODS
606

607     boolean isCluster(String JavaDoc name) {
608         Map JavaDoc<String JavaDoc,ClusterConfig> cConfigMap =
609                 mDomainConfig.getClusterConfigMap();
610         
611         if (cConfigMap == null) {
612             return false;
613         }
614         ClusterConfig cConfig = (ClusterConfig) cConfigMap.get(name);
615         if ( cConfig == null) {
616             return false;
617         } else {
618             return true;
619         }
620     }
621     
622     boolean isStandaloneServer(String JavaDoc name) {
623         Map JavaDoc<String JavaDoc,StandaloneServerConfig> ssConfigMap =
624                 mDomainConfig.getStandaloneServerConfigMap();
625         
626         if (ssConfigMap == null) {
627             return false;
628         }
629         StandaloneServerConfig ssConfig = (StandaloneServerConfig)
630         ssConfigMap.get(name);
631         if ( ssConfig == null) {
632             return false;
633         } else {
634             return true;
635         }
636     }
637     
638     /**
639      * sets the lb-enabled flag for the target, also sets the disable-timeout-in-minutes
640      * if the status flag is false.
641      * @param target the cluster or the server for which the lb-enabled has to be set
642      * @param timeout The disable-timeout-in-minutes if the server has to be disabled
643      * @param status true to enable, false to disable the server
644      */

645     private void setServerStatus(String JavaDoc target, int timeout, boolean status) {
646         //timeout has to be specified for disable operation
647
if (timeout < 0 && !status) {
648             String JavaDoc msg = resBundle.getString("InvalidNumber");
649             throw new IllegalArgumentException JavaDoc(msg);
650         }
651         
652         try {
653             // disables cluster if target is a cluster
654
if (isCluster(target)) {
655                 //get the cluster config
656
ClusterConfig cRef = mDomainConfig.getClusterConfigMap().get(target);
657                 if (cRef == null) {
658                     mLogger.log(Level.FINEST," server " + target +
659                             " does not exist in any cluster in the domain");
660                     String JavaDoc msg = formatter.format(resBundle.getString("ServerNotDefined"),
661                             target);
662                     throw new MBeanException JavaDoc(new RuntimeException JavaDoc(msg));
663                 }
664
665                 //iterate through all the servers in the cluster
666
for(ServerRefConfig sRef : cRef.getServerRefConfigMap().values()){
667                     //set lb-enabled flag and the timeout with error checks
668
setLBEnabled(sRef, status, timeout, target);
669                 }
670             } else { // target is a server
671
ServerRefConfig sRef = null;
672                 boolean foundTarget = false;
673                 //get all the lb-configs
674
Map JavaDoc<String JavaDoc,LBConfig> lbConfigs = mDomainConfig.getLBConfigMap();
675                 //iterate through lb-configs
676
for(LBConfig lbConfig : lbConfigs.values()){
677                     //get the server-ref in this lb-config
678
Map JavaDoc<String JavaDoc,ServerRefConfig> serverRefs = lbConfig.getServerRefConfigMap();
679                     //get the server-ref for this target
680
sRef = serverRefs.get(target);
681                     if (sRef == null) {
682                         mLogger.log(Level.FINEST," server " + target +
683                                 " does not exist in " + serverRefs);
684                     } else {
685                         foundTarget = true;
686                         break;
687                     }
688                 }
689                 // did not find server target
690
if (!foundTarget) {
691                     //get the server-ref from some some cluster
692
sRef = getServerRefConfigFromCluster(target);
693                     if (sRef == null) {
694                         mLogger.log(Level.FINEST," server " + target +
695                                 " does not exist in any cluster in the domain");
696                         String JavaDoc msg = formatter.format(resBundle.getString("ServerNotDefined"),
697                                             target);
698                         throw new MBeanException JavaDoc(new RuntimeException JavaDoc(msg));
699                     }
700                 }
701                 //set the lb-enabled flag
702
setLBEnabled(sRef, status, timeout, target);
703             }
704             
705         } catch(Exception JavaDoc ce) {
706             ce.printStackTrace();
707             throw new RuntimeException JavaDoc(ce);
708         }
709         
710     }
711
712     /**
713      * sets the lb-enabled flag for the target
714      * @param sRef server-ref class
715      * @param status the enable status
716      * @param timeout disable timeout
717      * @param target the target cluster or server
718      * @throws javax.management.MBeanException wrapper for all exceptions
719      */

720     private void setLBEnabled(final ServerRefConfig sRef, final boolean status,
721             final int timeout, final String JavaDoc target) throws MBeanException JavaDoc {
722         int curTout = sRef.getDisableTimeoutInMinutes();
723         //check if it is already in the state desired
724
boolean enabled = sRef.getLBEnabled();
725         if(!status){
726             if ((enabled == false) && (curTout == timeout)) {
727                         String JavaDoc msg = formatter.format(resBundle.getString("ServerDisabled"),
728                                 sRef.getRef());
729                         throw new MBeanException JavaDoc(new Exception JavaDoc(msg));
730             }
731             //set the disable timeout in minutes
732
sRef.setDisableTimeoutInMinutes(timeout);
733             //set the lb-enabled to false
734
sRef.setLBEnabled(false);
735             mLogger.log(Level.INFO,formatter.format(resBundle.getString(
736                     "http_lb_admin.ServerDisabled"), target));
737         }else{
738             if (enabled == true) {
739                         String JavaDoc msg = formatter.format(resBundle.getString("ServerEnabled"),
740                                 sRef.getRef());
741                 throw new MBeanException JavaDoc(new Exception JavaDoc("ServerEnabled"));
742             }
743             sRef.setLBEnabled(true);
744             mLogger.log(Level.INFO,formatter.format(resBundle.getString(
745                     "http_lb_admin.ServerEnabled"), target));
746         }
747     }
748     
749     /**
750      * sets the lb-enabled flag to the value of status for the given target
751      * if status is false also sets the disable-timeout-in-minutes for the application
752      * @param target server or cluster target
753      * @param appName application name
754      * @param timeout disable timeout in minutes
755      * @param status enable status
756      */

757     private void setApplicationStatus(String JavaDoc target, String JavaDoc appName,int timeout, boolean status){
758         
759         //disable timeout is required for disable operation
760
if (timeout < 0 && !status) {
761             String JavaDoc msg = resBundle.getString("InvalidNumber");
762             throw new IllegalArgumentException JavaDoc(msg);
763         }
764         
765         try {
766             DeployedItemRefConfig dRef = null;
767             // disables cluster if target is a cluster
768
if (isCluster(target)) {
769                 //get the clusterConfig for this cluster
770
Map JavaDoc<String JavaDoc,ClusterConfig> clusterConfigs = mDomainConfig.getClusterConfigMap();
771                 ClusterConfig clusterConfig = clusterConfigs.get(target);
772                 //get the deployed item object corresponding to the given appName
773
dRef = clusterConfig.getDeployedItemRefConfigMap().get(appName);
774             } else { // target is a server
775
//get the standalone serverConfig
776
Map JavaDoc<String JavaDoc,StandaloneServerConfig> ssConfigMap =
777                         mDomainConfig.getStandaloneServerConfigMap();
778                 StandaloneServerConfig ssc = ssConfigMap.get(target);
779                 if (ssc == null) {
780                     //get the clustered server config
781
ClusteredServerConfig s = mDomainConfig.getClusteredServerConfigMap().get(target);
782                     //get the deployed item object corresponding to the given appName
783
dRef = s.getDeployedItemRefConfigMap().get(appName);
784                 }else{
785                     //get the deployed item object corresponding to the given appName
786
dRef = ssc.getDeployedItemRefConfigMap().get(appName);
787                 }
788             }
789             if (dRef == null) {
790                 mLogger.log(Level.FINEST," server " + target +
791                         " does not exist in any cluster in the domain");
792                 String JavaDoc msg = formatter.format(resBundle.getString("AppRefNotDefined"),
793                         target);
794                 throw new MBeanException JavaDoc(new RuntimeException JavaDoc(msg));
795             }
796             int curTout = Integer.parseInt(
797                     dRef.getDisableTimeoutInMinutes());
798             //check if the app is already in the state desired
799
boolean enabled = dRef.getLBEnabled();
800             if(!status){
801                 if ((enabled == false) && (curTout == timeout)) {
802                     String JavaDoc msg = resBundle.getString("AppDisabledOnServer"
803                             );
804                     throw new MBeanException JavaDoc(new Exception JavaDoc(msg));
805                 }
806                 //set the disable timeout
807
dRef.setDisableTimeoutInMinutes( "" + timeout );
808                 //disable the app
809
dRef.setLBEnabled(false);
810                 mLogger.log(Level.INFO,resBundle.getString(
811                         "http_lb_admin.ApplicationDisabled"));
812             }else{
813                 if (enabled == true) {
814                     String JavaDoc msg = resBundle.getString("AppEnabledOnServer"
815                             );
816                     throw new MBeanException JavaDoc(new Exception JavaDoc(msg));
817                 }
818                 //enable the app
819
dRef.setLBEnabled(true);
820                 mLogger.log(Level.INFO,resBundle.getString(
821                         "http_lb_admin.ApplicationEnabled"));
822             }
823         } catch(Exception JavaDoc ce) {
824             throw new RuntimeException JavaDoc(ce);
825         }
826         
827     }
828     
829     /**
830      * returns the server-ref elements corresponding to the target
831      * by searching all the cluster-ref elements.
832      * @param target target server or cluster
833      * @return ServerRefConfig the class that refers to the server-ref obtained by searching through all the clusters
834      * @throws javax.management.MBeanException wrapper for all the exceptions
835      */

836     private ServerRefConfig getServerRefConfigFromCluster(String JavaDoc target)
837     throws MBeanException JavaDoc {
838         // check if this server is part of cluster, then
839
// turn on lb-enable flag in the cluster.
840
//get all the lb-configs
841
Map JavaDoc<String JavaDoc,LBConfig> lbConfigs = mDomainConfig.getLBConfigMap();
842         //iterate through all the lb-configs
843
for(LBConfig lbConfig : lbConfigs.values()){
844             //get the cluster-refs in this lb-config
845
Map JavaDoc<String JavaDoc,ClusterRefConfig> clusterRefs = lbConfig.getClusterRefConfigMap();
846             //iterate through all the cluster-refs
847
for(ClusterRefConfig clusterRef :clusterRefs.values()){
848                 
849                 //get the cluster name
850
String JavaDoc clusterName = clusterRef.getReferencedClusterName();
851                 
852                 //get the clusterConfig for this clustername
853
Map JavaDoc<String JavaDoc,ClusterConfig> clusterConfigs = mDomainConfig.getClusterConfigMap();
854                 ClusterConfig config = clusterConfigs.get(clusterName);
855                 
856                 //get all the server-refs for this cluster
857
Map JavaDoc<String JavaDoc,ServerRefConfig> serverRefConfigs = config.getServerRefConfigMap();
858                 
859                 //iterate through the server-refs
860
for(ServerRefConfig serverRefConfig : serverRefConfigs.values() ){
861                     
862                     //if this server-ref matches the given target , return it
863
if(serverRefConfig.getName().equals(target)){
864                         return serverRefConfig;
865                     }
866                     
867                 }
868             }
869         }
870         return null;
871     }
872
873     /**
874      * Gets the Maps of LoadBalancerServerMonitor for specified load balancer and
875      * specified target(s).
876      *
877      * @param targetLoadBalancer Load Balancer for which Monitors are to be
878      * returned
879      * @param target Target cluster name. This is used if
880      * allTargets (next param) is false.
881      * @param allTargets list Monitors for all targets.
882      *
883      * @return Map of LoadBalancerServerMonitors and their names
884      */

885     public Map JavaDoc<String JavaDoc, LoadBalancerServerMonitor> getInstanceMonitors(
886         final String JavaDoc targetLoadBalancer, final String JavaDoc target, boolean allTargets) {
887
888         Map JavaDoc<String JavaDoc,LoadBalancerServerMonitor>
889         loadBalancerServerMonitorMap = new HashMap JavaDoc<String JavaDoc,LoadBalancerServerMonitor>();
890     
891         MonitoringRoot mRoot = mDomainRoot.getMonitoringRoot();
892         Map JavaDoc<String JavaDoc, LoadBalancerMonitor> loadBalancerMonitorMap =
893                 mRoot.getLoadBalancerMonitorMap();
894         LoadBalancerMonitor loadBalancerMonitor =
895                 loadBalancerMonitorMap.get(targetLoadBalancer);
896         
897         Map JavaDoc<String JavaDoc, LoadBalancerClusterMonitor> loadBalancerClusterMonitorMap =
898                 loadBalancerMonitor.getLoadBalancerClusterMonitorMap();
899         if (!allTargets) {
900             LoadBalancerClusterMonitor loadBalancerClusterMonitor =
901                 loadBalancerClusterMonitorMap.get(target);
902             populateLoadBalancerServerMonitorMap(target,
903                 loadBalancerServerMonitorMap, loadBalancerClusterMonitor);
904         } else {
905             for (String JavaDoc clusterName : loadBalancerClusterMonitorMap.keySet()) {
906                 LoadBalancerClusterMonitor loadBalancerClusterMonitor =
907                     loadBalancerClusterMonitorMap.get(clusterName);
908                 populateLoadBalancerServerMonitorMap(target,
909                     loadBalancerServerMonitorMap, loadBalancerClusterMonitor);
910             }
911         }
912         return loadBalancerServerMonitorMap;
913     }
914
915     /**
916      * Returns the stats for an instance. If the instance is being load
917      * balanced by multiple load balancers the a map of stats keyed by
918      * load balancer name is returned
919      *
920      * @param serverName instance name
921      *
922      * @return Map of LoadBalancerServerMonitor keyed by load balancer name
923      */

924     public Map JavaDoc<String JavaDoc, LoadBalancerServerMonitor>
925         getInstanceAggregateStats(String JavaDoc serverName) {
926         
927         Collection JavaDoc<LoadBalancerConfig> loadBalancers =
928             getLoadBalancers(serverName, false).values();
929
930         Map JavaDoc<String JavaDoc,LoadBalancerServerMonitor>
931             loadBalancerServerMonitorMap = new HashMap JavaDoc<String JavaDoc,LoadBalancerServerMonitor>();
932
933         MonitoringRoot mRoot = mDomainRoot.getMonitoringRoot();
934         Map JavaDoc<String JavaDoc, LoadBalancerMonitor> loadBalancerMonitorMap =
935             mRoot.getLoadBalancerMonitorMap();
936         
937         for (LoadBalancerConfig loadBalancer : loadBalancers) {
938             String JavaDoc targetLoadBalancer = loadBalancer.getName();
939             LoadBalancerMonitor loadBalancerMonitor =
940                 loadBalancerMonitorMap.get(targetLoadBalancer);
941         
942             Map JavaDoc<String JavaDoc, LoadBalancerClusterMonitor> loadBalancerClusterMonitorMap =
943                 loadBalancerMonitor.getLoadBalancerClusterMonitorMap();
944             for (String JavaDoc clusterName : loadBalancerClusterMonitorMap.keySet()) {
945                 LoadBalancerClusterMonitor loadBalancerClusterMonitor =
946                     loadBalancerClusterMonitorMap.get(clusterName);
947                 LoadBalancerServerMonitor loadBalancerServerMonitor =
948                     loadBalancerClusterMonitor.getLoadBalancerServerMonitorMap()
949                     .get(serverName);
950                 loadBalancerServerMonitorMap.put(
951                     targetLoadBalancer, loadBalancerServerMonitor);
952             }
953         }
954         return loadBalancerServerMonitorMap;
955     }
956     
957     /**
958      * Returns the load balancers loadbalancing a target :
959      * standalone instance, clustered instance or a cluster
960      *
961      * @param targetName standalone instance name or
962      * clustered instance name or a cluster name
963      * @param isCluster whether the targetName is a cluster or instance name
964      *
965      * @return Map of LoadBalancerConfig keyed by load balancer name
966      */

967     public Map JavaDoc<String JavaDoc,LoadBalancerConfig> getLoadBalancers(
968         String JavaDoc targetName, boolean isCluster) {
969         Map JavaDoc<String JavaDoc, LBConfig> lbConfigMap = fetchLBConfigs(targetName, isCluster);
970         return fetchLoadBalancerConfigs(lbConfigMap);
971     }
972     
973     private Map JavaDoc<String JavaDoc, LBConfig> fetchLBConfigs(
974         String JavaDoc targetName, boolean isCluster) {
975
976         Map JavaDoc<String JavaDoc,LBConfig> result = new HashMap JavaDoc<String JavaDoc,LBConfig>();
977         Map JavaDoc<String JavaDoc,LBConfig> lbConfigMap = mDomainConfig.getLBConfigMap();
978         
979         if (isCluster) {
980             for (String JavaDoc lbConfigName : lbConfigMap.keySet()) {
981                 LBConfig lbConfig = lbConfigMap.get(lbConfigName);
982                 Map JavaDoc<String JavaDoc,ClusterRefConfig> lbClusterRefConfigMap =
983                     lbConfig.getClusterRefConfigMap();
984                 for (String JavaDoc clusterRef : lbClusterRefConfigMap.keySet()) {
985                     if (clusterRef.equals(targetName)) {
986                         result.put(lbConfigName, lbConfig);
987                         break;
988                     }
989                 }
990             }
991         } else if (isStandaloneServer(targetName)) {
992          /*its a serverName which means you have to find LBConfigs containing
993          1. standalone server references with the same name
994          2. clustered server references with the same name */

995             for (String JavaDoc lbConfigName : lbConfigMap.keySet()) {
996                 LBConfig lbConfig = lbConfigMap.get(lbConfigName);
997                 Map JavaDoc<String JavaDoc,ServerRefConfig> lbServerRefConfigMap =
998                     lbConfig.getServerRefConfigMap();
999                 for (String JavaDoc serverRef : lbServerRefConfigMap.keySet()) {
1000                    if (serverRef.equals(targetName)) {
1001                        result.put(lbConfigName, lbConfig);
1002                        break;
1003                    }
1004                }
1005            }
1006        } else {//we assume that its a clustered instance name
1007
for (String JavaDoc lbConfigName : lbConfigMap.keySet()) {
1008                LBConfig lbConfig = lbConfigMap.get(lbConfigName);
1009                Map JavaDoc<String JavaDoc,ClusterRefConfig> lbClusterRefConfigMap =
1010                    lbConfig.getClusterRefConfigMap();
1011                Map JavaDoc<String JavaDoc,ClusterConfig> clusterConfigMap =
1012                    mDomainConfig.getClusterConfigMap();
1013                Map JavaDoc<String JavaDoc,ClusterConfig> relevantClusterConfigMap = new HashMap JavaDoc<String JavaDoc,ClusterConfig>();
1014                for (String JavaDoc clusterRef : lbClusterRefConfigMap.keySet())
1015                    relevantClusterConfigMap.put(clusterRef,
1016                        clusterConfigMap.get(clusterRef));
1017                //so now we have the right set of <cluster> elements
1018
for (String JavaDoc clusterName : relevantClusterConfigMap.keySet()) {
1019                    ClusterConfig clusterConfig =
1020                        relevantClusterConfigMap.get(clusterName);
1021                    Map JavaDoc<String JavaDoc,ServerRefConfig> clusteredServerRefConfigMap =
1022                        clusterConfig.getServerRefConfigMap();
1023                    for (String JavaDoc serverRef : clusteredServerRefConfigMap.keySet()) {
1024                        if (serverRef.equals(targetName)) {
1025                            result.put(lbConfigName, lbConfig);
1026                            break;
1027                        }
1028                    }
1029                }
1030            }
1031        }
1032        return result;
1033    }
1034    
1035    private Map JavaDoc<String JavaDoc,LoadBalancerConfig> fetchLoadBalancerConfigs(
1036        Map JavaDoc<String JavaDoc, LBConfig> lbConfigMap) {
1037
1038        Map JavaDoc<String JavaDoc,LoadBalancerConfig> relevantLoadBalancerConfigMap = new HashMap JavaDoc<String JavaDoc,LoadBalancerConfig>();
1039
1040        for (String JavaDoc lbConfigName : lbConfigMap.keySet()) {
1041            //collect all load-balancer elements which refer to this lb-config
1042
Map JavaDoc<String JavaDoc,LoadBalancerConfig> allLoadBalancerConfigMap =
1043                 mDomainRoot.getDomainConfig().getLoadBalancerConfigMap();
1044
1045            for (String JavaDoc loadBalancerName : allLoadBalancerConfigMap.keySet()) {
1046                LoadBalancerConfig loadBalancerConfig =
1047                    allLoadBalancerConfigMap.get(loadBalancerName);
1048                if (loadBalancerConfig.getLbConfigName().equals(lbConfigName))
1049                    relevantLoadBalancerConfigMap.put(
1050                        loadBalancerName, loadBalancerConfig);
1051            }
1052        }
1053        return relevantLoadBalancerConfigMap;
1054    }
1055    
1056    private void populateLoadBalancerServerMonitorMap(String JavaDoc target,
1057        Map JavaDoc<String JavaDoc, LoadBalancerServerMonitor> loadBalancerServerMonitorMap,
1058        LoadBalancerClusterMonitor loadBalancerClusterMonitor) {
1059        
1060        Map JavaDoc<String JavaDoc, LoadBalancerServerMonitor> tmpLoadBalancerServerMonitorMap =
1061                loadBalancerClusterMonitor.getLoadBalancerServerMonitorMap();
1062        for (String JavaDoc serverName : tmpLoadBalancerServerMonitorMap.keySet()) {
1063            LoadBalancerServerMonitor loadBalancerServerMonitor =
1064                    tmpLoadBalancerServerMonitorMap.get(serverName);
1065            if (isStandaloneServer(serverName))
1066                loadBalancerServerMonitorMap.put(
1067                        serverName, loadBalancerServerMonitor);
1068            else loadBalancerServerMonitorMap.put(
1069                    loadBalancerClusterMonitor.getName() + "." + target,
1070                    loadBalancerServerMonitor);
1071        }
1072    }
1073    
1074    private LoadBalancer createLoadBalancer(final String JavaDoc configName) {
1075        mDomainConfig.createLoadBalancerConfig(
1076            configName+LB_SUFFIX, configName, false, null);
1077        Map JavaDoc<String JavaDoc,LoadBalancer> lbs = mDomainRoot.getLoadBalancerMap();
1078        LoadBalancer lb = lbs.get(configName+LB_SUFFIX);
1079        return lb;
1080    }
1081    
1082    /**
1083     * creates a map of the parameters
1084     */

1085    private Map JavaDoc<String JavaDoc,String JavaDoc> getParams(Map JavaDoc<String JavaDoc,String JavaDoc> options) {
1086        
1087        Map JavaDoc<String JavaDoc,String JavaDoc> params = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
1088        params.put(LBConfigKeys.HTTPS_ROUTING_KEY,options.get(HTTPS_ROUTING));
1089        params.put(LBConfigKeys.MONITORING_ENABLED_KEY,options.get(MONITOR));
1090        params.put(LBConfigKeys.RELOAD_POLL_INTERVAL_IN_SECONDS_KEY, options.get(RELOAD_INTERVAL));
1091        params.put(LBConfigKeys.RESPONSE_TIMEOUT_IN_SECONDS_KEY, options.get(RESPONSE_TIMEOUT));
1092        params.put(LBConfigKeys.ROUTE_COOKIE_ENABLED_KEY, options.get(ROUTE_COOKIE));
1093        return params;
1094    }
1095    
1096    /**
1097     * writes the String lbxml to the file given by filePath
1098     */

1099    private String JavaDoc writeToFile(final String JavaDoc lbxml, final String JavaDoc filePath) {
1100        FileOutputStream JavaDoc fo = null;
1101        try{
1102            fo = new FileOutputStream JavaDoc(filePath);
1103            fo.write(lbxml.getBytes());
1104        }catch(IOException JavaDoc ioe){
1105            ioe.printStackTrace();
1106        }finally{
1107            try{
1108                fo.close();
1109            }catch(IOException JavaDoc e){}
1110        }
1111        
1112        return filePath;
1113    }
1114    
1115    // PRIVATE VARIABLES
1116
DomainConfig mDomainConfig = null;
1117    
1118    DomainRoot mDomainRoot = null;
1119    
1120    static final String JavaDoc LB_CONFIG_SUFFIX = "_LB_CONFIG";
1121    
1122    static final String JavaDoc LB_SUFFIX = "-lb-temp";
1123    
1124    Logger JavaDoc mLogger = null;
1125    
1126    ResourceBundle JavaDoc resBundle = null;
1127    
1128    Formatter formatter = null;
1129    
1130    public static final String JavaDoc RESPONSE_TIMEOUT = "responsetimeout";
1131    public static final String JavaDoc HTTPS_ROUTING = "httpsrouting";
1132    public static final String JavaDoc RELOAD_INTERVAL = "reloadinterval";
1133    public static final String JavaDoc MONITOR = "monitor";
1134    public static final String JavaDoc ROUTE_COOKIE = "routecookie";
1135    public static final String JavaDoc HEALTH_CHECKER_URL = "healthcheckerurl";
1136    public static final String JavaDoc HEALTH_CHECKER_TIMEOUT = "healthcheckertimeout";
1137    public static final String JavaDoc HEALTH_CHECKER_INTERVAL = "healthcheckerinterval";
1138    public static final String JavaDoc TARGET = "target";
1139    public static final String JavaDoc CONFIG = "config";
1140    public static final String JavaDoc LB_POLICY = "lbpolicy";
1141    public static final String JavaDoc LB_POLICY_MODULE = "lbpolicymodule";
1142    
1143}
1144
1145
1146
1147
Popular Tags