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
b93c29c3
Commit
b93c29c3
authored
Apr 26, 2018
by
Sarath Subramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2619: Add query param in relationship GET API to get extended info about referred entities
parent
6d51ddec
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
7 deletions
+128
-7
AtlasRelationship.java
...va/org/apache/atlas/model/instance/AtlasRelationship.java
+87
-0
AtlasRelationshipStore.java
.../atlas/repository/store/graph/AtlasRelationshipStore.java
+8
-0
AtlasRelationshipStoreV1.java
...s/repository/store/graph/v1/AtlasRelationshipStoreV1.java
+19
-5
EntityGraphRetriever.java
...atlas/repository/store/graph/v1/EntityGraphRetriever.java
+0
-0
RelationshipREST.java
...main/java/org/apache/atlas/web/rest/RelationshipREST.java
+14
-2
No files found.
intg/src/main/java/org/apache/atlas/model/instance/AtlasRelationship.java
View file @
b93c29c3
...
@@ -32,6 +32,7 @@ import javax.xml.bind.annotation.XmlRootElement;
...
@@ -32,6 +32,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Objects
;
...
@@ -407,4 +408,89 @@ public class AtlasRelationship extends AtlasStruct implements Serializable {
...
@@ -407,4 +408,89 @@ public class AtlasRelationship extends AtlasStruct implements Serializable {
public
String
toString
()
{
public
String
toString
()
{
return
toString
(
new
StringBuilder
()).
toString
();
return
toString
(
new
StringBuilder
()).
toString
();
}
}
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
static
class
AtlasRelationshipWithExtInfo
implements
Serializable
{
private
AtlasRelationship
relationship
;
private
Map
<
String
,
AtlasEntityHeader
>
referredEntities
;
public
AtlasRelationshipWithExtInfo
()
{
}
public
AtlasRelationshipWithExtInfo
(
AtlasRelationship
relationship
)
{
setRelationship
(
relationship
);
}
public
AtlasRelationship
getRelationship
()
{
return
relationship
;
}
public
void
setRelationship
(
AtlasRelationship
relationship
)
{
this
.
relationship
=
relationship
;
}
public
Map
<
String
,
AtlasEntityHeader
>
getReferredEntities
()
{
return
referredEntities
;
}
public
void
setReferredEntities
(
Map
<
String
,
AtlasEntityHeader
>
referredEntities
)
{
this
.
referredEntities
=
referredEntities
;
}
public
boolean
referredEntitiesContains
(
String
guid
)
{
return
(
referredEntities
!=
null
)
?
referredEntities
.
containsKey
(
guid
)
:
false
;
}
@JsonIgnore
public
final
void
addReferredEntity
(
String
guid
,
AtlasEntityHeader
entityHeader
)
{
Map
<
String
,
AtlasEntityHeader
>
r
=
this
.
referredEntities
;
if
(
r
==
null
)
{
r
=
new
HashMap
<>();
this
.
referredEntities
=
r
;
}
if
(
guid
!=
null
)
{
r
.
put
(
guid
,
entityHeader
);
}
}
@JsonIgnore
public
final
AtlasEntityHeader
removeReferredEntity
(
String
guid
)
{
Map
<
String
,
AtlasEntityHeader
>
r
=
this
.
referredEntities
;
return
r
!=
null
&&
guid
!=
null
?
r
.
remove
(
guid
)
:
null
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
{
return
false
;
}
if
(!
super
.
equals
(
o
))
{
return
false
;
}
AtlasRelationshipWithExtInfo
that
=
(
AtlasRelationshipWithExtInfo
)
o
;
return
Objects
.
equals
(
relationship
,
that
.
relationship
)
&&
Objects
.
equals
(
referredEntities
,
that
.
referredEntities
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
super
.
hashCode
(),
relationship
,
referredEntities
);
}
@Override
public
String
toString
()
{
final
StringBuilder
sb
=
new
StringBuilder
(
"AtlasRelationshipWithExtInfo{"
);
sb
.
append
(
"relationship="
).
append
(
relationship
);
sb
.
append
(
", referredEntities="
).
append
(
referredEntities
);
sb
.
append
(
'}'
);
return
sb
.
toString
();
}
}
}
}
\ No newline at end of file
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasRelationshipStore.java
View file @
b93c29c3
...
@@ -19,6 +19,7 @@ package org.apache.atlas.repository.store.graph;
...
@@ -19,6 +19,7 @@ package org.apache.atlas.repository.store.graph;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasRelationship
;
import
org.apache.atlas.model.instance.AtlasRelationship
;
import
org.apache.atlas.model.instance.AtlasRelationship.AtlasRelationshipWithExtInfo
;
import
org.apache.atlas.repository.graphdb.AtlasEdge
;
import
org.apache.atlas.repository.graphdb.AtlasEdge
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
...
@@ -48,6 +49,13 @@ public interface AtlasRelationshipStore {
...
@@ -48,6 +49,13 @@ public interface AtlasRelationshipStore {
*/
*/
AtlasRelationship
getById
(
String
guid
)
throws
AtlasBaseException
;
AtlasRelationship
getById
(
String
guid
)
throws
AtlasBaseException
;
/**
* Retrieve a relationship instance and its referred entities using guid.
* @param guid relationship instance guid
* @return AtlasRelationship
*/
AtlasRelationshipWithExtInfo
getExtInfoById
(
String
guid
)
throws
AtlasBaseException
;
AtlasEdge
getOrCreate
(
AtlasVertex
end1Vertex
,
AtlasVertex
end2Vertex
,
AtlasRelationship
relationship
)
throws
AtlasBaseException
;
AtlasEdge
getOrCreate
(
AtlasVertex
end1Vertex
,
AtlasVertex
end2Vertex
,
AtlasRelationship
relationship
)
throws
AtlasBaseException
;
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipStoreV1.java
View file @
b93c29c3
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.RequestContextV1
;
import
org.apache.atlas.annotation.GraphTransaction
;
import
org.apache.atlas.annotation.GraphTransaction
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.TypeCategory
;
import
org.apache.atlas.model.TypeCategory
;
...
@@ -27,6 +26,7 @@ import org.apache.atlas.model.instance.AtlasClassification;
...
@@ -27,6 +26,7 @@ import org.apache.atlas.model.instance.AtlasClassification;
import
org.apache.atlas.model.instance.AtlasEntity.Status
;
import
org.apache.atlas.model.instance.AtlasEntity.Status
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasRelationship
;
import
org.apache.atlas.model.instance.AtlasRelationship
;
import
org.apache.atlas.model.instance.AtlasRelationship.AtlasRelationshipWithExtInfo
;
import
org.apache.atlas.model.typedef.AtlasRelationshipDef
;
import
org.apache.atlas.model.typedef.AtlasRelationshipDef
;
import
org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags
;
import
org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags
;
import
org.apache.atlas.model.typedef.AtlasRelationshipEndDef
;
import
org.apache.atlas.model.typedef.AtlasRelationshipEndDef
;
...
@@ -204,14 +204,28 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
...
@@ -204,14 +204,28 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
LOG
.
debug
(
"==> getById({})"
,
guid
);
LOG
.
debug
(
"==> getById({})"
,
guid
);
}
}
AtlasRelationship
ret
;
AtlasEdge
edge
=
graphHelper
.
getEdgeForGUID
(
guid
);
AtlasRelationship
ret
=
entityRetriever
.
mapEdgeToAtlasRelationship
(
edge
);
AtlasEdge
edge
=
graphHelper
.
getEdgeForGUID
(
guid
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== getById({}): {}"
,
guid
,
ret
);
}
ret
=
entityRetriever
.
mapEdgeToAtlasRelationship
(
edge
);
return
ret
;
}
@Override
@GraphTransaction
public
AtlasRelationshipWithExtInfo
getExtInfoById
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== getById({}): {}"
,
guid
,
ret
);
LOG
.
debug
(
"==> getExtInfoById({})"
,
guid
);
}
AtlasEdge
edge
=
graphHelper
.
getEdgeForGUID
(
guid
);
AtlasRelationshipWithExtInfo
ret
=
entityRetriever
.
mapEdgeToAtlasRelationshipWithExtInfo
(
edge
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== getExtInfoById({}): {}"
,
guid
,
ret
);
}
}
return
ret
;
return
ret
;
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
View file @
b93c29c3
This diff is collapsed.
Click to expand it.
webapp/src/main/java/org/apache/atlas/web/rest/RelationshipREST.java
View file @
b93c29c3
...
@@ -20,6 +20,7 @@ package org.apache.atlas.web.rest;
...
@@ -20,6 +20,7 @@ package org.apache.atlas.web.rest;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasRelationship
;
import
org.apache.atlas.model.instance.AtlasRelationship
;
import
org.apache.atlas.model.instance.AtlasRelationship.AtlasRelationshipWithExtInfo
;
import
org.apache.atlas.repository.store.graph.AtlasRelationshipStore
;
import
org.apache.atlas.repository.store.graph.AtlasRelationshipStore
;
import
org.apache.atlas.utils.AtlasPerfTracer
;
import
org.apache.atlas.utils.AtlasPerfTracer
;
import
org.apache.atlas.web.util.Servlets
;
import
org.apache.atlas.web.util.Servlets
;
...
@@ -30,12 +31,14 @@ import javax.inject.Inject;
...
@@ -30,12 +31,14 @@ import javax.inject.Inject;
import
javax.inject.Singleton
;
import
javax.inject.Singleton
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.DefaultValue
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.PUT
;
import
javax.ws.rs.PUT
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.QueryParam
;
/**
/**
* REST interface for entity relationships.
* REST interface for entity relationships.
...
@@ -102,18 +105,27 @@ public class RelationshipREST {
...
@@ -102,18 +105,27 @@ public class RelationshipREST {
@Path
(
"/guid/{guid}"
)
@Path
(
"/guid/{guid}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasRelationship
getById
(
@PathParam
(
"guid"
)
String
guid
)
throws
AtlasBaseException
{
public
AtlasRelationshipWithExtInfo
getById
(
@PathParam
(
"guid"
)
String
guid
,
@QueryParam
(
"extendedInfo"
)
@DefaultValue
(
"false"
)
boolean
extendedInfo
)
throws
AtlasBaseException
{
Servlets
.
validateQueryParamLength
(
"guid"
,
guid
);
Servlets
.
validateQueryParamLength
(
"guid"
,
guid
);
AtlasPerfTracer
perf
=
null
;
AtlasPerfTracer
perf
=
null
;
AtlasRelationshipWithExtInfo
ret
;
try
{
try
{
if
(
AtlasPerfTracer
.
isPerfTraceEnabled
(
PERF_LOG
))
{
if
(
AtlasPerfTracer
.
isPerfTraceEnabled
(
PERF_LOG
))
{
perf
=
AtlasPerfTracer
.
getPerfTracer
(
PERF_LOG
,
"RelationshipREST.getById("
+
guid
+
")"
);
perf
=
AtlasPerfTracer
.
getPerfTracer
(
PERF_LOG
,
"RelationshipREST.getById("
+
guid
+
")"
);
}
}
return
relationshipStore
.
getById
(
guid
);
if
(
extendedInfo
)
{
ret
=
relationshipStore
.
getExtInfoById
(
guid
);
}
else
{
ret
=
new
AtlasRelationshipWithExtInfo
(
relationshipStore
.
getById
(
guid
));
}
return
ret
;
}
finally
{
}
finally
{
AtlasPerfTracer
.
log
(
perf
);
AtlasPerfTracer
.
log
(
perf
);
}
}
...
...
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