1 23 package com.sun.enterprise.management.j2ee; 24 25 import java.io.IOException ; 26 import java.util.Iterator ; 27 import java.util.Set ; 28 import java.util.HashSet ; 29 import java.util.Map ; 30 import java.util.Date ; 31 import java.util.Collections ; 32 33 import javax.management.ObjectName ; 34 35 import com.sun.appserv.management.base.QueryMgr; 36 import com.sun.appserv.management.base.Util; 37 import com.sun.appserv.management.base.AMX; 38 import com.sun.appserv.management.base.XTypes; 39 40 import com.sun.appserv.management.config.AMXConfig; 41 import com.sun.appserv.management.config.ServerConfig; 42 import com.sun.appserv.management.config.ClusterConfig; 43 44 import com.sun.appserv.management.j2ee.J2EETypes; 45 import com.sun.appserv.management.j2ee.JVM; 46 import com.sun.appserv.management.j2ee.J2EEManagedObject; 47 import com.sun.appserv.management.j2ee.J2EEServer; 48 import com.sun.appserv.management.j2ee.J2EECluster; 49 import com.sun.appserv.management.j2ee.StateManageable; 50 import com.sun.appserv.management.j2ee.EventProvider; 51 52 import com.sun.appserv.management.monitor.Monitoring; 53 54 import com.sun.appserv.management.util.misc.GSetUtil; 55 import com.sun.appserv.management.util.misc.MapUtil; 56 import com.sun.appserv.management.util.misc.CollectionUtil; 57 import com.sun.appserv.management.util.misc.ExceptionUtil; 58 59 60 import com.sun.enterprise.management.AMXTestBase; 61 import com.sun.enterprise.management.Capabilities; 62 63 64 66 public final class J2EETest extends AMXTestBase 67 { 68 public 69 J2EETest( ) 70 throws IOException 71 { 72 turnOnMonitoring(); 73 } 74 75 private static boolean FAILURES_WARNED = false; 76 77 public static Capabilities 78 getCapabilities() 79 { 80 return getOfflineCapableCapabilities( false ); 81 } 82 83 86 public void 87 testJ2EEServerMatchesServerConfig() 88 { 89 final Map <String ,ServerConfig> serverConfigMap = 90 getDomainConfig().getServerConfigMap(); 91 92 final Map <String ,J2EEServer> j2eeServerMap = 93 getDomainRoot().getJ2EEDomain().getJ2EEServerMap(); 94 95 assert( serverConfigMap.keySet().equals( j2eeServerMap.keySet() ) ) : 96 "ServerConfig names do not match J2EEServer names, ServerConfig names = " + 97 toString( serverConfigMap.keySet() ) + ", J2EEServer names = " + 98 toString( j2eeServerMap.keySet() ); 99 100 } 101 102 103 106 public void 107 testJ2EEClusterMatchesClusterConfig() 108 { 109 final Map <String ,ClusterConfig> clusterConfigMap = getDomainConfig().getClusterConfigMap(); 110 final Map <String ,J2EECluster> j2eeClusterMap = getJ2EEDomain().getJ2EEClusterMap(); 111 112 assert( clusterConfigMap.keySet().equals( j2eeClusterMap.keySet() ) ) : 113 "ClusterConfig names do not match J2EECluster names, ClusterConfig names = " + 114 toString( clusterConfigMap.keySet() ) + ", J2EECluster names = " + 115 toString( j2eeClusterMap.keySet() ); 116 } 117 118 public void 119 testJVMs() 120 { 121 final QueryMgr queryMgr = getQueryMgr(); 122 123 final Set jvms = queryMgr.queryJ2EETypeSet( J2EETypes.JVM ); 124 final Iterator iter = jvms.iterator(); 125 126 String lastVendor = null; 127 String lastVersion = null; 128 while ( iter.hasNext() ) 129 { 130 final JVM jvm = (JVM)iter.next(); 131 132 assert( jvm.getnode() != null ); 134 135 assert( jvm.getjavaVendor() != null ); 137 if ( lastVendor == null ) 138 { 139 lastVendor = jvm.getjavaVendor(); 140 } 141 else 142 { 143 assert( lastVendor.equals( jvm.getjavaVendor() ) ); 144 } 145 146 assert( jvm.getjavaVersion() != null ); 148 if ( lastVersion == null ) 149 { 150 lastVersion = jvm.getjavaVersion(); 151 } 152 else 153 { 154 assert( lastVersion.equals( jvm.getjavaVersion() ) ); 155 } 156 } 157 } 158 159 private boolean 160 appearsToBeDefaultWebModule( final String webModuleName ) 161 { 162 return webModuleName.startsWith( "//" ) && webModuleName.endsWith( "/" ); 163 } 164 165 168 private static final Map <String ,String > ToConfigMap = MapUtil.newMap( new String [] 169 { 170 J2EETypes.J2EE_DOMAIN, XTypes.DOMAIN_CONFIG, 171 J2EETypes.J2EE_CLUSTER, XTypes.CLUSTER_CONFIG, 172 J2EETypes.J2EE_SERVER, XTypes.STANDALONE_SERVER_CONFIG, 173 J2EETypes.JVM, XTypes.JAVA_CONFIG, 174 175 J2EETypes.J2EE_APPLICATION, XTypes.J2EE_APPLICATION_CONFIG, 176 J2EETypes.EJB_MODULE, XTypes.EJB_MODULE_CONFIG, 177 J2EETypes.WEB_MODULE, XTypes.WEB_MODULE_CONFIG, 178 J2EETypes.APP_CLIENT_MODULE, XTypes.APP_CLIENT_MODULE_CONFIG, 179 180 J2EETypes.JAVA_MAIL_RESOURCE, XTypes.MAIL_RESOURCE_CONFIG, 181 J2EETypes.JDBC_RESOURCE, XTypes.JDBC_RESOURCE_CONFIG, 182 J2EETypes.JNDI_RESOURCE, XTypes.JNDI_RESOURCE_CONFIG, 183 J2EETypes.WEB_SERVICE_ENDPOINT, XTypes.WEB_SERVICE_ENDPOINT_CONFIG, 184 } 185 ); 186 187 private static String 188 getConfigPeerJ2EEType( final String j2eeType ) 189 { 190 return ToConfigMap.get( j2eeType ); 191 } 192 193 196 private static final Map <String ,String > ToMonitorMap = 197 Collections.unmodifiableMap( MapUtil.newMap( new String [] 198 { 199 J2EETypes.J2EE_SERVER, XTypes.SERVER_ROOT_MONITOR, 200 J2EETypes.J2EE_APPLICATION, XTypes.APPLICATION_MONITOR, 201 202 J2EETypes.WEB_MODULE, XTypes.WEB_MODULE_VIRTUAL_SERVER_MONITOR, 203 J2EETypes.SERVLET, XTypes.SERVLET_MONITOR, 204 205 J2EETypes.EJB_MODULE, XTypes.EJB_MODULE_MONITOR, 206 J2EETypes.STATELESS_SESSION_BEAN, XTypes.STATELESS_SESSION_BEAN_MONITOR, 207 J2EETypes.STATEFUL_SESSION_BEAN, XTypes.STATEFUL_SESSION_BEAN_MONITOR, 208 J2EETypes.ENTITY_BEAN, XTypes.ENTITY_BEAN_MONITOR, 209 J2EETypes.MESSAGE_DRIVEN_BEAN, XTypes.MESSAGE_DRIVEN_BEAN_MONITOR, 210 })); 211 212 private static final Set <String > HasNoStats = 214 GSetUtil.newUnmodifiableStringSet( J2EETypes.J2EE_SERVER ); 215 216 217 protected String 218 getMonitoringPeerJ2EEType( final String j2eeType ) 219 { 220 return ToMonitorMap.get( j2eeType ); 221 } 222 223 protected String 224 getMonitoringPeerProps( final J2EEManagedObject item ) 225 { 226 final String j2eeType = item.getJ2EEType(); 227 final String monitoringPeerJ2EEType = getMonitoringPeerJ2EEType( j2eeType ); 228 final ObjectName objectName = Util.getObjectName( item ); 229 230 String props = null; 231 if ( monitoringPeerJ2EEType != null ) 232 { 233 props = Util.makeRequiredProps( monitoringPeerJ2EEType, item.getName() ); 234 235 for( final String propKey : ToMonitorMap.keySet() ) 236 { 237 final String value = objectName.getKeyProperty( propKey ); 238 if ( value != null ) 239 { 240 final String prop = 241 Util.makeProp( getMonitoringPeerJ2EEType( propKey ), value ); 242 props = Util.concatenateProps( props, prop ); 243 } 244 } 245 } 246 247 return props; 248 } 249 250 public void 251 testJ2EE() 252 throws ClassNotFoundException 253 { 254 final QueryMgr queryMgr = getQueryMgr(); 255 256 final Set <J2EEManagedObject> j2eeAll = 257 queryMgr.queryInterfaceSet( J2EEManagedObject.class.getName(), null); 258 259 final Set <ObjectName > failedSet = new HashSet <ObjectName >(); 260 final Set <ObjectName > noPeerSet = new HashSet <ObjectName >(); 261 262 for( final J2EEManagedObject item : j2eeAll ) 263 { 264 final ObjectName objectName = Util.getObjectName( item ); 265 assert( objectName.equals( Util.newObjectName( item.getobjectName() ) ) ); 266 267 final String j2eeType = item.getJ2EEType(); 268 269 if ( item.isstateManageable() ) 270 { 271 assert( item instanceof StateManageable ); 272 273 final StateManageable sm = (StateManageable)item; 274 275 final int state = sm.getstate(); 276 assert( state == StateManageable.STATE_STARTING || 277 state == StateManageable.STATE_RUNNING || 278 state == StateManageable.STATE_STOPPING || 279 state == StateManageable.STATE_STOPPED || 280 state == StateManageable.STATE_FAILED ); 281 282 if ( state == StateManageable.STATE_RUNNING ) 283 { 284 try 285 { 286 final long startTime = sm.getstartTime(); 287 288 final long MILLIS_PER_DAY = 24L * 60L * 60L * 1000L; 290 final long days30 = 30L * MILLIS_PER_DAY; 291 if ( startTime < now() - days30 ) 292 { 293 warning( "MBean " + quote( objectName ) + 294 " claims a start time of " + new Date ( startTime ) + ", which is more than 30 days prior to now = " + 295 new Date ( now() ) ); 296 failedSet.add( objectName ); 297 } 298 } 299 catch( Exception e ) 300 { 301 final Throwable rootCause = ExceptionUtil.getRootCause( e ); 302 warning( "MBean " + quote( objectName ) + 303 " is 'stateManageable' and in 'STATE_RUNNING', but could not supply Attribute 'startTime', " + 304 "threw an exception of class " + 305 rootCause.getClass().getName() ); 306 failedSet.add( objectName ); 307 } 308 } 309 } 310 311 if ( item.iseventProvider() ) 312 { 313 assert( item instanceof EventProvider ); 314 315 final EventProvider ep = (EventProvider)item; 316 final String [] types = ep.gettypes(); 317 assert types != null : 318 "Item claims to be EventProvider, but provides null 'types': " + 319 toString( objectName ); 320 } 321 322 327 final String monitoringPeerJ2EEType = getMonitoringPeerJ2EEType( j2eeType ); 328 final Monitoring monitoringPeer = item.getMonitoringPeer(); 329 if ( monitoringPeerJ2EEType != null ) 330 { 331 if ( monitoringPeer == null ) 333 { 334 final String props = getMonitoringPeerProps( item ); 335 final Set <Monitoring> monitors = getQueryMgr().queryPropsSet( props ); 336 if ( monitors.size() != 0 ) 337 { 338 warning( "MBean " + quote( objectName ) + 339 " returned null for its monitoring peer, but found the following:" + 340 NEWLINE + 341 CollectionUtil.toString( Util.toObjectNames( monitors ), NEWLINE ) ); 342 343 failedSet.add( objectName ); 344 } 345 } 346 else 347 { 348 if ( ! HasNoStats.contains( j2eeType ) ) 351 { 352 assert item.isstatisticProvider() && item.isstatisticsProvider(); 353 } 354 } 355 } 356 else 357 { 358 if ( item.isstatisticProvider() || item.isstatisticsProvider() ) 360 { 361 warning( "MBean " + quote( objectName ) + 362 " should not have its statisticProvider set to true" ); 363 failedSet.add( objectName ); 364 } 365 } 366 367 368 if ( item.isConfigProvider() ) 369 { 370 final AMXConfig config = item.getConfigPeer(); 371 372 if ( config == null ) 373 { 374 final String props = Util.makeRequiredProps( 376 getConfigPeerJ2EEType( j2eeType ), item.getName() ); 377 378 if ( getQueryMgr().queryPropsSet( props ).size() != 0 ) 379 { 380 warning( "MBean " + quote( objectName ) + 381 " has existing config peer, but returned null" ); 382 failedSet.add( objectName ); 383 } 384 } 385 } 386 } 387 388 if ( noPeerSet.size() != 0 ) 389 { 390 warning( "The following MBeans do not have a Monitoring peer:" + 391 NEWLINE + toString( noPeerSet ) ); 392 393 } 394 395 if( failedSet.size() != 0 ) 396 { 397 failure( "Failures in the following " + failedSet.size() + " MBeans:\n" + 398 toString( failedSet ) ); 399 } 400 } 401 } 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | Popular Tags |