KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > NodeAgentHelper


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 /*
24  * NodeAgentHelper.java
25  *
26  * Created on October 23, 2003, 11:27 AM
27  */

28
29 package com.sun.enterprise.config.serverbeans;
30
31 import com.sun.enterprise.config.ConfigContext;
32 import com.sun.enterprise.config.ConfigException;
33
34 import com.sun.enterprise.config.serverbeans.Domain;
35 import com.sun.enterprise.config.serverbeans.NodeAgents;
36 import com.sun.enterprise.config.serverbeans.NodeAgent;
37 import com.sun.enterprise.config.serverbeans.Server;
38 import com.sun.enterprise.config.serverbeans.JmxConnector;
39
40 import com.sun.enterprise.security.store.IdentityManager;
41
42 import com.sun.enterprise.admin.util.JMXConnectorConfig;
43 import com.sun.enterprise.admin.util.IAdminConstants;
44
45 import java.util.ArrayList JavaDoc;
46
47 /**
48  *
49  * @author kebbs
50  */

51 public class NodeAgentHelper extends ConfigAPIHelper {
52         
53     public static NodeAgent[] getNodeAgentsInDomain(ConfigContext configContext)
54         throws ConfigException
55     {
56         final Domain domain = getDomainConfigBean(configContext);
57         return domain.getNodeAgents().getNodeAgent();
58     }
59        
60     
61     public static boolean isANodeAgent(ConfigContext configContext, String JavaDoc agentName)
62         throws ConfigException
63     {
64         final Domain domain = getDomainConfigBean(configContext);
65         final NodeAgents controllers = domain.getNodeAgents();
66         if (controllers == null) {
67             return false;
68         }
69         final NodeAgent controller = controllers.getNodeAgentByName(agentName);
70         return (controller != null ? true : false);
71     }
72        
73     public static boolean hasNodeAgentRendezvousd(ConfigContext configContext,
74         NodeAgent agent) throws ConfigException
75     {
76         ElementProperty rendezvousProperty = agent.getElementPropertyByName(
77             IAdminConstants.RENDEZVOUS_PROPERTY_NAME);
78         String JavaDoc rendezvous=rendezvousProperty.getValue();
79         if (rendezvous != null && rendezvousProperty.getValue().equals(Boolean.TRUE.toString())) {
80             return true;
81         }
82         return false;
83     }
84         
85     public static NodeAgent getNodeAgentByName(ConfigContext configContext, String JavaDoc agentName)
86         throws ConfigException
87     {
88         final Domain domain = getDomainConfigBean(configContext);
89         final NodeAgent controller = domain.getNodeAgents().getNodeAgentByName(agentName);
90         if (controller == null) {
91             throw new ConfigException(_strMgr.getString("noSuchAgent",
92                 agentName));
93         }
94         return controller;
95     }
96         
97     public static NodeAgent getNodeAgentForServer(ConfigContext configContext, String JavaDoc instanceName)
98         throws ConfigException
99     {
100         final Server server = ServerHelper.getServerByName(configContext, instanceName);
101         final Domain domain = getDomainConfigBean(configContext);
102         final NodeAgent controller = domain.getNodeAgents().getNodeAgentByName(
103             server.getNodeAgentRef());
104         if (controller == null) {
105             throw new ConfigException(_strMgr.getString("noSuchAgentForInstance",
106                 instanceName, server.getNodeAgentRef()));
107         }
108         return controller;
109     }
110         
111     
112     public static NodeAgent[] getNodeAgentsForCluster(ConfigContext configContext, String JavaDoc clusterName)
113         throws ConfigException
114     {
115         final ArrayList JavaDoc result = new ArrayList JavaDoc();
116         final Server[] servers = ServerHelper.getServersInCluster(configContext, clusterName);
117         for (int i = 0; i < servers.length; i++) {
118             NodeAgent controller = getNodeAgentForServer(configContext,
119                 servers[i].getName());
120             if (!result.contains(controller)) {
121                 result.add(controller);
122             }
123         }
124         return (NodeAgent[])result.toArray(new NodeAgent[result.size()]);
125     }
126    
127     public static JmxConnector getNodeAgentSystemConnector(ConfigContext configContext, String JavaDoc agentName)
128         throws ConfigException
129      {
130         final NodeAgent controller = getNodeAgentByName(configContext, agentName);
131         final String JavaDoc systemConnectorName = controller.getSystemJmxConnectorName();
132         final JmxConnector connector = controller.getJmxConnector();
133         if (connector == null) {
134             throw new ConfigException(_strMgr.getString("noAgentSystemConnector", agentName,
135                 systemConnectorName));
136         }
137         return connector;
138     }
139     
140     /**
141      * Returns mbean server connection info for the named node agent.
142      */

143     public static JMXConnectorConfig getJMXConnectorInfo(ConfigContext configContext, String JavaDoc nodeAgentName)
144         throws ConfigException
145     {
146         JmxConnector connector = NodeAgentHelper.getNodeAgentSystemConnector(
147             configContext, nodeAgentName);
148         String JavaDoc adminUser = IdentityManager.getUser();
149         String JavaDoc adminPassword = IdentityManager.getPassword();
150         ElementProperty hostProp = connector.getElementPropertyByName(HOST_PROPERTY_NAME);
151
152         if (adminUser == null || adminPassword == null || hostProp == null) {
153             throw new ConfigException(_strMgr.getString("missingAgentConnectorAuth", nodeAgentName));
154         }
155         return new JMXConnectorConfig(hostProp.getValue(), connector.getPort(),
156             adminUser, adminPassword, connector.getProtocol());
157     }
158     
159 }
160
Popular Tags