Skip to content

Commit

Permalink
Merge pull request #2328 from atlanhq/tag/gov-1311
Browse files Browse the repository at this point in the history
GOV-1311: Update removepropagationOnEntityDelete default as true and remove propagation if updated after archiving asset
  • Loading branch information
sumandas0 authored Sep 6, 2023
2 parents 67e7dfa + 880d0b4 commit b25946f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public final class GraphHelper {

private int maxRetries = 3;
private long retrySleepTimeMillis = 1000;
private boolean removePropagations = false;
private boolean removePropagations = true;

public GraphHelper(AtlasGraph graph) {
this.graph = graph;
try {
maxRetries = ApplicationProperties.get().getInt(RETRY_COUNT, 3);
retrySleepTimeMillis = ApplicationProperties.get().getLong(RETRY_DELAY, 1000);
removePropagations = ApplicationProperties.get().getBoolean(DEFAULT_REMOVE_PROPAGATIONS_ON_ENTITY_DELETE, false);
removePropagations = ApplicationProperties.get().getBoolean(DEFAULT_REMOVE_PROPAGATIONS_ON_ENTITY_DELETE, true);
} catch (AtlasException e) {
LOG.error("Could not load configuration. Setting to default value for " + RETRY_COUNT, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1292,17 +1292,10 @@ private void setBlockedClassificationIds(AtlasEdge edge, List<String> classifica
}
}
}


public void createAndQueueTask(String taskType, AtlasVertex entityVertex, String classificationVertexId, String relationshipGuid, Boolean currentRestrictPropagationThroughLineage) throws AtlasBaseException {
if (!CLASSIFICATION_PROPAGATION_DELETE.equals(taskType) && skipClassificationTaskCreation(classificationVertexId)) {
LOG.info("Task is already scheduled for classification id {}, no need to schedule task for vertex {}", classificationVertexId, entityVertex.getIdForDisplay());
return;
}

public void createAndQueueTaskWithoutCheck(String taskType, AtlasVertex entityVertex, String classificationVertexId, String relationshipGuid) throws AtlasBaseException {
String currentUser = RequestContext.getCurrentUser();
String entityGuid = GraphHelper.getGuid(entityVertex);
Map<String, Object> taskParams = ClassificationTask.toParameters(entityGuid, classificationVertexId, relationshipGuid, currentRestrictPropagationThroughLineage);
Map<String, Object> taskParams = ClassificationTask.toParameters(entityGuid, classificationVertexId, relationshipGuid);
AtlasTask task = taskManagement.createTask(taskType, currentUser, taskParams, classificationVertexId, entityGuid);

AtlasGraphUtilsV2.addEncodedProperty(entityVertex, PENDING_TASKS_PROPERTY_KEY, task.getGuid());
Expand All @@ -1316,9 +1309,13 @@ public void createAndQueueTask(String taskType, AtlasVertex entityVertex, String
return;
}

createAndQueueTaskWithoutCheck(taskType, entityVertex, classificationVertexId, relationshipGuid);
}

public void createAndQueueTaskWithoutCheck(String taskType, AtlasVertex entityVertex, String classificationVertexId, String relationshipGuid, Boolean currentRestrictPropagationThroughLineage) throws AtlasBaseException {
String currentUser = RequestContext.getCurrentUser();
String entityGuid = GraphHelper.getGuid(entityVertex);
Map<String, Object> taskParams = ClassificationTask.toParameters(entityGuid, classificationVertexId, relationshipGuid);
Map<String, Object> taskParams = ClassificationTask.toParameters(entityGuid, classificationVertexId, relationshipGuid, currentRestrictPropagationThroughLineage);
AtlasTask task = taskManagement.createTask(taskType, currentUser, taskParams, classificationVertexId, entityGuid);

AtlasGraphUtilsV2.addEncodedProperty(entityVertex, PENDING_TASKS_PROPERTY_KEY, task.getGuid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@
import static org.apache.atlas.repository.graph.GraphHelper.getPropagatedEdges;
import static org.apache.atlas.repository.graph.GraphHelper.getPropagatableClassifications;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationEntityGuid;
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.AtlasGraphUtilsV2.*;
import static org.apache.atlas.repository.store.graph.v2.tasks.ClassificationPropagateTaskFactory.CLASSIFICATION_PROPAGATION_ADD;
import static org.apache.atlas.repository.store.graph.v2.tasks.ClassificationPropagateTaskFactory.CLASSIFICATION_PROPAGATION_DELETE;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.IN;
Expand Down Expand Up @@ -3178,14 +3177,18 @@ public void updateClassifications(EntityMutationContext context, String guid, Li
isClassificationUpdated = true;
}

boolean removePropagation = false;
// check for removePropagationsOnEntityDelete update
Boolean currentRemovePropagations = currentClassification.getRemovePropagationsOnEntityDelete();
Boolean updatedRemovePropagations = classification.getRemovePropagationsOnEntityDelete();

if (updatedRemovePropagations != null && (updatedRemovePropagations != currentRemovePropagations)) {
if (updatedRemovePropagations != null && !updatedRemovePropagations.equals(currentRemovePropagations)) {
AtlasGraphUtilsV2.setEncodedProperty(classificationVertex, CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, updatedRemovePropagations);

isClassificationUpdated = true;

boolean isEntityDeleted = DELETED.toString().equals(entityVertex.getProperty(STATE_PROPERTY_KEY, String.class));
if (isEntityDeleted && updatedRemovePropagations) {
removePropagation = true;
}
}

if (isClassificationUpdated) {
Expand All @@ -3201,10 +3204,6 @@ public void updateClassifications(EntityMutationContext context, String guid, Li
mapClassification(EntityOperation.UPDATE, context, classification, entityType, entityVertex, classificationVertex);
updateModificationMetadata(entityVertex);

// handle update of 'propagate' flag
Boolean currentTagPropagation = currentClassification.isPropagate();
Boolean updatedTagPropagation = classification.isPropagate();

/* -----------------------------
| Current Tag | Updated Tag |
| Propagation | Propagation |
Expand All @@ -3218,18 +3217,24 @@ public void updateClassifications(EntityMutationContext context, String guid, Li
| true | false | => Remove Tag Propagation (send REMOVE classification notifications)
|-------------|-------------| */

Boolean currentTagPropagation = currentClassification.isPropagate();
Boolean updatedTagPropagation = classification.isPropagate();
Boolean currentRestrictPropagationThroughLineage = currentClassification.getRestrictPropagationThroughLineage();
Boolean updatedRestrictPropagationThroughLineage = classification.getRestrictPropagationThroughLineage();

if (taskManagement != null && DEFERRED_ACTION_ENABLED) {
String propagationType = updatedTagPropagation ? CLASSIFICATION_PROPAGATION_ADD : CLASSIFICATION_PROPAGATION_DELETE;
if ((!Objects.equals(updatedRemovePropagations, currentRemovePropagations) ||
!Objects.equals(currentTagPropagation, updatedTagPropagation) ||
!Objects.equals(currentRestrictPropagationThroughLineage, updatedRestrictPropagationThroughLineage)) &&
taskManagement != null && DEFERRED_ACTION_ENABLED) {

String propagationType = CLASSIFICATION_PROPAGATION_ADD;
if (removePropagation || !updatedTagPropagation)
{
propagationType = CLASSIFICATION_PROPAGATION_DELETE;
}
createAndQueueTask(propagationType, entityVertex, classificationVertex.getIdForDisplay(), currentRestrictPropagationThroughLineage);

updatedTagPropagation = null;
}


// compute propagatedEntityVertices once and use it for subsequent iterations and notifications
if (updatedTagPropagation != null && (currentTagPropagation != updatedTagPropagation || currentRestrictPropagationThroughLineage != updatedRestrictPropagationThroughLineage)) {
if (updatedTagPropagation) {
Expand Down Expand Up @@ -3972,11 +3977,11 @@ private void addToUpdatedBusinessAttributes(Map<String, Map<String, Object>> upd

private void createAndQueueTask(String taskType, AtlasVertex entityVertex, String classificationVertexId, Boolean currentPropagateThroughLineage) throws AtlasBaseException{

deleteDelegate.getHandler().createAndQueueTask(taskType, entityVertex, classificationVertexId, null, currentPropagateThroughLineage);
deleteDelegate.getHandler().createAndQueueTaskWithoutCheck(taskType, entityVertex, classificationVertexId, null, currentPropagateThroughLineage);
}

private void createAndQueueTask(String taskType, AtlasVertex entityVertex, String classificationVertexId) throws AtlasBaseException {
deleteDelegate.getHandler().createAndQueueTask(taskType, entityVertex, classificationVertexId, null);
deleteDelegate.getHandler().createAndQueueTaskWithoutCheck(taskType, entityVertex, classificationVertexId, null);
}

public void removePendingTaskFromEntity(String entityGuid, String taskGuid) throws EntityNotFoundException {
Expand Down

0 comments on commit b25946f

Please sign in to comment.