You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sv...@apache.org on 2016/12/05 09:31:29 UTC
incubator-atlas git commit: Reduce excessive exception logging
Repository: incubator-atlas
Updated Branches:
refs/heads/master 74a8de1a9 -> c413975aa
Reduce excessive exception logging
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/c413975a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/c413975a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/c413975a
Branch: refs/heads/master
Commit: c413975aa9a10b2e3f576c68fefeffe11229b693
Parents: 74a8de1
Author: Apoorv Naik <an...@hortonworks.com>
Authored: Mon Dec 5 15:01:23 2016 +0530
Committer: Vimal Sharma <sv...@apache.org>
Committed: Mon Dec 5 15:01:23 2016 +0530
----------------------------------------------------------------------
.../simple/AtlasAuthorizationUtils.java | 22 +++++++---
release-log.txt | 1 +
.../atlas/GraphTransactionInterceptor.java | 12 ++---
.../exception/EntityNotFoundException.java | 4 +-
.../typesystem/exception/NotFoundException.java | 46 ++++++++++++++++++++
.../exception/SchemaNotFoundException.java | 4 +-
.../exception/TraitNotFoundException.java | 3 +-
.../web/errors/AtlasBaseExceptionMapper.java | 36 ++++-----------
.../atlas/web/errors/ExceptionMapperUtil.java | 1 -
.../web/errors/NotFoundExceptionMapper.java | 39 +++++++++++++++++
10 files changed, 119 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
----------------------------------------------------------------------
diff --git a/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java b/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
index 9327f63..e48c5ae 100644
--- a/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
+++ b/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
@@ -18,15 +18,16 @@
package org.apache.atlas.authorize.simple;
-import java.util.HashSet;
-import java.util.Set;
-
import org.apache.atlas.AtlasClient;
import org.apache.atlas.authorize.AtlasActionTypes;
import org.apache.atlas.authorize.AtlasResourceTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+
public class AtlasAuthorizationUtils {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthorizationUtils.class);
private static boolean isDebugEnabled = LOG.isDebugEnabled();
@@ -47,7 +48,13 @@ public class AtlasAuthorizationUtils {
String[] split = contextPath.split("/", 3);
String api = split[0];
if (split.length > 1) {
- return (!api.equals("v1")) ? api : String.format("v1/%s", split[1]);
+ if (Objects.equals(api, "v1")) {
+ return String.format("v1/%s", split[1]);
+ } else if (Objects.equals(api, "v2")) {
+ return String.format("v2/%s", split[1]);
+ } else {
+ return api;
+ }
} else {
return api;
}
@@ -101,14 +108,15 @@ public class AtlasAuthorizationUtils {
LOG.debug("==> getAtlasResourceType for " + contextPath);
}
String api = getApi(contextPath);
- if (api.startsWith("types")) {
+ if (api.startsWith("types") || api.startsWith("v2/types")) {
resourceTypes.add(AtlasResourceTypes.TYPE);
} else if (api.startsWith("admin") && (contextPath.contains("/session") || contextPath.contains("/version"))) {
resourceTypes.add(AtlasResourceTypes.UNKNOWN);
} else if ((api.startsWith("discovery") && contextPath.contains("/gremlin")) || api.startsWith("admin")
|| api.startsWith("graph")) {
resourceTypes.add(AtlasResourceTypes.OPERATION);
- } else if (api.startsWith("entities") || api.startsWith("lineage") || api.startsWith("discovery")) {
+ } else if (api.startsWith("entities") || api.startsWith("lineage") ||
+ api.startsWith("discovery") || api.startsWith("v2/entity")) {
resourceTypes.add(AtlasResourceTypes.ENTITY);
} else if (api.startsWith("v1/taxonomies")) {
resourceTypes.add(AtlasResourceTypes.TAXONOMY);
@@ -117,7 +125,7 @@ public class AtlasAuthorizationUtils {
if (contextPath.contains("/terms")) {
resourceTypes.add(AtlasResourceTypes.TERM);
}
- } else if (api.startsWith("v1/entities")) {
+ } else if (api.startsWith("v1/entities") || api.startsWith("v2/entities")) {
resourceTypes.add(AtlasResourceTypes.ENTITY);
} else {
LOG.error("Unable to find Atlas Resource corresponding to : " + api + "\nSetting "
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 03e44f2..1b2d26c 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-1349 Reduce excessive exception logging (apoorvnaik via svimal2106)
ATLAS-1343 CTAS query is not captured by Atlas with Hive2 (svimal2106)
ATLAS-1337 fixed FalconHookIT (ayubpathan via mneethiraj)
ATLAS-1338 fix SqoopHookIT (ayubpathan via mneethiraj)
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/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 c773bac..a7124bf 100644
--- a/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java
+++ b/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java
@@ -19,13 +19,14 @@ package org.apache.atlas;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
+import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graphdb.AtlasGraph;
-import org.apache.atlas.typesystem.exception.EntityNotFoundException;
-import org.apache.atlas.typesystem.exception.SchemaNotFoundException;
+import org.apache.atlas.typesystem.exception.NotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
@@ -79,10 +80,9 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
}
boolean logException(Throwable t) {
- if ((t instanceof SchemaNotFoundException) || (t instanceof EntityNotFoundException)) {
- return false;
- }
- return true;
+ return !(t instanceof NotFoundException) &&
+ ((t instanceof AtlasBaseException) &&
+ ((AtlasBaseException) t).getAtlasErrorCode().getHttpCode() != Response.Status.NOT_FOUND);
}
public static abstract class PostTransactionHook {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java
index 0fec895..7579b80 100644
--- a/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java
+++ b/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java
@@ -18,12 +18,10 @@
package org.apache.atlas.typesystem.exception;
-import org.apache.atlas.AtlasException;
-
/**
* A simple wrapper for 404.
*/
-public class EntityNotFoundException extends AtlasException {
+public class EntityNotFoundException extends NotFoundException {
public EntityNotFoundException() {
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/server-api/src/main/java/org/apache/atlas/typesystem/exception/NotFoundException.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/NotFoundException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/NotFoundException.java
new file mode 100644
index 0000000..b45b970
--- /dev/null
+++ b/server-api/src/main/java/org/apache/atlas/typesystem/exception/NotFoundException.java
@@ -0,0 +1,46 @@
+/**
+ * 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.typesystem.exception;
+
+import org.apache.atlas.AtlasException;
+
+/**
+ * A simple wrapper for 404.
+ */
+public class NotFoundException extends AtlasException {
+ public NotFoundException() {
+ }
+
+ public NotFoundException(String message) {
+ super(message);
+ }
+
+ public NotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public NotFoundException(Throwable cause) {
+ super(cause);
+ }
+
+ public NotFoundException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java
index 3214149..55b4088 100644
--- a/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java
+++ b/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java
@@ -17,9 +17,7 @@
*/
package org.apache.atlas.typesystem.exception;
-import org.apache.atlas.AtlasException;
-
-public class SchemaNotFoundException extends AtlasException {
+public class SchemaNotFoundException extends NotFoundException {
public SchemaNotFoundException() {
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/server-api/src/main/java/org/apache/atlas/typesystem/exception/TraitNotFoundException.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/TraitNotFoundException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/TraitNotFoundException.java
index 59c657c..2d5663e 100644
--- a/server-api/src/main/java/org/apache/atlas/typesystem/exception/TraitNotFoundException.java
+++ b/server-api/src/main/java/org/apache/atlas/typesystem/exception/TraitNotFoundException.java
@@ -17,13 +17,12 @@
*/
package org.apache.atlas.typesystem.exception;
-import org.apache.atlas.AtlasException;
/**
* A simple wrapper for 404.
* Thrown when a requested trait can not be found.
*/
-public class TraitNotFoundException extends AtlasException{
+public class TraitNotFoundException extends NotFoundException {
public TraitNotFoundException() {
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java b/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
index 70b2482..ec1767c 100755
--- a/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
+++ b/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
@@ -21,34 +21,31 @@ package org.apache.atlas.web.errors;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.type.AtlasType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.concurrent.ThreadLocalRandom;
import javax.inject.Singleton;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.ThreadLocalRandom;
/**
- * Exception mapper for Jersey.
- * @param <E>
+ * AtlasBaseException mapper for Jersey.
*/
@Provider
@Singleton
public class AtlasBaseExceptionMapper implements ExceptionMapper<AtlasBaseException> {
- private static final Logger LOGGER = LoggerFactory.getLogger(AtlasBaseExceptionMapper.class);
@Override
public Response toResponse(AtlasBaseException exception) {
final long id = ThreadLocalRandom.current().nextLong();
- // Log the response and use the error codes from the Exception
- logException(id, exception);
- return buildAtlasBaseExceptionResponse((AtlasBaseException) exception);
+ // Only log the exception is there's an internal error
+ if (exception.getAtlasErrorCode().getHttpCode() == Response.Status.INTERNAL_SERVER_ERROR) {
+ ExceptionMapperUtil.logException(id, exception);
+ }
+ return buildAtlasBaseExceptionResponse(exception);
}
protected Response buildAtlasBaseExceptionResponse(AtlasBaseException baseException) {
@@ -64,19 +61,4 @@ public class AtlasBaseExceptionMapper implements ExceptionMapper<AtlasBaseExcept
}
return responseBuilder.build();
}
-
- @SuppressWarnings("UnusedParameters")
- protected String formatErrorMessage(long id, AtlasBaseException exception) {
- return String.format("There was an error processing your request. It has been logged (ID %016x).", id);
- }
-
- protected void logException(long id, AtlasBaseException exception) {
- LOGGER.error(formatLogMessage(id, exception), exception);
- }
-
- @SuppressWarnings("UnusedParameters")
- protected String formatLogMessage(long id, Throwable exception) {
- return String.format("Error handling a request: %016x", id);
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java b/webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java
index a14f939..e2511e5 100644
--- a/webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java
+++ b/webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java
@@ -17,7 +17,6 @@
*/
package org.apache.atlas.web.errors;
-import org.apache.atlas.exception.AtlasBaseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/c413975a/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java b/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
new file mode 100644
index 0000000..9f97bb2
--- /dev/null
+++ b/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
@@ -0,0 +1,39 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.errors;
+
+import org.apache.atlas.typesystem.exception.NotFoundException;
+
+import javax.inject.Singleton;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import java.util.concurrent.ThreadLocalRandom;
+
+@Provider
+@Singleton
+public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> {
+ @Override
+ public Response toResponse(NotFoundException e) {
+ final long id = ThreadLocalRandom.current().nextLong();
+ return Response
+ .status(Response.Status.NOT_FOUND)
+ .entity(ExceptionMapperUtil.formatErrorMessage(id, e))
+ .build();
+ }
+}