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
f4574531
Commit
f4574531
authored
May 16, 2019
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3212: Importing with import transforms applied to exising entities.
parent
b0063fa5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
69 deletions
+76
-69
GraphTransaction.java
...in/java/org/apache/atlas/annotation/GraphTransaction.java
+1
-0
GraphTransactionInterceptor.java
...in/java/org/apache/atlas/GraphTransactionInterceptor.java
+11
-6
AtlasEntityStoreV2.java
...e/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
+1
-1
BulkImporterImpl.java
...che/atlas/repository/store/graph/v2/BulkImporterImpl.java
+63
-62
No files found.
common/src/main/java/org/apache/atlas/annotation/GraphTransaction.java
View file @
f4574531
...
@@ -25,4 +25,5 @@ import java.lang.annotation.Target;
...
@@ -25,4 +25,5 @@ import java.lang.annotation.Target;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
METHOD
)
@Target
(
ElementType
.
METHOD
)
public
@interface
GraphTransaction
{
public
@interface
GraphTransaction
{
boolean
logRollback
()
default
true
;
}
}
repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java
View file @
f4574531
...
@@ -20,6 +20,7 @@ package org.apache.atlas;
...
@@ -20,6 +20,7 @@ package org.apache.atlas;
import
com.google.common.annotations.VisibleForTesting
;
import
com.google.common.annotations.VisibleForTesting
;
import
org.aopalliance.intercept.MethodInterceptor
;
import
org.aopalliance.intercept.MethodInterceptor
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.apache.atlas.annotation.GraphTransaction
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.exception.NotFoundException
;
import
org.apache.atlas.exception.NotFoundException
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
...
@@ -63,6 +64,7 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
...
@@ -63,6 +64,7 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
Method
method
=
invocation
.
getMethod
();
Method
method
=
invocation
.
getMethod
();
String
invokingClass
=
method
.
getDeclaringClass
().
getSimpleName
();
String
invokingClass
=
method
.
getDeclaringClass
().
getSimpleName
();
String
invokedMethodName
=
method
.
getName
();
String
invokedMethodName
=
method
.
getName
();
boolean
logRollback
=
method
.
getAnnotation
(
GraphTransaction
.
class
).
logRollback
();
boolean
isInnerTxn
=
isTxnOpen
.
get
();
boolean
isInnerTxn
=
isTxnOpen
.
get
();
// Outermost txn marks any subsequent transaction as inner
// Outermost txn marks any subsequent transaction as inner
...
@@ -99,7 +101,7 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
...
@@ -99,7 +101,7 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
}
}
innerFailure
.
set
(
true
);
innerFailure
.
set
(
true
);
}
else
{
}
else
{
doRollback
(
t
);
doRollback
(
logRollback
,
t
);
}
}
throw
t
;
throw
t
;
}
}
...
@@ -159,12 +161,15 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
...
@@ -159,12 +161,15 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
}
}
}
}
private
void
doRollback
(
final
Throwable
t
)
{
private
void
doRollback
(
boolean
logRollback
,
final
Throwable
t
)
{
if
(
logException
(
t
))
{
if
(
logRollback
)
{
LOG
.
error
(
"graph rollback due to exception "
,
t
);
if
(
logException
(
t
))
{
}
else
{
LOG
.
error
(
"graph rollback due to exception "
,
t
);
LOG
.
error
(
"graph rollback due to exception {}:{}"
,
t
.
getClass
().
getSimpleName
(),
t
.
getMessage
());
}
else
{
LOG
.
error
(
"graph rollback due to exception {}:{}"
,
t
.
getClass
().
getSimpleName
(),
t
.
getMessage
());
}
}
}
graph
.
rollback
();
graph
.
rollback
();
}
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java
View file @
f4574531
...
@@ -276,7 +276,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
...
@@ -276,7 +276,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
}
}
@Override
@Override
@GraphTransaction
@GraphTransaction
(
logRollback
=
false
)
public
EntityMutationResponse
createOrUpdateForImport
(
EntityStream
entityStream
)
throws
AtlasBaseException
{
public
EntityMutationResponse
createOrUpdateForImport
(
EntityStream
entityStream
)
throws
AtlasBaseException
{
return
createOrUpdate
(
entityStream
,
false
,
true
);
return
createOrUpdate
(
entityStream
,
false
,
true
);
}
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/BulkImporterImpl.java
View file @
f4574531
...
@@ -6,9 +6,9 @@
...
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* with the License. You may obtain a copy of the License at
*
*
<p>
*
http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
*
<p>
* Unless required by applicable law or agreed to in writing, software
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -22,7 +22,6 @@ import org.apache.atlas.AtlasErrorCode;
...
@@ -22,7 +22,6 @@ import org.apache.atlas.AtlasErrorCode;
import
org.apache.atlas.RequestContext
;
import
org.apache.atlas.RequestContext
;
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.impexp.AtlasExportRequest
;
import
org.apache.atlas.model.impexp.AtlasImportResult
;
import
org.apache.atlas.model.impexp.AtlasImportResult
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
...
@@ -30,14 +29,12 @@ import org.apache.atlas.model.instance.AtlasEntityHeader;
...
@@ -30,14 +29,12 @@ import org.apache.atlas.model.instance.AtlasEntityHeader;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.EntityMutationResponse
;
import
org.apache.atlas.model.instance.EntityMutationResponse
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasSchemaViolationException
;
import
org.apache.atlas.repository.graphdb.AtlasSchemaViolationException
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.impexp.StartEntityFetchByExportRequest
;
import
org.apache.atlas.repository.store.graph.AtlasEntityStore
;
import
org.apache.atlas.repository.store.graph.AtlasEntityStore
;
import
org.apache.atlas.repository.store.graph.BulkImporter
;
import
org.apache.atlas.repository.store.graph.BulkImporter
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.atlas.util.AtlasGremlinQueryProvider
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -48,7 +45,6 @@ import java.util.ArrayList;
...
@@ -48,7 +45,6 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
static
org
.
apache
.
atlas
.
repository
.
Constants
.
HISTORICAL_GUID_PROPERTY_KEY
;
import
static
org
.
apache
.
atlas
.
repository
.
Constants
.
HISTORICAL_GUID_PROPERTY_KEY
;
...
@@ -59,15 +55,14 @@ public class BulkImporterImpl implements BulkImporter {
...
@@ -59,15 +55,14 @@ public class BulkImporterImpl implements BulkImporter {
private
final
AtlasEntityStore
entityStore
;
private
final
AtlasEntityStore
entityStore
;
private
final
EntityGraphRetriever
entityGraphRetriever
;
private
final
EntityGraphRetriever
entityGraphRetriever
;
private
final
Map
<
AtlasObjectId
,
String
>
objectIdExistingGuidMap
;
private
AtlasTypeRegistry
typeRegistry
;
private
final
StartEntityFetchByExportRequest
startEntityFetchByExportRequest
;
private
final
int
MAX_ATTEMPTS
=
2
;
@Inject
@Inject
public
BulkImporterImpl
(
Atlas
Graph
atlasGraph
,
Atlas
EntityStore
entityStore
,
AtlasTypeRegistry
typeRegistry
)
{
public
BulkImporterImpl
(
AtlasEntityStore
entityStore
,
AtlasTypeRegistry
typeRegistry
)
{
this
.
entityStore
=
entityStore
;
this
.
entityStore
=
entityStore
;
this
.
entityGraphRetriever
=
new
EntityGraphRetriever
(
typeRegistry
);
this
.
entityGraphRetriever
=
new
EntityGraphRetriever
(
typeRegistry
);
this
.
objectIdExistingGuidMap
=
new
HashMap
<>();
this
.
typeRegistry
=
typeRegistry
;
this
.
startEntityFetchByExportRequest
=
new
StartEntityFetchByExportRequest
(
atlasGraph
,
typeRegistry
,
AtlasGremlinQueryProvider
.
INSTANCE
);
}
}
@Override
@Override
...
@@ -80,7 +75,6 @@ public class BulkImporterImpl implements BulkImporter {
...
@@ -80,7 +75,6 @@ public class BulkImporterImpl implements BulkImporter {
throw
new
AtlasBaseException
(
AtlasErrorCode
.
INVALID_PARAMETERS
,
"no entities to create/update."
);
throw
new
AtlasBaseException
(
AtlasErrorCode
.
INVALID_PARAMETERS
,
"no entities to create/update."
);
}
}
fetchExistingEntitiesNotCreatedByImport
(
importResult
.
getExportResult
().
getRequest
());
EntityMutationResponse
ret
=
new
EntityMutationResponse
();
EntityMutationResponse
ret
=
new
EntityMutationResponse
();
ret
.
setGuidAssignments
(
new
HashMap
<>());
ret
.
setGuidAssignments
(
new
HashMap
<>());
...
@@ -98,38 +92,49 @@ public class BulkImporterImpl implements BulkImporter {
...
@@ -98,38 +92,49 @@ public class BulkImporterImpl implements BulkImporter {
continue
;
continue
;
}
}
AtlasEntityStreamForImport
oneEntityStream
=
new
AtlasEntityStreamForImport
(
entityWithExtInfo
,
entityStream
);
for
(
int
attempt
=
0
;
attempt
<
MAX_ATTEMPTS
;
attempt
++)
{
try
{
try
{
AtlasEntityStreamForImport
oneEntityStream
=
new
AtlasEntityStreamForImport
(
entityWithExtInfo
,
null
);
EntityMutationResponse
resp
=
entityStore
.
createOrUpdateForImport
(
oneEntityStream
);
EntityMutationResponse
resp
=
entityStore
.
createOrUpdateForImport
(
oneEntityStream
);
if
(
resp
.
getGuidAssignments
()
!=
null
)
{
if
(
resp
.
getGuidAssignments
()
!=
null
)
{
ret
.
getGuidAssignments
().
putAll
(
resp
.
getGuidAssignments
());
ret
.
getGuidAssignments
().
putAll
(
resp
.
getGuidAssignments
());
}
}
currentPercent
=
updateImportMetrics
(
entityWithExtInfo
,
resp
,
importResult
,
processedGuids
,
entityStream
.
getPosition
(),
entityImportStreamWithResidualList
.
getStreamSize
(),
currentPercent
);
currentPercent
=
updateImportMetrics
(
entityWithExtInfo
,
resp
,
importResult
,
processedGuids
,
entityStream
.
getPosition
(),
entityStream
.
onImportComplete
(
entity
.
getGuid
());
entityImportStreamWithResidualList
.
getStreamSize
(),
}
catch
(
AtlasBaseException
e
)
{
currentPercent
);
if
(!
updateResidualList
(
e
,
residualList
,
entityWithExtInfo
.
getEntity
().
getGuid
()))
{
throw
e
;
entityStream
.
onImportComplete
(
entity
.
getGuid
());
}
break
;
}
catch
(
AtlasSchemaViolationException
e
)
{
}
catch
(
AtlasBaseException
e
)
{
AtlasObjectId
objectId
=
entityGraphRetriever
.
toAtlasObjectIdWithoutGuid
(
entity
);
if
(!
updateResidualList
(
e
,
residualList
,
entityWithExtInfo
.
getEntity
().
getGuid
()))
{
if
(
objectIdExistingGuidMap
.
containsKey
(
objectId
))
{
throw
e
;
updateVertexGuidIfImportingToNonImportedEntity
(
entity
,
objectId
);
}
}
break
;
}
catch
(
AtlasSchemaViolationException
e
)
{
continue
;
if
(
LOG
.
isDebugEnabled
())
{
}
LOG
.
debug
(
"Entity: {}"
,
entity
.
getGuid
(),
e
);
catch
(
Throwable
e
)
{
}
AtlasBaseException
abe
=
new
AtlasBaseException
(
e
);
if
(
attempt
==
0
)
{
if
(!
updateResidualList
(
abe
,
residualList
,
entityWithExtInfo
.
getEntity
().
getGuid
()))
{
updateVertexGuid
(
entity
);
throw
abe
;
}
else
{
LOG
.
error
(
"Guid update failed: {}"
,
entityWithExtInfo
.
getEntity
().
getGuid
());
throw
e
;
}
}
catch
(
Throwable
e
)
{
AtlasBaseException
abe
=
new
AtlasBaseException
(
e
);
if
(!
updateResidualList
(
abe
,
residualList
,
entityWithExtInfo
.
getEntity
().
getGuid
()))
{
throw
abe
;
}
LOG
.
warn
(
"Exception: {}"
,
entity
.
getGuid
(),
e
);
break
;
}
finally
{
RequestContext
.
get
().
clearCache
();
}
}
}
finally
{
RequestContext
.
get
().
clearCache
();
}
}
}
}
...
@@ -139,25 +144,21 @@ public class BulkImporterImpl implements BulkImporter {
...
@@ -139,25 +144,21 @@ public class BulkImporterImpl implements BulkImporter {
return
ret
;
return
ret
;
}
}
private
void
fetchExistingEntitiesNotCreatedByImport
(
AtlasExportRequest
request
)
{
@GraphTransaction
List
<
AtlasObjectId
>
objectIds
=
startEntityFetchByExportRequest
.
get
(
request
);
public
void
updateVertexGuid
(
AtlasEntity
entity
)
{
if
(
objectIds
.
isEmpty
())
{
String
entityGuid
=
entity
.
getGuid
();
AtlasObjectId
objectId
=
entityGraphRetriever
.
toAtlasObjectIdWithoutGuid
(
entity
);
AtlasEntityType
entityType
=
typeRegistry
.
getEntityTypeByName
(
entity
.
getTypeName
());
String
vertexGuid
=
null
;
try
{
vertexGuid
=
AtlasGraphUtilsV2
.
getGuidByUniqueAttributes
(
entityType
,
objectId
.
getUniqueAttributes
());
}
catch
(
AtlasBaseException
e
)
{
LOG
.
warn
(
"Entity: {}: Does not exist!"
,
objectId
);
return
;
return
;
}
}
for
(
AtlasObjectId
objectId
:
objectIds
)
{
if
(
StringUtils
.
isEmpty
(
vertexGuid
)
||
vertexGuid
.
equals
(
entityGuid
))
{
String
existingGuid
=
objectId
.
getGuid
();
objectId
.
setGuid
(
null
);
objectIdExistingGuidMap
.
put
(
objectId
,
existingGuid
);
}
}
@GraphTransaction
public
void
updateVertexGuidIfImportingToNonImportedEntity
(
AtlasEntity
entity
,
AtlasObjectId
objectId
)
{
String
entityGuid
=
entity
.
getGuid
();
String
vertexGuid
=
objectIdExistingGuidMap
.
get
(
objectId
);
if
(
vertexGuid
.
equals
(
entityGuid
))
{
return
;
return
;
}
}
...
@@ -174,7 +175,7 @@ public class BulkImporterImpl implements BulkImporter {
...
@@ -174,7 +175,7 @@ public class BulkImporterImpl implements BulkImporter {
private
void
addHistoricalGuid
(
AtlasVertex
v
,
String
vertexGuid
)
{
private
void
addHistoricalGuid
(
AtlasVertex
v
,
String
vertexGuid
)
{
String
existingJson
=
AtlasGraphUtilsV2
.
getProperty
(
v
,
HISTORICAL_GUID_PROPERTY_KEY
,
String
.
class
);
String
existingJson
=
AtlasGraphUtilsV2
.
getProperty
(
v
,
HISTORICAL_GUID_PROPERTY_KEY
,
String
.
class
);
AtlasGraphUtilsV2
.
setProperty
(
v
,
HISTORICAL_GUID_PROPERTY_KEY
,
getJsonArray
(
existingJson
,
vertexGuid
));
AtlasGraphUtilsV2
.
setProperty
(
v
,
HISTORICAL_GUID_PROPERTY_KEY
,
getJsonArray
(
existingJson
,
vertexGuid
));
}
}
...
...
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