The YARN service registry can be used in a numbe of ways :-
A user of the registry may be both a publisher of entries —Service Records— and a consumer of other services located via their service records. Different parts of a distributed application may also use it for different purposes -central manager services can publish bindings for use by the worker services, which can then look up the bindings to communicate with that manager even if it was restarted on different nodes in the cluster.
The registry cannot be used:-
This record MAY have application attempt persistence policy of and an ID of the application attempt
yarn:persistence = "application_attempt"
yarn:id = ${application_attemptId}
This means that the record will be deleted when the application attempt completes, even if a new attempt is created. Every Application attempt will have to re-register the endpoint —which may be needed to locate the service anyway.
Alternatively, the record MAY have the persistence policy of "application":
yarn:persistence = "application_attempt"
yarn:id = application_attemptId
This means that the record will persist even between application attempts, albeit with out of date endpoint information.
Client applications look up the service by way of the path.
The choice of path is an application specific one. For services with a yarn application name guaranteed to be unique, we recommend a convention of:
/users/${username}/applications/${service-class}/${instance-name}
Alternatively, the application Id can be used in the path:
/users/${username}/applications/${service-class}/${applicationId}
The latter makes mapping a YARN application listing entry to a service record trivial.
Client applications may locate the service
After locating a service record, the client may enumerate the external
bindings and locate the entry with the desired API.
Here all containers in a YARN application are publishing service endpoints for public consumption.
id:password
pair which gives them the right to update these entries without the kerberos credentials of the user. This allows the containers to update their entries even after the user tokens granting the AM write access to a registry path expire.They then a register service record on a path consisting of:
${base-path} + "/" + RegistryPathUtils.encodeYarnID(containerId)
This record should have the container persistence policy an ID of the container
yarn:persistence = "container"
yarn:id = containerId
When the container is terminated, the entry will be automatically deleted.
The exported service endpoints of this container-deployed service should be listed in the external
endpoint list of the service record.
Clients may enumerate all containers exported by a YARN application by listing the entries under ${base-path}
.
Services which are generally fixed in a cluster, but which need to publish binding and configuration information may be published in the registry. Example: an Apache Oozie service. Services external to the cluster to which deployed applications may also be published. Example: An Amazon Dynamo instance.
These services can be registered under paths which belong to the users running the service, such as /users/oozie
or /users/hbase
. Client applications would use this path. While this can authenticate the validity of the service record, it does rely on the client applications knowing the username a service is deployed on, or being configured with the full path.
The alternative is for the services to be deployed under a static services path, under /services
. For example, /services/oozie
could contain the registration of the Oozie service. As the permissions for this path are restricted to pre-configured system accounts, the presence of a service registration does, on a secure cluster, confirm that it was registered by the cluster administration tools.
/services
and it has been deployed by one of the system user accounts —it may register itself directly.Here YARN containers register with their AM to receive work, usually by some heartbeat mechanism where they report in regularly. If the AM is configured for containers to outlive the application attempt, when an AM fails the containers keep running. These containers will need to bind to any restarted AM. They may also wish to conclude that if an AM does not restart, that they should eventually time out and terminate themselves. Such a policy helps the application react to network partitions.
internal
endpoint list, with the specific API the containers useManagement ports and bindings are simply another endpoint to publish. These should be published as internal endpoints, as they are not intended for public consumption. By convention, the name of the management protocol shoudl be used as the endpoint's declared API: JMX
, ganglia
, etc.
A client application wishes to locate all services implementing a specific API, such as "org.apache.hbase"
registryOperations.list(path)
to list all nodes directly under that path, getting a relative list of child nodes.stat()
on each child.ServiceRecordHeader.getLength()
, it MAY contain a service record.resolve()
operation. If successful, it does contain a service record —so the client can enumerate the external
endpoints and locate the one with the desired API.children
field of each RegistryPathStatus
status entry should be examined. If it is >= 0, the enumeration should be performed recursively on the path of that entry.This algorithm describes a depth first search of the registry tree. Variations are of course possible, including breadth first search, or immediately halting the search as soon as a single entry point. There is also the option of parallel searches of different subtrees —which may reduce search time, albeit at the price of a higher client load on the registry infrastructure.
A Utility class RegistryUtils
provides static utility methods for common registry operations,
in particular, RegistryUtils.listServiceRecords(registryOperations, path)
performs the listing and collection of all immediate child record entries of
a specified path.