Repository: incubator-atlas Updated Branches: refs/heads/master 90f1566af -> 68a324e39
ATLAS-1547 Added tests for Hard delete(sumasai) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/68a324e3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/68a324e3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/68a324e3 Branch: refs/heads/master Commit: 68a324e395b55dcff1fd9a2f185e1ac742df8d1f Parents: 90f1566 Author: Suma Shivaprasad <[email protected]> Authored: Thu Feb 16 12:16:34 2017 -0800 Committer: Suma Shivaprasad <[email protected]> Committed: Thu Feb 16 12:16:34 2017 -0800 ---------------------------------------------------------------------- release-log.txt | 3 +- .../store/graph/v1/AtlasEntityStoreV1.java | 2 +- .../store/graph/v1/DeleteHandlerV1.java | 4 +- .../graph/v1/AtlasDeleteHandlerV1Test.java | 45 ++++++----------- .../store/graph/v1/SoftDeleteHandlerV1Test.java | 51 +++++++++++--------- .../java/org/apache/atlas/RequestContextV1.java | 3 +- 6 files changed, 51 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/68a324e3/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 9111d4e..8488de7 100644 --- a/release-log.txt +++ b/release-log.txt @@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ALL CHANGES: +ATLAS-1547 Added tests for hard delete (mneethiraj) ATLAS-1546 (ATLAS-1546.3.patch)Hive hook should choose appropriate JAAS config if host uses kerberos ticket-cache (nixonrodrigues via kevalbhat) ATLAS-1503 Export/import support to copy data between Atlas instances (ashutoshm via mneethiraj) ATLAS-1554 v2 EntityREST implementation for entity partial update (sarathkumarsubramanian via mneethiraj) @@ -16,7 +17,7 @@ ATLAS-1547 Fix DeleteHandlerV1 for new model changes and add tests (mneethiraj) ATLAS-1556 Edit entity button not working from search table of tag detail page. (kevalbhatt) ATLAS-1559 Regression - If a new tag is created then the earlier tags doesn't render properly (kevalbhatt) ATLAS-1508 Make AtlasADAuthenticationProvider like Ranger ADLdap Methods (gss2002 via mneethiraj) -ATLAS-1547 Add tests for DeleteHandlerV1 (sumasai via mneethiraj) +ATLAS-1547 Add tests for DeleteHandlerV1 (sumasai) ATLAS-1557 IDBased resolver should attempt unique-attribute match as well (mneethiraj) ATLAS-1555 Move classification endpoint from Entities API to Entity API and remove Entities API (svimal2106) ATLAS-1548 Create entity : Change PUT and POST object structure based on new API Changes (kevalbhatt) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/68a324e3/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java index 93f7b86..4312287 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java @@ -204,7 +204,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore { @GraphTransaction public EntityMutationResponse deleteByIds(final List<String> guids) throws AtlasBaseException { if (CollectionUtils.isEmpty(guids)) { - throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guids); + throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Guid(s) not specified"); } Collection<AtlasVertex> deletionCandidates = new ArrayList<>(); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/68a324e3/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java index 4d11b20..f1efe46 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java @@ -243,9 +243,9 @@ public abstract class DeleteHandlerV1 { return !softDelete || forceDelete; } - protected void deleteEdge(AtlasEdge edge, boolean updateReverseAttribute, boolean force) throws AtlasBaseException { + protected void deleteEdge(AtlasEdge edge, boolean updateInverseAttribute, boolean force) throws AtlasBaseException { //update inverse attribute - if (updateReverseAttribute) { + if (updateInverseAttribute) { AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edge.getLabel()); AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName()); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/68a324e3/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java index 9653b72..492abc4 100644 --- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java +++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java @@ -25,8 +25,10 @@ import org.apache.atlas.RepositoryMetadataModule; import org.apache.atlas.RequestContextV1; import org.apache.atlas.TestUtils; import org.apache.atlas.TestUtilsV2; +import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntityHeader; +import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasStruct; import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutations; @@ -142,11 +144,7 @@ public abstract class AtlasDeleteHandlerV1Test { @BeforeTest public void init() throws Exception { - - final Class<? extends DeleteHandlerV1> deleteHandlerImpl = AtlasRepositoryConfiguration.getDeleteHandlerV1Impl(); - final Constructor<? extends DeleteHandlerV1> deleteHandlerImplConstructor = deleteHandlerImpl.getConstructor(AtlasTypeRegistry.class); - DeleteHandlerV1 deleteHandler = deleteHandlerImplConstructor.newInstance(typeRegistry); - + DeleteHandlerV1 deleteHandler = getDeleteHandler(typeRegistry); entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry); RequestContextV1.clear(); @@ -185,7 +183,6 @@ public abstract class AtlasDeleteHandlerV1Test { EntityMutationResponse newCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(newDBEntity), false); assertNotEquals(newCreationResponse.getFirstEntityCreated().getGuid(), response.getFirstEntityCreated().getGuid()); - //TODO - Enable after GET is ready //get by unique attribute should return the new entity ITypedReferenceableInstance instance = metadataService.getEntityDefinitionReference(TestUtils.DATABASE_TYPE, "name", (String) dbEntity.getAttribute("name")); assertEquals(instance.getId()._getId(), newCreationResponse.getFirstEntityCreated().getGuid()); @@ -220,9 +217,7 @@ public abstract class AtlasDeleteHandlerV1Test { assertEntityDeleted(columnCreated.getGuid()); - //TODO - Fix after GET is ready -// ITypedReferenceableInstance tableInstance = repositoryService.getEntityDefinition(tableId); -// assertColumnForTestDeleteReference(tableInstance); + assertColumnForTestDeleteReference(entityStore.getById(tableCreated.getGuid())); //Deleting table should update process AtlasEntity process = TestUtilsV2.createProcessEntity(null, Arrays.asList(tableCreated.getAtlasObjectId())); @@ -281,11 +276,11 @@ public abstract class AtlasDeleteHandlerV1Test { assertEquals(deletionResponse.getUpdatedEntities().get(0).getGuid(), tableId); assertEntityDeleted(colId); - tableInstance = metadataService.getEntityDefinitionReference(TestUtils.TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME)); - assertDeletedColumn(tableInstance); + final AtlasEntity.AtlasEntityWithExtInfo tableEntityCreated = entityStore.getById(tableId); + assertDeletedColumn(tableEntityCreated); assertTestDisconnectUnidirectionalArrayReferenceFromClassType( - (List<ITypedReferenceableInstance>) tableInstance.get("columns"), colId); + (List<AtlasObjectId>) tableEntityCreated.getEntity().getAttribute(COLUMNS_ATTR_NAME), colId); //update by removing a column - col1 final AtlasEntity tableEntity1 = TestUtilsV2.createTableEntity(dbEntity, (String) tableEntity.getAttribute(NAME)); @@ -298,7 +293,6 @@ public abstract class AtlasDeleteHandlerV1Test { init(); deletionResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo1), false); - //TODO - enable after fixing unique atribute resolver assertEquals(deletionResponse.getDeletedEntities().size(), 1); assertEquals(deletionResponse.getDeletedEntities().get(0).getGuid(), column2Created.getGuid()); assertEntityDeleted(colId); @@ -320,18 +314,17 @@ public abstract class AtlasDeleteHandlerV1Test { // Verify that tables and their composite columns have been deleted from the graph Repository. assertEntityDeleted(tableDeleted.getGuid()); assertEntityDeleted(colDeleted.getGuid()); - assertTestDeleteEntities(tableInstance); } - protected abstract void assertDeletedColumn(ITypedReferenceableInstance tableInstance) throws AtlasException; + protected abstract void assertDeletedColumn(AtlasEntity.AtlasEntityWithExtInfo tableInstance) throws AtlasException, AtlasBaseException; - protected abstract void assertTestDeleteEntities(ITypedReferenceableInstance tableInstance) throws Exception; + protected abstract void assertTestDeleteEntities(AtlasEntity.AtlasEntityWithExtInfo tableInstance) throws Exception; protected abstract void assertTableForTestDeleteReference(String tableId) throws Exception; - protected abstract void assertColumnForTestDeleteReference(AtlasEntity tableInstance) - throws AtlasException; + protected abstract void assertColumnForTestDeleteReference(AtlasEntity.AtlasEntityWithExtInfo tableInstance) + throws AtlasBaseException; protected abstract void assertProcessForTestDeleteReference(AtlasEntityHeader processInstance) throws Exception; @@ -354,9 +347,6 @@ public abstract class AtlasDeleteHandlerV1Test { final AtlasEntityHeader janeEmployeeCreated = hrDeptCreationResponse.getCreatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Jane"); final AtlasEntityHeader juliusEmployeeCreated = hrDeptCreationResponse.getUpdatedEntityByTypeNameAndAttribute(TestUtilsV2.MANAGER_TYPE, NAME, "Julius"); -// ITypedReferenceableInstance hrDeptInstance = metadataService.getEntityDefinition(hrDeptCreationResponse.getFirstCreatedEntityByTypeName(DEPARTMENT_TYPE).getGuid()); -// Map<String, String> nameGuidMap = getEmployeeNameGuidMap(hrDeptInstance); - ITypedReferenceableInstance max = metadataService.getEntityDefinition(maxEmployeeCreated.getGuid()); String maxGuid = max.getId()._getId(); AtlasVertex vertex = GraphHelper.getInstance().getVertexForGUID(maxGuid); @@ -451,7 +441,7 @@ public abstract class AtlasDeleteHandlerV1Test { } return null; } -// + protected abstract void assertTestUpdateEntity_MultiplicityOneNonCompositeReference(String janeGuid) throws Exception; /** @@ -513,8 +503,8 @@ public abstract class AtlasDeleteHandlerV1Test { assertEntityDeleted(janeEmployee.getGuid()); - john = metadataService.getEntityDefinitionReference(TestUtilsV2.EMPLOYEE_TYPE, NAME, "John"); - assertJohnForTestDisconnectBidirectionalReferences(john, janeEmployee.getGuid()); + final AtlasEntity.AtlasEntityWithExtInfo johnUpdated = entityStore.getById(johnEmployee.getGuid()); + assertJohnForTestDisconnectBidirectionalReferences(johnUpdated, janeEmployee.getGuid()); } protected List<String> extractGuids(final List<AtlasEntityHeader> updatedEntities) { @@ -525,14 +515,14 @@ public abstract class AtlasDeleteHandlerV1Test { return guids; } - protected abstract void assertJohnForTestDisconnectBidirectionalReferences(ITypedReferenceableInstance john, + protected abstract void assertJohnForTestDisconnectBidirectionalReferences(AtlasEntity.AtlasEntityWithExtInfo john, String janeGuid) throws Exception; protected abstract void assertMaxForTestDisconnectBidirectionalReferences(Map<String, String> nameGuidMap) throws Exception; protected abstract void assertTestDisconnectUnidirectionalArrayReferenceFromClassType( - List<ITypedReferenceableInstance> columns, String columnGuid); + List<AtlasObjectId> columns, String columnGuid) throws AtlasBaseException; /** * Verify deleting entities that are the target of a unidirectional class array reference @@ -768,9 +758,6 @@ public abstract class AtlasDeleteHandlerV1Test { assertEquals(deletionResponse.getUpdatedEntities().size(), 1); assertEquals(deletionResponse.getUpdatedEntities().get(0).getGuid(), tableId); assertEntityDeleted(colId); - - tableInstance = metadataService.getEntityDefinitionReference(TestUtils.TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME)); - assertDeletedColumn(tableInstance); } protected abstract void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes( http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/68a324e3/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java index 987951e..eba9c77 100644 --- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java +++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java @@ -19,7 +19,7 @@ package org.apache.atlas.repository.store.graph.v1; import org.apache.atlas.AtlasClient; -import org.apache.atlas.AtlasException; +import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasObjectId; @@ -28,6 +28,7 @@ import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.services.MetadataService; import org.apache.atlas.type.AtlasTypeRegistry; +import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.IStruct; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedStruct; @@ -54,19 +55,25 @@ public class SoftDeleteHandlerV1Test extends AtlasDeleteHandlerV1Test { } @Override - protected void assertDeletedColumn(final ITypedReferenceableInstance tableInstance) throws AtlasException { + protected void assertDeletedColumn(final AtlasEntity.AtlasEntityWithExtInfo tableInstance) throws AtlasBaseException { + final List<AtlasObjectId> columns = (List<AtlasObjectId>) tableInstance.getEntity().getAttribute(COLUMNS_ATTR_NAME); + Assert.assertEquals(columns.size(), 3); + final AtlasEntity.AtlasEntityWithExtInfo colDeleted = entityStore.getById(columns.get(0).getGuid()); + assertEquals(colDeleted.getEntity().getStatus(), AtlasEntity.Status.DELETED); } @Override - protected void assertTestDeleteEntities(final ITypedReferenceableInstance tableInstance) throws Exception { - + protected void assertTestDeleteEntities(final AtlasEntity.AtlasEntityWithExtInfo tableInstance) throws Exception { + //Assert that the deleted table can be fully constructed back + List<IReferenceableInstance> columns = (List<IReferenceableInstance>) tableInstance.getEntity().getAttribute(COLUMNS_ATTR_NAME); + assertEquals(columns.size(), 3); + assertNotNull(tableInstance.getEntity().getAttribute("database")); } @Override protected void assertTableForTestDeleteReference(final String tableId) throws Exception { - //TODO - Fix after GET is ready ITypedReferenceableInstance table = metadataService.getEntityDefinition(tableId); assertNotNull(table.get(NAME)); assertNotNull(table.get("description")); @@ -84,14 +91,12 @@ public class SoftDeleteHandlerV1Test extends AtlasDeleteHandlerV1Test { } @Override - protected void assertColumnForTestDeleteReference(final AtlasEntity tableInstance) throws AtlasException { - - List<AtlasObjectId> columns = (List<AtlasObjectId>) tableInstance.getAttribute(COLUMNS_ATTR_NAME); + protected void assertColumnForTestDeleteReference(final AtlasEntity.AtlasEntityWithExtInfo tableInstance) throws AtlasBaseException { + List<AtlasObjectId> columns = (List<AtlasObjectId>) tableInstance.getEntity().getAttribute(COLUMNS_ATTR_NAME); assertEquals(columns.size(), 1); - //TODO - Enable after GET is ready - ITypedReferenceableInstance colInst = metadataService.getEntityDefinition(columns.get(0).getGuid()); - assertEquals(colInst.getId().getState(), Id.EntityState.DELETED); + final AtlasEntity.AtlasEntityWithExtInfo byId = entityStore.getById(columns.get(0).getGuid()); + assertEquals(byId.getEntity().getStatus(), AtlasEntity.Status.DELETED); } @Override @@ -108,8 +113,6 @@ public class SoftDeleteHandlerV1Test extends AtlasDeleteHandlerV1Test { @Override protected void assertEntityDeleted(final String id) throws Exception { -// ITypedReferenceableInstance entity = metadataService.getEntityDefinition(id); -// assertEquals(entity.getId().getState(), Id.EntityState.DELETED); final AtlasEntity.AtlasEntityWithExtInfo byId = entityStore.getById(id); assertEquals(byId.getEntity().getStatus(), AtlasEntity.Status.DELETED); } @@ -123,11 +126,14 @@ public class SoftDeleteHandlerV1Test extends AtlasDeleteHandlerV1Test { } @Override - protected void assertJohnForTestDisconnectBidirectionalReferences(final ITypedReferenceableInstance john, final String janeGuid) throws Exception { - Id mgr = (Id) john.get("manager"); + protected void assertJohnForTestDisconnectBidirectionalReferences(final AtlasEntity.AtlasEntityWithExtInfo john, final String janeGuid) throws Exception { + AtlasObjectId mgr = (AtlasObjectId) john.getEntity().getAttribute("manager"); assertNotNull(mgr); - assertEquals(mgr._getId(), janeGuid); - assertEquals(mgr.getState(), Id.EntityState.DELETED); + assertEquals(mgr.getGuid(), janeGuid); + + + final AtlasEntity.AtlasEntityWithExtInfo mgrEntity = entityStore.getById(mgr.getGuid()); + assertEquals(mgrEntity.getEntity().getStatus(), AtlasEntity.Status.DELETED); } @Override @@ -164,13 +170,14 @@ public class SoftDeleteHandlerV1Test extends AtlasDeleteHandlerV1Test { } @Override - protected void assertTestDisconnectUnidirectionalArrayReferenceFromClassType(final List<ITypedReferenceableInstance> columns, final String columnGuid) { + protected void assertTestDisconnectUnidirectionalArrayReferenceFromClassType(final List<AtlasObjectId> columns, final String columnGuid) throws AtlasBaseException { Assert.assertEquals(columns.size(), 3); - for (ITypedReferenceableInstance column : columns) { - if (column.getId()._getId().equals(columnGuid)) { - assertEquals(column.getId().getState(), Id.EntityState.DELETED); + for (AtlasObjectId column : columns) { + AtlasEntity.AtlasEntityWithExtInfo columnEntity = entityStore.getById(column.getGuid()); + if (column.getGuid().equals(columnGuid)) { + assertEquals(columnEntity.getEntity().getStatus(), AtlasEntity.Status.DELETED); } else { - assertEquals(column.getId().getState(), Id.EntityState.ACTIVE); + assertEquals(columnEntity.getEntity().getStatus(), AtlasEntity.Status.ACTIVE); } } } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/68a324e3/server-api/src/main/java/org/apache/atlas/RequestContextV1.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/RequestContextV1.java b/server-api/src/main/java/org/apache/atlas/RequestContextV1.java index bf73174..59adb00 100644 --- a/server-api/src/main/java/org/apache/atlas/RequestContextV1.java +++ b/server-api/src/main/java/org/apache/atlas/RequestContextV1.java @@ -94,7 +94,6 @@ public class RequestContextV1 { this.updatedEntityIds.add(entityId); } - public void recordEntityDelete(AtlasObjectId entityId) { deletedEntityIds.add(entityId); } @@ -114,7 +113,7 @@ public class RequestContextV1 { public long getRequestTime() { return requestTime; } - + public boolean isDeletedEntity(AtlasObjectId entityId) { return deletedEntityIds.contains(entityId); }
