ATLAS-2892: Delete by name REST endpoint. Change-Id: I9b0a40b42bc945f51aa098e1b15f28f7d2c9fee2
Signed-off-by: Ashutosh Mestry <ames...@hortonworks.com> Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/88b980b8 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/88b980b8 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/88b980b8 Branch: refs/heads/branch-1.0 Commit: 88b980b8ed9d1295c9bb89d9e19c2e02ff437382 Parents: 9b586e2 Author: Ashutosh Mestry <ames...@hortonworks.com> Authored: Wed Sep 26 13:02:53 2018 -0700 Committer: Ashutosh Mestry <ames...@hortonworks.com> Committed: Thu Nov 1 15:42:56 2018 -0700 ---------------------------------------------------------------------- dashboardv2/public/js/models/VTag.js | 6 +-- .../public/js/views/tag/TagLayoutView.js | 2 +- .../apache/atlas/store/AtlasTypeDefStore.java | 3 ++ .../store/graph/AtlasTypeDefGraphStore.java | 26 +++++++++ .../store/graph/AtlasTypeDefGraphStoreTest.java | 21 ++++++++ .../src/test/resources/json/hiveDBv2.json | 56 ++++++++++++++++++++ .../org/apache/atlas/web/rest/TypesREST.java | 26 +++++++++ 7 files changed, 134 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/88b980b8/dashboardv2/public/js/models/VTag.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/models/VTag.js b/dashboardv2/public/js/models/VTag.js index 384bcc3..d436bb5 100644 --- a/dashboardv2/public/js/models/VTag.js +++ b/dashboardv2/public/js/models/VTag.js @@ -49,11 +49,7 @@ define(['require', return this.constructor.nonCrudOperation.call(this, url, 'DELETE', options); }, deleteTag: function(options) { - var url = UrlLinks.classificationDefApiUrl(); - options = _.extend({ - contentType: 'application/json', - dataType: 'json' - }, options); + var url = UrlLinks.classificationDefApiUrl(options.typeName); return this.constructor.nonCrudOperation.call(this, url, 'DELETE', options); }, saveTagAttribute: function(options) { http://git-wip-us.apache.org/repos/asf/atlas/blob/88b980b8/dashboardv2/public/js/views/tag/TagLayoutView.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/views/tag/TagLayoutView.js b/dashboardv2/public/js/views/tag/TagLayoutView.js index 7381e64..a5df515 100644 --- a/dashboardv2/public/js/views/tag/TagLayoutView.js +++ b/dashboardv2/public/js/views/tag/TagLayoutView.js @@ -578,7 +578,7 @@ define(['require', structDefs: [] }; deleteTagData.deleteTag({ - data: JSON.stringify(deleteJson), + typeName: that.tag, success: function() { Utils.notifySuccess({ content: "Classification " + that.tag + Messages.deleteSuccessMessage http://git-wip-us.apache.org/repos/asf/atlas/blob/88b980b8/intg/src/main/java/org/apache/atlas/store/AtlasTypeDefStore.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/store/AtlasTypeDefStore.java b/intg/src/main/java/org/apache/atlas/store/AtlasTypeDefStore.java index 025f89a..9a74627 100644 --- a/intg/src/main/java/org/apache/atlas/store/AtlasTypeDefStore.java +++ b/intg/src/main/java/org/apache/atlas/store/AtlasTypeDefStore.java @@ -99,8 +99,11 @@ public interface AtlasTypeDefStore { AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException; + /* Generic operation */ AtlasBaseTypeDef getByName(String name) throws AtlasBaseException; AtlasBaseTypeDef getByGuid(String guid) throws AtlasBaseException; + + void deleteTypeByName(String typeName) throws AtlasBaseException; } http://git-wip-us.apache.org/repos/asf/atlas/blob/88b980b8/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java index bd82eb5..b142179 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java @@ -40,6 +40,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -598,6 +599,31 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { } } + + @Override + @GraphTransaction + public void deleteTypeByName(String typeName) throws AtlasBaseException { + AtlasType atlasType = typeRegistry.getType(typeName); + if (atlasType == null) { + throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS.TYPE_NAME_NOT_FOUND, typeName); + } + + AtlasTypesDef typesDef = new AtlasTypesDef(); + AtlasBaseTypeDef baseTypeDef = getByName(typeName); + + if (baseTypeDef instanceof AtlasClassificationDef) { + typesDef.setClassificationDefs(Collections.singletonList((AtlasClassificationDef) baseTypeDef)); + } else if (baseTypeDef instanceof AtlasEntityDef) { + typesDef.setEntityDefs(Collections.singletonList((AtlasEntityDef) baseTypeDef)); + } else if (baseTypeDef instanceof AtlasEnumDef) { + typesDef.setEnumDefs(Collections.singletonList((AtlasEnumDef) baseTypeDef)); + } else if (baseTypeDef instanceof AtlasStructDef) { + typesDef.setStructDefs(Collections.singletonList((AtlasStructDef) baseTypeDef)); + } + + deleteTypesDef(typesDef); + } + @Override public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException { final AtlasTypesDef typesDef = new AtlasTypesDef(); http://git-wip-us.apache.org/repos/asf/atlas/blob/88b980b8/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java index f1b7736..493ad13 100644 --- a/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java +++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java @@ -24,10 +24,16 @@ import org.apache.atlas.TestUtilsV2; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.typedef.*; +import org.apache.atlas.model.impexp.AtlasExportRequest; +import org.apache.atlas.model.typedef.AtlasClassificationDef; +import org.apache.atlas.model.typedef.AtlasEntityDef; +import org.apache.atlas.model.typedef.AtlasEnumDef; +import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.runner.LocalSolrRunner; import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.type.AtlasType; +import org.apache.atlas.utils.TestResourceFileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -40,6 +46,8 @@ import java.util.Collections; import java.util.List; import java.util.Set; import java.util.HashSet; + +import java.io.IOException; import java.util.Arrays; import java.util.Date; @@ -319,6 +327,19 @@ public class AtlasTypeDefGraphStoreTest { } } + @Test + public void deleteTypeByName() throws IOException { + try { + final String HIVEDB_v2_JSON = "hiveDBv2"; + final String hiveDB2 = "hive_db_v2"; + AtlasTypesDef typesDef = TestResourceFileUtils.readObjectFromJson(".", HIVEDB_v2_JSON, AtlasTypesDef.class); + typeDefStore.createTypesDef(typesDef); + typeDefStore.deleteTypeByName(hiveDB2); + } catch (AtlasBaseException e) { + fail("Deletion should've succeeded"); + } + } + @Test(dependsOnMethods = "testGet") public void testCreateWithValidAttributes(){ AtlasTypesDef hiveTypes = TestUtilsV2.defineHiveTypes(); http://git-wip-us.apache.org/repos/asf/atlas/blob/88b980b8/repository/src/test/resources/json/hiveDBv2.json ---------------------------------------------------------------------- diff --git a/repository/src/test/resources/json/hiveDBv2.json b/repository/src/test/resources/json/hiveDBv2.json new file mode 100644 index 0000000..f46d5f7 --- /dev/null +++ b/repository/src/test/resources/json/hiveDBv2.json @@ -0,0 +1,56 @@ +{ + "enumDefs": [], + "structDefs": [], + "classificationDefs": [], + "entityDefs": [{ + "category": "ENTITY", + "name": "hive_db_v2", + "typeVersion": "1.0", + "attributeDefs": [{ + "name": "name", + "typeName": "string", + "isOptional": false, + "cardinality": "SINGLE", + "valuesMinCount": 1, + "valuesMaxCount": 1, + "isUnique": true, + "isIndexable": true + }, { + "name": "description", + "typeName": "string", + "isOptional": false, + "cardinality": "SINGLE", + "valuesMinCount": 1, + "valuesMaxCount": 1, + "isUnique": false, + "isIndexable": true + }, { + "name": "locationUri", + "typeName": "string", + "isOptional": true, + "cardinality": "SINGLE", + "valuesMinCount": 0, + "valuesMaxCount": 1, + "isUnique": false, + "isIndexable": false + }, { + "name": "owner", + "typeName": "string", + "isOptional": true, + "cardinality": "SINGLE", + "valuesMinCount": 0, + "valuesMaxCount": 1, + "isUnique": false, + "isIndexable": false + }, { + "name": "createTime", + "typeName": "int", + "isOptional": true, + "cardinality": "SINGLE", + "valuesMinCount": 0, + "valuesMaxCount": 1, + "isUnique": false, + "isIndexable": false + }] + }] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/atlas/blob/88b980b8/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java index 13e6512..2091fdf 100644 --- a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java +++ b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java @@ -41,6 +41,7 @@ import javax.inject.Singleton; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; import javax.ws.rs.core.Context; +import java.util.Collections; import java.util.List; import java.util.Set; @@ -410,6 +411,31 @@ public class TypesREST { } /** + * Delete API for type identified by its name. + * @param typeName Name of the type to be deleted. + * @throws AtlasBaseException + * @HTTP 204 On successful deletion of the requested type definitions + * @HTTP 400 On validation failure for any type definitions + */ + @DELETE + @Path("/typedef/name/{typeName}") + @Consumes(Servlets.JSON_MEDIA_TYPE) + @Produces(Servlets.JSON_MEDIA_TYPE) + public void deleteAtlasTypeByName(@PathParam("typeName") final String typeName) throws AtlasBaseException { + AtlasPerfTracer perf = null; + + try { + if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { + perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesREST.deleteAtlasTypeByName(" + typeName + ")"); + } + + typeDefStore.deleteTypeByName(typeName); + } finally { + AtlasPerfTracer.log(perf); + } + } + + /** * Populate a SearchFilter on the basis of the Query Parameters * @return */