atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject [2/2] incubator-atlas git commit: ATLAS-1659: fix to update full-text search string when traits/tags are added/removed from entity
Date Sat, 18 Mar 2017 02:10:20 GMT
ATLAS-1659: fix to update full-text search string when traits/tags are added/removed from entity

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/298fdb9d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/298fdb9d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/298fdb9d

Branch: refs/heads/0.8-incubating
Commit: 298fdb9d2e14227676da7448bdb5d54a1a6a1db6
Parents: 31320f7
Author: apoorvnaik <anaik@hortonworks.com>
Authored: Wed Mar 8 14:06:09 2017 -0800
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Fri Mar 17 19:04:01 2017 -0700

----------------------------------------------------------------------
 .../repository/graph/FullTextMapperV2.java      | 57 ++++++++++++++++----
 .../graph/v1/AtlasEntityChangeNotifier.java     | 42 ++++++++++++++-
 2 files changed, 88 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/298fdb9d/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
index e029c39..a60ef9e 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
@@ -54,7 +54,7 @@ public class FullTextMapperV2 {
 
     @Inject
     public FullTextMapperV2(AtlasTypeRegistry typeRegistry) {
-        this.entityGraphRetriever = new EntityGraphRetriever(typeRegistry);
+        entityGraphRetriever = new EntityGraphRetriever(typeRegistry);
 
         Configuration configuration = null;
 
@@ -69,23 +69,42 @@ public class FullTextMapperV2 {
         }
     }
 
-    public String map(String guid) throws AtlasBaseException {
+    /**
+     * Map newly associated/defined classifications for the entity with given GUID
+     * @param guid Entity guid
+     * @param classifications new classifications added to the entity
+     * @return Full text string ONLY for the added classifications
+     * @throws AtlasBaseException
+     */
+    public String getIndexTextForClassifications(String guid, List<AtlasClassification>
classifications) throws AtlasBaseException {
         String                 ret     = null;
-        RequestContext         context = RequestContext.get();
-        AtlasEntityWithExtInfo entity  = context.getInstanceV2(guid);
+        AtlasEntityWithExtInfo entityWithExtInfo  = getAndCacheEntity(guid);
 
-        if (entity == null) {
-            entity = entityGraphRetriever.toAtlasEntityWithExtInfo(guid);
+        if (entityWithExtInfo != null) {
+            StringBuilder sb = new StringBuilder();
 
-            if (entity != null) {
-                context.cache(entity);
+            if (CollectionUtils.isNotEmpty(classifications)) {
+                for (AtlasClassification classification : classifications) {
+                    sb.append(classification.getTypeName()).append(FULL_TEXT_DELIMITER);
 
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Cache miss -> GUID = {}", guid);
+                    mapAttributes(classification.getAttributes(), entityWithExtInfo, sb,
new HashSet<String>());
                 }
             }
+
+            ret = sb.toString();
         }
 
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("FullTextMapperV2.map({}): {}", guid, ret);
+        }
+
+        return ret;
+    }
+
+    public String getIndexTextForEntity(String guid) throws AtlasBaseException {
+        String                 ret     = null;
+        AtlasEntityWithExtInfo entity  = getAndCacheEntity(guid);
+
         if (entity != null) {
             StringBuilder sb = new StringBuilder();
 
@@ -179,4 +198,22 @@ public class FullTextMapperV2 {
             sb.append(String.valueOf(value)).append(FULL_TEXT_DELIMITER);
         }
     }
+
+    private AtlasEntityWithExtInfo getAndCacheEntity(String guid) throws AtlasBaseException
{
+        RequestContext         context = RequestContext.get();
+        AtlasEntityWithExtInfo entityWithExtInfo = context.getInstanceV2(guid);
+
+        if (entityWithExtInfo == null) {
+            entityWithExtInfo = entityGraphRetriever.toAtlasEntityWithExtInfo(guid);
+
+            if (entityWithExtInfo != null) {
+                context.cache(entityWithExtInfo);
+
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Cache miss -> GUID = {}", guid);
+                }
+            }
+        }
+        return entityWithExtInfo;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/298fdb9d/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
index 41674fe..8719cd4 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
@@ -41,6 +41,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
@@ -85,6 +86,10 @@ public class AtlasEntityChangeNotifier {
     }
 
     public void onClassificationAddedToEntity(String entityId, List<AtlasClassification>
classifications) throws AtlasBaseException {
+        // Only new classifications need to be used for a partial full text string which
can be
+        // appended to the existing fullText
+        updateFullTextMapping(entityId, classifications);
+
         ITypedReferenceableInstance entity = toITypedReferenceable(entityId);
         List<ITypedStruct>          traits = toITypedStructs(classifications);
 
@@ -102,6 +107,9 @@ public class AtlasEntityChangeNotifier {
     }
 
     public void onClassificationDeletedFromEntity(String entityId, List<String> traitNames)
throws AtlasBaseException {
+        // Since the entity has already been modified in the graph, we need to recursively
remap the entity
+        doFullTextMapping(entityId);
+
         ITypedReferenceableInstance entity = toITypedReferenceable(entityId);
 
         if (entity == null || CollectionUtils.isEmpty(traitNames)) {
@@ -202,7 +210,7 @@ public class AtlasEntityChangeNotifier {
             }
 
             try {
-                String fullText = fullTextMapperV2.map(guid);
+                String fullText = fullTextMapperV2.getIndexTextForEntity(guid);
 
                 GraphHelper.setProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY,
fullText);
             } catch (AtlasBaseException e) {
@@ -210,4 +218,36 @@ public class AtlasEntityChangeNotifier {
             }
         }
     }
+
+    private void updateFullTextMapping(String entityId, List<AtlasClassification> classifications)
{
+        try {
+            if(!AtlasRepositoryConfiguration.isFullTextSearchEnabled()) {
+                return;
+            }
+        } catch (AtlasException e) {
+            LOG.warn("Unable to determine if FullText is disabled. Proceeding with FullText
mapping");
+        }
+
+        if (StringUtils.isEmpty(entityId) || CollectionUtils.isEmpty(classifications)) {
+            return;
+        }
+        AtlasVertex atlasVertex = AtlasGraphUtilsV1.findByGuid(entityId);
+
+        try {
+            String classificationFullText = fullTextMapperV2.getIndexTextForClassifications(entityId,
classifications);
+            String existingFullText = (String) GraphHelper.getProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY);
+
+            String newFullText = existingFullText + " " + classificationFullText;
+            GraphHelper.setProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, newFullText);
+        } catch (AtlasBaseException e) {
+            LOG.error("FullText mapping failed for Vertex[ guid = {} ]", entityId, e);
+        }
+    }
+
+    private void doFullTextMapping(String guid) {
+        AtlasEntityHeader entityHeader = new AtlasEntityHeader();
+        entityHeader.setGuid(guid);
+
+        doFullTextMapping(Collections.singletonList(entityHeader));
+    }
 }
\ No newline at end of file


Mime
View raw message