Commit 5ebb1690 by Madhan Neethiraj

ATLAS-2982: import fails to create classification-def

parent 18350777
......@@ -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();
......
......@@ -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();
}
......
......@@ -672,11 +672,10 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
}
try {
final boolean isImport = entityStream instanceof EntityImportStream;
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);
}
}
......
......@@ -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 {
......
......@@ -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;
......
......@@ -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);
......
......@@ -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) {
......
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