Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

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:

...

Code Block
<metainfo>
  <versions>
    <active>true</active>
  </versions>
  <extends>2.0.6</extends>
</metainfo>

Example: Implementing a Simple Test Service

In this example, we will create a new service called "TESTSRV", add it to an existing Stack definition and use the Ambari APIs to install/configure/restart the service.

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.
  2. Create a directory named /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV
  3. In that directory, create a metainfo.xml file that describes the new service. For example:

    Code Block
    <?xml version="1.0"?>
    <metainfo>
        <schemaVersion>2.0</schemaVersion>
        <services>
            <service>
                <name>TESTSRV</name>
                <comment>A New Test Service</comment>
                <version>0.1.0</version>
                <components>
                    <component>
                        <name>TEST_CLIENT</name>
                        <category>CLIENT</category>
                        <commandScript>
                            <script>scripts/test_client.py</script>
                            <scriptType>PYTHON</scriptType>
                            <timeout>600</timeout>
                        </commandScript>
                    </component>
                </components>
                <osSpecifics>
                    <osSpecific>
                        <osFamily>any</osFamily>
                    </osSpecific>
                </osSpecifics>
            </service>
        </services>
    </metainfo>
  4. In the above, my service name is "TESTSRV", and it contains one component "TEST_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 script /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV/package/scripts.
  6. Browse to the scripts directory and create the test_client.py file. For example:

    Code Block
    import sys
    from resource_management import *
    
    class TestClient(Script):
      def install(self, env):
        print 'Install the client';
      def configure(self, env):
        print 'Configure the client';
    
    if __name__ == "__main__":
      TestClient().execute()
  7. Now, restart Ambari Server for this new service definition to be distributed to all the Agents in the cluster.
Install the Service into the Cluster
  1. Add the Service to the Cluster.

    Code Block
    POST
    /api/v1/clusters/MyCluster/services
    {
    "ServiceInfo": {
      "service_name":"TESTSRV"
      }
    }
  2. Install the component on a host. For example, on the c6403.ambari.apache.org host.

    Code Block
    POST
    /api/v1/clusters/MyCluster/hosts/c6403.ambari.apache.org/host_components/TEST_CLIENT
    
    {
      "RequestInfo":{
        "context":"Install Test Srv"},
         "Body":{
          "HostRoles":{
            "state":"INSTALLED"
          }
       }
    }
  3. Use the following to configure the client on the host. This will end up calling the configure() method in the command script.

    Code Block
    POST
    /api/v1/clusters/MyCluster/requests
     
    {
      "RequestInfo" : {
        "command" : "CONFIGURE",
        "context" : "Config Test Srv Client"
      },
      "Requests/resource_filters": [{
        "service_name" : "TESTSRV",
         "component_name" : "TEST_CLIENT",
        "hosts" : "c6403.ambari.apache.org"
      }]
    }
  4. If you want to see which hosts the component is installed.

    Code Block
    GET
    /api/v1/clusters/MyCluster/components/TEST_CLIENT