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 029import java.util.ArrayList; 030import java.util.List; 031 032import org.forgerock.opendj.config.server.ConfigException; 033import org.opends.server.admin.std.server.VersionMonitorProviderCfg; 034import org.opends.server.api.MonitorProvider; 035import org.opends.server.types.Attribute; 036import org.opends.server.types.Attributes; 037import org.opends.server.types.InitializationException; 038import org.opends.server.util.DynamicConstants; 039 040/** This class defines a monitor provider that reports Directory Server version information. */ 041public class VersionMonitorProvider 042 extends MonitorProvider<VersionMonitorProviderCfg> 043{ 044 /** The name of the attribute used to provide the product name. */ 045 public static final String ATTR_PRODUCT_NAME = "productName"; 046 /** The name of the attribute used to provide the short name. */ 047 public static final String ATTR_SHORT_NAME = "shortName"; 048 /** The name of the attribute used to provide the major version number. */ 049 public static final String ATTR_MAJOR_VERSION = "majorVersion"; 050 /** The name of the attribute used to provide the minor version number. */ 051 public static final String ATTR_MINOR_VERSION = "minorVersion"; 052 /** The name of the attribute used to provide the point version number. */ 053 public static final String ATTR_POINT_VERSION = "pointVersion"; 054 /** The name of the attribute used to provide the version qualifier string. */ 055 public static final String ATTR_VERSION_QUALIFIER = "versionQualifier"; 056 /** The name of the attribute used to provide the weekly build number. */ 057 public static final String ATTR_BUILD_NUMBER = "buildNumber"; 058 /** The name of the attribute used to provide the list of bugfix IDs. */ 059 public static final String ATTR_FIX_IDS = "fixIDs"; 060 /** The name of the attribute used to provide the Subversion revision number. */ 061 public static final String ATTR_REVISION_NUMBER = "revisionNumber"; 062 /** The name of the attribute used to provide the build ID (aka the build timestamp). */ 063 public static final String ATTR_BUILD_ID = "buildID"; 064 /** The name of the attribute used to provide the compact version string. */ 065 public static final String ATTR_COMPACT_VERSION = "compactVersion"; 066 /** The name of the attribute used to provide the full version string. */ 067 public static final String ATTR_FULL_VERSION = "fullVersion"; 068 069 @Override 070 public void initializeMonitorProvider(VersionMonitorProviderCfg configuration) 071 throws ConfigException, InitializationException 072 { 073 // No initialization is required. 074 } 075 076 @Override 077 public String getMonitorInstanceName() 078 { 079 return "Version"; 080 } 081 082 @Override 083 public List<Attribute> getMonitorData() 084 { 085 ArrayList<Attribute> attrs = new ArrayList<>(12); 086 087 attrs.add(createAttribute(ATTR_PRODUCT_NAME, DynamicConstants.PRODUCT_NAME)); 088 attrs.add(createAttribute(ATTR_SHORT_NAME, DynamicConstants.SHORT_NAME)); 089 attrs.add(createAttribute(ATTR_MAJOR_VERSION, DynamicConstants.MAJOR_VERSION)); 090 attrs.add(createAttribute(ATTR_MINOR_VERSION, DynamicConstants.MINOR_VERSION)); 091 attrs.add(createAttribute(ATTR_POINT_VERSION, DynamicConstants.POINT_VERSION)); 092 093 String versionQualifier = DynamicConstants.VERSION_QUALIFIER; 094 if (versionQualifier != null && versionQualifier.length() > 0) 095 { 096 attrs.add(createAttribute(ATTR_VERSION_QUALIFIER, versionQualifier)); 097 } 098 099 int buildNumber = DynamicConstants.BUILD_NUMBER; 100 if (buildNumber > 0) 101 { 102 attrs.add(createAttribute(ATTR_BUILD_NUMBER, buildNumber)); 103 } 104 105 String fixIDs = DynamicConstants.FIX_IDS; 106 if (fixIDs != null && fixIDs.length() > 0) 107 { 108 attrs.add(createAttribute(ATTR_FIX_IDS, fixIDs)); 109 } 110 111 attrs.add(createAttribute(ATTR_REVISION_NUMBER, DynamicConstants.REVISION)); 112 attrs.add(createAttribute(ATTR_BUILD_ID, DynamicConstants.BUILD_ID)); 113 attrs.add(createAttribute(ATTR_COMPACT_VERSION, DynamicConstants.COMPACT_VERSION_STRING)); 114 attrs.add(createAttribute(ATTR_FULL_VERSION, DynamicConstants.FULL_VERSION_STRING)); 115 116 return attrs; 117 } 118 119 private Attribute createAttribute(String name, Object value) 120 { 121 return Attributes.create(name, String.valueOf(value)); 122 } 123}