Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Beta with Master #2353

Merged
merged 6 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -49,7 +49,7 @@
import static org.apache.atlas.repository.Constants.TRAIT_NAMES_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.VERTEX_INDEX_NAME;
import static org.apache.atlas.repository.util.AccessControlUtils.ACCESS_READ_PERSONA_METADATA;
import static org.apache.atlas.repository.util.AccessControlUtils.ACCESS_READ_PURPOSE_GLOSSARY;
import static org.apache.atlas.repository.util.AccessControlUtils.ACCESS_READ_PERSONA_GLOSSARY;
import static org.apache.atlas.repository.util.AccessControlUtils.getConnectionQualifiedNameFromPolicyAssets;
import static org.apache.atlas.repository.util.AccessControlUtils.getESAliasName;
import static org.apache.atlas.repository.util.AccessControlUtils.getIsAllowPolicy;
Expand Down Expand Up @@ -183,9 +183,9 @@ private void personaPolicyToESDslClauses(List<AtlasEntity> policies,

addPersonaMetadataFilterConnectionClause(connectionQName, allowClauseList);

} else if (getPolicyActions(policy).contains(ACCESS_READ_PURPOSE_GLOSSARY)) {
} else if (getPolicyActions(policy).contains(ACCESS_READ_PERSONA_GLOSSARY)) {
for (String glossaryQName : assets) {
addPersonaMetadataFilterClauses(glossaryQName, allowClauseList);
addPersonaGlossaryFilterClauses(glossaryQName, allowClauseList);
}
}
}
Expand All @@ -209,19 +209,21 @@ private String getAliasName(AtlasEntity entity) {
}

private void addPersonaMetadataFilterClauses(String asset, List<Map<String, Object>> clauseList) {
addPersonaFilterClauses(asset, clauseList);
}

private void addPersonaMetadataFilterConnectionClause(String connection, List<Map<String, Object>> clauseList) {
clauseList.add(mapOf("term", mapOf(QUALIFIED_NAME, connection)));
clauseList.add(mapOf("term", mapOf(QUALIFIED_NAME, asset)));
clauseList.add(mapOf("wildcard", mapOf(QUALIFIED_NAME, asset + "/*")));
clauseList.add(mapOf("wildcard", mapOf(QUALIFIED_NAME, asset)));
}

private void addPersonaFilterClauses(String asset, List<Map<String, Object>> clauseList) {
private void addPersonaGlossaryFilterClauses(String asset, List<Map<String, Object>> clauseList) {
clauseList.add(mapOf("term", mapOf(QUALIFIED_NAME, asset)));
clauseList.add(mapOf("wildcard", mapOf(QUALIFIED_NAME, asset + "/*")));
clauseList.add(mapOf("wildcard", mapOf(QUALIFIED_NAME, "*@" + asset)));
}

private void addPersonaMetadataFilterConnectionClause(String connection, List<Map<String, Object>> clauseList) {
clauseList.add(mapOf("term", mapOf(QUALIFIED_NAME, connection)));
}

private void addPurposeMetadataFilterClauses(List<String> tags, List<Map<String, Object>> clauseList) {
clauseList.add(mapOf("terms", mapOf(TRAIT_NAMES_PROPERTY_KEY, tags)));
clauseList.add(mapOf("terms", mapOf(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, tags)));
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public final class AccessControlUtils {

public static final String ACCESS_READ_PURPOSE_METADATA = "entity-read";
public static final String ACCESS_READ_PERSONA_METADATA = "persona-asset-read";
public static final String ACCESS_READ_PURPOSE_GLOSSARY = "persona-glossary-read";
public static final String ACCESS_READ_PERSONA_GLOSSARY = "persona-glossary-read";

public static final String POLICY_CATEGORY_PERSONA = "persona";
public static final String POLICY_CATEGORY_PURPOSE = "purpose";
Expand Down
Loading