Services managed by Ambari are defined in its stacks folder.
To define your own services and stacks to be managed by Ambari, follow the steps below.
There is also an example you can follow on how to create your custom stack and service.
A stack is a collection of services. Multiple versions of a stack can be defined, each with its own set of services. Stacks in Ambari are defined in ambari-server/src/main/resources/stacks folder, which can be found at /var/lib/ambari-server/resources/stacks folder after install.
Services managed by a stack can be defined either in ambari-server/src/main/resources/common-services or ambari-server/src/main/resources/stacks folders. These folders after install can be found at /var/lib/ambari-server/resources/common-services or /var/lib/ambari-server/resources/stacks folders respectively.
Question: When do I define service in common-services vs. stacks folders?
One would define services in the common-services folder if there is possibility of the service being used in multiple stacks. For example, almost all stacks would need the HDFS service - so instead of redefining HDFS in each stack, the one defined in common-services is referenced. Likewise, if a service is never going to be shared, it can be defined in the stacks folder. Basically services defined in stacks folder are used by containment, whereas the ones defined in common-services are used by reference.
Shown below is how to define a service in common-services folder. The same approach can be taken when defining services in the stacks folder, which will be discussed in the Define Stack section.
Services MUST provide the main metainfo.xml file which provides important metadata about the service.
Apart from that, other files can be provided to give more information about the service. More details about these files are provided below.
A service may also inherit from either a previous stack version or common services. For more information see the Service Inheritance page.
In the metainfo.xml service descriptor, one can first define the service and its components.
Question: Is it possible to define multiple services in the same metainfo.xml?
Yes. Though it is possible, it is discouraged to define multiple services in the same service folder.
With the components defined, we need to provide scripts which can handle the various stages of the service and component's lifecycle.
The scripts necessary to manage service and components are specified in the metainfo.xml (HDFS)
Each of these scripts should extend the Script class which provides useful methods. Example: NameNode script
These scripts should be provided in the <service-id>/<service-version>/package/scripts folder.
|package/scripts||Contains scripts invoked by Ambari. These scripts are loaded into the execution path with the correct environment. |
|package/files||Contains files used by above scripts. Generally these are other scripts (bash, python, etc.) invoked as a separate process. |
Example: checkWebUI.py is run in HDFS service-check to determine if Journal Nodes are available
Template files used by above scripts to generate files on managed hosts. These are generally configuration files required by the service to operate.
Ambari by default supports Python scripts for management of service and components.
Component scripts should extend
resource_management.Script class and provide methods required for that component's lifecycle.
Taken from the page on how to create custom stack, the following methods are needed for MASTER, SLAVE and CLIENT components to go through their lifecycle.
Ambari provides helpful Python libraries below which are useful in writing service scripts. For complete reference on these libraries visit the Ambari Python Libraries page.
OS Variant Scripts
If the service is supported on multiple OSes which requires separate scripts, the base resource_management.Script class can be extended with different @OsFamilyImpl() annotations.
This allows for the separation of only OS specific methods of the component.
Example: NameNode default script, NameNode Windows script.
DataNode Start and Stop.
Sometimes services need to perform actions unique to that service which go beyond the default actions provided by Ambari (like install, start, stop, configure, etc.).
Services can define such actions and expose them to the user in UI so that they can be easily invoked.
As an example, we show the Rebalance HDFS custom action implemented by HDFS.
- Define custom command inside the customCommands section of the component in metainfo.xml.
- Implement method with same name as custom command in script referenced from metainfo.xml.
This will provide ability by the backend to run the script on all managed hosts where the service is installed.
No UI changes are necessary to see the custom action on the host page.
The action should show up in the host-component's list of actions. Any master-component actions will automatically show up on the service's action menu.
When the action is clicked in UI, the POST call is made automatically to trigger the script defined above.
Question: How do I provide my own label and icon for the custom action in UI?
In Ambari UI, add your component action to the App.HostComponentActionMap object with custom icon and name. Ex: REBALANCEHDFS.
Configuration files for a service should be placed by default in the configuration folder.
If a different named folder has to be used, the <configuration-dir> element can be used in metainfo.xml to point to that folder.
The important sections of the metainfo.xml with regards to configurations are:
- config-type - String representing a group of configurations. Example: core-site, hdfs-site, yarn-site, etc. When configurations are saved in Ambari, they are persisted within a version of config-type which is immutable. If you change and save HDFS core-site configs 4 times, you will have 4 versions of config-type core-site. Also, when a service's configs are saved, only the changed config-types are updated.
- configFiles - lists the config-files handled by the enclosing component
- configFile - represents one config-file of a certain type
- type - type of file based on which contents are generated differently
- xml - XML file generated in Hadoop friendly format. Ex: hdfs-site.xml
- env - Generally used for scripts where the content value is used as a template. The template has config-tags whose values are populated at runtime during file generation. Ex: hadoop-env.sh
- properties - Generates property files where entries are in key=value format. Ex: falcon-runtime.properties
- dictionaryName - Name of the config-type as which key/values of this config file will be stored
- type - type of file based on which contents are generated differently
- configuration-dependencies - Lists the config-types on which this component or service depends on. 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. From the code section above, whenever core-site is updated, both HDFS service as well as HDFS_CLIENT component will be marked as requiring restart.
- configuration-dir - Directory where files listed in configFiles will be. Optional. Default value is configuration.
Adding new configs in a config-type
There are a number of different parameters that can be specified to a config item when it is added to a config-type. These have been covered here.
UI - Categories
Configurations defined above show up in the service's Configs page.
To customize categories and ordering of configurations in UI, the following files have to be updated.
Create Category - Update the ambari-web/app/models/stack_service.js file to add your own service, along with your new categories.
Use Category - To place configs inside a defined category, and specify an order in which configs are placed, add configs to ambari-web/app/data/HDP2/site_properties.js file. In this file one can specify the category to use, and the index where a config should be placed. The stack folders in ambari-web/app/data are hierarchical and inherit from previous versions. The mapping of configurations into sections is defined here. Example Hive Categories, Tez Categories.
UI - Enhanced Configs
The Enhanced Configs feature makes it possible for service providers to customize their service's configs to a great deal and determine which configs are prominently shown to user without making any UI code changes. Customization includes providing a service friendly layout, better controls (sliders, combos, lists, toggles, spinners, etc.), better validation (minimum, maximum, enums), automatic unit conversion (MB, GB, seconds, milliseconds, etc.), configuration dependencies and improved dynamic recommendations of default values.
A service provider can accomplish all the above just by changing their service definition in the stacks/ folder.
Read more in the Enhanced Configs page
Each service is capable of defining which alerts Ambari should track by providing an alerts.json file.
Ambari is capable of enabling and disabling Kerberos for a cluster. To inform Ambari of the identities and configurations to be used for the service and its components, each service can provide a kerberos.json file.
Ambari provides the Ambari Metrics System ("AMS") service for collecting, aggregating and serving Hadoop and system metrics in Ambari-managed clusters.
A service can add a list of quick links to the Ambari web UI by adding metainfo to a text file following a predefined JSON format. Ambari server parses the quicklink JSON file and provides its content to the UI. So that Ambari web UI can calculate quick link URLs based on the information and populate the quicklinks drop-down list accordingly.
Read more about quick links JSON file design in the Quick Links page.
Each service can define which widgets and heatmaps show up by default on the service summary page by defining a widgets.json file.
You can read more about the widgets descriptor in the Enhanced Service Dashboard page.
Role Command Order
From Ambari 2.2, each service can define its own role command order by including the role_command_order.json file in its service folder. The service should only specify the relationship of its components to other components. In other words, if a service only includes COMP_X, it should only list dependencies related to COMP_X. If when COMP_X starts it is dependent on the NameNode start and when the NameNode stops it should wait for COMP_X to stop, the following would be included in the role command order:
The entries in the service's role command order will be merged with the role command order defined in the stack. For example, since the stack already has a dependency for NAMENODE-STOP, in the example above COMP_X-STOP would be added to the rest of the NAMENODE-STOP dependencies and in addition the COMP_X-START dependency on NAMENODE-START would just be added as a new dependency.
For more details on role command order, see the Role Command Order section below.
From Ambari 2.4, each service can choose to define its own service advisor rather than define the details of its configuration and layout in the stack advisor. This is particularly useful for custom services which are not defined in the stack. Ambari provides the Service Advisor capability where a service can write a Python script named service-advisor.py in their service folder. This folder can be in the stack's services directory where the service is defined or can be inherited from the service definition in common-services or elsewhere. Example: common-services/HAWQ/2.0.0.
Unlike the Stack-advisor scripts, the service-advisor scripts do not automatically extend the parent service's service-advisor scripts. The service-advisor script needs to explicitly extend their parent's service service-advisor script. The following code sample shows how you would refer to a parent's service_advisor.py. In this case it is extending the root service-advisor.py file in the resources/stacks directory.
Like the stack advisors, service advisors provide information on 4 important aspects:
- Recommend layout of the service on cluster
- Recommend service configurations
- Validate layout of the service on cluster
- Validate service configurations
By providing the service-advisor.py file, one can control dynamically each of the above for the service.
The main interface for the service-advisor scripts contains documentation on how each of the above are called, and what data is provided.
- Service Advisor interface
- HAWQ 2.0.0 Service Advisor implementation
- PXF 3.0.0 Service Advisor implementation
From Ambari 2.4, each service can now define its upgrade within its service definition. This is particularly useful for custom services which no longer need to modify the stack's upgrade-packs in order to integrate themselves into the cluster upgrade.
Each service can define upgrade-packs, which are XML files describing the upgrade process of that particular service and how the upgrade pack relates to the overall stack upgrade-packs. These upgrade-pack XML files are placed in the service's upgrades/ folder in separate sub-folders specific to the stack-version they are meant to extend. Some examples of this can be seen in the testing code.
Each upgrade-pack that the service defines should match the file name of the service defined by a particular stack version. For example in the testing code, HDP 2.2.0 had an upgrade_test_15388.xml upgrade-pack. The HDFS service defined an extension to that upgrade pack HDP/2.0.5/services/HDFS/upgrades/HDP/2.2.0/upgrade_test_15388.xml. In this case the upgrade-pack was defined in the HDP/2.0.5 stack. The upgrade-pack is an extension to HDP/2.2.0 because it is defined in upgrade/HDP/2.2.0 directory. Finally the name of the service's extension to the upgrade-pack upgrade_test_15388.xml matches the name of the upgrade-pack in HDP/2.2.0/upgrades.
The file format for the service is much the same as that of the stack. The target, target-stack and type attributes should all be the same as the stack's upgrade-pack. The service is able to add its own prerequisite checks.
The order section of the upgrade-pack, consists of group elements just like the stack's upgrade-pack. The key difference is defining how these groups relate to groups in the stack's upgrade pack or other service upgrade-packs. In the first example we are referencing the PRE_CLUSTER group and adding a new execute-stage for the service FOO. The entry is supposed to be added after the execute-stage for HDFS based on the <add-after-group-entry> tag.
The same syntax can be used to order other sections like service check priorities and group services.
It is also possible to add new groups and order them after other groups in the stack's upgrade-packs. In the following example, we are adding the FOO group after the HIVE group using the add-after-group tag.
You could also include both the add-after-group and the add-after-group-entry tags in the same group. This will create a new group if it doesn't already exist and will order it after the add-after-group's group name. The add-after-group-entry will determine the internal ordering of that group's services, priorities or execute stages.
The processing section of the upgrade-pack remains the same as what it would be in the stack's upgrade-pack.
A stack is a versioned collection of services. Each stack is a folder is defined in ambari-server/src/main/resources/stacks source. Once installed, these stack definitions are available on the ambari-server machine at /var/lib/ambari-server/resources/stacks.
Each stack folder contains one sub-folder per version of the stack. Some of these stack-versions are active while some are not. Each stack-version includes services which are either referenced from common-services, or defined inside the stack-version's services folder.
- versions/active - Whether this stack-version is still available for install. If not available, this version will not show up in UI during install.
- extends - The stack-version in this stack that is being extended. Extended stack-versions inherit services along with almost all aspects of the parent stack-version.
- minJdk - Minimum JDK with which this stack-version is supported. Users are warned during installer wizard if the JDK used by Ambari is lower than this version.
- maxJdk - Maximum JDK with which this stack-version is supported. Users are warned during installer wizard if the JDK used by Ambari is greater than this version.
The stack_features.json contains a list of features that are included in Ambari and allows the stack to specify which versions of the stack include those features. The list of features are determined by the particular Ambari release. The reference list for a particular Ambari version should be found in the HDP/2.0.6/properties/stack_features.json in the branch for that Ambari release. Each feature has a name and description and the stack can provide the minimum and maximum version where that feature is supported.
"description": "Snappy compressor/decompressor support",
The stack_tools.json includes the name and location where the stack_selector and conf_selector tools are installed.
"stack_selector": ["hdp-select", "/usr/bin/hdp-select", "hdp-select"],
"conf_selector": ["conf-select", "/usr/bin/conf-select", "conf-select"]
Any custom stack must include these two JSON files. For further information see the Stack Properties wiki page.
Each stack-version includes services which are either referenced from common-services, or defined inside the stack-version's services folder.
Services are defined in common-services if they will be shared across multiple stacks. If they will never be shared, then they can be defined inside the stack-version.
To reference a service from common-services, the service descriptor file should use the <extends> element. (Example: HDFS in HDP-2.0.6)
In exactly the same format as services defined in common-services, a new service can be defined inside the services folder.
When a stack-version extends another stack-version, it inherits all details of the parent service. It is also free to override and remove any portion of the inherited service definition.
- HDP-2.3 / HDFS - Adding NFS_GATEWAY component, updating service version and OS specific packages
- HDP-2.2 / Storm - Deleting STORM_REST_API component, updating service version and OS specific packages
- HDP-2.3 / YARN - Deleting YARN node-label configuration from capacity-scheduler.xml
- HDP-2.3 / Kafka - Add Kafka Broker Process alert
Role Command Order
Role is another name for Component (Ex: NAMENODE, DATANODE, RESOURCEMANAGER, HBASE_MASTER, etc.)
As the name implies, it is possible to tell Ambari about the order in which commands should be run for the components defined in your stack.
For example: "ZooKeeper Server should be started before starting NameNode". Or "HBase Master should be started only after NameNode and DataNodes are started".
This can be specified by including the role_command_order.json file in the stack-version folder.
Specified in JSON format, the file contains a JSON object with top-level keys being either section names or comments Ex: HDP-2.0.6.
Inside each section object, the key describes the dependent component-action, and the value lists the component-actions which should be done before it.
Ambari uses the below sections only:
|Section Name||When Used|
|Command orders are applied in all situations|
|Command orders are applied when cluster has instance of GLUSTERFS service|
|Command orders are applied when cluster does not have instance of GLUSTERFS service|
|Command orders are applied when HDFS service is installed and JOURNALNODE component exists (HDFS HA is enabled)|
|Command orders are applied when YARN service is installed and multiple RESOURCEMANAGER host-components exist (YARN HA is enabled)|
Commands currently supported by Ambari are
|Role Command Order||Explanation|
|"HIVE_METASTORE-START": ["MYSQL_SERVER-START", "NAMENODE-START"]||Start MySQL and NameNode components before starting Hive Metastore|
|"MAPREDUCE_SERVICE_CHECK-SERVICE_CHECK": ["NODEMANAGER-START", "RESOURCEMANAGER-START"],||MapReduce service check needs ResourceManager and NodeManagers started|
|"ZOOKEEPER_SERVER-STOP" : ["HBASE_MASTER-STOP", "HBASE_REGIONSERVER-STOP", "METRICS_COLLECTOR-STOP"],||Before stopping ZooKeeper servers, make sure HBase Masters, HBase RegionServers and AMS Metrics Collector are stopped.|
Each stack-version can provide the location of package repositories to use, by providing a repos/repoinfo.xml (Ex: HDP-2.0.6)
The repoinfo.xml file contains repositories grouped by operating systems. Each OS specifies a list of repositories that are shown to the user when the stack-version is selected for install.
These repositories are used in conjunction with the packages defined in a service's metainfo.xml to install appropriate bits on the system.
baseurl- URL of the RPM repository where provided repoid can be found
repoid - Repo ID to use that are hosted at baseurl
reponame - Display name for the repo being used.
Though repository base URL is capable of providing updates to a particular repo, it has to be defined at build time. This could be an issue later when the repository changes location, or update builds are hosted at a different site.
For such scenarios, a stack-version can provide the location of a JSON file which can provide details of other repo URLs to use.
Example: HDP-2.3 repoinfo.xml uses <latest> file, which then points to alternate repository URLs where latest builds can be found:
A stack-version could have very basic and common instructions that need to be run before or after certain Ambari commands, across all services.
Instead of duplicating this code across all service scripts and asking users to worry about them, Ambari provides the Hooks ability where common before and after code can be pulled away into the hooks folder. (Ex: HDP-2.0.6)
The general naming pattern for hooks sub-folders is "<before|after>-<ANY|<CommandName>>".
What this means is that the scripts/hook.py file under the sub-folder is run either before or after the command.
|before-START||Hook script called before START command is run on any component of the stack-version.|
|before-INSTALL||Hook script called before installing of any component of the stack-version|
Based on the commands currently supported by Ambari, the following sub-folders can be created based on necessity
|<custom_command>||Custom commands specified by the user like the DECOMMISSION or REBALANCEHDFS commands specified by HDFS|
The scripts/hook.py script should import resource_management.libraries.script.hook module and extend the Hook class
Though most configurations are set at the service level, there can be configurations which apply across all services to indicate the state of the cluster installed with this stack.
For example, things like "is security enabled?", "what user runs smoke tests?" etc.
Such configurations can be defined in the configuration folder of the stack. They are available for access just like the service-level configs.
With each stack containing multiple complex services, it becomes necessary to dynamically determine how the services are laid out on the cluster, and for determining values of certain configurations.
Ambari provides the Stack Advisor capability where stacks can write a Python script named stack-advisor.py in the services/ folder. Example: HDP-2.0.6.
Stack-advisor scripts automatically extend the parent stack-version's stack-advisor scripts. This allows newer stack-versions to change behavior without effecting earlier behavior.
Stack advisors provide information on 4 important aspects:
- Recommend layout of services on cluster
- Recommend service configurations
- Validate layout of services on cluster
- Validate service configurations
By providing the stack-advisor.py file, one can control dynamically each of the above.
The main interface for the stack-advisor scripts contains documentation on how each of the above are called, and what data is provided
- Stack Advisor interface
- Default Stack Advisor implementation - for all stacks
- HDP (2.0.6) Default Stack Advisor implementation
- YARN container size calculated
- Recommended configurations - HDFS, YARN, MapReduce2, HBase (HDP-2.0.6), HBase (HDP-2.3)
- Delete HBase Bucket Cache configs on smaller machines
- Specify maximum value for Tez config
Similar to stack configurations, most properties are defined at the service level, however there are global properties which can be defined at the stack-version level affecting across all services.
Some examples are: stack-selector and conf-selector specific names or what stack versions certain stack features are supported by. Most of these properties were introduced in Ambari 2.4 version in the effort of parameterize stack information and facilitate the reuse of common-services code by other distributions.
Such properties can be defined in .json format in the properties folder of the stack.
More details about stack properties can be found on Stack Properties section.
At the stack-version level one can contribute heatmap entries to the main dashboard of the cluster.
Generally these heatmaps would be ones which apply to all services - like host level heatmaps.
Example: HDP-2.0.6 contributes host level heatmaps
We have seen previously the Kerberos descriptor at the service level.
One can be defined at the stack-version level also to describe identities across all services.
Read more about the Kerberos support and the Kerberos Descriptor in the Automated Kerberization page.
Ambari provides the ability to upgrade your cluster from a lower stack-version to a higher stack-version.
Each stack-version can define upgrade-packs, which are XML files describing the upgrade process. These upgrade-pack XML files are placed in the stack-version's upgrades/ folder.
Example: HDP-2.3, HDP-2.4
Each stack-version should have an upgrade-pack for the next stack-version a cluster can upgrade to.
Ex: Upgrade-pack from HDP-2.3 to HDP-2.4
There are two types of upgrades:
|Rolling Upgrade (RU)|
Minimal cluster downtime - services available throughout upgrade process
|Takes time (sometimes days depending on cluster size) due to incremental upgrade approach|
|Express Upgrade (EU)||Cluster unavailable - services are stopped during upgrade process||Much faster - clusters can be upgraded in a couple of hours|
Each component which has to be upgraded by Ambari should specify the versionAdvertised flag in the metainfo.xml.
This will tell Ambari to use the component's version and perform upgrade. Not specifying this flag will result in Ambari not upgrading the component.
Example: HDFS NameNode (versionAdvertised=true), AMS Metrics Collector (versionAdvertised=false).
In Rolling Upgrade each service is upgraded with minimal downtime in mind. The general approach is to quickly upgrade the master components, followed by upgrading of workers in batches.
The service will not be available when masters are restarting. However when master components are in High Availability (HA), the service continues to be available through restart of each master.
In Express Upgrade the goal is to upgrade entire cluster as fast as possible - even if it means cluster downtime. It is generally much faster than Rolling Upgrade.
For each service the components are first stopped, upgraded and then started.
You can read about Express Upgrade steps in this documentation.