001package com.pingidentity.ds.plugin; 002 003import com.unboundid.directory.sdk.common.api.MonitorProvider; 004import com.unboundid.directory.sdk.common.config.MonitorProviderConfig; 005import com.unboundid.directory.sdk.common.types.ServerContext; 006import com.unboundid.ldap.sdk.Attribute; 007import com.unboundid.ldap.sdk.ResultCode; 008import com.unboundid.util.args.ArgumentParser; 009 010import java.util.ArrayList; 011import java.util.List; 012 013public class SnapshotChangelogMonitorProvider extends MonitorProvider 014{ 015 016 public static final String ATTR_NAME_CURRENT_CHANGE_NUMBER = "current-change-number"; 017 private final SnapshotChangelog snapshotChangelog; 018 019 public SnapshotChangelogMonitorProvider(SnapshotChangelog snapshotChangelog) 020 { 021 this.snapshotChangelog = snapshotChangelog; 022 023 } 024 025 @Override 026 public void initializeMonitorProvider(ServerContext serverContext, MonitorProviderConfig config, 027 ArgumentParser parser) 028 { 029 } 030 031 /** 032 * Performs the necessary processing to compute the extension name 033 * 034 * @return the extension name 035 */ 036 @Override 037 public String getExtensionName() 038 { 039 return "Snapshot Changelog Monitor Provider"; 040 } 041 042 /** 043 * Performs the necessary processing to provide a list of descriptive paragraphs about the extension 044 * 045 * @return an array of descriptive paragraphs 046 */ 047 @Override 048 public String[] getExtensionDescription() 049 { 050 return new String[]{"This extension provides monitoring information about the Snapshot Changelog it depends " + 051 "from"}; 052 } 053 054 /** 055 * Performs the necessary processing to compute the name of the instance of the extension 056 * 057 * @return the name of the instance of the monitor provider 058 */ 059 @Override 060 public String getMonitorInstanceName() 061 { 062 final String suffix = " extension monitor"; 063 String name = "Default snapshot-changelog"; 064 if ( snapshotChangelog != null && snapshotChangelog.config != null && snapshotChangelog.config.getConfigObjectName() != null ) 065 { 066 name = snapshotChangelog.config.getConfigObjectName(); 067 } 068 return name + suffix; 069 } 070 071 /** 072 * Performs the necessary processing to compute the attributes to feature in the monitoring entry 073 * 074 * @return list of attributes to return in the monitoring entry corresponding to the instance of SnapshotChangelog 075 */ 076 @Override 077 public List<Attribute> getMonitorAttributes() 078 { 079 List<Attribute> result = new ArrayList<>(); 080 result.add(new Attribute(SnapshotChangelog.CHANGELOG_PREFIX + ATTR_NAME_CURRENT_CHANGE_NUMBER, 081 snapshotChangelog.persister.getCurrentChangeNumber().toString())); 082 return result; 083 } 084 085 @Override 086 public boolean isConfigurationAcceptable(MonitorProviderConfig config, ArgumentParser parser, List<String> 087 unacceptableReasons) 088 { 089 return true; 090 } 091 092 @Override 093 public void defineConfigArguments(ArgumentParser parser) 094 { 095 } 096 097 @Override 098 public ResultCode applyConfiguration(MonitorProviderConfig config, ArgumentParser parser, List<String> 099 adminActionsRequired, List<String> messages) 100 { 101 return ResultCode.SUCCESS; 102 } 103 104 @Override 105 public String getMonitorObjectClass() 106 { 107 return null; 108 } 109 110 @Override 111 public void finalizeMonitorProvider() 112 { 113 } 114}