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

Compare with Current View Page History

« Previous Version 25 Next »

As of Ambari 1.5.0, the "Add Service" capability is available in the Ambari Web UI (Services > Actions menu in the Services area). Below describes the method to add a Service to Ambari via the REST API.

Steps to add a new service to an existing cluster (the service is already part of the stack)

The stack definition can be found under server resources. On an installed and running Ambari server the location would be /var/lib/ambari-server/resources/stacks.

NOTE: Make sure to append, -H "X-Requested-By:ambari" as a part of your curl calls for Ambari versions 1.4.1 and up.

Step 1 - Add a Service to the cluster

API Call

curl -u <username>:<password> -i -X POST -d '{"ServiceInfo":{"service_name":"<service-name>"}}' http://<ambari-server-host>:8080/api/v1/clusters/<cluster-name>/services 

 

Step 2 - Add Components to the service

Service components are defined in the metainfo.xml file found in the service definition under HDP stack. E.g.: ambari-server/resources/stacks/HDP/0.1/services/HBASE/metainfo.xml

Service Component types:

Type

Number of Instances

Example

MASTER

1 or many

HBASE (multi-master)

SLAVE

many

TASKTRACKER

CLIENT

many

HDFS CLIENT

API Call

curl -u <username>:<password> -i -X POST http://<ambari-server-host>:8080/api/v1/clusters/<cluster-name>/services/<service-name>/components/<component-name>
Example:
curl -u <username>:<password> -i -X POST http://<ambari-server-host>:8080/api/v1/clusters/c1/services/MAPREDUCE/components/JOBTRACKER

 

Step 3 - Create configuration

Configurations in Ambari are distinguished using type and tag properties. Once a configuration is created it can be applied to a service, specifying the type and tag for the configuration.
The tag can be treated as a version number with a versioning scheme like, "version" + unix timestamp, indicating that the latest tag is also the latest configuration.

API Call

curl -u <username>:<password> -i -X POST -d '{"type": "<config-type>", "tag": "<config-tag>", "properties" : { "key1" : "value1", "key2" : "value2", "key3" : "value3"  }}' http://<ambari-server-host>:8080/api/v1/clusters/<cluster-name>/configurations
Example:
curl -i -X POST -d '{"type": "core-site", "tag": "version1363902625", "properties" : { "fs.default.name" : "localhost:8020"}}' http://<cluster-name>:8080/api/v1/clusters/c1/configurations

Note:
This is not an incremental add to properties and every configuration once created is immutable.
New lines and spaces are tolerated. This is specially important when copying existing configuration that is pretty printed JSON string.

 

Step 4 - Apply configuration to the cluster

The configurations as of Ambari 1.3.0 are attached to the cluster and overridable at service, service component and host component levels.

API call

curl -u <username>:<password> -i -X PUT -d '{"Clusters": {"desired_configs": { "type": "<config-type>", "tag" :"<config-tag>" }}}' http://<ambari-server-host>:8080/api/v1/clusters/<cluster-name> |
Example:
curl -u admin:admin -i -X PUT -d '{ "Clusters" : {"desired_configs": {"type": "test-site", "tag" : "version1" }}}'  http://<cluster-name>:8080/api/v1/clusters/c1

 

Step 5 - Create host components

This essentially means creating the host to service component mapping or assigning Roles to hosts in your cluster.

API Call

curl -u <username>:<password> -i -X POST -d '{"host_components" : [{"HostRoles":{"component_name":"<component-name>"}}] }' http://<ambari-server-host>:8080/api/v1/clusters/<cluster-name>/hosts?Hosts/host_name=<host-names>

Note: This is the same hostname used during registration of the host. Multiple hosts can be assigned the same Role using this API

 

Step 6 - Install & Start the service

Make sure the service components are created and the configurations attached by making a GET call.

http://<ambari-server-host>:8080/api/v1/clusters/<cluster-name>/services/<service-name>

Install the service.

API Call

curl -u <username>:<password> -i -X PUT -d '{"ServiceInfo": {"state" : "INSTALLED"}}'  http://<ambari-server-host>:8080/api/v1/clusters/<cluster-name>/services/<service-name>

Start the service.

API Call

curl -u <username>:<password> -i -X PUT -d '{"ServiceInfo": {"state" : "STARTED"}}'  http://<ambari-server-host>:8080/api/v1/clusters/<cluster-name>/services/<service-name>
  • No labels