[2/2] atlas git commit: ATLAS-2774: enhancement to support parameterized delete-type (hard or soft) per API call
ATLAS-2774: enhancement to support parameterized delete-type (hard or soft) per API call (cherry picked from commit d003ddb33b16a0a67e6b7f7eae29c1638a4d0971) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/daabed13 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/daabed13 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/daabed13 Branch: refs/heads/branch-0.8 Commit: daabed1312c73916136eacf09218300d75bb8f9b Parents: 5c9bf7a Author: Madhan Neethiraj Authored: Wed Nov 14 19:50:56 2018 -0800 Committer: Madhan Neethiraj Committed: Wed Nov 14 22:16:13 2018 -0800 -- .../org/apache/atlas/AtlasConfiguration.java| 2 + .../java/org/apache/atlas/store/DeleteType.java | 44 .../graph/GraphBackedMetadataRepository.java| 19 +- .../graph/TypedInstanceToGraphMapper.java | 15 +- .../store/graph/v1/AtlasEntityStoreV1.java | 8 +- .../store/graph/v1/BulkImporterImpl.java| 4 +- .../store/graph/v1/DeleteHandlerDelegate.java | 89 .../store/graph/v1/DeleteHandlerDelegateV1.java | 86 .../store/graph/v1/EntityGraphMapper.java | 28 +-- .../store/graph/v1/HardDeleteHandlerV1.java | 4 - .../store/graph/v1/SoftDeleteHandlerV1.java | 4 - .../test/java/org/apache/atlas/TestModules.java | 31 --- .../AbstractGremlinQueryOptimizerTest.java | 3 +- ...hBackedMetadataRepositoryDeleteTestBase.java | 18 +- .../GraphBackedRepositoryHardDeleteTest.java| 7 +- .../GraphBackedRepositorySoftDeleteTest.java| 7 +- .../ReverseReferenceUpdateHardDeleteTest.java | 7 +- .../ReverseReferenceUpdateSoftDeleteTest.java | 7 +- .../graph/ReverseReferenceUpdateTestBase.java | 10 + .../repository/impexp/ExportImportTestBase.java | 13 -- .../repository/impexp/ExportServiceTest.java| 4 - .../impexp/ExportSkipLineageTest.java | 7 +- .../graph/v1/AtlasDeleteHandlerV1Test.java | 8 + .../store/graph/v1/AtlasEntityStoreV1Test.java | 4 +- .../store/graph/v1/HardDeleteHandlerV1Test.java | 7 +- .../InverseReferenceUpdateHardDeleteV1Test.java | 8 +- .../InverseReferenceUpdateSoftDeleteV1Test.java | 8 +- .../graph/v1/InverseReferenceUpdateV1Test.java | 14 ++ .../store/graph/v1/SoftDeleteHandlerV1Test.java | 8 +- .../store/graph/v1/SoftReferenceTest.java | 13 +- .../java/org/apache/atlas/RequestContext.java | 18 +- .../java/org/apache/atlas/RequestContextV1.java | 28 ++- .../apache/atlas/web/filters/AuditFilter.java | 26 ++- .../web/adapters/TestEntityRESTDelete.java | 208 +++ 34 files changed, 629 insertions(+), 138 deletions(-) -- http://git-wip-us.apache.org/repos/asf/atlas/blob/daabed13/common/src/main/java/org/apache/atlas/AtlasConfiguration.java -- diff --git a/common/src/main/java/org/apache/atlas/AtlasConfiguration.java b/common/src/main/java/org/apache/atlas/AtlasConfiguration.java index 1b3ce1e..c5357f5 100644 --- a/common/src/main/java/org/apache/atlas/AtlasConfiguration.java +++ b/common/src/main/java/org/apache/atlas/AtlasConfiguration.java @@ -33,6 +33,8 @@ public enum AtlasConfiguration { QUERY_PARAM_MAX_LENGTH("atlas.query.param.max.length", 4*1024), + REST_API_ENABLE_DELETE_TYPE_OVERRIDE("atlas.rest.enable.delete.type.override", false), + NOTIFICATION_HOOK_TOPIC_NAME("atlas.notification.hook.topic.name", "ATLAS_HOOK"), NOTIFICATION_ENTITIES_TOPIC_NAME("atlas.notification.entities.topic.name", "ATLAS_ENTITIES"), http://git-wip-us.apache.org/repos/asf/atlas/blob/daabed13/intg/src/main/java/org/apache/atlas/store/DeleteType.java -- diff --git a/intg/src/main/java/org/apache/atlas/store/DeleteType.java b/intg/src/main/java/org/apache/atlas/store/DeleteType.java new file mode 100644 index 000..de5e5e4 --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/store/DeleteType.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permiss
[1/2] atlas git commit: ATLAS-2774: enhancement to support parameterized delete-type (hard or soft) per API call
Repository: atlas Updated Branches: refs/heads/branch-0.8 5c9bf7a30 -> daabed131 http://git-wip-us.apache.org/repos/asf/atlas/blob/daabed13/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityRESTDelete.java -- diff --git a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityRESTDelete.java b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityRESTDelete.java new file mode 100644 index 000..5a8724b --- /dev/null +++ b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityRESTDelete.java @@ -0,0 +1,208 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.web.adapters; + +import org.apache.atlas.RequestContext; +import org.apache.atlas.RequestContextV1; +import org.apache.atlas.TestModules; +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.EntityMutationResponse; +import org.apache.atlas.model.instance.EntityMutations; +import org.apache.atlas.model.typedef.AtlasTypesDef; +import org.apache.atlas.store.AtlasTypeDefStore; +import org.apache.atlas.store.DeleteType; +import org.apache.atlas.web.rest.EntityREST; +import org.mockito.Mockito; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; + +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertNotNull; +import static org.testng.AssertJUnit.assertTrue; +import static org.testng.FileAssert.fail; + +@Guice(modules = {TestModules.TestOnlyModule.class}) +public class TestEntityRESTDelete { + +@Inject +private AtlasTypeDefStore typeStore; + +@Inject +private EntityREST entityREST; + +private List dbEntities = new ArrayList<>(); + +@BeforeClass +public void setUp() throws Exception { +AtlasTypesDef typesDef = TestUtilsV2.defineHiveTypes(); +typeStore.createTypesDef(typesDef); +} + +@AfterMethod +public void cleanup() { +RequestContext.clear(); +} + +private void assertSoftDelete(String guid) throws AtlasBaseException { +AtlasEntity.AtlasEntityWithExtInfo entity = entityREST.getById(guid, false); +assertTrue(entity != null && entity.getEntity().getStatus() == AtlasEntity.Status.DELETED); +} + +private void assertHardDelete(String guid) { +try { +entityREST.getById(guid, false); +fail("Entity should have been deleted. Exception should have been thrown."); +} catch (AtlasBaseException e) { +assertTrue(true); +} +} + +private void createEntities() throws Exception { +dbEntities.clear(); + +for (int i = 1; i <= 2; i++) { +AtlasEntity dbEntity = TestUtilsV2.createDBEntity(); + +final EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntity.AtlasEntitiesWithExtInfo(dbEntity)); + +assertNotNull(response); +List entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE); + +assertNotNull(entitiesMutated); +Assert.assertEquals(entitiesMutated.size(), 1); +assertNotNull(entitiesMutated.get(0)); +dbEntity.setGuid(entitiesMutated.get(0).getGuid()); + +dbEntities.add(dbEntity); +} +} + +@Test +public void deleteByGuidTestSoft() throws Exception { +RequestContextV1.get().setDeleteType(DeleteType.SOFT); + +createEntities(); + +EntityMutationResponse response = entityREST.deleteByGuid(dbEntities.get(0).getGuid()); + +assertNotNull(response); +assertNotNull(response.getDeletedEntities()); +assertSoftDelete(dbEntities.get(0).getGuid()); +} + +@Test +public void deleteByGuidTestHard()
atlas git commit: ATLAS-2774: enhancement to support parameterized delete-type (hard or soft) per API call
Repository: atlas Updated Branches: refs/heads/branch-1.0 2bebba809 -> 7869c9a5f ATLAS-2774: enhancement to support parameterized delete-type (hard or soft) per API call (cherry picked from commit d003ddb33b16a0a67e6b7f7eae29c1638a4d0971) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/7869c9a5 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/7869c9a5 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/7869c9a5 Branch: refs/heads/branch-1.0 Commit: 7869c9a5fe884397b883f30236ae01aa710d8c31 Parents: 2bebba8 Author: Madhan Neethiraj Authored: Tue Nov 13 17:11:48 2018 -0800 Committer: Madhan Neethiraj Committed: Wed Nov 14 18:07:39 2018 -0800 -- .../org/apache/atlas/AtlasConfiguration.java| 2 + .../java/org/apache/atlas/store/DeleteType.java | 44 .../store/graph/v1/DeleteHandlerDelegate.java | 86 .../store/graph/v1/SoftDeleteHandlerV1.java | 4 - .../store/graph/v2/AtlasEntityStoreV2.java | 10 +- .../graph/v2/AtlasRelationshipStoreV2.java | 20 +- .../store/graph/v2/BulkImporterImpl.java| 2 +- .../store/graph/v2/EntityGraphMapper.java | 31 ++- .../test/java/org/apache/atlas/TestModules.java | 25 --- .../repository/impexp/ExportImportTestBase.java | 12 -- .../repository/impexp/ExportServiceTest.java| 12 -- .../impexp/ExportSkipLineageTest.java | 7 +- .../store/graph/v1/SoftReferenceTest.java | 12 +- .../store/graph/v2/AtlasEntityStoreV2Test.java | 2 +- .../store/graph/v2/AtlasEntityTestBase.java | 6 +- .../AtlasRelationshipStoreHardDeleteV2Test.java | 13 +- .../AtlasRelationshipStoreSoftDeleteV2Test.java | 11 +- .../graph/v2/AtlasRelationshipStoreV2Test.java | 15 +- .../InverseReferenceUpdateHardDeleteV2Test.java | 11 +- .../InverseReferenceUpdateSoftDeleteV2Test.java | 11 +- .../graph/v2/InverseReferenceUpdateV2Test.java | 10 + .../java/org/apache/atlas/RequestContext.java | 44 ++-- .../apache/atlas/web/filters/AuditFilter.java | 20 ++ .../web/adapters/TestEntityRESTDelete.java | 207 +++ 24 files changed, 479 insertions(+), 138 deletions(-) -- http://git-wip-us.apache.org/repos/asf/atlas/blob/7869c9a5/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java -- diff --git a/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java b/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java index 1b3ce1e..c5357f5 100644 --- a/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java +++ b/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java @@ -33,6 +33,8 @@ public enum AtlasConfiguration { QUERY_PARAM_MAX_LENGTH("atlas.query.param.max.length", 4*1024), + REST_API_ENABLE_DELETE_TYPE_OVERRIDE("atlas.rest.enable.delete.type.override", false), + NOTIFICATION_HOOK_TOPIC_NAME("atlas.notification.hook.topic.name", "ATLAS_HOOK"), NOTIFICATION_ENTITIES_TOPIC_NAME("atlas.notification.entities.topic.name", "ATLAS_ENTITIES"), http://git-wip-us.apache.org/repos/asf/atlas/blob/7869c9a5/intg/src/main/java/org/apache/atlas/store/DeleteType.java -- diff --git a/intg/src/main/java/org/apache/atlas/store/DeleteType.java b/intg/src/main/java/org/apache/atlas/store/DeleteType.java new file mode 100644 index 000..de5e5e4 --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/store/DeleteType.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.store; + +import org.apache.commons.lang.StringUtils; + +public enum DeleteType { +DEFAULT, +SOFT, +HARD; + +public static DeleteType from(String s) { +if(StringUtils.isEmpty(s)) { +return DEFAULT; +} + +switch (s.toLowerCase()) { +case "soft": +return SOFT; + +case "hard": +return HARD; + +default: +
atlas git commit: ATLAS-2774: enhancement to support parameterized delete-type (hard or soft) per API call
Repository: atlas Updated Branches: refs/heads/master 62cdbdc6d -> d003ddb33 ATLAS-2774: enhancement to support parameterized delete-type (hard or soft) per API call Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/d003ddb3 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/d003ddb3 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/d003ddb3 Branch: refs/heads/master Commit: d003ddb33b16a0a67e6b7f7eae29c1638a4d0971 Parents: 62cdbdc Author: Madhan Neethiraj Authored: Tue Nov 13 17:11:48 2018 -0800 Committer: Madhan Neethiraj Committed: Wed Nov 14 17:57:13 2018 -0800 -- .../org/apache/atlas/AtlasConfiguration.java| 2 + .../java/org/apache/atlas/store/DeleteType.java | 44 .../store/graph/v1/DeleteHandlerDelegate.java | 86 .../store/graph/v1/SoftDeleteHandlerV1.java | 4 - .../store/graph/v2/AtlasEntityStoreV2.java | 10 +- .../graph/v2/AtlasRelationshipStoreV2.java | 20 +- .../store/graph/v2/BulkImporterImpl.java| 2 +- .../store/graph/v2/EntityGraphMapper.java | 31 ++- .../test/java/org/apache/atlas/TestModules.java | 25 --- .../repository/impexp/ExportImportTestBase.java | 12 -- .../repository/impexp/ExportServiceTest.java| 12 -- .../impexp/ExportSkipLineageTest.java | 7 +- .../store/graph/v1/SoftReferenceTest.java | 12 +- .../store/graph/v2/AtlasEntityStoreV2Test.java | 2 +- .../store/graph/v2/AtlasEntityTestBase.java | 6 +- .../AtlasRelationshipStoreHardDeleteV2Test.java | 13 +- .../AtlasRelationshipStoreSoftDeleteV2Test.java | 11 +- .../graph/v2/AtlasRelationshipStoreV2Test.java | 15 +- .../InverseReferenceUpdateHardDeleteV2Test.java | 11 +- .../InverseReferenceUpdateSoftDeleteV2Test.java | 11 +- .../graph/v2/InverseReferenceUpdateV2Test.java | 10 + .../java/org/apache/atlas/RequestContext.java | 44 ++-- .../apache/atlas/web/filters/AuditFilter.java | 20 ++ .../web/adapters/TestEntityRESTDelete.java | 207 +++ 24 files changed, 479 insertions(+), 138 deletions(-) -- http://git-wip-us.apache.org/repos/asf/atlas/blob/d003ddb3/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java -- diff --git a/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java b/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java index 1b3ce1e..c5357f5 100644 --- a/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java +++ b/intg/src/main/java/org/apache/atlas/AtlasConfiguration.java @@ -33,6 +33,8 @@ public enum AtlasConfiguration { QUERY_PARAM_MAX_LENGTH("atlas.query.param.max.length", 4*1024), + REST_API_ENABLE_DELETE_TYPE_OVERRIDE("atlas.rest.enable.delete.type.override", false), + NOTIFICATION_HOOK_TOPIC_NAME("atlas.notification.hook.topic.name", "ATLAS_HOOK"), NOTIFICATION_ENTITIES_TOPIC_NAME("atlas.notification.entities.topic.name", "ATLAS_ENTITIES"), http://git-wip-us.apache.org/repos/asf/atlas/blob/d003ddb3/intg/src/main/java/org/apache/atlas/store/DeleteType.java -- diff --git a/intg/src/main/java/org/apache/atlas/store/DeleteType.java b/intg/src/main/java/org/apache/atlas/store/DeleteType.java new file mode 100644 index 000..de5e5e4 --- /dev/null +++ b/intg/src/main/java/org/apache/atlas/store/DeleteType.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.store; + +import org.apache.commons.lang.StringUtils; + +public enum DeleteType { +DEFAULT, +SOFT, +HARD; + +public static DeleteType from(String s) { +if(StringUtils.isEmpty(s)) { +return DEFAULT; +} + +switch (s.toLowerCase()) { +case "soft": +return SOFT; + +case "hard": +return HARD; + +default: +return DEFAULT; +} +} +} http://git-wip-us.apache.org/repo