001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Nicolas Modrzyk.
020: * Contributor(s): _______________________.
021: */package org.continuent.sequoia.common.jmx;
022:
023: import java.text.MessageFormat;
024:
025: import javax.management.MalformedObjectNameException;
026: import javax.management.ObjectName;
027:
028: /**
029: * This class contains static information on the jmx services.
030: *
031: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
032: * @version 1.0
033: */
034: public final class JmxConstants {
035:
036: /** RMI Adaptor */
037: public static final String ADAPTOR_TYPE_RMI = "rmiAdaptor"; //$NON-NLS-1$
038:
039: /** ssl config for rmi */
040: public static final String CONNECTOR_RMI_SSL = "jmx.rmi.ssl"; //$NON-NLS-1$
041:
042: /** Http adaptor */
043: public static final String ADAPTOR_TYPE_HTTP = "httpAdaptor"; //$NON-NLS-1$
044:
045: /** jmx authenticator username */
046: public static final String CONNECTOR_AUTH_USERNAME = "jmx.auth.username"; //$NON-NLS-1$
047: /** jmx authenticator password */
048: public static final String CONNECTOR_AUTH_PASSWORD = "jmx.auth.password"; //$NON-NLS-1$
049:
050: /** Default RMI port number value. */
051: public static final int DEFAULT_JMX_RMI_PORT = 1090;
052:
053: /** Default JMX server HTTP adaptor port value. */
054: public static final int DEFAULT_JMX_HTTP_PORT = 8090;
055:
056: /**
057: * This is in the xsl transformation file, so we should leave as is. Other
058: * domain are filtered.
059: */
060: private static final String SEQUOIA_DOMAIN_NAME = "sequoia"; //$NON-NLS-1$
061:
062: /** the controller mbean type */
063: private static final String CONTROLLER_TYPE_VALUE = "Controller"; //$NON-NLS-1$
064: /** the virtual database mbean type */
065: public static final String VIRTUALDATABASE_TYPE_VALUE = "VirtualDataBase"; //$NON-NLS-1$
066: /** the data collector mbean type */
067: public static final String DATABASEBACKEND_TYPE_VALUE = "VirtualDataBase.Backend"; //$NON-NLS-1$
068:
069: private static final String DATACOLLECTOR_TYPE_VALUE = "datacollector"; //$NON-NLS-1$
070:
071: private static final String DATACOLLECTOR = "datacollector"; //$NON-NLS-1$
072: /** the cache mbean type */
073: private static final String SEQUOIA_TYPE_CACHE = "cache"; //$NON-NLS-1$
074:
075: private static final String CONTROLLER_OBJECTNAME = "sequoia:type=Controller"; //$NON-NLS-1$
076: // 0 => virtual database name
077: private static final String VIRTUALDATABASE_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase,name={0}"; //$NON-NLS-1$
078: // 0 => virtual database name, 1 => backend name
079: private static final String DATABASEBACKEND_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.Backend,VirtualDataBase={0},name={1}"; //$NON-NLS-1$
080: // 0 => vdb name, 1 => backend name
081: private static final String BACKENDTASKQUEUES_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.Backend.TaskQueues,VirtualDataBase={0},Backend={1}"; //$NON-NLS-1$
082: // 0 => vdb name
083: private static final String RECOVERYLOG_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.RecoveryLog,VirtualDataBase={0}"; //$NON-NLS-1$
084: // 0 => vdb name
085: private static final String LOADBALANCER_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.LoadBalancer,VirtualDataBase={0}"; //$NON-NLS-1$
086: // 0 => vdb name
087: private static final String REQUESTMANAGER_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.RequestManager,VirtualDataBase={0}"; //$NON-NLS-1$
088: // 0 => vdb name
089: private static final String ABSTRACTSCHEDULER_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.AbstractScheduler,VirtualDataBase={0}"; //$NON-NLS-1$
090: // 0 => vdb name
091: private static final String PARSINGCACHE_OBJECTNAME_PATTERN = "sequoia:type=VirtualDataBase.RequestManager.ParsingCache,VirtualDataBase={0}"; //$NON-NLS-1$
092:
093: /** Virtual database property name */
094: public static final String VIRTUALDATABASE_PROPERTY = "VirtualDataBase"; //$NON-NLS-1$
095:
096: /**
097: * Get the associated jmx object name
098: *
099: * @param name the name of the mbean
100: * @param type the sequoia type of the mbean
101: * @return the associated object name, no exception is thrown as the object
102: * name calculated is always valid ex;
103: * sequoia:type:=<type>:name:=<name>
104: */
105: private static ObjectName getJmxObjectName(String name, String type) {
106: try {
107: return new ObjectName(SEQUOIA_DOMAIN_NAME + ":type=" + type
108: + ",name=" + name);
109: } catch (Exception e) {
110: e.printStackTrace();
111: // impossible?
112: return null;
113: }
114: }
115:
116: /**
117: * Get the associated controller object name
118: *
119: * @return the ObjectName associated to a controller
120: * @throws MalformedObjectNameException if the provided name is not correct
121: * @see JmxConstants#CONTROLLER_OBJECTNAME
122: */
123: public static ObjectName getControllerObjectName()
124: throws MalformedObjectNameException {
125: return new ObjectName(CONTROLLER_OBJECTNAME);
126: }
127:
128: /**
129: * Get the objectname associated with a virtualdatabase
130: *
131: * @param virtualDataBaseName the name of the virtualdatabase
132: * @return sequoia:type:=<virtualdatabase>:name:=<name>
133: * @throws MalformedObjectNameException if the provided name is not correct
134: */
135: public static ObjectName getVirtualDataBaseObjectName(
136: String virtualDataBaseName)
137: throws MalformedObjectNameException {
138: return new ObjectName(MessageFormat.format(
139: VIRTUALDATABASE_OBJECTNAME_PATTERN,
140: new String[] { virtualDataBaseName }));
141: }
142:
143: /**
144: * Get the associated data collector object name
145: *
146: * @return sequoia:type:=<datacollector>:name:=<name>
147: */
148: public static ObjectName getDataCollectorObjectName() {
149: return getJmxObjectName(DATACOLLECTOR, DATACOLLECTOR_TYPE_VALUE);
150: }
151:
152: /**
153: * Get the object name associated with a backend on a given virtual database
154: *
155: * @param virtualDataBaseName name of the virtual database
156: * @param name name of the backend
157: * @return the object name associated with a backend on a given virtual
158: * database
159: * @throws MalformedObjectNameException if the provided name is not correct
160: */
161: public static ObjectName getDatabaseBackendObjectName(
162: String virtualDataBaseName, String name)
163: throws MalformedObjectNameException {
164: return new ObjectName(MessageFormat.format(
165: DATABASEBACKEND_OBJECTNAME_PATTERN, new String[] {
166: virtualDataBaseName, name }));
167: }
168:
169: /**
170: * Get the object name associated with the recovery log on a given virtual
171: * database
172: *
173: * @param vdbName name of the virtual database
174: * @return the object name associated with the recovery log on a given virtual
175: * database
176: * @throws MalformedObjectNameException if the provided name is not correct
177: */
178: public static ObjectName getRecoveryLogObjectName(String vdbName)
179: throws MalformedObjectNameException {
180: return new ObjectName(MessageFormat.format(
181: RECOVERYLOG_OBJECTNAME_PATTERN,
182: new String[] { vdbName }));
183: }
184:
185: /**
186: * Get the associated cache object name
187: *
188: * @param vdbName name of the virtual database
189: * @return sequoia:type:=<cache>:name:=<name>
190: */
191: public static ObjectName getCacheObjectName(String vdbName) {
192: return getJmxObjectName(vdbName + "--cache", SEQUOIA_TYPE_CACHE);
193: }
194:
195: /**
196: * Return the object name associated to the request manager of a given virtual
197: * database.
198: *
199: * @param vdbName name of the virtual database
200: * @return return the object name associated to the request manager of a given
201: * virtual database
202: * @throws MalformedObjectNameException if the object name is malformed
203: * @see #REQUESTMANAGER_OBJECTNAME_PATTERN
204: */
205: public static ObjectName getRequestManagerObjectName(String vdbName)
206: throws MalformedObjectNameException {
207: return new ObjectName(MessageFormat.format(
208: REQUESTMANAGER_OBJECTNAME_PATTERN,
209: new String[] { vdbName }));
210: }
211:
212: /**
213: * Return the object name associated to the load balancer of a given virtual
214: * database.
215: *
216: * @param vdbName name of the virtual database
217: * @return return the object name associated to the load balancer of a given
218: * virtual database
219: * @throws MalformedObjectNameException if the object name is malformed
220: * @see #LOADBALANCER_OBJECTNAME_PATTERN
221: */
222: public static ObjectName getLoadBalancerObjectName(String vdbName)
223: throws MalformedObjectNameException {
224: return new ObjectName(MessageFormat.format(
225: LOADBALANCER_OBJECTNAME_PATTERN,
226: new String[] { vdbName }));
227: }
228:
229: /**
230: * Return the object name associated to the task queues of a given backend.
231: *
232: * @param vdbName name of the virtual database managing the backend
233: * @param backendName name of the backend
234: * @return return the object name associated to the task queues of a given
235: * backend
236: * @throws MalformedObjectNameException if the object name is malformed
237: * @see #BACKENDTASKQUEUES_OBJECTNAME_PATTERN
238: */
239: public static ObjectName getBackendTaskQueuesObjectName(
240: String vdbName, String backendName)
241: throws MalformedObjectNameException {
242: return new ObjectName(MessageFormat.format(
243: BACKENDTASKQUEUES_OBJECTNAME_PATTERN, new String[] {
244: vdbName, backendName }));
245: }
246:
247: /**
248: * Gets the object name of the given vdb scheduler
249: *
250: * @param vdbName name of the virtual database
251: * @return object name associated to the given virtual database scheduler
252: * @throws MalformedObjectNameException if the provided vdb name is incorrect
253: */
254: public static ObjectName getAbstractSchedulerObjectName(
255: String vdbName) throws MalformedObjectNameException {
256: return new ObjectName(MessageFormat.format(
257: ABSTRACTSCHEDULER_OBJECTNAME_PATTERN,
258: new String[] { vdbName }));
259: }
260:
261: /**
262: * Gets the object name of the given vdb request manager parsing cache
263: *
264: * @param vdbName name of the virtual database
265: * @return object name associated to the given virtual database scheduler
266: * @throws MalformedObjectNameException if the provided vdb name is incorrect
267: */
268: public static ObjectName getParsingCacheObjectName(String vdbName)
269: throws MalformedObjectNameException {
270: return new ObjectName(MessageFormat.format(
271: PARSINGCACHE_OBJECTNAME_PATTERN,
272: new String[] { vdbName }));
273: }
274:
275: /**
276: * Sequoia rules to determine if a mbean need authentication or not. By
277: * default all the mbeans need authentication apart from the controller mbean
278: * and the data collector mbean
279: *
280: * @param mbean <tt>ObjectName</tt> of the mbean to test
281: * @return <tt>true</tt> if the call to the mbean should have a user and a
282: * password attribute attached to it.
283: */
284: public static boolean mbeanNeedAuthentication(ObjectName mbean) {
285: String type = mbean.getKeyProperty("type"); //$NON-NLS-1$
286: if (type == null) {
287: return false;
288: }
289: if (type.equalsIgnoreCase(CONTROLLER_TYPE_VALUE)
290: || type.equalsIgnoreCase(DATACOLLECTOR_TYPE_VALUE)) {
291: return false;
292: } else {
293: return true;
294: }
295: }
296: }
|