YARN-3456. Improve handling of incomplete TimelineEntities. (Varun Saxena via rohithsharmaks)

This commit is contained in:
rohithsharmaks 2015-12-07 15:16:56 +05:30
parent 65f395226b
commit 01a641bc44
6 changed files with 46 additions and 3 deletions

View File

@ -599,6 +599,9 @@ Release 2.8.0 - UNRELEASED
YARN-4358. Reservation System: Improve relationship between SharingPolicy YARN-4358. Reservation System: Improve relationship between SharingPolicy
and ReservationAgent. (Carlo Curino via asuresh) and ReservationAgent. (Carlo Curino via asuresh)
YARN-3456. Improve handling of incomplete TimelineEntities. (Varun Saxena
via rohithsharmaks)
OPTIMIZATIONS OPTIMIZATIONS
YARN-3339. TestDockerContainerExecutor should pull a single image and not YARN-3339. TestDockerContainerExecutor should pull a single image and not

View File

@ -29,7 +29,6 @@
import java.net.URLConnection; import java.net.URLConnection;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.Arrays;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
@ -301,7 +300,12 @@ protected void serviceInit(Configuration conf) throws Exception {
public TimelinePutResponse putEntities( public TimelinePutResponse putEntities(
TimelineEntity... entities) throws IOException, YarnException { TimelineEntity... entities) throws IOException, YarnException {
TimelineEntities entitiesContainer = new TimelineEntities(); TimelineEntities entitiesContainer = new TimelineEntities();
entitiesContainer.addEntities(Arrays.asList(entities)); for (TimelineEntity entity : entities) {
if (entity.getEntityId() == null || entity.getEntityType() == null) {
throw new YarnException("Incomplete entity without entity id/type");
}
entitiesContainer.addEntity(entity);
}
ClientResponse resp = doPosting(entitiesContainer, null); ClientResponse resp = doPosting(entitiesContainer, null);
return resp.getEntity(TimelinePutResponse.class); return resp.getEntity(TimelinePutResponse.class);
} }

View File

@ -95,6 +95,15 @@ public void testPostEntitiesWithError() throws Exception {
} }
} }
@Test
public void testPostIncompleteEntities() throws Exception {
try {
client.putEntities(new TimelineEntity());
Assert.fail("Exception should have been thrown");
} catch (YarnException e) {
}
}
@Test @Test
public void testPostEntitiesNoResponse() throws Exception { public void testPostEntitiesNoResponse() throws Exception {
mockEntityClientResponse( mockEntityClientResponse(

View File

@ -42,6 +42,7 @@
import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.server.timeline.TimelineReader.Field; import org.apache.hadoop.yarn.server.timeline.TimelineReader.Field;
import org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager; import org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager;
import org.apache.hadoop.yarn.webapp.BadRequestException;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -338,7 +339,10 @@ private TimelinePutResponse doPostEntities(
entity.getDomainId().length() == 0) { entity.getDomainId().length() == 0) {
entity.setDomainId(DEFAULT_DOMAIN_ID); 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 // check if there is existing entity
TimelineEntity existingEntity = null; TimelineEntity existingEntity = null;
try { try {

View File

@ -229,6 +229,8 @@ public TimelinePutResponse postEntities(
} }
try { try {
return timelineDataManager.postEntities(entities, callerUGI); return timelineDataManager.postEntities(entities, callerUGI);
} catch (BadRequestException bre) {
throw bre;
} catch (Exception e) { } catch (Exception e) {
LOG.error("Error putting entities", e); LOG.error("Error putting entities", e);
throw new WebApplicationException(e, throw new WebApplicationException(e,

View File

@ -502,6 +502,27 @@ public void testPostEntities() throws Exception {
Assert.assertEquals("test type 1", entity.getEntityType()); Assert.assertEquals("test type 1", entity.getEntityType());
} }
@Test
public void testPostIncompleteEntities() throws Exception {
TimelineEntities entities = new TimelineEntities();
TimelineEntity entity1 = new TimelineEntity();
entity1.setEntityId("test id 1");
entity1.setEntityType("test type 1");
entity1.setStartTime(System.currentTimeMillis());
entity1.setDomainId("domain_id_1");
entities.addEntity(entity1);
// Add an entity with no id or type.
entities.addEntity(new TimelineEntity());
WebResource r = resource();
// One of the entities has no id or type. HTTP 400 will be returned
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);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
assertEquals(ClientResponse.Status.BAD_REQUEST,
response.getClientResponseStatus());
}
@Test @Test
public void testPostEntitiesWithYarnACLsEnabled() throws Exception { public void testPostEntitiesWithYarnACLsEnabled() throws Exception {
AdminACLsManager oldAdminACLsManager = AdminACLsManager oldAdminACLsManager =