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
1e0962d7
Commit
1e0962d7
authored
Dec 05, 2019
by
Mandar Ambawane
Committed by
Sarath Subramanian
Dec 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3549 Add a new REST endpoint to get EntityHeader using unique attributes
Signed-off-by:
Sarath Subramanian
<
sarath@apache.org
>
parent
c95aba21
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
0 deletions
+120
-0
AtlasEntityStore.java
...apache/atlas/repository/store/graph/AtlasEntityStore.java
+3
-0
AtlasEntityStoreV2.java
...e/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
+27
-0
EntityREST.java
...p/src/main/java/org/apache/atlas/web/rest/EntityREST.java
+41
-0
TestEntityREST.java
...st/java/org/apache/atlas/web/adapters/TestEntityREST.java
+49
-0
No files found.
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
View file @
1e0962d7
...
...
@@ -72,6 +72,9 @@ public interface AtlasEntityStore {
*/
AtlasEntityHeader
getHeaderById
(
String
guid
)
throws
AtlasBaseException
;
public
AtlasEntityHeader
getEntityHeaderByUniqueAttributes
(
AtlasEntityType
entityType
,
Map
<
String
,
Object
>
uniqAttributes
)
throws
AtlasBaseException
;
/**
* Batch GET to retrieve entities by their ID
* @param guid
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
View file @
1e0962d7
...
...
@@ -264,6 +264,33 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
return
ret
;
}
@Override
@GraphTransaction
public
AtlasEntityHeader
getEntityHeaderByUniqueAttributes
(
AtlasEntityType
entityType
,
Map
<
String
,
Object
>
uniqAttributes
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> getEntityHeaderByUniqueAttributes({}, {})"
,
entityType
.
getTypeName
(),
uniqAttributes
);
}
AtlasVertex
entityVertex
=
AtlasGraphUtilsV2
.
getVertexByUniqueAttributes
(
entityType
,
uniqAttributes
);
EntityGraphRetriever
entityRetriever
=
new
EntityGraphRetriever
(
typeRegistry
);
AtlasEntityHeader
ret
=
entityRetriever
.
toAtlasEntityHeader
(
entityVertex
);
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND
,
entityType
.
getTypeName
(),
uniqAttributes
.
toString
());
}
AtlasAuthorizationUtils
.
verifyAccess
(
new
AtlasEntityAccessRequest
(
typeRegistry
,
AtlasPrivilege
.
ENTITY_READ
,
ret
),
"read entity: typeName="
,
entityType
.
getTypeName
(),
", uniqueAttributes="
,
uniqAttributes
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== getEntityHeaderByUniqueAttributes({}, {}): {}"
,
entityType
.
getTypeName
(),
uniqAttributes
,
ret
);
}
return
ret
;
}
/**
* Check state of entities in the store
* @param request AtlasCheckStateRequest
...
...
webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
View file @
1e0962d7
...
...
@@ -149,6 +149,47 @@ public class EntityREST {
}
/**
* Fetch AtlasEntityHeader given its type and unique attribute.
*
* In addition to the typeName path parameter, attribute key-value pair(s) can be provided in the following format
*
* attr:<attrName>=<attrValue>
*
* NOTE: The attrName and attrValue should be unique across entities, eg. qualifiedName
*
* The REST request would look something like this
*
* GET /v2/entity/uniqueAttribute/type/aType/header?attr:aTypeAttribute=someValue
*
* @param typeName
* @return AtlasEntityHeader
* @throws AtlasBaseException
*/
@GET
@Path
(
"/uniqueAttribute/type/{typeName}/header"
)
public
AtlasEntityHeader
getEntityHeaderByUniqueAttributes
(
@PathParam
(
"typeName"
)
String
typeName
,
@Context
HttpServletRequest
servletRequest
)
throws
AtlasBaseException
{
Servlets
.
validateQueryParamLength
(
"typeName"
,
typeName
);
AtlasPerfTracer
perf
=
null
;
try
{
Map
<
String
,
Object
>
attributes
=
getAttributes
(
servletRequest
);
if
(
AtlasPerfTracer
.
isPerfTraceEnabled
(
PERF_LOG
))
{
perf
=
AtlasPerfTracer
.
getPerfTracer
(
PERF_LOG
,
"EntityREST.getEntityHeaderByUniqueAttributes("
+
typeName
+
","
+
attributes
+
")"
);
}
AtlasEntityType
entityType
=
ensureEntityType
(
typeName
);
validateUniqueAttribute
(
entityType
,
attributes
);
return
entitiesStore
.
getEntityHeaderByUniqueAttributes
(
entityType
,
attributes
);
}
finally
{
AtlasPerfTracer
.
log
(
perf
);
}
}
/**
* Fetch complete definition of an entity given its type and unique attribute.
*
* In addition to the typeName path parameter, attribute key-value pair(s) can be provided in the following format
...
...
webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java
View file @
1e0962d7
...
...
@@ -110,6 +110,55 @@ public class TestEntityREST {
TestEntitiesREST
.
verifyAttributes
(
response
.
getEntity
().
getAttributes
(),
dbEntity
.
getAttributes
());
}
@Test
public
void
testGetEntityHeaderByUniqueAttributes
()
throws
Exception
{
createTestEntity
();
String
[]
attrVal
=
{
String
.
valueOf
(
dbEntity
.
getAttribute
(
"name"
))};
Map
<
String
,
String
[]>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"attr:name"
,
attrVal
);
HttpServletRequest
mockRequest
=
Mockito
.
mock
(
HttpServletRequest
.
class
);
Mockito
.
when
(
mockRequest
.
getParameterMap
()).
thenReturn
(
paramMap
);
AtlasEntityHeader
response
=
entityREST
.
getEntityHeaderByUniqueAttributes
(
dbEntity
.
getTypeName
(),
mockRequest
);
Assert
.
assertNotNull
(
response
);
Assert
.
assertEquals
(
dbEntity
.
getAttribute
(
"name"
),
response
.
getAttribute
(
"name"
));
Assert
.
assertEquals
(
dbEntity
.
getAttribute
(
"description"
),
response
.
getAttribute
(
"description"
));
}
@Test
(
expectedExceptions
=
AtlasBaseException
.
class
)
public
void
testGetEntityHeaderByUniqueAttributes_2
()
throws
Exception
{
createTestEntity
();
String
[]
attrVal
=
{
String
.
valueOf
(
dbEntity
.
getAttribute
(
"name"
)
+
"_2"
)};
Map
<
String
,
String
[]>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"attr:name"
,
attrVal
);
HttpServletRequest
mockRequest
=
Mockito
.
mock
(
HttpServletRequest
.
class
);
Mockito
.
when
(
mockRequest
.
getParameterMap
()).
thenReturn
(
paramMap
);
entityREST
.
getEntityHeaderByUniqueAttributes
(
dbEntity
.
getTypeName
(),
mockRequest
);
}
@Test
(
expectedExceptions
=
AtlasBaseException
.
class
)
public
void
testGetEntityHeaderByUniqueAttributes_3
()
throws
Exception
{
createTestEntity
();
String
[]
attrVal
=
{
String
.
valueOf
(
dbEntity
.
getAttribute
(
"description"
))};
Map
<
String
,
String
[]>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"attr:description"
,
attrVal
);
HttpServletRequest
mockRequest
=
Mockito
.
mock
(
HttpServletRequest
.
class
);
Mockito
.
when
(
mockRequest
.
getParameterMap
()).
thenReturn
(
paramMap
);
entityREST
.
getEntityHeaderByUniqueAttributes
(
dbEntity
.
getTypeName
(),
mockRequest
);
}
@Test
(
dependsOnMethods
=
"testGetEntityById"
)
public
void
testAddAndGetClassification
()
throws
Exception
{
...
...
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