Java Code Examples for org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse

The following examples show how to use org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ambari-metrics   Source File: TimelineWebServices.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Store the given metrics into the timeline store, and return errors that
 * happened during storing.
 */
@Path("/metrics/aggregated")
@POST
@Consumes({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */})
public TimelinePutResponse postAggregatedMetrics(
  @Context HttpServletRequest req,
  @Context HttpServletResponse res,
  AggregationResult metrics) {

  init(res);
  if (metrics == null) {
    return new TimelinePutResponse();
  }

  try {
    if (LOG.isTraceEnabled()) {
      LOG.trace("Storing aggregated metrics: " +
              TimelineUtils.dumpTimelineRecordtoJSON(metrics, true));
    }

    return timelineMetricStore.putHostAggregatedMetrics(metrics);
  } catch (Exception e) {
    LOG.error("Error saving metrics.", e);
    throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
  }
}
 
Example 2
Source Project: ambari-metrics   Source File: TimelineWebServices.java    License: Apache License 2.0 6 votes vote down vote up
@Path("/containermetrics")
@POST
@Consumes({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */})
public TimelinePutResponse postContainerMetrics(
    @Context HttpServletRequest req,
    @Context HttpServletResponse res,
    List<ContainerMetric> metrics) {
  init(res);
  if (metrics == null || metrics.isEmpty()) {
    return new TimelinePutResponse();
  }

  try {
    if (LOG.isTraceEnabled()) {
      LOG.trace("Storing container metrics: " + TimelineUtils
          .dumpTimelineRecordtoJSON(metrics, true));
    }

    return timelineMetricStore.putContainerMetrics(metrics);

  } catch (Exception e) {
    LOG.error("Error saving metrics.", e);
    throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
  }
}
 
Example 3
@Override
public TimelinePutResponse putHostAggregatedMetrics(AggregationResult aggregationResult) throws SQLException, IOException {
  Map<TimelineMetric, MetricHostAggregate> aggregateMap = new HashMap<>();
  String hostname = null;
  for (TimelineMetricWithAggregatedValues entry : aggregationResult.getResult()) {
    aggregateMap.put(entry.getTimelineMetric(), entry.getMetricAggregate());
    hostname = hostname == null ? entry.getTimelineMetric().getHostName() : hostname;
  }
  long timestamp = aggregationResult.getTimeInMilis();
  if (LOG.isDebugEnabled()) {
    LOG.debug(String.format("Adding host %s to aggregated by in-memory aggregator. Timestamp : %s", hostname, timestamp));
  }
  hBaseAccessor.saveHostAggregateRecords(aggregateMap, PhoenixTransactSQL.METRICS_AGGREGATE_MINUTE_TABLE_NAME);

  return new TimelinePutResponse();
}
 
Example 4
@Test
public void testRunPositive() throws Exception {
  HBaseTimelineMetricsService metricStore = createNiceMock(HBaseTimelineMetricsService.class);

  expect(metricStore.putMetricsSkipCache(anyObject(TimelineMetrics.class)))
    .andReturn(new TimelinePutResponse());
  
  // metric found
  expect(metricStore.getTimelineMetrics(EasyMock.<List<String>>anyObject(),
    EasyMock.<List<String>>anyObject(), anyObject(String.class),
    anyObject(String.class), anyObject(Long.class), anyObject(Long.class),
    eq(Precision.SECONDS), eq(1), eq(true), anyObject(TopNConfig.class), anyString()))
    .andReturn(null).anyTimes();

  mockStatic(ExitUtil.class);

  replay(metricStore);

  TimelineMetricStoreWatcher timelineMetricStoreWatcher =
    new TimelineMetricStoreWatcher(metricStore, TimelineMetricConfiguration.getInstance());
  timelineMetricStoreWatcher.run();
  timelineMetricStoreWatcher.run();
  timelineMetricStoreWatcher.run();
  verify(metricStore);

}
 
Example 5
Source Project: hadoop   Source File: TestTimelineClient.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPostEntitiesWithError() throws Exception {
  mockEntityClientResponse(client, ClientResponse.Status.OK, true, false);
  try {
    TimelinePutResponse response = client.putEntities(generateEntity());
    Assert.assertEquals(1, response.getErrors().size());
    Assert.assertEquals("test entity id", response.getErrors().get(0)
        .getEntityId());
    Assert.assertEquals("test entity type", response.getErrors().get(0)
        .getEntityType());
    Assert.assertEquals(TimelinePutResponse.TimelinePutError.IO_EXCEPTION,
        response.getErrors().get(0).getErrorCode());
  } catch (YarnException e) {
    Assert.fail("Exception is not expected");
  }
}
 
Example 6
Source Project: hadoop   Source File: TestTimelineClient.java    License: Apache License 2.0 6 votes vote down vote up
private static ClientResponse mockEntityClientResponse(
    TimelineClientImpl client, ClientResponse.Status status,
    boolean hasError, boolean hasRuntimeError) {
  ClientResponse response = mock(ClientResponse.class);
  if (hasRuntimeError) {
    doThrow(new ClientHandlerException(new ConnectException())).when(client)
        .doPostingObject(any(TimelineEntities.class), any(String.class));
    return response;
  }
  doReturn(response).when(client)
      .doPostingObject(any(TimelineEntities.class), any(String.class));
  when(response.getClientResponseStatus()).thenReturn(status);
  TimelinePutResponse.TimelinePutError error =
      new TimelinePutResponse.TimelinePutError();
  error.setEntityId("test entity id");
  error.setEntityType("test entity type");
  error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION);
  TimelinePutResponse putResponse = new TimelinePutResponse();
  if (hasError) {
    putResponse.addError(error);
  }
  when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse);
  return response;
}
 
Example 7
Source Project: hadoop   Source File: TimelineWebServices.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Store the given entities into the timeline store, and return the errors
 * that happen during storing.
 */
@POST
@Consumes({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */})
public TimelinePutResponse postEntities(
    @Context HttpServletRequest req,
    @Context HttpServletResponse res,
    TimelineEntities entities) {
  init(res);
  UserGroupInformation callerUGI = getUser(req);
  if (callerUGI == null) {
    String msg = "The owner of the posted timeline entities is not set";
    LOG.error(msg);
    throw new ForbiddenException(msg);
  }
  try {
    return timelineDataManager.postEntities(entities, callerUGI);
  } catch (Exception e) {
    LOG.error("Error putting entities", e);
    throw new WebApplicationException(e,
        Response.Status.INTERNAL_SERVER_ERROR);
  }
}
 
Example 8
Source Project: hadoop   Source File: TestTimelineAuthenticationFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPutTimelineEntities() throws Exception {
  KerberosTestUtils.doAs(HTTP_USER + "/localhost", new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      TimelineClient client = createTimelineClientForUGI();
      TimelineEntity entityToStore = new TimelineEntity();
      entityToStore.setEntityType(
          TestTimelineAuthenticationFilter.class.getName());
      entityToStore.setEntityId("entity1");
      entityToStore.setStartTime(0L);
      TimelinePutResponse putResponse = client.putEntities(entityToStore);
      Assert.assertEquals(0, putResponse.getErrors().size());
      TimelineEntity entityToRead =
          testTimelineServer.getTimelineStore().getEntity(
              "entity1", TestTimelineAuthenticationFilter.class.getName(), null);
      Assert.assertNotNull(entityToRead);
      return null;
    }
  });
}
 
Example 9
Source Project: hadoop   Source File: TestTimelineWebServices.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPostEntitiesWithPrimaryFilter() throws Exception {
  TimelineEntities entities = new TimelineEntities();
  TimelineEntity entity = new TimelineEntity();
  Map<String, Set<Object>> filters = new HashMap<String, Set<Object>>();
  filters.put(TimelineStore.SystemFilter.ENTITY_OWNER.toString(),
      new HashSet<Object>());
  entity.setPrimaryFilters(filters);
  entity.setEntityId("test id 6");
  entity.setEntityType("test type 6");
  entity.setStartTime(System.currentTimeMillis());
  entities.addEntity(entity);
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  TimelinePutResponse putResposne =
      response.getEntity(TimelinePutResponse.class);
  Assert.assertEquals(0, putResposne.getErrors().size());
}
 
Example 10
Source Project: big-c   Source File: TestTimelineClient.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPostEntitiesWithError() throws Exception {
  mockEntityClientResponse(client, ClientResponse.Status.OK, true, false);
  try {
    TimelinePutResponse response = client.putEntities(generateEntity());
    Assert.assertEquals(1, response.getErrors().size());
    Assert.assertEquals("test entity id", response.getErrors().get(0)
        .getEntityId());
    Assert.assertEquals("test entity type", response.getErrors().get(0)
        .getEntityType());
    Assert.assertEquals(TimelinePutResponse.TimelinePutError.IO_EXCEPTION,
        response.getErrors().get(0).getErrorCode());
  } catch (YarnException e) {
    Assert.fail("Exception is not expected");
  }
}
 
Example 11
Source Project: big-c   Source File: TestTimelineClient.java    License: Apache License 2.0 6 votes vote down vote up
private static ClientResponse mockEntityClientResponse(
    TimelineClientImpl client, ClientResponse.Status status,
    boolean hasError, boolean hasRuntimeError) {
  ClientResponse response = mock(ClientResponse.class);
  if (hasRuntimeError) {
    doThrow(new ClientHandlerException(new ConnectException())).when(client)
        .doPostingObject(any(TimelineEntities.class), any(String.class));
    return response;
  }
  doReturn(response).when(client)
      .doPostingObject(any(TimelineEntities.class), any(String.class));
  when(response.getClientResponseStatus()).thenReturn(status);
  TimelinePutResponse.TimelinePutError error =
      new TimelinePutResponse.TimelinePutError();
  error.setEntityId("test entity id");
  error.setEntityType("test entity type");
  error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION);
  TimelinePutResponse putResponse = new TimelinePutResponse();
  if (hasError) {
    putResponse.addError(error);
  }
  when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse);
  return response;
}
 
Example 12
Source Project: big-c   Source File: TimelineWebServices.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Store the given entities into the timeline store, and return the errors
 * that happen during storing.
 */
@POST
@Consumes({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */})
public TimelinePutResponse postEntities(
    @Context HttpServletRequest req,
    @Context HttpServletResponse res,
    TimelineEntities entities) {
  init(res);
  UserGroupInformation callerUGI = getUser(req);
  if (callerUGI == null) {
    String msg = "The owner of the posted timeline entities is not set";
    LOG.error(msg);
    throw new ForbiddenException(msg);
  }
  try {
    return timelineDataManager.postEntities(entities, callerUGI);
  } catch (Exception e) {
    LOG.error("Error putting entities", e);
    throw new WebApplicationException(e,
        Response.Status.INTERNAL_SERVER_ERROR);
  }
}
 
Example 13
Source Project: big-c   Source File: TestTimelineAuthenticationFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPutTimelineEntities() throws Exception {
  KerberosTestUtils.doAs(HTTP_USER + "/localhost", new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      TimelineClient client = createTimelineClientForUGI();
      TimelineEntity entityToStore = new TimelineEntity();
      entityToStore.setEntityType(
          TestTimelineAuthenticationFilter.class.getName());
      entityToStore.setEntityId("entity1");
      entityToStore.setStartTime(0L);
      TimelinePutResponse putResponse = client.putEntities(entityToStore);
      Assert.assertEquals(0, putResponse.getErrors().size());
      TimelineEntity entityToRead =
          testTimelineServer.getTimelineStore().getEntity(
              "entity1", TestTimelineAuthenticationFilter.class.getName(), null);
      Assert.assertNotNull(entityToRead);
      return null;
    }
  });
}
 
Example 14
Source Project: big-c   Source File: TestTimelineWebServices.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPostEntitiesWithPrimaryFilter() throws Exception {
  TimelineEntities entities = new TimelineEntities();
  TimelineEntity entity = new TimelineEntity();
  Map<String, Set<Object>> filters = new HashMap<String, Set<Object>>();
  filters.put(TimelineStore.SystemFilter.ENTITY_OWNER.toString(),
      new HashSet<Object>());
  entity.setPrimaryFilters(filters);
  entity.setEntityId("test id 6");
  entity.setEntityType("test type 6");
  entity.setStartTime(System.currentTimeMillis());
  entities.addEntity(entity);
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  TimelinePutResponse putResposne =
      response.getEntity(TimelinePutResponse.class);
  Assert.assertEquals(0, putResposne.getErrors().size());
}
 
Example 15
Source Project: tez   Source File: ATSV15HistoryLoggingService.java    License: Apache License 2.0 6 votes vote down vote up
private void logEntity(TimelineEntityGroupId groupId, TimelineEntity entity, String domainId) {
  if (historyACLPolicyManager != null && domainId != null && !domainId.isEmpty()) {
    historyACLPolicyManager.updateTimelineEntityDomain(entity, domainId);
  }

  try {
    TimelinePutResponse response = timelineClient.putEntities(
        appContext.getApplicationAttemptId(), groupId, entity);
    if (response != null
        && !response.getErrors().isEmpty()) {
      int count = response.getErrors().size();
      for (int i = 0; i < count; ++i) {
        TimelinePutError err = response.getErrors().get(i);
        if (err.getErrorCode() != 0) {
          LOG.warn("Could not post history event to ATS"
              + ", atsPutError=" + err.getErrorCode()
              + ", entityId=" + err.getEntityId());
        }
      }
    }
    // Do nothing additional, ATS client library should handle throttling
    // or auto-disable as needed
  } catch (Exception e) {
    LOG.warn("Could not handle history events", e);
  }
}
 
Example 16
Source Project: ambari-metrics   Source File: TimelineWebServices.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Store the given metrics into the timeline store, and return errors that
 * happened during storing.
 */
@Path("/metrics")
@POST
@Consumes({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */})
public TimelinePutResponse postMetrics(
  @Context HttpServletRequest req,
  @Context HttpServletResponse res,
  TimelineMetrics metrics) {

  init(res);
  if (metrics == null) {
    return new TimelinePutResponse();
  }

  try {

    // TODO: Check ACLs for MetricEntity using the TimelineACLManager.
    // TODO: Save owner of the MetricEntity.

    if (LOG.isTraceEnabled()) {
      LOG.trace("Storing metrics: " +
        TimelineUtils.dumpTimelineRecordtoJSON(metrics, true));
    }

    if (CollectionUtils.isNotEmpty(metrics.getMetrics()) && metrics.getMetrics().get(0).getAppId().equals(SMOKETEST_METRIC_APP_ID)) {
      return timelineMetricStore.putMetricsSkipCache(metrics);
    } else {
      return timelineMetricStore.putMetrics(metrics);
    }

  } catch (Exception e) {
    LOG.error("Error saving metrics.", e);
    throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
  }
}
 
Example 17
@Override
public TimelinePutResponse putMetrics(TimelineMetrics metrics) throws SQLException, IOException {
  // Error indicated by the Sql exception
  TimelinePutResponse response = new TimelinePutResponse();

  hBaseAccessor.insertMetricRecordsWithMetadata(metricMetadataManager, metrics, false);

  if (configuration.isCollectorInMemoryAggregationEnabled()) {
    cache.putMetrics(metrics.getMetrics());
  }

  return response;
}
 
Example 18
@Override
public TimelinePutResponse putContainerMetrics(List<ContainerMetric> metrics)
  throws SQLException, IOException {

  if (containerMetricsDisabled) {
    LOG.debug("Ignoring submitted container metrics according to configuration. Values will not be stored.");
    return new TimelinePutResponse();
  }

  hBaseAccessor.insertContainerMetrics(metrics);
  return new TimelinePutResponse();
}
 
Example 19
@Test
public void testRunNegative() throws Exception {
  HBaseTimelineMetricsService metricStore = createNiceMock(HBaseTimelineMetricsService.class);

  expect(metricStore.putMetrics(anyObject(TimelineMetrics.class)))
    .andReturn(new TimelinePutResponse());

  // no metrics found
  expect(metricStore.getTimelineMetrics(EasyMock.<List<String>>anyObject(),
    EasyMock.<List<String>>anyObject(), anyObject(String.class),
    anyObject(String.class), anyObject(Long.class), anyObject(Long.class),
    eq(Precision.SECONDS), eq(1), eq(true), anyObject(TopNConfig.class), anyString()))
    .andReturn(null).anyTimes();

  String msg = "Error getting metrics from TimelineMetricStore. " +
    "Shutting down by TimelineMetricStoreWatcher.";
  mockStatic(ExitUtil.class);
  ExitUtil.terminate(-1, msg);
  expectLastCall().anyTimes();

  replayAll();

  TimelineMetricStoreWatcher timelineMetricStoreWatcher =
    new TimelineMetricStoreWatcher(metricStore, TimelineMetricConfiguration.getInstance());
  timelineMetricStoreWatcher.run();
  timelineMetricStoreWatcher.run();
  timelineMetricStoreWatcher.run();

  verifyAll();

}
 
Example 20
Source Project: hadoop   Source File: TimelineClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TimelinePutResponse putEntities(
    TimelineEntity... entities) throws IOException, YarnException {
  TimelineEntities entitiesContainer = new TimelineEntities();
  entitiesContainer.addEntities(Arrays.asList(entities));
  ClientResponse resp = doPosting(entitiesContainer, null);
  return resp.getEntity(TimelinePutResponse.class);
}
 
Example 21
Source Project: hadoop   Source File: TestTimelineClient.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntities() throws Exception {
  mockEntityClientResponse(client, ClientResponse.Status.OK, false, false);
  try {
    TimelinePutResponse response = client.putEntities(generateEntity());
    Assert.assertEquals(0, response.getErrors().size());
  } catch (YarnException e) {
    Assert.fail("Exception is not expected");
  }
}
 
Example 22
Source Project: hadoop   Source File: TestTimelineWebServicesWithSSL.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPutEntities() throws Exception {
  TestTimelineClient client = new TestTimelineClient();
  try {
    client.init(conf);
    client.start();
    TimelineEntity expectedEntity = new TimelineEntity();
    expectedEntity.setEntityType("test entity type");
    expectedEntity.setEntityId("test entity id");
    expectedEntity.setDomainId("test domain id");
    TimelineEvent event = new TimelineEvent();
    event.setEventType("test event type");
    event.setTimestamp(0L);
    expectedEntity.addEvent(event);

    TimelinePutResponse response = client.putEntities(expectedEntity);
    Assert.assertEquals(0, response.getErrors().size());
    Assert.assertTrue(client.resp.toString().contains("https"));

    TimelineEntity actualEntity = store.getEntity(
        expectedEntity.getEntityId(), expectedEntity.getEntityType(),
        EnumSet.allOf(Field.class));
    Assert.assertNotNull(actualEntity);
    Assert.assertEquals(
        expectedEntity.getEntityId(), actualEntity.getEntityId());
    Assert.assertEquals(
        expectedEntity.getEntityType(), actualEntity.getEntityType());
  } finally {
    client.stop();
    client.close();
  }
}
 
Example 23
Source Project: hadoop   Source File: TestTimelineWebServices.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntities() throws Exception {
  TimelineEntities entities = new TimelineEntities();
  TimelineEntity entity = new TimelineEntity();
  entity.setEntityId("test id 1");
  entity.setEntityType("test type 1");
  entity.setStartTime(System.currentTimeMillis());
  entity.setDomainId("domain_id_1");
  entities.addEntity(entity);
  WebResource r = resource();
  // No owner, will be rejected
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(ClientResponse.Status.FORBIDDEN,
      response.getClientResponseStatus());

  response = r.path("ws").path("v1").path("timeline")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  TimelinePutResponse putResposne =
      response.getEntity(TimelinePutResponse.class);
  Assert.assertNotNull(putResposne);
  Assert.assertEquals(0, putResposne.getErrors().size());
  // verify the entity exists in the store
  response = r.path("ws").path("v1").path("timeline")
      .path("test type 1").path("test id 1")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  entity = response.getEntity(TimelineEntity.class);
  Assert.assertNotNull(entity);
  Assert.assertEquals("test id 1", entity.getEntityId());
  Assert.assertEquals("test type 1", entity.getEntityType());
}
 
Example 24
Source Project: hadoop   Source File: TestTimelineWebServices.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntitiesToDefaultDomain() throws Exception {
  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineEntities entities = new TimelineEntities();
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityId("test id 7");
    entity.setEntityType("test type 7");
    entity.setStartTime(System.currentTimeMillis());
    entities.addEntity(entity);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("timeline")
        .queryParam("user.name", "anybody_1")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, entities);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    TimelinePutResponse putResposne =
        response.getEntity(TimelinePutResponse.class);
    Assert.assertNotNull(putResposne);
    Assert.assertEquals(0, putResposne.getErrors().size());
    // verify the entity exists in the store
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 7").path("test id 7")
        .queryParam("user.name", "any_body_2")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNotNull(entity);
    Assert.assertEquals("test id 7", entity.getEntityId());
    Assert.assertEquals("test type 7", entity.getEntityType());
    Assert.assertEquals(TimelineDataManager.DEFAULT_DOMAIN_ID,
        entity.getDomainId());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}
 
Example 25
Source Project: hadoop   Source File: ApplicationMaster.java    License: Apache License 2.0 5 votes vote down vote up
private static void publishContainerStartEvent(
    final TimelineClient timelineClient, Container container, String domainId,
    UserGroupInformation ugi) {
  final TimelineEntity entity = new TimelineEntity();
  entity.setEntityId(container.getId().toString());
  entity.setEntityType(DSEntity.DS_CONTAINER.toString());
  entity.setDomainId(domainId);
  entity.addPrimaryFilter("user", ugi.getShortUserName());
  TimelineEvent event = new TimelineEvent();
  event.setTimestamp(System.currentTimeMillis());
  event.setEventType(DSEvent.DS_CONTAINER_START.toString());
  event.addEventInfo("Node", container.getNodeId().toString());
  event.addEventInfo("Resources", container.getResource().toString());
  entity.addEvent(event);

  try {
    ugi.doAs(new PrivilegedExceptionAction<TimelinePutResponse>() {
      @Override
      public TimelinePutResponse run() throws Exception {
        return timelineClient.putEntities(entity);
      }
    });
  } catch (Exception e) {
    LOG.error("Container start event could not be published for "
        + container.getId().toString(),
        e instanceof UndeclaredThrowableException ? e.getCause() : e);
  }
}
 
Example 26
Source Project: big-c   Source File: TimelineClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TimelinePutResponse putEntities(
    TimelineEntity... entities) throws IOException, YarnException {
  TimelineEntities entitiesContainer = new TimelineEntities();
  entitiesContainer.addEntities(Arrays.asList(entities));
  ClientResponse resp = doPosting(entitiesContainer, null);
  return resp.getEntity(TimelinePutResponse.class);
}
 
Example 27
Source Project: big-c   Source File: TestTimelineClient.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntities() throws Exception {
  mockEntityClientResponse(client, ClientResponse.Status.OK, false, false);
  try {
    TimelinePutResponse response = client.putEntities(generateEntity());
    Assert.assertEquals(0, response.getErrors().size());
  } catch (YarnException e) {
    Assert.fail("Exception is not expected");
  }
}
 
Example 28
Source Project: big-c   Source File: TestTimelineWebServicesWithSSL.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPutEntities() throws Exception {
  TestTimelineClient client = new TestTimelineClient();
  try {
    client.init(conf);
    client.start();
    TimelineEntity expectedEntity = new TimelineEntity();
    expectedEntity.setEntityType("test entity type");
    expectedEntity.setEntityId("test entity id");
    expectedEntity.setDomainId("test domain id");
    TimelineEvent event = new TimelineEvent();
    event.setEventType("test event type");
    event.setTimestamp(0L);
    expectedEntity.addEvent(event);

    TimelinePutResponse response = client.putEntities(expectedEntity);
    Assert.assertEquals(0, response.getErrors().size());
    Assert.assertTrue(client.resp.toString().contains("https"));

    TimelineEntity actualEntity = store.getEntity(
        expectedEntity.getEntityId(), expectedEntity.getEntityType(),
        EnumSet.allOf(Field.class));
    Assert.assertNotNull(actualEntity);
    Assert.assertEquals(
        expectedEntity.getEntityId(), actualEntity.getEntityId());
    Assert.assertEquals(
        expectedEntity.getEntityType(), actualEntity.getEntityType());
  } finally {
    client.stop();
    client.close();
  }
}
 
Example 29
Source Project: big-c   Source File: TestTimelineWebServices.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntities() throws Exception {
  TimelineEntities entities = new TimelineEntities();
  TimelineEntity entity = new TimelineEntity();
  entity.setEntityId("test id 1");
  entity.setEntityType("test type 1");
  entity.setStartTime(System.currentTimeMillis());
  entity.setDomainId("domain_id_1");
  entities.addEntity(entity);
  WebResource r = resource();
  // No owner, will be rejected
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(ClientResponse.Status.FORBIDDEN,
      response.getClientResponseStatus());

  response = r.path("ws").path("v1").path("timeline")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .post(ClientResponse.class, entities);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  TimelinePutResponse putResposne =
      response.getEntity(TimelinePutResponse.class);
  Assert.assertNotNull(putResposne);
  Assert.assertEquals(0, putResposne.getErrors().size());
  // verify the entity exists in the store
  response = r.path("ws").path("v1").path("timeline")
      .path("test type 1").path("test id 1")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  entity = response.getEntity(TimelineEntity.class);
  Assert.assertNotNull(entity);
  Assert.assertEquals("test id 1", entity.getEntityId());
  Assert.assertEquals("test type 1", entity.getEntityType());
}
 
Example 30
Source Project: big-c   Source File: TestTimelineWebServices.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPostEntitiesToDefaultDomain() throws Exception {
  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineEntities entities = new TimelineEntities();
    TimelineEntity entity = new TimelineEntity();
    entity.setEntityId("test id 7");
    entity.setEntityType("test type 7");
    entity.setStartTime(System.currentTimeMillis());
    entities.addEntity(entity);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("timeline")
        .queryParam("user.name", "anybody_1")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, entities);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    TimelinePutResponse putResposne =
        response.getEntity(TimelinePutResponse.class);
    Assert.assertNotNull(putResposne);
    Assert.assertEquals(0, putResposne.getErrors().size());
    // verify the entity exists in the store
    response = r.path("ws").path("v1").path("timeline")
        .path("test type 7").path("test id 7")
        .queryParam("user.name", "any_body_2")
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    entity = response.getEntity(TimelineEntity.class);
    Assert.assertNotNull(entity);
    Assert.assertEquals("test id 7", entity.getEntityId());
    Assert.assertEquals("test type 7", entity.getEntityType());
    Assert.assertEquals(TimelineDataManager.DEFAULT_DOMAIN_ID,
        entity.getDomainId());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}