You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

*** DRAFT - Being Edited ***

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 to define your own services or stacks.
There is also an example you can follow to create your custom stack and service.

A stack is a distribution of a set 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 from multiple stack-versions. Likewise, if a service is going to be contained in only one stack and never going to be shared, it can be defined in the stacks folder. Basically services defined in stacks folder are by used containment, whereas the ones defined in common-services are used by reference. 

Define Service

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 should 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.

metainfo.xml

In the metainfo.xml file, one can first define the service and its components.

Complete reference can be found in the Writing metainfo.xml page.
A good reference implementation is the HDFS metainfo.xml.

 

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.

YARN and MapReduce2 are services that are defined together in the YARN folder.  Its metainfo.xml defines both services.

Scripts

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)
 

These scripts should be provided in the <service-id>/<service-version>/package/scripts folder.

FolderPurpose
package/scriptsContains scripts invoked by Ambari. These scripts are loaded into the execution path with the correct environment.
Example: HDFS
package/filesContains 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
package/templates

Template files used by above scripts to generate files on managed hosts. These are generally configuration files required by the service to operate.
Example: exclude_hosts_list.j2 which is used by scripts to generate /etc/hadoop/conf/dfs.exclude

Python

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.

master.py
import sys
from resource_management import *
class Master(Script):
  def install(self, env):
    print 'Install the Sample Srv Master';
  def stop(self, env):
    print 'Stop the Sample Srv Master';
  def start(self, env):
    print 'Start the Sample Srv Master';
  def status(self, env):
    print 'Status of the Sample Srv Master';
  def configure(self, env):
    print 'Configure the Sample Srv Master';
if __name__ == "__main__":
  Master().execute()
slave.py
import sys
from resource_management import *
class Slave(Script):
  def install(self, env):
    print 'Install the Sample Srv Slave';
  def stop(self, env):
    print 'Stop the Sample Srv Slave';
  def start(self, env):
    print 'Start the Sample Srv Slave';
  def status(self, env):
    print 'Status of the Sample Srv Slave';
  def configure(self, env):
    print 'Configure the Sample Srv Slave';
if __name__ == "__main__":
  Slave().execute()
client.py
import sys
from resource_management import *
class SampleClient(Script):
  def install(self, env):
    print 'Install the Sample Srv Client';
  def configure(self, env):
    print 'Configure the Sample Srv Client';
if __name__ == "__main__":
  SampleClient().execute()

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. TODO

  • resource_management
  • ambari_commons
  • ambari_simplejson 

Examples

NameNode Start, Stop.

DataNode Start and Stop.

HDFS configurations persistence

Configuration

Files

Alerts

Kerberos

Metrics

Widgets

Define Stack

Services

Command Order

Repositories

Hooks

Configurations

Stack Advisor

Themes

Widgets

  • No labels