Commit ffcdbb17 by apoorvnaik Committed by Madhan Neethiraj

ATLAS-1346: Search API to return empty list/container object instead of exception

parent cae6522d
......@@ -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}"),
......
......@@ -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 (sarath.kum4r@gmail.com 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)
......
......@@ -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 {
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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));
......
......@@ -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;
......
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