Service Metainfo and Component Category
metainfo.xml file in a Service describes the service, the components of the service and the management scripts to use for executing commands. A component of a service must be either a MASTER, SLAVE or CLIENT category. The <category> tells Ambari what default commands should be available to manage and monitor the component. Details of various sections in metainfo.xml can be found in the Writing metainfo.xml section..
For each Component you must specify the <commandScript> to use when executing commands. There is a defined set of default commands the component must support depending on the components category.
|Component Category||Default Lifecycle Commands|
|MASTER||install, start, stop, configure, status|
|SLAVE||install, start, stop, configure, status|
|CLIENT||install, configure, status|
Ambari supports different commands scripts written in PYTHON. The type is used to know how to execute the command scripts. You can also create custom commands if there are other commands beyond the default lifecycle commands your component needs to support.
For example, in the YARN Service describes the ResourceManager component as follows in
The ResourceManager is a MASTER component, and the command script is
scripts/resourcemanager.py, which can be found in the
services/YARN/package directory. That command script is PYTHON and that script implements the default lifecycle commands as python methods. This is the install method for the default INSTALL command:
You can also see a custom command is defined DECOMMISSION, which means there is also a decommission method in that python command script:
Implementing a Custom Service
In this example, we will create a custom service called "SAMPLESRV". This service includes MASTER, SLAVE and CLIENT components.
Create a Custom Service
Create a directory named
SAMPLESRVthat will contain the service definition for SAMPLESRV.
SAMPLESRVdirectory, create a
metainfo.xmlfile that describes the new service. For example:
- In the above, the service name is "SAMPLESRV", and it contains:
- one MASTER component "SAMPLESRV_MASTER"
- one SLAVE component "SAMPLESRV_SLAVE"
- one CLIENT component "SAMPLESRV_CLIENT"
Next, let's create that command script. Create a directory for the command script
package/scriptsthat we designated in the service metainfo.
Within the scripts directory, create the
.pycommand script files mentioned in the metainfo.
Implementing a Custom Command
Browse to the
SAMPLESRVdirectory, and edit the
metainfo.xmlfile that describes the service. For example, adding a custom command to the SAMPLESRV_CLIENT:
Next, let's create that command script by editing the package/scripts/sample_client.py file that we designated in the service metainfo.
Adding Configs to the Custom Service
In this example, we will add a configuration type "test-config" to our SAMPLESRV.
Modify the metainfo.xml
Create a directory for the configuration dictionary file
test-config.xmlfile. For example:
There is an optional setting "configuration-dir". Custom services should either not include the setting or should leave it as the default value "configuration".
- Configuration dependencies can be included in the metainfo.xml in the a "
configuration-dependencies" section. This section can be added to the service as a whole or a particular component. One of the implications of this dependency is that whenever the config-type is updated, Ambari automatically marks the component or service as requiring restart.