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
34d235f3
Commit
34d235f3
authored
8 years ago
by
Madhan Neethiraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1471: avoid unnecessary overhead in debug log calls
parent
9c0c46db
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
365 additions
and
133 deletions
+365
-133
DeleteHandler.java
...java/org/apache/atlas/repository/graph/DeleteHandler.java
+40
-13
FullTextMapper.java
...ava/org/apache/atlas/repository/graph/FullTextMapper.java
+8
-2
GraphBackedMetadataRepository.java
...atlas/repository/graph/GraphBackedMetadataRepository.java
+34
-9
GraphBackedSearchIndexer.java
...ache/atlas/repository/graph/GraphBackedSearchIndexer.java
+18
-10
GraphHelper.java
...n/java/org/apache/atlas/repository/graph/GraphHelper.java
+114
-53
GraphToTypedInstanceMapper.java
...he/atlas/repository/graph/GraphToTypedInstanceMapper.java
+73
-22
TypedInstanceToGraphMapper.java
...he/atlas/repository/graph/TypedInstanceToGraphMapper.java
+78
-24
No files found.
repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java
View file @
34d235f3
...
@@ -79,8 +79,11 @@ public abstract class DeleteHandler {
...
@@ -79,8 +79,11 @@ public abstract class DeleteHandler {
String
guid
=
GraphHelper
.
getGuid
(
instanceVertex
);
String
guid
=
GraphHelper
.
getGuid
(
instanceVertex
);
Id
.
EntityState
state
=
GraphHelper
.
getState
(
instanceVertex
);
Id
.
EntityState
state
=
GraphHelper
.
getState
(
instanceVertex
);
if
(
requestContext
.
getDeletedEntityIds
().
contains
(
guid
)
||
state
==
Id
.
EntityState
.
DELETED
)
{
if
(
requestContext
.
getDeletedEntityIds
().
contains
(
guid
)
||
state
==
Id
.
EntityState
.
DELETED
)
{
LOG
.
debug
(
"Skipping deletion of {} as it is already deleted"
,
guid
);
if
(
LOG
.
isDebugEnabled
())
{
continue
;
LOG
.
debug
(
"Skipping deletion of {} as it is already deleted"
,
guid
);
}
continue
;
}
}
// Get GUIDs and vertices for all deletion candidates.
// Get GUIDs and vertices for all deletion candidates.
...
@@ -131,13 +134,19 @@ public abstract class DeleteHandler {
...
@@ -131,13 +134,19 @@ public abstract class DeleteHandler {
* @throws AtlasException
* @throws AtlasException
*/
*/
protected
void
deleteTypeVertex
(
AtlasVertex
instanceVertex
,
boolean
force
)
throws
AtlasException
{
protected
void
deleteTypeVertex
(
AtlasVertex
instanceVertex
,
boolean
force
)
throws
AtlasException
{
LOG
.
debug
(
"Deleting {}"
,
string
(
instanceVertex
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Deleting {}"
,
string
(
instanceVertex
));
}
String
typeName
=
GraphHelper
.
getTypeName
(
instanceVertex
);
String
typeName
=
GraphHelper
.
getTypeName
(
instanceVertex
);
IDataType
type
=
typeSystem
.
getDataType
(
IDataType
.
class
,
typeName
);
IDataType
type
=
typeSystem
.
getDataType
(
IDataType
.
class
,
typeName
);
FieldMapping
fieldMapping
=
getFieldMapping
(
type
);
FieldMapping
fieldMapping
=
getFieldMapping
(
type
);
for
(
AttributeInfo
attributeInfo
:
fieldMapping
.
fields
.
values
())
{
for
(
AttributeInfo
attributeInfo
:
fieldMapping
.
fields
.
values
())
{
LOG
.
debug
(
"Deleting attribute {} for {}"
,
attributeInfo
.
name
,
string
(
instanceVertex
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Deleting attribute {} for {}"
,
attributeInfo
.
name
,
string
(
instanceVertex
));
}
String
edgeLabel
=
GraphHelper
.
getEdgeLabel
(
type
,
attributeInfo
);
String
edgeLabel
=
GraphHelper
.
getEdgeLabel
(
type
,
attributeInfo
);
switch
(
attributeInfo
.
dataType
().
getTypeCategory
())
{
switch
(
attributeInfo
.
dataType
().
getTypeCategory
())
{
...
@@ -200,7 +209,10 @@ public abstract class DeleteHandler {
...
@@ -200,7 +209,10 @@ public abstract class DeleteHandler {
*/
*/
public
boolean
deleteEdgeReference
(
AtlasEdge
edge
,
DataTypes
.
TypeCategory
typeCategory
,
boolean
isComposite
,
public
boolean
deleteEdgeReference
(
AtlasEdge
edge
,
DataTypes
.
TypeCategory
typeCategory
,
boolean
isComposite
,
boolean
forceDeleteStructTrait
)
throws
AtlasException
{
boolean
forceDeleteStructTrait
)
throws
AtlasException
{
LOG
.
debug
(
"Deleting {}"
,
string
(
edge
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Deleting {}"
,
string
(
edge
));
}
boolean
forceDelete
=
boolean
forceDelete
=
(
typeCategory
==
DataTypes
.
TypeCategory
.
STRUCT
||
typeCategory
==
DataTypes
.
TypeCategory
.
TRAIT
)
&&
forceDeleteStructTrait
;
(
typeCategory
==
DataTypes
.
TypeCategory
.
STRUCT
||
typeCategory
==
DataTypes
.
TypeCategory
.
TRAIT
)
&&
forceDeleteStructTrait
;
if
(
typeCategory
==
DataTypes
.
TypeCategory
.
STRUCT
||
typeCategory
==
DataTypes
.
TypeCategory
.
TRAIT
if
(
typeCategory
==
DataTypes
.
TypeCategory
.
STRUCT
||
typeCategory
==
DataTypes
.
TypeCategory
.
TRAIT
...
@@ -247,7 +259,9 @@ public abstract class DeleteHandler {
...
@@ -247,7 +259,9 @@ public abstract class DeleteHandler {
protected
void
deleteVertex
(
AtlasVertex
instanceVertex
,
boolean
force
)
throws
AtlasException
{
protected
void
deleteVertex
(
AtlasVertex
instanceVertex
,
boolean
force
)
throws
AtlasException
{
//Update external references(incoming edges) to this vertex
//Update external references(incoming edges) to this vertex
LOG
.
debug
(
"Setting the external references to {} to null(removing edges)"
,
string
(
instanceVertex
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Setting the external references to {} to null(removing edges)"
,
string
(
instanceVertex
));
}
for
(
AtlasEdge
edge
:
(
Iterable
<
AtlasEdge
>)
instanceVertex
.
getEdges
(
AtlasEdgeDirection
.
IN
))
{
for
(
AtlasEdge
edge
:
(
Iterable
<
AtlasEdge
>)
instanceVertex
.
getEdges
(
AtlasEdgeDirection
.
IN
))
{
Id
.
EntityState
edgeState
=
GraphHelper
.
getState
(
edge
);
Id
.
EntityState
edgeState
=
GraphHelper
.
getState
(
edge
);
...
@@ -271,8 +285,11 @@ public abstract class DeleteHandler {
...
@@ -271,8 +285,11 @@ public abstract class DeleteHandler {
* @throws AtlasException
* @throws AtlasException
*/
*/
protected
void
deleteEdgeBetweenVertices
(
AtlasVertex
outVertex
,
AtlasVertex
inVertex
,
String
attributeName
)
throws
AtlasException
{
protected
void
deleteEdgeBetweenVertices
(
AtlasVertex
outVertex
,
AtlasVertex
inVertex
,
String
attributeName
)
throws
AtlasException
{
LOG
.
debug
(
"Removing edge from {} to {} with attribute name {}"
,
string
(
outVertex
),
string
(
inVertex
),
if
(
LOG
.
isDebugEnabled
())
{
attributeName
);
LOG
.
debug
(
"Removing edge from {} to {} with attribute name {}"
,
string
(
outVertex
),
string
(
inVertex
),
attributeName
);
}
String
typeName
=
GraphHelper
.
getTypeName
(
outVertex
);
String
typeName
=
GraphHelper
.
getTypeName
(
outVertex
);
String
outId
=
GraphHelper
.
getGuid
(
outVertex
);
String
outId
=
GraphHelper
.
getGuid
(
outVertex
);
Id
.
EntityState
state
=
GraphHelper
.
getState
(
outVertex
);
Id
.
EntityState
state
=
GraphHelper
.
getState
(
outVertex
);
...
@@ -331,8 +348,11 @@ public abstract class DeleteHandler {
...
@@ -331,8 +348,11 @@ public abstract class DeleteHandler {
//if composite attribute, remove the reference as well. else, just remove the edge
//if composite attribute, remove the reference as well. else, just remove the edge
//for example, when table is deleted, process still references the table
//for example, when table is deleted, process still references the table
//but when column is deleted, table will not reference the deleted column
//but when column is deleted, table will not reference the deleted column
LOG
.
debug
(
"Removing edge {} from the array attribute {}"
,
string
(
elementEdge
),
if
(
LOG
.
isDebugEnabled
())
{
attributeName
);
LOG
.
debug
(
"Removing edge {} from the array attribute {}"
,
string
(
elementEdge
),
attributeName
);
}
elements
.
remove
(
elementEdge
.
getId
().
toString
());
elements
.
remove
(
elementEdge
.
getId
().
toString
());
GraphHelper
.
setProperty
(
outVertex
,
propertyName
,
elements
);
GraphHelper
.
setProperty
(
outVertex
,
propertyName
,
elements
);
break
;
break
;
...
@@ -367,8 +387,11 @@ public abstract class DeleteHandler {
...
@@ -367,8 +387,11 @@ public abstract class DeleteHandler {
if
(
shouldUpdateReverseAttribute
)
{
if
(
shouldUpdateReverseAttribute
)
{
//remove this key
//remove this key
LOG
.
debug
(
"Removing edge {}, key {} from the map attribute {}"
,
string
(
mapEdge
),
key
,
if
(
LOG
.
isDebugEnabled
())
{
attributeName
);
LOG
.
debug
(
"Removing edge {}, key {} from the map attribute {}"
,
string
(
mapEdge
),
key
,
attributeName
);
}
keys
.
remove
(
key
);
keys
.
remove
(
key
);
GraphHelper
.
setProperty
(
outVertex
,
propertyName
,
keys
);
GraphHelper
.
setProperty
(
outVertex
,
propertyName
,
keys
);
GraphHelper
.
setProperty
(
outVertex
,
keyPropertyName
,
null
);
GraphHelper
.
setProperty
(
outVertex
,
keyPropertyName
,
null
);
...
@@ -426,7 +449,11 @@ public abstract class DeleteHandler {
...
@@ -426,7 +449,11 @@ public abstract class DeleteHandler {
*/
*/
private
void
deleteAllTraits
(
AtlasVertex
instanceVertex
)
throws
AtlasException
{
private
void
deleteAllTraits
(
AtlasVertex
instanceVertex
)
throws
AtlasException
{
List
<
String
>
traitNames
=
GraphHelper
.
getTraitNames
(
instanceVertex
);
List
<
String
>
traitNames
=
GraphHelper
.
getTraitNames
(
instanceVertex
);
LOG
.
debug
(
"Deleting traits {} for {}"
,
traitNames
,
string
(
instanceVertex
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Deleting traits {} for {}"
,
traitNames
,
string
(
instanceVertex
));
}
String
typeName
=
GraphHelper
.
getTypeName
(
instanceVertex
);
String
typeName
=
GraphHelper
.
getTypeName
(
instanceVertex
);
for
(
String
traitNameToBeDeleted
:
traitNames
)
{
for
(
String
traitNameToBeDeleted
:
traitNames
)
{
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapper.java
View file @
34d235f3
...
@@ -56,12 +56,18 @@ public class FullTextMapper {
...
@@ -56,12 +56,18 @@ public class FullTextMapper {
ITypedReferenceableInstance
typedReference
;
ITypedReferenceableInstance
typedReference
;
if
(
instanceCache
.
containsKey
(
guid
))
{
if
(
instanceCache
.
containsKey
(
guid
))
{
typedReference
=
instanceCache
.
get
(
guid
);
typedReference
=
instanceCache
.
get
(
guid
);
LOG
.
debug
(
"Cache hit: guid = {}, entityId = {}"
,
guid
,
typedReference
.
getId
().
_getId
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Cache hit: guid = {}, entityId = {}"
,
guid
,
typedReference
.
getId
().
_getId
());
}
}
else
{
}
else
{
typedReference
=
typedReference
=
graphToTypedInstanceMapper
.
mapGraphToTypedInstance
(
guid
,
instanceVertex
);
graphToTypedInstanceMapper
.
mapGraphToTypedInstance
(
guid
,
instanceVertex
);
instanceCache
.
put
(
guid
,
typedReference
);
instanceCache
.
put
(
guid
,
typedReference
);
LOG
.
debug
(
"Cache miss: guid = {}, entityId = {}"
,
guid
,
typedReference
.
getId
().
getId
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Cache miss: guid = {}, entityId = {}"
,
guid
,
typedReference
.
getId
().
getId
());
}
}
}
String
fullText
=
forInstance
(
typedReference
,
followReferences
);
String
fullText
=
forInstance
(
typedReference
,
followReferences
);
StringBuilder
fullTextBuilder
=
StringBuilder
fullTextBuilder
=
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
View file @
34d235f3
...
@@ -136,7 +136,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -136,7 +136,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@GraphTransaction
@GraphTransaction
public
List
<
String
>
createEntities
(
ITypedReferenceableInstance
...
entities
)
throws
RepositoryException
,
public
List
<
String
>
createEntities
(
ITypedReferenceableInstance
...
entities
)
throws
RepositoryException
,
EntityExistsException
{
EntityExistsException
{
LOG
.
debug
(
"adding entities={}"
,
entities
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"adding entities={}"
,
entities
);
}
try
{
try
{
TypedInstanceToGraphMapper
instanceToGraphMapper
=
new
TypedInstanceToGraphMapper
(
graphToInstanceMapper
,
deleteHandler
);
TypedInstanceToGraphMapper
instanceToGraphMapper
=
new
TypedInstanceToGraphMapper
(
graphToInstanceMapper
,
deleteHandler
);
instanceToGraphMapper
.
mapTypedInstanceToGraph
(
TypedInstanceToGraphMapper
.
Operation
.
CREATE
,
entities
);
instanceToGraphMapper
.
mapTypedInstanceToGraph
(
TypedInstanceToGraphMapper
.
Operation
.
CREATE
,
entities
);
...
@@ -151,7 +154,9 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -151,7 +154,9 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@Override
@Override
@GraphTransaction
@GraphTransaction
public
ITypedReferenceableInstance
getEntityDefinition
(
String
guid
)
throws
RepositoryException
,
EntityNotFoundException
{
public
ITypedReferenceableInstance
getEntityDefinition
(
String
guid
)
throws
RepositoryException
,
EntityNotFoundException
{
LOG
.
debug
(
"Retrieving entity with guid={}"
,
guid
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Retrieving entity with guid={}"
,
guid
);
}
AtlasVertex
instanceVertex
=
graphHelper
.
getVertexForGUID
(
guid
);
AtlasVertex
instanceVertex
=
graphHelper
.
getVertexForGUID
(
guid
);
...
@@ -166,7 +171,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -166,7 +171,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@GraphTransaction
@GraphTransaction
public
ITypedReferenceableInstance
getEntityDefinition
(
String
entityType
,
String
attribute
,
Object
value
)
public
ITypedReferenceableInstance
getEntityDefinition
(
String
entityType
,
String
attribute
,
Object
value
)
throws
AtlasException
{
throws
AtlasException
{
LOG
.
debug
(
"Retrieving entity with type={} and {}={}"
,
entityType
,
attribute
,
value
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Retrieving entity with type={} and {}={}"
,
entityType
,
attribute
,
value
);
}
IDataType
type
=
typeSystem
.
getDataType
(
IDataType
.
class
,
entityType
);
IDataType
type
=
typeSystem
.
getDataType
(
IDataType
.
class
,
entityType
);
String
propertyKey
=
getFieldNameInVertex
(
type
,
attribute
);
String
propertyKey
=
getFieldNameInVertex
(
type
,
attribute
);
AtlasVertex
instanceVertex
=
graphHelper
.
findVertex
(
propertyKey
,
value
,
AtlasVertex
instanceVertex
=
graphHelper
.
findVertex
(
propertyKey
,
value
,
...
@@ -180,7 +188,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -180,7 +188,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@Override
@Override
@GraphTransaction
@GraphTransaction
public
List
<
String
>
getEntityList
(
String
entityType
)
throws
RepositoryException
{
public
List
<
String
>
getEntityList
(
String
entityType
)
throws
RepositoryException
{
LOG
.
debug
(
"Retrieving entity list for type={}"
,
entityType
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Retrieving entity list for type={}"
,
entityType
);
}
AtlasGraphQuery
query
=
graph
.
query
().
has
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
entityType
);
AtlasGraphQuery
query
=
graph
.
query
().
has
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
entityType
);
Iterator
<
AtlasVertex
>
results
=
query
.
vertices
().
iterator
();
Iterator
<
AtlasVertex
>
results
=
query
.
vertices
().
iterator
();
if
(!
results
.
hasNext
())
{
if
(!
results
.
hasNext
())
{
...
@@ -206,7 +217,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -206,7 +217,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@Override
@Override
@GraphTransaction
@GraphTransaction
public
List
<
String
>
getTraitNames
(
String
guid
)
throws
AtlasException
{
public
List
<
String
>
getTraitNames
(
String
guid
)
throws
AtlasException
{
LOG
.
debug
(
"Retrieving trait names for entity={}"
,
guid
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Retrieving trait names for entity={}"
,
guid
);
}
AtlasVertex
instanceVertex
=
graphHelper
.
getVertexForGUID
(
guid
);
AtlasVertex
instanceVertex
=
graphHelper
.
getVertexForGUID
(
guid
);
return
GraphHelper
.
getTraitNames
(
instanceVertex
);
return
GraphHelper
.
getTraitNames
(
instanceVertex
);
}
}
...
@@ -224,7 +238,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -224,7 +238,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
public
void
addTrait
(
String
guid
,
ITypedStruct
traitInstance
)
throws
RepositoryException
{
public
void
addTrait
(
String
guid
,
ITypedStruct
traitInstance
)
throws
RepositoryException
{
Preconditions
.
checkNotNull
(
traitInstance
,
"Trait instance cannot be null"
);
Preconditions
.
checkNotNull
(
traitInstance
,
"Trait instance cannot be null"
);
final
String
traitName
=
traitInstance
.
getTypeName
();
final
String
traitName
=
traitInstance
.
getTypeName
();
LOG
.
debug
(
"Adding a new trait={} for entity={}"
,
traitName
,
guid
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Adding a new trait={} for entity={}"
,
traitName
,
guid
);
}
try
{
try
{
AtlasVertex
instanceVertex
=
graphHelper
.
getVertexForGUID
(
guid
);
AtlasVertex
instanceVertex
=
graphHelper
.
getVertexForGUID
(
guid
);
...
@@ -260,7 +277,9 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -260,7 +277,9 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@Override
@Override
@GraphTransaction
@GraphTransaction
public
void
deleteTrait
(
String
guid
,
String
traitNameToBeDeleted
)
throws
TraitNotFoundException
,
EntityNotFoundException
,
RepositoryException
{
public
void
deleteTrait
(
String
guid
,
String
traitNameToBeDeleted
)
throws
TraitNotFoundException
,
EntityNotFoundException
,
RepositoryException
{
LOG
.
debug
(
"Deleting trait={} from entity={}"
,
traitNameToBeDeleted
,
guid
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Deleting trait={} from entity={}"
,
traitNameToBeDeleted
,
guid
);
}
AtlasVertex
instanceVertex
=
graphHelper
.
getVertexForGUID
(
guid
);
AtlasVertex
instanceVertex
=
graphHelper
.
getVertexForGUID
(
guid
);
...
@@ -303,7 +322,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -303,7 +322,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@Override
@Override
@GraphTransaction
@GraphTransaction
public
AtlasClient
.
EntityResult
updateEntities
(
ITypedReferenceableInstance
...
entitiesUpdated
)
throws
RepositoryException
{
public
AtlasClient
.
EntityResult
updateEntities
(
ITypedReferenceableInstance
...
entitiesUpdated
)
throws
RepositoryException
{
LOG
.
debug
(
"updating entity {}"
,
entitiesUpdated
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"updating entity {}"
,
entitiesUpdated
);
}
try
{
try
{
TypedInstanceToGraphMapper
instanceToGraphMapper
=
new
TypedInstanceToGraphMapper
(
graphToInstanceMapper
,
deleteHandler
);
TypedInstanceToGraphMapper
instanceToGraphMapper
=
new
TypedInstanceToGraphMapper
(
graphToInstanceMapper
,
deleteHandler
);
instanceToGraphMapper
.
mapTypedInstanceToGraph
(
TypedInstanceToGraphMapper
.
Operation
.
UPDATE_FULL
,
instanceToGraphMapper
.
mapTypedInstanceToGraph
(
TypedInstanceToGraphMapper
.
Operation
.
UPDATE_FULL
,
...
@@ -319,7 +341,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -319,7 +341,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@Override
@Override
@GraphTransaction
@GraphTransaction
public
AtlasClient
.
EntityResult
updatePartial
(
ITypedReferenceableInstance
entity
)
throws
RepositoryException
{
public
AtlasClient
.
EntityResult
updatePartial
(
ITypedReferenceableInstance
entity
)
throws
RepositoryException
{
LOG
.
debug
(
"updating entity {}"
,
entity
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"updating entity {}"
,
entity
);
}
try
{
try
{
TypedInstanceToGraphMapper
instanceToGraphMapper
=
new
TypedInstanceToGraphMapper
(
graphToInstanceMapper
,
deleteHandler
);
TypedInstanceToGraphMapper
instanceToGraphMapper
=
new
TypedInstanceToGraphMapper
(
graphToInstanceMapper
,
deleteHandler
);
instanceToGraphMapper
.
mapTypedInstanceToGraph
(
TypedInstanceToGraphMapper
.
Operation
.
UPDATE_PARTIAL
,
entity
);
instanceToGraphMapper
.
mapTypedInstanceToGraph
(
TypedInstanceToGraphMapper
.
Operation
.
UPDATE_PARTIAL
,
entity
);
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
View file @
34d235f3
...
@@ -233,7 +233,10 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh
...
@@ -233,7 +233,10 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh
AtlasGraphManagement
management
=
provider
.
get
().
getManagementSystem
();
AtlasGraphManagement
management
=
provider
.
get
().
getManagementSystem
();
for
(
IDataType
dataType
:
dataTypes
)
{
for
(
IDataType
dataType
:
dataTypes
)
{
LOG
.
debug
(
"Creating indexes for type name={}, definition={}"
,
dataType
.
getName
(),
dataType
.
getClass
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Creating indexes for type name={}, definition={}"
,
dataType
.
getName
(),
dataType
.
getClass
());
}
try
{
try
{
addIndexForType
(
management
,
dataType
);
addIndexForType
(
management
,
dataType
);
LOG
.
info
(
"Index creation for type {} complete"
,
dataType
.
getName
());
LOG
.
info
(
"Index creation for type {} complete"
,
dataType
.
getName
());
...
@@ -506,17 +509,17 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh
...
@@ -506,17 +509,17 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh
AtlasPropertyKey
propertyKey
,
boolean
enforceUniqueness
)
{
AtlasPropertyKey
propertyKey
,
boolean
enforceUniqueness
)
{
String
propertyName
=
propertyKey
.
getName
();
String
propertyName
=
propertyKey
.
getName
();
LOG
.
debug
(
"Creating composite index for property {} of type {} "
,
propertyName
,
propertyClass
.
getName
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Creating composite index for property {} of type {}; isUnique={} "
,
propertyName
,
propertyClass
.
getName
(),
enforceUniqueness
);
}
AtlasGraphIndex
existingIndex
=
management
.
getGraphIndex
(
propertyName
);
AtlasGraphIndex
existingIndex
=
management
.
getGraphIndex
(
propertyName
);
if
(
existingIndex
==
null
)
{
if
(
existingIndex
==
null
)
{
if
(
enforceUniqueness
)
{
LOG
.
debug
(
"Enabling unique index for property {} of type {} "
,
propertyName
,
propertyClass
.
getName
());
}
management
.
createExactMatchIndex
(
propertyName
,
enforceUniqueness
,
Collections
.
singletonList
(
propertyKey
));
management
.
createExactMatchIndex
(
propertyName
,
enforceUniqueness
,
Collections
.
singletonList
(
propertyKey
));
}
}
LOG
.
info
(
"Created composite index for property {} of type {} "
,
propertyName
,
propertyClass
.
getName
());
LOG
.
info
(
"Created composite index for property {} of type {}; isUnique={} "
,
propertyName
,
propertyClass
.
getName
(),
enforceUniqueness
);
}
}
...
@@ -536,8 +539,10 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh
...
@@ -536,8 +539,10 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh
Class
propertyClass
,
AtlasPropertyKey
propertyKey
,
final
String
systemPropertyKey
,
Class
propertyClass
,
AtlasPropertyKey
propertyKey
,
final
String
systemPropertyKey
,
AtlasCardinality
cardinality
)
{
AtlasCardinality
cardinality
)
{
LOG
.
debug
(
"Creating composite index for property {} of type {} and {}"
,
propertyKey
.
getName
(),
propertyClass
.
getName
(),
if
(
LOG
.
isDebugEnabled
())
{
systemPropertyKey
);
LOG
.
debug
(
"Creating composite index for property {} of type {} and {}"
,
propertyKey
.
getName
(),
propertyClass
.
getName
(),
systemPropertyKey
);
}
AtlasPropertyKey
typePropertyKey
=
management
.
getPropertyKey
(
systemPropertyKey
);
AtlasPropertyKey
typePropertyKey
=
management
.
getPropertyKey
(
systemPropertyKey
);
if
(
typePropertyKey
==
null
)
{
if
(
typePropertyKey
==
null
)
{
...
@@ -562,9 +567,12 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh
...
@@ -562,9 +567,12 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateCh
private
void
updateVertexIndex
(
AtlasGraphManagement
management
,
String
propertyName
,
Class
propertyClass
,
private
void
updateVertexIndex
(
AtlasGraphManagement
management
,
String
propertyName
,
Class
propertyClass
,
AtlasCardinality
cardinality
,
AtlasPropertyKey
propertyKey
)
{
AtlasCardinality
cardinality
,
AtlasPropertyKey
propertyKey
)
{
if
(
checkIfVertexIndexApplicable
(
propertyClass
,
cardinality
))
{
if
(
checkIfVertexIndexApplicable
(
propertyClass
,
cardinality
))
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Creating backing index for property {} of type {} "
,
propertyName
,
propertyClass
.
getName
());
}
// Use backing index
// Use backing index
management
.
addVertexIndexKey
(
Constants
.
VERTEX_INDEX
,
propertyKey
);
management
.
addVertexIndexKey
(
Constants
.
VERTEX_INDEX
,
propertyKey
);
LOG
.
debug
(
"Creating backing index for property {} of type {} "
,
propertyName
,
propertyClass
.
getName
());
LOG
.
info
(
"Created backing index for property {} of type {} "
,
propertyName
,
propertyClass
.
getName
());
LOG
.
info
(
"Created backing index for property {} of type {} "
,
propertyName
,
propertyClass
.
getName
());
}
}
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
View file @
34d235f3
...
@@ -24,7 +24,6 @@ import com.google.common.collect.HashBiMap;
...
@@ -24,7 +24,6 @@ import com.google.common.collect.HashBiMap;
import
org.apache.atlas.ApplicationProperties
;
import
org.apache.atlas.ApplicationProperties
;
import
org.apache.atlas.AtlasException
;
import
org.apache.atlas.AtlasException
;
import
org.apache.atlas.RequestContext
;
import
org.apache.atlas.RequestContext
;
import
org.apache.atlas.aspect.Monitored
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.RepositoryException
;
import
org.apache.atlas.repository.RepositoryException
;
import
org.apache.atlas.repository.graphdb.AtlasEdge
;
import
org.apache.atlas.repository.graphdb.AtlasEdge
;
...
@@ -129,10 +128,12 @@ public final class GraphHelper {
...
@@ -129,10 +128,12 @@ public final class GraphHelper {
return
vertexWithIdentity
;
return
vertexWithIdentity
;
}
}
@Monitored
public
AtlasVertex
createVertexWithoutIdentity
(
String
typeName
,
Id
typedInstanceId
,
Set
<
String
>
superTypeNames
)
{
public
AtlasVertex
createVertexWithoutIdentity
(
String
typeName
,
Id
typedInstanceId
,
Set
<
String
>
superTypeNames
)
{
LOG
.
debug
(
"Creating AtlasVertex for type {} id {}"
,
typeName
,
if
(
LOG
.
isDebugEnabled
())
{
typedInstanceId
!=
null
?
typedInstanceId
.
_getId
()
:
null
);
LOG
.
debug
(
"Creating AtlasVertex for type {} id {}"
,
typeName
,
typedInstanceId
!=
null
?
typedInstanceId
.
_getId
()
:
null
);
}
final
AtlasVertex
vertexWithoutIdentity
=
graph
.
addVertex
();
final
AtlasVertex
vertexWithoutIdentity
=
graph
.
addVertex
();
// add type information
// add type information
...
@@ -157,9 +158,11 @@ public final class GraphHelper {
...
@@ -157,9 +158,11 @@ public final class GraphHelper {
return
vertexWithoutIdentity
;
return
vertexWithoutIdentity
;
}
}
@Monitored
private
AtlasEdge
addEdge
(
AtlasVertex
fromVertex
,
AtlasVertex
toVertex
,
String
edgeLabel
)
{
private
AtlasEdge
addEdge
(
AtlasVertex
fromVertex
,
AtlasVertex
toVertex
,
String
edgeLabel
)
{
LOG
.
debug
(
"Adding edge for {} -> label {} -> {}"
,
string
(
fromVertex
),
edgeLabel
,
string
(
toVertex
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Adding edge for {} -> label {} -> {}"
,
string
(
fromVertex
),
edgeLabel
,
string
(
toVertex
));
}
AtlasEdge
edge
=
graph
.
addEdge
(
fromVertex
,
toVertex
,
edgeLabel
);
AtlasEdge
edge
=
graph
.
addEdge
(
fromVertex
,
toVertex
,
edgeLabel
);
setProperty
(
edge
,
Constants
.
STATE_PROPERTY_KEY
,
Id
.
EntityState
.
ACTIVE
.
name
());
setProperty
(
edge
,
Constants
.
STATE_PROPERTY_KEY
,
Id
.
EntityState
.
ACTIVE
.
name
());
...
@@ -168,14 +171,20 @@ public final class GraphHelper {
...
@@ -168,14 +171,20 @@ public final class GraphHelper {
setProperty
(
edge
,
Constants
.
CREATED_BY_KEY
,
RequestContext
.
get
().
getUser
());
setProperty
(
edge
,
Constants
.
CREATED_BY_KEY
,
RequestContext
.
get
().
getUser
());
setProperty
(
edge
,
Constants
.
MODIFIED_BY_KEY
,
RequestContext
.
get
().
getUser
());
setProperty
(
edge
,
Constants
.
MODIFIED_BY_KEY
,
RequestContext
.
get
().
getUser
());
LOG
.
debug
(
"Added {}"
,
string
(
edge
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Added {}"
,
string
(
edge
));
}
return
edge
;
return
edge
;
}
}
public
AtlasEdge
getOrCreateEdge
(
AtlasVertex
outVertex
,
AtlasVertex
inVertex
,
String
edgeLabel
)
throws
RepositoryException
{
public
AtlasEdge
getOrCreateEdge
(
AtlasVertex
outVertex
,
AtlasVertex
inVertex
,
String
edgeLabel
)
throws
RepositoryException
{
for
(
int
numRetries
=
0
;
numRetries
<
maxRetries
;
numRetries
++)
{
for
(
int
numRetries
=
0
;
numRetries
<
maxRetries
;
numRetries
++)
{
try
{
try
{
LOG
.
debug
(
"Running edge creation attempt {}"
,
numRetries
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Running edge creation attempt {}"
,
numRetries
);
}
Iterator
<
AtlasEdge
>
edges
=
getAdjacentEdgesByLabel
(
inVertex
,
AtlasEdgeDirection
.
IN
,
edgeLabel
);
Iterator
<
AtlasEdge
>
edges
=
getAdjacentEdgesByLabel
(
inVertex
,
AtlasEdgeDirection
.
IN
,
edgeLabel
);
while
(
edges
.
hasNext
())
{
while
(
edges
.
hasNext
())
{
...
@@ -209,7 +218,6 @@ public final class GraphHelper {
...
@@ -209,7 +218,6 @@ public final class GraphHelper {
return
null
;
return
null
;
}
}
@Monitored
public
AtlasEdge
getEdgeByEdgeId
(
AtlasVertex
outVertex
,
String
edgeLabel
,
String
edgeId
)
{
public
AtlasEdge
getEdgeByEdgeId
(
AtlasVertex
outVertex
,
String
edgeLabel
,
String
edgeId
)
{
if
(
edgeId
==
null
)
{
if
(
edgeId
==
null
)
{
return
null
;
return
null
;
...
@@ -235,26 +243,26 @@ public final class GraphHelper {
...
@@ -235,26 +243,26 @@ public final class GraphHelper {
* @return AtlasVertex with the given property keys
* @return AtlasVertex with the given property keys
* @throws EntityNotFoundException
* @throws EntityNotFoundException
*/
*/
@Monitored
public
AtlasVertex
findVertex
(
Object
...
args
)
throws
EntityNotFoundException
{
public
AtlasVertex
findVertex
(
Object
...
args
)
throws
EntityNotFoundException
{
StringBuilder
condition
=
new
StringBuilder
();
AtlasGraphQuery
query
=
graph
.
query
();
AtlasGraphQuery
query
=
graph
.
query
();
for
(
int
i
=
0
;
i
<
args
.
length
;
i
+=
2
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
+=
2
)
{
query
=
query
.
has
((
String
)
args
[
i
],
args
[
i
+
1
]);
query
=
query
.
has
((
String
)
args
[
i
],
args
[
i
+
1
]);
condition
.
append
(
args
[
i
]).
append
(
" = "
).
append
(
args
[
i
+
1
]).
append
(
", "
);
}
}
String
conditionStr
=
condition
.
toString
();
LOG
.
debug
(
"Finding AtlasVertex with {}"
,
conditionStr
);
Iterator
<
AtlasVertex
>
results
=
query
.
vertices
().
iterator
();
Iterator
<
AtlasVertex
>
results
=
query
.
vertices
().
iterator
();
// returning one since entityType, qualifiedName should be unique
// returning one since entityType, qualifiedName should be unique
AtlasVertex
vertex
=
results
.
hasNext
()
?
results
.
next
()
:
null
;
AtlasVertex
vertex
=
results
.
hasNext
()
?
results
.
next
()
:
null
;
if
(
vertex
==
null
)
{
if
(
vertex
==
null
)
{
LOG
.
debug
(
"Could not find a vertex with {}"
,
condition
.
toString
());
String
conditionStr
=
getConditionString
(
args
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Could not find a vertex with {}"
,
conditionStr
);
}
throw
new
EntityNotFoundException
(
"Could not find an entity in the repository with "
+
conditionStr
);
throw
new
EntityNotFoundException
(
"Could not find an entity in the repository with "
+
conditionStr
);
}
else
{
}
else
{
LOG
.
debug
(
"Found a vertex {} with {}"
,
string
(
vertex
),
conditionStr
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Found a vertex {} with {}"
,
string
(
vertex
),
getConditionString
(
args
));
}
}
}
return
vertex
;
return
vertex
;
...
@@ -262,9 +270,11 @@ public final class GraphHelper {
...
@@ -262,9 +270,11 @@ public final class GraphHelper {
//In some cases of parallel APIs, the edge is added, but get edge by label doesn't return the edge. ATLAS-1104
//In some cases of parallel APIs, the edge is added, but get edge by label doesn't return the edge. ATLAS-1104
//So traversing all the edges
//So traversing all the edges
@Monitored
public
Iterator
<
AtlasEdge
>
getAdjacentEdgesByLabel
(
AtlasVertex
instanceVertex
,
AtlasEdgeDirection
direction
,
final
String
edgeLabel
)
{
public
Iterator
<
AtlasEdge
>
getAdjacentEdgesByLabel
(
AtlasVertex
instanceVertex
,
AtlasEdgeDirection
direction
,
final
String
edgeLabel
)
{
LOG
.
debug
(
"Finding edges for {} with label {}"
,
string
(
instanceVertex
),
edgeLabel
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Finding edges for {} with label {}"
,
string
(
instanceVertex
),
edgeLabel
);
}
if
(
instanceVertex
!=
null
&&
edgeLabel
!=
null
)
{
if
(
instanceVertex
!=
null
&&
edgeLabel
!=
null
)
{
final
Iterator
<
AtlasEdge
>
iterator
=
instanceVertex
.
getEdges
(
direction
).
iterator
();
final
Iterator
<
AtlasEdge
>
iterator
=
instanceVertex
.
getEdges
(
direction
).
iterator
();
return
new
Iterator
<
AtlasEdge
>()
{
return
new
Iterator
<
AtlasEdge
>()
{
...
@@ -311,7 +321,6 @@ public final class GraphHelper {
...
@@ -311,7 +321,6 @@ public final class GraphHelper {
* @param edgeLabel
* @param edgeLabel
* @return
* @return
*/
*/
@Monitored
public
AtlasEdge
getEdgeForLabel
(
AtlasVertex
vertex
,
String
edgeLabel
)
{
public
AtlasEdge
getEdgeForLabel
(
AtlasVertex
vertex
,
String
edgeLabel
)
{
Iterator
<
AtlasEdge
>
iterator
=
getAdjacentEdgesByLabel
(
vertex
,
AtlasEdgeDirection
.
OUT
,
edgeLabel
);
Iterator
<
AtlasEdge
>
iterator
=
getAdjacentEdgesByLabel
(
vertex
,
AtlasEdgeDirection
.
OUT
,
edgeLabel
);
AtlasEdge
latestDeletedEdge
=
null
;
AtlasEdge
latestDeletedEdge
=
null
;
...
@@ -321,7 +330,10 @@ public final class GraphHelper {
...
@@ -321,7 +330,10 @@ public final class GraphHelper {
AtlasEdge
edge
=
iterator
.
next
();
AtlasEdge
edge
=
iterator
.
next
();
Id
.
EntityState
edgeState
=
getState
(
edge
);
Id
.
EntityState
edgeState
=
getState
(
edge
);
if
(
edgeState
==
null
||
edgeState
==
Id
.
EntityState
.
ACTIVE
)
{
if
(
edgeState
==
null
||
edgeState
==
Id
.
EntityState
.
ACTIVE
)
{
LOG
.
debug
(
"Found {}"
,
string
(
edge
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Found {}"
,
string
(
edge
));
}
return
edge
;
return
edge
;
}
else
{
}
else
{
Long
modificationTime
=
edge
.
getProperty
(
Constants
.
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
Long
.
class
);
Long
modificationTime
=
edge
.
getProperty
(
Constants
.
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
Long
.
class
);
...
@@ -331,12 +343,15 @@ public final class GraphHelper {
...
@@ -331,12 +343,15 @@ public final class GraphHelper {
}
}
}
}
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Found {}"
,
latestDeletedEdge
==
null
?
"null"
:
string
(
latestDeletedEdge
));
}
//If the vertex is deleted, return latest deleted edge
//If the vertex is deleted, return latest deleted edge
LOG
.
debug
(
"Found {}"
,
latestDeletedEdge
==
null
?
"null"
:
string
(
latestDeletedEdge
));
return
latestDeletedEdge
;
return
latestDeletedEdge
;
}
}
@Monitored
public
static
String
vertexString
(
final
AtlasVertex
vertex
)
{
public
static
String
vertexString
(
final
AtlasVertex
vertex
)
{
StringBuilder
properties
=
new
StringBuilder
();
StringBuilder
properties
=
new
StringBuilder
();
for
(
String
propertyKey
:
vertex
.
getPropertyKeys
())
{
for
(
String
propertyKey
:
vertex
.
getPropertyKeys
())
{
...
@@ -347,27 +362,38 @@ public final class GraphHelper {
...
@@ -347,27 +362,38 @@ public final class GraphHelper {
return
"v["
+
vertex
.
getIdForDisplay
()
+
"], Properties["
+
properties
+
"]"
;
return
"v["
+
vertex
.
getIdForDisplay
()
+
"], Properties["
+
properties
+
"]"
;
}
}
@Monitored
public
static
String
edgeString
(
final
AtlasEdge
edge
)
{
public
static
String
edgeString
(
final
AtlasEdge
edge
)
{
return
"e["
+
edge
.
getLabel
()
+
"], ["
+
edge
.
getOutVertex
()
+
" -> "
+
edge
.
getLabel
()
+
" -> "
return
"e["
+
edge
.
getLabel
()
+
"], ["
+
edge
.
getOutVertex
()
+
" -> "
+
edge
.
getLabel
()
+
" -> "
+
edge
.
getInVertex
()
+
"]"
;
+
edge
.
getInVertex
()
+
"]"
;
}
}
@Monitored
public
static
<
T
extends
AtlasElement
>
void
setProperty
(
T
element
,
String
propertyName
,
Object
value
)
{
public
static
<
T
extends
AtlasElement
>
void
setProperty
(
T
element
,
String
propertyName
,
Object
value
)
{
String
elementStr
=
string
(
element
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
LOG
.
debug
(
"Setting property {} = \"{}\" to {}"
,
actualPropertyName
,
value
,
elementStr
);
String
elementStr
=
null
;
if
(
LOG
.
isDebugEnabled
())
{
elementStr
=
string
(
element
);
LOG
.
debug
(
"Setting property {} = \"{}\" to {}"
,
actualPropertyName
,
value
,
elementStr
);
}
Object
existValue
=
element
.
getProperty
(
actualPropertyName
,
Object
.
class
);
Object
existValue
=
element
.
getProperty
(
actualPropertyName
,
Object
.
class
);
if
(
value
==
null
||
(
value
instanceof
Collection
&&
((
Collection
)
value
).
isEmpty
()))
{
if
(
value
==
null
||
(
value
instanceof
Collection
&&
((
Collection
)
value
).
isEmpty
()))
{
if
(
existValue
!=
null
)
{
if
(
existValue
!=
null
)
{
LOG
.
info
(
"Removing property - {} value from {}"
,
actualPropertyName
,
elementStr
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Removing property - {} value from {}"
,
actualPropertyName
,
elementStr
);
}
element
.
removeProperty
(
actualPropertyName
);
element
.
removeProperty
(
actualPropertyName
);
}
}
}
else
{
}
else
{
if
(!
value
.
equals
(
existValue
))
{
if
(!
value
.
equals
(
existValue
))
{
element
.
setProperty
(
actualPropertyName
,
value
);
element
.
setProperty
(
actualPropertyName
,
value
);
LOG
.
debug
(
"Set property {} = \"{}\" to {}"
,
actualPropertyName
,
value
,
elementStr
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Set property {} = \"{}\" to {}"
,
actualPropertyName
,
value
,
elementStr
);
}
}
}
}
}
}
}
...
@@ -382,21 +408,23 @@ public final class GraphHelper {
...
@@ -382,21 +408,23 @@ public final class GraphHelper {
* @param clazz
* @param clazz
* @return
* @return
*/
*/
@Monitored
public
static
<
T
>
T
getSingleValuedProperty
(
AtlasElement
element
,
String
propertyName
,
Class
<
T
>
clazz
)
{
public
static
<
T
>
T
getSingleValuedProperty
(
AtlasElement
element
,
String
propertyName
,
Class
<
T
>
clazz
)
{
String
elementStr
=
string
(
element
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
LOG
.
debug
(
"Reading property {} from {}"
,
actualPropertyName
,
elementStr
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Reading property {} from {}"
,
actualPropertyName
,
string
(
element
));
}
return
element
.
getProperty
(
actualPropertyName
,
clazz
);
return
element
.
getProperty
(
actualPropertyName
,
clazz
);
}
}
@Monitored
public
static
Object
getProperty
(
AtlasVertex
<?,?>
vertex
,
String
propertyName
)
{
public
static
Object
getProperty
(
AtlasVertex
<?,?>
vertex
,
String
propertyName
)
{
String
elementStr
=
string
(
vertex
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
LOG
.
debug
(
"Reading property {} from {}"
,
actualPropertyName
,
elementStr
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Reading property {} from {}"
,
actualPropertyName
,
string
(
vertex
));
}
if
(
AtlasGraphProvider
.
getGraphInstance
().
isMultiProperty
(
actualPropertyName
))
{
if
(
AtlasGraphProvider
.
getGraphInstance
().
isMultiProperty
(
actualPropertyName
))
{
return
vertex
.
getPropertyValues
(
actualPropertyName
,
String
.
class
);
return
vertex
.
getPropertyValues
(
actualPropertyName
,
String
.
class
);
...
@@ -406,11 +434,13 @@ public final class GraphHelper {
...
@@ -406,11 +434,13 @@ public final class GraphHelper {
}
}
}
}
@Monitored
public
static
Object
getProperty
(
AtlasEdge
<?,?>
edge
,
String
propertyName
)
{
public
static
Object
getProperty
(
AtlasEdge
<?,?>
edge
,
String
propertyName
)
{
String
elementStr
=
string
(
edge
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
LOG
.
debug
(
"Reading property {} from {}"
,
actualPropertyName
,
elementStr
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Reading property {} from {}"
,
actualPropertyName
,
string
(
edge
));
}
return
edge
.
getProperty
(
actualPropertyName
,
Object
.
class
);
return
edge
.
getProperty
(
actualPropertyName
,
Object
.
class
);
}
}
...
@@ -430,10 +460,13 @@ public final class GraphHelper {
...
@@ -430,10 +460,13 @@ public final class GraphHelper {
* @param propertyName
* @param propertyName
* @param value
* @param value
*/
*/
@Monitored
public
static
void
addProperty
(
AtlasVertex
vertex
,
String
propertyName
,
Object
value
)
{
public
static
void
addProperty
(
AtlasVertex
vertex
,
String
propertyName
,
Object
value
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
LOG
.
debug
(
"Adding property {} = \"{}\" to vertex {}"
,
actualPropertyName
,
value
,
string
(
vertex
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Adding property {} = \"{}\" to vertex {}"
,
actualPropertyName
,
value
,
string
(
vertex
));
}
vertex
.
addProperty
(
actualPropertyName
,
value
);
vertex
.
addProperty
(
actualPropertyName
,
value
);
}
}
...
@@ -442,12 +475,20 @@ public final class GraphHelper {
...
@@ -442,12 +475,20 @@ public final class GraphHelper {
*
*
* @param edge
* @param edge
*/
*/
@Monitored
public
void
removeEdge
(
AtlasEdge
edge
)
{
public
void
removeEdge
(
AtlasEdge
edge
)
{
String
edgeString
=
string
(
edge
);
String
edgeString
=
null
;
LOG
.
debug
(
"Removing {}"
,
edgeString
);
if
(
LOG
.
isDebugEnabled
())
{
edgeString
=
string
(
edge
);
LOG
.
debug
(
"Removing {}"
,
edgeString
);
}
graph
.
removeEdge
(
edge
);
graph
.
removeEdge
(
edge
);
LOG
.
info
(
"Removed {}"
,
edgeString
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
info
(
"Removed {}"
,
edgeString
);
}
}
}
/**
/**
...
@@ -455,12 +496,20 @@ public final class GraphHelper {
...
@@ -455,12 +496,20 @@ public final class GraphHelper {
*
*
* @param vertex
* @param vertex
*/
*/
@Monitored
public
void
removeVertex
(
AtlasVertex
vertex
)
{
public
void
removeVertex
(
AtlasVertex
vertex
)
{
String
vertexString
=
string
(
vertex
);
String
vertexString
=
null
;
LOG
.
debug
(
"Removing {}"
,
vertexString
);
if
(
LOG
.
isDebugEnabled
())
{
vertexString
=
string
(
vertex
);
LOG
.
debug
(
"Removing {}"
,
vertexString
);
}
graph
.
removeVertex
(
vertex
);
graph
.
removeVertex
(
vertex
);
LOG
.
info
(
"Removed {}"
,
vertexString
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
info
(
"Removed {}"
,
vertexString
);
}
}
}
public
AtlasVertex
getVertexForGUID
(
String
guid
)
throws
EntityNotFoundException
{
public
AtlasVertex
getVertexForGUID
(
String
guid
)
throws
EntityNotFoundException
{
...
@@ -564,7 +613,10 @@ public final class GraphHelper {
...
@@ -564,7 +613,10 @@ public final class GraphHelper {
*/
*/
public
AtlasVertex
getVertexForInstanceByUniqueAttribute
(
ClassType
classType
,
IReferenceableInstance
instance
)
public
AtlasVertex
getVertexForInstanceByUniqueAttribute
(
ClassType
classType
,
IReferenceableInstance
instance
)
throws
AtlasException
{
throws
AtlasException
{
LOG
.
debug
(
"Checking if there is an instance with the same unique attributes for instance {}"
,
instance
.
toShortString
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Checking if there is an instance with the same unique attributes for instance {}"
,
instance
.
toShortString
());
}
AtlasVertex
result
=
null
;
AtlasVertex
result
=
null
;
for
(
AttributeInfo
attributeInfo
:
classType
.
fieldMapping
().
fields
.
values
())
{
for
(
AttributeInfo
attributeInfo
:
classType
.
fieldMapping
().
fields
.
values
())
{
if
(
attributeInfo
.
isUnique
)
{
if
(
attributeInfo
.
isUnique
)
{
...
@@ -573,7 +625,9 @@ public final class GraphHelper {
...
@@ -573,7 +625,9 @@ public final class GraphHelper {
result
=
findVertex
(
propertyKey
,
instance
.
get
(
attributeInfo
.
name
),
result
=
findVertex
(
propertyKey
,
instance
.
get
(
attributeInfo
.
name
),
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
classType
.
getName
(),
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
classType
.
getName
(),
Constants
.
STATE_PROPERTY_KEY
,
Id
.
EntityState
.
ACTIVE
.
name
());
Constants
.
STATE_PROPERTY_KEY
,
Id
.
EntityState
.
ACTIVE
.
name
());
LOG
.
debug
(
"Found vertex by unique attribute : {}={}"
,
propertyKey
,
instance
.
get
(
attributeInfo
.
name
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Found vertex by unique attribute : {}={}"
,
propertyKey
,
instance
.
get
(
attributeInfo
.
name
));
}
}
catch
(
EntityNotFoundException
e
)
{
}
catch
(
EntityNotFoundException
e
)
{
//Its ok if there is no entity with the same unique value
//Its ok if there is no entity with the same unique value
}
}
...
@@ -745,7 +799,6 @@ public final class GraphHelper {
...
@@ -745,7 +799,6 @@ public final class GraphHelper {
}
}
@Monitored
public
static
void
setArrayElementsProperty
(
IDataType
elementType
,
AtlasVertex
instanceVertex
,
String
propertyName
,
List
<
Object
>
values
)
{
public
static
void
setArrayElementsProperty
(
IDataType
elementType
,
AtlasVertex
instanceVertex
,
String
propertyName
,
List
<
Object
>
values
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
if
(
GraphHelper
.
isReference
(
elementType
))
{
if
(
GraphHelper
.
isReference
(
elementType
))
{
...
@@ -756,7 +809,6 @@ public final class GraphHelper {
...
@@ -756,7 +809,6 @@ public final class GraphHelper {
}
}
}
}
@Monitored
public
static
void
setMapValueProperty
(
IDataType
elementType
,
AtlasVertex
instanceVertex
,
String
propertyName
,
Object
value
)
{
public
static
void
setMapValueProperty
(
IDataType
elementType
,
AtlasVertex
instanceVertex
,
String
propertyName
,
Object
value
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
if
(
GraphHelper
.
isReference
(
elementType
))
{
if
(
GraphHelper
.
isReference
(
elementType
))
{
...
@@ -767,7 +819,6 @@ public final class GraphHelper {
...
@@ -767,7 +819,6 @@ public final class GraphHelper {
}
}
}
}
@Monitored
public
static
Object
getMapValueProperty
(
IDataType
elementType
,
AtlasVertex
instanceVertex
,
String
propertyName
)
{
public
static
Object
getMapValueProperty
(
IDataType
elementType
,
AtlasVertex
instanceVertex
,
String
propertyName
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
if
(
GraphHelper
.
isReference
(
elementType
))
{
if
(
GraphHelper
.
isReference
(
elementType
))
{
...
@@ -778,7 +829,6 @@ public final class GraphHelper {
...
@@ -778,7 +829,6 @@ public final class GraphHelper {
}
}
}
}
@Monitored
public
static
List
<
Object
>
getArrayElementsProperty
(
IDataType
elementType
,
AtlasVertex
instanceVertex
,
String
propertyName
)
{
public
static
List
<
Object
>
getArrayElementsProperty
(
IDataType
elementType
,
AtlasVertex
instanceVertex
,
String
propertyName
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
if
(
GraphHelper
.
isReference
(
elementType
))
{
if
(
GraphHelper
.
isReference
(
elementType
))
{
...
@@ -921,4 +971,15 @@ public final class GraphHelper {
...
@@ -921,4 +971,15 @@ public final class GraphHelper {
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
return
instanceVertex
.
getListProperty
(
actualPropertyName
);
return
instanceVertex
.
getListProperty
(
actualPropertyName
);
}
}
private
String
getConditionString
(
Object
[]
args
)
{
StringBuilder
condition
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
args
.
length
;
i
+=
2
)
{
condition
.
append
(
args
[
i
]).
append
(
" = "
).
append
(
args
[
i
+
1
]).
append
(
", "
);
}
return
condition
.
toString
();
}
}
}
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java
View file @
34d235f3
...
@@ -70,7 +70,10 @@ public final class GraphToTypedInstanceMapper {
...
@@ -70,7 +70,10 @@ public final class GraphToTypedInstanceMapper {
public
ITypedReferenceableInstance
mapGraphToTypedInstance
(
String
guid
,
AtlasVertex
instanceVertex
)
public
ITypedReferenceableInstance
mapGraphToTypedInstance
(
String
guid
,
AtlasVertex
instanceVertex
)
throws
AtlasException
{
throws
AtlasException
{
LOG
.
debug
(
"Mapping graph root vertex {} to typed instance for guid {}"
,
instanceVertex
,
guid
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Mapping graph root vertex {} to typed instance for guid {}"
,
instanceVertex
,
guid
);
}
String
typeName
=
GraphHelper
.
getSingleValuedProperty
(
instanceVertex
,
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
String
.
class
);
String
typeName
=
GraphHelper
.
getSingleValuedProperty
(
instanceVertex
,
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
String
.
class
);
List
<
String
>
traits
=
GraphHelper
.
getTraitNames
(
instanceVertex
);
List
<
String
>
traits
=
GraphHelper
.
getTraitNames
(
instanceVertex
);
String
state
=
GraphHelper
.
getStateAsString
(
instanceVertex
);
String
state
=
GraphHelper
.
getStateAsString
(
instanceVertex
);
...
@@ -80,11 +83,16 @@ public final class GraphToTypedInstanceMapper {
...
@@ -80,11 +83,16 @@ public final class GraphToTypedInstanceMapper {
Date
modifiedTime
=
new
Date
(
GraphHelper
.
getModifiedTime
(
instanceVertex
));
Date
modifiedTime
=
new
Date
(
GraphHelper
.
getModifiedTime
(
instanceVertex
));
AtlasSystemAttributes
systemAttributes
=
new
AtlasSystemAttributes
(
createdBy
,
modifiedBy
,
createdTime
,
modifiedTime
);
AtlasSystemAttributes
systemAttributes
=
new
AtlasSystemAttributes
(
createdBy
,
modifiedBy
,
createdTime
,
modifiedTime
);
LOG
.
debug
(
"Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}"
,
createdBy
,
modifiedBy
,
createdTime
,
modifiedTime
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}"
,
createdBy
,
modifiedBy
,
createdTime
,
modifiedTime
);
}
Id
id
=
new
Id
(
guid
,
Integer
.
parseInt
(
String
.
valueOf
(
GraphHelper
.
getProperty
(
instanceVertex
,
Constants
.
VERSION_PROPERTY_KEY
))),
Id
id
=
new
Id
(
guid
,
Integer
.
parseInt
(
String
.
valueOf
(
GraphHelper
.
getProperty
(
instanceVertex
,
Constants
.
VERSION_PROPERTY_KEY
))),
typeName
,
state
);
typeName
,
state
);
LOG
.
debug
(
"Created id {} for instance type {}"
,
id
,
typeName
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Created id {} for instance type {}"
,
id
,
typeName
);
}
ClassType
classType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
typeName
);
ClassType
classType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
typeName
);
ITypedReferenceableInstance
typedInstance
=
ITypedReferenceableInstance
typedInstance
=
...
@@ -100,7 +108,10 @@ public final class GraphToTypedInstanceMapper {
...
@@ -100,7 +108,10 @@ public final class GraphToTypedInstanceMapper {
private
void
mapVertexToInstanceTraits
(
AtlasVertex
instanceVertex
,
ITypedReferenceableInstance
typedInstance
,
private
void
mapVertexToInstanceTraits
(
AtlasVertex
instanceVertex
,
ITypedReferenceableInstance
typedInstance
,
List
<
String
>
traits
)
throws
AtlasException
{
List
<
String
>
traits
)
throws
AtlasException
{
for
(
String
traitName
:
traits
)
{
for
(
String
traitName
:
traits
)
{
LOG
.
debug
(
"mapping trait {} to instance"
,
traitName
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"mapping trait {} to instance"
,
traitName
);
}
TraitType
traitType
=
typeSystem
.
getDataType
(
TraitType
.
class
,
traitName
);
TraitType
traitType
=
typeSystem
.
getDataType
(
TraitType
.
class
,
traitName
);
mapVertexToTraitInstance
(
instanceVertex
,
typedInstance
,
traitName
,
traitType
);
mapVertexToTraitInstance
(
instanceVertex
,
typedInstance
,
traitName
,
traitType
);
}
}
...
@@ -110,8 +121,11 @@ public final class GraphToTypedInstanceMapper {
...
@@ -110,8 +121,11 @@ public final class GraphToTypedInstanceMapper {
public
void
mapVertexToInstance
(
AtlasVertex
instanceVertex
,
ITypedInstance
typedInstance
,
public
void
mapVertexToInstance
(
AtlasVertex
instanceVertex
,
ITypedInstance
typedInstance
,
Map
<
String
,
AttributeInfo
>
fields
)
throws
AtlasException
{
Map
<
String
,
AttributeInfo
>
fields
)
throws
AtlasException
{
LOG
.
debug
(
"Mapping vertex {} to instance {} for fields"
,
instanceVertex
,
typedInstance
.
getTypeName
(),
if
(
LOG
.
isDebugEnabled
())
{
fields
);
LOG
.
debug
(
"Mapping vertex {} to instance {} for fields"
,
instanceVertex
,
typedInstance
.
getTypeName
(),
fields
);
}
for
(
AttributeInfo
attributeInfo
:
fields
.
values
())
{
for
(
AttributeInfo
attributeInfo
:
fields
.
values
())
{
mapVertexToAttribute
(
instanceVertex
,
typedInstance
,
attributeInfo
);
mapVertexToAttribute
(
instanceVertex
,
typedInstance
,
attributeInfo
);
}
}
...
@@ -119,7 +133,11 @@ public final class GraphToTypedInstanceMapper {
...
@@ -119,7 +133,11 @@ public final class GraphToTypedInstanceMapper {
private
void
mapVertexToAttribute
(
AtlasVertex
instanceVertex
,
ITypedInstance
typedInstance
,
private
void
mapVertexToAttribute
(
AtlasVertex
instanceVertex
,
ITypedInstance
typedInstance
,
AttributeInfo
attributeInfo
)
throws
AtlasException
{
AttributeInfo
attributeInfo
)
throws
AtlasException
{
LOG
.
debug
(
"Mapping attributeInfo {}"
,
attributeInfo
.
name
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Mapping attributeInfo {}"
,
attributeInfo
.
name
);
}
final
IDataType
dataType
=
attributeInfo
.
dataType
();
final
IDataType
dataType
=
attributeInfo
.
dataType
();
final
String
vertexPropertyName
=
GraphHelper
.
getQualifiedFieldName
(
typedInstance
,
attributeInfo
);
final
String
vertexPropertyName
=
GraphHelper
.
getQualifiedFieldName
(
typedInstance
,
attributeInfo
);
String
relationshipLabel
=
GraphHelper
.
getEdgeLabel
(
typedInstance
,
attributeInfo
);
String
relationshipLabel
=
GraphHelper
.
getEdgeLabel
(
typedInstance
,
attributeInfo
);
...
@@ -172,7 +190,9 @@ public final class GraphToTypedInstanceMapper {
...
@@ -172,7 +190,9 @@ public final class GraphToTypedInstanceMapper {
private
Object
mapVertexToClassReference
(
AtlasVertex
instanceVertex
,
AttributeInfo
attributeInfo
,
private
Object
mapVertexToClassReference
(
AtlasVertex
instanceVertex
,
AttributeInfo
attributeInfo
,
String
relationshipLabel
,
IDataType
dataType
,
AtlasEdge
optionalEdge
)
throws
AtlasException
{
String
relationshipLabel
,
IDataType
dataType
,
AtlasEdge
optionalEdge
)
throws
AtlasException
{
LOG
.
debug
(
"Finding edge for {} -> label {} "
,
instanceVertex
,
relationshipLabel
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Finding edge for {} -> label {} "
,
instanceVertex
,
relationshipLabel
);
}
AtlasEdge
edge
=
null
;
AtlasEdge
edge
=
null
;
if
(
optionalEdge
==
null
)
{
if
(
optionalEdge
==
null
)
{
...
@@ -184,7 +204,11 @@ public final class GraphToTypedInstanceMapper {
...
@@ -184,7 +204,11 @@ public final class GraphToTypedInstanceMapper {
if
(
GraphHelper
.
elementExists
(
edge
))
{
if
(
GraphHelper
.
elementExists
(
edge
))
{
final
AtlasVertex
referenceVertex
=
edge
.
getInVertex
();
final
AtlasVertex
referenceVertex
=
edge
.
getInVertex
();
final
String
guid
=
GraphHelper
.
getSingleValuedProperty
(
referenceVertex
,
Constants
.
GUID_PROPERTY_KEY
,
String
.
class
);
final
String
guid
=
GraphHelper
.
getSingleValuedProperty
(
referenceVertex
,
Constants
.
GUID_PROPERTY_KEY
,
String
.
class
);
LOG
.
debug
(
"Found vertex {} for label {} with guid {}"
,
referenceVertex
,
relationshipLabel
,
guid
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Found vertex {} for label {} with guid {}"
,
referenceVertex
,
relationshipLabel
,
guid
);
}
if
(
attributeInfo
.
isComposite
)
{
if
(
attributeInfo
.
isComposite
)
{
//Also, when you retrieve a type's instance, you get the complete object graph of the composites
//Also, when you retrieve a type's instance, you get the complete object graph of the composites
LOG
.
debug
(
"Found composite, mapping vertex to instance"
);
LOG
.
debug
(
"Found composite, mapping vertex to instance"
);
...
@@ -194,7 +218,11 @@ public final class GraphToTypedInstanceMapper {
...
@@ -194,7 +218,11 @@ public final class GraphToTypedInstanceMapper {
Id
referenceId
=
Id
referenceId
=
new
Id
(
guid
,
GraphHelper
.
getSingleValuedProperty
(
referenceVertex
,
Constants
.
VERSION_PROPERTY_KEY
,
Integer
.
class
),
new
Id
(
guid
,
GraphHelper
.
getSingleValuedProperty
(
referenceVertex
,
Constants
.
VERSION_PROPERTY_KEY
,
Integer
.
class
),
dataType
.
getName
(),
state
);
dataType
.
getName
(),
state
);
LOG
.
debug
(
"Found non-composite, adding id {} "
,
referenceId
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Found non-composite, adding id {} "
,
referenceId
);
}
return
referenceId
;
return
referenceId
;
}
}
}
}
...
@@ -205,7 +233,9 @@ public final class GraphToTypedInstanceMapper {
...
@@ -205,7 +233,9 @@ public final class GraphToTypedInstanceMapper {
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
private
void
mapVertexToArrayInstance
(
AtlasVertex
<?,?>
instanceVertex
,
ITypedInstance
typedInstance
,
private
void
mapVertexToArrayInstance
(
AtlasVertex
<?,?>
instanceVertex
,
ITypedInstance
typedInstance
,
AttributeInfo
attributeInfo
,
String
propertyName
)
throws
AtlasException
{
AttributeInfo
attributeInfo
,
String
propertyName
)
throws
AtlasException
{
LOG
.
debug
(
"mapping vertex {} to array {}"
,
instanceVertex
,
attributeInfo
.
name
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"mapping vertex {} to array {}"
,
instanceVertex
,
attributeInfo
.
name
);
}
final
DataTypes
.
ArrayType
arrayType
=
(
DataTypes
.
ArrayType
)
attributeInfo
.
dataType
();
final
DataTypes
.
ArrayType
arrayType
=
(
DataTypes
.
ArrayType
)
attributeInfo
.
dataType
();
final
IDataType
elementType
=
arrayType
.
getElemType
();
final
IDataType
elementType
=
arrayType
.
getElemType
();
...
@@ -257,7 +287,10 @@ public final class GraphToTypedInstanceMapper {
...
@@ -257,7 +287,10 @@ public final class GraphToTypedInstanceMapper {
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
private
void
mapVertexToMapInstance
(
AtlasVertex
<?,?>
instanceVertex
,
ITypedInstance
typedInstance
,
private
void
mapVertexToMapInstance
(
AtlasVertex
<?,?>
instanceVertex
,
ITypedInstance
typedInstance
,
AttributeInfo
attributeInfo
,
final
String
propertyName
)
throws
AtlasException
{
AttributeInfo
attributeInfo
,
final
String
propertyName
)
throws
AtlasException
{
LOG
.
debug
(
"mapping vertex {} to array {}"
,
instanceVertex
,
attributeInfo
.
name
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"mapping vertex {} to array {}"
,
instanceVertex
,
attributeInfo
.
name
);
}
List
<
String
>
keys
=
GraphHelper
.
getListProperty
(
instanceVertex
,
propertyName
);
List
<
String
>
keys
=
GraphHelper
.
getListProperty
(
instanceVertex
,
propertyName
);
if
(
keys
==
null
||
keys
.
size
()
==
0
)
{
if
(
keys
==
null
||
keys
.
size
()
==
0
)
{
return
;
return
;
...
@@ -283,7 +316,10 @@ public final class GraphToTypedInstanceMapper {
...
@@ -283,7 +316,10 @@ public final class GraphToTypedInstanceMapper {
private
ITypedStruct
mapVertexToStructInstance
(
AtlasVertex
instanceVertex
,
StructType
structType
,
private
ITypedStruct
mapVertexToStructInstance
(
AtlasVertex
instanceVertex
,
StructType
structType
,
String
relationshipLabel
,
AtlasEdge
optionalEdge
)
throws
AtlasException
{
String
relationshipLabel
,
AtlasEdge
optionalEdge
)
throws
AtlasException
{
LOG
.
debug
(
"mapping {} to struct {}"
,
string
(
instanceVertex
),
relationshipLabel
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"mapping {} to struct {}"
,
string
(
instanceVertex
),
relationshipLabel
);
}
ITypedStruct
structInstance
=
null
;
ITypedStruct
structInstance
=
null
;
AtlasEdge
edge
;
AtlasEdge
edge
;
...
@@ -296,10 +332,12 @@ public final class GraphToTypedInstanceMapper {
...
@@ -296,10 +332,12 @@ public final class GraphToTypedInstanceMapper {
if
(
GraphHelper
.
elementExists
(
edge
))
{
if
(
GraphHelper
.
elementExists
(
edge
))
{
structInstance
=
structType
.
createInstance
();
structInstance
=
structType
.
createInstance
();
AtlasVertex
structInstanceVertex
=
edge
.
getInVertex
();
AtlasVertex
structInstanceVertex
=
edge
.
getInVertex
();
LOG
.
debug
(
"Found struct instance {}, mapping to instance {} "
,
string
(
structInstanceVertex
),
if
(
LOG
.
isDebugEnabled
())
{
structInstance
.
getTypeName
());
LOG
.
debug
(
"Found struct instance {}, mapping to instance {} "
,
string
(
structInstanceVertex
),
mapVertexToInstance
(
structInstanceVertex
,
structInstance
,
structType
.
fieldMapping
().
fields
);
structInstance
.
getTypeName
());
}
mapVertexToInstance
(
structInstanceVertex
,
structInstance
,
structType
.
fieldMapping
().
fields
);
}
}
return
structInstance
;
return
structInstance
;
}
}
...
@@ -314,12 +352,19 @@ public final class GraphToTypedInstanceMapper {
...
@@ -314,12 +352,19 @@ public final class GraphToTypedInstanceMapper {
private
void
mapVertexToTraitInstance
(
AtlasVertex
<?,?>
instanceVertex
,
String
typedInstanceTypeName
,
String
traitName
,
private
void
mapVertexToTraitInstance
(
AtlasVertex
<?,?>
instanceVertex
,
String
typedInstanceTypeName
,
String
traitName
,
TraitType
traitType
,
ITypedStruct
traitInstance
)
throws
AtlasException
{
TraitType
traitType
,
ITypedStruct
traitInstance
)
throws
AtlasException
{
String
relationshipLabel
=
GraphHelper
.
getTraitLabel
(
typedInstanceTypeName
,
traitName
);
String
relationshipLabel
=
GraphHelper
.
getTraitLabel
(
typedInstanceTypeName
,
traitName
);
LOG
.
debug
(
"Finding edge for {} -> label {} "
,
instanceVertex
,
relationshipLabel
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Finding edge for {} -> label {} "
,
instanceVertex
,
relationshipLabel
);
}
for
(
AtlasEdge
<?,?>
edge
:
instanceVertex
.
getEdges
(
AtlasEdgeDirection
.
OUT
,
relationshipLabel
))
{
for
(
AtlasEdge
<?,?>
edge
:
instanceVertex
.
getEdges
(
AtlasEdgeDirection
.
OUT
,
relationshipLabel
))
{
final
AtlasVertex
<?,?>
traitInstanceVertex
=
edge
.
getInVertex
();
final
AtlasVertex
<?,?>
traitInstanceVertex
=
edge
.
getInVertex
();
if
(
traitInstanceVertex
!=
null
)
{
if
(
traitInstanceVertex
!=
null
)
{
LOG
.
debug
(
"Found trait instance vertex {}, mapping to instance {} "
,
traitInstanceVertex
,
if
(
LOG
.
isDebugEnabled
())
{
traitInstance
.
getTypeName
());
LOG
.
debug
(
"Found trait instance vertex {}, mapping to instance {} "
,
traitInstanceVertex
,
traitInstance
.
getTypeName
());
}
mapVertexToInstance
(
traitInstanceVertex
,
traitInstance
,
traitType
.
fieldMapping
().
fields
);
mapVertexToInstance
(
traitInstanceVertex
,
traitInstance
,
traitType
.
fieldMapping
().
fields
);
break
;
break
;
}
}
...
@@ -328,7 +373,10 @@ public final class GraphToTypedInstanceMapper {
...
@@ -328,7 +373,10 @@ public final class GraphToTypedInstanceMapper {
private
void
mapVertexToPrimitive
(
AtlasVertex
<?,?>
instanceVertex
,
ITypedInstance
typedInstance
,
private
void
mapVertexToPrimitive
(
AtlasVertex
<?,?>
instanceVertex
,
ITypedInstance
typedInstance
,
AttributeInfo
attributeInfo
)
throws
AtlasException
{
AttributeInfo
attributeInfo
)
throws
AtlasException
{
LOG
.
debug
(
"Adding primitive {} from vertex {}"
,
attributeInfo
,
instanceVertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Adding primitive {} from vertex {}"
,
attributeInfo
,
instanceVertex
);
}
final
String
vertexPropertyName
=
GraphHelper
.
getQualifiedFieldName
(
typedInstance
,
attributeInfo
);
final
String
vertexPropertyName
=
GraphHelper
.
getQualifiedFieldName
(
typedInstance
,
attributeInfo
);
if
(
GraphHelper
.
getSingleValuedProperty
(
instanceVertex
,
vertexPropertyName
,
Object
.
class
)
==
null
)
{
if
(
GraphHelper
.
getSingleValuedProperty
(
instanceVertex
,
vertexPropertyName
,
Object
.
class
)
==
null
)
{
return
;
return
;
...
@@ -369,8 +417,11 @@ public final class GraphToTypedInstanceMapper {
...
@@ -369,8 +417,11 @@ public final class GraphToTypedInstanceMapper {
if
(
referredVertex
!=
null
)
{
if
(
referredVertex
!=
null
)
{
switch
(
referredType
.
getTypeCategory
())
{
switch
(
referredType
.
getTypeCategory
())
{
case
STRUCT:
case
STRUCT:
LOG
.
debug
(
"Found struct instance vertex {}, mapping to instance {} "
,
referredVertex
,
if
(
LOG
.
isDebugEnabled
())
{
referredType
.
getName
());
LOG
.
debug
(
"Found struct instance vertex {}, mapping to instance {} "
,
referredVertex
,
referredType
.
getName
());
}
StructType
structType
=
(
StructType
)
referredType
;
StructType
structType
=
(
StructType
)
referredType
;
ITypedStruct
instance
=
structType
.
createInstance
();
ITypedStruct
instance
=
structType
.
createInstance
();
Map
<
String
,
AttributeInfo
>
fields
=
structType
.
fieldMapping
().
fields
;
Map
<
String
,
AttributeInfo
>
fields
=
structType
.
fieldMapping
().
fields
;
...
...
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
View file @
34d235f3
...
@@ -90,7 +90,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -90,7 +90,10 @@ public final class TypedInstanceToGraphMapper {
throws
AtlasException
{
throws
AtlasException
{
RequestContext
requestContext
=
RequestContext
.
get
();
RequestContext
requestContext
=
RequestContext
.
get
();
for
(
ITypedReferenceableInstance
typedInstance
:
typedInstances
)
{
for
(
ITypedReferenceableInstance
typedInstance
:
typedInstances
)
{
LOG
.
debug
(
"Adding/updating entity {}"
,
typedInstance
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Adding/updating entity {}"
,
typedInstance
);
}
Collection
<
IReferenceableInstance
>
newInstances
=
walkClassInstances
(
typedInstance
);
Collection
<
IReferenceableInstance
>
newInstances
=
walkClassInstances
(
typedInstance
);
TypeUtils
.
Pair
<
List
<
ITypedReferenceableInstance
>,
List
<
ITypedReferenceableInstance
>>
instancesPair
=
TypeUtils
.
Pair
<
List
<
ITypedReferenceableInstance
>,
List
<
ITypedReferenceableInstance
>>
instancesPair
=
createVerticesAndDiscoverInstances
(
newInstances
);
createVerticesAndDiscoverInstances
(
newInstances
);
...
@@ -126,7 +129,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -126,7 +129,10 @@ public final class TypedInstanceToGraphMapper {
EntityProcessor
entityProcessor
=
new
EntityProcessor
();
EntityProcessor
entityProcessor
=
new
EntityProcessor
();
try
{
try
{
LOG
.
debug
(
"Walking the object graph for instance {}"
,
typedInstance
.
toShortString
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Walking the object graph for instance {}"
,
typedInstance
.
toShortString
());
}
new
ObjectGraphWalker
(
typeSystem
,
entityProcessor
,
typedInstance
).
walk
();
new
ObjectGraphWalker
(
typeSystem
,
entityProcessor
,
typedInstance
).
walk
();
}
catch
(
AtlasException
me
)
{
}
catch
(
AtlasException
me
)
{
throw
new
RepositoryException
(
"TypeSystem error when walking the ObjectGraph"
,
me
);
throw
new
RepositoryException
(
"TypeSystem error when walking the ObjectGraph"
,
me
);
...
@@ -153,7 +159,9 @@ public final class TypedInstanceToGraphMapper {
...
@@ -153,7 +159,9 @@ public final class TypedInstanceToGraphMapper {
@Monitored
@Monitored
private
String
addOrUpdateAttributesAndTraits
(
Operation
operation
,
ITypedReferenceableInstance
typedInstance
)
private
String
addOrUpdateAttributesAndTraits
(
Operation
operation
,
ITypedReferenceableInstance
typedInstance
)
throws
AtlasException
{
throws
AtlasException
{
LOG
.
debug
(
"Adding/Updating typed instance {}"
,
typedInstance
.
toShortString
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Adding/Updating typed instance {}"
,
typedInstance
.
toShortString
());
}
Id
id
=
typedInstance
.
getId
();
Id
id
=
typedInstance
.
getId
();
if
(
id
==
null
)
{
// oops
if
(
id
==
null
)
{
// oops
...
@@ -178,8 +186,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -178,8 +186,10 @@ public final class TypedInstanceToGraphMapper {
void
mapInstanceToVertex
(
ITypedInstance
typedInstance
,
AtlasVertex
instanceVertex
,
void
mapInstanceToVertex
(
ITypedInstance
typedInstance
,
AtlasVertex
instanceVertex
,
Map
<
String
,
AttributeInfo
>
fields
,
boolean
mapOnlyUniqueAttributes
,
Operation
operation
)
Map
<
String
,
AttributeInfo
>
fields
,
boolean
mapOnlyUniqueAttributes
,
Operation
operation
)
throws
AtlasException
{
throws
AtlasException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Mapping instance {} to vertex {}"
,
typedInstance
.
toShortString
(),
string
(
instanceVertex
));
}
LOG
.
debug
(
"Mapping instance {} to vertex {}"
,
typedInstance
.
toShortString
(),
string
(
instanceVertex
));
for
(
AttributeInfo
attributeInfo
:
fields
.
values
())
{
for
(
AttributeInfo
attributeInfo
:
fields
.
values
())
{
if
(
mapOnlyUniqueAttributes
&&
!
attributeInfo
.
isUnique
)
{
if
(
mapOnlyUniqueAttributes
&&
!
attributeInfo
.
isUnique
)
{
continue
;
continue
;
...
@@ -189,7 +199,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -189,7 +199,10 @@ public final class TypedInstanceToGraphMapper {
GraphHelper
.
setProperty
(
instanceVertex
,
Constants
.
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
GraphHelper
.
setProperty
(
instanceVertex
,
Constants
.
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
RequestContext
.
get
().
getRequestTime
());
RequestContext
.
get
().
getRequestTime
());
GraphHelper
.
setProperty
(
instanceVertex
,
Constants
.
MODIFIED_BY_KEY
,
RequestContext
.
get
().
getUser
());
GraphHelper
.
setProperty
(
instanceVertex
,
Constants
.
MODIFIED_BY_KEY
,
RequestContext
.
get
().
getUser
());
LOG
.
debug
(
"Setting modifiedBy: {} and modifiedTime: {}"
,
RequestContext
.
get
().
getUser
(),
RequestContext
.
get
().
getRequestTime
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Setting modifiedBy: {} and modifiedTime: {}"
,
RequestContext
.
get
().
getUser
(),
RequestContext
.
get
().
getRequestTime
());
}
}
}
void
mapAttributeToVertex
(
ITypedInstance
typedInstance
,
AtlasVertex
instanceVertex
,
void
mapAttributeToVertex
(
ITypedInstance
typedInstance
,
AtlasVertex
instanceVertex
,
...
@@ -198,7 +211,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -198,7 +211,10 @@ public final class TypedInstanceToGraphMapper {
if
(
typedInstance
.
isValueSet
(
attributeInfo
.
name
)
||
operation
==
Operation
.
CREATE
)
{
if
(
typedInstance
.
isValueSet
(
attributeInfo
.
name
)
||
operation
==
Operation
.
CREATE
)
{
Object
attrValue
=
typedInstance
.
get
(
attributeInfo
.
name
);
Object
attrValue
=
typedInstance
.
get
(
attributeInfo
.
name
);
LOG
.
debug
(
"Mapping attribute {} = {}"
,
attributeInfo
.
name
,
attrValue
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Mapping attribute {} = {}"
,
attributeInfo
.
name
,
attrValue
);
}
switch
(
attributeInfo
.
dataType
().
getTypeCategory
())
{
switch
(
attributeInfo
.
dataType
().
getTypeCategory
())
{
case
PRIMITIVE:
case
PRIMITIVE:
...
@@ -246,14 +262,20 @@ public final class TypedInstanceToGraphMapper {
...
@@ -246,14 +262,20 @@ public final class TypedInstanceToGraphMapper {
List
<
ITypedReferenceableInstance
>
instancesToUpdate
=
new
ArrayList
<>();
List
<
ITypedReferenceableInstance
>
instancesToUpdate
=
new
ArrayList
<>();
for
(
IReferenceableInstance
instance
:
instances
)
{
for
(
IReferenceableInstance
instance
:
instances
)
{
LOG
.
debug
(
"Discovering instance to create/update for {}"
,
instance
.
toShortString
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Discovering instance to create/update for {}"
,
instance
.
toShortString
());
}
ITypedReferenceableInstance
newInstance
;
ITypedReferenceableInstance
newInstance
;
Id
id
=
instance
.
getId
();
Id
id
=
instance
.
getId
();
if
(!
idToVertexMap
.
containsKey
(
id
))
{
if
(!
idToVertexMap
.
containsKey
(
id
))
{
AtlasVertex
instanceVertex
;
AtlasVertex
instanceVertex
;
if
(
id
.
isAssigned
())
{
// has a GUID
if
(
id
.
isAssigned
())
{
// has a GUID
LOG
.
debug
(
"Instance has an assigned id {}"
,
instance
.
getId
().
_getId
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Instance has an assigned id {}"
,
instance
.
getId
().
_getId
());
}
instanceVertex
=
graphHelper
.
getVertexForGUID
(
id
.
id
);
instanceVertex
=
graphHelper
.
getVertexForGUID
(
id
.
id
);
if
(!(
instance
instanceof
ReferenceableInstance
))
{
if
(!(
instance
instanceof
ReferenceableInstance
))
{
throw
new
IllegalStateException
(
throw
new
IllegalStateException
(
...
@@ -269,7 +291,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -269,7 +291,10 @@ public final class TypedInstanceToGraphMapper {
//no entity with the given unique attribute, create new
//no entity with the given unique attribute, create new
if
(
instanceVertex
==
null
)
{
if
(
instanceVertex
==
null
)
{
LOG
.
debug
(
"Creating new vertex for instance {}"
,
instance
.
toShortString
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Creating new vertex for instance {}"
,
instance
.
toShortString
());
}
newInstance
=
classType
.
convert
(
instance
,
Multiplicity
.
REQUIRED
);
newInstance
=
classType
.
convert
(
instance
,
Multiplicity
.
REQUIRED
);
instanceVertex
=
graphHelper
.
createVertexWithIdentity
(
newInstance
,
classType
.
getAllSuperTypeNames
());
instanceVertex
=
graphHelper
.
createVertexWithIdentity
(
newInstance
,
classType
.
getAllSuperTypeNames
());
instancesToCreate
.
add
(
newInstance
);
instancesToCreate
.
add
(
newInstance
);
...
@@ -278,7 +303,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -278,7 +303,10 @@ public final class TypedInstanceToGraphMapper {
mapInstanceToVertex
(
newInstance
,
instanceVertex
,
classType
.
fieldMapping
().
fields
,
true
,
Operation
.
CREATE
);
mapInstanceToVertex
(
newInstance
,
instanceVertex
,
classType
.
fieldMapping
().
fields
,
true
,
Operation
.
CREATE
);
}
else
{
}
else
{
LOG
.
debug
(
"Re-using existing vertex {} for instance {}"
,
string
(
instanceVertex
),
instance
.
toShortString
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Re-using existing vertex {} for instance {}"
,
string
(
instanceVertex
),
instance
.
toShortString
());
}
if
(!(
instance
instanceof
ReferenceableInstance
))
{
if
(!(
instance
instanceof
ReferenceableInstance
))
{
throw
new
IllegalStateException
(
throw
new
IllegalStateException
(
String
.
format
(
"%s is not of type ITypedReferenceableInstance"
,
instance
.
toShortString
()));
String
.
format
(
"%s is not of type ITypedReferenceableInstance"
,
instance
.
toShortString
()));
...
@@ -306,7 +334,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -306,7 +334,10 @@ public final class TypedInstanceToGraphMapper {
private
void
addTraits
(
ITypedReferenceableInstance
typedInstance
,
AtlasVertex
instanceVertex
,
ClassType
classType
)
private
void
addTraits
(
ITypedReferenceableInstance
typedInstance
,
AtlasVertex
instanceVertex
,
ClassType
classType
)
throws
AtlasException
{
throws
AtlasException
{
for
(
String
traitName
:
typedInstance
.
getTraits
())
{
for
(
String
traitName
:
typedInstance
.
getTraits
())
{
LOG
.
debug
(
"mapping trait {}"
,
traitName
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"mapping trait {}"
,
traitName
);
}
GraphHelper
.
addProperty
(
instanceVertex
,
Constants
.
TRAIT_NAMES_PROPERTY_KEY
,
traitName
);
GraphHelper
.
addProperty
(
instanceVertex
,
Constants
.
TRAIT_NAMES_PROPERTY_KEY
,
traitName
);
ITypedStruct
traitInstance
=
(
ITypedStruct
)
typedInstance
.
getTrait
(
traitName
);
ITypedStruct
traitInstance
=
(
ITypedStruct
)
typedInstance
.
getTrait
(
traitName
);
...
@@ -319,8 +350,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -319,8 +350,10 @@ public final class TypedInstanceToGraphMapper {
private
void
mapArrayCollectionToVertex
(
ITypedInstance
typedInstance
,
AtlasVertex
instanceVertex
,
private
void
mapArrayCollectionToVertex
(
ITypedInstance
typedInstance
,
AtlasVertex
instanceVertex
,
AttributeInfo
attributeInfo
,
Operation
operation
)
throws
AtlasException
{
AttributeInfo
attributeInfo
,
Operation
operation
)
throws
AtlasException
{
LOG
.
debug
(
"Mapping instance {} for array attribute {} vertex {}"
,
typedInstance
.
toShortString
(),
if
(
LOG
.
isDebugEnabled
())
{
attributeInfo
.
name
,
string
(
instanceVertex
));
LOG
.
debug
(
"Mapping instance {} for array attribute {} vertex {}"
,
typedInstance
.
toShortString
(),
attributeInfo
.
name
,
string
(
instanceVertex
));
}
List
newElements
=
(
List
)
typedInstance
.
get
(
attributeInfo
.
name
);
List
newElements
=
(
List
)
typedInstance
.
get
(
attributeInfo
.
name
);
boolean
newAttributeEmpty
=
(
newElements
==
null
||
newElements
.
isEmpty
());
boolean
newAttributeEmpty
=
(
newElements
==
null
||
newElements
.
isEmpty
());
...
@@ -338,8 +371,11 @@ public final class TypedInstanceToGraphMapper {
...
@@ -338,8 +371,11 @@ public final class TypedInstanceToGraphMapper {
for
(;
index
<
newElements
.
size
();
index
++)
{
for
(;
index
<
newElements
.
size
();
index
++)
{
Object
currentElement
=
(
currentElements
!=
null
&&
index
<
currentElements
.
size
())
?
Object
currentElement
=
(
currentElements
!=
null
&&
index
<
currentElements
.
size
())
?
currentElements
.
get
(
index
)
:
null
;
currentElements
.
get
(
index
)
:
null
;
LOG
.
debug
(
"Adding/updating element at position {}, current element {}, new element {}"
,
index
,
if
(
LOG
.
isDebugEnabled
())
{
currentElement
,
newElements
.
get
(
index
));
LOG
.
debug
(
"Adding/updating element at position {}, current element {}, new element {}"
,
index
,
currentElement
,
newElements
.
get
(
index
));
}
Object
newEntry
=
addOrUpdateCollectionEntry
(
instanceVertex
,
attributeInfo
,
elementType
,
Object
newEntry
=
addOrUpdateCollectionEntry
(
instanceVertex
,
attributeInfo
,
elementType
,
newElements
.
get
(
index
),
currentElement
,
propertyName
,
operation
);
newElements
.
get
(
index
),
currentElement
,
propertyName
,
operation
);
newElementsCreated
.
add
(
newEntry
);
newElementsCreated
.
add
(
newEntry
);
...
@@ -372,7 +408,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -372,7 +408,10 @@ public final class TypedInstanceToGraphMapper {
List
<
AtlasEdge
>
cloneElements
=
new
ArrayList
<>(
currentEntries
);
List
<
AtlasEdge
>
cloneElements
=
new
ArrayList
<>(
currentEntries
);
cloneElements
.
removeAll
(
newEntries
);
cloneElements
.
removeAll
(
newEntries
);
List
<
AtlasEdge
>
additionalElements
=
new
ArrayList
<>();
List
<
AtlasEdge
>
additionalElements
=
new
ArrayList
<>();
LOG
.
debug
(
"Removing unused entries from the old collection - {}"
,
cloneElements
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Removing unused entries from the old collection - {}"
,
cloneElements
);
}
if
(!
cloneElements
.
isEmpty
())
{
if
(!
cloneElements
.
isEmpty
())
{
for
(
AtlasEdge
edge
:
cloneElements
)
{
for
(
AtlasEdge
edge
:
cloneElements
)
{
...
@@ -393,8 +432,11 @@ public final class TypedInstanceToGraphMapper {
...
@@ -393,8 +432,11 @@ public final class TypedInstanceToGraphMapper {
private
void
mapMapCollectionToVertex
(
ITypedInstance
typedInstance
,
AtlasVertex
instanceVertex
,
private
void
mapMapCollectionToVertex
(
ITypedInstance
typedInstance
,
AtlasVertex
instanceVertex
,
AttributeInfo
attributeInfo
,
Operation
operation
)
throws
AtlasException
{
AttributeInfo
attributeInfo
,
Operation
operation
)
throws
AtlasException
{
LOG
.
debug
(
"Mapping instance {} to vertex {} for attribute {}"
,
typedInstance
.
toShortString
(),
string
(
instanceVertex
),
if
(
LOG
.
isDebugEnabled
())
{
attributeInfo
.
name
);
LOG
.
debug
(
"Mapping instance {} to vertex {} for attribute {}"
,
typedInstance
.
toShortString
(),
string
(
instanceVertex
),
attributeInfo
.
name
);
}
@SuppressWarnings
(
"unchecked"
)
Map
<
Object
,
Object
>
newAttribute
=
@SuppressWarnings
(
"unchecked"
)
Map
<
Object
,
Object
>
newAttribute
=
(
Map
<
Object
,
Object
>)
typedInstance
.
get
(
attributeInfo
.
name
);
(
Map
<
Object
,
Object
>)
typedInstance
.
get
(
attributeInfo
.
name
);
...
@@ -544,8 +586,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -544,8 +586,10 @@ public final class TypedInstanceToGraphMapper {
// add a new vertex for the struct or trait instance
// add a new vertex for the struct or trait instance
AtlasVertex
structInstanceVertex
=
graphHelper
.
createVertexWithoutIdentity
(
structInstance
.
getTypeName
(),
null
,
AtlasVertex
structInstanceVertex
=
graphHelper
.
createVertexWithoutIdentity
(
structInstance
.
getTypeName
(),
null
,
Collections
.<
String
>
emptySet
());
// no super types for struct type
Collections
.<
String
>
emptySet
());
// no super types for struct type
LOG
.
debug
(
"created vertex {} for struct {} value {}"
,
string
(
structInstanceVertex
),
attributeInfo
.
name
,
if
(
LOG
.
isDebugEnabled
())
{
structInstance
.
toShortString
());
LOG
.
debug
(
"created vertex {} for struct {} value {}"
,
string
(
structInstanceVertex
),
attributeInfo
.
name
,
structInstance
.
toShortString
());
}
// map all the attributes to this new vertex
// map all the attributes to this new vertex
mapInstanceToVertex
(
structInstance
,
structInstanceVertex
,
structInstance
.
fieldMapping
().
fields
,
false
,
mapInstanceToVertex
(
structInstance
,
structInstanceVertex
,
structInstance
.
fieldMapping
().
fields
,
false
,
...
@@ -561,7 +605,9 @@ public final class TypedInstanceToGraphMapper {
...
@@ -561,7 +605,9 @@ public final class TypedInstanceToGraphMapper {
//Already existing vertex. Update
//Already existing vertex. Update
AtlasVertex
structInstanceVertex
=
currentEdge
.
getInVertex
();
AtlasVertex
structInstanceVertex
=
currentEdge
.
getInVertex
();
LOG
.
debug
(
"Updating struct vertex {} with struct {}"
,
string
(
structInstanceVertex
),
newAttributeValue
.
toShortString
());
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Updating struct vertex {} with struct {}"
,
string
(
structInstanceVertex
),
newAttributeValue
.
toShortString
());
}
// Update attributes
// Update attributes
final
MessageDigest
digester
=
MD5Utils
.
getDigester
();
final
MessageDigest
digester
=
MD5Utils
.
getDigester
();
...
@@ -570,7 +616,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -570,7 +616,10 @@ public final class TypedInstanceToGraphMapper {
if
(!
newSignature
.
equals
(
curSignature
))
{
if
(!
newSignature
.
equals
(
curSignature
))
{
//Update struct vertex instance only if there is a change
//Update struct vertex instance only if there is a change
LOG
.
debug
(
"Updating struct {} since signature has changed {} {} "
,
newAttributeValue
,
curSignature
,
newSignature
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Updating struct {} since signature has changed {} {} "
,
newAttributeValue
,
curSignature
,
newSignature
);
}
mapInstanceToVertex
(
newAttributeValue
,
structInstanceVertex
,
newAttributeValue
.
fieldMapping
().
fields
,
false
,
operation
);
mapInstanceToVertex
(
newAttributeValue
,
structInstanceVertex
,
newAttributeValue
.
fieldMapping
().
fields
,
false
,
operation
);
GraphHelper
.
setProperty
(
structInstanceVertex
,
SIGNATURE_HASH_PROPERTY_KEY
,
String
.
valueOf
(
newSignature
));
GraphHelper
.
setProperty
(
structInstanceVertex
,
SIGNATURE_HASH_PROPERTY_KEY
,
String
.
valueOf
(
newSignature
));
}
}
...
@@ -638,7 +687,10 @@ public final class TypedInstanceToGraphMapper {
...
@@ -638,7 +687,10 @@ public final class TypedInstanceToGraphMapper {
ITypedReferenceableInstance
newAttributeValue
,
ITypedReferenceableInstance
newAttributeValue
,
AtlasVertex
newVertex
,
AttributeInfo
attributeInfo
,
AtlasVertex
newVertex
,
AttributeInfo
attributeInfo
,
String
edgeLabel
)
throws
AtlasException
{
String
edgeLabel
)
throws
AtlasException
{
LOG
.
debug
(
"Updating {} for reference attribute {}"
,
string
(
currentEdge
),
attributeInfo
.
name
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Updating {} for reference attribute {}"
,
string
(
currentEdge
),
attributeInfo
.
name
);
}
// Update edge if it exists
// Update edge if it exists
AtlasVertex
currentVertex
=
currentEdge
.
getInVertex
();
AtlasVertex
currentVertex
=
currentEdge
.
getInVertex
();
String
currentEntityId
=
GraphHelper
.
getGuid
(
currentVertex
);
String
currentEntityId
=
GraphHelper
.
getGuid
(
currentVertex
);
...
@@ -663,7 +715,9 @@ public final class TypedInstanceToGraphMapper {
...
@@ -663,7 +715,9 @@ public final class TypedInstanceToGraphMapper {
final
String
traitName
=
traitInstance
.
getTypeName
();
final
String
traitName
=
traitInstance
.
getTypeName
();
AtlasVertex
traitInstanceVertex
=
graphHelper
.
createVertexWithoutIdentity
(
traitInstance
.
getTypeName
(),
null
,
AtlasVertex
traitInstanceVertex
=
graphHelper
.
createVertexWithoutIdentity
(
traitInstance
.
getTypeName
(),
null
,
typeSystem
.
getDataType
(
TraitType
.
class
,
traitName
).
getAllSuperTypeNames
());
typeSystem
.
getDataType
(
TraitType
.
class
,
traitName
).
getAllSuperTypeNames
());
LOG
.
debug
(
"created vertex {} for trait {}"
,
string
(
traitInstanceVertex
),
traitName
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"created vertex {} for trait {}"
,
string
(
traitInstanceVertex
),
traitName
);
}
// map all the attributes to this newly created AtlasVertex
// map all the attributes to this newly created AtlasVertex
mapInstanceToVertex
(
traitInstance
,
traitInstanceVertex
,
traitInstance
.
fieldMapping
().
fields
,
false
,
Operation
.
CREATE
);
mapInstanceToVertex
(
traitInstance
,
traitInstanceVertex
,
traitInstance
.
fieldMapping
().
fields
,
false
,
Operation
.
CREATE
);
...
...
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