@GET
  @Path("/apps/{appid}/appattempts/{appattemptid}/containers")
  @Produces(MediaType.APPLICATION_JSON)
  public Set<TimelineEntity> getContainers(@Context HttpServletRequest req,
      @Context HttpServletResponse res, @PathParam("appid") String appId,
      @PathParam("appattemptid") String appattemptId,
      @QueryParam("userid") String userId,
      @QueryParam("flowname") String flowName,
      @QueryParam("flowrunid") String flowRunId,
      @QueryParam("limit") String limit,
      @QueryParam("createdtimestart") String createdTimeStart,
      @QueryParam("createdtimeend") String createdTimeEnd,
      @QueryParam("relatesto") String relatesTo,
      @QueryParam("isrelatedto") String isRelatedTo,
      @QueryParam("infofilters") String infofilters,
      @QueryParam("conffilters") String conffilters,
      @QueryParam("metricfilters") String metricfilters,
      @QueryParam("eventfilters") String eventfilters,
      @QueryParam("confstoretrieve") String confsToRetrieve,
      @QueryParam("metricstoretrieve") String metricsToRetrieve,
      @QueryParam("fields") String fields,
      @QueryParam("metricslimit") String metricsLimit,
      @QueryParam("metricstimestart") String metricsTimeStart,
      @QueryParam("metricstimeend") String metricsTimeEnd,
      @QueryParam("fromid") String fromId) {
    return getContainers(req, res, null, appId, appattemptId, userId, flowName,
        flowRunId, limit, createdTimeStart, createdTimeEnd, relatesTo,
        isRelatedTo, infofilters, conffilters, metricfilters, eventfilters,
        confsToRetrieve, metricsToRetrieve, fields, metricsLimit,
        metricsTimeStart, metricsTimeEnd, fromId);
  }
@Test
  void testGetContainers() throws Exception {
    Client client = createClient();
    try {
      // total 3 containers in a application.
      URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/"
          + "timeline/clusters/cluster1/apps/app1/entities/YARN_CONTAINER");
      ClientResponse resp = getResponse(client, uri);
      Set<TimelineEntity> entities =
          resp.getEntity(new GenericType<Set<TimelineEntity>>() {
          });
      assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
          resp.getType().toString());
      assertNotNull(entities);
      int totalEntities = entities.size();
      assertEquals(3, totalEntities);
      assertTrue(
          entities.contains(newEntity(
              TimelineEntityType.YARN_CONTAINER.toString(), "container_1_1")),
          "Entity with container_1_1 should have been present in response.");
      assertTrue(
          entities.contains(newEntity(
              TimelineEntityType.YARN_CONTAINER.toString(), "container_2_1")),
          "Entity with container_2_1 should have been present in response.");
      assertTrue(
          entities.contains(newEntity(
              TimelineEntityType.YARN_CONTAINER.toString(), "container_2_2")),
          "Entity with container_2_2 should have been present in response.");

      // for app-attempt1 1 container has run
      uri = URI.create("http://localhost:" + serverPort + "/ws/v2/"
          + "timeline/clusters/cluster1/apps/app1/"
          + "appattempts/app-attempt-1/containers");
      resp = getResponse(client, uri);
      entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
      });
      assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType());
      assertNotNull(entities);
      int retrievedEntity = entities.size();
      assertEquals(1, retrievedEntity);
      assertTrue(
          entities.contains(newEntity(
              TimelineEntityType.YARN_CONTAINER.toString(), "container_1_1")),
          "Entity with container_1_1 should have been present in response.");

      // for app-attempt2 2 containers has run
      uri = URI.create("http://localhost:" + serverPort + "/ws/v2/"
          + "timeline/clusters/cluster1/apps/app1/"
          + "appattempts/app-attempt-2/containers");
      resp = getResponse(client, uri);
      entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
      });
      assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType());
      assertNotNull(entities);
      retrievedEntity += entities.size();
      assertEquals(2, entities.size());
      assertTrue(
          entities.contains(newEntity(
              TimelineEntityType.YARN_CONTAINER.toString(), "container_2_1")),
          "Entity with container_2_1 should have been present in response.");
      assertTrue(
          entities.contains(newEntity(
              TimelineEntityType.YARN_CONTAINER.toString(), "container_2_2")),
          "Entity with container_2_2 should have been present in response.");

      assertEquals(totalEntities, retrievedEntity);

    } finally {
      client.destroy();
    }
  }