001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.monitors;
028
029
030
031 import java.util.ArrayList;
032 import java.util.LinkedHashSet;
033
034 import org.opends.server.admin.std.server.VersionMonitorProviderCfg;
035 import org.opends.server.api.MonitorProvider;
036 import org.opends.server.config.ConfigException;
037 import org.opends.server.core.DirectoryServer;
038 import org.opends.server.loggers.debug.DebugTracer;
039 import org.opends.server.protocols.asn1.ASN1OctetString;
040 import org.opends.server.types.Attribute;
041 import org.opends.server.types.AttributeType;
042 import org.opends.server.types.AttributeValue;
043 import org.opends.server.types.DebugLogLevel;
044 import org.opends.server.types.InitializationException;
045 import org.opends.server.util.DynamicConstants;
046
047 import static org.opends.server.loggers.debug.DebugLogger.*;
048
049
050
051 /**
052 * This class defines a monitor provider that reports Directory Server version
053 * information.
054 */
055 public class VersionMonitorProvider
056 extends MonitorProvider<VersionMonitorProviderCfg>
057 {
058 /**
059 * The tracer object for the debug logger.
060 */
061 private static final DebugTracer TRACER = getTracer();
062
063 /**
064 * The name of the attribute used to provide the product name.
065 */
066 public static final String ATTR_PRODUCT_NAME = "productName";
067
068
069
070 /**
071 * The name of the attribute used to provide the short name.
072 */
073 public static final String ATTR_SHORT_NAME = "shortName";
074
075
076
077 /**
078 * The name of the attribute used to provide the major version number.
079 */
080 public static final String ATTR_MAJOR_VERSION = "majorVersion";
081
082
083
084 /**
085 * The name of the attribute used to provide the minor version number.
086 */
087 public static final String ATTR_MINOR_VERSION = "minorVersion";
088
089
090
091 /**
092 * The name of the attribute used to provide the point version number.
093 */
094 public static final String ATTR_POINT_VERSION = "pointVersion";
095
096
097
098 /**
099 * The name of the attribute used to provide the version qualifier string.
100 */
101 public static final String ATTR_VERSION_QUALIFIER = "versionQualifier";
102
103
104
105 /**
106 * The name of the attribute used to provide the weekly build number.
107 */
108 public static final String ATTR_BUILD_NUMBER = "buildNumber";
109
110
111
112 /**
113 * The name of the attribute used to provide the list of bugfix IDs.
114 */
115 public static final String ATTR_FIX_IDS = "fixIDs";
116
117
118
119 /**
120 * The name of the attribute used to provide the Subversion revision number.
121 */
122 public static final String ATTR_REVISION_NUMBER = "revisionNumber";
123
124
125
126 /**
127 * The name of the attribute used to provide the build ID (aka the build
128 * timestamp).
129 */
130 public static final String ATTR_BUILD_ID = "buildID";
131
132
133
134 /**
135 * The name of the attribute used to provide the compact version string.
136 */
137 public static final String ATTR_COMPACT_VERSION = "compactVersion";
138
139
140
141 /**
142 * The name of the attribute used to provide the full version string.
143 */
144 public static final String ATTR_FULL_VERSION = "fullVersion";
145
146
147
148 /**
149 * Initializes this monitor provider.
150 */
151 public VersionMonitorProvider()
152 {
153 super("Version Monitor Provider");
154
155 // No initialization should be performed here.
156 }
157
158
159
160 /**
161 * {@inheritDoc}
162 */
163 public void initializeMonitorProvider(VersionMonitorProviderCfg configuration)
164 throws ConfigException, InitializationException
165 {
166 // No initialization is required.
167 }
168
169
170
171 /**
172 * Retrieves the name of this monitor provider. It should be unique among all
173 * monitor providers, including all instances of the same monitor provider.
174 *
175 * @return The name of this monitor provider.
176 */
177 public String getMonitorInstanceName()
178 {
179 return "Version";
180 }
181
182
183
184 /**
185 * Retrieves the length of time in milliseconds that should elapse between
186 * calls to the <CODE>updateMonitorData()</CODE> method. A negative or zero
187 * return value indicates that the <CODE>updateMonitorData()</CODE> method
188 * should not be periodically invoked.
189 *
190 * @return The length of time in milliseconds that should elapse between
191 * calls to the <CODE>updateMonitorData()</CODE> method.
192 */
193 public long getUpdateInterval()
194 {
195 // This monitor does not need to run periodically.
196 return 0;
197 }
198
199
200
201 /**
202 * Performs any processing periodic processing that may be desired to update
203 * the information associated with this monitor. Note that best-effort
204 * attempts will be made to ensure that calls to this method come
205 * <CODE>getUpdateInterval()</CODE> milliseconds apart, but no guarantees will
206 * be made.
207 */
208 public void updateMonitorData()
209 {
210 // This monitor does not need to run periodically.
211 return;
212 }
213
214
215
216 /**
217 * Retrieves a set of attributes containing monitor data that should be
218 * returned to the client if the corresponding monitor entry is requested.
219 *
220 * @return A set of attributes containing monitor data that should be
221 * returned to the client if the corresponding monitor entry is
222 * requested.
223 */
224 public ArrayList<Attribute> getMonitorData()
225 {
226 ArrayList<Attribute> attrs = new ArrayList<Attribute>(12);
227
228 attrs.add(createAttribute(ATTR_PRODUCT_NAME,
229 DynamicConstants.PRODUCT_NAME));
230 attrs.add(createAttribute(ATTR_SHORT_NAME, DynamicConstants.SHORT_NAME));
231 attrs.add(createAttribute(ATTR_MAJOR_VERSION,
232 String.valueOf(DynamicConstants.MAJOR_VERSION)));
233 attrs.add(createAttribute(ATTR_MINOR_VERSION,
234 String.valueOf(DynamicConstants.MINOR_VERSION)));
235 attrs.add(createAttribute(ATTR_POINT_VERSION,
236 String.valueOf(DynamicConstants.POINT_VERSION)));
237
238 String versionQualifier = DynamicConstants.VERSION_QUALIFIER;
239 if ((versionQualifier != null) && (versionQualifier.length() > 0))
240 {
241 attrs.add(createAttribute(ATTR_VERSION_QUALIFIER, versionQualifier));
242 }
243
244 int buildNumber = DynamicConstants.BUILD_NUMBER;
245 if (buildNumber > 0)
246 {
247 attrs.add(createAttribute(ATTR_BUILD_NUMBER,
248 String.valueOf(buildNumber)));
249 }
250
251 String fixIDs = DynamicConstants.FIX_IDS;
252 if ((fixIDs != null) && (fixIDs.length() > 0))
253 {
254 attrs.add(createAttribute(ATTR_FIX_IDS, fixIDs));
255 }
256
257 attrs.add(createAttribute(ATTR_REVISION_NUMBER,
258 String.valueOf(DynamicConstants.REVISION_NUMBER)));
259 attrs.add(createAttribute(ATTR_BUILD_ID, DynamicConstants.BUILD_ID));
260 attrs.add(createAttribute(ATTR_COMPACT_VERSION,
261 DynamicConstants.COMPACT_VERSION_STRING));
262 attrs.add(createAttribute(ATTR_FULL_VERSION,
263 DynamicConstants.FULL_VERSION_STRING));
264
265 return attrs;
266 }
267
268
269
270 /**
271 * Constructs an attribute using the provided information. It will have the
272 * default syntax.
273 *
274 * @param name The name to use for the attribute.
275 * @param value The value to use for the attribute.
276 *
277 * @return The attribute created from the provided information.
278 */
279 private Attribute createAttribute(String name, String value)
280 {
281 AttributeType attrType = DirectoryServer.getDefaultAttributeType(name);
282
283 ASN1OctetString encodedValue = new ASN1OctetString(value);
284 LinkedHashSet<AttributeValue> values = new LinkedHashSet<AttributeValue>(1);
285
286 try
287 {
288 values.add(new AttributeValue(encodedValue,
289 attrType.normalize(encodedValue)));
290 }
291 catch (Exception e)
292 {
293 if (debugEnabled())
294 {
295 TRACER.debugCaught(DebugLogLevel.ERROR, e);
296 }
297
298 values.add(new AttributeValue(encodedValue, encodedValue));
299 }
300
301 return new Attribute(attrType, name, values);
302 }
303 }
304