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
0571fa42
Commit
0571fa42
authored
5 years ago
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3797: Refactoring: Improve Edge Creation.
parent
3de30f55
master
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
14 deletions
+27
-14
AtlasJanusGraph.java
...pache/atlas/repository/graphdb/janus/AtlasJanusGraph.java
+19
-5
GraphHelper.java
...n/java/org/apache/atlas/repository/graph/GraphHelper.java
+8
-9
No files found.
graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusGraph.java
View file @
0571fa42
...
...
@@ -26,6 +26,7 @@ import org.apache.atlas.AtlasErrorCode;
import
org.apache.atlas.AtlasException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.groovy.GroovyExpression
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.repository.graphdb.AtlasEdge
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasGraphIndexClient
;
...
...
@@ -85,6 +86,7 @@ import java.util.Set;
import
static
org
.
apache
.
atlas
.
repository
.
Constants
.
INDEX_SEARCH_VERTEX_PREFIX_DEFAULT
;
import
static
org
.
apache
.
atlas
.
repository
.
Constants
.
INDEX_SEARCH_VERTEX_PREFIX_PROPERTY
;
import
static
org
.
apache
.
atlas
.
repository
.
graphdb
.
janus
.
AtlasJanusGraphDatabase
.
getGraphInstance
;
import
static
org
.
apache
.
atlas
.
type
.
Constants
.
STATE_PROPERTY_KEY
;
/**
* Janus implementation of AtlasGraph.
...
...
@@ -174,12 +176,11 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
@Override
public
AtlasEdge
getEdgeBetweenVertices
(
AtlasVertex
fromVertex
,
AtlasVertex
toVertex
,
String
edgeLabel
)
{
GraphTraversal
gt
=
V
(
fromVertex
.
getId
()).
outE
(
edgeLabel
).
where
(
__
.
otherV
().
hasId
(
toVertex
.
getId
()));
Object
o
=
gt
.
hasNext
()
?
gt
.
next
()
:
null
;
if
(
o
==
null
)
{
return
null
;
}
return
GraphDbObjectFactory
.
createEdge
(
this
,
(
Edge
)
o
);
Edge
gremlinEdge
=
getFirstActiveEdge
(
gt
);
return
(
gremlinEdge
!=
null
)
?
GraphDbObjectFactory
.
createEdge
(
this
,
gremlinEdge
)
:
null
;
}
@Override
...
...
@@ -567,9 +568,22 @@ public class AtlasJanusGraph implements AtlasGraph<AtlasJanusVertex, AtlasJanusE
private
final
class
ConvertGremlinValueFunction
implements
Function
<
Object
,
Object
>
{
@Override
public
Object
apply
(
Object
input
)
{
return
convertGremlinValue
(
input
);
}
}
private
Edge
getFirstActiveEdge
(
GraphTraversal
gt
)
{
while
(
gt
.
hasNext
())
{
Edge
gremlinEdge
=
(
Edge
)
gt
.
next
();
if
(
gremlinEdge
!=
null
&&
gremlinEdge
.
property
(
STATE_PROPERTY_KEY
).
isPresent
()
&&
gremlinEdge
.
property
(
STATE_PROPERTY_KEY
).
value
().
equals
(
AtlasEntity
.
Status
.
ACTIVE
.
toString
())
)
{
return
gremlinEdge
;
}
}
return
null
;
}
}
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
View file @
0571fa42
...
...
@@ -150,21 +150,18 @@ public final class GraphHelper {
}
public
AtlasEdge
getOrCreateEdge
(
AtlasVertex
outVertex
,
AtlasVertex
inVertex
,
String
edgeLabel
)
throws
RepositoryException
{
AtlasPerfMetrics
.
MetricRecorder
metric
=
RequestContext
.
get
().
startMetricRecord
(
"getOrCreateEdge"
);
for
(
int
numRetries
=
0
;
numRetries
<
maxRetries
;
numRetries
++)
{
try
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Running edge creation attempt {}"
,
numRetries
);
}
Iterator
<
AtlasEdge
>
edges
=
getAdjacentEdgesByLabel
(
inVertex
,
AtlasEdgeDirection
.
IN
,
edgeLabel
);
while
(
edges
.
hasNext
())
{
AtlasEdge
edge
=
edges
.
next
();
if
(
edge
.
getOutVertex
().
getId
().
equals
(
outVertex
.
getId
()))
{
Id
.
EntityState
edgeState
=
getState
(
edge
);
if
(
edgeState
==
null
||
edgeState
==
Id
.
EntityState
.
ACTIVE
)
{
return
edge
;
}
if
(
inVertex
.
hasEdges
(
AtlasEdgeDirection
.
IN
,
edgeLabel
)
&&
outVertex
.
hasEdges
(
AtlasEdgeDirection
.
OUT
,
edgeLabel
))
{
AtlasEdge
edge
=
graph
.
getEdgeBetweenVertices
(
outVertex
,
inVertex
,
edgeLabel
);
if
(
edge
!=
null
)
{
return
edge
;
}
}
...
...
@@ -186,6 +183,8 @@ public final class GraphHelper {
}
}
}
RequestContext
.
get
().
endMetricRecord
(
metric
);
return
null
;
}
...
...
This diff is collapsed.
Click to expand it.
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