Repository: atlas
Updated Branches:
  refs/heads/master 18350777e -> 5ebb16901


ATLAS-2982: import fails to create classification-def


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

Branch: refs/heads/master
Commit: 5ebb16901040c22a717de29f962ca53941ba4078
Parents: 1835077
Author: Madhan Neethiraj <mad...@apache.org>
Authored: Wed Nov 28 08:15:21 2018 -0800
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Wed Nov 28 21:01:24 2018 -0800

----------------------------------------------------------------------
 .../atlas/authorize/AtlasAuthorizationUtils.java       |  6 +++---
 .../apache/atlas/repository/impexp/ImportService.java  |  3 +++
 .../repository/store/graph/v2/AtlasEntityStoreV2.java  | 13 ++++++-------
 .../repository/store/graph/v2/EntityGraphMapper.java   | 10 +++++-----
 .../store/graph/v2/EntityMutationContext.java          |  4 ----
 .../store/graph/v2/IDBasedEntityResolver.java          |  5 +++--
 .../src/main/java/org/apache/atlas/RequestContext.java |  8 ++++++++
 7 files changed, 28 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/5ebb1690/authorization/src/main/java/org/apache/atlas/authorize/AtlasAuthorizationUtils.java
----------------------------------------------------------------------
diff --git 
a/authorization/src/main/java/org/apache/atlas/authorize/AtlasAuthorizationUtils.java
 
b/authorization/src/main/java/org/apache/atlas/authorize/AtlasAuthorizationUtils.java
index 3f5bd24..c59b186 100644
--- 
a/authorization/src/main/java/org/apache/atlas/authorize/AtlasAuthorizationUtils.java
+++ 
b/authorization/src/main/java/org/apache/atlas/authorize/AtlasAuthorizationUtils.java
@@ -111,7 +111,7 @@ public class AtlasAuthorizationUtils {
         boolean ret      = false;
         String  userName = getCurrentUserName();
 
-        if (StringUtils.isNotEmpty(userName)) {
+        if (StringUtils.isNotEmpty(userName) && 
!RequestContext.get().isImportInProgress()) {
             try {
                 AtlasAuthorizer authorizer = 
AtlasAuthorizerFactory.getAtlasAuthorizer();
 
@@ -132,7 +132,7 @@ public class AtlasAuthorizationUtils {
         boolean ret      = false;
         String  userName = getCurrentUserName();
 
-        if (StringUtils.isNotEmpty(userName)) {
+        if (StringUtils.isNotEmpty(userName) && 
!RequestContext.get().isImportInProgress()) {
             try {
                 AtlasAuthorizer authorizer = 
AtlasAuthorizerFactory.getAtlasAuthorizer();
 
@@ -153,7 +153,7 @@ public class AtlasAuthorizationUtils {
         boolean ret      = false;
         String  userName = getCurrentUserName();
 
-        if (StringUtils.isNotEmpty(userName)) {
+        if (StringUtils.isNotEmpty(userName) && 
!RequestContext.get().isImportInProgress()) {
             try {
                 AtlasAuthorizer authorizer = 
AtlasAuthorizerFactory.getAtlasAuthorizer();
 

http://git-wip-us.apache.org/repos/asf/atlas/blob/5ebb1690/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
 
b/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
index b5d8b7c..d06fd4a 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
@@ -19,6 +19,7 @@ package org.apache.atlas.repository.impexp;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.apache.atlas.AtlasErrorCode;
+import org.apache.atlas.RequestContext;
 import org.apache.atlas.entitytransform.BaseEntityHandler;
 import org.apache.atlas.entitytransform.TransformerContext;
 import org.apache.atlas.exception.AtlasBaseException;
@@ -79,6 +80,8 @@ public class ImportService {
 
     public AtlasImportResult run(ZipSource source, AtlasImportRequest request, 
String userName,
                                  String hostName, String requestingIP) throws 
AtlasBaseException {
+        RequestContext.get().setImportInProgress(true);
+
         if (request == null) {
             request = new AtlasImportRequest();
         }

http://git-wip-us.apache.org/repos/asf/atlas/blob/5ebb1690/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
index 6ee0279..d97b74d 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
@@ -672,11 +672,10 @@ public class AtlasEntityStoreV2 implements 
AtlasEntityStore {
         }
 
         try {
-            final boolean               isImport = entityStream instanceof 
EntityImportStream;
-            final EntityMutationContext context  = 
preCreateOrUpdate(entityStream, entityGraphMapper, isPartialUpdate);
+            final EntityMutationContext context = 
preCreateOrUpdate(entityStream, entityGraphMapper, isPartialUpdate);
 
             // Check if authorized to create entities
-            if (!isImport && 
CollectionUtils.isNotEmpty(context.getCreatedEntities())) {
+            if (!RequestContext.get().isImportInProgress()) {
                 for (AtlasEntity entity : context.getCreatedEntities()) {
                     AtlasAuthorizationUtils.verifyAccess(new 
AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new 
AtlasEntityHeader(entity)),
                                                          "create entity: 
type=", entity.getTypeName());
@@ -710,7 +709,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore 
{
                 }
 
                 // Check if authorized to update entities
-                if (!isImport) {
+                if (!RequestContext.get().isImportInProgress()) {
                     for (AtlasEntity entity : context.getUpdatedEntities()) {
                         AtlasAuthorizationUtils.verifyAccess(new 
AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, new 
AtlasEntityHeader(entity)),
                                                              "update entity: 
type=", entity.getTypeName());
@@ -723,7 +722,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore 
{
             ret.setGuidAssignments(context.getGuidAssignments());
 
             // Notify the change listeners
-            entityChangeNotifier.onEntitiesMutated(ret, isImport);
+            entityChangeNotifier.onEntitiesMutated(ret, 
RequestContext.get().isImportInProgress());
 
             if (LOG.isDebugEnabled()) {
                 LOG.debug("<== createOrUpdate()");
@@ -772,7 +771,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore 
{
 
 
                     //Create vertices which do not exist in the repository
-                    if ((entityStream instanceof EntityImportStream) && 
AtlasTypeUtil.isAssignedGuid(entity.getGuid())) {
+                    if (RequestContext.get().isImportInProgress() && 
AtlasTypeUtil.isAssignedGuid(entity.getGuid())) {
                         vertex = 
entityGraphMapper.createVertexWithGuid(entity, entity.getGuid());
                     } else {
                          vertex = entityGraphMapper.createVertex(entity);
@@ -792,7 +791,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore 
{
                 }
 
                 // during import, update the system attributes
-                if (entityStream instanceof EntityImportStream) {
+                if (RequestContext.get().isImportInProgress()) {
                     entityGraphMapper.updateSystemAttributes(vertex, entity);
                 }
             }

http://git-wip-us.apache.org/repos/asf/atlas/blob/5ebb1690/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
index f5a5982..6c830ba 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
@@ -416,7 +416,7 @@ public class EntityGraphMapper {
                 AtlasEdge currentEdge;
 
                 // if relationshipGuid is assigned in AtlasRelatedObjectId use 
it to fetch existing AtlasEdge
-                if (StringUtils.isNotEmpty(relationshipGuid) && 
!context.isImport()) {
+                if (StringUtils.isNotEmpty(relationshipGuid) && 
!RequestContext.get().isImportInProgress()) {
                     currentEdge = graphHelper.getEdgeForGUID(relationshipGuid);
                 } else {
                     currentEdge = 
graphHelper.getEdgeForLabel(ctx.getReferringVertex(), edgeLabel, edgeDirection);
@@ -611,7 +611,7 @@ public class EntityGraphMapper {
     }
 
     private void updateRelationshipGuidForImport(EntityMutationContext 
context, String inverseAttributeName, AtlasVertex inverseVertex, AtlasEdge 
edge) throws AtlasBaseException {
-        if (!context.isImport()) {
+        if (!RequestContext.get().isImportInProgress()) {
             return;
         }
 
@@ -795,7 +795,7 @@ public class EntityGraphMapper {
         }
 
         if (attributeVertex == null) {
-            if(context.isImport()) {
+            if(RequestContext.get().isImportInProgress()) {
                 return null;
             }
 
@@ -836,7 +836,7 @@ public class EntityGraphMapper {
                     ret = getOrCreateRelationship(fromVertex, toVertex, 
relationshipName, relationshipAttributes);
 
                     // for import use the relationship guid provided
-                    if (context.isImport()) {
+                    if (RequestContext.get().isImportInProgress()) {
                         String relationshipGuid = 
getRelationshipGuid(ctx.getValue());
 
                         if(!StringUtils.isEmpty(relationshipGuid)) {
@@ -1384,7 +1384,7 @@ public class EntityGraphMapper {
                 }
 
                 if (propagateTags == null) {
-                    if(context.isImport()) {
+                    if(RequestContext.get().isImportInProgress()) {
                         propagateTags = false;
                         classification.setPropagate(propagateTags);
                     } else {

http://git-wip-us.apache.org/repos/asf/atlas/blob/5ebb1690/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityMutationContext.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityMutationContext.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityMutationContext.java
index f5dc117..453dbe6 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityMutationContext.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityMutationContext.java
@@ -87,10 +87,6 @@ public class EntityMutationContext {
 
     public AtlasVertex getVertex(String guid) { return 
entityVsVertex.get(guid); }
 
-    public boolean isImport() {
-        return (context != null) && context.getEntityStream() instanceof 
EntityImportStream;
-    }
-
     @Override
     public boolean equals(final Object o) {
         if (this == o) return true;

http://git-wip-us.apache.org/repos/asf/atlas/blob/5ebb1690/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/IDBasedEntityResolver.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/IDBasedEntityResolver.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/IDBasedEntityResolver.java
index 0fcdf94..fe76b3a 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/IDBasedEntityResolver.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/IDBasedEntityResolver.java
@@ -18,6 +18,7 @@
 package org.apache.atlas.repository.store.graph.v2;
 
 import org.apache.atlas.AtlasErrorCode;
+import org.apache.atlas.RequestContext;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.TypeCategory;
 import org.apache.atlas.model.instance.AtlasEntity;
@@ -51,7 +52,7 @@ public class IDBasedEntityResolver implements EntityResolver {
             boolean isAssignedGuid = AtlasTypeUtil.isAssignedGuid(guid);
             AtlasVertex vertex = isAssignedGuid ? 
AtlasGraphUtilsV2.findByGuid(guid) : null;
 
-            if (vertex == null && !(entityStream instanceof 
EntityImportStream)) { // if not found in the store, look if the entity is 
present in the stream
+            if (vertex == null && !RequestContext.get().isImportInProgress()) 
{ // if not found in the store, look if the entity is present in the stream
                 AtlasEntity entity = entityStream.getByGuid(guid);
 
                 if (entity != null) { // look for the entity in the store 
using unique-attributes
@@ -70,7 +71,7 @@ public class IDBasedEntityResolver implements EntityResolver {
             if (vertex != null) {
                 context.addResolvedGuid(guid, vertex);
             } else {
-                if (isAssignedGuid && !(entityStream instanceof 
EntityImportStream)) {
+                if (isAssignedGuid && 
!RequestContext.get().isImportInProgress()) {
                     throw new 
AtlasBaseException(AtlasErrorCode.REFERENCED_ENTITY_NOT_FOUND, guid);
                 } else {
                     context.addLocalGuidReference(guid);

http://git-wip-us.apache.org/repos/asf/atlas/blob/5ebb1690/server-api/src/main/java/org/apache/atlas/RequestContext.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/java/org/apache/atlas/RequestContext.java 
b/server-api/src/main/java/org/apache/atlas/RequestContext.java
index b49591d..099d713 100644
--- a/server-api/src/main/java/org/apache/atlas/RequestContext.java
+++ b/server-api/src/main/java/org/apache/atlas/RequestContext.java
@@ -50,6 +50,7 @@ public class RequestContext {
     private DeleteType  deleteType   = DeleteType.DEFAULT;
     private int         maxAttempts  = 1;
     private int         attemptCount = 1;
+    private boolean     isImportInProgress = false;
 
 
     private RequestContext() {
@@ -145,6 +146,13 @@ public class RequestContext {
         this.attemptCount = attemptCount;
     }
 
+    public boolean isImportInProgress() {
+        return isImportInProgress;
+    }
+
+    public void setImportInProgress(boolean importInProgress) {
+        isImportInProgress = importInProgress;
+    }
 
     public void recordEntityUpdate(AtlasObjectId entity) {
         if (entity != null && entity.getGuid() != null) {

Reply via email to