001: package com.sun.portal.fabric.mbeans;
002:
003: import com.sun.portal.admin.common.context.PSConfigContext;
004: import com.sun.portal.admin.common.context.PortalDomainContext;
005: import com.sun.portal.admin.common.util.AdminClientUtil;
006: import com.sun.portal.admin.common.util.AdminUtil;
007: import com.sun.portal.admin.server.AdminServerUtil;
008: import com.sun.portal.admin.server.PASModule;
009: import com.sun.portal.admin.server.mbeans.PSResource;
010: import com.sun.portal.log.common.LoggersList;
011: import com.sun.portal.log.common.PortalLogger;
012:
013: import javax.management.MBeanServer;
014: import javax.management.MBeanServerConnection;
015: import javax.management.MalformedObjectNameException;
016: import javax.management.ObjectName;
017: import javax.management.remote.JMXConnector;
018: import java.net.URL;
019: import java.util.Hashtable;
020: import java.util.LinkedList;
021: import java.util.List;
022: import java.util.Properties;
023: import java.util.logging.Level;
024: import java.util.logging.Logger;
025:
026: /**
027: *
028: */
029: public class PortalLogConfigHostBridge extends PSResource implements
030: PortalLogConfigHostBridgeMBean {
031:
032: private static Logger logger = PortalLogger
033: .getLogger(PortalLogConfigHostBridge.class);
034: protected static final String PORTAL_LOG_OBJECT_NAME = "PortalDomain.PortalLogConfigurator";
035:
036: /*
037: * The values componentID and instance has different meanings depending on the component
038: * component = Portal
039: * componentID = Portal ID
040: * instance = Instance ID
041: *
042: * component = Search
043: * componentID = Search Server ID
044: * instance = <not applicable>
045: *
046: * component = Gateway, NLProxy, RWProxy
047: * componentID = Host
048: * instance = Profile Name
049: *
050: */
051: public void init(PSConfigContext cc, PortalDomainContext pdc,
052: List path) {
053: super .init(cc, pdc, path);
054: }
055:
056: public Hashtable getCommonLogDetails(String component,
057: String componentID, String instance) throws Exception {
058: Object obj = null;
059: MBeanServerConnection serverConnection = null;
060: try {
061: //validate the component
062: PortalLogConfigurator.validateComponent(component);
063: //get appropriate MBeanServerConnector
064: serverConnection = getConnection(component, componentID,
065: instance);
066: //invoke getCommonLogDetails on PortalLogconfigurator on that server
067: ObjectName logConfigObjName = getLogConfigObjName();
068: Object[] params = new Object[] { component, componentID,
069: instance };
070: String[] signature = new String[] { "java.lang.String",
071: "java.lang.String", "java.lang.String" };
072: obj = serverConnection.invoke(logConfigObjName,
073: "getCommonLogDetails", params, signature);
074: } finally {
075: closeRemoteConnection(serverConnection);
076: }
077: if (obj == null)
078: return null;
079: else
080: return (Hashtable) obj;
081: }
082:
083: public List getSpecificLogDetails(String component,
084: String componentID, String instance) throws Exception {
085: Object obj = null;
086: MBeanServerConnection serverConnection = null;
087: try {
088: //validate the component
089: PortalLogConfigurator.validateComponent(component);
090: //get appropriate MBeanServerConnector
091: serverConnection = getConnection(component, componentID,
092: instance);
093: //invoke getCommonLogDetails on PortalLogconfigurator on that server
094: ObjectName logConfigObjName = getLogConfigObjName();
095: Object[] params = new Object[] { component, componentID,
096: instance };
097: String[] signature = new String[] { "java.lang.String",
098: "java.lang.String", "java.lang.String" };
099: obj = serverConnection.invoke(logConfigObjName,
100: "getSpecificLogDetails", params, signature);
101: } finally {
102: closeRemoteConnection(serverConnection);
103: }
104: if (obj == null)
105: return null;
106: else
107: return (List) obj;
108: }
109:
110: public void setSpecificLogDetails(String component,
111: String componentID, String instance, List loggersDetails)
112: throws Exception {
113: MBeanServerConnection serverConnection = null;
114: try {
115: //validate the component
116: PortalLogConfigurator.validateComponent(component);
117: //get appropriate MBeanServerConnector
118: serverConnection = getConnection(component, componentID,
119: instance);
120: //invoke getCommonLogDetails on PortalLogconfigurator on that server
121: ObjectName logConfigObjName = getLogConfigObjName();
122: Object[] params = new Object[] { component, componentID,
123: instance, loggersDetails };
124: String[] signature = new String[] { "java.lang.String",
125: "java.lang.String", "java.lang.String",
126: "java.util.List" };
127: serverConnection.invoke(logConfigObjName,
128: "setSpecificLogDetails", params, signature);
129: } finally {
130: closeRemoteConnection(serverConnection);
131: }
132: }
133:
134: public void setCommonLogDetails(String component,
135: String componentID, String instance, Hashtable values)
136: throws Exception {
137: MBeanServerConnection serverConnection = null;
138: try {
139: //validate the component
140: PortalLogConfigurator.validateComponent(component);
141: //get appropriate MBeanServerConnector
142: serverConnection = getConnection(component, componentID,
143: instance);
144: //invoke getCommonLogDetails on PortalLogconfigurator on that serverlog
145: ObjectName logConfigObjName = getLogConfigObjName();
146: Object[] params = new Object[] { component, componentID,
147: instance, values };
148: String[] signature = new String[] { "java.lang.String",
149: "java.lang.String", "java.lang.String",
150: "java.util.Hashtable" };
151: serverConnection.invoke(logConfigObjName,
152: "setCommonLogDetails", params, signature);
153: } finally {
154: closeRemoteConnection(serverConnection);
155: }
156: }
157:
158: public Hashtable getLogFileNames(String component,
159: String componentID, String instance) throws Exception {
160: Object obj = null;
161: MBeanServerConnection serverConnection = null;
162: try {
163: //validate the component
164: PortalLogConfigurator.validateComponent(component);
165: //get appropriate MBeanServerConnector
166: serverConnection = getConnection(component, componentID,
167: instance);
168: //invoke getCommonLogDetails on PortalLogconfigurator on that server
169: ObjectName logConfigObjName = getLogConfigObjName();
170: Object[] params = new Object[] { component, componentID,
171: instance };
172: String[] signature = new String[] { "java.lang.String",
173: "java.lang.String", "java.lang.String" };
174: obj = serverConnection.invoke(logConfigObjName,
175: "getLogFileNames", params, signature);
176: } finally {
177: closeRemoteConnection(serverConnection);
178: }
179: if (obj == null)
180: return null;
181: else
182: return (Hashtable) obj;
183: }
184:
185: public Hashtable getLogRecords(String component,
186: String componentID, String instance,
187: Hashtable logViewerInputs) throws Exception {
188: Object obj = null;
189: MBeanServerConnection serverConnection = null;
190: try {
191: //validate the component
192: PortalLogConfigurator.validateComponent(component);
193: //get appropriate MBeanServerConnector
194: serverConnection = getConnection(component, componentID,
195: instance);
196: //invoke getCommonLogDetails on PortalLogconfigurator on that server
197: ObjectName logConfigObjName = getLogConfigObjName();
198: Object[] params = new Object[] { component, componentID,
199: instance, logViewerInputs };
200: String[] signature = new String[] { "java.lang.String",
201: "java.lang.String", "java.lang.String",
202: "java.util.Hashtable" };
203: obj = serverConnection.invoke(logConfigObjName,
204: "getLogRecords", params, signature);
205: } finally {
206: closeRemoteConnection(serverConnection);
207: }
208: if (obj == null)
209: return null;
210: else
211: return (Hashtable) obj;
212: }
213:
214: public Hashtable getLoggerDetails(String component,
215: String componentID, String instance, String loggerName)
216: throws Exception {
217: Object obj = null;
218: MBeanServerConnection serverConnection = null;
219: try {
220: //validate the component
221: PortalLogConfigurator.validateComponent(component);
222: //get appropriate MBeanServerConnector
223: serverConnection = getConnection(component, componentID,
224: instance);
225: //invoke getCommonLogDetails on PortalLogconfigurator on that server
226: ObjectName logConfigObjName = getLogConfigObjName();
227: Object[] params = new Object[] { component, componentID,
228: instance, loggerName };
229: String[] signature = new String[] { "java.lang.String",
230: "java.lang.String", "java.lang.String",
231: "java.lang.String" };
232: obj = serverConnection.invoke(logConfigObjName,
233: "getLoggerDetails", params, signature);
234: } finally {
235: closeRemoteConnection(serverConnection);
236: }
237: if (obj == null)
238: return null;
239: else
240: return (Hashtable) obj;
241: }
242:
243: private ObjectName getLogConfigObjName()
244: throws MalformedObjectNameException {
245: LinkedList path = new LinkedList();
246: path.addFirst(AdminUtil.DEFAULT_DOMAIN);
247: path.addFirst("portalLogConfigurator");
248: return AdminUtil.getResourceMBeanObjectName(
249: PORTAL_LOG_OBJECT_NAME, path);
250: }
251:
252: private void closeRemoteConnection(
253: MBeanServerConnection serverConnection) {
254: try {
255: if (!serverConnection.equals(PASModule.getMBeanServer()))
256: ((JMXConnector) serverConnection).close();
257: } catch (Exception e) {
258: //drop through it is not open
259: }
260: }
261:
262: private MBeanServerConnection getConnection(String component,
263: String componentID, String instance) throws Exception {
264: MBeanServerConnection serverConnection;
265: //find if it is local or remote
266: if (isRemote(component, componentID, instance)) {
267: try {
268: JMXConnector connector = AdminServerUtil
269: .getJMXConnector(getHost(component,
270: componentID, instance));
271: serverConnection = connector.getMBeanServerConnection();
272: } catch (Exception e) {
273: logger.log(Level.SEVERE, "PSFB_CSPFM0006", e);
274: throw e;
275: }
276: } else {
277: serverConnection = PASModule.getMBeanServer();
278: }
279: return serverConnection;
280: }
281:
282: private String getHost(String component, String componentID,
283: String instance) throws Exception {
284: String host = null;
285: //if portal
286: if (LoggersList.COMPONENT_PORTAL_INSTANCE.equals(component)) {
287: ObjectName objName = getPortalInstanceObjectName(
288: componentID, instance);
289: host = (String) (PASModule.getMBeanServer().getAttribute(
290: objName, "Host"));
291: } else if (LoggersList.COMPONENT_GW_INSTANCE.equals(component)
292: || LoggersList.COMPONENT_NLP_INSTANCE.equals(component)
293: || LoggersList.COMPONENT_RWP_INSTANCE.equals(component)) {
294: host = componentID;
295: } else if (LoggersList.COMPONENT_SEARCH_INSTANCE
296: .equals(component)) {
297: ObjectName objName = getSearchServerObjectName(componentID);
298: Object[] params = {};
299: String[] signatures = {};
300: Properties p = (Properties) PASModule.getMBeanServer()
301: .invoke(objName, "retrieveVitals", params,
302: signatures);
303: URL searchURL = new URL(p.getProperty("url"));
304: host = searchURL.getHost();
305: }
306: //TODO for other components
307: return host;
308: }
309:
310: private boolean isRemote(String component, String componentID,
311: String instance) throws Exception {
312: boolean isRemote = false;
313: //if portal
314: if (LoggersList.COMPONENT_PORTAL_INSTANCE.equals(component)) {
315: MBeanServer server = PASModule.getMBeanServer();
316: Boolean isLocal = (Boolean) server.invoke(
317: getPortalInstanceObjectName(componentID, instance),
318: "isLocal", null, null);
319: isRemote = !isLocal.booleanValue();
320: } else if (LoggersList.COMPONENT_GW_INSTANCE.equals(component)
321: || LoggersList.COMPONENT_NLP_INSTANCE.equals(component)
322: || LoggersList.COMPONENT_RWP_INSTANCE.equals(component)) {
323: isRemote = !AdminUtil.isLocal(componentID);
324: } else if (LoggersList.COMPONENT_SEARCH_INSTANCE
325: .equals(component)) {
326: isRemote = !AdminUtil.isLocal(getHost(component,
327: componentID, instance));
328: }
329:
330: logger.log(Level.FINEST, "PSFB_CSPFM1019", new Object[] {
331: component, componentID, instance,
332: Boolean.valueOf(isRemote) });
333: //TODO for other components
334: return isRemote;
335: }
336:
337: private ObjectName getPortalInstanceObjectName(String componentID,
338: String instance) throws Exception {
339: return AdminUtil.getInstanceMBeanObjectName(m_sPsDomainID,
340: componentID, instance);
341: }
342:
343: private ObjectName getSearchServerObjectName(String componentID)
344: throws Exception {
345: LinkedList path = new LinkedList();
346: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
347: path.addFirst(componentID);
348: return AdminClientUtil.getResourceMBeanObjectName(
349: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
350: }
351:
352: }
|