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
2720af61
Commit
2720af61
authored
Mar 20, 2017
by
apoorvnaik
Committed by
Madhan Neethiraj
Apr 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1673: Type deletion should check for reference & instances
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
d0cb5c37
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
16 deletions
+110
-16
AtlasTypeRegistry.java
...rc/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
+58
-1
GraphBackedSearchIndexer.java
...ache/atlas/repository/graph/GraphBackedSearchIndexer.java
+3
-15
AtlasTypeDefGraphStore.java
.../atlas/repository/store/graph/AtlasTypeDefGraphStore.java
+3
-0
AtlasClassificationDefStoreV1.java
...ository/store/graph/v1/AtlasClassificationDefStoreV1.java
+10
-0
AtlasEntityDefStoreV1.java
...tlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
+10
-0
AtlasGraphUtilsV1.java
...he/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java
+16
-0
AtlasStructDefStoreV1.java
...tlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
+10
-0
No files found.
intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
View file @
2720af61
...
...
@@ -512,6 +512,63 @@ public class AtlasTypeRegistry {
}
}
public
void
removeTypesDef
(
AtlasTypesDef
typesDef
)
throws
AtlasBaseException
{
if
(
null
!=
typesDef
&&
!
typesDef
.
isEmpty
())
{
removeTypesWithNoRefResolve
(
typesDef
.
getEnumDefs
());
removeTypesWithNoRefResolve
(
typesDef
.
getStructDefs
());
removeTypesWithNoRefResolve
(
typesDef
.
getClassificationDefs
());
removeTypesWithNoRefResolve
(
typesDef
.
getEntityDefs
());
resolveReferences
();
}
}
private
void
removeTypesWithNoRefResolve
(
Collection
<?
extends
AtlasBaseTypeDef
>
typeDefs
)
{
if
(
CollectionUtils
.
isNotEmpty
(
typeDefs
))
{
for
(
AtlasBaseTypeDef
typeDef
:
typeDefs
)
{
if
(
StringUtils
.
isNotEmpty
(
typeDef
.
getGuid
()))
{
removeTypeByGuidWithNoRefResolve
(
typeDef
);
}
else
{
removeTypeByNameWithNoRefResolve
(
typeDef
);
}
}
}
}
private
void
removeTypeByNameWithNoRefResolve
(
AtlasBaseTypeDef
typeDef
)
{
switch
(
typeDef
.
getCategory
())
{
case
ENUM:
registryData
.
enumDefs
.
removeTypeDefByName
(
typeDef
.
getName
());
break
;
case
STRUCT:
registryData
.
structDefs
.
removeTypeDefByName
(
typeDef
.
getName
());
break
;
case
CLASSIFICATION:
registryData
.
classificationDefs
.
removeTypeDefByName
(
typeDef
.
getName
());
break
;
case
ENTITY:
registryData
.
entityDefs
.
removeTypeDefByName
(
typeDef
.
getName
());
break
;
}
}
private
void
removeTypeByGuidWithNoRefResolve
(
AtlasBaseTypeDef
typeDef
)
{
switch
(
typeDef
.
getCategory
())
{
case
ENUM:
registryData
.
enumDefs
.
removeTypeDefByGuid
(
typeDef
.
getGuid
());
break
;
case
STRUCT:
registryData
.
structDefs
.
removeTypeDefByGuid
(
typeDef
.
getGuid
());
break
;
case
CLASSIFICATION:
registryData
.
classificationDefs
.
removeTypeDefByGuid
(
typeDef
.
getGuid
());
break
;
case
ENTITY:
registryData
.
entityDefs
.
removeTypeDefByGuid
(
typeDef
.
getGuid
());
break
;
}
}
public
void
removeTypeByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeTypeByGuid({})"
,
guid
);
...
...
@@ -892,7 +949,7 @@ class TypeCache {
public
void
removeTypeByName
(
String
name
)
{
if
(
name
!=
null
)
{
typeNameMap
.
get
(
name
);
typeNameMap
.
remove
(
name
);
}
}
...
...
repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
View file @
2720af61
...
...
@@ -20,7 +20,6 @@ package org.apache.atlas.repository.graph;
import
com.google.common.annotations.VisibleForTesting
;
import
com.google.common.base.Preconditions
;
import
org.apache.atlas.ApplicationProperties
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.AtlasException
;
...
...
@@ -62,6 +61,7 @@ import org.apache.commons.configuration.Configuration;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.inject.Inject
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
...
...
@@ -70,25 +70,13 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.Map
;
import
javax.inject.Inject
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGDECIMAL
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGINTEGER
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_BOOLEAN
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_BYTE
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_DATE
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_DOUBLE
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_FLOAT
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_LONG
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_SHORT
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_STRING
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.*;
/**
* Adds index for properties of a given type when its added before any instances are added.
*/
public
class
GraphBackedSearchIndexer
implements
SearchIndexer
,
ActiveStateChangeHandler
,
public
class
GraphBackedSearchIndexer
implements
SearchIndexer
,
ActiveStateChangeHandler
,
TypeDefChangeListener
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GraphBackedSearchIndexer
.
class
);
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
View file @
2720af61
...
...
@@ -493,6 +493,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ
}
}
// Remove all from
ttr
.
removeTypesDef
(
typesDef
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={})"
,
CollectionUtils
.
size
(
typesDef
.
getEnumDefs
()),
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java
View file @
2720af61
...
...
@@ -258,6 +258,10 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
TRAIT
);
if
(
AtlasGraphUtilsV1
.
typeHasInstanceVertex
(
name
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_HAS_REFERENCES
,
name
);
}
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
...
...
@@ -300,6 +304,12 @@ public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 imple
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
TRAIT
);
String
typeName
=
AtlasGraphUtilsV1
.
getProperty
(
ret
,
Constants
.
TYPENAME_PROPERTY_KEY
,
String
.
class
);
if
(
AtlasGraphUtilsV1
.
typeHasInstanceVertex
(
typeName
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_HAS_REFERENCES
,
typeName
);
}
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
View file @
2720af61
...
...
@@ -256,6 +256,10 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
CLASS
);
if
(
AtlasGraphUtilsV1
.
typeHasInstanceVertex
(
name
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_HAS_REFERENCES
,
name
);
}
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
...
...
@@ -298,6 +302,12 @@ public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
CLASS
);
String
typeName
=
AtlasGraphUtilsV1
.
getProperty
(
ret
,
Constants
.
TYPENAME_PROPERTY_KEY
,
String
.
class
);
if
(
AtlasGraphUtilsV1
.
typeHasInstanceVertex
(
typeName
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_HAS_REFERENCES
,
typeName
);
}
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java
View file @
2720af61
...
...
@@ -234,6 +234,22 @@ public class AtlasGraphUtilsV1 {
return
vertex
;
}
public
static
boolean
typeHasInstanceVertex
(
String
typeName
)
throws
AtlasBaseException
{
AtlasGraphQuery
query
=
AtlasGraphProvider
.
getGraphInstance
()
.
query
()
.
has
(
Constants
.
TYPE_NAME_PROPERTY_KEY
,
AtlasGraphQuery
.
ComparisionOperator
.
EQUAL
,
typeName
);
Iterator
<
AtlasVertex
>
results
=
query
.
vertices
().
iterator
();
boolean
hasInstanceVertex
=
results
!=
null
&&
results
.
hasNext
();
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"typeName {} has instance vertex {}"
,
typeName
,
hasInstanceVertex
);
}
return
hasInstanceVertex
;
}
public
static
AtlasVertex
findByTypeAndPropertyName
(
String
typeName
,
String
propertyName
,
Object
attrVal
)
{
AtlasGraphQuery
query
=
AtlasGraphProvider
.
getGraphInstance
().
query
()
.
has
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
typeName
)
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
View file @
2720af61
...
...
@@ -267,6 +267,10 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
STRUCT
);
if
(
AtlasGraphUtilsV1
.
typeHasInstanceVertex
(
name
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_HAS_REFERENCES
,
name
);
}
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
,
name
);
}
...
...
@@ -309,6 +313,12 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
AtlasVertex
ret
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
STRUCT
);
String
typeName
=
AtlasGraphUtilsV1
.
getProperty
(
ret
,
Constants
.
TYPENAME_PROPERTY_KEY
,
String
.
class
);
if
(
AtlasGraphUtilsV1
.
typeHasInstanceVertex
(
typeName
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_HAS_REFERENCES
,
typeName
);
}
if
(
ret
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
TYPE_GUID_NOT_FOUND
,
guid
);
}
...
...
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