001    /*
002     * Copyright 2008-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.sdk.unboundidds.monitors;
022    
023    
024    
025    import java.util.Collections;
026    import java.util.LinkedHashMap;
027    import java.util.Map;
028    
029    import com.unboundid.ldap.sdk.Entry;
030    import com.unboundid.util.NotMutable;
031    import com.unboundid.util.ThreadSafety;
032    import com.unboundid.util.ThreadSafetyLevel;
033    
034    import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
035    
036    
037    
038    /**
039     * <BLOCKQUOTE>
040     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
041     *   LDAP SDK for Java.  It is not available for use in applications that
042     *   include only the Standard Edition of the LDAP SDK, and is not supported for
043     *   use in conjunction with non-UnboundID products.
044     * </BLOCKQUOTE>
045     * This class defines a monitor entry that provides general information about
046     * the Directory Server version.  Information that it may make available
047     * includes:
048     * <UL>
049     *   <LI>The full Directory Server version string, which may contain
050     *       spaces.</LI>
051     *   <LI>The compact Directory Server version string, which will not contain
052     *       any spaces and may use a more compact representation than the full
053     *       version string.</LI>
054     *   <LI>The Directory Server product name.</LI>
055     *   <LI>A compact representation of the Directory Server product name.</LI>
056     *   <LI>The server major version number.</LI>
057     *   <LI>The server minor version number.</LI>
058     *   <LI>The server point version number.</LI>
059     *   <LI>A version qualifier string which may provide a more descriptive name
060     *       for the build of the server.</LI>
061     *   <LI>The server build ID string.</LI>
062     *   <LI>The server promoted build number.</LI>
063     *   <LI>The source control revision number for the source used to build the
064     *       server.</LI>
065     *   <LI>A list of the bugfix IDs for any special fixes included in the
066     *       server.</LI>
067     * </UL>
068     * The server should present at most one version monitor entry.  It can be
069     * retrieved using the {@link MonitorManager#getVersionMonitorEntry} method.
070     * This entry provides specific methods for accessing this version information
071     * (e.g., the {@link VersionMonitorEntry#getFullVersion} method can be used to
072     * retrieve the full version string for the server).  Alternately, this
073     * information may be accessed using the generic API.  See the
074     * {@link MonitorManager} class documentation for an example that demonstrates
075     * the use of the generic API for accessing monitor data.
076     */
077    @NotMutable()
078    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
079    public final class VersionMonitorEntry
080           extends MonitorEntry
081    {
082      /**
083       * The structural object class used in version monitor entries.
084       */
085      protected static final String VERSION_MONITOR_OC =
086           "ds-version-monitor-entry";
087    
088    
089    
090      /**
091       * The name of the attribute used to provide the server build ID.
092       */
093      private static final String ATTR_BUILD_ID = "buildID";
094    
095    
096    
097      /**
098       * The name of the attribute used to provide the server promoted build number.
099       */
100      private static final String ATTR_BUILD_NUMBER = "buildNumber";
101    
102    
103    
104      /**
105       * The name of the attribute used to provide a compact server version string.
106       */
107      private static final String ATTR_COMPACT_VERSION = "compactVersion";
108    
109    
110    
111      /**
112       * The name of the attribute used to provide the list of bugfix IDs.
113       */
114      private static final String ATTR_FIX_IDS = "fixIDs";
115    
116    
117    
118      /**
119       * The name of the attribute used to provide a full server version string.
120       */
121      private static final String ATTR_FULL_VERSION = "fullVersion";
122    
123    
124    
125      /**
126       * The name of the attribute used to hold the Groovy library version.
127       */
128      private static final String ATTR_GROOVY_VERSION = "groovyVersion";
129    
130    
131    
132      /**
133       * The name of the attribute used to hold the Berkeley DB JE library version.
134       */
135      private static final String ATTR_JE_VERSION = "jeVersion";
136    
137    
138    
139      /**
140       * The name of the attribute used to hold the jzlib library version.
141       */
142      private static final String ATTR_JZLIB_VERSION = "jzlibVersion";
143    
144    
145    
146      /**
147       * The name of the attribute used to hold the LDAP SDK library version.
148       */
149      private static final String ATTR_LDAP_SDK_VERSION = "ldapSDKVersion";
150    
151    
152    
153      /**
154       * The name of the attribute used to provide the major version number.
155       */
156      private static final String ATTR_MAJOR_VERSION = "majorVersion";
157    
158    
159    
160      /**
161       * The name of the attribute used to provide the minor version number.
162       */
163      private static final String ATTR_MINOR_VERSION = "minorVersion";
164    
165    
166    
167      /**
168       * The name of the attribute used to provide the point version number.
169       */
170      private static final String ATTR_POINT_VERSION = "pointVersion";
171    
172    
173    
174      /**
175       * The name of the attribute used to provide the product name.
176       */
177      private static final String ATTR_PRODUCT_NAME = "productName";
178    
179    
180    
181      /**
182       * The name of the attribute used to provide the source revision number.
183       */
184      private static final String ATTR_REVISION_NUMBER = "revisionNumber";
185    
186    
187    
188      /**
189       * The name of the attribute used to hold the server SDK library version.
190       */
191      private static final String ATTR_SERVER_SDK_VERSION = "serverSDKVersion";
192    
193    
194    
195      /**
196       * The name of the attribute used to provide the short product name.
197       */
198      private static final String ATTR_SHORT_NAME = "shortName";
199    
200    
201    
202      /**
203       * The name of the attribute used to hold the server SNMP4J library version.
204       */
205      private static final String ATTR_SNMP4J_VERSION = "snmp4jVersion";
206    
207    
208    
209      /**
210       * The name of the attribute used to hold the server SNMP4J agent library
211       * version.
212       */
213      private static final String ATTR_SNMP4J_AGENT_VERSION = "snmp4jAgentVersion";
214    
215    
216    
217      /**
218       * The name of the attribute used to hold the server SNMP4J AgentX library
219       * version.
220       */
221      private static final String ATTR_SNMP4J_AGENTX_VERSION =
222           "snmp4jAgentXVersion";
223    
224    
225    
226      /**
227       * The name of the attribute used to provide the server's version qualifier.
228       */
229      private static final String ATTR_VERSION_QUALIFIER = "versionQualifier";
230    
231    
232    
233      /**
234       * The serial version UID for this serializable class.
235       */
236      private static final long serialVersionUID = -8501846678698542926L;
237    
238    
239    
240      // The server build number.
241      private final Long buildNumber;
242    
243      // The server major version number.
244      private final Long majorVersion;
245    
246      // The server minor version number.
247      private final Long minorVersion;
248    
249      // The server point version number.
250      private final Long pointVersion;
251    
252      // The server source revision number.
253      private final Long revisionNumber;
254    
255      // The server build ID.
256      private final String buildID;
257    
258      // The compact server version string.
259      private final String compactVersion;
260    
261      // The list of bugfix IDs.
262      private final String fixIDs;
263    
264      // The Groovy library version.
265      private final String groovyVersion;
266    
267      // The full server version string.
268      private final String fullVersion;
269    
270      // The Berkeley DB JE library version.
271      private final String jeVersion;
272    
273      // The jzlib library version.
274      private final String jzlibVersion;
275    
276      // The LDAP SDK library version.
277      private final String ldapSDKVersion;
278    
279      // The server product name.
280      private final String productName;
281    
282      // The server SDK library version.
283      private final String serverSDKVersion;
284    
285      // The server short product name.
286      private final String shortName;
287    
288      // The SNMP4J library version.
289      private final String snmp4jVersion;
290    
291      // The SNMP4J agent library version.
292      private final String snmp4jAgentVersion;
293    
294      // The SNMP4J AgentX library version.
295      private final String snmp4jAgentXVersion;
296    
297      // The server version qualifier string.
298      private final String versionQualifier;
299    
300    
301    
302      /**
303       * Creates a new version monitor entry from the provided entry.
304       *
305       * @param  entry  The entry to be parsed as a version monitor entry.  It must
306       *                not be {@code null}.
307       */
308      public VersionMonitorEntry(final Entry entry)
309      {
310        super(entry);
311    
312        buildNumber         = getLong(ATTR_BUILD_NUMBER);
313        majorVersion        = getLong(ATTR_MAJOR_VERSION);
314        minorVersion        = getLong(ATTR_MINOR_VERSION);
315        pointVersion        = getLong(ATTR_POINT_VERSION);
316        revisionNumber      = getLong(ATTR_REVISION_NUMBER);
317        buildID             = getString(ATTR_BUILD_ID);
318        compactVersion      = getString(ATTR_COMPACT_VERSION);
319        fixIDs              = getString(ATTR_FIX_IDS);
320        groovyVersion       = getString(ATTR_GROOVY_VERSION);
321        fullVersion         = getString(ATTR_FULL_VERSION);
322        jeVersion           = getString(ATTR_JE_VERSION);
323        jzlibVersion        = getString(ATTR_JZLIB_VERSION);
324        ldapSDKVersion      = getString(ATTR_LDAP_SDK_VERSION);
325        productName         = getString(ATTR_PRODUCT_NAME);
326        serverSDKVersion    = getString(ATTR_SERVER_SDK_VERSION);
327        shortName           = getString(ATTR_SHORT_NAME);
328        snmp4jVersion       = getString(ATTR_SNMP4J_VERSION);
329        snmp4jAgentVersion  = getString(ATTR_SNMP4J_AGENT_VERSION);
330        snmp4jAgentXVersion = getString(ATTR_SNMP4J_AGENTX_VERSION);
331        versionQualifier    = getString(ATTR_VERSION_QUALIFIER);
332      }
333    
334    
335    
336      /**
337       * Retrieves the Directory Server build ID string.
338       *
339       * @return  The Directory Server build ID string, or {@code null} if it was
340       *          not included in the monitor entry.
341       */
342      public String getBuildID()
343      {
344        return buildID;
345      }
346    
347    
348    
349      /**
350       * Retrieves the Directory Server promoted build number.
351       *
352       * @return  The Directory Server promoted build number, or {@code null} if it
353       *          was not included in the monitor entry.
354       */
355      public Long getBuildNumber()
356      {
357        return buildNumber;
358      }
359    
360    
361    
362      /**
363       * Retrieves a compact representation of the Directory Server version string.
364       * It will not contain any spaces.
365       *
366       * @return  A compact representation of the Directory Server version string,
367       *          or {@code null} if it was not included in the monitor entry.
368       */
369      public String getCompactVersion()
370      {
371        return compactVersion;
372      }
373    
374    
375    
376      /**
377       * Retrieves a space-delimited list of the bugfix IDs for special fixes
378       * included in the Directory Server.
379       *
380       * @return  A space-delimited list of the bugfix IDs for special fixes
381       *          included in the Directory Server, or {@code null} if it was not
382       *          included in the monitor entry.
383       */
384      public String getFixIDs()
385      {
386        return fixIDs;
387      }
388    
389    
390    
391      /**
392       * Retrieves the full Directory Server version string.
393       *
394       * @return  The full Directory Server version string, or {@code null} if it
395       *          was not included in the monitor entry.
396       */
397      public String getFullVersion()
398      {
399        return fullVersion;
400      }
401    
402    
403    
404      /**
405       * Retrieves the Groovy library version string.
406       *
407       * @return  The Groovy library version string, or {@code null} if it was not
408       *          included in the monitor entry.
409       */
410      public String getGroovyVersion()
411      {
412        return groovyVersion;
413      }
414    
415    
416    
417      /**
418       * Retrieves the Berkeley DB Java Edition library version string.
419       *
420       * @return  The Berkeley DB Java Edition library version string, or
421       *          {@code null} if it was not included in the monitor entry.
422       */
423      public String getBerkeleyDBJEVersion()
424      {
425        return jeVersion;
426      }
427    
428    
429    
430      /**
431       * Retrieves the jzlib library version string.
432       *
433       * @return  The jzlib library version string, or {@code null} if it was not
434       *          included in the monitor entry.
435       */
436      public String getJZLibVersion()
437      {
438        return jzlibVersion;
439      }
440    
441    
442    
443      /**
444       * Retrieves the UnboundID LDAP SDK for Java library version string.
445       *
446       * @return  The UnboundID LDAP SDK for Java library version string, or
447       *          {@code null} if it was not included in the monitor entry.
448       */
449      public String getLDAPSDKVersion()
450      {
451        return ldapSDKVersion;
452      }
453    
454    
455    
456      /**
457       * Retrieves the Directory Server major version number.
458       *
459       * @return  The Directory Server major version number, or {@code null} if it
460       *          was not included in the monitor entry.
461       */
462      public Long getMajorVersion()
463      {
464        return majorVersion;
465      }
466    
467    
468    
469      /**
470       * Retrieves the Directory Server minor version number.
471       *
472       * @return  The Directory Server minor version number, or {@code null} if it
473       *          was not included in the monitor entry.
474       */
475      public Long getMinorVersion()
476      {
477        return minorVersion;
478      }
479    
480    
481    
482      /**
483       * Retrieves the Directory Server point version number.
484       *
485       * @return  The Directory Server point version number, or {@code null} if it
486       *          was not included in the monitor entry.
487       */
488      public Long getPointVersion()
489      {
490        return pointVersion;
491      }
492    
493    
494    
495      /**
496       * Retrieves the Directory Server product name (e.g., "UnboundID Directory
497       * Server").
498       *
499       * @return  The Directory Server product name, or {@code null} if it was not
500       *          included in the monitor entry.
501       */
502      public String getProductName()
503      {
504        return productName;
505      }
506    
507    
508    
509      /**
510       * Retrieves the source revision number from which the Directory Server was
511       * built.
512       *
513       * @return  The source revision number from which the Directory Server was
514       *          built, or {@code null} if it was not included in the monitor
515       *          entry.
516       */
517      public Long getRevisionNumber()
518      {
519        return revisionNumber;
520      }
521    
522    
523    
524      /**
525       * Retrieves the UnboundID Server SDK library version string.
526       *
527       * @return  The UnboundID Server SDK library version string, or {@code null}
528       *          if it was not included in the monitor entry.
529       */
530      public String getServerSDKVersion()
531      {
532        return serverSDKVersion;
533      }
534    
535    
536    
537      /**
538       * Retrieves the Directory Server short product name (e.g., "UnboundID-DS").
539       *
540       * @return  The Directory Server short product name, or {@code null} if it was
541       *          not included in the monitor entry.
542       */
543      public String getShortProductName()
544      {
545        return shortName;
546      }
547    
548    
549    
550      /**
551       * Retrieves the SNMP4J library version string.
552       *
553       * @return  The SNMP4J library version string, or {@code null} if it was not
554       *          included in the monitor entry.
555       */
556      public String getSNMP4JVersion()
557      {
558        return snmp4jVersion;
559      }
560    
561    
562    
563      /**
564       * Retrieves the SNMP4J agent library version string.
565       *
566       * @return  The SNMP4J agent library version string, or {@code null} if it was
567       *          not included in the monitor entry.
568       */
569      public String getSNMP4JAgentVersion()
570      {
571        return snmp4jAgentVersion;
572      }
573    
574    
575    
576      /**
577       * Retrieves the SNMP4J AgentX library version string.
578       *
579       * @return  The SNMP4J AgentX library version string, or {@code null} if it
580       *          was not included in the monitor entry.
581       */
582      public String getSNMP4JAgentXVersion()
583      {
584        return snmp4jAgentXVersion;
585      }
586    
587    
588    
589      /**
590       * Retrieves the Directory Server version qualifier string (e.g., "-beta1").
591       *
592       * @return  The Directory Server version qualifier string, or {@code null} if
593       *          it was not included in the monitor entry.
594       */
595      public String getVersionQualifier()
596      {
597        return versionQualifier;
598      }
599    
600    
601    
602      /**
603       * {@inheritDoc}
604       */
605      @Override()
606      public String getMonitorDisplayName()
607      {
608        return INFO_VERSION_MONITOR_DISPNAME.get();
609      }
610    
611    
612    
613      /**
614       * {@inheritDoc}
615       */
616      @Override()
617      public String getMonitorDescription()
618      {
619        return INFO_VERSION_MONITOR_DESC.get();
620      }
621    
622    
623    
624      /**
625       * {@inheritDoc}
626       */
627      @Override()
628      public Map<String,MonitorAttribute> getMonitorAttributes()
629      {
630        final LinkedHashMap<String,MonitorAttribute> attrs =
631             new LinkedHashMap<String,MonitorAttribute>(20);
632    
633        if (productName != null)
634        {
635          addMonitorAttribute(attrs,
636               ATTR_PRODUCT_NAME,
637               INFO_VERSION_DISPNAME_PRODUCT_NAME.get(),
638               INFO_VERSION_DESC_PRODUCT_NAME.get(),
639               productName);
640        }
641    
642        if (shortName != null)
643        {
644          addMonitorAttribute(attrs,
645               ATTR_SHORT_NAME,
646               INFO_VERSION_DISPNAME_SHORT_NAME.get(),
647               INFO_VERSION_DESC_SHORT_NAME.get(),
648               shortName);
649        }
650    
651        if (fullVersion != null)
652        {
653          addMonitorAttribute(attrs,
654               ATTR_FULL_VERSION,
655               INFO_VERSION_DISPNAME_FULL_VERSION.get(),
656               INFO_VERSION_DESC_FULL_VERSION.get(),
657               fullVersion);
658        }
659    
660        if (compactVersion != null)
661        {
662          addMonitorAttribute(attrs,
663               ATTR_COMPACT_VERSION,
664               INFO_VERSION_DISPNAME_COMPACT_VERSION.get(),
665               INFO_VERSION_DESC_COMPACT_VERSION.get(),
666               compactVersion);
667        }
668    
669        if (buildID != null)
670        {
671          addMonitorAttribute(attrs,
672               ATTR_BUILD_ID,
673               INFO_VERSION_DISPNAME_BUILD_ID.get(),
674               INFO_VERSION_DESC_BUILD_ID.get(),
675               buildID);
676        }
677    
678        if (majorVersion != null)
679        {
680          addMonitorAttribute(attrs,
681               ATTR_MAJOR_VERSION,
682               INFO_VERSION_DISPNAME_MAJOR_VERSION.get(),
683               INFO_VERSION_DESC_MAJOR_VERSION.get(),
684               majorVersion);
685        }
686    
687        if (minorVersion != null)
688        {
689          addMonitorAttribute(attrs,
690               ATTR_MINOR_VERSION,
691               INFO_VERSION_DISPNAME_MINOR_VERSION.get(),
692               INFO_VERSION_DESC_MINOR_VERSION.get(),
693               minorVersion);
694        }
695    
696        if (pointVersion != null)
697        {
698          addMonitorAttribute(attrs,
699               ATTR_POINT_VERSION,
700               INFO_VERSION_DISPNAME_POINT_VERSION.get(),
701               INFO_VERSION_DESC_POINT_VERSION.get(),
702               pointVersion);
703        }
704    
705        if (buildNumber != null)
706        {
707          addMonitorAttribute(attrs,
708               ATTR_BUILD_NUMBER,
709               INFO_VERSION_DISPNAME_BUILD_NUMBER.get(),
710               INFO_VERSION_DESC_BUILD_NUMBER.get(),
711               buildNumber);
712        }
713    
714        if (versionQualifier != null)
715        {
716          addMonitorAttribute(attrs,
717               ATTR_VERSION_QUALIFIER,
718               INFO_VERSION_DISPNAME_VERSION_QUALIFIER.get(),
719               INFO_VERSION_DESC_VERSION_QUALIFIER.get(),
720               versionQualifier);
721        }
722    
723        if (revisionNumber != null)
724        {
725          addMonitorAttribute(attrs,
726               ATTR_REVISION_NUMBER,
727               INFO_VERSION_DISPNAME_REVISION_NUMBER.get(),
728               INFO_VERSION_DESC_REVISION_NUMBER.get(),
729               revisionNumber);
730        }
731    
732        if (fixIDs != null)
733        {
734          addMonitorAttribute(attrs,
735               ATTR_FIX_IDS,
736               INFO_VERSION_DISPNAME_FIX_IDS.get(),
737               INFO_VERSION_DESC_FIX_IDS.get(),
738               fixIDs);
739        }
740    
741        if (groovyVersion != null)
742        {
743          addMonitorAttribute(attrs,
744               ATTR_GROOVY_VERSION,
745               INFO_VERSION_DISPNAME_GROOVY_VERSION.get(),
746               INFO_VERSION_DESC_GROOVY_VERSION.get(),
747               groovyVersion);
748        }
749    
750        if (jeVersion != null)
751        {
752          addMonitorAttribute(attrs,
753               ATTR_JE_VERSION,
754               INFO_VERSION_DISPNAME_JE_VERSION.get(),
755               INFO_VERSION_DESC_JE_VERSION.get(),
756               jeVersion);
757        }
758    
759        if (jzlibVersion != null)
760        {
761          addMonitorAttribute(attrs,
762               ATTR_JZLIB_VERSION,
763               INFO_VERSION_DISPNAME_JZLIB_VERSION.get(),
764               INFO_VERSION_DESC_JZLIB_VERSION.get(),
765               jzlibVersion);
766        }
767    
768        if (ldapSDKVersion != null)
769        {
770          addMonitorAttribute(attrs,
771               ATTR_LDAP_SDK_VERSION,
772               INFO_VERSION_DISPNAME_LDAP_SDK_VERSION.get(),
773               INFO_VERSION_DESC_LDAP_SDK_VERSION.get(),
774               ldapSDKVersion);
775        }
776    
777        if (serverSDKVersion != null)
778        {
779          addMonitorAttribute(attrs,
780               ATTR_SERVER_SDK_VERSION,
781               INFO_VERSION_DISPNAME_SERVER_SDK_VERSION.get(),
782               INFO_VERSION_DESC_SERVER_SDK_VERSION.get(),
783               serverSDKVersion);
784        }
785    
786        if (snmp4jVersion != null)
787        {
788          addMonitorAttribute(attrs,
789               ATTR_SNMP4J_VERSION,
790               INFO_VERSION_DISPNAME_SNMP4J_VERSION.get(),
791               INFO_VERSION_DESC_SNMP4J_VERSION.get(),
792               snmp4jVersion);
793        }
794    
795        if (snmp4jAgentVersion != null)
796        {
797          addMonitorAttribute(attrs,
798               ATTR_SNMP4J_AGENT_VERSION,
799               INFO_VERSION_DISPNAME_SNMP4J_AGENT_VERSION.get(),
800               INFO_VERSION_DESC_SNMP4J_AGENT_VERSION.get(),
801               snmp4jAgentVersion);
802        }
803    
804        if (snmp4jAgentXVersion != null)
805        {
806          addMonitorAttribute(attrs,
807               ATTR_SNMP4J_AGENTX_VERSION,
808               INFO_VERSION_DISPNAME_SNMP4J_AGENTX_VERSION.get(),
809               INFO_VERSION_DESC_SNMP4J_AGENTX_VERSION.get(),
810               snmp4jAgentXVersion);
811        }
812    
813        return Collections.unmodifiableMap(attrs);
814      }
815    }