Versions Compared

Key

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

...

  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.

    Code Block
    cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services
  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.

    Code Block
    mkdir /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV
    cd /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV
  3. Browse to the newly created TESTSRV 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>
                <displayName>New Test Service</displayName>
                <comment>A New Test Service</comment>
                <version>0.1.0</version>
                <components>
                    <component>
                        <name>TEST_CLIENT</name>
                        <displayName>New Test Client</displayName>
                        <category>CLIENT</category>
                        <cardinality>1+</cardinality>
                        <commandScript>
                            <script>scripts/test_client.py</script>
                            <scriptType>PYTHON</scriptType>
                            <timeout>600</timeout>
                        </commandScript>
                        <customCommands>
                          <customCommand>
                            <name>SOMETHINGCUSTOM</name>
                            <commandScript>
                              <script>scripts/test_client.py</script>
                              <scriptType>PYTHON</scriptType>
                              <timeout>600</timeout>
                            </commandScript>
                          </customCommand>
                        </customCommands>
                    </component>
                </components>
                <osSpecifics>
                    <osSpecific>
                        <osFamily>any</osFamily>  <!-- note: use osType rather than osFamily for Ambari 1.5.0 and 1.5.1 -->
                    </osSpecific>
                </osSpecifics>
            </service>
        </services>
    </metainfo>
  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.

    Code Block
    mkdir -p /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/TESTSRV/package/scripts
    cd /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';
      def somethingcustom(self, env):
        print 'Something custom';
    
    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.

    Code Block
    ambari-server restart
Adding Repository details in repoinfo.xml

When adding a custom service, it may be needed to add additional repository details for the stack especially if the service binaries are available through a separate repository. Additional <repo> entries can be added and Ambari will ensure that the base URL provided is used to create repo files on the hosts where service is being installed.

<reposinfo>
<os family="redhat6">
    <repo>
<baseurl>http://cust.service.lab.com/Services/centos6/1.1/myservices</baseurl>
<repoid>CUSTOM-1.1</repoid>
<reponame>CUSTOM</reponame>
</repo>
    <repo>
<baseurl>http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.1</baseurl>
<repoid>HDP-2.0.6</repoid>
<reponame>HDP</reponame>
</repo>
<repo>
<baseurl>http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.17/repos/centos6</baseurl>
<repoid>HDP-UTILS-1.1.0.17</repoid>
<reponame>HDP-UTILS</reponame>
</repo>
</os>
</reposinfo>

 

Install the Service (via the Ambari REST API)

...