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

Publish Application-Specific Data

The TimelineV2Client API helps you publish application-specific data to Timeline Service 2.0. For your applications, you must define a TimelineEntity object and publish the events to Timeline Service 2.0.

The YARN applications that write to Timeline Service 2.0 must be running on the cluster.

  1. Create and start the timeline client.
    You must specify the Application ID to write to Timeline Service 2.0.
    Following is an example for defining a timeline client:
    // Create and start the Timeline client v.2
    TimelineV2Client timelineClient =
        TimelineV2Client.createTimelineClient(appId);
    timelineClient.init(conf);
    timelineClient.start();
    
    try {
      TimelineEntity myEntity = new TimelineEntity();
      myEntity.setType("MY_APPLICATION");
      myEntity.setId("MyApp1");
      // Compose other entity info
    
      // Blocking write
      timelineClient.putEntities(myEntity);
    
      TimelineEntity myEntity2 = new TimelineEntity();
      // Compose other info
    
      // Non-blocking write
      timelineClient.putEntitiesAsync(myEntity2);
    
    } catch (IOException | YarnException e) {
      // Handle the exception
    } finally {
      // Stop the Timeline client
      timelineClient.stop();
    }
  2. Set the timeline collector information.
    You can either use amRMClient and register the timeline client or set the information explicitly in the timeline client.
    amRMClient.registerTimelineV2Client(timelineClient);
    timelineClient.setTimelineCollectorInfo(response.getCollectorInfo());