Search in sources :

Example 11 with TimelinePutResponse

use of org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse in project jstorm by alibaba.

the class JstormMaster method publishContainerStartEvent.

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(JOYConstants.USER, ugi.getShortUserName());
    TimelineEvent event = new TimelineEvent();
    event.setTimestamp(System.currentTimeMillis());
    event.setEventType(DSEvent.DS_CONTAINER_START.toString());
    event.addEventInfo(JOYConstants.NODE, container.getNodeId().toString());
    event.addEventInfo(JOYConstants.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);
    }
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timeline.TimelineEvent) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ParseException(org.apache.commons.cli.ParseException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 12 with TimelinePutResponse

use of org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse in project hadoop by apache.

the class ApplicationMaster method publishApplicationAttemptEvent.

private void publishApplicationAttemptEvent(final TimelineClient timelineClient, String appAttemptId, DSEvent appEvent, String domainId, UserGroupInformation ugi) {
    final TimelineEntity entity = new TimelineEntity();
    entity.setEntityId(appAttemptId);
    entity.setEntityType(DSEntity.DS_APP_ATTEMPT.toString());
    entity.setDomainId(domainId);
    entity.addPrimaryFilter(USER_TIMELINE_FILTER_NAME, ugi.getShortUserName());
    TimelineEvent event = new TimelineEvent();
    event.setEventType(appEvent.toString());
    event.setTimestamp(System.currentTimeMillis());
    entity.addEvent(event);
    try {
        TimelinePutResponse response = timelineClient.putEntities(entity);
        processTimelineResponseErrors(response);
    } catch (YarnException | IOException | ClientHandlerException e) {
        LOG.error("App Attempt " + (appEvent.equals(DSEvent.DS_APP_ATTEMPT_START) ? "start" : "end") + " event could not be published for " + appAttemptID, e);
    }
}
Also used : TimelineEvent(org.apache.hadoop.yarn.api.records.timeline.TimelineEvent) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) IOException(java.io.IOException) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 13 with TimelinePutResponse

use of org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse in project hadoop by apache.

the class TestTimelineClient method testPostEntities.

@Test
public void testPostEntities() throws Exception {
    mockEntityClientResponse(spyTimelineWriter, 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");
    }
}
Also used : TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) Test(org.junit.Test)

Example 14 with TimelinePutResponse

use of org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse in project hadoop by apache.

the class TimelineDataManager method doPostEntities.

private TimelinePutResponse doPostEntities(TimelineEntities entities, UserGroupInformation callerUGI) throws YarnException, IOException {
    if (entities == null) {
        return new TimelinePutResponse();
    }
    metrics.incrPostEntitiesTotal(entities.getEntities().size());
    TimelineEntities entitiesToPut = new TimelineEntities();
    List<TimelinePutResponse.TimelinePutError> errors = new ArrayList<TimelinePutResponse.TimelinePutError>();
    for (TimelineEntity entity : entities.getEntities()) {
        // the default domain
        if (entity.getDomainId() == null || entity.getDomainId().length() == 0) {
            entity.setDomainId(DEFAULT_DOMAIN_ID);
        }
        if (entity.getEntityId() == null || entity.getEntityType() == null) {
            throw new BadRequestException("Incomplete entity without entity" + " id/type");
        }
        // check if there is existing entity
        TimelineEntity existingEntity = null;
        try {
            existingEntity = store.getEntity(entity.getEntityId(), entity.getEntityType(), EnumSet.of(Field.PRIMARY_FILTERS));
            if (existingEntity != null) {
                addDefaultDomainIdIfAbsent(existingEntity);
                if (!existingEntity.getDomainId().equals(entity.getDomainId())) {
                    throw new YarnException("The domain of the timeline entity " + "{ id: " + entity.getEntityId() + ", type: " + entity.getEntityType() + " } is not allowed to be changed from " + existingEntity.getDomainId() + " to " + entity.getDomainId());
                }
            }
            if (!timelineACLsManager.checkAccess(callerUGI, ApplicationAccessType.MODIFY_APP, entity)) {
                throw new YarnException(callerUGI + " is not allowed to put the timeline entity " + "{ id: " + entity.getEntityId() + ", type: " + entity.getEntityType() + " } into the domain " + entity.getDomainId() + ".");
            }
        } catch (Exception e) {
            // Skip the entity which already exists and was put by others
            LOG.warn("Skip the timeline entity: { id: " + entity.getEntityId() + ", type: " + entity.getEntityType() + " }", e);
            TimelinePutResponse.TimelinePutError error = new TimelinePutResponse.TimelinePutError();
            error.setEntityId(entity.getEntityId());
            error.setEntityType(entity.getEntityType());
            error.setErrorCode(TimelinePutResponse.TimelinePutError.ACCESS_DENIED);
            errors.add(error);
            continue;
        }
        entitiesToPut.addEntity(entity);
    }
    TimelinePutResponse response = store.put(entitiesToPut);
    // add the errors of timeline system filter key conflict
    response.addErrors(errors);
    return response;
}
Also used : TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) ArrayList(java.util.ArrayList) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException)

Example 15 with TimelinePutResponse

use of org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse in project hadoop by apache.

the class TimelineWebServices method putDomain.

/**
   * Store the given domain into the timeline store, and return the errors
   * that happen during storing.
   */
@PUT
@Path("/domain")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 })
public TimelinePutResponse putDomain(@Context HttpServletRequest req, @Context HttpServletResponse res, TimelineDomain domain) {
    init(res);
    UserGroupInformation callerUGI = getUser(req);
    if (callerUGI == null) {
        String msg = "The owner of the posted timeline domain is not set";
        LOG.error(msg);
        throw new ForbiddenException(msg);
    }
    domain.setOwner(callerUGI.getShortUserName());
    try {
        timelineDataManager.putDomain(domain, callerUGI);
    } catch (YarnException e) {
        // The user doesn't have the access to override the existing domain.
        LOG.error(e.getMessage(), e);
        throw new ForbiddenException(e);
    } catch (RuntimeException e) {
        LOG.error("Error putting domain", e);
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    } catch (IOException e) {
        LOG.error("Error putting domain", e);
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
    return new TimelinePutResponse();
}
Also used : ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) WebApplicationException(javax.ws.rs.WebApplicationException) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

TimelinePutResponse (org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse)25 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)20 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)15 Test (org.junit.Test)14 ClientResponse (com.sun.jersey.api.client.ClientResponse)8 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)8 WebResource (com.sun.jersey.api.client.WebResource)7 TimelineEvent (org.apache.hadoop.yarn.api.records.timeline.TimelineEvent)7 IOException (java.io.IOException)6 AdminACLsManager (org.apache.hadoop.yarn.security.AdminACLsManager)5 Set (java.util.Set)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 SortedSet (java.util.SortedSet)2 TimelinePutError (org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse.TimelinePutError)2 File (java.io.File)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1