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
d1109efe
Commit
d1109efe
authored
Aug 16, 2019
by
Sarath Subramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3377: Update AtlasPatchRegistry to use graph query instead of index query
parent
2223c82c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
44 deletions
+42
-44
AtlasPatchRegistry.java
...g/apache/atlas/repository/patches/AtlasPatchRegistry.java
+42
-44
No files found.
repository/src/main/java/org/apache/atlas/repository/patches/AtlasPatchRegistry.java
View file @
d1109efe
...
@@ -22,7 +22,9 @@ import org.apache.atlas.RequestContext;
...
@@ -22,7 +22,9 @@ import org.apache.atlas.RequestContext;
import
org.apache.atlas.model.patches.AtlasPatch
;
import
org.apache.atlas.model.patches.AtlasPatch
;
import
org.apache.atlas.model.patches.AtlasPatch.AtlasPatches
;
import
org.apache.atlas.model.patches.AtlasPatch.AtlasPatches
;
import
org.apache.atlas.model.patches.AtlasPatch.PatchStatus
;
import
org.apache.atlas.model.patches.AtlasPatch.PatchStatus
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasGraphQuery
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery.Result
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery.Result
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
...
@@ -45,8 +47,6 @@ import java.util.Map;
...
@@ -45,8 +47,6 @@ import java.util.Map;
import
static
org
.
apache
.
atlas
.
model
.
patches
.
AtlasPatch
.
PatchStatus
.
FAILED
;
import
static
org
.
apache
.
atlas
.
model
.
patches
.
AtlasPatch
.
PatchStatus
.
FAILED
;
import
static
org
.
apache
.
atlas
.
model
.
patches
.
AtlasPatch
.
PatchStatus
.
UNKNOWN
;
import
static
org
.
apache
.
atlas
.
model
.
patches
.
AtlasPatch
.
PatchStatus
.
UNKNOWN
;
import
static
org
.
apache
.
atlas
.
repository
.
Constants
.*;
import
static
org
.
apache
.
atlas
.
repository
.
Constants
.*;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
AtlasGraphProvider
.
getGraphInstance
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
bootstrap
.
AtlasTypeDefStoreInitializer
.
TYPEDEF_PATCH_TYPE
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v2
.
AtlasGraphUtilsV2
.
getEncodedProperty
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v2
.
AtlasGraphUtilsV2
.
getEncodedProperty
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v2
.
AtlasGraphUtilsV2
.
getIndexSearchPrefix
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v2
.
AtlasGraphUtilsV2
.
getIndexSearchPrefix
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v2
.
AtlasGraphUtilsV2
.
setEncodedProperty
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v2
.
AtlasGraphUtilsV2
.
setEncodedProperty
;
...
@@ -96,20 +96,20 @@ public class AtlasPatchRegistry {
...
@@ -96,20 +96,20 @@ public class AtlasPatchRegistry {
}
}
public
void
updateStatus
(
String
patchId
,
PatchStatus
patchStatus
)
{
public
void
updateStatus
(
String
patchId
,
PatchStatus
patchStatus
)
{
AtlasVertex
patchVertex
=
findByPatchId
(
patchId
);
try
{
AtlasVertex
patchVertex
=
findByPatchId
(
patchId
);
if
(
patchVertex
==
null
)
{
return
;
}
setEncodedProperty
(
patchVertex
,
PATCH_STATE_PROPERTY_KEY
,
patchStatus
.
toString
());
setEncodedProperty
(
patchVertex
,
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
RequestContext
.
get
().
getRequestTime
());
setEncodedProperty
(
patchVertex
,
MODIFIED_BY_KEY
,
getCurrentUser
());
setEncodedProperty
(
patchVertex
,
PATCH_STATE_PROPERTY_KEY
,
patchStatus
.
toString
());
patchNameStatusMap
.
put
(
patchId
,
patchStatus
);
if
(
patchVertex
!=
null
)
{
setEncodedProperty
(
patchVertex
,
PATCH_STATE_PROPERTY_KEY
,
patchStatus
.
toString
());
setEncodedProperty
(
patchVertex
,
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
RequestContext
.
get
().
getRequestTime
());
setEncodedProperty
(
patchVertex
,
MODIFIED_BY_KEY
,
getCurrentUser
());
setEncodedProperty
(
patchVertex
,
PATCH_STATE_PROPERTY_KEY
,
patchStatus
.
toString
());
}
}
finally
{
graph
.
commit
();
graph
.
commit
();
patchNameStatusMap
.
put
(
patchId
,
patchStatus
);
}
}
}
private
static
String
getId
(
String
incomingId
,
String
patchFile
,
int
index
)
{
private
static
String
getId
(
String
incomingId
,
String
patchFile
,
int
index
)
{
...
@@ -128,20 +128,27 @@ public class AtlasPatchRegistry {
...
@@ -128,20 +128,27 @@ public class AtlasPatchRegistry {
private
void
createOrUpdatePatchVertex
(
AtlasGraph
graph
,
String
patchId
,
String
description
,
private
void
createOrUpdatePatchVertex
(
AtlasGraph
graph
,
String
patchId
,
String
description
,
String
patchType
,
String
action
,
PatchStatus
patchStatus
)
{
String
patchType
,
String
action
,
PatchStatus
patchStatus
)
{
boolean
isPatchRegistered
=
MapUtils
.
isNotEmpty
(
patchNameStatusMap
)
&&
patchNameStatusMap
.
containsKey
(
patchId
);
try
{
AtlasVertex
patchVertex
=
isPatchRegistered
?
findByPatchId
(
patchId
)
:
graph
.
addVertex
();
AtlasVertex
patchVertex
=
findByPatchId
(
patchId
);
setEncodedProperty
(
patchVertex
,
PATCH_ID_PROPERTY_KEY
,
patchId
);
if
(
patchVertex
==
null
)
{
setEncodedProperty
(
patchVertex
,
PATCH_DESCRIPTION_PROPERTY_KEY
,
description
);
patchVertex
=
graph
.
addVertex
();
setEncodedProperty
(
patchVertex
,
PATCH_TYPE_PROPERTY_KEY
,
patchType
);
}
setEncodedProperty
(
patchVertex
,
PATCH_ACTION_PROPERTY_KEY
,
action
);
setEncodedProperty
(
patchVertex
,
PATCH_STATE_PROPERTY_KEY
,
patchStatus
.
toString
());
setEncodedProperty
(
patchVertex
,
PATCH_ID_PROPERTY_KEY
,
patchId
);
setEncodedProperty
(
patchVertex
,
TIMESTAMP_PROPERTY_KEY
,
RequestContext
.
get
().
getRequestTime
());
setEncodedProperty
(
patchVertex
,
PATCH_DESCRIPTION_PROPERTY_KEY
,
description
);
setEncodedProperty
(
patchVertex
,
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
RequestContext
.
get
().
getRequestTime
());
setEncodedProperty
(
patchVertex
,
PATCH_TYPE_PROPERTY_KEY
,
patchType
);
setEncodedProperty
(
patchVertex
,
CREATED_BY_KEY
,
AtlasTypeDefGraphStoreV2
.
getCurrentUser
());
setEncodedProperty
(
patchVertex
,
PATCH_ACTION_PROPERTY_KEY
,
action
);
setEncodedProperty
(
patchVertex
,
MODIFIED_BY_KEY
,
AtlasTypeDefGraphStoreV2
.
getCurrentUser
());
setEncodedProperty
(
patchVertex
,
PATCH_STATE_PROPERTY_KEY
,
patchStatus
.
toString
());
setEncodedProperty
(
patchVertex
,
TIMESTAMP_PROPERTY_KEY
,
RequestContext
.
get
().
getRequestTime
());
graph
.
commit
();
setEncodedProperty
(
patchVertex
,
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
RequestContext
.
get
().
getRequestTime
());
setEncodedProperty
(
patchVertex
,
CREATED_BY_KEY
,
AtlasTypeDefGraphStoreV2
.
getCurrentUser
());
setEncodedProperty
(
patchVertex
,
MODIFIED_BY_KEY
,
AtlasTypeDefGraphStoreV2
.
getCurrentUser
());
}
finally
{
graph
.
commit
();
patchNameStatusMap
.
put
(
patchId
,
patchStatus
);
}
}
}
private
static
Map
<
String
,
PatchStatus
>
getPatchNameStatusForAllRegistered
(
AtlasGraph
graph
)
{
private
static
Map
<
String
,
PatchStatus
>
getPatchNameStatusForAllRegistered
(
AtlasGraph
graph
)
{
...
@@ -170,7 +177,7 @@ public class AtlasPatchRegistry {
...
@@ -170,7 +177,7 @@ public class AtlasPatchRegistry {
while
(
results
!=
null
&&
results
.
hasNext
())
{
while
(
results
!=
null
&&
results
.
hasNext
())
{
AtlasVertex
patchVertex
=
results
.
next
().
getVertex
();
AtlasVertex
patchVertex
=
results
.
next
().
getVertex
();
AtlasPatch
patch
=
toAtlasPatch
(
patchVertex
);
AtlasPatch
patch
=
toAtlasPatch
(
patchVertex
);
ret
.
add
(
patch
);
ret
.
add
(
patch
);
}
}
...
@@ -180,10 +187,10 @@ public class AtlasPatchRegistry {
...
@@ -180,10 +187,10 @@ public class AtlasPatchRegistry {
}
}
}
catch
(
Throwable
t
)
{
}
catch
(
Throwable
t
)
{
LOG
.
warn
(
"getAllPatches(): Returned empty result!"
);
LOG
.
warn
(
"getAllPatches(): Returned empty result!"
);
}
finally
{
graph
.
commit
();
}
}
graph
.
commit
();
return
new
AtlasPatches
(
ret
);
return
new
AtlasPatches
(
ret
);
}
}
...
@@ -204,20 +211,11 @@ public class AtlasPatchRegistry {
...
@@ -204,20 +211,11 @@ public class AtlasPatchRegistry {
return
ret
;
return
ret
;
}
}
private
static
AtlasVertex
findByPatchId
(
String
patchId
)
{
public
AtlasVertex
findByPatchId
(
String
patchId
)
{
AtlasVertex
ret
=
null
;
AtlasGraphQuery
query
=
graph
.
query
().
has
(
Constants
.
PATCH_ID_PROPERTY_KEY
,
patchId
);
String
indexQuery
=
getIndexSearchPrefix
()
+
"\""
+
PATCH_ID_PROPERTY_KEY
+
"\" : ("
+
patchId
+
")"
;
Iterator
<
AtlasVertex
>
results
=
query
.
vertices
().
iterator
();
Iterator
<
Result
<
Object
,
Object
>>
results
=
getGraphInstance
().
indexQuery
(
VERTEX_INDEX
,
indexQuery
).
vertices
();
while
(
results
!=
null
&&
results
.
hasNext
())
{
ret
=
results
.
next
().
getVertex
();
if
(
ret
!=
null
)
{
return
results
.
hasNext
()
?
results
.
next
()
:
null
;
break
;
}
}
return
ret
;
}
}
private
static
PatchStatus
getPatchStatus
(
AtlasVertex
vertex
)
{
private
static
PatchStatus
getPatchStatus
(
AtlasVertex
vertex
)
{
...
...
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