Retrieving configurations from the Centralized Configuration


Configurations of certain components such as AR System server, Flashboards, Approval Server and many more are stored in the Centralized Configuration. Use the Configuration API to perform different operations, such as Create, Read, Update, and Delete for configurations stored in the Centralized Configuration. The Configuration API is a part of arapi91_build004.jar AR API JAR file.

Advantages of using the Configuration API

  • By using this API, you can retrieve the required value of a setting.
    For example, you can retrieve a global-level value for a setting that has a local-level value set.
  • Backward compatibility is managed reliably and effectively.

Best Practice
We recommend that you use the Configuration API to create, update, or retrieve the configurations from the Centralized Configuration.



Using the Configuration API for the settings in the Centralized Configuration

You can perform Create, Retrieve, Update, and Delete (CRUD) operations by using the Configuration API. The following table lists the APIs and syntax for using the API:

API name

Description

Syntax

createSettingEntries

Creates a new Centralized Configuration.

createSettingEntries(String componentGUID,
String componentName,String componentType,
List<String[]> nameValuePair)

Does not create a local -level configuration if a global-level value has been set for the same configuration.

Creates a new local-level configuration if a configuration does not exist.

createSettingEntries(String componentGUID,
String componentName,
String componentType, List<String[]> nameValuePair,
 
boolean bConsiderGlobal)

CreateComponentAndSettings

Creates a new component and new settings if they do not already exist.

CreateComponentAndSettings(String componentName, String componentType, String componentDescription, List<String[]> nameValuePair)

Does not create a local -level configuration if a global-level value has been set for the same configuration.

Creates a new local-level configuration if a configuration does not exist.

String createComponentAndSettings(String componentName, String componentType, String componentDescription, List<String[]> nameValuePair, boolean bConsiderGlobal)
List

Retrieves an existing Centralized configuration.

Gives a list of all matching parameters.

List<String[]> getConfigSettingsAsList(String configName, String configType,String settingName, int settingType) 

Returns the effective value of a setting.

List<String[]> getConfigSettingsAsList(String configName, String configType,String settingName) 
Map

Returns a name value pair as a map, where the setting name is unique.

Map<String, List<String>> getConfigSettingsAsMap(String configName, String configType, String settingName, int settingType)

Returns the effective value of a setting.

Map<String, List<String>> getConfigSettingsAsMap(String configName, String configType, String settingName)

updateConfigSetting

Updates an existing configuration.

Updates the setting value based on the entry ID that you provide.

updateConfigSetting(String settingEntryID, String settingName, String settingValue)

Identifies the entry based on details such as GUID, Component Name that you provide, and updates the value.

Creates a new entry if an entry does not exist.

updateOrCreateSetting(String componentGUID, String componentName, String componentType, String settingName, String settingValue)

deleteSetting

Deletes an existing configuration.

Checks if an entry exists that matches the provided details. If yes, deletes the entry.

Deletes only one entry at a time.

deleteSetting(String componentName, String componentType, String settingName, String settingValue)

Deletes all the entries that matche with the setting name you provide.

deleteSetting(String componentName, String componentType, String settingName)

Deletes an entry that you pass as a parameter.

deleteSettingWithEntryId(String componentName, String componentType, Entry entry)

Code example

The following code sample illustrates different operations such as Create Settings, List Settings, and Delete Settings that you can perform using the Configuration API:

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.bmc.arsys.api.ARException;
import com.bmc.arsys.api.ARServerUser;
import com.bmc.arsys.api.Constants;
import com.bmc.arsys.api.Entry;
import com.bmc.arsys.util.ArrayCentralConfig;
import com.bmc.arsys.util.CentralConfigFactory;

public class ArrayCentralConfigTest {
    protected static ARServerUser serverUser = null;
    protected static ArrayCentralConfig centralConfig = null;
    protected static String user = "Demo";
    protected static String password = "";
    protected static String authentication = "";
    protected static String locale = null;
    protected static String serverName = "localhost";
    protected static int tcpPort = 0;

    public static void main(String[] args) throws ARException {

        ARServerUser serverUser = new ARServerUser(user, password, authentication, locale,
                serverName,
            tcpPort);
        CentralConfigFactory factory = CentralConfigFactory.newInstance(serverUser);
        centralConfig = factory.newArrayCentralConfig();

        CreateSettingEntries();
        CreateSettingEntriesConsiderGlobal();
        CreateComponentAndSettings();
        CreateComponentAndSettingsConsiderGlobal();
        getConfigSettingsAsListSpecificSettings();
        getConfigSettingsAsListSpecificSettings();
        getConfigSettingsAsListSpecificSettings();
        getConfigSettingsAsList();
        getConfigSettingsAsMapSpecificSettings();
        getConfigSettingsAsMapSpecificSettings();
        getConfigSettingsAsMapSpecificSettings();
        getConfigSettingsAsMap();
        updateConfigSetting();
        updateOrCreateSetting();
        deleteSettingwithKeyandValue();
        deleteSettingwithKey();
        deleteSettingWithEntryId();

    }

   /* Function will create configuration setting with name MyKey and value MyValue
    * for component type server and component name myservername
    */
    static void CreateSettingEntries() throws ARException {
        List<String[]> nameValuePair = new ArrayList<String[]>();
        String nameValue[] = { "MyKey", "MyValue" };
        nameValuePair.add(nameValue);
        centralConfig.createSettingEntries(null, "myservername", "com.bmc.arsys.server",
                nameValuePair);
    }

   /* Function will create configuration setting with name MyKey and value MyValue
    * for component type server and component name myservername in following scenarios
    * 1. if config setting MyKey does not exists for component type server in global configuration
    * 2. if config setting MyKey exists for component type server in global configuration, but its value is different
    *
    */
    static void CreateSettingEntriesConsiderGlobal() throws ARException {
        List<String[]> nameValuePair = new ArrayList<String[]>();
        String nameValue[] = { "MyKey", "MyValue" };
        nameValuePair.add(nameValue);
        centralConfig.createSettingEntries(null, "myservername", "com.bmc.arsys.server",
                nameValuePair, true);
    }

   /* Function will first delete all the settings for component type server and component name myservername if exist
    * if not then will create component of type server and componentname myservername
    * then create configuration settings passed in nameValuePair
    *
    */
    static void CreateComponentAndSettings() throws ARException {
        List<String[]> nameValuePair = new ArrayList<String[]>();
        String nameValue[] = { "MyKey", "MyValue" };
        nameValuePair.add(nameValue);
        centralConfig.createComponentAndSettings(null, "myservername", "com.bmc.arsys.server",
                nameValuePair);
    }

   /* Function will first delete all the settings for component type server and component name myservername if exist
    * if not then will create component of type server and componentname myservername
    * then create configuration settings passed in nameValuePair in following scenarios
    * 1. if config setting does not exists for component type server in global configuration
    * 2. if config setting exists for component type server in global configuration, but its value is different
    *
    */
    static void CreateComponentAndSettingsConsiderGlobal() throws ARException {
        List<String[]> nameValuePair = new ArrayList<String[]>();
        String nameValue[] = { "MyKey", "MyValue" };
        nameValuePair.add(nameValue);
        centralConfig.createComponentAndSettings(null, "myservername", "com.bmc.arsys.server",
                nameValuePair, true);
    }

   /* Function will get requested or all the settings for component type server and component name myservername
    * in case some settings have multiple entries in ccs form, it will return one for each.
    * If third parameter i.e. settingName is passed as null then all the setting are returned else one specified
    * If fourth parameter i.e. setting type is passed as Constants.GLOBAL_SETTINGS, only global settings will be considered
    *                          setting type is passed as Constants.LOCAL_SETTINGS, only local settings will be considered
    *                          setting type is passed as Constants.MERGED_SETTINGS, merged settings will be considered
    */
    static void getConfigSettingsAsListSpecificSettings() throws ARException {
        List<String[]> settings = centralConfig.getConfigSettingsAsList("myservername",
               "com.bmc.arsys.server", null, Constants.GLOBAL_SETTINGS);

    }

   /* Function will get requested or all the settings for component type server and component name myservername
    * in case some settings have multiple entries in ccs form, it will return one for each.
    * If third parameter i.e. settingName is passed as null then all the setting are returned else one specified
    * This version will always return merged settings
    */
    static void getConfigSettingsAsList() throws ARException {
        List<String[]> settings = centralConfig.getConfigSettingsAsList("myservername",
               "com.bmc.arsys.server", null);
    }

   /* Function will get requested or all the settings for component type server and component name myservername
    * in case some settings have multiple entries in ccs form, it only one entry with lst having for value for each value.
    * If third parameter i.e. settingName is passed as null then all the setting are returned else one specified
    * If fourth parameter i.e. setting type is passed as Constants.GLOBAL_SETTINGS, only global settings will be considered
    *                          setting type is passed as Constants.LOCAL_SETTINGS, only local settings will be considered
    *                          setting type is passed as Constants.MERGED_SETTINGS, merged settings will be considered
    */
    static void getConfigSettingsAsMapSpecificSettings() throws ARException {
        Map<String, List<String>> settings = centralConfig.getConfigSettingsAsMap("myservername",
               "com.bmc.arsys.server", null,
                Constants.GLOBAL_SETTINGS);
    }

   /* Function will get requested or all the settings for component type server and component name myservername
    * in case some settings have multiple entries in ccs form, it only one entry with lst having for value for each value.
    * If third parameter i.e. settingName is passed as null then all the setting are returned else one specified
    * This implementaion will always return merged entries
    */
    static void getConfigSettingsAsMap() throws ARException {
        Map<String, List<String>> settings = centralConfig.getConfigSettingsAsMap("myservername",
               "com.bmc.arsys.server", null);

    }

   /* Function sets value of setting MyKey with new value MyNewValue for component type server and
    * component name myservername
    */
    static void updateConfigSetting() throws ARException {
        List<Entry> settingEntries = centralConfig.getConfigSettingsWithEntryIDs("myservername",
               "com.bmc.arsys.server", "MyKey");
       if (settingEntries != null && settingEntries.size() > 0) {
            String entryID = settingEntries.get(0).getEntryId();
            String settingValue = "MyNewValue";
            centralConfig.updateConfigSetting(entryID, "MyKey", settingValue);
        }

    }

   /* Function sets value of setting MyKey with new value MyNewValue for component type server and
    * component name myservername if setting exists else creates new entry
    */
    static void updateOrCreateSetting() throws ARException {
        centralConfig.updateOrCreateSetting(null, "myservername", "com.bmc.arsys.server", "MyKey",
               "MyNewValue");
    }

   /* Function deletes setting MyKey for component type server and
    * component name myservername if its value is MyValue
    */
    static void deleteSettingwithKeyandValue() throws ARException {
        centralConfig.deleteSetting("myservername", "com.bmc.arsys.server", "MyKey", "MyValue");
    }

   /* Function deletes all the settings with name MyKey for component type server and
    * component name myservername
    */
    static void deleteSettingwithKey() throws ARException {
        centralConfig.deleteSetting("myservername", "com.bmc.arsys.server", "MyKey");
    }

   /* Function deletes setting defined by entry
    */
    static void deleteSettingWithEntryId() throws ARException {
        List<Entry> settingEntries = centralConfig.getConfigSettingsWithEntryIDs("myservername",
               "com.bmc.arsys.server", "MyKey");
       if (settingEntries != null && settingEntries.size() > 0) {
            centralConfig.deleteSettingWithEntryId("myservername", "com.bmc.arsys.server",
                    settingEntries.get(0));
        }
    }
}



 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*