Managing Data Operating System
Also available as:
PDF
loading table of contents...

Deploying and Managing Services and Microservices on YARN

Using the YARN Services API, you can run simple and complex template-based apps on containers such as docker containers.

Without having the need to write new code or modify your apps, you can create and manage the life cycle of these YARN services.


{
  "name": "sleeper-service",
  "version": "1.0.0",
  "components" : [
    {
      "name": "sleeper",
      "number_of_containers": 2,
      "launch_command": "sleep 900000",
      "resource": {
      "cpus": 1,
      "memory": "256"
     }
    }
   ]
  }
      
    

Each service file contains, at a minimum, a name, version, and list of components. Each component of a service has a name, a number of containers to be launched (also referred to as component instances), a launch command, and an amount of resources to be requested for each container.

Components optionally also include an artifact specification. The artifact can be the default type (with no artifact specified, like the sleeper-service example above) or can have other artifact types such as DOCKER, TARBALL, or SERVICE.

An example YARN service file that specifies Docker containers running the centos/httpd-24-centos7:latest Docker image appears as follows:


{
  "name": "simple-httpd-service",
  "version": "1.0.0",
  "lifetime": "3600",
  "components": [
    {
      "name": "httpd",
      "number_of_containers": 2,
      "launch_command": "/usr/bin/run-httpd",
      "artifact": {
        "id": "centos/httpd-24-centos7:latest",
        "type": "DOCKER"
      },
      "resource": {
        "cpus": 1,
        "memory": "1024"
      },
      "configuration": {
        "files": [
          {
            "type": "TEMPLATE",
            "dest_file": "/var/www/html/index.html",
            "properties": {
              "content": "<html><header><title>Title</title></header><body>Hello from ${COMPONENT_INSTANCE_NAME}!</body></html>"
            }
          }
        ]
      }
    }
  ]
}

In addition to illustrating the DOCKER artifact type, this service file introduces two additional features, a lifetime that indicates the number of seconds after which a service will be stopped and a configuration section. The example shows one type of configuration file that can be created for the service (other supported file types include STATIC, ARCHIVE, HADOOP_XML, PROPERTIES, JSON, and YAML). The configuration specification also may include an env section for specifying environment variables for the container and a properties section that is typically used to pass configuration properties to the YARN service Application Master (AM).