1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Set ; 26 import java.util.Map ; 27 import java.util.HashMap ; 28 29 import com.sun.appserv.management.base.XTypes; 30 import com.sun.appserv.management.base.Util; 31 32 import com.sun.appserv.management.config.DomainConfig; 33 import com.sun.appserv.management.config.Enabled; 34 import com.sun.appserv.management.config.ClusteredServerConfig; 35 import com.sun.appserv.management.config.DeployedItemRefConfig; 36 import com.sun.appserv.management.config.ResourceRefConfig; 37 import com.sun.appserv.management.config.NodeAgentConfig; 38 import com.sun.appserv.management.config.ClusterConfig; 39 import com.sun.appserv.management.config.RefConfig; 40 41 import com.sun.appserv.management.util.misc.GSetUtil; 42 43 import com.sun.enterprise.management.AMXTestBase; 44 import com.sun.enterprise.management.ClusterSupportRequired; 45 46 import com.sun.enterprise.management.PropertyKeys; 47 48 50 public final class ClusteredServerConfigTest extends AMXTestBase 51 implements ClusterSupportRequired 52 { 53 public ClusteredServerConfigTest() 54 { 55 } 56 57 private void 58 sanityCheck( final ClusteredServerConfig csc ) 59 { 60 assert XTypes.CLUSTERED_SERVER_CONFIG.equals( csc.getJ2EEType() ); 61 62 final String configName = csc.getReferencedConfigName(); 63 final String nodeAgentName = csc.getReferencedNodeAgentName(); 64 65 final Map <String ,DeployedItemRefConfig> deployedItems = 66 csc.getDeployedItemRefConfigMap(); 67 68 69 final Map <String ,ResourceRefConfig> resources = 70 csc.getResourceRefConfigMap(); 71 72 final String lbWeight = csc.getLBWeight(); 73 csc.setLBWeight( lbWeight ); 74 } 75 76 77 public ClusteredServerConfig 78 createClusteredServer( 79 final String serverName, 80 final String nodeAgentName, 81 final int basePort ) 82 { 83 final DomainConfig domainConfig = getDomainConfig(); 84 85 if ( domainConfig.getClusteredServerConfigMap().get( serverName ) != null ) 86 { 87 domainConfig.removeClusteredServerConfig( serverName ); 88 } 89 else if ( domainConfig.getStandaloneServerConfigMap().get( serverName ) != null ) 90 { 91 domainConfig.removeStandaloneServerConfig( serverName ); 92 } 93 94 final ClusterConfig clusterConfig = 95 ClusterConfigTest.ensureDefaultInstance( domainConfig ); 96 97 if ( domainConfig.getClusteredServerConfigMap().get( serverName ) != null ) 98 { 99 domainConfig.removeClusteredServerConfig( serverName ); 100 assert domainConfig.getClusteredServerConfigMap().get( serverName ) == null; 101 } 102 103 final ConfigSetup setup = new ConfigSetup( getDomainRoot() ); 104 final Map <String ,String > options = new HashMap <String ,String >(); 105 setup.setupServerPorts( options, basePort ); 106 107 final ClusteredServerConfig csc = 108 domainConfig.createClusteredServerConfig( serverName, 109 clusterConfig.getName(), 110 nodeAgentName, 111 options ); 112 sanityCheck( csc ); 113 114 return csc; 115 } 116 117 private void 118 verifyRefContainers() 119 { 120 final Set <String > j2eeTypes = 121 GSetUtil.newUnmodifiableStringSet( 122 XTypes.DEPLOYED_ITEM_REF_CONFIG, XTypes.RESOURCE_REF_CONFIG ); 123 124 final Set <RefConfig> refs = getQueryMgr().queryJ2EETypesSet( j2eeTypes ); 125 126 for( final RefConfig ref : refs ) 127 { 128 assert ref.getContainer() != null : 129 "MBean " + Util.getObjectName( ref ) + " return null from getContainer()"; 130 } 131 } 132 133 public void 134 testCreateRemove() 135 { 136 final DomainConfig domainConfig = getDomainConfig(); 137 final NodeAgentConfig nodeAgentConfig = getDASNodeAgentConfig(); 138 139 if ( nodeAgentConfig == null ) 140 { 141 warning( "SKIPPING ClusteredServerConfigTest.testCreateRemove: " + 142 "no DAS Node Agent has been specified; use " + 143 PropertyKeys.DAS_NODE_AGENT_NAME ); 144 } 145 else 146 { 147 final int NUM = 5; 148 final String baseName = "ClusteredServerConfigTest"; 149 150 verifyRefContainers(); 151 152 final ClusteredServerConfig[] servers = new ClusteredServerConfig[ NUM ]; 153 for( int i = 0; i < NUM; ++i ) 154 { 155 final int basePort = 11000 + i * 10; 156 servers[ i ] = createClusteredServer( baseName + "-" + i, 157 nodeAgentConfig.getName(), 158 basePort ); 159 printVerbose( "Created ClusteredServerConfig: " + servers[ i ].getName() ); 160 assert XTypes.CLUSTERED_SERVER_CONFIG.equals( servers[ i ].getJ2EEType() ); 161 162 verifyRefContainers(); 163 } 164 165 for( int i = 0; i < NUM; ++i ) 166 { 167 final String name = servers[ i ].getName(); 168 domainConfig.removeClusteredServerConfig( name ); 169 printVerbose( "Removed ClusteredServerConfig: " + name ); 170 } 171 172 } 173 } 174 175 } 176 177 178 | Popular Tags |