Commit 2a93a6aa by Vimal Sharma

Move classification endpoint from Entities API to Entity API and remove Entities API

parent b2ec89d5
...@@ -57,7 +57,7 @@ define(['require', 'utils/Enums'], function(require, Enums) { ...@@ -57,7 +57,7 @@ define(['require', 'utils/Enums'], function(require, Enums) {
return this.baseUrlV2 + '/entity/guid/' + token + '/classifications'; return this.baseUrlV2 + '/entity/guid/' + token + '/classifications';
} else { } else {
// For Multiple Assignment // For Multiple Assignment
return this.baseUrlV2 + '/entities/classification'; return this.baseUrlV2 + '/entity/bulk/classification';
} }
}, },
......
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -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) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
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) ATLAS-1548 Create entity : Change PUT and POST object structure based on new API Changes (kevalbhatt)
ATLAS-1522 entity type attributes (like hive_table.sd, hive_table.columns) should use AtlasObjectId as value instead of entire entity contents (mneethiraj) ATLAS-1522 entity type attributes (like hive_table.sd, hive_table.columns) should use AtlasObjectId as value instead of entire entity contents (mneethiraj)
ATLAS-1546 Hive hook should choose appropriate JAAS config when host uses kerberos ticket-cache (nixonrodrigues,gss2002 via mneethiraj) ATLAS-1546 Hive hook should choose appropriate JAAS config when host uses kerberos ticket-cache (nixonrodrigues,gss2002 via mneethiraj)
......
/**
* 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.rest;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.instance.ClassificationAssociateRequest;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream;
import org.apache.atlas.repository.store.graph.v1.EntityStream;
import org.apache.atlas.services.MetadataService;
import org.apache.atlas.typesystem.ITypedStruct;
import org.apache.atlas.web.adapters.AtlasInstanceRestAdapters;
import org.apache.atlas.web.util.Servlets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
import static org.apache.atlas.web.adapters.AtlasInstanceRestAdapters.toAtlasBaseException;
@Path("v2/entities")
@Singleton
public class EntitiesREST {
private static final Logger LOG = LoggerFactory.getLogger(EntitiesREST.class);
private AtlasEntityStore entitiesStore;
@Context
private HttpServletRequest httpServletRequest;
private final MetadataService metadataService;
private final AtlasInstanceRestAdapters restAdapters;
@Inject
public EntitiesREST(AtlasEntityStore entitiesStore, MetadataService metadataService, AtlasInstanceRestAdapters restAdapters) {
LOG.info("EntitiesRest Init");
this.entitiesStore = entitiesStore;
this.metadataService = metadataService;
this.restAdapters = restAdapters;
}
/**
* Bulk API to associate a tag to multiple entities
*
*/
@POST
@Path("/classification")
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public void addClassification(ClassificationAssociateRequest request) throws AtlasBaseException {
AtlasClassification classification = request == null ? null : request.getClassification();
List<String> entityGuids = request == null ? null : request.getEntityGuids();
if (classification == null || StringUtils.isEmpty(classification.getTypeName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no classification");
}
if (CollectionUtils.isEmpty(entityGuids)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "empty entity list");
}
final ITypedStruct trait = restAdapters.getTrait(classification);
try {
metadataService.addTrait(entityGuids, trait);
} catch (IllegalArgumentException e) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e);
} catch (AtlasException e) {
throw toAtlasBaseException(e);
}
}
}
...@@ -27,6 +27,7 @@ import org.apache.atlas.model.instance.AtlasClassification; ...@@ -27,6 +27,7 @@ import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.instance.ClassificationAssociateRequest;
import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.AtlasEntityStore;
...@@ -390,6 +391,37 @@ public class EntityREST { ...@@ -390,6 +391,37 @@ public class EntityREST {
} }
} }
/**
* Bulk API to associate a tag to multiple entities
*
*/
@POST
@Path("/bulk/classification")
@Consumes({Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON})
@Produces(Servlets.JSON_MEDIA_TYPE)
public void addClassification(ClassificationAssociateRequest request) throws AtlasBaseException {
AtlasClassification classification = request == null ? null : request.getClassification();
List<String> entityGuids = request == null ? null : request.getEntityGuids();
if (classification == null || org.apache.commons.lang.StringUtils.isEmpty(classification.getTypeName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no classification");
}
if (CollectionUtils.isEmpty(entityGuids)) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "empty entity list");
}
final ITypedStruct trait = restAdapters.getTrait(classification);
try {
metadataService.addTrait(entityGuids, trait);
} catch (IllegalArgumentException e) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, e);
} catch (AtlasException e) {
throw toAtlasBaseException(e);
}
}
private AtlasEntityType ensureEntityType(String typeName) throws AtlasBaseException { private AtlasEntityType ensureEntityType(String typeName) throws AtlasBaseException {
AtlasEntityType ret = typeRegistry.getEntityTypeByName(typeName); AtlasEntityType ret = typeRegistry.getEntityTypeByName(typeName);
......
...@@ -37,7 +37,6 @@ import org.apache.atlas.repository.graph.AtlasGraphProvider; ...@@ -37,7 +37,6 @@ import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer; import org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer;
import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.web.rest.EntitiesREST;
import org.apache.atlas.web.rest.EntityREST; import org.apache.atlas.web.rest.EntityREST;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -70,9 +69,6 @@ public class TestEntitiesREST { ...@@ -70,9 +69,6 @@ public class TestEntitiesREST {
private AtlasTypeDefStore typeStore; private AtlasTypeDefStore typeStore;
@Inject @Inject
private EntitiesREST entitiesREST;
@Inject
private EntityREST entityREST; private EntityREST entityREST;
private List<String> createdGuids = new ArrayList<>(); private List<String> createdGuids = new ArrayList<>();
...@@ -138,7 +134,7 @@ public class TestEntitiesREST { ...@@ -138,7 +134,7 @@ public class TestEntitiesREST {
public void testTagToMultipleEntities() throws Exception{ public void testTagToMultipleEntities() throws Exception{
AtlasClassification tag = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {{ put("tag", "tagName"); }}); AtlasClassification tag = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {{ put("tag", "tagName"); }});
ClassificationAssociateRequest classificationAssociateRequest = new ClassificationAssociateRequest(createdGuids, tag); ClassificationAssociateRequest classificationAssociateRequest = new ClassificationAssociateRequest(createdGuids, tag);
entitiesREST.addClassification(classificationAssociateRequest); entityREST.addClassification(classificationAssociateRequest);
for (String guid : createdGuids) { for (String guid : createdGuids) {
final AtlasClassification result_tag = entityREST.getClassification(guid, TestUtilsV2.CLASSIFICATION); final AtlasClassification result_tag = entityREST.getClassification(guid, TestUtilsV2.CLASSIFICATION);
Assert.assertNotNull(result_tag); Assert.assertNotNull(result_tag);
......
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