Repository: atlas Updated Branches: refs/heads/ATLAS-2251 0a00dcb1a -> f4e37f0a7
ATLAS-2251: EntityResource (getEntityList fix) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/f4e37f0a Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/f4e37f0a Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/f4e37f0a Branch: refs/heads/ATLAS-2251 Commit: f4e37f0a7f5e38dfc0bb0f932d74cb0618911f5a Parents: 0a00dcb Author: apoorvnaik <apoorvn...@apache.org> Authored: Tue Nov 7 14:20:46 2017 -0800 Committer: apoorvnaik <apoorvn...@apache.org> Committed: Wed Nov 8 21:08:05 2017 -0800 ---------------------------------------------------------------------- .../store/graph/AtlasEntityStore.java | 9 +++++ .../store/graph/v1/AtlasEntityStoreV1.java | 20 +++++++++++ .../store/graph/v1/AtlasGraphUtilsV1.java | 19 ++++++++++ .../atlas/web/resources/EntityResource.java | 38 ++++++++++++-------- 4 files changed, 71 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/f4e37f0a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java index 5a0b74e..0fe35b6 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java @@ -32,6 +32,15 @@ import java.util.Map; * Persistence/Retrieval API for AtlasEntity */ public interface AtlasEntityStore { + + /** + * List all the entity guids for a given typename + * @param typename + * @return + * @throws AtlasBaseException + */ + List<String> getEntityGUIDS(String typename) throws AtlasBaseException; + /** * * Get entity definition by its guid http://git-wip-us.apache.org/repos/asf/atlas/blob/f4e37f0a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java index a5db81b..89bf7dc 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java @@ -77,6 +77,26 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore { @Override @GraphTransaction + public List<String> getEntityGUIDS(final String typename) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> getEntityGUIDS({})", typename); + } + + if (StringUtils.isEmpty(typename)) { + throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME); + } + + List<String> ret = AtlasGraphUtilsV1.findEntityGUIDsByType(typename); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== getEntityGUIDS({})", typename); + } + + return ret; + } + + @Override + @GraphTransaction public AtlasEntityWithExtInfo getById(String guid) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> getById({})", guid); http://git-wip-us.apache.org/repos/asf/atlas/blob/f4e37f0a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java index 1eb4183..6a6ac60 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java @@ -43,9 +43,12 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -325,6 +328,22 @@ public class AtlasGraphUtilsV1 { return vertex; } + public static List<String> findEntityGUIDsByType(String typename) { + AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance().query() + .has(Constants.ENTITY_TYPE_PROPERTY_KEY, typename); + Iterator<AtlasVertex> results = query.vertices().iterator(); + if (!results.hasNext()) { + return Collections.emptyList(); + } + + ArrayList<String> entityList = new ArrayList<>(); + while (results.hasNext()) { + entityList.add(getIdFromVertex(results.next())); + } + + return entityList; + } + public static boolean relationshipTypeHasInstanceEdges(String typeName) throws AtlasBaseException { AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance() .query() http://git-wip-us.apache.org/repos/asf/atlas/blob/f4e37f0a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java index 42d5631..11879e6 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java @@ -20,21 +20,21 @@ package org.apache.atlas.web.resources; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import com.sun.jersey.api.core.ResourceContext; import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasConstants; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasException; import org.apache.atlas.CreateUpdateEntitiesResult; import org.apache.atlas.EntityAuditEvent; +import org.apache.atlas.discovery.AtlasDiscoveryService; import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.instance.*; +import org.apache.atlas.model.instance.AtlasClassification; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo; import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; +import org.apache.atlas.model.instance.EntityMutationResponse; +import org.apache.atlas.model.instance.GuidMapping; import org.apache.atlas.model.legacy.EntityResult; -import org.apache.atlas.v1.model.instance.Id; -import org.apache.atlas.v1.model.instance.Referenceable; -import org.apache.atlas.v1.model.instance.Struct; +import org.apache.atlas.repository.audit.EntityAuditRepository; import org.apache.atlas.repository.converters.AtlasInstanceConverter; import org.apache.atlas.repository.store.graph.AtlasEntityStore; import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream; @@ -45,6 +45,9 @@ import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.ParamChecker; +import org.apache.atlas.v1.model.instance.Id; +import org.apache.atlas.v1.model.instance.Referenceable; +import org.apache.atlas.v1.model.instance.Struct; import org.apache.atlas.web.rest.EntityREST; import org.apache.atlas.web.util.Servlets; import org.apache.commons.collections.CollectionUtils; @@ -93,21 +96,26 @@ public class EntityResource { private final AtlasInstanceConverter restAdapters; private final AtlasEntityStore entitiesStore; private final AtlasTypeRegistry typeRegistry; - private final EntityREST entityREST; + private final EntityREST entityREST; + private final EntityAuditRepository entityAuditRepository; + private final AtlasDiscoveryService atlasDiscoveryService; @Context UriInfo uriInfo; - @Context - private ResourceContext resourceContext; - - @Inject - public EntityResource(AtlasInstanceConverter restAdapters, AtlasEntityStore entitiesStore, AtlasTypeRegistry typeRegistry, EntityREST entityREST) { + public EntityResource(final AtlasInstanceConverter restAdapters, + final AtlasEntityStore entitiesStore, + final AtlasTypeRegistry typeRegistry, + final EntityREST entityREST, + final EntityAuditRepository entityAuditRepository, + final AtlasDiscoveryService atlasDiscoveryService) { this.restAdapters = restAdapters; this.entitiesStore = entitiesStore; this.typeRegistry = typeRegistry; this.entityREST = entityREST; + this.entityAuditRepository = entityAuditRepository; + this.atlasDiscoveryService = atlasDiscoveryService; } /** @@ -673,13 +681,13 @@ public class EntityResource { LOG.debug("Fetching entity list for type={} ", entityType); } - final List<String> entityList = new ArrayList<>(); // TODO: metadataService.getEntityList(entityType); + List<String> entityGUIDS = entitiesStore.getEntityGUIDS(entityType); JSONObject response = new JSONObject(); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId()); response.put(AtlasClient.TYPENAME, entityType); - response.put(AtlasClient.RESULTS, new JSONArray(entityList)); - response.put(AtlasClient.COUNT, entityList.size()); + response.put(AtlasClient.RESULTS, new JSONArray(entityGUIDS)); + response.put(AtlasClient.COUNT, entityGUIDS.size()); return Response.ok(response).build(); } catch (NullPointerException e) { @@ -1116,7 +1124,7 @@ public class EntityResource { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getAuditEvents(" + guid + ", " + startKey + ", " + count + ")"); } - List<EntityAuditEvent> events = new ArrayList<>(); // TODO: metadataService.getAuditEvents(guid, startKey, count); + List<EntityAuditEvent> events = entityAuditRepository.listEvents(guid, startKey, count); JSONObject response = new JSONObject(); response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());