LBConfigHelperpublic final class LBConfigHelper extends Object Helper class for simplifying load balancer administration. |
Fields Summary |
---|
private final com.sun.appserv.management.config.DomainConfig | mDomainConfig | private final com.sun.appserv.management.DomainRoot | mDomainRoot | private static final String | LB_CONFIG_SUFFIX | private static final String | LB_SUFFIX | private final Logger | mLogger | private final ResourceBundle | resBundle | private com.sun.appserv.management.util.misc.Formatter | formatter | public static final String | RESPONSE_TIMEOUT | public static final String | HTTPS_ROUTING | public static final String | RELOAD_INTERVAL | public static final String | MONITOR | public static final String | ROUTE_COOKIE | public static final String | HEALTH_CHECKER_URL | public static final String | HEALTH_CHECKER_TIMEOUT | public static final String | HEALTH_CHECKER_INTERVAL | public static final String | TARGET | public static final String | CONFIG | public static final String | LB_POLICY | public static final String | LB_POLICY_MODULE | public static final String | AUTO_APPLY_ENABLED | public static final String | LB_ENABLE_ALL_INSTANCES | public static final String | LB_ENABLE_ALL_APPLICATIONS | public static final String | LB_WEIGHT |
Constructors Summary |
---|
public LBConfigHelper(com.sun.appserv.management.DomainRoot domainRoot)Public constructor
mDomainConfig = domainRoot.getDomainConfig();
mDomainRoot = domainRoot;
mLogger = Logger.getLogger(domainRoot.getMBeanLoggerName());
resBundle = ResourceBundle.getBundle(this.getClass().getPackage().getName()+".LocalStrings");
formatter = new Formatter(new StringSourceBase());
|
Methods Summary |
---|
public void | configureLBWeight(java.lang.String clusterName, java.util.Map instanceVsWeights)Configures the lb-weight attribute of each instance with the corresponding weight. Corresponds to the CLI
command configure-lb-weight
//get ALL clustered <server> elements
Map<String,ClusterConfig> clusterConfigMap = mDomainConfig.getClusterConfigMap();
//get the cluster config for the given cluster
ClusterConfig clusterConfig = clusterConfigMap.get(clusterName);
if(clusterConfig == null)
throw new IllegalArgumentException(formatter.format(resBundle.getString("InvalidCluster"),clusterName));
//get the map of clustered server config
Map<String,ClusteredServerConfig> clusteredServerConfigMap = clusterConfig.getClusteredServerConfigMap();
//iterate through all the given weights and instances
for(Object instance:instanceVsWeights.keySet()){
//get the corresponding clustered server config for this instance
ClusteredServerConfig clusteredServerConfig = clusteredServerConfigMap.get(instance);
if(clusteredServerConfig == null)
throw new IllegalArgumentException(formatter.format(resBundle.getString("InvalidInstance"),instance,clusterName));
//set the lb-weight
clusteredServerConfig.setLBWeight( instanceVsWeights.get(instance).toString());
}
| public java.lang.String | createLBRef(java.lang.String lbName, java.lang.String configName, java.lang.String target, java.util.Map options)This method supports the create-http-lb-ref CLI command. It creates a server-ref|cluster-ref, health-checker by using
the given parameters.
String healthCheckerUrl = options.get(HEALTH_CHECKER_URL);
String healthCheckerInterval = options.get(HEALTH_CHECKER_INTERVAL);
String healthCheckerTimeout = options.get(HEALTH_CHECKER_TIMEOUT);
String lbPolicy = options.get(LB_POLICY);
String lbPolicyModule = options.get(LB_POLICY_MODULE);
boolean isCluster = isCluster(target);
boolean enableAllInstances =
Boolean.getBoolean(options.get(LB_ENABLE_ALL_INSTANCES));
boolean enableAllApps =
Boolean.getBoolean(options.get(LB_ENABLE_ALL_APPLICATIONS));
if((configName!=null) &&
(mDomainConfig.getLBConfigMap().get(configName)==null)){
String msg = formatter.format(resBundle.getString("LbConfigNotDefined"),
configName);
throw new MBeanException(new RuntimeException(msg));
}
else if (lbName!=null){
LoadBalancerConfig loadBalancerConfig =
mDomainConfig.getLoadBalancerConfigMap().get(lbName);
if (loadBalancerConfig==null){
String msg = formatter.format(
resBundle.getString("LoadBalancerConfigNotDefined"),lbName);
throw new MBeanException(new RuntimeException(msg));
}
configName = loadBalancerConfig.getLbConfigName();
}
LBConfig lbConfig = mDomainConfig.getLBConfigMap().get(configName);
if(!isCluster){
if((lbPolicy!=null) || (lbPolicyModule!=null)){
//throw exception
String msg = formatter.format(resBundle.getString("NotCluster"),
target);
throw new MBeanException(new RuntimeException(msg));
}
}
if(isCluster){
//create the cluster-ref
ClusterRefConfig clusterRefConfig =
lbConfig.createClusterRefConfig(target, lbPolicy, lbPolicyModule);
//create the health checker
clusterRefConfig.createHealthCheckerConfig(healthCheckerUrl,
healthCheckerInterval, healthCheckerTimeout);
}else{
//create the server-ref
ServerRefConfig serverRefConfig = lbConfig.createServerRefConfig(target,"30",true,true);
//create the health checker
serverRefConfig.createHealthCheckerConfig(healthCheckerUrl,
healthCheckerInterval, healthCheckerTimeout);
}
//lb-enable all the instances in the target
if (enableAllInstances)
enableServer(target);
//lb-enable all applications in the target
if (enableAllApps)
enableAllApplications(target);
return null;
| private com.sun.appserv.management.ext.lb.LoadBalancer | createLoadBalancer(java.lang.String configName)
mDomainConfig.createLoadBalancerConfig(
configName+LB_SUFFIX, configName, false, null);
Map<String,LoadBalancer> lbs = mDomainRoot.getLoadBalancerMap();
LoadBalancer lb = lbs.get(configName+LB_SUFFIX);
return lb;
| public final com.sun.appserv.management.config.LoadBalancerConfig | createLoadBalancer(java.lang.String loadbalancerName, java.lang.String target, java.util.Map options, java.util.Map properties)This method supports the create-http-lb CLI command. It creates a lb-config, cluster-ref, health-checker by using
the given parameters.
if (loadbalancerName == null ) {
throw new IllegalArgumentException(
"loadbalancerName can not be null");
}
//check if the load-balancer with the name already exists
if (mDomainConfig.getLoadBalancerConfigMap().get(loadbalancerName)!=null)
{
String msg = formatter.format(
resBundle.getString("LoadBalancerConfigExists"),
loadbalancerName);
throw new MBeanException(new RuntimeException(msg));
}
String healthCheckerUrl = options.get(HEALTH_CHECKER_URL);
String healthCheckerInterval = options.get(HEALTH_CHECKER_INTERVAL);
String healthCheckerTimeout = options.get(HEALTH_CHECKER_TIMEOUT);
String lbPolicy = options.get(LB_POLICY);
String lbPolicyModule = options.get(LB_POLICY_MODULE);
boolean autoApplyEnabled = Boolean.valueOf(
options.get(AUTO_APPLY_ENABLED)).booleanValue();
boolean enableAllInstances = Boolean.valueOf(
options.get(LB_ENABLE_ALL_INSTANCES)).booleanValue();
boolean enableAllApps = Boolean.valueOf(
options.get(LB_ENABLE_ALL_APPLICATIONS)).booleanValue();
boolean isCluster = isCluster(target);
Map<String,String> params = getParams(options);
//iniitialize lb-config name that we are going to use for this lb
String lbConfigName = loadbalancerName + LB_CONFIG_SUFFIX;
//the following block tries to get a unique lb-config name
//get all the lb-configs
Map<String,LBConfig> lbconfigMap = mDomainConfig.getLBConfigMap();
if(lbconfigMap != null){
//keep appending a counter till there is no lb-config by that name
for(int i=1;lbconfigMap.get(lbConfigName) != null;i++){
lbConfigName = loadbalancerName + LB_CONFIG_SUFFIX + "_" + i;
}
}
if(!isCluster){
if((lbPolicy!=null) || (lbPolicyModule!=null)){
//throw exception
String msg = formatter.format(resBundle.getString("NotCluster"),
target);
throw new MBeanException(new RuntimeException(msg));
}
}
//create the lb-config
LBConfig lbConfig = mDomainConfig.createLBConfig(lbConfigName, params);
if(isCluster){
//create the cluster-ref
ClusterRefConfig clusterRefConfig =
lbConfig.createClusterRefConfig(target, lbPolicy,
lbPolicyModule);
//create the health checker
clusterRefConfig.createHealthCheckerConfig(healthCheckerUrl,
healthCheckerInterval, healthCheckerTimeout);
}else{
//create the server-ref
ServerRefConfig serverRefConfig = lbConfig.createServerRefConfig(target,"30",true,true);
//create the health checker
serverRefConfig.createHealthCheckerConfig(healthCheckerUrl,
healthCheckerInterval, healthCheckerTimeout);
}
//lb-enable all the instances in the target
if (enableAllInstances)
setServerStatus(target, 0,true, true);
else
setServerStatus(target, 0,false, true);
//lb-enable all applications in the target, dtd's default value is false
if (enableAllApps)
enableAllApplications(target);
// now create the load-balancer element
return mDomainConfig.createLoadBalancerConfig(loadbalancerName,
lbConfigName, autoApplyEnabled, properties);
| public com.sun.appserv.management.config.LoadBalancerConfig | createLoadbalancer(java.lang.String loadbalancerName, boolean autoApplyEnabled, java.lang.String[] targets, java.util.Map params)Creates a load balancer element ( and the necessary config)
// first create the lb-config element
if ( loadbalancerName == null ) {
throw new IllegalArgumentException(
"loadbalancerName can not be null");
}
//iniitialize lb-config name that we are going to use for this lb
String lbConfigName = loadbalancerName + LB_CONFIG_SUFFIX;
//the following block tries to get a unique lb-config name
//get all the lb-configs
Map<String,LBConfig> lbconfigMap = mDomainConfig.getLBConfigMap();
if(lbconfigMap != null){
//keep appending a counter till there is no lb-config by that name
for(int i=1;lbconfigMap.get(lbConfigName) != null;i++){
lbConfigName = loadbalancerName + LB_CONFIG_SUFFIX + "_" + i;
}
}
//create the lb-config
LBConfig lbConfig = mDomainConfig.createLBConfig(lbConfigName, params);
//get the default values for health-checker
final Map healthCheckerAttrsMap = mDomainRoot.getDomainConfig().getDefaultAttributeValues(HealthCheckerConfig.J2EE_TYPE);
final String healthCheckerUrl = (String) healthCheckerAttrsMap.get("url");
final String healthCheckerInterval = (String) healthCheckerAttrsMap.get("interval-in-seconds");
final String healthCheckerTimeout = (String) healthCheckerAttrsMap.get("timeout-in-seconds");
if ( targets != null) {
for (int idx =0; idx < targets.length; idx++) {
String targetName = targets[idx];
if ( isCluster(targetName)) {
//create the cluster-ref
ClusterRefConfig clusterRefConfig =
lbConfig.createClusterRefConfig(targetName, null);
//create the health checker
clusterRefConfig.createHealthCheckerConfig(healthCheckerUrl,
healthCheckerInterval, healthCheckerTimeout);
} else if ( isStandaloneServer( targetName)) {
//create the server-ref
ServerRefConfig serverRefConfig =
lbConfig.createServerRefConfig(targetName, null);
//create the health checker
serverRefConfig.createHealthCheckerConfig(healthCheckerUrl,
healthCheckerInterval, healthCheckerTimeout);
}
}
}
// now create the load-balancer element
return mDomainConfig.createLoadBalancerConfig(loadbalancerName,
lbConfigName, autoApplyEnabled, null);
| public void | disableApplication(java.lang.String target, java.lang.String appName, int timeout)Disables load balancing for a particular application in a server instance
with a quiescing period specififed by the timeout .
setApplicationStatus(target, appName, timeout, false);
| public void | disableServer(java.lang.String target, int timeout)Disables load balancing for a server with a quiescing period specififed
by the timeout .
setServerStatus(target,timeout,false, false);
| public void | enableAllApplications(java.lang.String target)Enables all user applications in the given target
//check if the target is cluster
if (isCluster(target)) {
//get the cluster config
ClusterConfig cRef = mDomainConfig.getClusterConfigMap().get(target);
enableAllApplications(cRef.getDeployedItemRefConfigMap());
} else {
//The target must be server, get the server config for this target
ServerConfig serverConfig = mDomainConfig.getServerConfigMap().get(target);
if(serverConfig != null){
enableAllApplications(serverConfig.getDeployedItemRefConfigMap());
}
}
| private void | enableAllApplications(java.util.Map deployedItemRefConfigMap)
//iterate through all the deployed items
for (DeployedItemRefConfig deployedItemRefConfig : deployedItemRefConfigMap.values()) {
//Check to see if the deployed item is App or Module (Web, EJB, RAR or Appclient)
final J2EEApplicationConfig app =
mDomainConfig.getJ2EEApplicationConfigMap().get(deployedItemRefConfig.getName());
if(app != null) {
//if the type is user, then only set the lb-enabled to true
if(app.getObjectType().equals(ObjectTypeValues.USER)) {
deployedItemRefConfig.setLBEnabled(true);
}
continue;
}
//Check to see if this is Web module
final WebModuleConfig web =
mDomainConfig.getWebModuleConfigMap().get(deployedItemRefConfig.getName());
if (web != null) {
//if the type is user, then only set the lb-enabled to true
if(web.getObjectType().equals(ObjectTypeValues.USER)) {
deployedItemRefConfig.setLBEnabled(true);
}
continue;
}
//Check to see if this is EJB module
final EJBModuleConfig ejb =
mDomainConfig.getEJBModuleConfigMap().get(deployedItemRefConfig.getName());
if (ejb != null) {
//if the type is user, then only set the lb-enabled to true
if(ejb.getObjectType().equals(ObjectTypeValues.USER)) {
deployedItemRefConfig.setLBEnabled(true);
}
continue;
}
//Check to see if this is RAR module
final RARModuleConfig rar =
mDomainConfig.getRARModuleConfigMap().get(deployedItemRefConfig.getName());
if (rar != null) {
//if the type is user, then only set the lb-enabled to true
if(rar.getObjectType().equals(ObjectTypeValues.USER)) {
deployedItemRefConfig.setLBEnabled(true);
}
continue;
}
//Check to see if this is AppClient module
final AppClientModuleConfig appClient =
mDomainConfig.getAppClientModuleConfigMap().get(deployedItemRefConfig.getName());
if (appClient != null) {
//if the type is user (There is no API yet), then only set the lb-enabled to true
//if(appClient.getObjectType().equals(ObjectTypeValues.USER)) {
deployedItemRefConfig.setLBEnabled(true);
//}
continue;
}
}
| public void | enableApplication(java.lang.String target, java.lang.String appName)Enables load balancing for a particular application in a server instance
setApplicationStatus(target, appName, 0, true);
| public void | enableServer(java.lang.String target)Enables a server for load balancing.
setServerStatus(target, 0, true, false);
| private java.util.Map | fetchLBConfigs(java.lang.String targetName, boolean isCluster)
Map<String,LBConfig> result = new HashMap<String,LBConfig>();
Map<String,LBConfig> lbConfigMap = mDomainConfig.getLBConfigMap();
if (isCluster) {
for (String lbConfigName : lbConfigMap.keySet()) {
LBConfig lbConfig = lbConfigMap.get(lbConfigName);
Map<String,ClusterRefConfig> lbClusterRefConfigMap =
lbConfig.getClusterRefConfigMap();
for (String clusterRef : lbClusterRefConfigMap.keySet()) {
if (clusterRef.equals(targetName)) {
result.put(lbConfigName, lbConfig);
break;
}
}
}
} else if (isStandaloneServer(targetName)) {
/*its a serverName which means you have to find LBConfigs containing
1. standalone server references with the same name
2. clustered server references with the same name */
for (String lbConfigName : lbConfigMap.keySet()) {
LBConfig lbConfig = lbConfigMap.get(lbConfigName);
Map<String,ServerRefConfig> lbServerRefConfigMap =
lbConfig.getServerRefConfigMap();
for (String serverRef : lbServerRefConfigMap.keySet()) {
if (serverRef.equals(targetName)) {
result.put(lbConfigName, lbConfig);
break;
}
}
}
} else {//we assume that its a clustered instance name
for (String lbConfigName : lbConfigMap.keySet()) {
LBConfig lbConfig = lbConfigMap.get(lbConfigName);
Map<String,ClusterRefConfig> lbClusterRefConfigMap =
lbConfig.getClusterRefConfigMap();
Map<String,ClusterConfig> clusterConfigMap =
mDomainConfig.getClusterConfigMap();
Map<String,ClusterConfig> relevantClusterConfigMap = new HashMap<String,ClusterConfig>();
for (String clusterRef : lbClusterRefConfigMap.keySet())
relevantClusterConfigMap.put(clusterRef,
clusterConfigMap.get(clusterRef));
//so now we have the right set of <cluster> elements
for (String clusterName : relevantClusterConfigMap.keySet()) {
ClusterConfig clusterConfig =
relevantClusterConfigMap.get(clusterName);
Map<String,ServerRefConfig> clusteredServerRefConfigMap =
clusterConfig.getServerRefConfigMap();
for (String serverRef : clusteredServerRefConfigMap.keySet()) {
if (serverRef.equals(targetName)) {
result.put(lbConfigName, lbConfig);
break;
}
}
}
}
}
return result;
| private java.util.Map | fetchLoadBalancerConfigs(java.util.Map lbConfigMap)
Map<String,LoadBalancerConfig> relevantLoadBalancerConfigMap = new HashMap<String,LoadBalancerConfig>();
for (String lbConfigName : lbConfigMap.keySet()) {
//collect all load-balancer elements which refer to this lb-config
Map<String,LoadBalancerConfig> allLoadBalancerConfigMap =
mDomainRoot.getDomainConfig().getLoadBalancerConfigMap();
for (String loadBalancerName : allLoadBalancerConfigMap.keySet()) {
LoadBalancerConfig loadBalancerConfig =
allLoadBalancerConfigMap.get(loadBalancerName);
if (loadBalancerConfig.getLbConfigName().equals(lbConfigName))
relevantLoadBalancerConfigMap.put(
loadBalancerName, loadBalancerConfig);
}
}
return relevantLoadBalancerConfigMap;
| public java.util.Map | getClustersInLBConfig(java.lang.String lbConfigName)Returns a filtered list of cluster references given the name of the load
balancer config.
Map<String,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
LBConfig lbconfig = lbconfigs.get(lbConfigName);
return lbconfig.getClusterRefConfigMap();
| public java.util.List | getLBConfigsForCluster(java.lang.String clusterName)Returns a filtered LBConfig list given the name of the cluster reference
Map<String,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
List<LBConfig> list = new ArrayList<LBConfig>();
for(LBConfig config:lbconfigs.values()){
Map<String,ClusterRefConfig> map = config.getClusterRefConfigMap();
for(String name:map.keySet()){
if(name.equals(clusterName)){
list.add(config);
}
}
}
return list;
| public java.util.List | getLBConfigsForServer(java.lang.String serverName)Returns a filtered LBConfig list given the name of the server reference
Map<String,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
List<LBConfig> list = new ArrayList<LBConfig>();
for(LBConfig config:lbconfigs.values()){
Map<String,ServerRefConfig> map = config.getServerRefConfigMap();
for(String name:map.keySet()){
if(name.equals(serverName)){
list.add(config);
}
}
}
return list;
| public java.util.Map | getLoadBalancers(java.lang.String targetName, boolean isCluster)Returns the load balancers loadbalancing a target :
standalone instance, clustered instance or a cluster
Map<String, LBConfig> lbConfigMap = fetchLBConfigs(targetName, isCluster);
return fetchLoadBalancerConfigs(lbConfigMap);
| private java.util.Map | getParams(java.util.Map options)creates a map of the parameters
Map<String,String> params = new HashMap<String,String>();
params.put(LBConfigKeys.HTTPS_ROUTING_KEY,options.get(HTTPS_ROUTING));
params.put(LBConfigKeys.MONITORING_ENABLED_KEY,options.get(MONITOR));
params.put(LBConfigKeys.RELOAD_POLL_INTERVAL_IN_SECONDS_KEY, options.get(RELOAD_INTERVAL));
params.put(LBConfigKeys.RESPONSE_TIMEOUT_IN_SECONDS_KEY, options.get(RESPONSE_TIMEOUT));
params.put(LBConfigKeys.ROUTE_COOKIE_ENABLED_KEY, options.get(ROUTE_COOKIE));
return params;
| private com.sun.appserv.management.config.ServerRefConfig | getServerRefConfigFromCluster(java.lang.String target)returns the server-ref elements corresponding to the target
by searching all the cluster-ref elements.
// check if this server is part of cluster, then
// turn on lb-enable flag in the cluster.
//get all the lb-configs
Map<String,LBConfig> lbConfigs = mDomainConfig.getLBConfigMap();
//iterate through all the lb-configs
for(LBConfig lbConfig : lbConfigs.values()){
//get the cluster-refs in this lb-config
Map<String,ClusterRefConfig> clusterRefs = lbConfig.getClusterRefConfigMap();
//iterate through all the cluster-refs
for(ClusterRefConfig clusterRef :clusterRefs.values()){
//get the cluster name
String clusterName = clusterRef.getReferencedClusterName();
//get the clusterConfig for this clustername
Map<String,ClusterConfig> clusterConfigs = mDomainConfig.getClusterConfigMap();
ClusterConfig config = clusterConfigs.get(clusterName);
//get all the server-refs for this cluster
Map<String,ServerRefConfig> serverRefConfigs = config.getServerRefConfigMap();
//iterate through the server-refs
for(ServerRefConfig serverRefConfig : serverRefConfigs.values() ){
//if this server-ref matches the given target , return it
if(serverRefConfig.getName().equals(target)){
return serverRefConfig;
}
}
}
}
return null;
| public java.util.Map | getServersInLBConfig(java.lang.String lbConfigName)Returns a filtered list of server references given the name of the load
balancer config.
Map<String,LBConfig> lbconfigs = mDomainConfig.getLBConfigMap();
LBConfig lbconfig = lbconfigs.get(lbConfigName);
return lbconfig.getServerRefConfigMap();
| boolean | isCluster(java.lang.String name)
Map<String,ClusterConfig> cConfigMap =
mDomainConfig.getClusterConfigMap();
if (cConfigMap == null) {
return false;
}
ClusterConfig cConfig = (ClusterConfig) cConfigMap.get(name);
if ( cConfig == null) {
return false;
} else {
return true;
}
| boolean | isStandaloneServer(java.lang.String name)
Map<String,StandaloneServerConfig> ssConfigMap =
mDomainConfig.getStandaloneServerConfigMap();
if (ssConfigMap == null) {
return false;
}
StandaloneServerConfig ssConfig = (StandaloneServerConfig)
ssConfigMap.get(name);
if ( ssConfig == null) {
return false;
} else {
return true;
}
| public java.lang.String[] | listTargets()Lists all the standalone server instances and clusters in the domain.
Set<String> targetSet = new HashSet<String>();
Map<String,ClusterConfig> cConfigMap =
mDomainConfig.getClusterConfigMap();
if (cConfigMap != null) {
targetSet.addAll( cConfigMap.keySet());
}
Map<String,StandaloneServerConfig> ssConfigMap =
mDomainConfig.getStandaloneServerConfigMap();
if (ssConfigMap != null) {
targetSet.addAll( ssConfigMap.keySet());
}
String[] targetArr = new String[targetSet.size()];
return (String[]) targetSet.toArray(targetArr);
| public java.lang.String[] | listTargets(java.lang.String lbName)Lists all the standalone server instances and clusters in the load
balancer.
Set<String> targetSet = new HashSet<String>();
Map<String, LoadBalancerConfig> lbMap =
mDomainConfig.getLoadBalancerConfigMap();
if (lbMap == null) {
return null;
}
LoadBalancerConfig lb = (LoadBalancerConfig) lbMap.get(lbName);
if (lb == null) {
return null;
}
String lbConfigName = lb.getLbConfigName();
Map<String, LBConfig> lbConfigMap = mDomainConfig.getLBConfigMap();
if ((lbConfigMap == null) || (lbConfigName == null) ){
return null;
}
LBConfig lbConfig = (LBConfig) lbConfigMap.get(lbConfigName);
if (lbConfig == null) {
return null;
}
Map<String,ClusterRefConfig> cRefMap =
lbConfig.getClusterRefConfigMap();
if ( cRefMap != null) {
targetSet.addAll(cRefMap.keySet());
}
Map<String,ServerRefConfig> sRefMap =
lbConfig.getServerRefConfigMap();
if ( sRefMap != null) {
targetSet.addAll(sRefMap.keySet());
}
String [] targetArr = new String[targetSet.size()];
return (String[]) targetSet.toArray(targetArr);
| public java.lang.String | removeLBRef(java.lang.String lbName, java.lang.String configName, java.lang.String target, boolean force)This method supports the delete-http-lb-ref CLI command. It removes a
server-ref|cluster-ref by using the given parameters.
boolean isCluster = isCluster(target);
if((configName!=null) &&
(mDomainConfig.getLBConfigMap().get(configName)==null)){
String msg = formatter.format(resBundle.getString("LbConfigNotDefined"),
configName);
throw new MBeanException(new RuntimeException(msg));
}
else if (lbName!=null){
LoadBalancerConfig loadBalancerConfig =
mDomainConfig.getLoadBalancerConfigMap().get(lbName);
if (loadBalancerConfig==null){
String msg = formatter.format(
resBundle.getString("LoadBalancerConfigNotDefined"),lbName);
throw new MBeanException(new RuntimeException(msg));
}
configName = loadBalancerConfig.getLbConfigName();
}
LBConfig lbConfig = mDomainConfig.getLBConfigMap().get(configName);
if(isCluster){
if (!force){
//check the lb-enabled flag for all server-refs in this cluster
Map<String, ServerRefConfig> serverRefConfigMap =
mDomainConfig.getClusterConfigMap().get(target).getServerRefConfigMap();
for (ServerRefConfig serverRefConfig : serverRefConfigMap.values()) {
if (serverRefConfig.getLBEnabled()){
String msg = formatter.format(
resBundle.getString("DisableServer"), target);
throw new MBeanException(new RuntimeException(msg));
}
}
}
//remove the cluster-ref
lbConfig.removeClusterRefConfig(target);
} else {
if (!force &&
(lbConfig.getServerRefConfigMap().get(target).getLBEnabled())){
String msg = formatter.format(
resBundle.getString("DisableServer"), target);
throw new MBeanException(new RuntimeException(msg));
}
//remove the server-ref
lbConfig.removeServerRefConfig(target);
}
return null;
| public void | removeLoadbalancer(java.lang.String loadbalancerName)Deletes a load balancer element ( and the necessary config, if nobody
else is using this config)
//first get the lbConfigName
final LoadBalancerConfig loadbalancerConfig =
mDomainConfig.getLoadBalancerConfigMap().get(loadbalancerName);
if(loadbalancerConfig == null){
final String msg = formatter.format(
resBundle.getString("LoadBalancerConfigNotDefined"),loadbalancerName);
throw new RuntimeException(msg);
}
final String lbConfigName = loadbalancerConfig .getLbConfigName();
//get the load balancers map
final Map<String, LoadBalancerConfig> lbMap = mDomainConfig.getLoadBalancerConfigMap();
if ( lbMap != null) {
// check to see if any other load-balancer is using lb-config
for(LoadBalancerConfig lbConfig : lbMap.values()){
if (!lbConfig.getName().equals(loadbalancerConfig.getName()) &&
lbConfig.getLbConfigName().equals(lbConfigName)) {
// this load-balancer element is still using it
final String msg = formatter.format(resBundle.getString("LbConfigIsInUse"),
lbConfigName);
throw new RuntimeException(msg);
}
}
}
// now remove load-balancer element
mDomainConfig.removeLoadBalancerConfig(loadbalancerName);
// no load-balancer element is using this lb-config, remove it
mDomainConfig.removeLBConfig(lbConfigName);
| private void | setApplicationStatus(java.lang.String target, java.lang.String appName, int timeout, boolean status)sets the lb-enabled flag to the value of status for the given target
if status is false also sets the disable-timeout-in-minutes for the application
//disable timeout is required for disable operation
if (timeout < 0 && !status) {
String msg = resBundle.getString("InvalidNumber");
throw new IllegalArgumentException(msg);
}
try {
DeployedItemRefConfig dRef = null;
// disables cluster if target is a cluster
if (isCluster(target)) {
//get the clusterConfig for this cluster
Map<String,ClusterConfig> clusterConfigs = mDomainConfig.getClusterConfigMap();
ClusterConfig clusterConfig = clusterConfigs.get(target);
//get the deployed item object corresponding to the given appName
dRef = clusterConfig.getDeployedItemRefConfigMap().get(appName);
} else { // target is a server
//get the standalone serverConfig
Map<String,StandaloneServerConfig> ssConfigMap =
mDomainConfig.getStandaloneServerConfigMap();
StandaloneServerConfig ssc = ssConfigMap.get(target);
if (ssc == null) {
//get the clustered server config
ClusteredServerConfig s = mDomainConfig.getClusteredServerConfigMap().get(target);
//get the deployed item object corresponding to the given appName
dRef = s.getDeployedItemRefConfigMap().get(appName);
}else{
//get the deployed item object corresponding to the given appName
dRef = ssc.getDeployedItemRefConfigMap().get(appName);
}
}
if (dRef == null) {
mLogger.log(Level.FINEST," server " + target +
" does not exist in any cluster in the domain");
String msg = formatter.format(resBundle.getString("AppRefNotDefined"),
target);
throw new MBeanException(new RuntimeException(msg));
}
int curTout = Integer.parseInt(
dRef.getDisableTimeoutInMinutes());
//check if the app is already in the state desired
boolean enabled = dRef.getLBEnabled();
if(!status){
if ((enabled == false) && (curTout == timeout)) {
String msg = resBundle.getString("AppDisabledOnServer"
);
throw new MBeanException(new Exception(msg));
}
//set the disable timeout
dRef.setDisableTimeoutInMinutes( "" + timeout );
//disable the app
dRef.setLBEnabled(false);
mLogger.log(Level.INFO,resBundle.getString(
"http_lb_admin.ApplicationDisabled"));
}else{
if (enabled == true) {
String msg = resBundle.getString("AppEnabledOnServer"
);
throw new MBeanException(new Exception(msg));
}
//enable the app
dRef.setLBEnabled(true);
mLogger.log(Level.INFO,resBundle.getString(
"http_lb_admin.ApplicationEnabled"));
}
} catch(Exception ce) {
throw new RuntimeException(ce);
}
| private void | setLBEnabled(com.sun.appserv.management.config.ServerRefConfig sRef, boolean status, int timeout, java.lang.String target, boolean ignore)sets the lb-enabled flag for the target
int curTout = sRef.getDisableTimeoutInMinutes();
//check if it is already in the state desired
boolean enabled = sRef.getLBEnabled();
if(!status){
if ((ignore == false) && (enabled == false) && (curTout == timeout)) {
String msg = formatter.format(resBundle.getString("ServerDisabled"),
sRef.getRef());
throw new MBeanException(new Exception(msg));
}
//set the disable timeout in minutes
sRef.setDisableTimeoutInMinutes(timeout);
//set the lb-enabled to false
sRef.setLBEnabled(false);
//mLogger.log(Level.INFO,formatter.format(resBundle.getString(
// "http_lb_admin.ServerDisabled"), target));
}else{
if ((ignore == false) && (enabled == true)){
String msg = formatter.format(resBundle.getString("ServerEnabled"),
sRef.getRef());
throw new MBeanException(new Exception("ServerEnabled"));
}
sRef.setLBEnabled(true);
//mLogger.log(Level.INFO,formatter.format(resBundle.getString(
// "http_lb_admin.ServerEnabled"), target));
}
| private void | setServerStatus(java.lang.String target, int timeout, boolean status, boolean ignore)sets the lb-enabled flag for the target, also sets the disable-timeout-in-minutes
if the status flag is false.
//timeout has to be specified for disable operation
if (timeout < 0 && !status) {
String msg = resBundle.getString("InvalidNumber");
throw new IllegalArgumentException(msg);
}
try {
// disables cluster if target is a cluster
if (isCluster(target)) {
//get the cluster config
ClusterConfig cRef = mDomainConfig.getClusterConfigMap().get(target);
if (cRef == null) {
mLogger.log(Level.FINEST," server " + target +
" does not exist in any cluster in the domain");
String msg = formatter.format(resBundle.getString("ServerNotDefined"),
target);
throw new MBeanException(new RuntimeException(msg));
}
//iterate through all the servers in the cluster
for(ServerRefConfig sRef : cRef.getServerRefConfigMap().values()){
//set lb-enabled flag and the timeout with error checks
setLBEnabled(sRef, status, timeout, target, ignore);
}
} else { // target is a server
ServerRefConfig sRef = null;
boolean foundTarget = false;
//get all the lb-configs
Map<String,LBConfig> lbConfigs = mDomainConfig.getLBConfigMap();
//iterate through lb-configs
for(LBConfig lbConfig : lbConfigs.values()){
//get the server-ref in this lb-config
Map<String,ServerRefConfig> serverRefs = lbConfig.getServerRefConfigMap();
//get the server-ref for this target
sRef = serverRefs.get(target);
if (sRef == null) {
mLogger.log(Level.FINEST," server " + target +
" does not exist in " + serverRefs);
} else {
foundTarget = true;
break;
}
}
// did not find server target
if (!foundTarget) {
//get the server-ref from some some cluster
sRef = getServerRefConfigFromCluster(target);
if (sRef == null) {
mLogger.log(Level.FINEST," server " + target +
" does not exist in any cluster in the domain");
String msg = formatter.format(resBundle.getString("ServerNotDefined"),
target);
throw new MBeanException(new RuntimeException(msg));
}
}
//set the lb-enabled flag
setLBEnabled(sRef, status, timeout, target, ignore);
}
} catch(Exception ce) {
ce.printStackTrace();
throw new RuntimeException(ce);
}
| private java.lang.String | writeToFile(java.lang.String lbxml, java.lang.String filePath)writes the String lbxml to the file given by filePath
FileOutputStream fo = null;
try{
fo = new FileOutputStream(filePath);
fo.write(lbxml.getBytes());
}catch(IOException ioe){
ioe.printStackTrace();
}finally{
try{
fo.close();
}catch(IOException e){}
}
return filePath;
|
|