Commit 801db28b by Sarath Subramanian

ATLAS-2632 Tag Propagation : Tag is added to propagatedClassification twice when…

ATLAS-2632 Tag Propagation : Tag is added to propagatedClassification twice when relationship is updated to BOTH
parent 0eaefe38
...@@ -30,12 +30,13 @@ import javax.xml.bind.annotation.XmlAccessType; ...@@ -30,12 +30,13 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE; import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
...@@ -82,8 +83,8 @@ public class AtlasRelationship extends AtlasStruct implements Serializable { ...@@ -82,8 +83,8 @@ public class AtlasRelationship extends AtlasStruct implements Serializable {
public enum Status { ACTIVE, DELETED } public enum Status { ACTIVE, DELETED }
private List<AtlasClassification> propagatedClassifications; private Set<AtlasClassification> propagatedClassifications;
private List<AtlasClassification> blockedPropagatedClassifications; private Set<AtlasClassification> blockedPropagatedClassifications;
@JsonIgnore @JsonIgnore
private static AtomicLong s_nextId = new AtomicLong(System.nanoTime()); private static AtomicLong s_nextId = new AtomicLong(System.nanoTime());
...@@ -198,7 +199,7 @@ public class AtlasRelationship extends AtlasStruct implements Serializable { ...@@ -198,7 +199,7 @@ public class AtlasRelationship extends AtlasStruct implements Serializable {
} }
if (CollectionUtils.isNotEmpty((List) propagatedClassifications)) { if (CollectionUtils.isNotEmpty((List) propagatedClassifications)) {
this.propagatedClassifications = new ArrayList<>(); this.propagatedClassifications = new HashSet<>();
for (Object elem : (List) propagatedClassifications) { for (Object elem : (List) propagatedClassifications) {
if (elem instanceof AtlasClassification) { if (elem instanceof AtlasClassification) {
...@@ -210,7 +211,7 @@ public class AtlasRelationship extends AtlasStruct implements Serializable { ...@@ -210,7 +211,7 @@ public class AtlasRelationship extends AtlasStruct implements Serializable {
} }
if (CollectionUtils.isNotEmpty((List) blockedPropagatedClassifications)) { if (CollectionUtils.isNotEmpty((List) blockedPropagatedClassifications)) {
this.blockedPropagatedClassifications = new ArrayList<>(); this.blockedPropagatedClassifications = new HashSet<>();
for (Object elem : (List) blockedPropagatedClassifications) { for (Object elem : (List) blockedPropagatedClassifications) {
if (elem instanceof AtlasClassification) { if (elem instanceof AtlasClassification) {
...@@ -308,19 +309,19 @@ public class AtlasRelationship extends AtlasStruct implements Serializable { ...@@ -308,19 +309,19 @@ public class AtlasRelationship extends AtlasStruct implements Serializable {
return "-" + Long.toString(s_nextId.getAndIncrement()); return "-" + Long.toString(s_nextId.getAndIncrement());
} }
public List<AtlasClassification> getPropagatedClassifications() { public Set<AtlasClassification> getPropagatedClassifications() {
return propagatedClassifications; return propagatedClassifications;
} }
public void setPropagatedClassifications(List<AtlasClassification> propagatedClassifications) { public void setPropagatedClassifications(Set<AtlasClassification> propagatedClassifications) {
this.propagatedClassifications = propagatedClassifications; this.propagatedClassifications = propagatedClassifications;
} }
public List<AtlasClassification> getBlockedPropagatedClassifications() { public Set<AtlasClassification> getBlockedPropagatedClassifications() {
return blockedPropagatedClassifications; return blockedPropagatedClassifications;
} }
public void setBlockedPropagatedClassifications(List<AtlasClassification> blockedPropagatedClassifications) { public void setBlockedPropagatedClassifications(Set<AtlasClassification> blockedPropagatedClassifications) {
this.blockedPropagatedClassifications = blockedPropagatedClassifications; this.blockedPropagatedClassifications = blockedPropagatedClassifications;
} }
...@@ -330,7 +331,7 @@ public class AtlasRelationship extends AtlasStruct implements Serializable { ...@@ -330,7 +331,7 @@ public class AtlasRelationship extends AtlasStruct implements Serializable {
private void init(String guid, AtlasObjectId end1, AtlasObjectId end2, String label, PropagateTags propagateTags, private void init(String guid, AtlasObjectId end1, AtlasObjectId end2, String label, PropagateTags propagateTags,
Status status, String createdBy, String updatedBy, Date createTime, Date updateTime, Long version, Status status, String createdBy, String updatedBy, Date createTime, Date updateTime, Long version,
List<AtlasClassification> propagatedClassifications, List<AtlasClassification> blockedPropagatedClassifications) { Set<AtlasClassification> propagatedClassifications, Set<AtlasClassification> blockedPropagatedClassifications) {
setGuid(guid); setGuid(guid);
setEnd1(end1); setEnd1(end1);
setEnd2(end2); setEnd2(end2);
......
...@@ -357,7 +357,7 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore { ...@@ -357,7 +357,7 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
return entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge); return entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge);
} }
private void handleBlockedClassifications(AtlasEdge edge, List<AtlasClassification> blockedPropagatedClassifications) throws AtlasBaseException { private void handleBlockedClassifications(AtlasEdge edge, Set<AtlasClassification> blockedPropagatedClassifications) throws AtlasBaseException {
if (blockedPropagatedClassifications != null) { if (blockedPropagatedClassifications != null) {
List<AtlasVertex> propagatedClassificationVertices = getClassificationVertices(edge); List<AtlasVertex> propagatedClassificationVertices = getClassificationVertices(edge);
List<String> currentClassificationIds = getBlockedClassificationIds(edge); List<String> currentClassificationIds = getBlockedClassificationIds(edge);
......
...@@ -65,6 +65,7 @@ import java.util.ArrayList; ...@@ -65,6 +65,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -1042,11 +1043,11 @@ public final class EntityGraphRetriever { ...@@ -1042,11 +1043,11 @@ public final class EntityGraphRetriever {
} }
private void readClassificationsFromEdge(AtlasEdge edge, AtlasRelationshipWithExtInfo relationshipWithExtInfo, boolean extendedInfo) throws AtlasBaseException { private void readClassificationsFromEdge(AtlasEdge edge, AtlasRelationshipWithExtInfo relationshipWithExtInfo, boolean extendedInfo) throws AtlasBaseException {
List<AtlasVertex> classificationVertices = getClassificationVertices(edge); List<AtlasVertex> classificationVertices = getClassificationVertices(edge);
List<String> blockedClassificationIds = getBlockedClassificationIds(edge); List<String> blockedClassificationIds = getBlockedClassificationIds(edge);
List<AtlasClassification> propagatedClassifications = new ArrayList<>(); AtlasRelationship relationship = relationshipWithExtInfo.getRelationship();
List<AtlasClassification> blockedClassifications = new ArrayList<>(); Set<AtlasClassification> propagatedClassifications = new HashSet<>();
AtlasRelationship relationship = relationshipWithExtInfo.getRelationship(); Set<AtlasClassification> blockedClassifications = new HashSet<>();
for (AtlasVertex classificationVertex : classificationVertices) { for (AtlasVertex classificationVertex : classificationVertices) {
String classificationId = classificationVertex.getIdForDisplay(); String classificationId = classificationVertex.getIdForDisplay();
......
...@@ -52,6 +52,7 @@ import java.io.IOException; ...@@ -52,6 +52,7 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -350,8 +351,8 @@ public class ClassificationPropagationTest { ...@@ -350,8 +351,8 @@ public class ClassificationPropagationTest {
assertClassificationExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag3.getTypeName(), employees2.getGuid()); assertClassificationExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag3.getTypeName(), employees2.getGuid());
AtlasRelationship process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); AtlasRelationship process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
List<AtlasClassification> propagatedClassifications = process3_employee_union_relationship.getPropagatedClassifications(); Set<AtlasClassification> propagatedClassifications = process3_employee_union_relationship.getPropagatedClassifications();
List<AtlasClassification> blockedClassifications = process3_employee_union_relationship.getBlockedPropagatedClassifications(); Set<AtlasClassification> blockedClassifications = process3_employee_union_relationship.getBlockedPropagatedClassifications();
assertNotNull(propagatedClassifications); assertNotNull(propagatedClassifications);
assertClassificationEquals(propagatedClassifications, PII_tag1); assertClassificationEquals(propagatedClassifications, PII_tag1);
...@@ -363,7 +364,7 @@ public class ClassificationPropagationTest { ...@@ -363,7 +364,7 @@ public class ClassificationPropagationTest {
PII_tag2.setEntityGuid(employees1.getGuid()); PII_tag2.setEntityGuid(employees1.getGuid());
PII_tag3.setEntityGuid(employees2.getGuid()); PII_tag3.setEntityGuid(employees2.getGuid());
process3_employee_union_relationship.setBlockedPropagatedClassifications(Arrays.asList(PII_tag2, PII_tag3)); process3_employee_union_relationship.setBlockedPropagatedClassifications(new HashSet<>(Arrays.asList(PII_tag2, PII_tag3)));
relationshipStore.update(process3_employee_union_relationship); relationshipStore.update(process3_employee_union_relationship);
process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
...@@ -383,7 +384,7 @@ public class ClassificationPropagationTest { ...@@ -383,7 +384,7 @@ public class ClassificationPropagationTest {
assertClassificationExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag1.getTypeName(), hdfs_path.getGuid()); assertClassificationExistInEntity(EMPLOYEES_UNION_TABLE, PII_tag1.getTypeName(), hdfs_path.getGuid());
} }
private void assertClassificationEquals(List<AtlasClassification> propagatedClassifications, AtlasClassification expected) { private void assertClassificationEquals(Set<AtlasClassification> propagatedClassifications, AtlasClassification expected) {
String expectedTypeName = expected.getTypeName(); String expectedTypeName = expected.getTypeName();
for (AtlasClassification c : propagatedClassifications) { for (AtlasClassification c : propagatedClassifications) {
if(c.getTypeName().equals(expectedTypeName)) { if(c.getTypeName().equals(expectedTypeName)) {
...@@ -417,19 +418,19 @@ public class ClassificationPropagationTest { ...@@ -417,19 +418,19 @@ public class ClassificationPropagationTest {
AtlasRelationship process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); AtlasRelationship process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
// remove blocked propagated classification entry for PII (from employees2) - allow PII from employees2 to propagate to employee_union // remove blocked propagated classification entry for PII (from employees2) - allow PII from employees2 to propagate to employee_union
process3_employee_union_relationship.setBlockedPropagatedClassifications(Arrays.asList(PII_tag3)); process3_employee_union_relationship.setBlockedPropagatedClassifications(new HashSet<>(Arrays.asList(PII_tag3)));
relationshipStore.update(process3_employee_union_relationship); relationshipStore.update(process3_employee_union_relationship);
process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
List<AtlasClassification> propagatedClassifications = process3_employee_union_relationship.getPropagatedClassifications(); Set<AtlasClassification> propagatedClassifications = process3_employee_union_relationship.getPropagatedClassifications();
List<AtlasClassification> blockedClassifications = process3_employee_union_relationship.getBlockedPropagatedClassifications(); Set<AtlasClassification> blockedClassifications = process3_employee_union_relationship.getBlockedPropagatedClassifications();
assertClassificationExistInList(propagatedClassifications, PII_tag1); assertClassificationExistInList(propagatedClassifications, PII_tag1);
assertClassificationExistInList(propagatedClassifications, PII_tag2); assertClassificationExistInList(propagatedClassifications, PII_tag2);
assertClassificationExistInList(blockedClassifications, PII_tag3); assertClassificationExistInList(blockedClassifications, PII_tag3);
// remove all blocked propagated classification entry // remove all blocked propagated classification entry
process3_employee_union_relationship.setBlockedPropagatedClassifications(Collections.emptyList()); process3_employee_union_relationship.setBlockedPropagatedClassifications(Collections.emptySet());
relationshipStore.update(process3_employee_union_relationship); relationshipStore.update(process3_employee_union_relationship);
process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE); process3_employee_union_relationship = getRelationship(EMPLOYEES_UNION_PROCESS, EMPLOYEES_UNION_TABLE);
...@@ -442,7 +443,7 @@ public class ClassificationPropagationTest { ...@@ -442,7 +443,7 @@ public class ClassificationPropagationTest {
assertTrue(blockedClassifications.isEmpty()); assertTrue(blockedClassifications.isEmpty());
} }
private void assertClassificationExistInList(List<AtlasClassification> classifications, AtlasClassification classification) { private void assertClassificationExistInList(Set<AtlasClassification> classifications, AtlasClassification classification) {
String classificationName = classification.getTypeName(); String classificationName = classification.getTypeName();
String entityGuid = classification.getEntityGuid(); String entityGuid = classification.getEntityGuid();
boolean foundClassification = false; boolean foundClassification = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment