1 23 24 29 30 package com.sun.enterprise.config.serverbeans; 31 32 import com.sun.enterprise.admin.util.IAdminConstants; 33 import com.sun.enterprise.config.ConfigContext; 34 import com.sun.enterprise.config.ConfigException; 35 import com.sun.enterprise.config.ConfigFactory; 36 import com.sun.enterprise.util.SystemPropertyConstants; 37 import java.util.HashMap ; 38 import java.util.Map ; 39 40 42 public class AppserverClusterViewFromCacheRepository { 43 44 private final String myName; 45 private final ConfigContext domainCC; 46 public AppserverClusterViewFromCacheRepository(final String domainXmlUrl) throws ConfigException { 47 if (domainXmlUrl == null) { 48 throw new IllegalArgumentException ("null_arg"); 49 } 50 myName = System.getProperty(SystemPropertyConstants.SERVER_NAME); 51 final String url = domainXmlUrl; 52 domainCC = ConfigFactory.createConfigContext(url, true, true, false, false); 53 } 54 55 public ConfigContext getUnResolvedConfigContext(){ 56 return domainCC; 57 } 58 59 public Map <String , JmsHost> getResolvedLocalJmsHostsInCluster(final String clusterName) throws ConfigException { 60 final Map <String , JmsHost> map = new HashMap <String , JmsHost> (); 61 final String myCluster = ClusterHelper.getClusterByName(domainCC, clusterName).getName(); 62 final Server[] buddies = ServerHelper.getServersInCluster(domainCC, myCluster); 63 for (final Server as : buddies) { 64 final JmsHost copy = getResolvedJmsHost(as); 65 map.put(as.getName(), copy); 66 } 67 return map; 68 } 69 70 71 public Map <String , JmsHost> getResolvedLocalJmsHostsInMyCluster(final boolean includeMe) throws ConfigException { 72 final Map <String , JmsHost> map = new HashMap <String , JmsHost> (); 73 if (ServerHelper.isServerClustered(domainCC, myName)) { 74 final String myCluster = ClusterHelper.getClusterForInstance(domainCC, myName).getName(); 75 final Server[] buddies = ServerHelper.getServersInCluster(domainCC, myCluster); 76 for (final Server as : buddies) { 77 if (!includeMe && myName.equals(as.getName())) 78 continue; 79 final JmsHost copy = getResolvedJmsHost(as); 80 map.put(as.getName(), copy); 81 } 82 } 83 return ( map ); 84 } 85 86 public JmsHost getResolvedJmsHost(final Server as) throws ConfigException{ 87 final JmsHost jmsHost = getResolvedLocalJmsHostInServer(as); 88 final JmsHost copy = new JmsHost(); 89 final String hostName = getNodeAgentHostName(as); 90 if (jmsHost != null) { 91 copy.setHost(hostName); 92 copy.setName(jmsHost.getName()); 93 final String resolved = this.resolve(as.getName(), SystemPropertyConstants.unSystemProperty(jmsHost.getPort())); 94 copy.setPort(resolved); 95 copy.setAdminPassword(jmsHost.getAdminPassword()); 96 copy.setAdminUserName(jmsHost.getAdminUserName()); 97 } 98 99 return copy; 100 } 101 102 public Map <String , JmsHost> getResolvedLocalJmsHostsInMyCluster() throws ConfigException { 103 return ( this.getResolvedLocalJmsHostsInMyCluster(false) ); 104 } 105 106 public Map <String , IiopListener[]> getResolvedIiopListenersInCluster(final boolean includeMe) throws ConfigException { 107 final Map <String , IiopListener[]> map = new HashMap <String , IiopListener[]> (); 108 if (ServerHelper.isServerClustered(domainCC, myName)) { 109 final String myCluster = ClusterHelper.getClusterForInstance(domainCC, myName).getName(); 110 final Server[] buddies = ServerHelper.getServersInCluster(domainCC, myCluster); 111 for (final Server as : buddies) { 112 if (!includeMe && myName.equals(as.getName())) 113 continue; 114 final IiopListener[] ls = getResolvedIiopListenersInServer(as); 115 map.put(as.getName(), ls); 116 } 117 } 118 return ( map ); 119 } 120 121 public Map <String , IiopListener[]> getResolvedIiopListenersInCluster() throws ConfigException { 122 return ( this.getResolvedIiopListenersInCluster(false) ); 123 } 124 125 private JmsHost getResolvedLocalJmsHostInServer(final Server server) throws ConfigException { 126 final Config cfg = ServerHelper.getConfigForServer(domainCC, server.getName()); 127 final JmsService jmsService = cfg.getJmsService(); 128 JmsHost jmsHost = null; 129 if (JMSServiceType.LOCAL.toString().equals(jmsService.getType())) { 130 jmsHost = getDefaultJmsHost(jmsService); 131 } 132 return ( jmsHost ); 133 } 134 135 private JmsHost getDefaultJmsHost(final JmsService jmsService) { 136 final JmsHost[] jmsHosts = jmsService.getJmsHost(); 137 final String defaultHostName = jmsService.getDefaultJmsHost(); 138 JmsHost defaultJmsHost = null; 139 for (final JmsHost h : jmsHosts) { 140 final String name = h.getName(); 141 if (name.equals(defaultHostName)) { 142 defaultJmsHost = h; 143 break; 144 } 145 } 146 return ( defaultJmsHost ); 147 } 148 public String getNodeAgentHostName(final Server as) throws ConfigException { 149 final NodeAgent na = NodeAgentHelper.getNodeAgentForServer(domainCC, as.getName()); 150 final boolean dasShookHandsWithNodeAgent = NodeAgentHelper.hasNodeAgentRendezvousd(domainCC, na); 151 if (! dasShookHandsWithNodeAgent) 152 throw new RuntimeException ("Error: NA: " + na.getName() + " has not rendezvous'ed with DAS"); 153 final String naHost = NodeAgentHelper.getNodeAgentSystemConnector(domainCC, na.getName()).getElementPropertyByName(IAdminConstants.HOST_PROPERTY_NAME).getValue(); 154 return ( naHost ); 155 } 156 private IiopListener[] getResolvedIiopListenersInServer(final Server server) throws ConfigException { 157 final Config cfg = ServerHelper.getConfigForServer(domainCC, server.getName()); 158 final IiopService iiop = cfg.getIiopService(); 159 final IiopListener[] lsnrs = iiop.getIiopListener(); 160 final IiopListener[] values = new IiopListener[lsnrs.length]; 161 int i = 0; 162 for (final IiopListener lsnr : lsnrs) { 163 final IiopListener copy = new IiopListener(); String resolved = resolve(server.getName(), SystemPropertyConstants.unSystemProperty(lsnr.getId())); 165 copy.setId(resolved); 166 resolved = resolve(server.getName(), SystemPropertyConstants.unSystemProperty(lsnr.getPort())); 167 copy.setPort(resolved); 168 resolved = resolve(server.getName(), SystemPropertyConstants.unSystemProperty(lsnr.getAddress())); 169 copy.setAddress(resolved); 170 System.out.println("Iiop Service Endpoint for Server: " + server.getName() + ", iiop-lsnr-id = " + copy.getId() + ", iiop-lsnr-port = " + copy.getPort() + ", iiop-lsnr-address = " + copy.getAddress()); 171 values[i++] = copy; 172 } 173 return ( values ); 174 } 175 private String resolve(final String server, final String value) throws ConfigException { 176 final PropertyResolver pr = new PropertyResolver(domainCC, server); 177 String resolved = pr.getPropertyValue(value, true); 178 if (resolved == null) resolved = value; 180 return ( resolved ); 181 } 182 } 183 enum JMSServiceType { 184 LOCAL, 185 REMOTE, 186 EMBEDDED 187 } 188 | Popular Tags |