KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > ClusteredServerConfigTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.management.config;
24
25 import java.util.Set JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
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 /**
49  */

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 JavaDoc configName = csc.getReferencedConfigName();
63         final String JavaDoc nodeAgentName = csc.getReferencedNodeAgentName();
64         
65         final Map JavaDoc<String JavaDoc,DeployedItemRefConfig> deployedItems =
66             csc.getDeployedItemRefConfigMap();
67             
68             
69         final Map JavaDoc<String JavaDoc,ResourceRefConfig> resources =
70             csc.getResourceRefConfigMap();
71         
72         final String JavaDoc lbWeight = csc.getLBWeight();
73         csc.setLBWeight( lbWeight );
74     }
75     
76     
77         public ClusteredServerConfig
78     createClusteredServer(
79         final String JavaDoc serverName,
80         final String JavaDoc 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 JavaDoc<String JavaDoc,String JavaDoc> options = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
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 JavaDoc<String JavaDoc> j2eeTypes =
121             GSetUtil.newUnmodifiableStringSet(
122                 XTypes.DEPLOYED_ITEM_REF_CONFIG, XTypes.RESOURCE_REF_CONFIG );
123         
124         final Set JavaDoc<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 JavaDoc 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 JavaDoc name = servers[ i ].getName();
168                 domainConfig.removeClusteredServerConfig( name );
169                 printVerbose( "Removed ClusteredServerConfig: " + name );
170             }
171             
172         }
173     }
174  
175 }
176
177
178
Popular Tags