Skip to end of metadata
Go to start of metadata

Background

The Stack definitions can be found in the source tree at /ambari-server/src/main/resources/stacks. After you install the Ambari Server, the Stack definitions can be found at /var/lib/ambari-server/resources/stacks

Structure

The structure of a Stack definition is as follows:

Defining a Service and Components

The 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 can be either a MASTER, SLAVE or CLIENT category. The <category> tells Ambari what default commands should be available to manage and monitor the component.

For each Component you specify the <commandScript> to use when executing commands. There is a defined set of default commands the component must support.

Component CategoryDefault Lifecycle Commands
MASTERinstall, start, stop, configure, status
SLAVEinstall, start, stop, configure, status
CLIENTinstall, 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 metainfo.xml:

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:

Using Stack Inheritance

Stacks can extend other Stacks in order to share command scripts and configurations. This reduces duplication of code across Stacks with the following:

  • define repositories for the child Stack
  • add new Services in the child Stack (not in the parent Stack)
  • override command scripts of the parent Services
  • override configurations of the parent Services

For example, the HDP 2.1 Stack extends HDP 2.0.6 Stack so only the changes applicable to HDP 2.1 Stack are present in that Stack definition. This extension is defined in the metainfo.xml for HDP 2.1 Stack:

Example: Implementing a Custom Service

In this example, we will create a custom service called "SAMPLESRV", add it to an existing Stack definition. This service includes MASTER, SLAVE and CLIENT components.

Create and Add the Service
  1. On the Ambari Server, browse to the /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services directory. In this case, we will browse to the HDP 2.0 Stack definition.

  2. Create a directory named /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV that will contain the service definition for SAMPLESRV.

  3. Browse to the newly created SAMPLESRV directory, create a metainfo.xml file that describes the new service.  For example:

  4. In the above, my service name is "SAMPLESRV", and it contains:
    • one MASTER component "SAMPLESRV_MASTER"
    • one SLAVE component "SAMPLESRV_SLAVE"
    • one CLIENT component "SAMPLESRV_CLIENT"
  5. Next, let's create that command script. Create a directory for the command script /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/SAMPLESRV/package/scripts that we designated in the service metainfo.

  6. Browse to the scripts directory and create the .py command script files.

    For example master.py file:

    For example slave.py file:

    For example sample_client.py file:

  7. Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.

Install the Service (via Ambari Web "Add Services")

The ability to add custom services via Ambari Web is new as of Ambari 1.7.0.

  1. In Ambari Web, browse to Services and click the Actions button in the Service navigation area on the left.
  2. The "Add Services" wizard launches. You will see an option to include "My Sample Service" (which is the <displayName> of the service as defined in the service metainfo.xml file).
  3. Select "My Sample Service" and click Next.
  4. Assign the "Sample Srv Master" and click Next.
  5. Select the hosts to install the "Sample Srv Client" and click Next.
  6. Once complete, the "My Sample Service" will be available Service navigation area.
  7. If you want to add the "Sample Srv Client" to any hosts, you can browse to Hosts and navigate to a specific host and click "+ Add".

Example: Implementing a Custom Client-only Service

In this example, we will create a custom service called "TESTSRV", add it to an existing Stack definition and use the Ambari APIs to install/configure the service. This service is a CLIENT so it has two commands: install and configure.

Create and Add the Service
  1. On the Ambari Server, browse to the /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services directory. In this case, we will browse to the HDP 2.0 Stack definition.

  2. Create a directory named /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV that will contain the service definition for TESTSRV.

  3. Browse to the newly created TESTSRV directory, create a metainfo.xml file that describes the new service. For example:

  4. In the above, my service name is "TESTSRV", and it contains one component "TEST_CLIENT" that is of component category "CLIENT". That client is managed via the command script scripts/test_client.py. Next, let's create that command script.
  5. Create a directory for the command script /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV/package/scripts that we designated in the service metainfo.

  6. Browse to the scripts directory and create the test_client.py file. For example:

  7. Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.

Install the Service (via the Ambari REST API)
  1. Add the Service to the Cluster.

  2. Add the Components to the Service. In this case, add TEST_CLIENT to TESTSRV.

  3. Install the component on all target hosts. For example, to install on c6402.ambari.apache.org and c6403.ambari.apache.org, first create the host_component resource on the hosts using POST.

  4. Now have Ambari install the components on all hosts. In this single command, you are instructing Ambari to install all components related to the service. This call the install() method in the command script on each host.

  5. Alternatively, instead of installing all components at the same time, you can explicitly install each host component. In this example, we will explicitly install the TEST_CLIENT on c6402.ambari.apache.org:

  6. Use the following to configure the client on the host. This will end up calling the configure() method in the command script.

  7. If you want to see which hosts the component is installed.

Install the Service (via Ambari Web "Add Services")

The ability to add custom services via Ambari Web is new as of Ambari 1.7.0.

  1. In Ambari Web, browse to Services and click the Actions button in the Service navigation area on the left.
  2. The "Add Services" wizard launches. You will see an option to include "My Test Service" (which is the <displayName> of the service as defined in the service metainfo.xml file).
  3. Select "My Test Service" and click Next.
  4. Select the hosts to install the "New Test Client" and click Next.
  5. Once complete, the "My Test Service" will be available Service navigation area.
  6. If you want to add the "New Test Client" to any hosts, you can browse to Hosts and navigate to a specific host and click "+ Add".

Example: Implementing a Custom Client-only Service (with Configs)

In this example, we will create a custom service called "TESTCONFIGSRV" and add it to an existing Stack definition. This service is a CLIENT so it has two commands: install and configure. And the service also includes a configuration type "test-config".

Create and Add the Service to the Stack
  1. On the Ambari Server, browse to the /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services directory. In this case, we will browse to the HDP 2.0 Stack definition.

  2. Create a directory named /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV that will contain the service definition for TESTCONFIGSRV.

  3. Browse to the newly created TESTCONFIGSRV directory, create a metainfo.xml file that describes the new service. For example:

  4. In the above, my service name is "TESTCONFIGSRV", and it contains one component "TESTCONFIG_CLIENT" that is of component category "CLIENT". That client is managed via the command script scripts/test_client.py. Next, let's create that command script.
  5. Create a directory for the command script /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV/package/scripts that we designated in the service metainfo <commandScript>.

  6. Browse to the scripts directory and create the test_client.py file. For example:

  7. Now let's define a config type for this service. Create a directory for the configuration dictionary file /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTCONFIGSRV/configuration.

  8. Browse to the configuration directory and create the test-config.xml file. For example:

  9. Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.

 

 

  • No labels