Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In order to retrieve the value from the configuration variable, perform the following.  Note that if the configuration variable is meant to be used by multiple components, it should probably be declared in a common interface or class.  Note  Note that use you should never save the return value if you want to dynamically change if the configurable value is changed.

Code Block
// Use case 1: To retrieve the global value
ManagementHostIPAdr.value();


// Use case 2: To retrieve the variable but first look for the override in zone.  
// Note that this will give an error for this variable as it was not declared as a scoped variable.
ManagementHostIPAdr.valueIn(zoneId);


// Use case 3: To use configuration that's declared by a different component.
public class NotClusterManagerChildrenNotChildOfClusterManager {
    ClusterManager.ManagementHostIPAddr.value();
}


// Use case 4: To use a configuration that you know it's there but you can't compile against.
// I strongly advise against this.  If a developer did not put their configuration variable in
// an interface for you to use, it's best to communicate with that developer and make sure you
// agree on where to place it.
public class NoCompilationAccessToClusterManager {
  @Inject ConfigDepot _depot;
  ConfigKey<?> mgmtAddr = _depot.get("host");
}
Managing the configuration

...

parameter

To manage the configuration

...

parameter, cloud-framework-config provides a Configurable interface.  By implementing this interface, the component declares itself to be a provider of configuration keys.  The keys and the default values are saved into the configuration table.

Code Block
public interface Configurable {

    /**
     * @return The name of the component that provided this configuration
     * variable.  This value is saved in the database so someone can easily
     * identify who provides this variable.
     **/
    String getConfigComponentName();

    /**
     * @return The list of config keys provided by this configuable.
     */
    ConfigKey<?>[] getConfigKeys();
}

How do I find which component declared a parameter I want to use?

Sharing configuration parameter should be done after some thought.  You want to make sure the original implementer intended the configuration parameter to be shared.  A clear indication would be if they defined it on an interface.  If not, it might have been just because they didn't think about it. 

To find out which component defined the parameter, look in the component field of the configuration table.  It will show which component defined the parameter that you might want to use.

How does it work?

On startup, ConfigDepotImpl gathers all of the Configurable interfaces and constructs a set of keys.  It checks to see if the key is already in the database already.  If not, then it populates the database with the default values.  If a key that is in the database but is no longer found in the key list, the updated field is changed to null.  At which point, an admin can decide to delete the obsolete key.  Going forward, any caching or special implementation will go into ConfigDepotImpl and no other components need to modify the core CloudStack code to add their own configuration variables.

What to do on CloudStack upgrades?

On every CloudStack upgrade, it will go through the list of configuration keys.  If a key is obsolete, it changes the update field of the row to null.  That key can be deleted or just left alone.  If the update field has been changed with the latest timestamp, it means some field in that row has changed and required updating.  The upgrades never changes the value field as that belongs to the administrator but it might change the default value field to show our defaults have changed.  If you didnot make changes to the value of the configuration parameter, you might want to update it to be the same as the new default value.

Todo Items

Todo items are found in the comments for ConfigDepotImpl.  Please add/remove on it if you take up different items.