Repository: atlas Updated Branches: refs/heads/branch-0.8 7876049ff -> ea33708cf
ATLAS-2892: Delete by name REST endpoint. Change-Id: I9b0a40b42bc945f51aa098e1b15f28f7d2c9fee2 Signed-off-by: Ashutosh Mestry <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/ea33708c Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/ea33708c Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/ea33708c Branch: refs/heads/branch-0.8 Commit: ea33708cffdaa9e79caee53bc43cd1d37f102bba Parents: 7876049 Author: Ashutosh Mestry <[email protected]> Authored: Wed Sep 26 13:02:53 2018 -0700 Committer: Ashutosh Mestry <[email protected]> Committed: Wed Sep 26 13:27:40 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 | 16 ++++++ .../src/test/resources/json/hiveDBv2.json | 56 ++++++++++++++++++++ .../org/apache/atlas/web/rest/TypesREST.java | 26 +++++++++ 7 files changed, 129 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/ea33708c/dashboardv2/public/js/models/VTag.js ---------------------------------------------------------------------- diff --git a/dashboardv2/public/js/models/VTag.js b/dashboardv2/public/js/models/VTag.js index fc5a97f..17acbd8 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/ea33708c/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 ff2cb01..49a820c 100644 --- a/dashboardv2/public/js/views/tag/TagLayoutView.js +++ b/dashboardv2/public/js/views/tag/TagLayoutView.js @@ -586,7 +586,7 @@ define(['require', structDefs: [] }; deleteTagData.deleteTag({ - data: JSON.stringify(deleteJson), + typeName: that.tag, success: function() { Utils.notifySuccess({ content: "Tag " + that.tag + Messages.deleteSuccessMessage http://git-wip-us.apache.org/repos/asf/atlas/blob/ea33708c/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 7f196c6..cf8931f 100644 --- a/intg/src/main/java/org/apache/atlas/store/AtlasTypeDefStore.java +++ b/intg/src/main/java/org/apache/atlas/store/AtlasTypeDefStore.java @@ -91,8 +91,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/ea33708c/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 4669286..ab82d56 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 @@ -51,6 +51,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; @@ -536,6 +537,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/ea33708c/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 a1fbf97..7a4069f 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 @@ -23,6 +23,7 @@ import org.apache.atlas.TestUtilsV2; import org.apache.atlas.RequestContextV1; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.SearchFilter; +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; @@ -31,6 +32,7 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasTypesDef; 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; @@ -39,6 +41,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; +import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -312,6 +315,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/ea33708c/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/ea33708c/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 062d664..1a429db 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 @@ -47,6 +47,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; +import java.util.Collections; import java.util.List; import java.util.Set; @@ -378,6 +379,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 */
