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
4b3c078c
Commit
4b3c078c
authored
Sep 17, 2018
by
Sarath Subramanian
Committed by
Ashutosh Mestry
Oct 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2874: Include handling of Atlas Entity Transformers in current Import logic
parent
8746b306
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
7 deletions
+83
-7
AtlasImportRequest.java
...ava/org/apache/atlas/model/impexp/AtlasImportRequest.java
+1
-0
ImportService.java
...ava/org/apache/atlas/repository/impexp/ImportService.java
+46
-4
ZipSource.java
...in/java/org/apache/atlas/repository/impexp/ZipSource.java
+36
-3
No files found.
intg/src/main/java/org/apache/atlas/model/impexp/AtlasImportRequest.java
View file @
4b3c078c
...
...
@@ -40,6 +40,7 @@ public class AtlasImportRequest implements Serializable {
private
static
final
long
serialVersionUID
=
1L
;
public
static
final
String
TRANSFORMS_KEY
=
"transforms"
;
public
static
final
String
TRANSFORMERS_KEY
=
"transformers"
;
public
static
final
String
OPTION_KEY_REPLICATED_FROM
=
"replicatedFrom"
;
private
static
final
String
START_POSITION_KEY
=
"startPosition"
;
private
static
final
String
START_GUID_KEY
=
"startGuid"
;
...
...
repository/src/main/java/org/apache/atlas/repository/impexp/ImportService.java
View file @
4b3c078c
...
...
@@ -19,15 +19,17 @@ package org.apache.atlas.repository.impexp;
import
com.google.common.annotations.VisibleForTesting
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.entitytransform.BaseEntityHandler
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.impexp.AtlasImportRequest
;
import
org.apache.atlas.model.impexp.AtlasImportResult
;
import
org.apache.atlas.model.impexp.AttributeTransform
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.repository.store.graph.BulkImporter
;
import
org.apache.atlas.store.AtlasTypeDefStore
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -40,6 +42,11 @@ import java.io.ByteArrayInputStream;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
apache
.
atlas
.
model
.
impexp
.
AtlasImportRequest
.
TRANSFORMERS_KEY
;
import
static
org
.
apache
.
atlas
.
model
.
impexp
.
AtlasImportRequest
.
TRANSFORMS_KEY
;
@Component
public
class
ImportService
{
...
...
@@ -82,9 +89,12 @@ public class ImportService {
try
{
LOG
.
info
(
"==> import(user={}, from={}, request={})"
,
userName
,
requestingIP
,
request
);
String
transforms
=
MapUtils
.
isNotEmpty
(
request
.
getOptions
())
?
request
.
getOptions
().
get
(
AtlasImportRequest
.
TRANSFORMS_KEY
)
:
null
;
String
transforms
=
MapUtils
.
isNotEmpty
(
request
.
getOptions
())
?
request
.
getOptions
().
get
(
TRANSFORMS_KEY
)
:
null
;
setImportTransform
(
source
,
transforms
);
String
transformers
=
MapUtils
.
isNotEmpty
(
request
.
getOptions
())
?
request
.
getOptions
().
get
(
TRANSFORMERS_KEY
)
:
null
;
setEntityTransformerHandlers
(
source
,
transformers
);
startTimestamp
=
System
.
currentTimeMillis
();
processTypes
(
source
.
getTypesDef
(),
result
);
setStartPosition
(
request
,
source
);
...
...
@@ -121,6 +131,38 @@ public class ImportService {
}
private
void
setEntityTransformerHandlers
(
ZipSource
source
,
String
transformersString
)
{
if
(
StringUtils
.
isEmpty
(
transformersString
))
{
return
;
}
Object
transformersObj
=
AtlasType
.
fromJson
(
transformersString
,
Object
.
class
);
List
transformers
=
(
transformersObj
!=
null
&&
transformersObj
instanceof
List
)
?
(
List
)
transformersObj
:
null
;
List
<
AttributeTransform
>
attributeTransforms
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
transformers
))
{
for
(
Object
transformer
:
transformers
)
{
String
transformerStr
=
AtlasType
.
toJson
(
transformer
);
AttributeTransform
attributeTransform
=
AtlasType
.
fromJson
(
transformerStr
,
AttributeTransform
.
class
);
if
(
attributeTransform
==
null
)
{
continue
;
}
attributeTransforms
.
add
(
attributeTransform
);
}
}
if
(
CollectionUtils
.
isNotEmpty
(
attributeTransforms
))
{
List
<
BaseEntityHandler
>
entityHandlers
=
BaseEntityHandler
.
createEntityHandlers
(
attributeTransforms
);
if
(
CollectionUtils
.
isNotEmpty
(
entityHandlers
))
{
source
.
setEntityHandlers
(
entityHandlers
);
}
}
}
private
void
debugLog
(
String
s
,
Object
...
params
)
{
if
(!
LOG
.
isDebugEnabled
())
return
;
...
...
@@ -148,7 +190,7 @@ public class ImportService {
try
{
LOG
.
info
(
"==> import(user={}, from={}, fileName={})"
,
userName
,
requestingIP
,
fileName
);
String
transforms
=
MapUtils
.
isNotEmpty
(
request
.
getOptions
())
?
request
.
getOptions
().
get
(
AtlasImportRequest
.
TRANSFORMS_KEY
)
:
null
;
String
transforms
=
MapUtils
.
isNotEmpty
(
request
.
getOptions
())
?
request
.
getOptions
().
get
(
TRANSFORMS_KEY
)
:
null
;
File
file
=
new
File
(
fileName
);
ZipSource
source
=
new
ZipSource
(
new
ByteArrayInputStream
(
FileUtils
.
readFileToByteArray
(
file
)),
ImportTransforms
.
fromJson
(
transforms
));
result
=
run
(
source
,
request
,
userName
,
hostName
,
requestingIP
);
...
...
repository/src/main/java/org/apache/atlas/repository/impexp/ZipSource.java
View file @
4b3c078c
...
...
@@ -17,6 +17,7 @@
*/
package
org
.
apache
.
atlas
.
repository
.
impexp
;
import
org.apache.atlas.entitytransform.BaseEntityHandler
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.impexp.AtlasExportResult
;
import
org.apache.atlas.model.instance.AtlasEntity
;
...
...
@@ -24,6 +25,7 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.repository.store.graph.v2.EntityImportStream
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -47,6 +49,7 @@ public class ZipSource implements EntityImportStream {
private
Iterator
<
String
>
iterator
;
private
Map
<
String
,
String
>
guidEntityJsonMap
;
private
ImportTransforms
importTransform
;
private
List
<
BaseEntityHandler
>
entityHandlers
;
private
int
currentPosition
;
public
ZipSource
(
InputStream
inputStream
)
throws
IOException
{
...
...
@@ -68,6 +71,14 @@ public class ZipSource implements EntityImportStream {
this
.
importTransform
=
importTransform
;
}
public
List
<
BaseEntityHandler
>
getEntityHandlers
()
{
return
entityHandlers
;
}
public
void
setEntityHandlers
(
List
<
BaseEntityHandler
>
entityHandlers
)
{
this
.
entityHandlers
=
entityHandlers
;
}
public
AtlasTypesDef
getTypesDef
()
throws
AtlasBaseException
{
final
String
fileName
=
ZipExportFileNames
.
ATLAS_TYPESDEF_NAME
.
toString
();
...
...
@@ -123,17 +134,39 @@ public class ZipSource implements EntityImportStream {
return
this
.
creationOrder
;
}
public
AtlasEntity
.
AtlasEntity
WithExtInfo
getEntityWithExtInfo
(
String
guid
)
throws
AtlasBaseException
{
public
AtlasEntityWithExtInfo
getEntityWithExtInfo
(
String
guid
)
throws
AtlasBaseException
{
String
s
=
getFromCache
(
guid
);
AtlasEntity
.
AtlasEntityWithExtInfo
entityWithExtInfo
=
convertFromJson
(
AtlasEntity
.
AtlasEntityWithExtInfo
.
class
,
s
);
AtlasEntity
WithExtInfo
entityWithExtInfo
=
convertFromJson
(
AtlasEntityWithExtInfo
.
class
,
s
);
if
(
importTransform
!=
null
)
{
if
(
entityHandlers
!=
null
)
{
applyTransformers
(
entityWithExtInfo
);
}
else
if
(
importTransform
!=
null
)
{
entityWithExtInfo
=
importTransform
.
apply
(
entityWithExtInfo
);
}
return
entityWithExtInfo
;
}
private
void
applyTransformers
(
AtlasEntityWithExtInfo
entityWithExtInfo
)
{
if
(
entityWithExtInfo
==
null
)
{
return
;
}
transform
(
entityWithExtInfo
.
getEntity
());
if
(
MapUtils
.
isNotEmpty
(
entityWithExtInfo
.
getReferredEntities
()))
{
for
(
AtlasEntity
e
:
entityWithExtInfo
.
getReferredEntities
().
values
())
{
transform
(
e
);
}
}
}
private
void
transform
(
AtlasEntity
e
)
{
for
(
BaseEntityHandler
handler
:
entityHandlers
)
{
handler
.
transform
(
e
);
}
}
private
<
T
>
T
convertFromJson
(
Class
<
T
>
clazz
,
String
jsonData
)
throws
AtlasBaseException
{
T
t
;
try
{
...
...
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