Default configuration does not contain default DeploymentContext variables
ConfigurationManager.setDeploymentContext is called from the static initializer, but it doesn't do anything unless you have specified a custom configuration or a custom configuration factory. To get interpolation of @environment, @serverId etc. to work it seems you need to call
ConfigurationManager.setDeploymentContext(ConfigurationManager.getDeploymentContext());
which looks a bit odd.
There are two ways to set the deployment context:
- Specify the class name of factory name of the DeploymentContext as a system property at start up
- By default, ConfigurationBasedDeploymentContext will be instantiated and installed as the deployment context. But unless you set the corresponding properties prefixed with "archaius.deployment" or explicitly call the setters, the getters will return null.
I suggest using the first approach since the way to define a deployment context is really application dependent.
Hi, Thanks for the clarification. I'm talking specifically about the second case here, using the default ConfigurationBasedDeploymentContext as well as the default and lazily instantiated ConcurrentCompositeConfiguration.
The issue is that even when you use the default ConfigurationBasedDeploymentContext and set the properties with the prefixes as VM arguments (like -Darchaius.configuration.environment=test), neither ConfigurationManager.setDeploymentContext nor ConfigurationBasedDeploymentContext.setValueInConfig is called.
This means that while ConfigurationManager.getDeploymentContext().getEnvironment() works, ConfigurationManager.getConfigInstance().getString("@environment") does not, even though it should according to: https://github.com/Netflix/archaius/wiki/Deployment-context (at the very bottom of the page). For the same reason properties that reference ${@environment} won't work.
@jakber I think it is the same issue as
https://github.com/Netflix/archaius/issues/116
There was a suggested fix there. I have not been able to get to it. Feel free to send a pull request if you have the bandwidth.
@jakber @gorzell
In my last pull request, this problem is fixed. However, I made a change to ConfigurationBasedDeploymentContext to have its key names the same as the standard property names in the format of @<name>. For example, the region key for ConfigurationBasedDeploymentContext was used to be archaius.deployment.region, after my change it will be @region. I think this change will resolve confusions about deployment context property names. However, it means that if you have to change the deployment context property name in your application set up. Let me know if this is OK with you.
The test DefaultDeploymentContextTest and CascadedPropertiesWithDeploymentContextTest (which was failing previously due to the same issue and was skipped) shows that the problem is fixed.
@gorzell In the last commit in the pull request, I restored those "archaius.*" properties. Now backward compatibility is ensured. Please take a look.