1 23 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 ; 46 47 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 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 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 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 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 clusterName) 113 throws ConfigException 114 { 115 final ArrayList result = new ArrayList (); 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 agentName) 128 throws ConfigException 129 { 130 final NodeAgent controller = getNodeAgentByName(configContext, agentName); 131 final String 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 143 public static JMXConnectorConfig getJMXConnectorInfo(ConfigContext configContext, String nodeAgentName) 144 throws ConfigException 145 { 146 JmxConnector connector = NodeAgentHelper.getNodeAgentSystemConnector( 147 configContext, nodeAgentName); 148 String adminUser = IdentityManager.getUser(); 149 String 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 |