From 374c94909f8808e2e7d2f49a1ce1d9f7c7fb48b7 Mon Sep 17 00:00:00 2001 From: Suman Das <59254445+sumandas0@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:38:17 +0530 Subject: [PATCH 1/4] fix: add unknown error code --- intg/src/main/java/org/apache/atlas/AtlasErrorCode.java | 3 +++ .../atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java index 311ea39116..751c867fb5 100644 --- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java +++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java @@ -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}"), @@ -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"), diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java index d408a2cd05..ff2b7fa2c9 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java @@ -18,6 +18,7 @@ package org.apache.atlas.repository.store.graph.v1; +import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.RequestContext; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.instance.AtlasEntity.Status; @@ -98,7 +99,7 @@ protected void deleteEdge(AtlasEdge edge, boolean force) throws AtlasBaseExcepti AtlasRelationshipStoreV2.recordRelationshipMutation(AtlasRelationshipStoreV2.RelationshipMutation.RELATIONSHIP_SOFT_DELETE, edge, entityRetriever); } catch (Exception e) { LOG.error("Error while deleting edge {}", GraphHelper.string(edge), e); - throw new AtlasBaseException(e); + throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_SERVER_ERROR, e, "Error while deleting edge " + GraphHelper.string(edge)); } } } From 52f13ddacc8bc49dbae2c05ed41720300583c9b9 Mon Sep 17 00:00:00 2001 From: Suman Das <59254445+sumandas0@users.noreply.github.com> Date: Tue, 30 Jan 2024 13:56:27 +0530 Subject: [PATCH 2/4] fix: add npe handler in mapper --- .../store/graph/v1/SoftDeleteHandlerV1.java | 3 +- .../store/graph/v2/EntityGraphRetriever.java | 111 ++++++++++-------- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java index ff2b7fa2c9..d408a2cd05 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java @@ -18,7 +18,6 @@ package org.apache.atlas.repository.store.graph.v1; -import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.RequestContext; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.instance.AtlasEntity.Status; @@ -99,7 +98,7 @@ protected void deleteEdge(AtlasEdge edge, boolean force) throws AtlasBaseExcepti AtlasRelationshipStoreV2.recordRelationshipMutation(AtlasRelationshipStoreV2.RelationshipMutation.RELATIONSHIP_SOFT_DELETE, edge, entityRetriever); } catch (Exception e) { LOG.error("Error while deleting edge {}", GraphHelper.string(edge), e); - throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_SERVER_ERROR, e, "Error while deleting edge " + GraphHelper.string(edge)); + throw new AtlasBaseException(e); } } } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java index 288764e424..b5f5c3425d 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java @@ -975,76 +975,83 @@ private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex) private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex, Set 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 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 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){ + LOG.error("mapVertexToAtlasEntityHeader: failed for entityVertex {}", entityVertex, npe); + throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_SERVER_ERROR, npe, "mapVertexToAtlasEntityHeader: failed for entityVertex " + entityVertex); + } + finally { + RequestContext.get().endMetricRecord(metricRecorder); + } return ret; } From 35af5eda52d4eaba9d0212d96a4c8f3dbf4603ce Mon Sep 17 00:00:00 2001 From: Suman Das <59254445+sumandas0@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:07:11 +0530 Subject: [PATCH 3/4] re: refactor the error type --- .../repository/store/graph/v2/EntityGraphRetriever.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java index b5f5c3425d..18111068f7 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java @@ -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; @@ -1045,9 +1044,10 @@ private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex, } } } - catch (NullPointerException npe){ - LOG.error("mapVertexToAtlasEntityHeader: failed for entityVertex {}", entityVertex, npe); - throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_SERVER_ERROR, npe, "mapVertexToAtlasEntityHeader: failed for entityVertex " + entityVertex); + 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); From 4ab94f7992f89c57aa53cafb23baa79a051bb341 Mon Sep 17 00:00:00 2001 From: Suman Das <59254445+sumandas0@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:30:48 +0530 Subject: [PATCH 4/4] re: add spacing --- .../atlas/repository/store/graph/v2/EntityGraphRetriever.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java index 18111068f7..390036d477 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphRetriever.java @@ -1047,7 +1047,7 @@ private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex, 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); + throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_SERVER_ERROR, npe, "mapVertexToAtlasEntityHeader: failed for entityVertex with id " + id); } finally { RequestContext.get().endMetricRecord(metricRecorder);