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
3e4fb5cd
Commit
3e4fb5cd
authored
Mar 31, 2019
by
Madhan Neethiraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3054: updated notification pre-process to handle updates to ownedRef attributes - #3
parent
d234de2d
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
325 additions
and
139 deletions
+325
-139
AtlasArrayType.java
intg/src/main/java/org/apache/atlas/type/AtlasArrayType.java
+0
-0
AtlasEntityType.java
.../src/main/java/org/apache/atlas/type/AtlasEntityType.java
+36
-40
AtlasRelationshipType.java
...ain/java/org/apache/atlas/type/AtlasRelationshipType.java
+9
-2
AtlasStructType.java
.../src/main/java/org/apache/atlas/type/AtlasStructType.java
+1
-0
AtlasTypeUtil.java
intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
+27
-0
TestAtlasStructType.java
.../test/java/org/apache/atlas/type/TestAtlasStructType.java
+2
-2
AtlasStructFormatConverter.java
...las/repository/converters/AtlasStructFormatConverter.java
+1
-1
AtlasEntityStream.java
...he/atlas/repository/store/graph/v2/AtlasEntityStream.java
+5
-0
NotificationHookConsumer.java
...g/apache/atlas/notification/NotificationHookConsumer.java
+49
-23
EntityPreprocessor.java
...e/atlas/notification/preprocessor/EntityPreprocessor.java
+1
-0
HivePreprocessor.java
...che/atlas/notification/preprocessor/HivePreprocessor.java
+4
-59
PreprocessorContext.java
.../atlas/notification/preprocessor/PreprocessorContext.java
+179
-7
RdbmsPreprocessor.java
...he/atlas/notification/preprocessor/RdbmsPreprocessor.java
+11
-5
No files found.
intg/src/main/java/org/apache/atlas/type/AtlasArrayType.java
View file @
3e4fb5cd
This diff is collapsed.
Click to expand it.
intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
View file @
3e4fb5cd
...
@@ -22,7 +22,6 @@ import org.apache.atlas.AtlasErrorCode;
...
@@ -22,7 +22,6 @@ import org.apache.atlas.AtlasErrorCode;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef.AtlasRelationshipAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef.AtlasRelationshipAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
...
@@ -544,7 +543,9 @@ public class AtlasEntityType extends AtlasStructType {
...
@@ -544,7 +543,9 @@ public class AtlasEntityType extends AtlasStructType {
superType
.
normalizeAttributeValues
(
ent
);
superType
.
normalizeAttributeValues
(
ent
);
}
}
normalizeValues
(
ent
);
super
.
normalizeAttributeValues
(
ent
);
normalizeRelationshipAttributeValues
(
ent
,
false
);
}
}
}
}
...
@@ -555,6 +556,8 @@ public class AtlasEntityType extends AtlasStructType {
...
@@ -555,6 +556,8 @@ public class AtlasEntityType extends AtlasStructType {
}
}
super
.
normalizeAttributeValuesForUpdate
(
ent
);
super
.
normalizeAttributeValuesForUpdate
(
ent
);
normalizeRelationshipAttributeValues
(
ent
,
true
);
}
}
}
}
...
@@ -565,7 +568,9 @@ public class AtlasEntityType extends AtlasStructType {
...
@@ -565,7 +568,9 @@ public class AtlasEntityType extends AtlasStructType {
superType
.
normalizeAttributeValues
(
obj
);
superType
.
normalizeAttributeValues
(
obj
);
}
}
normalizeValues
(
obj
);
super
.
normalizeAttributeValues
(
obj
);
normalizeRelationshipAttributeValues
(
obj
,
false
);
}
}
}
}
...
@@ -576,6 +581,8 @@ public class AtlasEntityType extends AtlasStructType {
...
@@ -576,6 +581,8 @@ public class AtlasEntityType extends AtlasStructType {
}
}
super
.
normalizeAttributeValuesForUpdate
(
obj
);
super
.
normalizeAttributeValuesForUpdate
(
obj
);
normalizeRelationshipAttributeValues
(
obj
,
true
);
}
}
}
}
...
@@ -743,67 +750,56 @@ public class AtlasEntityType extends AtlasStructType {
...
@@ -743,67 +750,56 @@ public class AtlasEntityType extends AtlasStructType {
return
ret
;
return
ret
;
}
}
private
void
normalizeRelationshipAttributeValues
(
AtlasStruct
obj
)
{
private
void
normalizeRelationshipAttributeValues
(
AtlasEntity
entity
,
boolean
isUpdate
)
{
if
(
obj
!=
null
&&
obj
instanceof
AtlasEntity
)
{
if
(
entity
!=
null
)
{
AtlasEntity
entityObj
=
(
AtlasEntity
)
obj
;
for
(
String
attributeName
:
relationshipAttributes
.
keySet
())
{
for
(
String
attributeName
:
relationshipAttributes
.
keySet
())
{
if
(
entity
Obj
.
hasRelationshipAttribute
(
attributeName
))
{
if
(
entity
.
hasRelationshipAttribute
(
attributeName
))
{
Object
attributeValue
=
entityObj
.
getRelationshipAttribute
(
attributeName
);
Object
attributeValue
=
entity
.
getRelationshipAttribute
(
attributeName
);
String
relationshipType
=
AtlasEntityUtil
.
getRelationshipType
(
attributeValue
);
String
relationshipType
=
AtlasEntityUtil
.
getRelationshipType
(
attributeValue
);
AtlasAttribute
attribute
=
getRelationshipAttribute
(
attributeName
,
relationshipType
);
AtlasAttribute
attribute
=
getRelationshipAttribute
(
attributeName
,
relationshipType
);
AtlasAttributeDef
attributeDef
=
attribute
.
getAttributeDef
();
attributeValue
=
getNormalizedValue
(
attributeValue
,
attributeDef
);
if
(
attribute
!=
null
)
{
AtlasType
attrType
=
attribute
.
getAttributeType
();
if
(
isValidRelationshipType
(
attrType
))
{
if
(
isUpdate
)
{
attributeValue
=
attrType
.
getNormalizedValueForUpdate
(
attributeValue
);
}
else
{
attributeValue
=
attrType
.
getNormalizedValue
(
attributeValue
);
}
entityObj
.
setRelationshipAttribute
(
attributeName
,
attributeValue
);
entity
.
setRelationshipAttribute
(
attributeName
,
attributeValue
);
}
}
}
}
}
}
}
}
}
}
public
void
normalizeRelationshipAttributeValues
(
Map
<
String
,
Object
>
obj
)
{
public
void
normalizeRelationshipAttributeValues
(
Map
<
String
,
Object
>
obj
,
boolean
isUpdate
)
{
if
(
obj
!=
null
)
{
if
(
obj
!=
null
)
{
for
(
String
attributeName
:
relationshipAttributes
.
keySet
())
{
for
(
String
attributeName
:
relationshipAttributes
.
keySet
())
{
if
(
obj
.
containsKey
(
attributeName
))
{
if
(
obj
.
containsKey
(
attributeName
))
{
Object
attributeValue
=
obj
.
get
(
attributeName
);
Object
attributeValue
=
obj
.
get
(
attributeName
);
String
relationshipType
=
AtlasEntityUtil
.
getRelationshipType
(
attributeValue
);
String
relationshipType
=
AtlasEntityUtil
.
getRelationshipType
(
attributeValue
);
AtlasAttribute
attribute
=
getRelationshipAttribute
(
attributeName
,
relationshipType
);
AtlasAttribute
attribute
=
getRelationshipAttribute
(
attributeName
,
relationshipType
);
AtlasAttributeDef
attributeDef
=
attribute
.
getAttributeDef
();
attributeValue
=
getNormalizedValue
(
attributeValue
,
attributeDef
);
obj
.
put
(
attributeName
,
attributeValue
);
}
}
}
}
private
Object
getNormalizedValue
(
Object
value
,
AtlasAttributeDef
attributeDef
)
{
String
relationshipType
=
AtlasEntityUtil
.
getRelationshipType
(
value
);
AtlasAttribute
attribute
=
getRelationshipAttribute
(
attributeDef
.
getName
(),
relationshipType
);
if
(
attribute
!=
null
)
{
if
(
attribute
!=
null
)
{
AtlasType
attrType
=
attribute
.
getAttributeType
();
AtlasType
attrType
=
attribute
.
getAttributeType
();
if
(
isValidRelationshipType
(
attrType
)
&&
value
!=
null
)
{
if
(
isValidRelationshipType
(
attrType
))
{
return
attrType
.
getNormalizedValue
(
value
);
if
(
isUpdate
)
{
}
attributeValue
=
attrType
.
getNormalizedValueForUpdate
(
attributeValue
);
}
else
{
attributeValue
=
attrType
.
getNormalizedValue
(
attributeValue
);
}
}
return
null
;
obj
.
put
(
attributeName
,
attributeValue
);
}
}
}
}
}
private
void
normalizeValues
(
AtlasEntity
ent
)
{
super
.
normalizeAttributeValues
(
ent
);
normalizeRelationshipAttributeValues
(
ent
);
}
}
private
void
normalizeValues
(
Map
<
String
,
Object
>
obj
)
{
super
.
normalizeAttributeValues
(
obj
);
normalizeRelationshipAttributeValues
(
obj
);
}
}
private
boolean
validateRelationshipAttributes
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
private
boolean
validateRelationshipAttributes
(
Object
obj
,
String
objName
,
List
<
String
>
messages
)
{
...
...
intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
View file @
3e4fb5cd
...
@@ -346,8 +346,15 @@ public class AtlasRelationshipType extends AtlasStructType {
...
@@ -346,8 +346,15 @@ public class AtlasRelationshipType extends AtlasStructType {
attributeDef
.
addConstraint
(
constraint
);
attributeDef
.
addConstraint
(
constraint
);
}
}
attribute
=
new
AtlasAttribute
(
entityType
,
attributeDef
,
AtlasType
attrType
=
typeRegistry
.
getType
(
attrTypeName
);
typeRegistry
.
getType
(
attrTypeName
),
getTypeName
(),
relationshipLabel
);
if
(
attrType
instanceof
AtlasArrayType
)
{
AtlasArrayType
arrayType
=
(
AtlasArrayType
)
attrType
;
arrayType
.
setCardinality
(
attributeDef
.
getCardinality
());
}
attribute
=
new
AtlasAttribute
(
entityType
,
attributeDef
,
attrType
,
getTypeName
(),
relationshipLabel
);
attribute
.
setLegacyAttribute
(
endDef
.
getIsLegacyAttribute
());
attribute
.
setLegacyAttribute
(
endDef
.
getIsLegacyAttribute
());
}
else
{
}
else
{
...
...
intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
View file @
3e4fb5cd
...
@@ -99,6 +99,7 @@ public class AtlasStructType extends AtlasType {
...
@@ -99,6 +99,7 @@ public class AtlasStructType extends AtlasType {
arrayType
.
setMinCount
(
attributeDef
.
getValuesMinCount
());
arrayType
.
setMinCount
(
attributeDef
.
getValuesMinCount
());
arrayType
.
setMaxCount
(
attributeDef
.
getValuesMaxCount
());
arrayType
.
setMaxCount
(
attributeDef
.
getValuesMaxCount
());
arrayType
.
setCardinality
(
cardinality
);
}
}
//check if attribute type is not classification
//check if attribute type is not classification
...
...
intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
View file @
3e4fb5cd
...
@@ -38,6 +38,7 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinali
...
@@ -38,6 +38,7 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinali
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef
;
import
org.apache.atlas.model.typedef.AtlasTypeDefHeader
;
import
org.apache.atlas.model.typedef.AtlasTypeDefHeader
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.type.AtlasStructType.AtlasAttribute
;
import
org.apache.atlas.v1.model.typedef.AttributeDefinition
;
import
org.apache.atlas.v1.model.typedef.AttributeDefinition
;
import
org.apache.atlas.v1.model.typedef.ClassTypeDefinition
;
import
org.apache.atlas.v1.model.typedef.ClassTypeDefinition
;
import
org.apache.atlas.v1.model.typedef.Multiplicity
;
import
org.apache.atlas.v1.model.typedef.Multiplicity
;
...
@@ -413,10 +414,36 @@ public class AtlasTypeUtil {
...
@@ -413,10 +414,36 @@ public class AtlasTypeUtil {
return
new
AtlasRelatedObjectId
(
getAtlasObjectId
(
entity
));
return
new
AtlasRelatedObjectId
(
getAtlasObjectId
(
entity
));
}
}
public
static
AtlasRelatedObjectId
toAtlasRelatedObjectId
(
AtlasEntity
entity
,
AtlasTypeRegistry
typeRegistry
)
{
return
new
AtlasRelatedObjectId
(
getAtlasObjectId
(
entity
,
typeRegistry
));
}
public
static
AtlasObjectId
getAtlasObjectId
(
AtlasEntity
entity
)
{
public
static
AtlasObjectId
getAtlasObjectId
(
AtlasEntity
entity
)
{
return
new
AtlasObjectId
(
entity
.
getGuid
(),
entity
.
getTypeName
());
return
new
AtlasObjectId
(
entity
.
getGuid
(),
entity
.
getTypeName
());
}
}
public
static
AtlasObjectId
getAtlasObjectId
(
AtlasEntity
entity
,
AtlasTypeRegistry
typeRegistry
)
{
String
typeName
=
entity
.
getTypeName
();
AtlasEntityType
entityType
=
typeRegistry
.
getEntityTypeByName
(
typeName
);
Map
<
String
,
Object
>
uniqAttributes
=
null
;
if
(
entityType
!=
null
&&
MapUtils
.
isNotEmpty
(
entityType
.
getUniqAttributes
()))
{
for
(
AtlasAttribute
attribute
:
entityType
.
getUniqAttributes
().
values
())
{
Object
attrValue
=
entity
.
getAttribute
(
attribute
.
getName
());
if
(
attrValue
!=
null
)
{
if
(
uniqAttributes
==
null
)
{
uniqAttributes
=
new
HashMap
<>();
}
uniqAttributes
.
put
(
attribute
.
getName
(),
attrValue
);
}
}
}
return
new
AtlasObjectId
(
entity
.
getGuid
(),
typeName
,
uniqAttributes
);
}
public
static
AtlasObjectId
getAtlasObjectId
(
AtlasEntityHeader
header
)
{
public
static
AtlasObjectId
getAtlasObjectId
(
AtlasEntityHeader
header
)
{
return
new
AtlasObjectId
(
header
.
getGuid
(),
header
.
getTypeName
());
return
new
AtlasObjectId
(
header
.
getGuid
(),
header
.
getTypeName
());
}
}
...
...
intg/src/test/java/org/apache/atlas/type/TestAtlasStructType.java
View file @
3e4fb5cd
...
@@ -63,12 +63,12 @@ public class TestAtlasStructType {
...
@@ -63,12 +63,12 @@ public class TestAtlasStructType {
multiValuedAttribMin
.
setName
(
MULTI_VAL_ATTR_NAME_MIN
);
multiValuedAttribMin
.
setName
(
MULTI_VAL_ATTR_NAME_MIN
);
multiValuedAttribMin
.
setTypeName
(
AtlasBaseTypeDef
.
getArrayTypeName
(
ATLAS_TYPE_INT
));
multiValuedAttribMin
.
setTypeName
(
AtlasBaseTypeDef
.
getArrayTypeName
(
ATLAS_TYPE_INT
));
multiValuedAttribMin
.
setCardinality
(
Cardinality
.
SE
T
);
multiValuedAttribMin
.
setCardinality
(
Cardinality
.
LIS
T
);
multiValuedAttribMin
.
setValuesMinCount
(
MULTI_VAL_ATTR_MIN_COUNT
);
multiValuedAttribMin
.
setValuesMinCount
(
MULTI_VAL_ATTR_MIN_COUNT
);
multiValuedAttribMax
.
setName
(
MULTI_VAL_ATTR_NAME_MAX
);
multiValuedAttribMax
.
setName
(
MULTI_VAL_ATTR_NAME_MAX
);
multiValuedAttribMax
.
setTypeName
(
AtlasBaseTypeDef
.
getArrayTypeName
(
ATLAS_TYPE_INT
));
multiValuedAttribMax
.
setTypeName
(
AtlasBaseTypeDef
.
getArrayTypeName
(
ATLAS_TYPE_INT
));
multiValuedAttribMax
.
setCardinality
(
Cardinality
.
LIS
T
);
multiValuedAttribMax
.
setCardinality
(
Cardinality
.
SE
T
);
multiValuedAttribMax
.
setValuesMaxCount
(
MULTI_VAL_ATTR_MAX_COUNT
);
multiValuedAttribMax
.
setValuesMaxCount
(
MULTI_VAL_ATTR_MAX_COUNT
);
AtlasStructDef
structDef
=
ModelTestUtil
.
newStructDef
();
AtlasStructDef
structDef
=
ModelTestUtil
.
newStructDef
();
...
...
repository/src/main/java/org/apache/atlas/repository/converters/AtlasStructFormatConverter.java
View file @
3e4fb5cd
...
@@ -190,7 +190,7 @@ public class AtlasStructFormatConverter extends AtlasAbstractFormatConverter {
...
@@ -190,7 +190,7 @@ public class AtlasStructFormatConverter extends AtlasAbstractFormatConverter {
if
(
entities
!=
null
)
{
if
(
entities
!=
null
)
{
v2Value
=
entities
;
v2Value
=
entities
;
attrType
=
new
AtlasArrayType
(
entityType
);
attrType
=
new
AtlasArrayType
(
entityType
,
arrayType
.
getMinCount
(),
arrayType
.
getMaxCount
(),
arrayType
.
getCardinality
()
);
if
(
LOG
.
isDebugEnabled
())
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"{}: replaced objIdList with entityList"
,
attr
.
getQualifiedName
());
LOG
.
debug
(
"{}: replaced objIdList with entityList"
,
attr
.
getQualifiedName
());
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStream.java
View file @
3e4fb5cd
...
@@ -22,6 +22,7 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
...
@@ -22,6 +22,7 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
public
class
AtlasEntityStream
implements
EntityStream
{
public
class
AtlasEntityStream
implements
EntityStream
{
protected
final
AtlasEntitiesWithExtInfo
entitiesWithExtInfo
;
protected
final
AtlasEntitiesWithExtInfo
entitiesWithExtInfo
;
...
@@ -33,6 +34,10 @@ public class AtlasEntityStream implements EntityStream {
...
@@ -33,6 +34,10 @@ public class AtlasEntityStream implements EntityStream {
this
(
new
AtlasEntitiesWithExtInfo
(
entity
),
null
);
this
(
new
AtlasEntitiesWithExtInfo
(
entity
),
null
);
}
}
public
AtlasEntityStream
(
List
<
AtlasEntity
>
entities
)
{
this
(
new
AtlasEntitiesWithExtInfo
(
entities
),
null
);
}
public
AtlasEntityStream
(
AtlasEntityWithExtInfo
entityWithExtInfo
)
{
public
AtlasEntityStream
(
AtlasEntityWithExtInfo
entityWithExtInfo
)
{
this
(
new
AtlasEntitiesWithExtInfo
(
entityWithExtInfo
),
null
);
this
(
new
AtlasEntitiesWithExtInfo
(
entityWithExtInfo
),
null
);
}
}
...
...
webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
View file @
3e4fb5cd
...
@@ -34,6 +34,7 @@ import org.apache.atlas.listener.ActiveStateChangeHandler;
...
@@ -34,6 +34,7 @@ import org.apache.atlas.listener.ActiveStateChangeHandler;
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
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo
;
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.model.notification.HookNotification
;
import
org.apache.atlas.model.notification.HookNotification
;
...
@@ -79,7 +80,6 @@ import javax.inject.Inject;
...
@@ -79,7 +80,6 @@ import javax.inject.Inject;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
...
@@ -492,7 +492,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -492,7 +492,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
return
;
return
;
}
}
preProcessNotificationMessage
(
kafkaMsg
);
PreprocessorContext
context
=
preProcessNotificationMessage
(
kafkaMsg
);
if
(
isEmptyMessage
(
kafkaMsg
))
{
if
(
isEmptyMessage
(
kafkaMsg
))
{
commit
(
kafkaMsg
);
commit
(
kafkaMsg
);
...
@@ -525,7 +525,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -525,7 +525,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
AtlasClient
.
API_V1
.
CREATE_ENTITY
.
getNormalizedPath
());
AtlasClient
.
API_V1
.
CREATE_ENTITY
.
getNormalizedPath
());
}
}
createOrUpdate
(
entities
,
false
);
createOrUpdate
(
entities
,
false
,
context
);
}
}
break
;
break
;
...
@@ -546,7 +546,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -546,7 +546,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
// There should only be one root entity
// There should only be one root entity
entities
.
getEntities
().
get
(
0
).
setGuid
(
guid
);
entities
.
getEntities
().
get
(
0
).
setGuid
(
guid
);
createOrUpdate
(
entities
,
true
);
createOrUpdate
(
entities
,
true
,
context
);
}
}
break
;
break
;
...
@@ -579,7 +579,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -579,7 +579,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
AtlasClientV2
.
API_V2
.
UPDATE_ENTITY
.
getNormalizedPath
());
AtlasClientV2
.
API_V2
.
UPDATE_ENTITY
.
getNormalizedPath
());
}
}
createOrUpdate
(
entities
,
false
);
createOrUpdate
(
entities
,
false
,
context
);
}
}
break
;
break
;
...
@@ -593,7 +593,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -593,7 +593,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
AtlasClientV2
.
API_V2
.
CREATE_ENTITY
.
getNormalizedPath
());
AtlasClientV2
.
API_V2
.
CREATE_ENTITY
.
getNormalizedPath
());
}
}
createOrUpdate
(
entities
,
false
);
createOrUpdate
(
entities
,
false
,
context
);
}
}
break
;
break
;
...
@@ -622,7 +622,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -622,7 +622,7 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
AtlasClientV2
.
API_V2
.
UPDATE_ENTITY
.
getNormalizedPath
());
AtlasClientV2
.
API_V2
.
UPDATE_ENTITY
.
getNormalizedPath
());
}
}
createOrUpdate
(
entities
,
false
);
createOrUpdate
(
entities
,
false
,
context
);
}
}
break
;
break
;
...
@@ -708,15 +708,15 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -708,15 +708,15 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
}
}
}
}
private
void
createOrUpdate
(
AtlasEntitiesWithExtInfo
entities
,
boolean
isPartialUpdate
)
throws
AtlasBaseException
{
private
void
createOrUpdate
(
AtlasEntitiesWithExtInfo
entities
,
boolean
isPartialUpdate
,
PreprocessorContext
context
)
throws
AtlasBaseException
{
List
<
AtlasEntity
>
entitiesList
=
entities
.
getEntities
();
List
<
AtlasEntity
>
entitiesList
=
entities
.
getEntities
();
AtlasEntityStream
entityStream
=
new
AtlasEntityStream
(
entities
);
AtlasEntityStream
entityStream
=
new
AtlasEntityStream
(
entities
);
if
(
commitBatchSize
<=
0
||
entitiesList
.
size
()
<=
commitBatchSize
)
{
if
(
commitBatchSize
<=
0
||
entitiesList
.
size
()
<=
commitBatchSize
)
{
atlasEntityStore
.
createOrUpdate
(
entityStream
,
isPartialUpdate
);
EntityMutationResponse
response
=
atlasEntityStore
.
createOrUpdate
(
entityStream
,
isPartialUpdate
);
}
else
{
Map
<
String
,
String
>
guidAssignments
=
new
HashMap
<>();
recordProcessedEntities
(
response
,
context
);
}
else
{
for
(
int
fromIdx
=
0
;
fromIdx
<
entitiesList
.
size
();
fromIdx
+=
commitBatchSize
)
{
for
(
int
fromIdx
=
0
;
fromIdx
<
entitiesList
.
size
();
fromIdx
+=
commitBatchSize
)
{
int
toIndex
=
fromIdx
+
commitBatchSize
;
int
toIndex
=
fromIdx
+
commitBatchSize
;
...
@@ -726,20 +726,30 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -726,20 +726,30 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
List
<
AtlasEntity
>
entitiesBatch
=
new
ArrayList
<>(
entitiesList
.
subList
(
fromIdx
,
toIndex
));
List
<
AtlasEntity
>
entitiesBatch
=
new
ArrayList
<>(
entitiesList
.
subList
(
fromIdx
,
toIndex
));
updateProcessedEntityReferences
(
entitiesBatch
,
guidAssignments
);
updateProcessedEntityReferences
(
entitiesBatch
,
context
.
getGuidAssignments
()
);
AtlasEntitiesWithExtInfo
batch
=
new
AtlasEntitiesWithExtInfo
(
entitiesBatch
);
AtlasEntitiesWithExtInfo
batch
=
new
AtlasEntitiesWithExtInfo
(
entitiesBatch
);
AtlasEntityStream
batchStream
=
new
AtlasEntityStream
(
batch
,
entityStream
);
AtlasEntityStream
batchStream
=
new
AtlasEntityStream
(
batch
,
entityStream
);
EntityMutationResponse
response
=
atlasEntityStore
.
createOrUpdate
(
batchStream
,
isPartialUpdate
);
EntityMutationResponse
response
=
atlasEntityStore
.
createOrUpdate
(
batchStream
,
isPartialUpdate
);
recordProcessedEntities
(
response
,
guidAssignments
);
recordProcessedEntities
(
response
,
context
);
RequestContext
.
get
().
resetEntityGuidUpdates
();
RequestContext
.
get
().
resetEntityGuidUpdates
();
RequestContext
.
get
().
clearCache
();
RequestContext
.
get
().
clearCache
();
}
}
}
}
if
(
context
!=
null
)
{
context
.
prepareForPostUpdate
();
List
<
AtlasEntity
>
postUpdateEntities
=
context
.
getPostUpdateEntities
();
if
(
CollectionUtils
.
isNotEmpty
(
postUpdateEntities
))
{
atlasEntityStore
.
createOrUpdate
(
new
AtlasEntityStream
(
postUpdateEntities
),
true
);
}
}
}
}
private
void
recordFailedMessages
()
{
private
void
recordFailedMessages
()
{
...
@@ -815,12 +825,11 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -815,12 +825,11 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
}
}
}
}
private
void
preProcessNotificationMessage
(
AtlasKafkaMessage
<
HookNotification
>
kafkaMsg
)
{
private
PreprocessorContext
preProcessNotificationMessage
(
AtlasKafkaMessage
<
HookNotification
>
kafkaMsg
)
{
if
(!
preprocessEnabled
)
{
PreprocessorContext
context
=
null
;
return
;
}
PreprocessorContext
context
=
new
PreprocessorContext
(
kafkaMsg
,
hiveTablesToIgnore
,
hiveTablesToPrune
,
hiveTablesCache
,
hiveTypesRemoveOwnedRefAttrs
,
rdbmsTypesRemoveOwnedRefAttrs
);
if
(
preprocessEnabled
)
{
context
=
new
PreprocessorContext
(
kafkaMsg
,
typeRegistry
,
hiveTablesToIgnore
,
hiveTablesToPrune
,
hiveTablesCache
,
hiveTypesRemoveOwnedRefAttrs
,
rdbmsTypesRemoveOwnedRefAttrs
);
if
(
context
.
isHivePreprocessEnabled
())
{
if
(
context
.
isHivePreprocessEnabled
())
{
preprocessHiveTypes
(
context
);
preprocessHiveTypes
(
context
);
...
@@ -860,6 +869,9 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -860,6 +869,9 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
}
}
}
}
return
context
;
}
private
void
rdbmsTypeRemoveOwnedRefAttrs
(
PreprocessorContext
context
)
{
private
void
rdbmsTypeRemoveOwnedRefAttrs
(
PreprocessorContext
context
)
{
List
<
AtlasEntity
>
entities
=
context
.
getEntities
();
List
<
AtlasEntity
>
entities
=
context
.
getEntities
();
...
@@ -1009,12 +1021,26 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
...
@@ -1009,12 +1021,26 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
return
ret
;
return
ret
;
}
}
private
void
recordProcessedEntities
(
EntityMutationResponse
mutationResponse
,
Map
<
String
,
String
>
guidAssignments
)
{
private
void
recordProcessedEntities
(
EntityMutationResponse
mutationResponse
,
PreprocessorContext
context
)
{
if
(
mutationResponse
!=
null
&&
MapUtils
.
isNotEmpty
(
mutationResponse
.
getGuidAssignments
()))
{
if
(
mutationResponse
!=
null
&&
context
!=
null
)
{
guidAssignments
.
putAll
(
mutationResponse
.
getGuidAssignments
());
if
(
MapUtils
.
isNotEmpty
(
mutationResponse
.
getGuidAssignments
()))
{
context
.
getGuidAssignments
().
putAll
(
mutationResponse
.
getGuidAssignments
());
}
if
(
LOG
.
isDebugEnabled
())
{
if
(
CollectionUtils
.
isNotEmpty
(
mutationResponse
.
getCreatedEntities
()))
{
LOG
.
debug
(
"recordProcessedEntities: added {} guidAssignments. updatedSize={}"
,
mutationResponse
.
getGuidAssignments
().
size
(),
guidAssignments
.
size
());
for
(
AtlasEntityHeader
entity
:
mutationResponse
.
getCreatedEntities
())
{
if
(
entity
!=
null
&&
entity
.
getGuid
()
!=
null
)
{
context
.
getCreatedEntities
().
add
(
entity
.
getGuid
());
}
}
}
if
(
CollectionUtils
.
isNotEmpty
(
mutationResponse
.
getDeletedEntities
()))
{
for
(
AtlasEntityHeader
entity
:
mutationResponse
.
getDeletedEntities
())
{
if
(
entity
!=
null
&&
entity
.
getGuid
()
!=
null
)
{
context
.
getDeletedEntities
().
add
(
entity
.
getGuid
());
}
}
}
}
}
}
}
}
...
...
webapp/src/main/java/org/apache/atlas/notification/preprocessor/EntityPreprocessor.java
View file @
3e4fb5cd
...
@@ -53,6 +53,7 @@ public abstract class EntityPreprocessor {
...
@@ -53,6 +53,7 @@ public abstract class EntityPreprocessor {
public
static
final
String
ATTRIBUTE_TABLES
=
"tables"
;
public
static
final
String
ATTRIBUTE_TABLES
=
"tables"
;
public
static
final
String
ATTRIBUTE_INDEXES
=
"indexes"
;
public
static
final
String
ATTRIBUTE_INDEXES
=
"indexes"
;
public
static
final
String
ATTRIBUTE_FOREIGN_KEYS
=
"foreign_keys"
;
public
static
final
String
ATTRIBUTE_FOREIGN_KEYS
=
"foreign_keys"
;
public
static
final
String
ATTRIBUTE_INSTANCE
=
"instance"
;
public
static
final
char
QNAME_SEP_CLUSTER_NAME
=
'@'
;
public
static
final
char
QNAME_SEP_CLUSTER_NAME
=
'@'
;
public
static
final
char
QNAME_SEP_ENTITY_NAME
=
'.'
;
public
static
final
char
QNAME_SEP_ENTITY_NAME
=
'.'
;
...
...
webapp/src/main/java/org/apache/atlas/notification/preprocessor/HivePreprocessor.java
View file @
3e4fb5cd
...
@@ -18,8 +18,6 @@
...
@@ -18,8 +18,6 @@
package
org
.
apache
.
atlas
.
notification
.
preprocessor
;
package
org
.
apache
.
atlas
.
notification
.
preprocessor
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.AtlasRelatedObjectId
;
import
org.apache.atlas.notification.preprocessor.PreprocessorContext.PreprocessAction
;
import
org.apache.atlas.notification.preprocessor.PreprocessorContext.PreprocessAction
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -27,16 +25,14 @@ import org.slf4j.LoggerFactory;
...
@@ -27,16 +25,14 @@ import org.slf4j.LoggerFactory;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
public
class
HivePreprocessor
{
public
class
HivePreprocessor
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
HivePreprocessor
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
HivePreprocessor
.
class
);
private
static
final
String
RELATIONSHIP_TYPE_HIVE_TABLE_COLUMNS
=
"hive_table_columns"
;
private
static
final
String
RELATIONSHIP_TYPE_HIVE_TABLE_COLUMNS
=
"hive_table_columns"
;
private
static
final
String
RELATIONSHIP_TYPE_HIVE_TABLE_PARTITION_KEYS
=
"hive_table_partitionkeys"
;
private
static
final
String
RELATIONSHIP_TYPE_HIVE_TABLE_PARTITION_KEYS
=
"hive_table_partitionkeys"
;
private
static
final
String
RELATIONSHIP_TYPE_HIVE_TABLE_STORAGEDESC
=
"hive_table_storagedesc"
;
static
class
HiveTablePreprocessor
extends
EntityPreprocessor
{
static
class
HiveTablePreprocessor
extends
EntityPreprocessor
{
public
HiveTablePreprocessor
()
{
public
HiveTablePreprocessor
()
{
...
@@ -67,62 +63,11 @@ public class HivePreprocessor {
...
@@ -67,62 +63,11 @@ public class HivePreprocessor {
entity
.
setAttribute
(
ATTRIBUTE_COLUMNS
,
null
);
entity
.
setAttribute
(
ATTRIBUTE_COLUMNS
,
null
);
entity
.
setAttribute
(
ATTRIBUTE_PARTITION_KEYS
,
null
);
entity
.
setAttribute
(
ATTRIBUTE_PARTITION_KEYS
,
null
);
}
else
if
(
context
.
getHiveTypesRemoveOwnedRefAttrs
())
{
}
else
if
(
context
.
getHiveTypesRemoveOwnedRefAttrs
())
{
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_SD
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_SD
,
RELATIONSHIP_TYPE_HIVE_TABLE_STORAGEDESC
,
ATTRIBUTE_TABLE
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_COLUMNS
,
RELATIONSHIP_TYPE_HIVE_TABLE_COLUMNS
,
ATTRIBUTE_TABLE
);
removeColumnsAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_COLUMNS
,
RELATIONSHIP_TYPE_HIVE_TABLE_COLUMNS
,
context
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_PARTITION_KEYS
,
RELATIONSHIP_TYPE_HIVE_TABLE_PARTITION_KEYS
,
ATTRIBUTE_TABLE
);
removeColumnsAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_PARTITION_KEYS
,
RELATIONSHIP_TYPE_HIVE_TABLE_PARTITION_KEYS
,
context
);
}
}
}
private
void
removeColumnsAttributeAndRegisterToMove
(
AtlasEntity
entity
,
String
attrName
,
String
relationshipType
,
PreprocessorContext
context
)
{
Object
attrVal
=
entity
.
removeAttribute
(
attrName
);
if
(
attrVal
!=
null
)
{
Set
<
String
>
guids
=
new
HashSet
<>();
context
.
collectGuids
(
attrVal
,
guids
);
for
(
String
guid
:
guids
)
{
AtlasEntity
colEntity
=
context
.
getEntity
(
guid
);
if
(
colEntity
!=
null
)
{
Object
attrTable
=
null
;
if
(
colEntity
.
hasRelationshipAttribute
(
ATTRIBUTE_TABLE
))
{
attrTable
=
colEntity
.
getRelationshipAttribute
(
ATTRIBUTE_TABLE
);
}
else
if
(
colEntity
.
hasAttribute
(
ATTRIBUTE_TABLE
))
{
attrTable
=
colEntity
.
getAttribute
(
ATTRIBUTE_TABLE
);
}
attrTable
=
setRelationshipType
(
attrTable
,
relationshipType
);
if
(
attrTable
!=
null
)
{
colEntity
.
setRelationshipAttribute
(
ATTRIBUTE_TABLE
,
attrTable
);
}
context
.
addToReferredEntitiesToMove
(
guid
);
}
}
}
}
}
}
private
AtlasRelatedObjectId
setRelationshipType
(
Object
attr
,
String
relationshipType
)
{
AtlasRelatedObjectId
ret
=
null
;
if
(
attr
instanceof
AtlasRelatedObjectId
)
{
ret
=
(
AtlasRelatedObjectId
)
attr
;
}
else
if
(
attr
instanceof
AtlasObjectId
)
{
ret
=
new
AtlasRelatedObjectId
((
AtlasObjectId
)
attr
);
}
else
if
(
attr
instanceof
Map
)
{
ret
=
new
AtlasRelatedObjectId
((
Map
)
attr
);
}
if
(
ret
!=
null
)
{
ret
.
setRelationshipType
(
relationshipType
);
}
return
ret
;
}
}
}
}
...
...
webapp/src/main/java/org/apache/atlas/notification/preprocessor/PreprocessorContext.java
View file @
3e4fb5cd
This diff is collapsed.
Click to expand it.
webapp/src/main/java/org/apache/atlas/notification/preprocessor/RdbmsPreprocessor.java
View file @
3e4fb5cd
...
@@ -32,6 +32,12 @@ import java.util.Set;
...
@@ -32,6 +32,12 @@ import java.util.Set;
public
class
RdbmsPreprocessor
{
public
class
RdbmsPreprocessor
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RdbmsPreprocessor
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RdbmsPreprocessor
.
class
);
private
static
final
String
RELATIONSHIP_TYPE_RDBMS_INSTANCE_DATABASES
=
"rdbms_instance_databases"
;
private
static
final
String
RELATIONSHIP_TYPE_RDBMS_DB_TABLES
=
"rdbms_db_tables"
;
private
static
final
String
RELATIONSHIP_TYPE_RDBMS_TABLE_COLUMNS
=
"rdbms_table_columns"
;
private
static
final
String
RELATIONSHIP_TYPE_RDBMS_TABLE_INDEXES
=
"rdbms_table_indexes"
;
private
static
final
String
RELATIONSHIP_TYPE_RDBMS_TABLE_FOREIGN_KEYS
=
"rdbms_table_foreign_key"
;
static
class
RdbmsInstancePreprocessor
extends
RdbmsTypePreprocessor
{
static
class
RdbmsInstancePreprocessor
extends
RdbmsTypePreprocessor
{
public
RdbmsInstancePreprocessor
()
{
public
RdbmsInstancePreprocessor
()
{
super
(
TYPE_RDBMS_INSTANCE
);
super
(
TYPE_RDBMS_INSTANCE
);
...
@@ -121,17 +127,17 @@ public class RdbmsPreprocessor {
...
@@ -121,17 +127,17 @@ public class RdbmsPreprocessor {
private
void
clearRefAttributesAndMove
(
AtlasEntity
entity
,
PreprocessorContext
context
)
{
private
void
clearRefAttributesAndMove
(
AtlasEntity
entity
,
PreprocessorContext
context
)
{
switch
(
entity
.
getTypeName
())
{
switch
(
entity
.
getTypeName
())
{
case
TYPE_RDBMS_INSTANCE:
case
TYPE_RDBMS_INSTANCE:
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_DATABASES
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_DATABASES
,
RELATIONSHIP_TYPE_RDBMS_INSTANCE_DATABASES
,
ATTRIBUTE_INSTANCE
);
break
;
break
;
case
TYPE_RDBMS_DB:
case
TYPE_RDBMS_DB:
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_TABLES
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_TABLES
,
RELATIONSHIP_TYPE_RDBMS_DB_TABLES
,
ATTRIBUTE_DB
);
break
;
break
;
case
TYPE_RDBMS_TABLE:
case
TYPE_RDBMS_TABLE:
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_COLUMNS
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_COLUMNS
,
RELATIONSHIP_TYPE_RDBMS_TABLE_COLUMNS
,
ATTRIBUTE_TABLE
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_INDEXES
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_INDEXES
,
RELATIONSHIP_TYPE_RDBMS_TABLE_INDEXES
,
ATTRIBUTE_TABLE
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_FOREIGN_KEYS
);
context
.
removeRefAttributeAndRegisterToMove
(
entity
,
ATTRIBUTE_FOREIGN_KEYS
,
RELATIONSHIP_TYPE_RDBMS_TABLE_FOREIGN_KEYS
,
ATTRIBUTE_TABLE
);
break
;
break
;
}
}
}
}
...
...
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