Commit f4dac184 by Ashutosh Mestry

ATLAS-2892: Delete by name REST endpoint.

Change-Id: I9b0a40b42bc945f51aa098e1b15f28f7d2c9fee2 Signed-off-by: 's avatarAshutosh Mestry <amestry@hortonworks.com>
parent b04c5bd2
......@@ -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) {
......
......@@ -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
......
......@@ -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;
}
......@@ -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();
......
......@@ -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();
......
{
"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
......@@ -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
*/
......
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