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
31125c58
Commit
31125c58
authored
4 years ago
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-4024: Export Service: Export of terms.
Signed-off-by:
Ashutosh Mestry
<
amestry@cloudera.com
>
parent
9cdc31d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
4 deletions
+79
-4
ExportService.java
...ava/org/apache/atlas/repository/impexp/ExportService.java
+40
-3
ExportTypeProcessor.java
...g/apache/atlas/repository/impexp/ExportTypeProcessor.java
+39
-1
No files found.
repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
View file @
31125c58
...
...
@@ -20,6 +20,7 @@ package org.apache.atlas.repository.impexp;
import
com.google.common.annotations.VisibleForTesting
;
import
org.apache.atlas.RequestContext
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.glossary.GlossaryService
;
import
org.apache.atlas.model.impexp.AtlasExportRequest
;
import
org.apache.atlas.model.impexp.AtlasExportResult
;
import
org.apache.atlas.model.instance.AtlasEntity
;
...
...
@@ -38,6 +39,7 @@ import org.apache.atlas.repository.util.UniqueList;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.atlas.util.AtlasGremlinQueryProvider
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.MapUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
...
...
@@ -65,14 +67,17 @@ public class ExportService {
private
final
EntityGraphRetriever
entityGraphRetriever
;
private
ExportTypeProcessor
exportTypeProcessor
;
private
final
HdfsPathEntityCreator
hdfsPathEntityCreator
;
private
final
GlossaryService
glossaryService
;
@Inject
public
ExportService
(
final
AtlasTypeRegistry
typeRegistry
,
AtlasGraph
graph
,
AuditsWriter
auditsWriter
,
HdfsPathEntityCreator
hdfsPathEntityCreator
)
{
AuditsWriter
auditsWriter
,
HdfsPathEntityCreator
hdfsPathEntityCreator
,
GlossaryService
glossaryService
)
{
this
.
typeRegistry
=
typeRegistry
;
this
.
entityGraphRetriever
=
new
EntityGraphRetriever
(
graph
,
this
.
typeRegistry
);
this
.
auditsWriter
=
auditsWriter
;
this
.
hdfsPathEntityCreator
=
hdfsPathEntityCreator
;
this
.
glossaryService
=
glossaryService
;
this
.
startEntityFetchByExportRequest
=
new
StartEntityFetchByExportRequest
(
graph
,
typeRegistry
,
AtlasGremlinQueryProvider
.
INSTANCE
);
this
.
entitiesExtractor
=
new
EntitiesExtractor
(
graph
,
typeRegistry
);
}
...
...
@@ -84,7 +89,7 @@ public class ExportService {
hostName
,
startTime
,
getCurrentChangeMarker
());
ExportContext
context
=
new
ExportContext
(
result
,
exportSink
);
exportTypeProcessor
=
new
ExportTypeProcessor
(
typeRegistry
);
exportTypeProcessor
=
new
ExportTypeProcessor
(
typeRegistry
,
glossaryService
);
try
{
LOG
.
info
(
"==> export(user={}, from={})"
,
userName
,
requestingIP
);
...
...
@@ -264,8 +269,12 @@ public class ExportService {
}
public
void
processEntity
(
AtlasEntityWithExtInfo
entityWithExtInfo
,
ExportContext
context
)
throws
AtlasBaseException
{
addEntity
(
entityWithExtInfo
,
context
);
exportTypeProcessor
.
addTypes
(
entityWithExtInfo
.
getEntity
(),
context
);
if
(
MapUtils
.
isNotEmpty
(
context
.
termsGlossary
))
{
addGlossaryEntities
(
context
);
}
addEntity
(
entityWithExtInfo
,
context
);
context
.
guidsProcessed
.
add
(
entityWithExtInfo
.
getEntity
().
getGuid
());
entitiesExtractor
.
get
(
entityWithExtInfo
.
getEntity
(),
context
);
...
...
@@ -280,6 +289,28 @@ public class ExportService {
}
}
private
void
addGlossaryEntities
(
ExportContext
context
)
{
try
{
for
(
String
termGuid
:
context
.
termsGlossary
.
keySet
())
{
try
{
String
glossaryGuid
=
context
.
termsGlossary
.
get
(
termGuid
);
if
(!
context
.
sink
.
hasEntity
(
glossaryGuid
))
{
AtlasEntity
glossary
=
entityGraphRetriever
.
toAtlasEntity
(
glossaryGuid
);
addEntity
(
new
AtlasEntityWithExtInfo
(
glossary
),
context
);
}
if
(!
context
.
sink
.
hasEntity
(
termGuid
))
{
AtlasEntity
term
=
entityGraphRetriever
.
toAtlasEntity
(
termGuid
);
addEntity
(
new
AtlasEntityWithExtInfo
(
term
),
context
);
}
}
catch
(
AtlasBaseException
exception
)
{
LOG
.
error
(
"Error fetching Glossary for term: {}"
,
termGuid
);
}
}
}
finally
{
context
.
clearTerms
();
}
}
private
void
addEntity
(
AtlasEntityWithExtInfo
entityWithExtInfo
,
ExportContext
context
)
throws
AtlasBaseException
{
if
(
context
.
sink
.
hasEntity
(
entityWithExtInfo
.
getEntity
().
getGuid
()))
{
...
...
@@ -355,6 +386,8 @@ public class ExportService {
final
Set
<
String
>
enumTypes
=
new
HashSet
<>();
final
Set
<
String
>
relationshipTypes
=
new
HashSet
<>();
final
Set
<
String
>
businessMetadataTypes
=
new
HashSet
<>();
final
Map
<
String
,
String
>
termsGlossary
=
new
HashMap
<>();
final
AtlasExportResult
result
;
private
final
ZipSink
sink
;
...
...
@@ -471,5 +504,9 @@ public class ExportService {
public
void
addToEntityCreationOrder
(
String
guid
)
{
entityCreationOrder
.
add
(
guid
);
}
public
void
clearTerms
()
{
termsGlossary
.
clear
();
}
}
}
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/impexp/ExportTypeProcessor.java
View file @
31125c58
...
...
@@ -19,9 +19,13 @@
package
org
.
apache
.
atlas
.
repository
.
impexp
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.glossary.GlossaryService
;
import
org.apache.atlas.model.TypeCategory
;
import
org.apache.atlas.model.glossary.AtlasGlossaryTerm
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasRelatedObjectId
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.type.AtlasArrayType
;
import
org.apache.atlas.type.AtlasBusinessMetadataType
;
...
...
@@ -37,15 +41,21 @@ import org.apache.commons.collections.CollectionUtils;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
class
ExportTypeProcessor
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ExportTypeProcessor
.
class
);
private
static
final
String
RELATIONSHIP_ATTR_MEANINGS
=
"meanings"
;
private
AtlasTypeRegistry
typeRegistry
;
private
GlossaryService
glossaryService
;
ExportTypeProcessor
(
AtlasTypeRegistry
typeRegistry
)
{
ExportTypeProcessor
(
AtlasTypeRegistry
typeRegistry
,
GlossaryService
glossaryService
)
{
this
.
typeRegistry
=
typeRegistry
;
this
.
glossaryService
=
glossaryService
;
}
public
void
addTypes
(
AtlasEntity
entity
,
ExportService
.
ExportContext
context
)
{
...
...
@@ -56,6 +66,34 @@ class ExportTypeProcessor {
addClassificationType
(
c
.
getTypeName
(),
context
);
}
}
addTerms
(
entity
,
context
);
}
private
void
addTerms
(
AtlasEntity
entity
,
ExportService
.
ExportContext
context
)
{
Object
relAttrMeanings
=
entity
.
getRelationshipAttribute
(
RELATIONSHIP_ATTR_MEANINGS
);
if
(
relAttrMeanings
==
null
||
!(
relAttrMeanings
instanceof
List
))
{
return
;
}
List
list
=
(
List
)
relAttrMeanings
;
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
;
}
for
(
Object
objectId
:
list
)
{
if
(
objectId
instanceof
AtlasRelatedObjectId
)
{
AtlasRelatedObjectId
termObjectId
=
(
AtlasRelatedObjectId
)
objectId
;
try
{
AtlasGlossaryTerm
term
=
glossaryService
.
getTerm
(
termObjectId
.
getGuid
());
context
.
termsGlossary
.
put
(
termObjectId
.
getGuid
(),
term
.
getAnchor
().
getGlossaryGuid
());
}
catch
(
AtlasBaseException
e
)
{
LOG
.
warn
(
"Error fetching term details: {}"
,
termObjectId
);
}
}
}
}
private
void
addType
(
String
typeName
,
ExportService
.
ExportContext
context
)
{
...
...
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