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 legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2010 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.server.monitors; 028 029 030 031import java.util.ArrayList; 032 033import org.opends.server.admin.std.server.VersionMonitorProviderCfg; 034import org.opends.server.api.MonitorProvider; 035import org.forgerock.opendj.config.server.ConfigException; 036import org.opends.server.core.DirectoryServer; 037import org.forgerock.i18n.slf4j.LocalizedLogger; 038import org.opends.server.types.*; 039import org.opends.server.util.DynamicConstants; 040 041 042 043/** 044 * This class defines a monitor provider that reports Directory Server version 045 * information. 046 */ 047public class VersionMonitorProvider 048 extends MonitorProvider<VersionMonitorProviderCfg> 049{ 050 private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); 051 052 /** 053 * The name of the attribute used to provide the product name. 054 */ 055 public static final String ATTR_PRODUCT_NAME = "productName"; 056 057 058 059 /** 060 * The name of the attribute used to provide the short name. 061 */ 062 public static final String ATTR_SHORT_NAME = "shortName"; 063 064 065 066 /** 067 * The name of the attribute used to provide the major version number. 068 */ 069 public static final String ATTR_MAJOR_VERSION = "majorVersion"; 070 071 072 073 /** 074 * The name of the attribute used to provide the minor version number. 075 */ 076 public static final String ATTR_MINOR_VERSION = "minorVersion"; 077 078 079 080 /** 081 * The name of the attribute used to provide the point version number. 082 */ 083 public static final String ATTR_POINT_VERSION = "pointVersion"; 084 085 086 087 /** 088 * The name of the attribute used to provide the version qualifier string. 089 */ 090 public static final String ATTR_VERSION_QUALIFIER = "versionQualifier"; 091 092 093 094 /** 095 * The name of the attribute used to provide the weekly build number. 096 */ 097 public static final String ATTR_BUILD_NUMBER = "buildNumber"; 098 099 100 101 /** 102 * The name of the attribute used to provide the list of bugfix IDs. 103 */ 104 public static final String ATTR_FIX_IDS = "fixIDs"; 105 106 107 108 /** 109 * The name of the attribute used to provide the Subversion revision number. 110 */ 111 public static final String ATTR_REVISION_NUMBER = "revisionNumber"; 112 113 114 115 /** 116 * The name of the attribute used to provide the build ID (aka the build 117 * timestamp). 118 */ 119 public static final String ATTR_BUILD_ID = "buildID"; 120 121 122 123 /** 124 * The name of the attribute used to provide the compact version string. 125 */ 126 public static final String ATTR_COMPACT_VERSION = "compactVersion"; 127 128 129 130 /** 131 * The name of the attribute used to provide the full version string. 132 */ 133 public static final String ATTR_FULL_VERSION = "fullVersion"; 134 135 136 137 /** {@inheritDoc} */ 138 public void initializeMonitorProvider(VersionMonitorProviderCfg configuration) 139 throws ConfigException, InitializationException 140 { 141 // No initialization is required. 142 } 143 144 145 146 /** 147 * Retrieves the name of this monitor provider. It should be unique among all 148 * monitor providers, including all instances of the same monitor provider. 149 * 150 * @return The name of this monitor provider. 151 */ 152 public String getMonitorInstanceName() 153 { 154 return "Version"; 155 } 156 157 158 /** 159 * Retrieves a set of attributes containing monitor data that should be 160 * returned to the client if the corresponding monitor entry is requested. 161 * 162 * @return A set of attributes containing monitor data that should be 163 * returned to the client if the corresponding monitor entry is 164 * requested. 165 */ 166 public ArrayList<Attribute> getMonitorData() 167 { 168 ArrayList<Attribute> attrs = new ArrayList<>(12); 169 170 attrs.add(createAttribute(ATTR_PRODUCT_NAME, 171 DynamicConstants.PRODUCT_NAME)); 172 attrs.add(createAttribute(ATTR_SHORT_NAME, DynamicConstants.SHORT_NAME)); 173 attrs.add(createAttribute(ATTR_MAJOR_VERSION, 174 String.valueOf(DynamicConstants.MAJOR_VERSION))); 175 attrs.add(createAttribute(ATTR_MINOR_VERSION, 176 String.valueOf(DynamicConstants.MINOR_VERSION))); 177 attrs.add(createAttribute(ATTR_POINT_VERSION, 178 String.valueOf(DynamicConstants.POINT_VERSION))); 179 180 String versionQualifier = DynamicConstants.VERSION_QUALIFIER; 181 if (versionQualifier != null && versionQualifier.length() > 0) 182 { 183 attrs.add(createAttribute(ATTR_VERSION_QUALIFIER, versionQualifier)); 184 } 185 186 int buildNumber = DynamicConstants.BUILD_NUMBER; 187 if (buildNumber > 0) 188 { 189 attrs.add(createAttribute(ATTR_BUILD_NUMBER, 190 String.valueOf(buildNumber))); 191 } 192 193 String fixIDs = DynamicConstants.FIX_IDS; 194 if (fixIDs != null && fixIDs.length() > 0) 195 { 196 attrs.add(createAttribute(ATTR_FIX_IDS, fixIDs)); 197 } 198 199 attrs.add(createAttribute(ATTR_REVISION_NUMBER, 200 String.valueOf(DynamicConstants.REVISION_NUMBER))); 201 attrs.add(createAttribute(ATTR_BUILD_ID, DynamicConstants.BUILD_ID)); 202 attrs.add(createAttribute(ATTR_COMPACT_VERSION, 203 DynamicConstants.COMPACT_VERSION_STRING)); 204 attrs.add(createAttribute(ATTR_FULL_VERSION, 205 DynamicConstants.FULL_VERSION_STRING)); 206 207 return attrs; 208 } 209 210 211 212 /** 213 * Constructs an attribute using the provided information. It will have the 214 * default syntax. 215 * 216 * @param name The name to use for the attribute. 217 * @param value The value to use for the attribute. 218 * 219 * @return The attribute created from the provided information. 220 */ 221 private Attribute createAttribute(String name, String value) 222 { 223 AttributeType attrType = DirectoryServer.getDefaultAttributeType(name); 224 return Attributes.create(attrType, value); 225 } 226} 227