Commit 5ebb1690 by Madhan Neethiraj

ATLAS-2982: import fails to create classification-def

parent 18350777
...@@ -111,7 +111,7 @@ public class AtlasAuthorizationUtils { ...@@ -111,7 +111,7 @@ public class AtlasAuthorizationUtils {
boolean ret = false; boolean ret = false;
String userName = getCurrentUserName(); String userName = getCurrentUserName();
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName) && !RequestContext.get().isImportInProgress()) {
try { try {
AtlasAuthorizer authorizer = AtlasAuthorizerFactory.getAtlasAuthorizer(); AtlasAuthorizer authorizer = AtlasAuthorizerFactory.getAtlasAuthorizer();
...@@ -132,7 +132,7 @@ public class AtlasAuthorizationUtils { ...@@ -132,7 +132,7 @@ public class AtlasAuthorizationUtils {
boolean ret = false; boolean ret = false;
String userName = getCurrentUserName(); String userName = getCurrentUserName();
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName) && !RequestContext.get().isImportInProgress()) {
try { try {
AtlasAuthorizer authorizer = AtlasAuthorizerFactory.getAtlasAuthorizer(); AtlasAuthorizer authorizer = AtlasAuthorizerFactory.getAtlasAuthorizer();
...@@ -153,7 +153,7 @@ public class AtlasAuthorizationUtils { ...@@ -153,7 +153,7 @@ public class AtlasAuthorizationUtils {
boolean ret = false; boolean ret = false;
String userName = getCurrentUserName(); String userName = getCurrentUserName();
if (StringUtils.isNotEmpty(userName)) { if (StringUtils.isNotEmpty(userName) && !RequestContext.get().isImportInProgress()) {
try { try {
AtlasAuthorizer authorizer = AtlasAuthorizerFactory.getAtlasAuthorizer(); AtlasAuthorizer authorizer = AtlasAuthorizerFactory.getAtlasAuthorizer();
......
...@@ -19,6 +19,7 @@ package org.apache.atlas.repository.impexp; ...@@ -19,6 +19,7 @@ package org.apache.atlas.repository.impexp;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.RequestContext;
import org.apache.atlas.entitytransform.BaseEntityHandler; import org.apache.atlas.entitytransform.BaseEntityHandler;
import org.apache.atlas.entitytransform.TransformerContext; import org.apache.atlas.entitytransform.TransformerContext;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
...@@ -79,6 +80,8 @@ public class ImportService { ...@@ -79,6 +80,8 @@ public class ImportService {
public AtlasImportResult run(ZipSource source, AtlasImportRequest request, String userName, public AtlasImportResult run(ZipSource source, AtlasImportRequest request, String userName,
String hostName, String requestingIP) throws AtlasBaseException { String hostName, String requestingIP) throws AtlasBaseException {
RequestContext.get().setImportInProgress(true);
if (request == null) { if (request == null) {
request = new AtlasImportRequest(); request = new AtlasImportRequest();
} }
......
...@@ -672,11 +672,10 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -672,11 +672,10 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
} }
try { 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 // Check if authorized to create entities
if (!isImport && CollectionUtils.isNotEmpty(context.getCreatedEntities())) { if (!RequestContext.get().isImportInProgress()) {
for (AtlasEntity entity : context.getCreatedEntities()) { for (AtlasEntity entity : context.getCreatedEntities()) {
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new AtlasEntityHeader(entity)), AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new AtlasEntityHeader(entity)),
"create entity: type=", entity.getTypeName()); "create entity: type=", entity.getTypeName());
...@@ -710,7 +709,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -710,7 +709,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
} }
// Check if authorized to update entities // Check if authorized to update entities
if (!isImport) { if (!RequestContext.get().isImportInProgress()) {
for (AtlasEntity entity : context.getUpdatedEntities()) { for (AtlasEntity entity : context.getUpdatedEntities()) {
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, new AtlasEntityHeader(entity)), AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, new AtlasEntityHeader(entity)),
"update entity: type=", entity.getTypeName()); "update entity: type=", entity.getTypeName());
...@@ -723,7 +722,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -723,7 +722,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
ret.setGuidAssignments(context.getGuidAssignments()); ret.setGuidAssignments(context.getGuidAssignments());
// Notify the change listeners // Notify the change listeners
entityChangeNotifier.onEntitiesMutated(ret, isImport); entityChangeNotifier.onEntitiesMutated(ret, RequestContext.get().isImportInProgress());
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== createOrUpdate()"); LOG.debug("<== createOrUpdate()");
...@@ -772,7 +771,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -772,7 +771,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
//Create vertices which do not exist in the repository //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()); vertex = entityGraphMapper.createVertexWithGuid(entity, entity.getGuid());
} else { } else {
vertex = entityGraphMapper.createVertex(entity); vertex = entityGraphMapper.createVertex(entity);
...@@ -792,7 +791,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -792,7 +791,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
} }
// during import, update the system attributes // during import, update the system attributes
if (entityStream instanceof EntityImportStream) { if (RequestContext.get().isImportInProgress()) {
entityGraphMapper.updateSystemAttributes(vertex, entity); entityGraphMapper.updateSystemAttributes(vertex, entity);
} }
} }
......
...@@ -416,7 +416,7 @@ public class EntityGraphMapper { ...@@ -416,7 +416,7 @@ public class EntityGraphMapper {
AtlasEdge currentEdge; AtlasEdge currentEdge;
// if relationshipGuid is assigned in AtlasRelatedObjectId use it to fetch existing AtlasEdge // 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); currentEdge = graphHelper.getEdgeForGUID(relationshipGuid);
} else { } else {
currentEdge = graphHelper.getEdgeForLabel(ctx.getReferringVertex(), edgeLabel, edgeDirection); currentEdge = graphHelper.getEdgeForLabel(ctx.getReferringVertex(), edgeLabel, edgeDirection);
...@@ -611,7 +611,7 @@ public class EntityGraphMapper { ...@@ -611,7 +611,7 @@ public class EntityGraphMapper {
} }
private void updateRelationshipGuidForImport(EntityMutationContext context, String inverseAttributeName, AtlasVertex inverseVertex, AtlasEdge edge) throws AtlasBaseException { private void updateRelationshipGuidForImport(EntityMutationContext context, String inverseAttributeName, AtlasVertex inverseVertex, AtlasEdge edge) throws AtlasBaseException {
if (!context.isImport()) { if (!RequestContext.get().isImportInProgress()) {
return; return;
} }
...@@ -795,7 +795,7 @@ public class EntityGraphMapper { ...@@ -795,7 +795,7 @@ public class EntityGraphMapper {
} }
if (attributeVertex == null) { if (attributeVertex == null) {
if(context.isImport()) { if(RequestContext.get().isImportInProgress()) {
return null; return null;
} }
...@@ -836,7 +836,7 @@ public class EntityGraphMapper { ...@@ -836,7 +836,7 @@ public class EntityGraphMapper {
ret = getOrCreateRelationship(fromVertex, toVertex, relationshipName, relationshipAttributes); ret = getOrCreateRelationship(fromVertex, toVertex, relationshipName, relationshipAttributes);
// for import use the relationship guid provided // for import use the relationship guid provided
if (context.isImport()) { if (RequestContext.get().isImportInProgress()) {
String relationshipGuid = getRelationshipGuid(ctx.getValue()); String relationshipGuid = getRelationshipGuid(ctx.getValue());
if(!StringUtils.isEmpty(relationshipGuid)) { if(!StringUtils.isEmpty(relationshipGuid)) {
...@@ -1384,7 +1384,7 @@ public class EntityGraphMapper { ...@@ -1384,7 +1384,7 @@ public class EntityGraphMapper {
} }
if (propagateTags == null) { if (propagateTags == null) {
if(context.isImport()) { if(RequestContext.get().isImportInProgress()) {
propagateTags = false; propagateTags = false;
classification.setPropagate(propagateTags); classification.setPropagate(propagateTags);
} else { } else {
......
...@@ -87,10 +87,6 @@ public class EntityMutationContext { ...@@ -87,10 +87,6 @@ public class EntityMutationContext {
public AtlasVertex getVertex(String guid) { return entityVsVertex.get(guid); } public AtlasVertex getVertex(String guid) { return entityVsVertex.get(guid); }
public boolean isImport() {
return (context != null) && context.getEntityStream() instanceof EntityImportStream;
}
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (this == o) return true; if (this == o) return true;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.atlas.repository.store.graph.v2; package org.apache.atlas.repository.store.graph.v2;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.RequestContext;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory; import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
...@@ -51,7 +52,7 @@ public class IDBasedEntityResolver implements EntityResolver { ...@@ -51,7 +52,7 @@ public class IDBasedEntityResolver implements EntityResolver {
boolean isAssignedGuid = AtlasTypeUtil.isAssignedGuid(guid); boolean isAssignedGuid = AtlasTypeUtil.isAssignedGuid(guid);
AtlasVertex vertex = isAssignedGuid ? AtlasGraphUtilsV2.findByGuid(guid) : null; 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); AtlasEntity entity = entityStream.getByGuid(guid);
if (entity != null) { // look for the entity in the store using unique-attributes if (entity != null) { // look for the entity in the store using unique-attributes
...@@ -70,7 +71,7 @@ public class IDBasedEntityResolver implements EntityResolver { ...@@ -70,7 +71,7 @@ public class IDBasedEntityResolver implements EntityResolver {
if (vertex != null) { if (vertex != null) {
context.addResolvedGuid(guid, vertex); context.addResolvedGuid(guid, vertex);
} else { } else {
if (isAssignedGuid && !(entityStream instanceof EntityImportStream)) { if (isAssignedGuid && !RequestContext.get().isImportInProgress()) {
throw new AtlasBaseException(AtlasErrorCode.REFERENCED_ENTITY_NOT_FOUND, guid); throw new AtlasBaseException(AtlasErrorCode.REFERENCED_ENTITY_NOT_FOUND, guid);
} else { } else {
context.addLocalGuidReference(guid); context.addLocalGuidReference(guid);
......
...@@ -50,6 +50,7 @@ public class RequestContext { ...@@ -50,6 +50,7 @@ public class RequestContext {
private DeleteType deleteType = DeleteType.DEFAULT; private DeleteType deleteType = DeleteType.DEFAULT;
private int maxAttempts = 1; private int maxAttempts = 1;
private int attemptCount = 1; private int attemptCount = 1;
private boolean isImportInProgress = false;
private RequestContext() { private RequestContext() {
...@@ -145,6 +146,13 @@ public class RequestContext { ...@@ -145,6 +146,13 @@ public class RequestContext {
this.attemptCount = attemptCount; this.attemptCount = attemptCount;
} }
public boolean isImportInProgress() {
return isImportInProgress;
}
public void setImportInProgress(boolean importInProgress) {
isImportInProgress = importInProgress;
}
public void recordEntityUpdate(AtlasObjectId entity) { public void recordEntityUpdate(AtlasObjectId entity) {
if (entity != null && entity.getGuid() != null) { if (entity != null && entity.getGuid() != null) {
......
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