You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ambari.apache.org by Dai Xiang <xi...@sky-data.cn> on 2018/01/05 01:29:03 UTC

How do services get configuartion and use them?

Hi!

I am new to Ambari and i have a question:
I want to write a customized service and want to use settings in config, but
how do service get and use configuration?

I find that getResource function read configs and compress them in
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java?

But i do not find where service use those config.

I guess i miss something important.

Could anyone help me?

-- 
Best Regards
Dai Xiang

Re: How do services get configuartion and use them?

Posted by Gonzalo Herreros <gh...@gmail.com>.
Hi,

Ambari invokes your Python scripts and provides you a number of libraries
you can import to extract the configuration you want and pass it to some
shell script if you want.
Your Python script needs to extend Script and implement some methods:

class MyServiceComponent(Script):

  def install(self, env):
    #Ask ambari to install packages, copy files, etc.

  def status(self, env):
     #Normally you just ask ambari here to check if your process is running
or throw an exception otherwise

  def start(self, env):
      #Invoke a shell script using ambari Execute to run your process


Then you can read the config config inside the script, example:

from resource_management.libraries.script.script import Script
config = Script.get_config()
hdfs_site = config['configurations']['hdfs-site']

Ambari knows which script to run for each component because it's referenced
in the service metainfo.xml file.

Example of a component script:
https://github.com/apache/ambari/blob/trunk/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/package/scripts/kafka_broker.py
See how it's referenced here:
https://github.com/apache/ambari/blob/trunk/ambari-server/src/main/resources/common-services/KAFKA/0.8.1/metainfo.xml
(While the config says scriptType=PYTHON, I don't think any other type is
supported).

More information here:
https://cwiki.apache.org/confluence/display/AMBARI/Defining+a+Custom+Stack+and+Services

Regards,
Gonzalo

On 5 January 2018 at 01:29, Dai Xiang <xi...@sky-data.cn> wrote:

> Hi!
>
> I am new to Ambari and i have a question:
> I want to write a customized service and want to use settings in config,
> but
> how do service get and use configuration?
>
> I find that getResource function read configs and compress them in
> ambari-server/src/main/java/org/apache/ambari/server/controller/internal/
> ClientConfigResourceProvider.java?
>
> But i do not find where service use those config.
>
> I guess i miss something important.
>
> Could anyone help me?
>
> --
> Best Regards
> Dai Xiang
>