1 9 10 package com.sun.enterprise.cli.commands; 11 12 import com.sun.appserv.server.util.Version; 13 import com.sun.enterprise.admin.servermgmt.DomainConfig; 14 import com.sun.enterprise.admin.servermgmt.pe.PEFileLayout; 15 import com.sun.enterprise.cli.framework.CLILogger; 16 import com.sun.enterprise.config.ConfigContext; 17 import com.sun.enterprise.config.ConfigException; 18 import com.sun.enterprise.config.ConfigFactory; 19 import com.sun.enterprise.config.serverbeans.HttpListener; 20 import com.sun.enterprise.config.serverbeans.IiopListener; 21 import com.sun.enterprise.config.serverbeans.JavaConfig; 22 import com.sun.enterprise.config.serverbeans.JmxConnector; 23 import com.sun.enterprise.config.serverbeans.ServerHelper; 24 import com.sun.enterprise.config.serverbeans.WebModule; 25 import com.sun.enterprise.util.SystemPropertyConstants; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 import com.sun.enterprise.util.i18n.StringManager; 29 33 public class DomainReporter { 34 35 private final boolean detailed; 36 private final DomainConfig dc; 37 private static final CLILogger logger = CLILogger.getInstance(); 38 private static final StringManager lsm = StringManager.getManager(DomainReporter.class); 39 private final List <String > records = new ArrayList <String >(); 40 private ConfigContext cc = null; private String sn = null; 43 DomainReporter(final DomainConfig dc) { 44 this(dc, false); 45 } 46 DomainReporter(final DomainConfig dc, final boolean terse) { 47 this.dc = dc; 48 this.detailed = !terse; 49 } 50 51 void report() throws ConfigException { 52 prepare(); 53 display(); 54 } 55 56 private void prepare() throws ConfigException { 57 final PEFileLayout layout = new PEFileLayout(dc); 58 final String xmlPath = layout.getDomainConfigFile().getAbsolutePath(); 59 this.cc = ConfigFactory.createConfigContext(xmlPath, true, false, false, true); 60 this.sn = SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME; 61 62 final String ver = Version.getFullVersion(); 63 records.add(getDomainBanner(dc.getDomainName(), ver, dc.getDomainRoot())); 64 if (detailed) { 65 records.add(getAdminConsoleMessage()); 66 records.add(getHttpUrlsMessage()); 67 records.add(getWebContextsMessage()); 68 records.add(getJmxServiceUrlMessage()); 69 records.add(getOccupiedPorts()); 70 records.add(getDebugMessage()); 71 } 72 } 73 74 private String getDomainBanner(final String dn, final String version, final String dr) { 75 return ( lsm.getString("domain.report.banner", dn, version, dr)); 76 } 77 78 private String getDebugMessage() throws ConfigException { 79 String msg = ""; 80 boolean debugMode = false; 81 try{ 82 debugMode = (Boolean )dc.get(DomainConfig.K_DEBUG); 83 } catch(final Exception e) {} if (debugMode) { 85 final JavaConfig jc = ServerHelper.getConfigForServer(cc, sn).getJavaConfig(); 86 final String dopt = jc.getDebugOptions(); 87 msg = lsm.getString("start.debug.msg", dopt); 88 } 89 return ( msg ); 90 } 91 private String getAdminConsoleMessage() throws ConfigException { 92 final HttpListener admin = ServerHelper.getHttpListener(cc, sn, ServerHelper.ADMIN_HTTP_LISTNER_ID); 93 String url = "", port = null; 94 if (admin != null) { 95 url = ServerHelper.getUrlString(admin); 96 port = admin.getPort(); 97 } 98 return ( lsm.getString("admin.console.msg", url, port) ); 99 } 100 private String getHttpUrlsMessage() throws ConfigException { 101 final HttpListener[] lss = ServerHelper.getHttpListeners(cc, sn); 102 String urls = ""; 103 if (lss != null) { 104 for (final HttpListener ls : lss) { 105 if (ServerHelper.ADMIN_HTTP_LISTNER_ID.equals(ls.getId())) 106 continue; if (ls.isEnabled()) { 108 urls += ServerHelper.getUrlString(ls); 109 urls += " "; 110 } 111 } 112 } 113 return ( lsm.getString("http.listeners.msg", urls) ); 114 } 115 private String getWebContextsMessage() throws ConfigException { 116 final WebModule[] wms = ServerHelper.getAssociatedWebModules(cc, sn); 117 String crs = ""; 118 for (final WebModule wm : wms) { 119 crs += wm.getContextRoot(); 120 crs += " "; 121 } 122 return ( lsm.getString("web.contexts.msg", crs) ); 123 } 124 125 private String getJmxServiceUrlMessage() throws ConfigException { 126 String url = ""; 127 final JmxConnector sjc = ServerHelper.getServerSystemConnector(cc, sn); 128 if (sjc != null) { 129 url += ServerHelper.getJmxServiceUrl(sjc); 130 } 131 return ( lsm.getString("jmx.connector.msg", url) ); 132 } 133 private String getOccupiedPorts() throws ConfigException { 134 String ports = ""; 135 ports = getHttpPorts() + getIiopPorts() + getJmxConnectorPorts(); 136 return ( lsm.getString("ports.msg", ports) ); 137 } 138 private String getHttpPorts() throws ConfigException { 139 String hp = ""; 140 final HttpListener[] hss = ServerHelper.getConfigForServer(cc, sn).getHttpService().getHttpListener(); 141 for (final HttpListener hs : hss) { 142 if (hs.isEnabled()) { 143 hp += hs.getPort(); 144 hp += " "; 145 } 146 } 147 return ( hp ); 148 } 149 private String getIiopPorts() throws ConfigException { 150 String ip = ""; 151 final IiopListener[] ils = ServerHelper.getConfigForServer(cc, sn).getIiopService().getIiopListener(); 152 for (final IiopListener is : ils) { 153 if (is.isEnabled()) { 154 ip += is.getPort(); 155 ip += " "; 156 } 157 } 158 return ( ip ); 159 } 160 private String getJmxConnectorPorts() throws ConfigException { 161 String jp = ""; 162 final JmxConnector[] jcs = ServerHelper.getConfigForServer(cc, sn).getAdminService().getJmxConnector(); 163 for (final JmxConnector jc : jcs) { 164 if (jc.isEnabled()) { 165 jp += jc.getPort(); 166 jp += " "; 167 } 168 } 169 return ( jp ); 170 } 171 172 private void display() { 173 for (final String record : records) { 174 logger.printMessage(record); 175 } 176 } 177 } 178 | Popular Tags |