Commit 39eb9f1e by Hemanth Yamijala

ATLAS-890 Log received messages in case of error (sumasai via yhemanth)

parent aad34ae0
......@@ -159,6 +159,11 @@ public class HookNotification implements JsonDeserializer<HookNotification.HookN
public List<Referenceable> getEntities() throws JSONException {
return entities;
}
@Override
public String toString() {
return entities.toString();
}
}
/**
......@@ -210,6 +215,16 @@ public class HookNotification implements JsonDeserializer<HookNotification.HookN
public String getAttributeValue() {
return attributeValue;
}
@Override
public String toString() {
return "{"
+ "entityType='" + typeName + '\''
+ ", attribute=" + attribute
+ ", value=" + attributeValue
+ ", entity=" + entity
+ '}';
}
}
/**
......@@ -247,5 +262,14 @@ public class HookNotification implements JsonDeserializer<HookNotification.HookN
public String getAttributeValue() {
return attributeValue;
}
@Override
public String toString() {
return "{"
+ "entityType='" + typeName + '\''
+ ", attribute=" + attribute
+ ", value=" + attributeValue
+ '}';
}
}
}
......@@ -23,6 +23,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset
ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags)
ALL CHANGES:
ATLAS-890 Log received messages in case of error (sumasai via yhemanth)
ATLAS-888 NPE in NotificationHookConsumer (sumasai via shwethags)
ATLAS-884 Process registration should call Entity update instead of create (sumasai)
ATLAS-515 Ability to initialize Kafka topics with more than 1 replica (yhemanth)
......
......@@ -105,6 +105,8 @@ public class EntityResource {
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response submit(@Context HttpServletRequest request) {
String entityJson = null;
try {
String entities = Servlets.getRequestPayload(request);
......@@ -118,7 +120,8 @@ public class EntityResource {
}}.toString();
}
LOG.debug("submitting entities {} ", AtlasClient.toString(new JSONArray(entities)));
entityJson = AtlasClient.toString(new JSONArray(entities));
LOG.debug("submitting entities {} ", entityJson);
final List<String> guids = metadataService.createEntities(entities);
JSONObject response = getResponse(new AtlasClient.EntityResult(guids, null, null));
......@@ -128,16 +131,16 @@ public class EntityResource {
return Response.created(locationURI).entity(response).build();
} catch(EntityExistsException e) {
LOG.error("Unique constraint violation", e);
LOG.error("Unique constraint violation for entity entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT));
} catch (ValueConversionException ve) {
LOG.error("Unable to persist entity instance due to a deserialization error ", ve);
LOG.error("Unable to persist entity instance due to a deserialization error entityDef={}", entityJson, ve);
throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause(), Response.Status.BAD_REQUEST));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to persist entity instance", e);
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to persist entity instance", e);
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......@@ -180,24 +183,28 @@ public class EntityResource {
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response updateEntities(@Context HttpServletRequest request) {
String entityJson = null;
try {
final String entities = Servlets.getRequestPayload(request);
LOG.debug("updating entities {} ", AtlasClient.toString(new JSONArray(entities)));
entityJson = AtlasClient.toString(new JSONArray(entities));
LOG.debug("updating entities {} ", entityJson);
AtlasClient.EntityResult entityResult = metadataService.updateEntities(entities);
JSONObject response = getResponse(entityResult);
return Response.ok(response).build();
} catch(EntityExistsException e) {
LOG.error("Unique constraint violation", e);
LOG.error("Unique constraint violation for entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT));
} catch (ValueConversionException ve) {
LOG.error("Unable to persist entity instance due to a deserialization error ", ve);
LOG.error("Unable to persist entity instance due to a deserialization error entityDef={}", entityJson, ve);
throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause(), Response.Status.BAD_REQUEST));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to persist entity instance", e);
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to persist entity instance", e);
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......@@ -241,32 +248,35 @@ public class EntityResource {
public Response updateByUniqueAttribute(@QueryParam("type") String entityType,
@QueryParam("property") String attribute,
@QueryParam("value") String value, @Context HttpServletRequest request) {
String entityJson = null;
try {
String entities = Servlets.getRequestPayload(request);
entityJson = Servlets.getRequestPayload(request);
LOG.debug("Partially updating entity by unique attribute {} {} {} {} ", entityType, attribute, value, entities);
LOG.debug("Partially updating entity by unique attribute {} {} {} {} ", entityType, attribute, value, entityJson);
Referenceable updatedEntity =
InstanceSerialization.fromJsonReferenceable(entities, true);
InstanceSerialization.fromJsonReferenceable(entityJson, true);
AtlasClient.EntityResult entityResult =
metadataService.updateEntityByUniqueAttribute(entityType, attribute, value, updatedEntity);
JSONObject response = getResponse(entityResult);
return Response.ok(response).build();
} catch (ValueConversionException ve) {
LOG.error("Unable to persist entity instance due to a deserialization error ", ve);
LOG.error("Unable to persist entity instance due to a deserialization error {} ", entityJson, ve);
throw new WebApplicationException(Servlets.getErrorResponse(ve.getCause(), Response.Status.BAD_REQUEST));
} catch(EntityExistsException e) {
LOG.error("Unique constraint violation", e);
LOG.error("Unique constraint violation for entity {} ", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.CONFLICT));
} catch (EntityNotFoundException e) {
LOG.error("An entity with type={} and qualifiedName={} does not exist", entityType, value, e);
LOG.error("An entity with type={} and qualifiedName={} does not exist {} ", entityType, value, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to create/update entity {}" + entityType + ":" + attribute + "." + value, e);
LOG.error("Unable to partially update entity {} {} " + entityType + ":" + attribute + "." + value, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to update entity {}" + entityType + ":" + attribute + "." + value, e);
LOG.error("Unable to partially update entity {} {} " + entityType + ":" + attribute + "." + value, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......@@ -294,9 +304,10 @@ public class EntityResource {
}
private Response updateEntityPartialByGuid(String guid, HttpServletRequest request) {
String entityJson = null;
try {
ParamChecker.notEmpty(guid, "Guid property cannot be null");
final String entityJson = Servlets.getRequestPayload(request);
entityJson = Servlets.getRequestPayload(request);
LOG.debug("partially updating entity for guid {} : {} ", guid, entityJson);
Referenceable updatedEntity =
......@@ -305,13 +316,13 @@ public class EntityResource {
JSONObject response = getResponse(entityResult);
return Response.ok(response).build();
} catch (EntityNotFoundException e) {
LOG.error("An entity with GUID={} does not exist", guid, e);
LOG.error("An entity with GUID={} does not exist {} ", guid, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to update entity {}", guid, e);
LOG.error("Unable to update entity by GUID {} {}", guid, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to update entity {}", guid, e);
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......@@ -327,22 +338,23 @@ public class EntityResource {
* @return response payload as json
*/
private Response updateEntityAttributeByGuid(String guid, String property, HttpServletRequest request) {
String value = null;
try {
Preconditions.checkNotNull(property, "Entity property cannot be null");
String value = Servlets.getRequestPayload(request);
value = Servlets.getRequestPayload(request);
Preconditions.checkNotNull(value, "Entity value cannot be null");
AtlasClient.EntityResult entityResult = metadataService.updateEntityAttributeByGuid(guid, property, value);
JSONObject response = getResponse(entityResult);
return Response.ok(response).build();
} catch (EntityNotFoundException e) {
LOG.error("An entity with GUID={} does not exist", guid, e);
LOG.error("An entity with GUID={} does not exist {} ", guid, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to add property {} to entity id {}", property, guid, e);
LOG.error("Unable to add property {} to entity id {} {} ", property, guid, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to add property {} to entity id {}", property, guid, e);
LOG.error("Unable to add property {} to entity id {} {} ", property, guid, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......@@ -377,16 +389,16 @@ public class EntityResource {
return Response.ok(response).build();
} catch (EntityNotFoundException e) {
if(guids != null || !guids.isEmpty()) {
LOG.error("An entity with GUID={} does not exist", guids, e);
LOG.error("An entity with GUID={} does not exist ", guids, e);
} else {
LOG.error("An entity with qualifiedName {}-{}-{} does not exist", entityType, attribute, value, e);
}
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to delete entities {}", guids, e);
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to delete entities {}", guids, e);
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......@@ -420,10 +432,10 @@ public class EntityResource {
return Response.status(status).entity(response).build();
} catch (EntityNotFoundException e) {
LOG.error("An entity with GUID={} does not exist", guid, e);
LOG.error("An entity with GUID={} does not exist ", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Bad GUID={}", guid, e);
LOG.error("Bad GUID={} ", guid, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to get instance definition for GUID {}", guid, e);
......@@ -564,8 +576,9 @@ public class EntityResource {
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response addTrait(@Context HttpServletRequest request, @PathParam("guid") final String guid) {
String traitDefinition = null;
try {
final String traitDefinition = Servlets.getRequestPayload(request);
traitDefinition = Servlets.getRequestPayload(request);
LOG.debug("Adding trait={} for entity={} ", traitDefinition, guid);
metadataService.addTrait(guid, traitDefinition);
......@@ -578,13 +591,13 @@ public class EntityResource {
return Response.created(locationURI).entity(response).build();
} catch (EntityNotFoundException | TypeNotFoundException e) {
LOG.error("An entity with GUID={} does not exist", guid, e);
LOG.error("An entity with GUID={} does not exist traitDef={} ", guid, traitDefinition, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to add trait for entity={}", guid, e);
LOG.error("Unable to add trait for entity={} traitDef={}", guid, traitDefinition, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to add trait for entity={}", guid, e);
LOG.error("Unable to add trait for entity={} traitDef={}", guid, traitDefinition, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......@@ -611,7 +624,7 @@ public class EntityResource {
return Response.ok(response).build();
} catch (EntityNotFoundException | TypeNotFoundException e) {
LOG.error("An entity with GUID={} does not exist", guid, e);
LOG.error("An entity with GUID={} does not exist traitName={} ", guid, traitName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (TraitNotFoundException e) {
LOG.error("The trait name={} for entity={} does not exist.", traitName, guid, e);
......@@ -650,10 +663,10 @@ public class EntityResource {
response.put(AtlasClient.EVENTS, getJSONArray(events));
return Response.ok(response).build();
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to get audit events for entity {}", guid, e);
LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to get audit events for entity {}", guid, e);
LOG.error("Unable to get audit events for entity guid={} startKey={}", guid, startKey, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment