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
3a9594e1
Commit
3a9594e1
authored
May 01, 2017
by
apoorvnaik
Committed by
Madhan Neethiraj
May 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1730,1736,1747: fixes in type validations and special character handling in attribute names
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
09425abc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
64 deletions
+77
-64
AtlasStructDefStoreV1.java
...tlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
+13
-0
GraphBackedTypeStore.java
...ache/atlas/repository/typestore/GraphBackedTypeStore.java
+20
-35
GraphBackedTypeStoreTest.java
.../atlas/repository/typestore/GraphBackedTypeStoreTest.java
+44
-29
No files found.
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
View file @
3a9594e1
...
...
@@ -103,6 +103,10 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
vertex
=
(
AtlasVertex
)
preCreateResult
;
}
if
(
CollectionUtils
.
isEmpty
(
structDef
.
getAttributeDefs
()))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
BAD_REQUEST
,
"Missing attributes for structdef"
);
}
AtlasStructDefStoreV1
.
updateVertexAddReferences
(
structDef
,
vertex
,
typeDefStore
);
AtlasStructDef
ret
=
toStructDef
(
vertex
);
...
...
@@ -410,6 +414,9 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
typeDefStore
.
updateTypeVertex
(
structDef
,
vertex
);
// Load up current struct definition for matching attributes
AtlasStructDef
currentStructDef
=
toStructDef
(
vertex
,
new
AtlasStructDef
(),
typeDefStore
);
// add/update attributes that are present in updated structDef
if
(
CollectionUtils
.
isNotEmpty
(
structDef
.
getAttributeDefs
()))
{
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
...
...
@@ -419,6 +426,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
throw
new
AtlasBaseException
(
AtlasErrorCode
.
CANNOT_ADD_MANDATORY_ATTRIBUTE
,
structDef
.
getName
(),
attributeDef
.
getName
());
}
}
// Validate the mandatory features of an attribute (compatibility with legacy type system)
if
(
StringUtils
.
isEmpty
(
attributeDef
.
getName
()))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
MISSING_MANDATORY_ATTRIBUTE
,
structDef
.
getName
(),
"name"
);
...
...
@@ -427,6 +435,11 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
throw
new
AtlasBaseException
(
AtlasErrorCode
.
MISSING_MANDATORY_ATTRIBUTE
,
structDef
.
getName
(),
"typeName"
);
}
AtlasAttributeDef
existingAttribute
=
currentStructDef
.
getAttribute
(
attributeDef
.
getName
());
if
(
null
!=
existingAttribute
&&
!
attributeDef
.
getTypeName
().
equals
(
existingAttribute
.
getTypeName
()))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
BAD_REQUEST
,
"Data type update for attribute is not supported"
);
}
String
propertyKey
=
AtlasGraphUtilsV1
.
getTypeDefPropertyKey
(
structDef
,
attributeDef
.
getName
());
AtlasGraphUtilsV1
.
setProperty
(
vertex
,
propertyKey
,
toJsonFromAttribute
(
structType
.
getAttribute
(
attributeDef
.
getName
())));
...
...
repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java
View file @
3a9594e1
...
...
@@ -18,16 +18,12 @@
package
org
.
apache
.
atlas
.
repository
.
typestore
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
setProperty
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
com.google.common.base.Function
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableSet
;
import
com.google.common.collect.Lists
;
import
com.google.inject.Inject
;
import
com.google.inject.Singleton
;
import
org.apache.atlas.AtlasException
;
import
org.apache.atlas.GraphTransaction
;
import
org.apache.atlas.repository.Constants
;
...
...
@@ -39,33 +35,22 @@ import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.typesystem.TypesDef
;
import
org.apache.atlas.typesystem.types.AttributeDefinition
;
import
org.apache.atlas.typesystem.types.AttributeInfo
;
import
org.apache.atlas.typesystem.types.ClassType
;
import
org.apache.atlas.typesystem.types.DataTypes
;
import
org.apache.atlas.typesystem.types.*
;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.atlas.typesystem.types.EnumType
;
import
org.apache.atlas.typesystem.types.EnumTypeDefinition
;
import
org.apache.atlas.typesystem.types.EnumValue
;
import
org.apache.atlas.typesystem.types.HierarchicalType
;
import
org.apache.atlas.typesystem.types.HierarchicalTypeDefinition
;
import
org.apache.atlas.typesystem.types.IDataType
;
import
org.apache.atlas.typesystem.types.StructType
;
import
org.apache.atlas.typesystem.types.StructTypeDefinition
;
import
org.apache.atlas.typesystem.types.TraitType
;
import
org.apache.atlas.typesystem.types.TypeSystem
;
import
org.apache.atlas.typesystem.types.TypeUtils
;
import
org.apache.atlas.typesystem.types.utils.TypesUtil
;
import
org.codehaus.jettison.json.JSONException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.google.common.base.Function
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableSet
;
import
com.google.common.collect.Lists
;
import
com.google.inject.Inject
;
import
com.google.inject.Singleton
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
static
org
.
apache
.
atlas
.
repository
.
graph
.
GraphHelper
.
setProperty
;
@Singleton
@Deprecated
...
...
@@ -298,7 +283,7 @@ public class GraphBackedTypeStore implements ITypeStore {
String
typeName
=
GraphHelper
.
getSingleValuedProperty
(
vertex
,
Constants
.
TYPENAME_PROPERTY_KEY
,
String
.
class
);
String
typeDescription
=
GraphHelper
.
getSingleValuedProperty
(
vertex
,
Constants
.
TYPEDESCRIPTION_PROPERTY_KEY
,
String
.
class
);
List
<
EnumValue
>
enumValues
=
new
ArrayList
<>();
List
<
String
>
values
=
vertex
.
getListProperty
(
getPropertyKey
(
typeName
));
List
<
String
>
values
=
GraphHelper
.
getListProperty
(
vertex
,
getPropertyKey
(
typeName
));
for
(
String
value
:
values
)
{
String
valueProperty
=
getPropertyKey
(
typeName
,
value
);
enumValues
.
add
(
new
EnumValue
(
value
,
GraphHelper
.
getSingleValuedProperty
(
vertex
,
valueProperty
,
Integer
.
class
)));
...
...
@@ -316,12 +301,12 @@ public class GraphBackedTypeStore implements ITypeStore {
private
AttributeDefinition
[]
getAttributes
(
AtlasVertex
vertex
,
String
typeName
)
throws
AtlasException
{
List
<
AttributeDefinition
>
attributes
=
new
ArrayList
<>();
List
<
String
>
attrNames
=
vertex
.
getListProperty
(
getPropertyKey
(
typeName
));
List
<
String
>
attrNames
=
GraphHelper
.
getListProperty
(
vertex
,
getPropertyKey
(
typeName
));
if
(
attrNames
!=
null
)
{
for
(
String
attrName
:
attrNames
)
{
try
{
String
propertyKey
=
getPropertyKey
(
typeName
,
attrName
);
AttributeDefinition
attrValue
=
AttributeInfo
.
fromJson
((
String
)
vertex
.
getJsonProperty
(
p
ropertyKey
));
String
encodedPropertyKey
=
GraphHelper
.
encodePropertyKey
(
getPropertyKey
(
typeName
,
attrName
)
);
AttributeDefinition
attrValue
=
AttributeInfo
.
fromJson
((
String
)
vertex
.
getJsonProperty
(
encodedP
ropertyKey
));
if
(
attrValue
!=
null
)
{
attributes
.
add
(
attrValue
);
...
...
repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java
View file @
3a9594e1
...
...
@@ -18,18 +18,8 @@
package
org
.
apache
.
atlas
.
repository
.
typestore
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createClassTypeDef
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createOptionalAttrDef
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createRequiredAttrDef
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createStructTypeDef
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
javax.inject.Inject
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableSet
;
import
org.apache.atlas.AtlasException
;
import
org.apache.atlas.RepositoryMetadataModule
;
import
org.apache.atlas.TestUtils
;
...
...
@@ -41,20 +31,7 @@ import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.typesystem.TypesDef
;
import
org.apache.atlas.typesystem.types.AttributeDefinition
;
import
org.apache.atlas.typesystem.types.ClassType
;
import
org.apache.atlas.typesystem.types.DataTypes
;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.atlas.typesystem.types.EnumType
;
import
org.apache.atlas.typesystem.types.EnumTypeDefinition
;
import
org.apache.atlas.typesystem.types.EnumValue
;
import
org.apache.atlas.typesystem.types.HierarchicalTypeDefinition
;
import
org.apache.atlas.typesystem.types.IDataType
;
import
org.apache.atlas.typesystem.types.Multiplicity
;
import
org.apache.atlas.typesystem.types.StructType
;
import
org.apache.atlas.typesystem.types.StructTypeDefinition
;
import
org.apache.atlas.typesystem.types.TraitType
;
import
org.apache.atlas.typesystem.types.TypeSystem
;
import
org.apache.atlas.typesystem.types.*
;
import
org.apache.atlas.typesystem.types.utils.TypesUtil
;
import
org.testng.Assert
;
import
org.testng.annotations.AfterClass
;
...
...
@@ -62,8 +39,16 @@ import org.testng.annotations.BeforeClass;
import
org.testng.annotations.Guice
;
import
org.testng.annotations.Test
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableSet
;
import
javax.inject.Inject
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createClassTypeDef
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createOptionalAttrDef
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createRequiredAttrDef
;
import
static
org
.
apache
.
atlas
.
typesystem
.
types
.
utils
.
TypesUtil
.
createStructTypeDef
;
@Guice
(
modules
=
RepositoryMetadataModule
.
class
)
public
class
GraphBackedTypeStoreTest
{
...
...
@@ -149,6 +134,37 @@ public class GraphBackedTypeStoreTest {
ts
.
defineTypes
(
types
);
}
@Test
public
void
testTypeWithSpecialChars
()
throws
AtlasException
{
HierarchicalTypeDefinition
<
ClassType
>
specialTypeDef1
=
createClassTypeDef
(
"SpecialTypeDef1"
,
"Typedef with special character"
,
ImmutableSet
.<
String
>
of
(),
createRequiredAttrDef
(
"attribute$"
,
DataTypes
.
STRING_TYPE
));
HierarchicalTypeDefinition
<
ClassType
>
specialTypeDef2
=
createClassTypeDef
(
"SpecialTypeDef2"
,
"Typedef with special character"
,
ImmutableSet
.<
String
>
of
(),
createRequiredAttrDef
(
"attribute%"
,
DataTypes
.
STRING_TYPE
));
HierarchicalTypeDefinition
<
ClassType
>
specialTypeDef3
=
createClassTypeDef
(
"SpecialTypeDef3"
,
"Typedef with special character"
,
ImmutableSet
.<
String
>
of
(),
createRequiredAttrDef
(
"attribute{"
,
DataTypes
.
STRING_TYPE
));
HierarchicalTypeDefinition
<
ClassType
>
specialTypeDef4
=
createClassTypeDef
(
"SpecialTypeDef4"
,
"Typedef with special character"
,
ImmutableSet
.<
String
>
of
(),
createRequiredAttrDef
(
"attribute}"
,
DataTypes
.
STRING_TYPE
));
HierarchicalTypeDefinition
<
ClassType
>
specialTypeDef5
=
createClassTypeDef
(
"SpecialTypeDef5"
,
"Typedef with special character"
,
ImmutableSet
.<
String
>
of
(),
createRequiredAttrDef
(
"attribute$%{}"
,
DataTypes
.
STRING_TYPE
));
TypesDef
typesDef
=
TypesUtil
.
getTypesDef
(
ImmutableList
.<
EnumTypeDefinition
>
of
(),
ImmutableList
.<
StructTypeDefinition
>
of
(),
ImmutableList
.<
HierarchicalTypeDefinition
<
TraitType
>>
of
(),
ImmutableList
.
of
(
specialTypeDef1
,
specialTypeDef2
,
specialTypeDef3
,
specialTypeDef4
,
specialTypeDef5
));
Map
<
String
,
IDataType
>
createdTypes
=
ts
.
defineTypes
(
typesDef
);
typeStore
.
store
(
ts
,
ImmutableList
.
copyOf
(
createdTypes
.
keySet
()));
//Validate the updated types
TypesDef
types
=
typeStore
.
restore
();
ts
.
reset
();
ts
.
defineTypes
(
types
);
}
@Test
(
dependsOnMethods
=
"testStore"
)
public
void
testTypeUpdate
()
throws
Exception
{
//Add enum value
...
...
@@ -238,5 +254,4 @@ public class GraphBackedTypeStoreTest {
}
Assert
.
assertTrue
(
clsTypeFound
,
typeName
+
" type not restored"
);
}
}
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