Repository: incubator-atlas Updated Branches: refs/heads/master cae6522da -> ffcdbb176
ATLAS-1346: Search API to return empty list/container object instead of exception Signed-off-by: Madhan Neethiraj <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/ffcdbb17 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/ffcdbb17 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/ffcdbb17 Branch: refs/heads/master Commit: ffcdbb17689ed325715a43dc407ca20348277a5a Parents: cae6522 Author: apoorvnaik <[email protected]> Authored: Wed Dec 21 17:17:47 2016 -0800 Committer: Madhan Neethiraj <[email protected]> Committed: Wed Jan 4 22:35:44 2017 -0800 ---------------------------------------------------------------------- .../java/org/apache/atlas/AtlasErrorCode.java | 2 +- release-log.txt | 1 + .../apache/atlas/GraphTransactionInterceptor.java | 11 ++++++++--- .../store/graph/AtlasTypeDefGraphStore.java | 18 +++--------------- .../graph/v1/AtlasClassificationDefStoreV1.java | 14 +++++--------- .../apache/atlas/web/resources/TypesResource.java | 5 ++--- .../java/org/apache/atlas/web/rest/TypesREST.java | 2 -- 7 files changed, 20 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ffcdbb17/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java index 94a249c..4060b85 100644 --- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java +++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java @@ -24,7 +24,7 @@ import javax.ws.rs.core.Response; import java.text.MessageFormat; import java.util.Arrays; public enum AtlasErrorCode { - NO_SEARCH_RESULTS(204, "ATLAS2041E", "Given search filter did not yield any results"), + NO_SEARCH_RESULTS(204, "ATLAS2041E", "Given search filter {0} did not yield any results"), // All Bad request enums go here UNKNOWN_TYPE(400, "ATLAS4001E", "Unknown type {0} for {1}.{2}"), http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ffcdbb17/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 580c755..3011a06 100644 --- a/release-log.txt +++ b/release-log.txt @@ -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) ALL CHANGES: +ATLAS-1346 Search API to return empty list/container object instead of exception (apoorvnaik via mneethiraj) ATLAS-1428 Create of entityDef type fails with type already exists exception ([email protected] via mneethiraj) ATLAS-1421 Regression : HTML is displayed for deleted entities in search-result and entity-details pages (Kalyanikashikar via mneethiraj) ATLAS-1417 HIveHook: synchronous execution fails to notify (sumasai via mneethiraj) http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ffcdbb17/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java b/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java index 7d6e593..a798f34 100644 --- a/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java +++ b/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java @@ -80,9 +80,14 @@ public class GraphTransactionInterceptor implements MethodInterceptor { } boolean logException(Throwable t) { - return !(t instanceof NotFoundException) && - ((t instanceof AtlasBaseException) && - ((AtlasBaseException) t).getAtlasErrorCode().getHttpCode() != Response.Status.NOT_FOUND); + if (t instanceof AtlasBaseException) { + Response.Status httpCode = ((AtlasBaseException) t).getAtlasErrorCode().getHttpCode(); + return httpCode != Response.Status.NOT_FOUND && httpCode != Response.Status.NO_CONTENT; + } else if (t instanceof NotFoundException) { + return false; + } else { + return true; + } } public static abstract class PostTransactionHook { http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ffcdbb17/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 95a34b0..f7c2931 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 @@ -208,9 +208,6 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ @GraphTransaction public AtlasEnumDefs searchEnumDefs(SearchFilter filter) throws AtlasBaseException { AtlasEnumDefs search = getEnumDefStore(typeRegistry).search(filter); - if (search == null || search.getTotalCount() == 0) { - throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS); - } return search; } @@ -323,9 +320,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ @GraphTransaction public AtlasStructDefs searchStructDefs(SearchFilter filter) throws AtlasBaseException { AtlasStructDefs search = getStructDefStore(typeRegistry).search(filter); - if (search == null || search.getTotalCount() == 0) { - throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS); - } + return search; } @@ -442,9 +437,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ @GraphTransaction public AtlasClassificationDefs searchClassificationDefs(SearchFilter filter) throws AtlasBaseException { AtlasClassificationDefs search = getClassificationDefStore(typeRegistry).search(filter); - if (search == null || search.getTotalCount() == 0) { - throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS); - } + return search; } @@ -557,9 +550,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ @GraphTransaction public AtlasEntityDefs searchEntityDefs(SearchFilter filter) throws AtlasBaseException { AtlasEntityDefs search = getEntityDefStore(typeRegistry).search(filter); - if (search == null || search.getTotalCount() == 0) { - throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS); - } + return search; } @@ -917,9 +908,6 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ LOG.error("Failed to retrieve the EntityDefs", ex); } - if (typesDef.isEmpty()) { - throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS); - } return typesDef; } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ffcdbb17/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java index d34757c..936dd4f 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java @@ -347,18 +347,14 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple } } - if (CollectionUtils.isNotEmpty(classificationDefs)) { - CollectionUtils.filter(classificationDefs, FilterUtil.getPredicateFromSearchFilter(filter)); + CollectionUtils.filter(classificationDefs, FilterUtil.getPredicateFromSearchFilter(filter)); - AtlasClassificationDefs ret = new AtlasClassificationDefs(classificationDefs); + AtlasClassificationDefs ret = new AtlasClassificationDefs(classificationDefs); - if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasClassificationDefStoreV1.search({}): {}", filter, ret); - } - return ret; - } else { - throw new AtlasBaseException(AtlasErrorCode.NO_SEARCH_RESULTS); + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasClassificationDefStoreV1.search({}): {}", filter, ret); } + return ret; } private void updateVertexPreCreate(AtlasClassificationDef classificationDef, http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ffcdbb17/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java index 41259c7..bbe660e 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java @@ -265,9 +265,8 @@ public class TypesResource { return Response.ok(response).build(); } catch (AtlasBaseException e) { - LOG.error("Given search filter did not yield any results"); - throw new WebApplicationException( - Servlets.getErrorResponse(new Exception("Given search filter did not yield any results "), Response.Status.BAD_REQUEST)); + LOG.warn("TypesREST exception: {} {}", e.getClass().getSimpleName(), e.getMessage()); + throw new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode())); } catch (Throwable e) { LOG.error("Unable to get types list", e); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/ffcdbb17/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 6f7b0fe..1f7adf3 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 @@ -34,8 +34,6 @@ import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.web.util.Servlets; import org.apache.http.annotation.Experimental; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.inject.Singleton; import javax.servlet.http.HttpServletRequest;
