Package org.apache.hadoop.yarn.api.records.timeline

Examples of org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse


    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("timeline")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, entities);
    TimelinePutResponse putResposne = response.getEntity(TimelinePutResponse.class);
    Assert.assertEquals(1, putResposne.getErrors().size());
    List<TimelinePutError> errors = putResposne.getErrors();
    Assert.assertEquals(TimelinePutResponse.TimelinePutError.SYSTEM_FILTER_CONFLICT,
      errors.get(0).getErrorCode());
  }
View Full Code Here


    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());
    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);
View Full Code Here

      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());
      TimelinePutResponse putResponse = response.getEntity(TimelinePutResponse.class);
      Assert.assertNotNull(putResponse);
      Assert.assertEquals(0, putResponse.getErrors().size());

      // override/append timeline data in the same entity with different user
      remoteUser = "other";
      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());
      putResponse = response.getEntity(TimelinePutResponse.class);
      Assert.assertNotNull(putResponse);
      Assert.assertEquals(1, putResponse.getErrors().size());
      Assert.assertEquals(TimelinePutResponse.TimelinePutError.ACCESS_DENIED,
          putResponse.getErrors().get(0).getErrorCode());
    } finally {
      timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
      remoteUser = null;
    }
  }
View Full Code Here

  @Override
  public TimelinePutResponse put(TimelineEntities entities) {
    try {
      deleteLock.readLock().lock();
      TimelinePutResponse response = new TimelinePutResponse();
      for (TimelineEntity entity : entities.getEntities()) {
        put(entity, response);
      }
      return response;
    } finally {
View Full Code Here

    return allEvents;
  }

  @Override
  public TimelinePutResponse put(TimelineEntities data) {
    TimelinePutResponse response = new TimelinePutResponse();
    for (TimelineEntity entity : data.getEntities()) {
      EntityIdentifier entityId =
          new EntityIdentifier(entity.getEntityId(), entity.getEntityType());
      // store entity info in memory
      TimelineEntity existingEntity = entities.get(entityId);
      if (existingEntity == null) {
        existingEntity = new TimelineEntity();
        existingEntity.setEntityId(entity.getEntityId());
        existingEntity.setEntityType(entity.getEntityType());
        existingEntity.setStartTime(entity.getStartTime());
        entities.put(entityId, existingEntity);
        entityInsertTimes.put(entityId, System.currentTimeMillis());
      }
      if (entity.getEvents() != null) {
        if (existingEntity.getEvents() == null) {
          existingEntity.setEvents(entity.getEvents());
        } else {
          existingEntity.addEvents(entity.getEvents());
        }
        Collections.sort(existingEntity.getEvents());
      }
      // check startTime
      if (existingEntity.getStartTime() == null) {
        if (existingEntity.getEvents() == null
            || existingEntity.getEvents().isEmpty()) {
          TimelinePutError error = new TimelinePutError();
          error.setEntityId(entityId.getId());
          error.setEntityType(entityId.getType());
          error.setErrorCode(TimelinePutError.NO_START_TIME);
          response.addError(error);
          entities.remove(entityId);
          entityInsertTimes.remove(entityId);
          continue;
        } else {
          Long min = Long.MAX_VALUE;
View Full Code Here

      @Context HttpServletRequest req,
      @Context HttpServletResponse res,
      TimelineEntities entities) {
    init(res);
    if (entities == null) {
      return new TimelinePutResponse();
    }
    UserGroupInformation callerUGI = getUser(req);
    try {
      List<EntityIdentifier> entityIDs = new ArrayList<EntityIdentifier>();
      TimelineEntities entitiesToPut = new TimelineEntities();
      List<TimelinePutResponse.TimelinePutError> errors =
          new ArrayList<TimelinePutResponse.TimelinePutError>();
      for (TimelineEntity entity : entities.getEntities()) {
        EntityIdentifier entityID =
            new EntityIdentifier(entity.getEntityId(), entity.getEntityType());

        // check if there is existing entity
        TimelineEntity existingEntity = null;
        try {
          existingEntity =
              store.getEntity(entityID.getId(), entityID.getType(),
                  EnumSet.of(Field.PRIMARY_FILTERS));
          if (existingEntity != null
              && !timelineACLsManager.checkAccess(callerUGI, existingEntity)) {
            throw new YarnException("The timeline entity " + entityID
                + " was not put by " + callerUGI + " before");
          }
        } catch (Exception e) {
          // Skip the entity which already exists and was put by others
          LOG.warn("Skip the timeline entity: " + entityID + ", because "
              + e.getMessage());
          TimelinePutResponse.TimelinePutError error =
              new TimelinePutResponse.TimelinePutError();
          error.setEntityId(entityID.getId());
          error.setEntityType(entityID.getType());
          error.setErrorCode(
              TimelinePutResponse.TimelinePutError.ACCESS_DENIED);
          errors.add(error);
          continue;
        }

        // inject owner information for the access check if this is the first
        // time to post the entity, in case it's the admin who is updating
        // the timeline data.
        try {
          if (existingEntity == null) {
            injectOwnerInfo(entity,
                callerUGI == null ? "" : callerUGI.getShortUserName());
          }
        } catch (YarnException e) {
          // Skip the entity which messes up the primary filter and record the
          // error
          LOG.warn("Skip the timeline entity: " + entityID + ", because "
              + e.getMessage());
          TimelinePutResponse.TimelinePutError error =
              new TimelinePutResponse.TimelinePutError();
          error.setEntityId(entityID.getId());
          error.setEntityType(entityID.getType());
          error.setErrorCode(
              TimelinePutResponse.TimelinePutError.SYSTEM_FILTER_CONFLICT);
          errors.add(error);
          continue;
        }

        entityIDs.add(entityID);
        entitiesToPut.addEntity(entity);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Storing the entity " + entityID + ", JSON-style content: "
              + TimelineUtils.dumpTimelineRecordtoJSON(entity));
        }
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("Storing entities: " + CSV_JOINER.join(entityIDs));
      }
      TimelinePutResponse response =  store.put(entitiesToPut);
      // add the errors of timeline system filter key conflict
      response.addErrors(errors);
      return response;
    } catch (IOException e) {
      LOG.error("Error putting entities", e);
      throw new WebApplicationException(e,
          Response.Status.INTERNAL_SERVER_ERROR);
View Full Code Here

  @Test
  public void testPostEntities() throws Exception {
    mockClientResponse(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");
    }
  }
View Full Code Here

  @Test
  public void testPostEntitiesWithError() throws Exception {
    mockClientResponse(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");
    }
  }
View Full Code Here

    conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, false);
    TimelineClientImpl client = createTimelineClient(conf);
    mockClientResponse(
        client, ClientResponse.Status.INTERNAL_SERVER_ERROR, false, false);
    try {
      TimelinePutResponse response = client.putEntities(generateEntity());
      Assert.assertEquals(0, response.getErrors().size());
    } catch (YarnException e) {
      Assert.fail(
          "putEntities should already return before throwing the exception");
    }
  }
View Full Code Here

    conf.unset(YarnConfiguration.TIMELINE_SERVICE_ENABLED);
    TimelineClientImpl client = createTimelineClient(conf);
    mockClientResponse(client, ClientResponse.Status.INTERNAL_SERVER_ERROR,
        false, false);
    try {
      TimelinePutResponse response = client.putEntities(generateEntity());
      Assert.assertEquals(0, response.getErrors().size());
    } catch (YarnException e) {
      Assert
          .fail("putEntities should already return before throwing the exception");
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.