001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.fabric.tasks;
006:
007: import com.sun.portal.admin.common.context.PSConfigContext;
008: import com.sun.portal.fabric.util.NetworkUtil;
009: import com.sun.portal.fabric.util.FileUtil;
010: import com.sun.portal.fabric.util.ClasspathGenUtil;
011: import com.sun.portal.monitoring.MonitoringConfiguration;
012: import com.sun.portal.monitoring.MonitoringException;
013: import com.sun.portal.log.common.PortalLogger;
014:
015: import com.sun.portal.util.Platform;
016:
017: import java.util.Properties;
018: import java.util.logging.Level;
019: import java.util.logging.Logger;
020: import java.util.logging.LogRecord;
021: import java.io.FileInputStream;
022: import java.io.File;
023: import java.io.IOException;
024:
025: public class MonitoringConfigurationHelper {
026: public static String fs = Platform.fs;
027:
028: // private static String KEY_HTML_ADAPTOR_PORT = "com.sun.portal.monitoring.MonitoringContext.html.adaptor.port";
029: private static String KEY_JMX_MP_PORT = "com.sun.portal.monitoring.security.ssl.SslContext.port";
030: // private static String KEY_NEXT_AVAIL_HTML_ADAPTOR_PORT = "com.sun.portal.fabric.tasks.MonitoringConfigurationHelper.html.adaptor.next.available.port";
031: private static String KEY_NEXT_AVAIL_JMX_MP_PORT = "com.sun.portal.fabric.tasks.MonitoringConfigurationHelper.ssl.SslContext.next.available.port";
032: private static Logger logger = PortalLogger
033: .getLogger(MonitoringConfigurationHelper.class);
034:
035: public static void configurePropertyFile(
036: String monitoringPropertiesFile, String host,
037: PSConfigContext context) {
038: try {
039: // ports configuration
040: String monitoringPortConfigFile = context.getPSConfigDir()
041: + fs + "MonitoringPortConfig.properties";
042: Properties portConfigProperties = new Properties();
043: portConfigProperties.load(new FileInputStream(
044: monitoringPortConfigFile));
045:
046: Properties properties = new Properties();
047: properties.load(new FileInputStream(
048: monitoringPropertiesFile));
049:
050: /*
051: String nextAvailableHtmlAdaptorPort = portConfigProperties.getProperty(KEY_NEXT_AVAIL_HTML_ADAPTOR_PORT);
052: String htmlAdaptorPort = properties.getProperty(KEY_HTML_ADAPTOR_PORT);
053: nextAvailableHtmlAdaptorPort = NetworkUtil.getNextAvailablePort(host, nextAvailableHtmlAdaptorPort);
054: if(nextAvailableHtmlAdaptorPort != null && !nextAvailableHtmlAdaptorPort.equals(htmlAdaptorPort)){
055: FileUtil.replaceTokenInFile(new File(monitoringPropertiesFile), htmlAdaptorPort, nextAvailableHtmlAdaptorPort);
056: logger.log(Level.INFO, "Configured HTML Adaptor port in <" + monitoringPropertiesFile + "> as "+ nextAvailableHtmlAdaptorPort);
057: }
058: */
059:
060: String nextAvailableJmxMpPort = portConfigProperties
061: .getProperty(KEY_NEXT_AVAIL_JMX_MP_PORT);
062: String jmxMpPort = properties.getProperty(KEY_JMX_MP_PORT);
063: nextAvailableJmxMpPort = NetworkUtil.getNextAvailablePort(
064: host, nextAvailableJmxMpPort);
065: if (nextAvailableJmxMpPort != null
066: && !nextAvailableJmxMpPort.equals(jmxMpPort)) {
067: FileUtil.replaceTokenInFile(new File(
068: monitoringPropertiesFile), jmxMpPort,
069: nextAvailableJmxMpPort);
070: logger.log(Level.INFO, "PSFB_CSPFT0247", new Object[] {
071: monitoringPropertiesFile,
072: nextAvailableJmxMpPort });
073: }
074:
075: int nextPort = 0;
076: try {
077: /*
078: nextPort = Integer.parseInt(nextAvailableHtmlAdaptorPort) + 1;
079: FileUtil.replaceTokenInFile(new File(monitoringPortConfigFile), nextAvailableHtmlAdaptorPort, new Integer(nextPort).toString());
080: logger.log(Level.INFO, "Next available HTML Adaptor port is set as " + nextPort);
081: */
082:
083: nextPort = Integer.parseInt(nextAvailableJmxMpPort) + 1;
084: FileUtil.replaceTokenInFile(new File(
085: monitoringPortConfigFile),
086: nextAvailableJmxMpPort, new Integer(nextPort)
087: .toString());
088: logger.log(Level.INFO, "PSFB_CSPFT0248", String
089: .valueOf(nextPort));
090: } catch (NumberFormatException nfe) {
091: if (logger.isLoggable(Level.SEVERE)) {
092: LogRecord rec = new LogRecord(Level.SEVERE,
093: "PSFB_CSPFT0249");
094: rec.setLoggerName(logger.getName());
095: rec
096: .setParameters(new Object[] { monitoringPortConfigFile });
097: rec.setThrown(nfe);
098: logger.log(rec);
099: }
100: }
101:
102: // monitoring classpath property - bea/ibm web container only
103: String contextCPKey = "com.sun.portal.monitoring.MonitoringContext.class.path";
104: String contextCP = properties.getProperty(contextCPKey);
105: if (contextCP != null && !contextCP.trim().equals("")) {
106: String tagSwappedContextCP = ClasspathGenUtil
107: .tagSwapClasspath(contextCP);
108: logger.log(Level.INFO, "PSFB_CSPFT0250", new Object[] {
109: contextCPKey, tagSwappedContextCP });
110: FileUtil.replaceLineInFile(new File(
111: monitoringPropertiesFile), contextCPKey + "=",
112: contextCPKey + "=" + tagSwappedContextCP);
113: }
114:
115: //delegatees - bea/ibm web container only
116: String delegateesKey = "com.sun.portal.monitoring.MonitoringContext.class.path.delegatees";
117: String delegatees = properties.getProperty(delegateesKey);
118: if (delegatees != null) {
119: //In case of serarator is different for the OS (Windows)
120: String tagSwappedDelegatees = ClasspathGenUtil
121: .tagSwapClasspath(delegatees);
122: logger.log(Level.INFO, "PSFB_CSPFT0250", new Object[] {
123: delegateesKey, tagSwappedDelegatees });
124: if (!delegatees.equals(tagSwappedDelegatees)) {
125: FileUtil.replaceLineInFile(new File(
126: monitoringPropertiesFile), delegateesKey
127: + "=", delegateesKey + "="
128: + tagSwappedDelegatees);
129: }
130: }
131:
132: // non delegatees - bea/ibm web containers only
133: String nonDelegateesKey = "com.sun.portal.monitoring.MonitoringContext.class.path.non.delegatees";
134: String nonDelegatees = properties
135: .getProperty(nonDelegateesKey);
136: if (nonDelegatees != null) {
137: //In case of serarator is different for the OS (Windows)
138: String tagSwappedNonDelegatees = ClasspathGenUtil
139: .tagSwapClasspath(nonDelegatees);
140: logger.log(Level.INFO, "PSFB_CSPFT0250", new Object[] {
141: nonDelegateesKey, tagSwappedNonDelegatees });
142: if (!nonDelegatees.equals(tagSwappedNonDelegatees)) {
143: FileUtil.replaceLineInFile(new File(
144: monitoringPropertiesFile), nonDelegateesKey
145: + "=", nonDelegateesKey + "="
146: + tagSwappedNonDelegatees);
147: }
148: }
149: } catch (IOException ex) {
150: if (logger.isLoggable(Level.SEVERE)) {
151: LogRecord rec = new LogRecord(Level.SEVERE,
152: "PSFB_CSPFT0251");
153: rec.setLoggerName(logger.getName());
154: rec
155: .setParameters(new Object[] { monitoringPropertiesFile });
156: rec.setThrown(ex);
157: logger.log(rec);
158: }
159: }
160:
161: // Monitoring configuration
162: try {
163: MonitoringConfiguration mconfig = new MonitoringConfiguration();
164: String[] params = { monitoringPropertiesFile, "setUp" };
165: logger.log(Level.INFO, "PSFB_CSPFT0252",
166: monitoringPropertiesFile);
167: mconfig.process(params);
168: } catch (MonitoringException mex) {
169: if (logger.isLoggable(Level.SEVERE)) {
170: LogRecord rec = new LogRecord(Level.SEVERE,
171: "PSFB_CSPFT0253");
172: rec.setLoggerName(logger.getName());
173: rec
174: .setParameters(new Object[] { monitoringPropertiesFile });
175: rec.setThrown(mex);
176: logger.log(rec);
177: }
178: }
179: }
180: }
|