Skip to content

Commit

Permalink
Merge pull request #2803 from atlanhq/error-code-fix
Browse files Browse the repository at this point in the history
fix: Add error code for unknown errors so we could run pinpoint on them
  • Loading branch information
sumandas0 authored Jan 31, 2024
2 parents b4a7987 + 4ab94f7 commit 8a876e6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 53 deletions.
3 changes: 3 additions & 0 deletions intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public enum AtlasErrorCode {
CATEGORY_PARENT_FROM_OTHER_GLOSSARY(409, "ATLAS-400-00-0015", "Parent category from another Anchor(glossary) not supported"),
CLASSIFICATION_TYPE_HAS_REFERENCES(409, "ATLAS-400-00-0016", "Given classification {0} [{1}] has references"),
// All internal errors go here
UNKNOWN_SERVER_ERROR(500, "ATLAS-500-00-000", "Unknown server error detected {0}"),

INTERNAL_ERROR(500, "ATLAS-500-00-001", "Internal server error {0}"),
INDEX_CREATION_FAILED(500, "ATLAS-500-00-002", "Index creation failed for {0}"),
INDEX_ROLLBACK_FAILED(500, "ATLAS-500-00-003", "Index rollback failed for {0}"),
Expand Down Expand Up @@ -271,6 +273,7 @@ public enum AtlasErrorCode {
CINV_UNHEALTHY(500, "ATLAS-500-00-21", "Unable to process type-definition operations"),
RUNTIME_EXCEPTION(500, "ATLAS-500-00-020", "Runtime exception {0}"),
KEYCLOAK_INIT_FAILED(500, "ATLAS-500-00-022", "Failed to initialize keycloak client: {0}"),

BATCH_SIZE_TOO_LARGE(406, "ATLAS-406-00-001", "Batch size is too large, please use a smaller batch size"),


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
import static org.apache.atlas.repository.graph.GraphHelper.*;
import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.getIdFromVertex;
import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.isReference;
import static org.apache.atlas.repository.store.graph.v2.tasks.ClassificationPropagateTaskFactory.CLASSIFICATION_ONLY_PROPAGATION_DELETE;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.IN;
Expand Down Expand Up @@ -975,76 +974,84 @@ private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex)
private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex, Set<String> attributes) throws AtlasBaseException {
AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("mapVertexToAtlasEntityHeader");
AtlasEntityHeader ret = new AtlasEntityHeader();
try {
String typeName = entityVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class);
String guid = entityVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class);
Boolean isIncomplete = isEntityIncomplete(entityVertex);

ret.setTypeName(typeName);
ret.setGuid(guid);
ret.setStatus(GraphHelper.getStatus(entityVertex));
if(RequestContext.get().includeClassifications()){
ret.setClassificationNames(getAllTraitNames(entityVertex));
}
ret.setIsIncomplete(isIncomplete);
ret.setLabels(getLabels(entityVertex));

ret.setCreatedBy(GraphHelper.getCreatedByAsString(entityVertex));
ret.setUpdatedBy(GraphHelper.getModifiedByAsString(entityVertex));
ret.setCreateTime(new Date(GraphHelper.getCreatedTime(entityVertex)));
ret.setUpdateTime(new Date(GraphHelper.getModifiedTime(entityVertex)));

if(RequestContext.get().includeMeanings()) {
List<AtlasTermAssignmentHeader> termAssignmentHeaders = mapAssignedTerms(entityVertex);
ret.setMeanings(termAssignmentHeaders);
ret.setMeaningNames(
termAssignmentHeaders.stream().map(AtlasTermAssignmentHeader::getDisplayText)
.collect(Collectors.toList()));
}
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);

String typeName = entityVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class);
String guid = entityVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class);
Boolean isIncomplete = isEntityIncomplete(entityVertex);

ret.setTypeName(typeName);
ret.setGuid(guid);
ret.setStatus(GraphHelper.getStatus(entityVertex));
if(RequestContext.get().includeClassifications()){
ret.setClassificationNames(getAllTraitNames(entityVertex));
}
ret.setIsIncomplete(isIncomplete);
ret.setLabels(getLabels(entityVertex));

ret.setCreatedBy(GraphHelper.getCreatedByAsString(entityVertex));
ret.setUpdatedBy(GraphHelper.getModifiedByAsString(entityVertex));
ret.setCreateTime(new Date(GraphHelper.getCreatedTime(entityVertex)));
ret.setUpdateTime(new Date(GraphHelper.getModifiedTime(entityVertex)));
if (entityType != null) {
for (AtlasAttribute headerAttribute : entityType.getHeaderAttributes().values()) {
Object attrValue = getVertexAttribute(entityVertex, headerAttribute);

if(RequestContext.get().includeMeanings()) {
List<AtlasTermAssignmentHeader> termAssignmentHeaders = mapAssignedTerms(entityVertex);
ret.setMeanings(termAssignmentHeaders);
ret.setMeaningNames(
termAssignmentHeaders.stream().map(AtlasTermAssignmentHeader::getDisplayText)
.collect(Collectors.toList()));
}
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
if (attrValue != null) {
ret.setAttribute(headerAttribute.getName(), attrValue);
}
}

if (entityType != null) {
for (AtlasAttribute headerAttribute : entityType.getHeaderAttributes().values()) {
Object attrValue = getVertexAttribute(entityVertex, headerAttribute);
Object displayText = getDisplayText(entityVertex, entityType);

if (attrValue != null) {
ret.setAttribute(headerAttribute.getName(), attrValue);
if (displayText != null) {
ret.setDisplayText(displayText.toString());
}
}

Object displayText = getDisplayText(entityVertex, entityType);
if (CollectionUtils.isNotEmpty(attributes)) {
for (String attrName : attributes) {
AtlasAttribute attribute = entityType.getAttribute(attrName);

if (displayText != null) {
ret.setDisplayText(displayText.toString());
}
if (attribute == null) {
attrName = toNonQualifiedName(attrName);

if (CollectionUtils.isNotEmpty(attributes)) {
for (String attrName : attributes) {
AtlasAttribute attribute = entityType.getAttribute(attrName);
if (ret.hasAttribute(attrName)) {
continue;
}

if (attribute == null) {
attrName = toNonQualifiedName(attrName);
attribute = entityType.getAttribute(attrName);

if (ret.hasAttribute(attrName)) {
continue;
if (attribute == null) {
attribute = entityType.getRelationshipAttribute(attrName, null);
}
}

attribute = entityType.getAttribute(attrName);
Object attrValue = getVertexAttribute(entityVertex, attribute);

if (attribute == null) {
attribute = entityType.getRelationshipAttribute(attrName, null);
if (attrValue != null) {
ret.setAttribute(attrName, attrValue);
}
}

Object attrValue = getVertexAttribute(entityVertex, attribute);

if (attrValue != null) {
ret.setAttribute(attrName, attrValue);
}
}
}
}
RequestContext.get().endMetricRecord(metricRecorder);
catch (NullPointerException npe) {
String id = entityVertex.getIdForDisplay()==null ? "null" :entityVertex.getIdForDisplay();
LOG.error("mapVertexToAtlasEntityHeader: failed for entityVertex with id {}", id, npe);
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_SERVER_ERROR, npe, "mapVertexToAtlasEntityHeader: failed for entityVertex with id " + id);
}
finally {
RequestContext.get().endMetricRecord(metricRecorder);
}
return ret;
}

Expand Down

0 comments on commit 8a876e6

Please sign in to comment.