Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
fdf97ae4
Commit
fdf97ae4
authored
Oct 24, 2016
by
Suma Shivaprasad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1200 Error Catalog enhancement (apoorvnaik via sumasai)
parent
5a4dd2e7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
343 additions
and
82 deletions
+343
-82
AtlasConstants.java
common/src/main/java/org/apache/atlas/AtlasConstants.java
+0
-1
AtlasErrorCode.java
intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
+76
-0
AtlasBaseException.java
...n/java/org/apache/atlas/exception/AtlasBaseException.java
+20
-0
AtlasTypesDef.java
...in/java/org/apache/atlas/model/typedef/AtlasTypesDef.java
+8
-0
release-log.txt
release-log.txt
+1
-0
AtlasTypeDefGraphStore.java
.../atlas/repository/store/graph/AtlasTypeDefGraphStore.java
+57
-23
AtlasClassificationDefStoreV1.java
...ository/store/graph/v1/AtlasClassificationDefStoreV1.java
+20
-16
AtlasEntityDefStoreV1.java
...tlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
+11
-10
AtlasEnumDefStoreV1.java
.../atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java
+8
-7
AtlasStructDefStoreV1.java
...tlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
+12
-11
AtlasTypeDefGraphStoreV1.java
...s/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
+3
-1
AllExceptionMapper.java
.../java/org/apache/atlas/web/errors/AllExceptionMapper.java
+51
-0
AtlasBaseExceptionMapper.java
...org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
+34
-12
ExceptionMapperUtil.java
...java/org/apache/atlas/web/errors/ExceptionMapperUtil.java
+41
-0
TypesREST.java
...pp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
+0
-0
web.xml
webapp/src/main/webapp/WEB-INF/web.xml
+1
-1
No files found.
common/src/main/java/org/apache/atlas/AtlasConstants.java
View file @
fdf97ae4
...
...
@@ -34,5 +34,4 @@ public final class AtlasConstants {
public
static
final
String
DEFAULT_ATLAS_REST_ADDRESS
=
"http://localhost:21000"
;
public
static
final
int
ATLAS_SHUTDOWN_HOOK_PRIORITY
=
30
;
public
static
final
String
DEFAULT_TYPE_VERSION
=
"1.0"
;
}
intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
0 → 100644
View file @
fdf97ae4
/**
* 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
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.text.MessageFormat
;
import
java.util.Arrays
;
import
javax.ws.rs.core.Response
;
public
enum
AtlasErrorCode
{
NO_SEARCH_RESULTS
(
204
,
"ATLAS2041E"
,
"Given search filter did not yield any results"
),
UNKNOWN_TYPE
(
400
,
"ATLAS4001E"
,
"Unknown type {0} for {1}.{2}"
),
TYPE_NAME_NOT_FOUND
(
404
,
"ATLAS4041E"
,
"Given typename {0} was invalid"
),
TYPE_GUID_NOT_FOUND
(
404
,
"ATLAS4042E"
,
"Given type guid {0} was invalid"
),
EMPTY_RESULTS
(
404
,
"ATLAS4044E"
,
"No result found for {0}"
),
TYPE_ALREADY_EXISTS
(
409
,
"ATLAS4091E"
,
"Given type {0} already exists"
),
TYPE_HAS_REFERENCES
(
409
,
"ATLAS4092E"
,
"Given type {0} has references"
),
TYPE_MATCH_FAILED
(
409
,
"ATLAS4093E"
,
"Given type {0} doesn't match {1}"
),
INTERNAL_ERROR
(
500
,
"ATLAS5001E"
,
"Internal server error {0}"
);
private
String
errorCode
;
private
String
errorMessage
;
private
Response
.
Status
httpCode
;
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasErrorCode
.
class
);
AtlasErrorCode
(
int
httpCode
,
String
errorCode
,
String
errorMessage
)
{
this
.
httpCode
=
Response
.
Status
.
fromStatusCode
(
httpCode
);
this
.
errorCode
=
errorCode
;
this
.
errorMessage
=
errorMessage
;
}
public
String
getFormattedErrorMessage
(
String
...
params
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
String
.
format
(
"<== AtlasErrorCode.getMessage(%s)"
,
Arrays
.
toString
(
params
)));
}
MessageFormat
mf
=
new
MessageFormat
(
errorMessage
);
String
result
=
mf
.
format
(
params
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
String
.
format
(
"==> AtlasErrorCode.getMessage(%s): %s"
,
Arrays
.
toString
(
params
),
result
));
}
return
result
;
}
public
Response
.
Status
getHttpCode
()
{
return
httpCode
;
}
public
String
getErrorCode
()
{
return
errorCode
;
}
}
intg/src/main/java/org/apache/atlas/exception/AtlasBaseException.java
View file @
fdf97ae4
...
...
@@ -17,27 +17,47 @@
*/
package
org
.
apache
.
atlas
.
exception
;
import
org.apache.atlas.AtlasErrorCode
;
import
javax.ws.rs.core.Response
;
/**
* Base Exception class for Atlas API.
*/
public
class
AtlasBaseException
extends
Exception
{
private
AtlasErrorCode
atlasErrorCode
;
public
AtlasBaseException
(
AtlasErrorCode
errorCode
,
String
...
params
)
{
super
(
errorCode
.
getFormattedErrorMessage
(
params
));
this
.
atlasErrorCode
=
errorCode
;
}
public
AtlasBaseException
()
{
this
(
AtlasErrorCode
.
INTERNAL_ERROR
);
}
public
AtlasBaseException
(
String
message
)
{
super
(
message
);
this
.
atlasErrorCode
=
AtlasErrorCode
.
INTERNAL_ERROR
;
}
public
AtlasBaseException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
this
.
atlasErrorCode
=
AtlasErrorCode
.
INTERNAL_ERROR
;
}
public
AtlasBaseException
(
Throwable
cause
)
{
super
(
cause
);
this
.
atlasErrorCode
=
AtlasErrorCode
.
INTERNAL_ERROR
;
}
public
AtlasBaseException
(
String
message
,
Throwable
cause
,
boolean
enableSuppression
,
boolean
writableStackTrace
)
{
super
(
message
,
cause
,
enableSuppression
,
writableStackTrace
);
this
.
atlasErrorCode
=
AtlasErrorCode
.
INTERNAL_ERROR
;
}
public
AtlasErrorCode
getAtlasErrorCode
()
{
return
atlasErrorCode
;
}
}
intg/src/main/java/org/apache/atlas/model/typedef/AtlasTypesDef.java
View file @
fdf97ae4
...
...
@@ -17,6 +17,7 @@
*/
package
org
.
apache
.
atlas
.
model
.
typedef
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
...
...
@@ -89,4 +90,11 @@ public class AtlasTypesDef {
public
void
setEntityDefs
(
List
<
AtlasEntityDef
>
entityDefs
)
{
this
.
entityDefs
=
entityDefs
;
}
public
boolean
isEmpty
()
{
return
CollectionUtils
.
isEmpty
(
enumDefs
)
&&
CollectionUtils
.
isEmpty
(
structDefs
)
&&
CollectionUtils
.
isEmpty
(
classificationDefs
)
&&
CollectionUtils
.
isEmpty
(
entityDefs
);
}
}
release-log.txt
View file @
fdf97ae4
...
...
@@ -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-1200 Error Catalog enhancement (apoorvnaik via sumasai)
ATLAS-1207 Dataset exists query in lineage APIs takes longer (shwethags)
ATLAS-1232 added preCreate(), preDelete() in typedef persistence, to enable edge creation for references in a later stage (mneethiraj)
ATLAS-1183 UI: help link should point to atlas website (kevalbhatt via shwethags)
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
View file @
fdf97ae4
...
...
@@ -17,6 +17,7 @@
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.GraphTransaction
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
...
...
@@ -41,6 +42,7 @@ import org.slf4j.LoggerFactory;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -102,9 +104,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
Collection
<
AtlasEnumDef
>
enumDefs
=
typeRegistry
.
getAllEnumDefs
();
if
(
enumDefs
!=
null
)
{
ret
=
new
ArrayList
<>(
enumDefs
);
}
ret
=
CollectionUtils
.
isNotEmpty
(
enumDefs
)
?
new
ArrayList
<>(
enumDefs
)
:
Collections
.<
AtlasEnumDef
>
emptyList
();
return
ret
;
}
...
...
@@ -113,7 +114,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction
public
AtlasEnumDef
getEnumDefByName
(
String
name
)
throws
AtlasBaseException
{
AtlasEnumDef
ret
=
typeRegistry
.
getEnumDefByName
(
name
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
return
ret
;
}
...
...
@@ -121,7 +124,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction
public
AtlasEnumDef
getEnumDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
AtlasEnumDef
ret
=
typeRegistry
.
getEnumDefByGuid
(
guid
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
return
ret
;
}
...
...
@@ -180,7 +185,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override
@GraphTransaction
public
AtlasEnumDefs
searchEnumDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
{
return
getEnumDefStore
(
typeRegistry
).
search
(
filter
);
AtlasEnumDefs
search
=
getEnumDefStore
(
typeRegistry
).
search
(
filter
);
if
(
search
==
null
||
search
.
getTotalCount
()
==
0
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
NO_SEARCH_RESULTS
);
}
return
search
;
}
@Override
...
...
@@ -206,9 +215,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
Collection
<
AtlasStructDef
>
structDefs
=
typeRegistry
.
getAllStructDefs
();
if
(
structDefs
!=
null
)
{
ret
=
new
ArrayList
<>(
structDefs
);
}
ret
=
CollectionUtils
.
isNotEmpty
(
structDefs
)
?
new
ArrayList
<>(
structDefs
)
:
Collections
.<
AtlasStructDef
>
emptyList
();
return
ret
;
}
...
...
@@ -217,7 +225,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction
public
AtlasStructDef
getStructDefByName
(
String
name
)
throws
AtlasBaseException
{
AtlasStructDef
ret
=
typeRegistry
.
getStructDefByName
(
name
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
return
ret
;
}
...
...
@@ -225,7 +235,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction
public
AtlasStructDef
getStructDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
AtlasStructDef
ret
=
typeRegistry
.
getStructDefByGuid
(
guid
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
return
ret
;
}
...
...
@@ -284,7 +296,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override
@GraphTransaction
public
AtlasStructDefs
searchStructDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
{
return
getStructDefStore
(
typeRegistry
).
search
(
filter
);
AtlasStructDefs
search
=
getStructDefStore
(
typeRegistry
).
search
(
filter
);
if
(
search
==
null
||
search
.
getTotalCount
()
==
0
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
NO_SEARCH_RESULTS
);
}
return
search
;
}
@Override
...
...
@@ -311,9 +327,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
Collection
<
AtlasClassificationDef
>
classificationDefs
=
typeRegistry
.
getAllClassificationDefs
();
if
(
classificationDefs
!=
null
)
{
ret
=
new
ArrayList
<>(
classificationDefs
);
}
ret
=
CollectionUtils
.
isNotEmpty
(
classificationDefs
)
?
new
ArrayList
<>(
classificationDefs
)
:
Collections
.<
AtlasClassificationDef
>
emptyList
();
return
ret
;
}
...
...
@@ -323,6 +338,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
public
AtlasClassificationDef
getClassificationDefByName
(
String
name
)
throws
AtlasBaseException
{
AtlasClassificationDef
ret
=
typeRegistry
.
getClassificationDefByName
(
name
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
return
ret
;
}
...
...
@@ -330,7 +348,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction
public
AtlasClassificationDef
getClassificationDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
AtlasClassificationDef
ret
=
typeRegistry
.
getClassificationDefByGuid
(
guid
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
return
ret
;
}
...
...
@@ -391,7 +411,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override
@GraphTransaction
public
AtlasClassificationDefs
searchClassificationDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
{
return
getClassificationDefStore
(
typeRegistry
).
search
(
filter
);
AtlasClassificationDefs
search
=
getClassificationDefStore
(
typeRegistry
).
search
(
filter
);
if
(
search
==
null
||
search
.
getTotalCount
()
==
0
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
NO_SEARCH_RESULTS
);
}
return
search
;
}
@Override
...
...
@@ -417,9 +441,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
Collection
<
AtlasEntityDef
>
entityDefs
=
typeRegistry
.
getAllEntityDefs
();
if
(
entityDefs
!=
null
)
{
ret
=
new
ArrayList
<>(
entityDefs
);
}
ret
=
CollectionUtils
.
isNotEmpty
(
entityDefs
)
?
new
ArrayList
<>(
entityDefs
)
:
Collections
.<
AtlasEntityDef
>
emptyList
();
return
ret
;
}
...
...
@@ -428,7 +451,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction
public
AtlasEntityDef
getEntityDefByName
(
String
name
)
throws
AtlasBaseException
{
AtlasEntityDef
ret
=
typeRegistry
.
getEntityDefByName
(
name
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
return
ret
;
}
...
...
@@ -436,7 +461,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@GraphTransaction
public
AtlasEntityDef
getEntityDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
AtlasEntityDef
ret
=
typeRegistry
.
getEntityDefByGuid
(
guid
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
return
ret
;
}
...
...
@@ -495,7 +522,11 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override
@GraphTransaction
public
AtlasEntityDefs
searchEntityDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
{
return
getEntityDefStore
(
typeRegistry
).
search
(
filter
);
AtlasEntityDefs
search
=
getEntityDefStore
(
typeRegistry
).
search
(
filter
);
if
(
search
==
null
||
search
.
getTotalCount
()
==
0
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
NO_SEARCH_RESULTS
);
}
return
search
;
}
@Override
...
...
@@ -809,6 +840,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
LOG
.
error
(
"Failed to retrieve the EntityDefs"
,
ex
);
}
if
(
typesDef
.
isEmpty
())
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
NO_SEARCH_RESULTS
);
}
return
typesDef
;
}
}
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java
View file @
fdf97ae4
...
...
@@ -18,6 +18,7 @@
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
...
...
@@ -58,13 +59,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasType
type
=
typeRegistry
.
getType
(
classificationDef
.
getName
());
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
CLASSIFICATION
)
{
throw
new
AtlasBaseException
(
classificationDef
.
getName
()
+
": not a classification type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
classificationDef
.
getName
(),
TypeCategory
.
TRAIT
.
name
()
);
}
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByName
(
classificationDef
.
getName
());
if
(
ret
!=
null
)
{
throw
new
AtlasBaseException
(
classificationDef
.
getName
()
+
": type already exists"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_ALREADY_EXISTS
,
classificationDef
.
getName
()
);
}
ret
=
typeDefStore
.
createTypeVertex
(
classificationDef
);
...
...
@@ -132,7 +133,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
vertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
TypeCategory
.
class
);
...
...
@@ -155,7 +156,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
AtlasClassificationDef
ret
=
toClassificationDef
(
vertex
);
...
...
@@ -193,13 +194,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasType
type
=
typeRegistry
.
getType
(
classificationDef
.
getName
());
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
CLASSIFICATION
)
{
throw
new
AtlasBaseException
(
classificationDef
.
getName
()
+
": not a struct type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
classificationDef
.
getName
(),
TypeCategory
.
TRAIT
.
name
()
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
updateVertexPreUpdate
(
classificationDef
,
(
AtlasClassificationType
)
type
,
vertex
);
...
...
@@ -223,13 +224,13 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasType
type
=
typeRegistry
.
getTypeByGuid
(
guid
);
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
CLASSIFICATION
)
{
throw
new
AtlasBaseException
(
classificationDef
.
getName
()
+
": not a struct type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
classificationDef
.
getName
(),
TypeCategory
.
TRAIT
.
name
()
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
updateVertexPreUpdate
(
classificationDef
,
(
AtlasClassificationType
)
type
,
vertex
);
...
...
@@ -253,7 +254,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
TRAIT
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
typeDefStore
.
deleteTypeVertexOutEdges
(
ret
);
...
...
@@ -295,7 +296,7 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
TRAIT
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
typeDefStore
.
deleteTypeVertexOutEdges
(
ret
);
...
...
@@ -346,15 +347,18 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
}
}
CollectionUtils
.
filter
(
classificationDefs
,
FilterUtil
.
getPredicateFromSearchFilter
(
filter
));
if
(
CollectionUtils
.
isNotEmpty
(
classificationDefs
))
{
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
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.search({}): {}"
,
filter
,
ret
);
}
return
ret
;
}
else
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
NO_SEARCH_RESULTS
);
}
return
ret
;
}
private
void
updateVertexPreCreate
(
AtlasClassificationDef
classificationDef
,
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
View file @
fdf97ae4
...
...
@@ -17,6 +17,7 @@
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
...
...
@@ -57,13 +58,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType
type
=
typeRegistry
.
getType
(
entityDef
.
getName
());
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
ENTITY
)
{
throw
new
AtlasBaseException
(
entityDef
.
getName
()
+
": not an entity type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
entityDef
.
getName
(),
TypeCategory
.
CLASS
.
name
()
);
}
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByName
(
entityDef
.
getName
());
if
(
ret
!=
null
)
{
throw
new
AtlasBaseException
(
entityDef
.
getName
()
+
": type already exists"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_ALREADY_EXISTS
,
entityDef
.
getName
()
);
}
ret
=
typeDefStore
.
createTypeVertex
(
entityDef
);
...
...
@@ -131,7 +132,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
vertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
TypeCategory
.
class
);
...
...
@@ -154,7 +155,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
AtlasEntityDef
ret
=
toEntityDef
(
vertex
);
...
...
@@ -191,13 +192,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType
type
=
typeRegistry
.
getType
(
entityDef
.
getName
());
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
ENTITY
)
{
throw
new
AtlasBaseException
(
entityDef
.
getName
()
+
": not an entity type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
entityDef
.
getName
(),
TypeCategory
.
CLASS
.
name
()
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
updateVertexPreUpdate
(
entityDef
,
(
AtlasEntityType
)
type
,
vertex
);
...
...
@@ -221,13 +222,13 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType
type
=
typeRegistry
.
getTypeByGuid
(
guid
);
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
ENTITY
)
{
throw
new
AtlasBaseException
(
entityDef
.
getName
()
+
": not an entity type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
entityDef
.
getName
(),
TypeCategory
.
CLASS
.
name
()
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
updateVertexPreUpdate
(
entityDef
,
(
AtlasEntityType
)
type
,
vertex
);
...
...
@@ -251,7 +252,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
CLASS
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
typeDefStore
.
deleteTypeVertexOutEdges
(
ret
);
...
...
@@ -293,7 +294,7 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
CLASS
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
typeDefStore
.
deleteTypeVertexOutEdges
(
ret
);
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java
View file @
fdf97ae4
...
...
@@ -17,6 +17,7 @@
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
...
...
@@ -57,7 +58,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByName
(
enumDef
.
getName
());
if
(
vertex
!=
null
)
{
throw
new
AtlasBaseException
(
enumDef
.
getName
()
+
": type already exists"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_ALREADY_EXISTS
,
enumDef
.
getName
()
);
}
vertex
=
typeDefStore
.
createTypeVertex
(
enumDef
);
...
...
@@ -102,7 +103,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
vertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
TypeCategory
.
class
);
...
...
@@ -125,7 +126,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
AtlasEnumDef
ret
=
toEnumDef
(
vertex
);
...
...
@@ -162,7 +163,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
toVertex
(
enumDef
,
vertex
);
...
...
@@ -185,7 +186,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
toVertex
(
enumDef
,
vertex
);
...
...
@@ -208,7 +209,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
typeDefStore
.
deleteTypeVertex
(
vertex
);
...
...
@@ -227,7 +228,7 @@ public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements Atla
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
typeDefStore
.
deleteTypeVertex
(
vertex
);
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
View file @
fdf97ae4
...
...
@@ -17,6 +17,7 @@
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
...
...
@@ -70,13 +71,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType
type
=
typeRegistry
.
getType
(
structDef
.
getName
());
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
STRUCT
)
{
throw
new
AtlasBaseException
(
structDef
.
getName
()
+
": not a struct type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
structDef
.
getName
(),
TypeCategory
.
STRUCT
.
name
()
);
}
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByName
(
structDef
.
getName
());
if
(
ret
!=
null
)
{
throw
new
AtlasBaseException
(
structDef
.
getName
()
+
": type already exists"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_ALREADY_EXISTS
,
structDef
.
getName
()
);
}
ret
=
typeDefStore
.
createTypeVertex
(
structDef
);
...
...
@@ -143,7 +144,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
STRUCT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
vertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
String
.
class
);
...
...
@@ -166,7 +167,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
STRUCT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
AtlasStructDef
ret
=
toStructDef
(
vertex
);
...
...
@@ -203,13 +204,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType
type
=
typeRegistry
.
getType
(
structDef
.
getName
());
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
STRUCT
)
{
throw
new
AtlasBaseException
(
structDef
.
getName
()
+
": not a struct type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
structDef
.
getName
(),
TypeCategory
.
STRUCT
.
name
()
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
STRUCT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
AtlasStructDefStoreV1
.
updateVertexPreUpdate
(
structDef
,
(
AtlasStructType
)
type
,
vertex
,
typeDefStore
);
...
...
@@ -233,13 +234,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasType
type
=
typeRegistry
.
getTypeByGuid
(
guid
);
if
(
type
.
getTypeCategory
()
!=
AtlasType
.
TypeCategory
.
STRUCT
)
{
throw
new
AtlasBaseException
(
structDef
.
getName
()
+
": not a struct type"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_MATCH_FAILED
,
structDef
.
getName
(),
TypeCategory
.
STRUCT
.
name
()
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
STRUCT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
AtlasStructDefStoreV1
.
updateVertexPreUpdate
(
structDef
,
(
AtlasStructType
)
type
,
vertex
,
typeDefStore
);
...
...
@@ -263,7 +264,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
STRUCT
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with name "
+
name
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
typeDefStore
.
deleteTypeVertexOutEdges
(
ret
);
...
...
@@ -305,7 +306,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
STRUCT
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with guid "
+
guid
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
typeDefStore
.
deleteTypeVertexOutEdges
(
ret
);
...
...
@@ -477,7 +478,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
referencedTypeVertex
=
typeDefStore
.
findTypeVertexByName
(
referencedTypeName
);
if
(
referencedTypeVertex
==
null
)
{
throw
new
AtlasBaseException
(
referencedTypeName
+
": unknown datatype"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
UNKNOWN_TYPE
,
referencedTypeName
,
typeName
,
attributeDef
.
getName
()
);
}
String
label
=
AtlasGraphUtilsV1
.
getEdgeLabel
(
typeName
,
attributeDef
.
getName
());
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
View file @
fdf97ae4
...
...
@@ -20,6 +20,8 @@ package org.apache.atlas.repository.store.graph.v1;
import
com.google.common.base.Preconditions
;
import
com.google.inject.Inject
;
import
org.apache.atlas.AtlasConstants
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
...
...
@@ -232,7 +234,7 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
Iterator
<
AtlasEdge
>
inEdges
=
vertex
.
getEdges
(
AtlasEdgeDirection
.
IN
).
iterator
();
if
(
inEdges
.
hasNext
())
{
throw
new
AtlasBaseException
(
"has references"
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_HAS_REFERENCES
);
}
Iterable
<
AtlasEdge
>
edges
=
vertex
.
getEdges
(
AtlasEdgeDirection
.
OUT
);
...
...
webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java
0 → 100644
View file @
fdf97ae4
/**
* 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
.
errors
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
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
;
/**
* Exception mapper for Jersey.
* @param <E>
*/
@Provider
@Singleton
public
class
AllExceptionMapper
implements
ExceptionMapper
<
Exception
>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
AllExceptionMapper
.
class
);
@Override
public
Response
toResponse
(
Exception
exception
)
{
final
long
id
=
ThreadLocalRandom
.
current
().
nextLong
();
// Log the response and use the error codes from the Exception
ExceptionMapperUtil
.
logException
(
id
,
exception
);
return
Response
.
serverError
()
.
entity
(
ExceptionMapperUtil
.
formatErrorMessage
(
id
,
exception
))
.
build
();
}
}
webapp/src/main/java/org/apache/atlas/web/errors/
Logging
ExceptionMapper.java
→
webapp/src/main/java/org/apache/atlas/web/errors/
AtlasBase
ExceptionMapper.java
View file @
fdf97ae4
...
...
@@ -18,38 +18,59 @@
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
javax.ws.rs.WebApplicationException
;
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
java
.util.concurrent.ThreadLocalRandom
;
import
java
x.ws.rs.ext.Provider
;
/**
* Exception mapper for Jersey.
* @param <E>
*/
public
class
LoggingExceptionMapper
<
E
extends
Throwable
>
implements
ExceptionMapper
<
E
>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
LoggingExceptionMapper
.
class
);
@Provider
@Singleton
public
class
AtlasBaseExceptionMapper
implements
ExceptionMapper
<
AtlasBaseException
>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
AtlasBaseExceptionMapper
.
class
);
@Override
public
Response
toResponse
(
E
exception
)
{
if
(
exception
instanceof
WebApplicationException
)
{
return
((
WebApplicationException
)
exception
).
getResponse
();
}
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
Response
.
serverError
().
entity
(
formatErrorMessage
(
id
,
exception
)).
build
();
return
buildAtlasBaseExceptionResponse
((
AtlasBaseException
)
exception
);
}
protected
Response
buildAtlasBaseExceptionResponse
(
AtlasBaseException
baseException
)
{
Map
<
String
,
String
>
errorJsonMap
=
new
LinkedHashMap
<>();
AtlasErrorCode
errorCode
=
baseException
.
getAtlasErrorCode
();
errorJsonMap
.
put
(
"errorCode"
,
errorCode
.
getErrorCode
());
errorJsonMap
.
put
(
"errorMessage"
,
baseException
.
getMessage
());
Response
.
ResponseBuilder
responseBuilder
=
Response
.
status
(
errorCode
.
getHttpCode
());
// No body for 204 (and maybe 304)
if
(
Response
.
Status
.
NO_CONTENT
!=
errorCode
.
getHttpCode
())
{
responseBuilder
.
entity
(
AtlasType
.
toJson
(
errorJsonMap
));
}
return
responseBuilder
.
build
();
}
@SuppressWarnings
(
"UnusedParameters"
)
protected
String
formatErrorMessage
(
long
id
,
E
exception
)
{
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
,
E
exception
)
{
protected
void
logException
(
long
id
,
AtlasBaseException
exception
)
{
LOGGER
.
error
(
formatLogMessage
(
id
,
exception
),
exception
);
}
...
...
@@ -57,4 +78,5 @@ public class LoggingExceptionMapper<E extends Throwable> implements ExceptionMap
protected
String
formatLogMessage
(
long
id
,
Throwable
exception
)
{
return
String
.
format
(
"Error handling a request: %016x"
,
id
);
}
}
webapp/src/main/java/org/apache/atlas/web/errors/ExceptionMapperUtil.java
0 → 100644
View file @
fdf97ae4
/**
* 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
.
errors
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
ExceptionMapperUtil
{
protected
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ExceptionMapperUtil
.
class
);
@SuppressWarnings
(
"UnusedParameters"
)
protected
static
String
formatErrorMessage
(
long
id
,
Exception
exception
)
{
return
String
.
format
(
"There was an error processing your request. It has been logged (ID %016x)."
,
id
);
}
protected
static
void
logException
(
long
id
,
Exception
exception
)
{
LOGGER
.
error
(
formatLogMessage
(
id
,
exception
),
exception
);
}
@SuppressWarnings
(
"UnusedParameters"
)
protected
static
String
formatLogMessage
(
long
id
,
Throwable
exception
)
{
return
String
.
format
(
"Error handling a request: %016x"
,
id
);
}
}
webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
View file @
fdf97ae4
This diff is collapsed.
Click to expand it.
webapp/src/main/webapp/WEB-INF/web.xml
View file @
fdf97ae4
...
...
@@ -27,7 +27,7 @@
<context-param>
<param-name>
guice.packages
</param-name>
<param-value>
org.apache.atlas.web.resources,org.apache.atlas.web.params,org.apache.atlas.web.rest
org.apache.atlas.web.resources,org.apache.atlas.web.params,org.apache.atlas.web.rest
,org.apache.atlas.web.errors
</param-value>
</context-param>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment