1 23 24 28 package com.sun.enterprise.management.support; 29 30 import java.util.Set ; 31 import java.util.HashSet ; 32 import java.util.Map ; 33 import java.util.Collections ; 34 35 import java.io.IOException ; 36 37 import javax.management.ObjectName ; 38 import javax.management.MBeanRegistrationException ; 39 import javax.management.InstanceAlreadyExistsException ; 40 import javax.management.InstanceNotFoundException ; 41 42 import com.sun.appserv.management.base.Util; 43 import com.sun.appserv.management.base.XTypes; 44 import com.sun.appserv.management.base.AMX; 45 import com.sun.appserv.management.base.AMXDebug; 46 import com.sun.appserv.management.base.SystemInfo; 47 48 import com.sun.appserv.management.client.ProxyFactory; 49 50 import com.sun.appserv.management.util.jmx.JMXUtil; 51 import com.sun.appserv.management.util.misc.GSetUtil; 52 import com.sun.appserv.management.util.misc.CollectionUtil; 53 import com.sun.appserv.management.util.misc.StringUtil; 54 55 import com.sun.appserv.management.config.ClusterConfig; 56 import com.sun.appserv.management.config.DomainConfig; 57 import com.sun.appserv.management.config.ServerConfig; 58 import com.sun.appserv.management.config.ClusteredServerConfig; 59 import com.sun.appserv.management.config.StandaloneServerConfig; 60 import com.sun.appserv.management.config.ServerRefConfig; 61 import com.sun.appserv.management.config.RefConfig; 62 63 import com.sun.appserv.management.util.stringifier.SmartStringifier; 64 65 import com.sun.enterprise.management.support.oldconfig.OldServersMBean; 66 import com.sun.enterprise.management.support.oldconfig.OldConfigProxies; 67 import com.sun.enterprise.management.support.oldconfig.OldProps; 68 69 import com.sun.appserv.management.util.jmx.MBeanRegistrationListener; 70 import com.sun.appserv.management.util.jmx.JMXUtil; 71 72 73 76 class LoaderOfOldConfig extends LoaderOfOld 77 { 78 private final boolean mSupportsClusters; 79 private ServerRefListener mServerRefListener; 80 81 LoaderOfOldConfig( final Loader loader ) 82 { 83 super( loader ); 84 85 final SystemInfo systemInfo = getDomainRoot().getSystemInfo(); 86 mSupportsClusters = systemInfo.supportsFeature( systemInfo.CLUSTERS_FEATURE ); 87 88 if ( NEEDS_SUPPORT.size() != 0 ) 89 { 90 getLogger().warning( 91 "Support for the following old config mbean types is not yet implemented: {" + 92 SmartStringifier.toString( NEEDS_SUPPORT ) + "}" ); 93 } 94 95 try 96 { 97 mServerRefListener = new ServerRefListener(); 98 } 99 catch( Exception e ) 100 { 101 debug( "" + e ); 102 throw new Error ( e ); 103 } 104 } 105 106 107 private ObjectName 108 getListenToServerRefConfigPattern() 109 { 110 final String jmxDomain = Util.getObjectName( getDomainRoot() ).getDomain(); 111 final String props = Util.makeJ2EETypeProp( XTypes.SERVER_REF_CONFIG ); 112 return Util.newObjectNamePattern( jmxDomain, props ); 113 } 114 115 118 private final class ServerRefListener 119 extends MBeanRegistrationListener 120 { 121 public ServerRefListener( ) 122 throws InstanceNotFoundException , IOException 123 { 124 super( getMBeanServer(), getListenToServerRefConfigPattern() ); 125 } 126 127 131 protected void 132 mbeanRegistered( final ObjectName objectName ) 133 { 134 debug( "mbeanRegistered: " + objectName ); 135 136 final ServerRefConfig ref = 137 ProxyFactory.getInstance( getMBeanServer() ).getProxy( objectName, ServerRefConfig.class); 138 if ( ref.getContainer() instanceof ClusterConfig ) 139 { 140 final String serverName = ref.getRef(); 141 debug( "mbeanRegistered: serverName = " + serverName ); 142 143 final DomainConfig domainConfig = getDomainRoot().getDomainConfig(); 144 145 if ( domainConfig.getClusteredServerConfigMap().get( serverName ) == null ) 146 { 147 final ServerConfig server = 148 domainConfig.getServerConfigMap().get( serverName ); 149 150 final ObjectName serverObjectName = Util.getObjectName( server ); 152 debug( "mbeanRegistered: serverConfig = " + serverObjectName ); 153 try 154 { 155 final Set <RefConfig> containees = new HashSet <RefConfig>(); 156 157 containees.addAll( server.getResourceRefConfigMap().values() ); 158 containees.addAll( server.getDeployedItemRefConfigMap().values() ); 159 160 mLoader.resyncAMXMBean( serverObjectName ); 161 162 for( final RefConfig containee : containees ) 163 { 164 mLoader.resyncAMXMBean( Util.getObjectName( containee ) ); 165 } 166 } 167 catch( Throwable t ) 168 { 169 getLogger().warning( 170 "mbeanRegistered: can't resync with: " + serverObjectName + 171 ": " + t); 172 } 173 } 174 else 175 { 176 debug( "mbeanRegistered: server is already Clustered (ignoring)" ); 177 } 178 } 179 else 180 { 181 debug( "mbeanRegistered: ref not from a cluster (ignoring)" ); 182 } 183 } 184 185 192 protected void 193 mbeanUnregistered( final ObjectName objectName ) 194 { 195 debug( "mbeanUnregistered: " + objectName ); 196 } 197 } 198 199 protected Set <String > 200 getIgnoreTypes() 201 { 202 return( OldConfigTypes.getIgnoreTypes() ); 203 } 204 205 private Set <ObjectName > 206 getOldServerConfigObjectNames() 207 { 208 ObjectName pattern = 212 Util.newObjectNamePattern( "com.sun.appserv", "type=server" ); 213 Set <ObjectName > objectNames = JMXUtil.queryNames( getMBeanServer(), pattern, null ); 214 215 if ( objectNames.size() == 0 ) 216 { 217 pattern = Util.newObjectNamePattern( "ias", "type=server" ); 218 219 objectNames = JMXUtil.queryNames( getMBeanServer(), pattern, null ); 220 } 221 return( objectNames ); 222 } 223 224 protected Set <ObjectName > 225 findAllOldCandidates() 226 { 227 ObjectName pattern = null; 228 Set <ObjectName > oldNames = null; 229 230 pattern = Util.newObjectNamePattern( "com.sun.appserv", "category=config" ); 231 oldNames = JMXUtil.queryNames( getMBeanServer(), pattern, null ); 232 233 oldNames.addAll( getOldServerConfigObjectNames() ); 234 235 debug( "LoaderOfOldConfig: found the following:" ); 236 debug( CollectionUtil.toString( oldNames, "\n" ) ); 237 return( oldNames ); 238 } 239 240 241 242 245 private static final Set <String > NEEDS_SUPPORT = GSetUtil.newUnmodifiableStringSet(); 246 247 protected Set <String > 248 getNeedsSupport() 249 { 250 return( NEEDS_SUPPORT ); 251 } 252 253 254 private boolean 255 isOldConfigMBean( final ObjectName objectName ) 256 { 257 boolean isOldConfigMBean = false; 258 259 if ( objectName.getDomain().equals( "com.sun.appserv" ) && 260 "config".equals( objectName.getKeyProperty( "category" ) ) ) 261 { 262 final String type = objectName.getKeyProperty( "type" ); 263 264 isOldConfigMBean = ! OldConfigTypes.getIgnoreTypes().contains( type ); 265 } 266 return( isOldConfigMBean ); 267 } 268 269 protected boolean 270 isOldMBean( final ObjectName objectName ) 271 { 272 return( isOldConfigMBean( objectName ) ); 273 } 274 275 private final static String OLD_SERVER_TYPE = "server"; 276 277 private final class MyOldTypes 278 implements OldTypeToJ2EETypeMapper 279 { 280 private final OldConfigTypes mOldTypes; 281 private final OldServersMBean mOldServers; 282 283 public 284 MyOldTypes() 285 { 286 mOldTypes = OldConfigTypes.getInstance(); 287 mOldServers = OldConfigProxies.getInstance( getMBeanServer() ).getOldServersMBean(); 288 } 289 290 public String 291 j2eeTypeToOldType( final String j2eeType ) 292 { 293 return( mOldTypes.j2eeTypeToOldType( j2eeType ) ); 294 } 295 296 private boolean 297 isStandaloneServer( final String name ) 298 { 299 boolean isStandalone = true; 300 301 if ( mSupportsClusters ) 302 { 303 final ObjectName [] standaloneServerObjectNames = 304 mOldServers.listUnclusteredServerInstances( false ); 305 306 isStandalone = false; 307 for( int i = 0; i < standaloneServerObjectNames.length; ++i ) 308 { 309 if ( name.equals( Util.getName( standaloneServerObjectNames[ i ] ) ) ) 310 { 311 isStandalone = true; 312 break; 313 } 314 } 315 } 316 317 debug( "isStandalone: " + name + " = " + isStandalone ); 318 319 return( isStandalone ); 320 } 321 322 private String 323 getServerJ2EEType( final String name ) 324 { 325 assert( name != null ); 326 327 final String j2eeType = isStandaloneServer( name ) ? 328 XTypes.STANDALONE_SERVER_CONFIG : 329 XTypes.CLUSTERED_SERVER_CONFIG; 330 331 debug( "Server " + name + " is of type " + j2eeType ); 332 return( j2eeType ); 333 } 334 335 public String 336 oldTypeToJ2EEType( final String oldType, final ObjectName objectName ) 337 { 338 String j2eeType = null; 339 340 if ( oldType.equals( objectName.getKeyProperty( "type" ) ) ) 341 { 342 j2eeType = oldObjectNameToJ2EEType( objectName ); 343 } 344 else if ( oldType.equals( OLD_SERVER_TYPE ) ) 345 { 346 final String name = objectName.getKeyProperty( "server" ); 348 assert( name != null ) : "no name in: " + objectName; 349 j2eeType = getServerJ2EEType( name ); 350 } 351 else 352 { 353 j2eeType = mOldTypes.oldTypeToJ2EEType( oldType, objectName ); 354 } 355 return( j2eeType ); 356 } 357 358 public String 359 oldObjectNameToJ2EEType( 360 final ObjectName objectName ) 361 { 362 String j2eeType = null; 363 364 final String oldType = objectName.getKeyProperty( "type" ); 365 if ( oldType.equals( OLD_SERVER_TYPE ) ) 367 { 368 final String name = objectName.getKeyProperty( "name" ); 369 j2eeType = getServerJ2EEType( name ); 370 } 371 else 372 { 373 j2eeType = mOldTypes.oldTypeToJ2EEType( oldType ); 374 } 375 if ( j2eeType == null ) 376 { 377 getLogger().warning( 378 "can't find j2eeType for com.sun.appserv type=" + oldType + 379 StringUtil.NEWLINE() + 380 "This usually means that a new domain.xml element has been added which " + 381 "is not yet supported by AMX. File a bug requesting support, being sure to " + 382 "specify the ObjectName " + StringUtil.quote( objectName ) ); 383 } 384 385 return( j2eeType ); 386 } 387 } 388 389 391 protected ObjectName 392 oldToNewObjectName( final ObjectName oldObjectName ) 393 { 394 trace( "oldToNewObjectName: " + oldObjectName ); 395 final OldTypeToJ2EETypeMapper mapper = new MyOldTypes( ); 396 final OldProps oldProps = new OldProps( oldObjectName, mapper ); 397 final String domainName = mLoader.getAMXJMXDomainName(); 398 399 String props = oldProps.getNewProps(); 400 401 final ObjectName newObjectName = Util.newObjectName( domainName, props ); 403 404 return( newObjectName ); 405 } 406 407 408 409 } 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | Popular Tags |