From 2e37d392bee9029dc6c87c5c197f9794ef3e5801 Mon Sep 17 00:00:00 2001 From: Nikhil P Bonte Date: Tue, 29 Oct 2024 17:10:25 +0530 Subject: [PATCH] MM-3720 Chargebee another NPE while removing Struct vertex --- .../store/graph/v1/DeleteHandlerV1.java | 106 ++++++++++-------- 1 file changed, 58 insertions(+), 48 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java index 537f27339f..68c6dacd9c 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java @@ -789,71 +789,81 @@ protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throw } String typeName = GraphHelper.getTypeName(instanceVertex); - AtlasType parentType = typeRegistry.getType(typeName); - if (parentType instanceof AtlasStructType) { - AtlasStructType structType = (AtlasStructType) parentType; - boolean isEntityType = (parentType instanceof AtlasEntityType); + if (StringUtils.isNotEmpty(typeName)) { + AtlasType parentType = typeRegistry.getType(typeName); - for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex)); - } + if (parentType instanceof AtlasStructType) { + AtlasStructType structType = (AtlasStructType) parentType; + boolean isEntityType = (parentType instanceof AtlasEntityType); + + for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex)); + } - boolean isOwned = isEntityType && attributeInfo.isOwnedRef(); - AtlasType attrType = attributeInfo.getAttributeType(); - String edgeLabel = attributeInfo.getRelationshipEdgeLabel(); + boolean isOwned = isEntityType && attributeInfo.isOwnedRef(); + AtlasType attrType = attributeInfo.getAttributeType(); + String edgeLabel = attributeInfo.getRelationshipEdgeLabel(); - switch (attrType.getTypeCategory()) { - case OBJECT_ID_TYPE: - //If its class attribute, delete the reference - deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned); - break; + switch (attrType.getTypeCategory()) { + case OBJECT_ID_TYPE: + //If its class attribute, delete the reference + deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned); + break; - case STRUCT: - //If its struct attribute, delete the reference - deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false); - break; + case STRUCT: + //If its struct attribute, delete the reference + deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false); + break; - case ARRAY: - //For array attribute, if the element is struct/class, delete all the references - AtlasArrayType arrType = (AtlasArrayType) attrType; - AtlasType elemType = arrType.getElementType(); + case ARRAY: + //For array attribute, if the element is struct/class, delete all the references + AtlasArrayType arrType = (AtlasArrayType) attrType; + AtlasType elemType = arrType.getElementType(); - if (isReference(elemType.getTypeCategory())) { - List edges = getCollectionElementsUsingRelationship(instanceVertex, attributeInfo); + if (isReference(elemType.getTypeCategory())) { + List edges = getCollectionElementsUsingRelationship(instanceVertex, attributeInfo); - if (CollectionUtils.isNotEmpty(edges)) { - for (AtlasEdge edge : edges) { - deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false, instanceVertex); + if (CollectionUtils.isNotEmpty(edges)) { + for (AtlasEdge edge : edges) { + deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false, instanceVertex); + } } } - } - break; + break; - case MAP: - //For map attribute, if the value type is struct/class, delete all the references - AtlasMapType mapType = (AtlasMapType) attrType; - TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory(); + case MAP: + //For map attribute, if the value type is struct/class, delete all the references + AtlasMapType mapType = (AtlasMapType) attrType; + TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory(); - if (isReference(valueTypeCategory)) { - List edges = getMapValuesUsingRelationship(instanceVertex, attributeInfo); + if (isReference(valueTypeCategory)) { + List edges = getMapValuesUsingRelationship(instanceVertex, attributeInfo); - for (AtlasEdge edge : edges) { - deleteEdgeReference(edge, valueTypeCategory, isOwned, false, instanceVertex); + for (AtlasEdge edge : edges) { + deleteEdgeReference(edge, valueTypeCategory, isOwned, false, instanceVertex); + } } - } - break; + break; - case PRIMITIVE: - // This is different from upstream atlas. - // Here we are not deleting the unique property thus users can only restore after deleting an entity. - if (attributeInfo.getVertexUniquePropertyName() != null && force) { - instanceVertex.removeProperty(attributeInfo.getVertexUniquePropertyName()); - } - break; + case PRIMITIVE: + // This is different from upstream atlas. + // Here we are not deleting the unique property thus users can only restore after deleting an entity. + if (attributeInfo.getVertexUniquePropertyName() != null && force) { + instanceVertex.removeProperty(attributeInfo.getVertexUniquePropertyName()); + } + break; + } } } + } else { + try { + LOG.error("typeName not found for the vertex {}", instanceVertex.getIdForDisplay()); + } catch (Exception e) { + LOG.error("Error while writing error log"); + e.printStackTrace(); + } } deleteVertex(instanceVertex, force);