I am trying to setup a new custom service, and I would like to be able to update Ambari's view of the configuration from the python script. However, when I try to set a value (e.g. Script.get_config()['configurations']['my-config-file']['my-property'] = "some data"), I see an error telling me I cannot update the immutable config dict.
I see some methods in the Ambari python resource_management.core source such as "update_config", "set_params", etc. that seem like they might be what I need, but they are not well documented.
The Ambari REST API is not an option either, unless I can determine the Ambari username/password from inside the script.
Is there a good way for me to set a property from within the python script?
@Ben Weintraub Thanks for confirming.
- In order to go the Stack Advisor route, check the stack and version on which you are trying to support/add this service.
Lets take example of HDP stack 2.5 and service as HIVE.
Lets say you are adding service named 'myService' in HDP 2.5 stack. You may name you recommendation fn. as "recommendMyServiceConfigurations". You will add this fn. to the dictionary here :
- After that you will write definition for your function "recommendMyServiceConfigurations()", reference fn.:
The way to deposit value for the config can be referred here as :
I assume that you will have relevant config file (.xml) associated with your service, of which configuration that you intend to set/modify is part of. Lets say its name is 'myService-site.xml'.
After that, if this config change is made dependent on any other config change, you need to add depends-on tag. Eg: if you intend to change configs 'A' based on change in config 'B', you may do like this:
<property> <name>A</name> <value>some_value</value> <description></description> <depends-on> <property> <type>B-config_site-name</type> <name>B</name> </property> </depends-on> </property>
- In case there is no explicit dependency possible, you may need to do the forced-configuration use, as otherwise Stack Advisor will filter the recommendation made. You will add the config 'A' in to 'forced-configuration', so that Stack Advisor doesn't filter it out while sending recommendations. Reference:
and then the same way you will deposit value, as mentioned earlier.
For testing while while development, you may put debugs to see we are hitting the code and eventually depositing value to config. Finally, whether the recommendation actually made way to UI, you can do it by doing inspect element on browser. Example browser on Chrome, and we are have set the value for config 'hive.llap.daemon.yarn.container.mb' on same lines as mentioned above.
Let me know if you run into any issues and the stage you are at while developing/testing.