1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.util.Set ; 28 import java.util.Collections ; 29 import java.util.Properties ; 30 31 import javax.management.ObjectName ; 32 import javax.management.AttributeList ; 33 34 import com.sun.appserv.management.base.QueryMgr; 35 import com.sun.appserv.management.base.Util; 36 import com.sun.appserv.management.base.XTypes; 37 38 import com.sun.appserv.management.config.ServerConfigKeys; 39 import com.sun.appserv.management.config.ServerRefConfig; 40 import com.sun.appserv.management.config.ServerRefConfigCR; 41 import com.sun.appserv.management.config.ClusteredServerConfig; 42 import com.sun.appserv.management.config.ClusterConfig; 43 44 import com.sun.appserv.management.util.misc.MapUtil; 45 import com.sun.appserv.management.util.misc.CollectionUtil; 46 47 48 import com.sun.enterprise.management.support.oldconfig.OldServersMBean; 49 50 public final class ClusteredServerConfigFactory extends StandaloneServerConfigFactory 51 { 52 public 53 ClusteredServerConfigFactory( final ConfigFactoryCallback callbacks ) 54 { 55 super( callbacks ); 56 } 57 58 private boolean 59 getLBEnabled( final ClusterConfig clusterConfig ) 60 { 61 final Map <String ,ServerRefConfig> refs = clusterConfig.getServerRefConfigMap(); 62 63 boolean enabled = false; 64 if ( refs.keySet().size() != 0 ) 66 { 67 final ServerRefConfig first = refs.values().iterator().next(); 68 enabled = first.getLBEnabled(); 69 } 70 71 return enabled; 72 } 73 74 public ObjectName 75 create( 76 final String serverName, 77 final String clusterName, 78 final String nodeAgentName, 79 final Map <String ,String > optional) 80 { 81 final ClusterConfig clusterConfig = 82 getDomainConfig().getClusterConfigMap().get( clusterName ); 83 if ( clusterConfig == null ) 84 { 85 throw new IllegalArgumentException ( "" + clusterName ); 86 } 87 88 final String configName = clusterConfig.getReferencedConfigName(); 89 90 debug( "creating server:\n" + (optional == null ? "null" : MapUtil.toString( optional )) ); 91 final ObjectName serverObjectName = 92 super.create( serverName, nodeAgentName, configName, optional ); 93 94 debug( "created server: " + serverName + " in cluster " + clusterName + 96 "with node agent " + nodeAgentName ); 97 final Map <String ,String > options = new HashMap <String ,String >(); 98 options.put( ServerRefConfigCR.ENABLED_KEY, "true" ); 99 options.put( ServerRefConfigCR.LB_ENABLED_KEY, "" + getLBEnabled(clusterConfig) ); 100 debug( "creating reference" ); 101 final ServerRefConfig refConfig = 102 clusterConfig.createServerRefConfig( serverName, options ); 103 debug( "created reference" ); 104 105 final String props = Util.makeRequiredProps( XTypes.CLUSTERED_SERVER_CONFIG, serverName ); 108 Set <ClusteredServerConfig> s = null; 109 while( (s = getQueryMgr().queryPropsSet( props )).size() == 0 ) 110 { 111 try 112 { 113 Thread.sleep( 20 ); 114 } 115 catch( InterruptedException e ) 116 { 117 throw new RuntimeException ( e ); 118 } 119 } 120 121 return Util.getObjectName( s.iterator().next() ); 122 } 123 124 125 private ClusterConfig 126 findClusterForClusteredServer( final String clusteredServerName ) 127 { 128 ClusterConfig clusterConfig = null; 130 131 final Map <String ,ClusterConfig> clusters = getDomainConfig().getClusterConfigMap(); 132 for( final ClusterConfig cc : clusters.values() ) 133 { 134 final Map <String ,ServerRefConfig> servers = cc.getServerRefConfigMap(); 135 136 if ( servers.keySet().contains( clusteredServerName ) ) 137 { 138 clusterConfig = cc; 139 break; 140 } 141 } 142 143 return clusterConfig; 144 } 145 146 protected void 147 removeByName(final String clusteredServerName) 148 { 149 final ClusterConfig clusterConfig = 151 findClusterForClusteredServer( clusteredServerName ); 152 if ( clusterConfig == null ) 153 { 154 throw new IllegalArgumentException ( "" + clusteredServerName ); 155 } 156 157 clusterConfig.removeServerRefConfig( clusteredServerName ); 159 160 super.removeByName( clusteredServerName ); 161 } 162 } 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | Popular Tags |