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
f8fe0945
Commit
f8fe0945
authored
Oct 12, 2016
by
Suma Shivaprasad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1223 Type REST API v2 implementation (apoorvnaik via sumasai)
parent
0d01f356
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
3517 additions
and
132 deletions
+3517
-132
Constants.java
.../src/main/java/org/apache/atlas/repository/Constants.java
+1
-0
pom.xml
intg/pom.xml
+1
-1
PList.java
intg/src/main/java/org/apache/atlas/model/PList.java
+3
-0
SearchFilter.java
intg/src/main/java/org/apache/atlas/model/SearchFilter.java
+7
-0
AtlasClassification.java
.../org/apache/atlas/model/instance/AtlasClassification.java
+4
-0
AtlasEntity.java
...ain/java/org/apache/atlas/model/instance/AtlasEntity.java
+4
-0
AtlasObjectId.java
...n/java/org/apache/atlas/model/instance/AtlasObjectId.java
+4
-0
AtlasStruct.java
...ain/java/org/apache/atlas/model/instance/AtlasStruct.java
+4
-0
AtlasBaseTypeDef.java
...java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java
+4
-1
AtlasClassificationDef.java
...rg/apache/atlas/model/typedef/AtlasClassificationDef.java
+8
-5
AtlasEntityDef.java
...n/java/org/apache/atlas/model/typedef/AtlasEntityDef.java
+8
-5
AtlasEnumDef.java
...ain/java/org/apache/atlas/model/typedef/AtlasEnumDef.java
+9
-4
AtlasStructDef.java
...n/java/org/apache/atlas/model/typedef/AtlasStructDef.java
+9
-4
AtlasTypesDef.java
...in/java/org/apache/atlas/model/typedef/AtlasTypesDef.java
+92
-0
AtlasTypeDefStore.java
...c/main/java/org/apache/atlas/store/AtlasTypeDefStore.java
+50
-10
AtlasTypeRegistry.java
...rc/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
+37
-37
AtlasTypeUtil.java
intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
+78
-0
pom.xml
pom.xml
+2
-0
release-log.txt
release-log.txt
+1
-0
pom.xml
repository/pom.xml
+5
-0
RepositoryMetadataModule.java
.../main/java/org/apache/atlas/RepositoryMetadataModule.java
+8
-5
AtlasClassificationDefStore.java
...s/repository/store/graph/AtlasClassificationDefStore.java
+56
-0
AtlasEntityDefStore.java
...che/atlas/repository/store/graph/AtlasEntityDefStore.java
+56
-0
AtlasEnumDefStore.java
...pache/atlas/repository/store/graph/AtlasEnumDefStore.java
+56
-0
AtlasStructDefStore.java
...che/atlas/repository/store/graph/AtlasStructDefStore.java
+56
-0
AtlasTypeDefGraphStore.java
.../atlas/repository/store/graph/AtlasTypeDefGraphStore.java
+451
-0
AtlasClassificationDefStoreV1.java
...ository/store/graph/v1/AtlasClassificationDefStoreV1.java
+363
-0
AtlasEntityDefStoreV1.java
...tlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
+360
-0
AtlasEnumDefStoreV1.java
.../atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java
+390
-0
AtlasGraphUtilsV1.java
...he/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java
+189
-0
AtlasStructDefStoreV1.java
...tlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
+474
-0
AtlasTypeDefGraphStoreV1.java
...s/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
+307
-0
FilterUtil.java
...ain/java/org/apache/atlas/repository/util/FilterUtil.java
+105
-0
TypeDefSorter.java
...ry/src/main/java/org/apache/atlas/util/TypeDefSorter.java
+81
-0
TypesREST.java
...pp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
+200
-59
RestModule.java
...ain/java/org/apache/atlas/web/rest/module/RestModule.java
+33
-0
web.xml
webapp/src/main/webapp/WEB-INF/web.xml
+1
-1
No files found.
common/src/main/java/org/apache/atlas/repository/Constants.java
View file @
f8fe0945
...
...
@@ -88,4 +88,5 @@ public final class Constants {
private
Constants
()
{
}
}
intg/pom.xml
View file @
f8fe0945
...
...
@@ -30,7 +30,7 @@
<packaging>
jar
</packaging>
<properties>
<checkstyle.failOnViolation>
tru
e
</checkstyle.failOnViolation>
<checkstyle.failOnViolation>
fals
e
</checkstyle.failOnViolation>
</properties>
<dependencies>
...
...
intg/src/main/java/org/apache/atlas/model/PList.java
View file @
f8fe0945
...
...
@@ -27,6 +27,8 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
import
org.apache.atlas.model.SearchFilter.SortType
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
/**
...
...
@@ -36,6 +38,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
PList
<
T
>
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/SearchFilter.java
View file @
f8fe0945
...
...
@@ -26,6 +26,8 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
/**
...
...
@@ -35,7 +37,12 @@ import javax.xml.bind.annotation.XmlRootElement;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
SearchFilter
{
public
static
final
String
PARAM_TYPE
=
"type"
;
public
static
final
String
PARAM_SUPERTYPE
=
"supertype"
;
public
static
final
String
PARAM_NOT_SUPERTYPE
=
"notSupertype"
;
/**
* to specify whether the result should be sorted? If yes, whether asc or desc.
*/
...
...
intg/src/main/java/org/apache/atlas/model/instance/AtlasClassification.java
View file @
f8fe0945
...
...
@@ -21,6 +21,8 @@ import java.io.Serializable;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlSeeAlso
;
...
...
@@ -40,6 +42,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasClassification
extends
AtlasStruct
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -73,6 +76,7 @@ public class AtlasClassification extends AtlasStruct implements Serializable {
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
@XmlSeeAlso
(
AtlasClassification
.
class
)
public
static
class
AtlasClassifications
extends
PList
<
AtlasClassification
>
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/instance/AtlasEntity.java
View file @
f8fe0945
...
...
@@ -22,6 +22,8 @@ import java.util.Date;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlSeeAlso
;
...
...
@@ -42,6 +44,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasEntity
extends
AtlasStruct
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -218,6 +221,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
@XmlSeeAlso
(
AtlasEntity
.
class
)
public
static
class
AtlasEntities
extends
PList
<
AtlasEntity
>
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/instance/AtlasObjectId.java
View file @
f8fe0945
...
...
@@ -21,6 +21,8 @@ import java.io.Serializable;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlSeeAlso
;
...
...
@@ -39,6 +41,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasObjectId
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -145,6 +148,7 @@ public class AtlasObjectId implements Serializable {
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
@XmlSeeAlso
(
AtlasObjectId
.
class
)
public
static
class
AtlasObjectIds
extends
PList
<
AtlasObjectId
>
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/instance/AtlasStruct.java
View file @
f8fe0945
...
...
@@ -26,6 +26,8 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlSeeAlso
;
...
...
@@ -47,6 +49,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasStruct
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -170,6 +173,7 @@ public class AtlasStruct implements Serializable {
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
@XmlSeeAlso
(
AtlasStruct
.
class
)
public
static
class
AtlasStructs
extends
PList
<
AtlasStruct
>
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/typedef/AtlasBaseTypeDef.java
View file @
f8fe0945
...
...
@@ -23,6 +23,8 @@ import java.util.Collection;
import
java.util.Date
;
import
java.util.Map
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
org.apache.commons.collections.CollectionUtils
;
...
...
@@ -41,6 +43,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
abstract
class
AtlasBaseTypeDef
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -238,7 +241,7 @@ public abstract class AtlasBaseTypeDef implements java.io.Serializable {
sb
=
new
StringBuilder
();
}
sb
.
append
(
"
,
AtlasBaseTypeDef{"
);
sb
.
append
(
"AtlasBaseTypeDef{"
);
sb
.
append
(
"guid='"
).
append
(
guid
).
append
(
'\''
);
sb
.
append
(
", createdBy='"
).
append
(
createdBy
).
append
(
'\''
);
sb
.
append
(
", updatedBy='"
).
append
(
updatedBy
).
append
(
'\''
);
...
...
intg/src/main/java/org/apache/atlas/model/typedef/AtlasClassificationDef.java
View file @
f8fe0945
...
...
@@ -17,11 +17,12 @@
*/
package
org
.
apache
.
atlas
.
model
.
typedef
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlSeeAlso
;
...
...
@@ -42,6 +43,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasClassificationDef
extends
AtlasStructDef
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -94,9 +96,9 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
}
if
(
CollectionUtils
.
isEmpty
(
superTypes
))
{
this
.
superTypes
=
Collections
.
emptySet
();
this
.
superTypes
=
new
HashSet
<
String
>
();
}
else
{
this
.
superTypes
=
Collections
.
unmodifiableSet
(
new
HashSet
<
String
>(
superTypes
)
);
this
.
superTypes
=
new
HashSet
<
String
>(
superTypes
);
}
}
...
...
@@ -112,7 +114,7 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
s
.
add
(
typeName
);
this
.
superTypes
=
Collections
.
unmodifiableSet
(
s
)
;
this
.
superTypes
=
s
;
}
}
...
...
@@ -124,7 +126,7 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
s
.
remove
(
typeName
);
this
.
superTypes
=
Collections
.
unmodifiableSet
(
s
)
;
this
.
superTypes
=
s
;
}
}
...
...
@@ -181,6 +183,7 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
@XmlSeeAlso
(
AtlasClassificationDef
.
class
)
public
static
class
AtlasClassificationDefs
extends
PList
<
AtlasClassificationDef
>
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/typedef/AtlasEntityDef.java
View file @
f8fe0945
...
...
@@ -17,11 +17,12 @@
*/
package
org
.
apache
.
atlas
.
model
.
typedef
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlSeeAlso
;
...
...
@@ -42,6 +43,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasEntityDef
extends
AtlasStructDef
implements
java
.
io
.
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -91,9 +93,9 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
}
if
(
CollectionUtils
.
isEmpty
(
superTypes
))
{
this
.
superTypes
=
Collections
.
emptySet
();
this
.
superTypes
=
new
HashSet
<
String
>
();
}
else
{
this
.
superTypes
=
Collections
.
unmodifiableSet
(
new
HashSet
<
String
>(
superTypes
)
);
this
.
superTypes
=
new
HashSet
<
String
>(
superTypes
);
}
}
...
...
@@ -109,7 +111,7 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
s
.
add
(
typeName
);
this
.
superTypes
=
Collections
.
unmodifiableSet
(
s
)
;
this
.
superTypes
=
s
;
}
}
...
...
@@ -121,7 +123,7 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
s
.
remove
(
typeName
);
this
.
superTypes
=
Collections
.
unmodifiableSet
(
s
)
;
this
.
superTypes
=
s
;
}
}
...
...
@@ -178,6 +180,7 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
@XmlSeeAlso
(
AtlasEntityDef
.
class
)
public
static
class
AtlasEntityDefs
extends
PList
<
AtlasEntityDef
>
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/typedef/AtlasEnumDef.java
View file @
f8fe0945
...
...
@@ -20,6 +20,8 @@ package org.apache.atlas.model.typedef;
import
java.io.Serializable
;
import
java.util.*
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlSeeAlso
;
...
...
@@ -41,6 +43,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasEnumDef
extends
AtlasBaseTypeDef
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -101,7 +104,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
}
if
(
CollectionUtils
.
isEmpty
(
elementDefs
))
{
this
.
elementDefs
=
Collections
.
emptyList
();
this
.
elementDefs
=
new
ArrayList
<
AtlasEnumElementDef
>
();
}
else
{
// if multiple elements with same value are present, keep only the last entry
List
<
AtlasEnumElementDef
>
tmpList
=
new
ArrayList
<
AtlasEnumElementDef
>(
elementDefs
.
size
());
...
...
@@ -124,7 +127,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
}
Collections
.
reverse
(
tmpList
);
this
.
elementDefs
=
Collections
.
unmodifiableList
(
tmpList
)
;
this
.
elementDefs
=
tmpList
;
}
}
...
...
@@ -154,7 +157,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
}
tmpList
.
add
(
new
AtlasEnumElementDef
(
elementDef
));
this
.
elementDefs
=
Collections
.
unmodifiableList
(
tmpList
)
;
this
.
elementDefs
=
tmpList
;
}
public
void
removeElement
(
String
elemValue
)
{
...
...
@@ -171,7 +174,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
}
}
this
.
elementDefs
=
Collections
.
unmodifiableList
(
tmpList
)
;
this
.
elementDefs
=
tmpList
;
}
}
...
...
@@ -247,6 +250,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
static
class
AtlasEnumElementDef
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -348,6 +352,7 @@ public class AtlasEnumDef extends AtlasBaseTypeDef implements Serializable {
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
@XmlSeeAlso
(
AtlasEnumDef
.
class
)
public
static
class
AtlasEnumDefs
extends
PList
<
AtlasEnumDef
>
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
View file @
f8fe0945
...
...
@@ -25,6 +25,8 @@ import java.util.List;
import
java.util.ListIterator
;
import
java.util.Set
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
javax.xml.bind.annotation.XmlSeeAlso
;
...
...
@@ -46,6 +48,7 @@ import org.codehaus.jackson.map.annotate.JsonSerialize;
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasStructDef
extends
AtlasBaseTypeDef
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -91,7 +94,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
if
(
CollectionUtils
.
isEmpty
(
attributeDefs
))
{
this
.
attributeDefs
=
Collections
.
emptyList
();
this
.
attributeDefs
=
new
ArrayList
<
AtlasAttributeDef
>
();
}
else
{
// if multiple attributes with same name are present, keep only the last entry
List
<
AtlasAttributeDef
>
tmpList
=
new
ArrayList
<
AtlasAttributeDef
>(
attributeDefs
.
size
());
...
...
@@ -114,7 +117,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
Collections
.
reverse
(
tmpList
);
this
.
attributeDefs
=
Collections
.
unmodifiableList
(
tmpList
)
;
this
.
attributeDefs
=
tmpList
;
}
}
...
...
@@ -140,7 +143,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
tmpList
.
add
(
new
AtlasAttributeDef
(
attributeDef
));
this
.
attributeDefs
=
Collections
.
unmodifiableList
(
tmpList
)
;
this
.
attributeDefs
=
tmpList
;
}
public
void
removeAttribute
(
String
attrName
)
{
...
...
@@ -156,7 +159,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
}
this
.
attributeDefs
=
Collections
.
unmodifiableList
(
tmpList
)
;
this
.
attributeDefs
=
tmpList
;
}
}
...
...
@@ -233,6 +236,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
static
class
AtlasAttributeDef
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
@@ -414,6 +418,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
@XmlSeeAlso
(
AtlasStructDef
.
class
)
public
static
class
AtlasStructDefs
extends
PList
<
AtlasStructDef
>
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
intg/src/main/java/org/apache/atlas/model/typedef/AtlasTypesDef.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
model
.
typedef
;
import
org.codehaus.jackson.annotate.JsonAutoDetect
;
import
org.codehaus.jackson.annotate.JsonIgnoreProperties
;
import
org.codehaus.jackson.map.annotate.JsonSerialize
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
static
org
.
codehaus
.
jackson
.
annotate
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
@XmlRootElement
@XmlAccessorType
(
XmlAccessType
.
PROPERTY
)
public
class
AtlasTypesDef
{
private
List
<
AtlasEnumDef
>
enumDefs
;
private
List
<
AtlasStructDef
>
structDefs
;
private
List
<
AtlasClassificationDef
>
classificationDefs
;
private
List
<
AtlasEntityDef
>
entityDefs
;
public
AtlasTypesDef
()
{
enumDefs
=
new
ArrayList
<>();
structDefs
=
new
ArrayList
<>();
classificationDefs
=
new
ArrayList
<>();
entityDefs
=
new
ArrayList
<>();
}
public
AtlasTypesDef
(
List
<
AtlasEnumDef
>
enumDefs
,
List
<
AtlasStructDef
>
structDefs
,
List
<
AtlasClassificationDef
>
classificationDefs
,
List
<
AtlasEntityDef
>
entityDefs
)
{
this
.
enumDefs
=
enumDefs
;
this
.
structDefs
=
structDefs
;
this
.
classificationDefs
=
classificationDefs
;
this
.
entityDefs
=
entityDefs
;
}
public
List
<
AtlasEnumDef
>
getEnumDefs
()
{
return
enumDefs
;
}
public
void
setEnumDefs
(
List
<
AtlasEnumDef
>
enumDefs
)
{
this
.
enumDefs
=
enumDefs
;
}
public
List
<
AtlasStructDef
>
getStructDefs
()
{
return
structDefs
;
}
public
void
setStructDefs
(
List
<
AtlasStructDef
>
structDefs
)
{
this
.
structDefs
=
structDefs
;
}
public
List
<
AtlasClassificationDef
>
getClassificationDefs
()
{
return
classificationDefs
;
}
public
void
setClassificationDefs
(
List
<
AtlasClassificationDef
>
classificationDefs
)
{
this
.
classificationDefs
=
classificationDefs
;
}
public
List
<
AtlasEntityDef
>
getEntityDefs
()
{
return
entityDefs
;
}
public
void
setEntityDefs
(
List
<
AtlasEntityDef
>
entityDefs
)
{
this
.
entityDefs
=
entityDefs
;
}
}
intg/src/main/java/org/apache/atlas/
api/AtlasApiTypes
.java
→
intg/src/main/java/org/apache/atlas/
store/AtlasTypeDefStore
.java
View file @
f8fe0945
...
...
@@ -15,8 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
api
;
package
org
.
apache
.
atlas
.
store
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
...
...
@@ -28,13 +27,26 @@ import org.apache.atlas.model.typedef.AtlasEnumDef;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
java.util.List
;
/**
*
API to work with CRUD of Atlas types - enum/struct/classification/entity.
*
Interface to persistence store of TypeDef
*/
public
interface
AtlasApiTypes
{
public
interface
AtlasTypeDefStore
{
void
init
()
throws
AtlasBaseException
;
/***********************/
/** EnumDef operation **/
/***********************/
AtlasEnumDef
createEnumDef
(
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
;
List
<
AtlasEnumDef
>
createEnumDefs
(
List
<
AtlasEnumDef
>
atlasEnumDefs
)
throws
AtlasBaseException
;
List
<
AtlasEnumDef
>
getAllEnumDefs
()
throws
AtlasBaseException
;
AtlasEnumDef
getEnumDefByName
(
String
name
)
throws
AtlasBaseException
;
AtlasEnumDef
getEnumDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
...
...
@@ -49,9 +61,15 @@ public interface AtlasApiTypes {
AtlasEnumDefs
searchEnumDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
;
/*************************/
/** StructDef operation **/
/*************************/
AtlasStructDef
createStructDef
(
AtlasStructDef
structDef
)
throws
AtlasBaseException
;
List
<
AtlasStructDef
>
createStructDefs
(
List
<
AtlasStructDef
>
structDefs
)
throws
AtlasBaseException
;
List
<
AtlasStructDef
>
getAllStructDefs
()
throws
AtlasBaseException
;
AtlasStructDef
getStructDefByName
(
String
name
)
throws
AtlasBaseException
;
AtlasStructDef
getStructDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
...
...
@@ -67,17 +85,24 @@ public interface AtlasApiTypes {
AtlasStructDefs
searchStructDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
;
/*********************************/
/** ClassificationDef operation **/
/*********************************/
AtlasClassificationDef
createClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
List
<
AtlasClassificationDef
>
createClassificationDefs
(
List
<
AtlasClassificationDef
>
classificationDefs
)
throws
AtlasBaseException
;
List
<
AtlasClassificationDef
>
getAllClassificationDefs
()
throws
AtlasBaseException
;
AtlasClassificationDef
getClassificationDefByName
(
String
name
)
throws
AtlasBaseException
;
AtlasClassificationDef
getClassificationDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasClassificationDef
updateClassificationDefByName
(
String
name
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
throws
AtlasBaseException
;
AtlasClassificationDef
updateClassificationDefByGuid
(
String
guid
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
throws
AtlasBaseException
;
void
deleteClassificationDefByName
(
String
name
)
throws
AtlasBaseException
;
...
...
@@ -86,19 +111,34 @@ public interface AtlasApiTypes {
AtlasClassificationDefs
searchClassificationDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
;
AtlasEntityDef
createEntityDef
(
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
/*************************/
/** EntityDef operation **/
/*************************/
AtlasEntityDef
createEntityDefs
(
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
List
<
AtlasEntityDef
>
createEntityDefs
(
List
<
AtlasEntityDef
>
entityDefs
)
throws
AtlasBaseException
;
List
<
AtlasEntityDef
>
getAllEntityDefs
()
throws
AtlasBaseException
;
AtlasEntityDef
getEntityDefByName
(
String
name
)
throws
AtlasBaseException
;
AtlasEntityDef
getEntityDefBy
IdBy
Guid
(
String
guid
)
throws
AtlasBaseException
;
AtlasEntityDef
getEntityDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasEntityDef
updateEntityDefByName
(
String
name
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
AtlasEntityDef
updateEntityDefByGuid
(
String
guid
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
void
deleteEntityDef
(
String
name
)
throws
AtlasBaseException
;
void
deleteEntityDef
ByName
(
String
name
)
throws
AtlasBaseException
;
void
deleteEntityDefByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasEntityDefs
searchEntityDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
;
/***** Bulk Operations *****/
AtlasTypesDef
createTypesDef
(
AtlasTypesDef
atlasTypesDef
)
throws
AtlasBaseException
;
AtlasTypesDef
updateTypesDef
(
AtlasTypesDef
atlasTypesDef
)
throws
AtlasBaseException
;
AtlasTypesDef
searchTypesDef
(
SearchFilter
searchFilter
)
throws
AtlasBaseException
;
}
intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
View file @
f8fe0945
...
...
@@ -47,11 +47,11 @@ public class AtlasTypeRegistry {
public
AtlasTypeRegistry
()
{
allTypes
=
new
ConcurrentHashMap
<
String
,
AtlasType
>();
enumDefs
=
new
TypeDefCache
<
AtlasEnumDef
>(
this
);
structDefs
=
new
TypeDefCache
<
AtlasStructDef
>(
this
);
classificationDefs
=
new
TypeDefCache
<
AtlasClassificationDef
>(
this
);
entityDefs
=
new
TypeDefCache
<
AtlasEntityDef
>(
this
);
allTypes
=
new
ConcurrentHashMap
<>();
enumDefs
=
new
TypeDefCache
<>(
this
);
structDefs
=
new
TypeDefCache
<>(
this
);
classificationDefs
=
new
TypeDefCache
<>(
this
);
entityDefs
=
new
TypeDefCache
<>(
this
);
registerType
(
new
AtlasBuiltInTypes
.
AtlasBooleanType
());
registerType
(
new
AtlasBuiltInTypes
.
AtlasByteType
());
...
...
@@ -77,7 +77,7 @@ public class AtlasTypeRegistry {
public
AtlasType
getType
(
String
typeName
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.getType(
"
+
typeName
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.getType(
{})"
,
typeName
);
}
AtlasType
ret
=
allTypes
.
get
(
typeName
);
...
...
@@ -105,7 +105,7 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.getType(
"
+
typeName
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.getType(
{})"
,
typeName
);
}
return
ret
;
...
...
@@ -114,13 +114,13 @@ public class AtlasTypeRegistry {
public
void
addEnumDef
(
AtlasEnumDef
enumDef
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addEnumDef(
"
+
enumDef
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.addEnumDef(
{})"
,
enumDef
);
}
enumDefs
.
addType
(
enumDef
,
new
AtlasEnumType
(
enumDef
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addEnumDef(
"
+
enumDef
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.addEnumDef(
{})"
,
enumDef
);
}
}
...
...
@@ -136,7 +136,7 @@ public class AtlasTypeRegistry {
public
void
removeEnumDefByGuid
(
String
guid
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEnumDefByGuid(
"
+
guid
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEnumDefByGuid(
{})"
,
guid
);
}
AtlasEnumDef
enumDef
=
enumDefs
.
getTypeDefByGuid
(
guid
);
...
...
@@ -146,13 +146,13 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEnumDefByGuid(
"
+
guid
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEnumDefByGuid(
{})"
,
guid
);
}
}
public
void
removeEnumDefByName
(
String
name
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEnumDefByName(
"
+
name
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEnumDefByName(
{})"
,
name
);
}
AtlasEnumDef
enumDef
=
enumDefs
.
getTypeDefByName
(
name
);
...
...
@@ -162,32 +162,32 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEnumDefByName(
"
+
name
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEnumDefByName(
{})"
,
name
);
}
}
public
void
addStructDefWithNoRefResolve
(
AtlasStructDef
structDef
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addStructDefWithNoRefResolve(
"
+
structDef
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.addStructDefWithNoRefResolve(
{})"
,
structDef
);
}
structDefs
.
addType
(
structDef
,
new
AtlasStructType
(
structDef
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addStructDefWithNoRefResolve(
"
+
structDef
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.addStructDefWithNoRefResolve(
{})"
,
structDef
);
}
}
public
void
addStructDef
(
AtlasStructDef
structDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addStructDef(
"
+
structDef
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.addStructDef(
{})"
,
structDef
);
}
structDefs
.
addType
(
structDef
,
new
AtlasStructType
(
structDef
,
this
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addStructDef(
"
+
structDef
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.addStructDef(
{})"
,
structDef
);
}
}
...
...
@@ -201,7 +201,7 @@ public class AtlasTypeRegistry {
public
void
removeStructDefByGuid
(
String
guid
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeStructDefByGuid(
"
+
guid
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.removeStructDefByGuid(
{})"
,
guid
);
}
AtlasStructDef
structDef
=
structDefs
.
getTypeDefByGuid
(
guid
);
...
...
@@ -211,13 +211,13 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeStructDefByGuid(
"
+
guid
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.removeStructDefByGuid(
{})"
,
guid
);
}
}
public
void
removeStructDefByName
(
String
name
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeStructDefByName(
"
+
name
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.removeStructDefByName(
{})"
,
name
);
}
AtlasStructDef
structDef
=
structDefs
.
getTypeDefByName
(
name
);
...
...
@@ -227,33 +227,33 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeStructDefByName(
"
+
name
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.removeStructDefByName(
{})"
,
name
);
}
}
public
void
addClassificationDefWithNoRefResolve
(
AtlasClassificationDef
classificationDef
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addClassificationDefWithNoRefResolve(
"
+
classificationDef
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.addClassificationDefWithNoRefResolve(
{})"
,
classificationDef
);
}
classificationDefs
.
addType
(
classificationDef
,
new
AtlasClassificationType
(
classificationDef
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addClassificationDefWithNoRefResolve(
"
+
classificationDef
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.addClassificationDefWithNoRefResolve(
{})"
,
classificationDef
);
}
}
public
void
addClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addClassificationDef(
"
+
classificationDef
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.addClassificationDef(
{})"
,
classificationDef
);
}
classificationDefs
.
addType
(
classificationDef
,
new
AtlasClassificationType
(
classificationDef
,
this
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addClassificationDef(
"
+
classificationDef
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.addClassificationDef(
{})"
,
classificationDef
);
}
}
...
...
@@ -269,7 +269,7 @@ public class AtlasTypeRegistry {
public
void
removeClassificationDefByGuid
(
String
guid
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeClassificationDefByGuid(
"
+
guid
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.removeClassificationDefByGuid(
{})"
,
guid
);
}
AtlasClassificationDef
classificationDef
=
classificationDefs
.
getTypeDefByGuid
(
guid
);
...
...
@@ -279,13 +279,13 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeClassificationDefByGuid(
"
+
guid
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.removeClassificationDefByGuid(
{})"
,
guid
);
}
}
public
void
removeClassificationDefByName
(
String
name
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeClassificationDefByName(
"
+
name
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.removeClassificationDefByName(
{})"
,
name
);
}
AtlasClassificationDef
classificationDef
=
classificationDefs
.
getTypeDefByName
(
name
);
...
...
@@ -295,32 +295,32 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeClassificationDefByName(
"
+
name
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.removeClassificationDefByName(
{})"
,
name
);
}
}
public
void
addEntityDefWithNoRefResolve
(
AtlasEntityDef
entityDef
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addEntityDefWithNoRefResolve(
"
+
entityDef
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.addEntityDefWithNoRefResolve(
{})"
,
entityDef
);
}
entityDefs
.
addType
(
entityDef
,
new
AtlasEntityType
(
entityDef
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addEntityDefWithNoRefResolve(
"
+
entityDef
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.addEntityDefWithNoRefResolve(
{})"
,
entityDef
);
}
}
public
void
addEntityDef
(
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.addEntityDef(
"
+
entityDef
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.addEntityDef(
{})"
,
entityDef
);
}
entityDefs
.
addType
(
entityDef
,
new
AtlasEntityType
(
entityDef
,
this
));
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.addEntityDef(
"
+
entityDef
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.addEntityDef(
{})"
,
entityDef
);
}
}
...
...
@@ -336,7 +336,7 @@ public class AtlasTypeRegistry {
public
void
removeEntityDefByGuid
(
String
guid
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEntityDefByGuid(
"
+
guid
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEntityDefByGuid(
{})"
,
guid
);
}
AtlasEntityDef
entityDef
=
entityDefs
.
getTypeDefByGuid
(
guid
);
...
...
@@ -346,13 +346,13 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEntityDefByGuid(
"
+
guid
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEntityDefByGuid(
{})"
,
guid
);
}
}
public
void
removeEntityDefByName
(
String
name
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEntityDefByName(
"
+
name
+
")"
);
LOG
.
debug
(
"==> AtlasTypeRegistry.removeEntityDefByName(
{})"
,
name
);
}
AtlasEntityDef
entityDef
=
entityDefs
.
getTypeDefByName
(
name
);
...
...
@@ -362,7 +362,7 @@ public class AtlasTypeRegistry {
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEntityDefByName(
"
+
name
+
")"
);
LOG
.
debug
(
"<== AtlasTypeRegistry.removeEntityDefByName(
{})"
,
name
);
}
}
...
...
intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
type
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_ARRAY_PREFIX
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_ARRAY_SUFFIX
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_MAP_PREFIX
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_MAP_SUFFIX
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasBaseTypeDef
.
ATLAS_TYPE_MAP_KEY_VAL_SEP
;
import
org.apache.commons.lang.StringUtils
;
import
java.util.HashSet
;
import
java.util.Set
;
/**
* Utility methods for AtlasType/AtlasTypeDef.
*/
public
class
AtlasTypeUtil
{
private
static
final
Set
<
String
>
ATLAS_BUILTIN_TYPENAMES
=
new
HashSet
<
String
>();
static
{
for
(
String
typeName
:
AtlasBaseTypeDef
.
ATLAS_BUILTIN_TYPES
)
{
ATLAS_BUILTIN_TYPENAMES
.
add
(
typeName
);
}
}
public
static
Set
<
String
>
getReferencedTypeNames
(
String
typeName
)
{
Set
<
String
>
ret
=
new
HashSet
<
String
>();
getReferencedTypeNames
(
typeName
,
ret
);
return
ret
;
}
public
static
boolean
isBuiltInType
(
String
typeName
)
{
return
ATLAS_BUILTIN_TYPENAMES
.
contains
(
typeName
);
}
private
static
void
getReferencedTypeNames
(
String
typeName
,
Set
<
String
>
referencedTypeNames
)
{
if
(
StringUtils
.
isNotBlank
(
typeName
)
&&
!
referencedTypeNames
.
contains
(
typeName
))
{
if
(
typeName
.
startsWith
(
ATLAS_TYPE_ARRAY_PREFIX
)
&&
typeName
.
endsWith
(
ATLAS_TYPE_ARRAY_SUFFIX
))
{
int
startIdx
=
ATLAS_TYPE_ARRAY_PREFIX
.
length
();
int
endIdx
=
typeName
.
length
()
-
ATLAS_TYPE_ARRAY_SUFFIX
.
length
();
String
elementTypeName
=
typeName
.
substring
(
startIdx
,
endIdx
);
getReferencedTypeNames
(
elementTypeName
,
referencedTypeNames
);
}
else
if
(
typeName
.
startsWith
(
ATLAS_TYPE_MAP_PREFIX
)
&&
typeName
.
endsWith
(
ATLAS_TYPE_MAP_SUFFIX
))
{
int
startIdx
=
ATLAS_TYPE_MAP_PREFIX
.
length
();
int
endIdx
=
typeName
.
length
()
-
ATLAS_TYPE_MAP_SUFFIX
.
length
();
String
[]
keyValueTypes
=
typeName
.
substring
(
startIdx
,
endIdx
).
split
(
ATLAS_TYPE_MAP_KEY_VAL_SEP
,
2
);
String
keyTypeName
=
keyValueTypes
.
length
>
0
?
keyValueTypes
[
0
]
:
null
;
String
valueTypeName
=
keyValueTypes
.
length
>
1
?
keyValueTypes
[
1
]
:
null
;
getReferencedTypeNames
(
keyTypeName
,
referencedTypeNames
);
getReferencedTypeNames
(
valueTypeName
,
referencedTypeNames
);
}
else
{
referencedTypeNames
.
add
(
typeName
);
}
}
}
}
pom.xml
View file @
f8fe0945
...
...
@@ -1760,6 +1760,8 @@
<exclude>
**/atlas.data/**
</exclude>
<exclude>
**/${sys:atlas.data}/**
</exclude>
<exclude>
**/policy-store.txt
</exclude>
<exclude>
**/*rebel*.xml
</exclude>
<exclude>
**/*rebel*.xml.bak
</exclude>
</excludes>
</configuration>
<executions>
...
...
release-log.txt
View file @
f8fe0945
...
...
@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
ATLAS-1223 Type REST API v2 implementation (apoorvnaik via sumasai)
ATLAS-1210 patch file to add "position" attribute to hive_column type (sarath.kum4r@gmail.com via sumasai)
ATLAS-694 Update Atlas code to use graph abstraction layer (jnhagelb via sumasai)
ATLAS-1215 Atlas UI not working in firefox due to fix in ATLAS-1199 (kevalbhatt)
...
...
repository/pom.xml
View file @
f8fe0945
...
...
@@ -34,6 +34,11 @@
<dependencies>
<dependency>
<groupId>
org.apache.atlas
</groupId>
<artifactId>
atlas-intg
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.atlas
</groupId>
<artifactId>
atlas-typesystem
</artifactId>
</dependency>
...
...
repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java
View file @
f8fe0945
...
...
@@ -18,6 +18,11 @@
package
org
.
apache
.
atlas
;
import
com.google.inject.Binder
;
import
com.google.inject.Singleton
;
import
com.google.inject.matcher.Matchers
;
import
com.google.inject.multibindings.Multibinder
;
import
org.aopalliance.intercept.MethodInterceptor
;
import
org.apache.atlas.discovery.DataSetLineageService
;
import
org.apache.atlas.discovery.DiscoveryService
;
...
...
@@ -31,6 +36,7 @@ import org.apache.atlas.repository.audit.EntityAuditRepository;
import
org.apache.atlas.repository.graph.DeleteHandler
;
import
org.apache.atlas.repository.graph.GraphBackedMetadataRepository
;
import
org.apache.atlas.repository.graph.GraphBackedSearchIndexer
;
import
org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1
;
import
org.apache.atlas.repository.typestore.GraphBackedTypeStore
;
import
org.apache.atlas.repository.typestore.ITypeStore
;
import
org.apache.atlas.service.Service
;
...
...
@@ -38,17 +44,13 @@ import org.apache.atlas.services.DefaultMetadataService;
import
org.apache.atlas.services.IBootstrapTypesRegistrar
;
import
org.apache.atlas.services.MetadataService
;
import
org.apache.atlas.services.ReservedTypesRegistrar
;
import
org.apache.atlas.store.AtlasTypeDefStore
;
import
org.apache.atlas.typesystem.types.TypeSystem
;
import
org.apache.atlas.typesystem.types.TypeSystemProvider
;
import
org.apache.atlas.typesystem.types.cache.TypeCache
;
import
org.apache.atlas.util.AtlasRepositoryConfiguration
;
import
org.apache.commons.configuration.Configuration
;
import
com.google.inject.Binder
;
import
com.google.inject.Singleton
;
import
com.google.inject.matcher.Matchers
;
import
com.google.inject.multibindings.Multibinder
;
/**
* Guice module for Repository module.
*/
...
...
@@ -65,6 +67,7 @@ public class RepositoryMetadataModule extends com.google.inject.AbstractModule {
// bind the ITypeStore interface to an implementation
bind
(
ITypeStore
.
class
).
to
(
GraphBackedTypeStore
.
class
).
asEagerSingleton
();
bind
(
AtlasTypeDefStore
.
class
).
to
(
AtlasTypeDefGraphStoreV1
.
class
).
asEagerSingleton
();
//GraphBackedSearchIndexer must be an eager singleton to force the search index creation to happen before
//we try to restore the type system (otherwise we'll end up running queries
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasClassificationDefStore.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs
;
import
java.util.List
;
/**
* Interface for graph persistence store for AtlasClassificationDef
*/
public
interface
AtlasClassificationDefStore
{
AtlasClassificationDef
create
(
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
List
<
AtlasClassificationDef
>
create
(
List
<
AtlasClassificationDef
>
classificationDefs
)
throws
AtlasBaseException
;
List
<
AtlasClassificationDef
>
getAll
()
throws
AtlasBaseException
;
AtlasClassificationDef
getByName
(
String
name
)
throws
AtlasBaseException
;
AtlasClassificationDef
getByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasClassificationDef
updateByName
(
String
name
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
AtlasClassificationDef
updateByGuid
(
String
guid
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
;
List
<
AtlasClassificationDef
>
update
(
List
<
AtlasClassificationDef
>
classificationDefs
)
throws
AtlasBaseException
;
void
deleteByName
(
String
name
)
throws
AtlasBaseException
;
void
deleteByNames
(
List
<
String
>
names
)
throws
AtlasBaseException
;
void
deleteByGuid
(
String
guid
)
throws
AtlasBaseException
;
void
deleteByGuids
(
List
<
String
>
guids
)
throws
AtlasBaseException
;
AtlasClassificationDefs
search
(
SearchFilter
filter
)
throws
AtlasBaseException
;
}
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStore.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef.AtlasEntityDefs
;
import
java.util.List
;
/**
* Interface for graph persistence store for AtlasEntityDef
*/
public
interface
AtlasEntityDefStore
{
AtlasEntityDef
create
(
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
List
<
AtlasEntityDef
>
create
(
List
<
AtlasEntityDef
>
entityDefs
)
throws
AtlasBaseException
;
List
<
AtlasEntityDef
>
getAll
()
throws
AtlasBaseException
;
AtlasEntityDef
getByName
(
String
name
)
throws
AtlasBaseException
;
AtlasEntityDef
getByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasEntityDef
updateByName
(
String
name
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
AtlasEntityDef
updateByGuid
(
String
guid
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
;
List
<
AtlasEntityDef
>
update
(
List
<
AtlasEntityDef
>
entityDefs
)
throws
AtlasBaseException
;
void
deleteByName
(
String
name
)
throws
AtlasBaseException
;
void
deleteByNames
(
List
<
String
>
names
)
throws
AtlasBaseException
;
void
deleteByGuid
(
String
guid
)
throws
AtlasBaseException
;
void
deleteByGuids
(
List
<
String
>
guids
)
throws
AtlasBaseException
;
AtlasEntityDefs
search
(
SearchFilter
filter
)
throws
AtlasBaseException
;
}
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEnumDefStore.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs
;
import
java.util.List
;
/**
* Interface for graph persistence store for AtlasEnumDef
*/
public
interface
AtlasEnumDefStore
{
AtlasEnumDef
create
(
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
;
List
<
AtlasEnumDef
>
create
(
List
<
AtlasEnumDef
>
atlasEnumDefs
)
throws
AtlasBaseException
;
List
<
AtlasEnumDef
>
getAll
()
throws
AtlasBaseException
;
AtlasEnumDef
getByName
(
String
name
)
throws
AtlasBaseException
;
AtlasEnumDef
getByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasEnumDef
updateByName
(
String
name
,
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
;
AtlasEnumDef
updateByGuid
(
String
guid
,
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
;
List
<
AtlasEnumDef
>
update
(
List
<
AtlasEnumDef
>
enumDefs
)
throws
AtlasBaseException
;
void
deleteByName
(
String
name
)
throws
AtlasBaseException
;
void
deleteByNames
(
List
<
String
>
names
)
throws
AtlasBaseException
;
void
deleteByGuid
(
String
guid
)
throws
AtlasBaseException
;
void
deleteByGuids
(
List
<
String
>
guids
)
throws
AtlasBaseException
;
AtlasEnumDefs
search
(
SearchFilter
filter
)
throws
AtlasBaseException
;
}
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasStructDefStore.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs
;
import
java.util.List
;
/**
* Interface for graph persistence store for AtlasStructDef
*/
public
interface
AtlasStructDefStore
{
AtlasStructDef
create
(
AtlasStructDef
structDef
)
throws
AtlasBaseException
;
List
<
AtlasStructDef
>
create
(
List
<
AtlasStructDef
>
structDefs
)
throws
AtlasBaseException
;
List
<
AtlasStructDef
>
getAll
()
throws
AtlasBaseException
;
AtlasStructDef
getByName
(
String
name
)
throws
AtlasBaseException
;
AtlasStructDef
getByGuid
(
String
guid
)
throws
AtlasBaseException
;
AtlasStructDef
updateByName
(
String
name
,
AtlasStructDef
structDef
)
throws
AtlasBaseException
;
AtlasStructDef
updateByGuid
(
String
guid
,
AtlasStructDef
structDef
)
throws
AtlasBaseException
;
List
<
AtlasStructDef
>
update
(
List
<
AtlasStructDef
>
structDefs
)
throws
AtlasBaseException
;
void
deleteByName
(
String
name
)
throws
AtlasBaseException
;
void
deleteByNames
(
List
<
String
>
names
)
throws
AtlasBaseException
;
void
deleteByGuid
(
String
guid
)
throws
AtlasBaseException
;
void
deleteByGuids
(
List
<
String
>
guids
)
throws
AtlasBaseException
;
AtlasStructDefs
search
(
SearchFilter
filter
)
throws
AtlasBaseException
;
}
repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
;
import
org.apache.atlas.GraphTransaction
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef.AtlasEntityDefs
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.repository.util.FilterUtil
;
import
org.apache.atlas.store.AtlasTypeDefStore
;
import
org.apache.atlas.util.TypeDefSorter
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.Predicate
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Collections
;
import
java.util.List
;
/**
* Abstract class for graph persistence store for TypeDef
*/
public
abstract
class
AtlasTypeDefGraphStore
implements
AtlasTypeDefStore
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasTypeDefGraphStore
.
class
);
protected
AtlasEnumDefStore
enumDefStore
;
protected
AtlasStructDefStore
structDefStore
;
protected
AtlasClassificationDefStore
classificationDefStore
;
protected
AtlasEntityDefStore
entityDefStore
;
protected
AtlasTypeDefGraphStore
()
{
}
@Override
public
void
init
()
throws
AtlasBaseException
{
}
@Override
@GraphTransaction
public
AtlasEnumDef
createEnumDef
(
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
{
return
enumDefStore
.
create
(
enumDef
);
}
@Override
@GraphTransaction
public
List
<
AtlasEnumDef
>
createEnumDefs
(
List
<
AtlasEnumDef
>
atlasEnumDefs
)
throws
AtlasBaseException
{
return
enumDefStore
.
create
(
atlasEnumDefs
);
}
@Override
@GraphTransaction
public
List
<
AtlasEnumDef
>
getAllEnumDefs
()
throws
AtlasBaseException
{
return
enumDefStore
.
getAll
();
}
@Override
@GraphTransaction
public
AtlasEnumDef
getEnumDefByName
(
String
name
)
throws
AtlasBaseException
{
return
enumDefStore
.
getByName
(
name
);
}
@Override
@GraphTransaction
public
AtlasEnumDef
getEnumDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
return
enumDefStore
.
getByGuid
(
guid
);
}
@Override
@GraphTransaction
public
AtlasEnumDef
updateEnumDefByName
(
String
name
,
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
{
return
enumDefStore
.
updateByName
(
name
,
enumDef
);
}
@Override
@GraphTransaction
public
AtlasEnumDef
updateEnumDefByGuid
(
String
guid
,
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
{
return
enumDefStore
.
updateByGuid
(
guid
,
enumDef
);
}
@Override
@GraphTransaction
public
void
deleteEnumDefByName
(
String
name
)
throws
AtlasBaseException
{
enumDefStore
.
deleteByName
(
name
);
}
@Override
@GraphTransaction
public
void
deleteEnumDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
enumDefStore
.
deleteByGuid
(
guid
);
}
@Override
@GraphTransaction
public
AtlasEnumDefs
searchEnumDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
{
return
enumDefStore
.
search
(
filter
);
}
@Override
@GraphTransaction
public
AtlasStructDef
createStructDef
(
AtlasStructDef
structDef
)
throws
AtlasBaseException
{
return
structDefStore
.
create
(
structDef
);
}
@Override
@GraphTransaction
public
List
<
AtlasStructDef
>
createStructDefs
(
List
<
AtlasStructDef
>
structDefs
)
throws
AtlasBaseException
{
return
structDefStore
.
create
(
structDefs
);
}
@Override
@GraphTransaction
public
List
<
AtlasStructDef
>
getAllStructDefs
()
throws
AtlasBaseException
{
return
structDefStore
.
getAll
();
}
@Override
@GraphTransaction
public
AtlasStructDef
getStructDefByName
(
String
name
)
throws
AtlasBaseException
{
return
structDefStore
.
getByName
(
name
);
}
@Override
@GraphTransaction
public
AtlasStructDef
getStructDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
return
structDefStore
.
getByGuid
(
guid
);
}
@Override
@GraphTransaction
public
AtlasStructDef
updateStructDefByName
(
String
name
,
AtlasStructDef
structDef
)
throws
AtlasBaseException
{
return
structDefStore
.
updateByName
(
name
,
structDef
);
}
@Override
@GraphTransaction
public
AtlasStructDef
updateStructDefByGuid
(
String
guid
,
AtlasStructDef
structDef
)
throws
AtlasBaseException
{
return
structDefStore
.
updateByGuid
(
guid
,
structDef
);
}
@Override
@GraphTransaction
public
void
deleteStructDefByName
(
String
name
)
throws
AtlasBaseException
{
structDefStore
.
deleteByName
(
name
);
}
@Override
@GraphTransaction
public
void
deleteStructDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
structDefStore
.
deleteByGuid
(
guid
);
}
@Override
@GraphTransaction
public
AtlasStructDefs
searchStructDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
{
return
structDefStore
.
search
(
filter
);
}
@Override
@GraphTransaction
public
AtlasClassificationDef
createClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
{
return
classificationDefStore
.
create
(
classificationDef
);
}
@Override
@GraphTransaction
public
List
<
AtlasClassificationDef
>
createClassificationDefs
(
List
<
AtlasClassificationDef
>
classificationDefs
)
throws
AtlasBaseException
{
return
classificationDefStore
.
create
(
classificationDefs
);
}
@Override
@GraphTransaction
public
List
<
AtlasClassificationDef
>
getAllClassificationDefs
()
throws
AtlasBaseException
{
return
classificationDefStore
.
getAll
();
}
@Override
@GraphTransaction
public
AtlasClassificationDef
getClassificationDefByName
(
String
name
)
throws
AtlasBaseException
{
return
classificationDefStore
.
getByName
(
name
);
}
@Override
@GraphTransaction
public
AtlasClassificationDef
getClassificationDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
return
classificationDefStore
.
getByGuid
(
guid
);
}
@Override
@GraphTransaction
public
AtlasClassificationDef
updateClassificationDefByName
(
String
name
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
{
return
classificationDefStore
.
updateByName
(
name
,
classificationDef
);
}
@Override
@GraphTransaction
public
AtlasClassificationDef
updateClassificationDefByGuid
(
String
guid
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
{
return
classificationDefStore
.
updateByGuid
(
guid
,
classificationDef
);
}
@Override
@GraphTransaction
public
void
deleteClassificationDefByName
(
String
name
)
throws
AtlasBaseException
{
classificationDefStore
.
deleteByName
(
name
);
}
@Override
@GraphTransaction
public
void
deleteClassificationDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
classificationDefStore
.
deleteByGuid
(
guid
);
}
@Override
@GraphTransaction
public
AtlasClassificationDefs
searchClassificationDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
{
return
classificationDefStore
.
search
(
filter
);
}
@Override
@GraphTransaction
public
AtlasEntityDef
createEntityDefs
(
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
{
return
entityDefStore
.
create
(
entityDef
);
}
@Override
@GraphTransaction
public
List
<
AtlasEntityDef
>
createEntityDefs
(
List
<
AtlasEntityDef
>
entityDefs
)
throws
AtlasBaseException
{
return
entityDefStore
.
create
(
entityDefs
);
}
@Override
@GraphTransaction
public
List
<
AtlasEntityDef
>
getAllEntityDefs
()
throws
AtlasBaseException
{
return
entityDefStore
.
getAll
();
}
@Override
@GraphTransaction
public
AtlasEntityDef
getEntityDefByName
(
String
name
)
throws
AtlasBaseException
{
return
entityDefStore
.
getByName
(
name
);
}
@Override
@GraphTransaction
public
AtlasEntityDef
getEntityDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
return
entityDefStore
.
getByGuid
(
guid
);
}
@Override
@GraphTransaction
public
AtlasEntityDef
updateEntityDefByName
(
String
name
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
{
return
entityDefStore
.
updateByName
(
name
,
entityDef
);
}
@Override
@GraphTransaction
public
AtlasEntityDef
updateEntityDefByGuid
(
String
guid
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
{
return
entityDefStore
.
updateByGuid
(
guid
,
entityDef
);
}
@Override
@GraphTransaction
public
void
deleteEntityDefByName
(
String
name
)
throws
AtlasBaseException
{
entityDefStore
.
deleteByName
(
name
);
}
@Override
@GraphTransaction
public
void
deleteEntityDefByGuid
(
String
guid
)
throws
AtlasBaseException
{
entityDefStore
.
deleteByGuid
(
guid
);
}
@Override
@GraphTransaction
public
AtlasEntityDefs
searchEntityDefs
(
SearchFilter
filter
)
throws
AtlasBaseException
{
return
entityDefStore
.
search
(
filter
);
}
private
List
<?
extends
AtlasBaseTypeDef
>
createOrUpdateTypeDefs
(
List
<?
extends
AtlasBaseTypeDef
>
typeDefs
,
boolean
isUpdate
)
{
List
<
AtlasBaseTypeDef
>
ret
=
Collections
.
emptyList
();
if
(
CollectionUtils
.
isNotEmpty
(
typeDefs
))
{
AtlasBaseTypeDef
typeDef
=
typeDefs
.
get
(
0
);
if
(
LOG
.
isDebugEnabled
())
{
if
(
isUpdate
)
{
LOG
.
debug
(
"Updating {} {}"
,
typeDefs
.
size
(),
typeDef
.
getClass
().
getSimpleName
());
}
else
{
LOG
.
debug
(
"Creating {} {}"
,
typeDefs
.
size
(),
typeDef
.
getClass
().
getSimpleName
());
}
}
if
(
typeDef
instanceof
AtlasEntityDef
)
{
List
<
AtlasEntityDef
>
entityDefs
=
TypeDefSorter
.
sortTypes
((
List
<
AtlasEntityDef
>)
typeDefs
);
try
{
if
(
isUpdate
)
{
return
entityDefStore
.
update
((
List
<
AtlasEntityDef
>)
typeDefs
);
}
else
{
return
entityDefStore
.
create
((
List
<
AtlasEntityDef
>)
typeDefs
);
}
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to "
+
(
isUpdate
?
"update"
:
"create"
)
+
" EntityDefs"
,
ex
);
}
}
else
if
(
typeDef
instanceof
AtlasClassificationDef
)
{
List
<
AtlasClassificationDef
>
classificationDefs
=
TypeDefSorter
.
sortTypes
((
List
<
AtlasClassificationDef
>)
typeDefs
);
try
{
if
(
isUpdate
)
{
return
classificationDefStore
.
update
((
List
<
AtlasClassificationDef
>)
typeDefs
);
}
else
{
return
classificationDefStore
.
create
((
List
<
AtlasClassificationDef
>)
typeDefs
);
}
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to "
+
(
isUpdate
?
"update"
:
"create"
)
+
" ClassificationDefs"
,
ex
);
}
}
else
if
(
typeDef
instanceof
AtlasStructDef
)
{
try
{
if
(
isUpdate
)
{
return
structDefStore
.
update
((
List
<
AtlasStructDef
>)
typeDefs
);
}
else
{
return
structDefStore
.
create
((
List
<
AtlasStructDef
>)
typeDefs
);
}
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to "
+
(
isUpdate
?
"update"
:
"create"
)
+
" StructDefs"
,
ex
);
}
}
else
if
(
typeDef
instanceof
AtlasEnumDef
)
{
try
{
if
(
isUpdate
)
{
return
enumDefStore
.
update
((
List
<
AtlasEnumDef
>)
typeDefs
);
}
else
{
return
enumDefStore
.
create
((
List
<
AtlasEnumDef
>)
typeDefs
);
}
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to "
+
(
isUpdate
?
"update"
:
"create"
)
+
" EnumDefs"
,
ex
);
}
}
}
return
ret
;
}
@Override
@GraphTransaction
public
AtlasTypesDef
createTypesDef
(
AtlasTypesDef
typesDef
)
throws
AtlasBaseException
{
AtlasTypesDef
createdTypeDefs
=
new
AtlasTypesDef
();
LOG
.
info
(
"Creating EnumDefs"
);
List
<?
extends
AtlasBaseTypeDef
>
createdEnumDefs
=
createOrUpdateTypeDefs
(
typesDef
.
getEnumDefs
(),
false
);
LOG
.
info
(
"Creating StructDefs"
);
List
<?
extends
AtlasBaseTypeDef
>
createdStructDefs
=
createOrUpdateTypeDefs
(
typesDef
.
getStructDefs
(),
false
);
LOG
.
info
(
"Creating ClassificationDefs"
);
List
<?
extends
AtlasBaseTypeDef
>
createdClassificationDefs
=
createOrUpdateTypeDefs
(
typesDef
.
getClassificationDefs
(),
false
);
LOG
.
info
(
"Creating EntityDefs"
);
List
<?
extends
AtlasBaseTypeDef
>
createdEntityDefs
=
createOrUpdateTypeDefs
(
typesDef
.
getEntityDefs
(),
false
);
typesDef
.
setEnumDefs
((
List
<
AtlasEnumDef
>)
createdEnumDefs
);
typesDef
.
setStructDefs
((
List
<
AtlasStructDef
>)
createdStructDefs
);
typesDef
.
setClassificationDefs
((
List
<
AtlasClassificationDef
>)
createdClassificationDefs
);
typesDef
.
setEntityDefs
((
List
<
AtlasEntityDef
>)
createdEntityDefs
);
return
typesDef
;
}
@Override
@GraphTransaction
public
AtlasTypesDef
updateTypesDef
(
AtlasTypesDef
typesDef
)
throws
AtlasBaseException
{
AtlasTypesDef
createdTypeDefs
=
new
AtlasTypesDef
();
LOG
.
info
(
"Updating EnumDefs"
);
List
<?
extends
AtlasBaseTypeDef
>
updatedEnumDefs
=
createOrUpdateTypeDefs
(
typesDef
.
getEnumDefs
(),
true
);
LOG
.
info
(
"Updating StructDefs"
);
List
<?
extends
AtlasBaseTypeDef
>
updatedStructDefs
=
createOrUpdateTypeDefs
(
typesDef
.
getStructDefs
(),
true
);
LOG
.
info
(
"Updating ClassificationDefs"
);
List
<?
extends
AtlasBaseTypeDef
>
updatedClassficationDefs
=
createOrUpdateTypeDefs
(
typesDef
.
getClassificationDefs
(),
true
);
LOG
.
info
(
"Updating EntityDefs"
);
List
<?
extends
AtlasBaseTypeDef
>
updatedEntityDefs
=
createOrUpdateTypeDefs
(
typesDef
.
getEntityDefs
(),
true
);
typesDef
.
setEnumDefs
((
List
<
AtlasEnumDef
>)
updatedEnumDefs
);
typesDef
.
setStructDefs
((
List
<
AtlasStructDef
>)
updatedStructDefs
);
typesDef
.
setClassificationDefs
((
List
<
AtlasClassificationDef
>)
updatedClassficationDefs
);
typesDef
.
setEntityDefs
((
List
<
AtlasEntityDef
>)
updatedEntityDefs
);
return
typesDef
;
}
@Override
@GraphTransaction
public
AtlasTypesDef
searchTypesDef
(
SearchFilter
searchFilter
)
throws
AtlasBaseException
{
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
();
Predicate
searchPredicates
=
FilterUtil
.
getPredicateFromSearchFilter
(
searchFilter
);
try
{
List
<
AtlasEnumDef
>
enumDefs
=
enumDefStore
.
getAll
();
CollectionUtils
.
filter
(
enumDefs
,
searchPredicates
);
typesDef
.
setEnumDefs
(
enumDefs
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to retrieve the EnumDefs"
,
ex
);
}
try
{
List
<
AtlasStructDef
>
structDefs
=
structDefStore
.
getAll
();
CollectionUtils
.
filter
(
structDefs
,
searchPredicates
);
typesDef
.
setStructDefs
(
structDefs
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to retrieve the StructDefs"
,
ex
);
}
try
{
List
<
AtlasClassificationDef
>
classificationDefs
=
classificationDefStore
.
getAll
();
CollectionUtils
.
filter
(
classificationDefs
,
searchPredicates
);
typesDef
.
setClassificationDefs
(
classificationDefs
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to retrieve the ClassificationDefs"
,
ex
);
}
try
{
List
<
AtlasEntityDef
>
entityDefs
=
entityDefStore
.
getAll
();
CollectionUtils
.
filter
(
entityDefs
,
searchPredicates
);
typesDef
.
setEntityDefs
(
entityDefs
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to retrieve the EntityDefs"
,
ex
);
}
return
typesDef
;
}
}
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.store.graph.AtlasClassificationDefStore
;
import
org.apache.atlas.repository.util.FilterUtil
;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
sun.security.provider.certpath.Vertex
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* ClassificationDef store in v1 format.
*/
public
class
AtlasClassificationDefStoreV1
implements
AtlasClassificationDefStore
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasClassificationDefStoreV1
.
class
);
private
final
AtlasTypeDefGraphStoreV1
typeDefStore
;
public
AtlasClassificationDefStoreV1
(
AtlasTypeDefGraphStoreV1
typeDefStore
)
{
super
();
this
.
typeDefStore
=
typeDefStore
;
}
@Override
public
AtlasClassificationDef
create
(
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.create({})"
,
classificationDef
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByName
(
classificationDef
.
getName
());
if
(
vertex
!=
null
)
{
throw
new
AtlasBaseException
(
classificationDef
.
getName
()
+
": type already exists"
);
}
vertex
=
typeDefStore
.
createTypeVertex
(
classificationDef
);
toVertex
(
classificationDef
,
vertex
);
AtlasClassificationDef
ret
=
toClassificationDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.create({}): {}"
,
classificationDef
,
ret
);
}
return
ret
;
}
@Override
public
List
<
AtlasClassificationDef
>
create
(
List
<
AtlasClassificationDef
>
classificationDefs
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.create({})"
,
classificationDefs
);
}
List
<
AtlasClassificationDef
>
classificationDefList
=
new
LinkedList
<>();
for
(
AtlasClassificationDef
structDef
:
classificationDefs
)
{
try
{
AtlasClassificationDef
atlasClassificationDef
=
create
(
structDef
);
classificationDefList
.
add
(
atlasClassificationDef
);
}
catch
(
AtlasBaseException
baseException
)
{
LOG
.
error
(
"Failed to create {}"
,
structDef
);
LOG
.
error
(
"Exception: {}"
,
baseException
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.create({}, {})"
,
classificationDefs
,
classificationDefList
);
}
return
classificationDefList
;
}
@Override
public
List
<
AtlasClassificationDef
>
getAll
()
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.getAll()"
);
}
List
<
AtlasClassificationDef
>
classificationDefs
=
new
LinkedList
<>();
Iterator
<
AtlasVertex
>
verticesByCategory
=
typeDefStore
.
findTypeVerticesByCategory
(
TypeCategory
.
TRAIT
);
while
(
verticesByCategory
.
hasNext
())
{
AtlasClassificationDef
classificationDef
=
toClassificationDef
(
verticesByCategory
.
next
());
classificationDefs
.
add
(
classificationDef
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.getAll()"
);
}
return
classificationDefs
;
}
@Override
public
AtlasClassificationDef
getByName
(
String
name
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.getByName({})"
,
name
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with name "
+
name
);
}
vertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
TypeCategory
.
class
);
AtlasClassificationDef
ret
=
toClassificationDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.getByName({}): {}"
,
name
,
ret
);
}
return
ret
;
}
@Override
public
AtlasClassificationDef
getByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.getByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with guid "
+
guid
);
}
AtlasClassificationDef
ret
=
toClassificationDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.getByGuid({}): {}"
,
guid
,
ret
);
}
return
ret
;
}
@Override
public
AtlasClassificationDef
updateByName
(
String
name
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.updateByName({}, {})"
,
name
,
classificationDef
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with name "
+
name
);
}
toVertex
(
classificationDef
,
vertex
);
AtlasClassificationDef
ret
=
toClassificationDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.updateByName({}, {}): {}"
,
name
,
classificationDef
,
ret
);
}
return
ret
;
}
@Override
public
AtlasClassificationDef
updateByGuid
(
String
guid
,
AtlasClassificationDef
classificationDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.updateByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with guid "
+
guid
);
}
toVertex
(
classificationDef
,
vertex
);
AtlasClassificationDef
ret
=
toClassificationDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.updateByGuid({}): {}"
,
guid
,
ret
);
}
return
ret
;
}
@Override
public
List
<
AtlasClassificationDef
>
update
(
List
<
AtlasClassificationDef
>
classificationDefs
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.update({})"
,
classificationDefs
);
}
List
<
AtlasClassificationDef
>
updatedClassificationDefs
=
new
ArrayList
<>();
for
(
AtlasClassificationDef
classificationDef
:
classificationDefs
)
{
try
{
AtlasClassificationDef
updatedDef
=
updateByName
(
classificationDef
.
getName
(),
classificationDef
);
updatedClassificationDefs
.
add
(
updatedDef
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to update {}"
,
classificationDef
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.update({}): {}"
,
classificationDefs
,
updatedClassificationDefs
);
}
return
updatedClassificationDefs
;
}
@Override
public
void
deleteByName
(
String
name
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.deleteByName({})"
,
name
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with name "
+
name
);
}
typeDefStore
.
deleteTypeVertex
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.deleteByName({})"
,
name
);
}
}
@Override
public
void
deleteByNames
(
List
<
String
>
names
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.deleteByNames({})"
,
names
);
}
for
(
String
name
:
names
)
{
try
{
deleteByName
(
name
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to delete {}"
,
name
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.deleteByNames({})"
,
names
);
}
}
@Override
public
void
deleteByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.deleteByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
TRAIT
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no classificationDef exists with guid "
+
guid
);
}
typeDefStore
.
deleteTypeVertex
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.deleteByGuid({})"
,
guid
);
}
}
@Override
public
void
deleteByGuids
(
List
<
String
>
guids
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.deleteByGuids({})"
,
guids
);
}
for
(
String
guid
:
guids
)
{
try
{
deleteByGuid
(
guid
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to delete {}"
,
guid
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.deleteByGuids({})"
,
guids
);
}
}
@Override
public
AtlasClassificationDefs
search
(
SearchFilter
filter
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasClassificationDefStoreV1.search({})"
,
filter
);
}
List
<
AtlasClassificationDef
>
classificationDefs
=
new
ArrayList
<
AtlasClassificationDef
>();
Iterator
<
AtlasVertex
>
vertices
=
typeDefStore
.
findTypeVerticesByCategory
(
TypeCategory
.
TRAIT
);
while
(
vertices
.
hasNext
())
{
AtlasVertex
vertex
=
vertices
.
next
();
AtlasClassificationDef
classificationDef
=
toClassificationDef
(
vertex
);
if
(
classificationDef
!=
null
)
{
classificationDefs
.
add
(
classificationDef
);
// TODO: add only if this passes filter
}
}
if
(
CollectionUtils
.
isNotEmpty
(
classificationDefs
))
{
CollectionUtils
.
filter
(
classificationDefs
,
FilterUtil
.
getPredicateFromSearchFilter
(
filter
));
}
AtlasClassificationDefs
ret
=
new
AtlasClassificationDefs
(
classificationDefs
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasClassificationDefStoreV1.search({}): {}"
,
filter
,
ret
);
}
return
ret
;
}
private
void
toVertex
(
AtlasClassificationDef
classificationDef
,
AtlasVertex
vertex
)
{
AtlasStructDefStoreV1
.
toVertex
(
classificationDef
,
vertex
,
typeDefStore
);
typeDefStore
.
createSuperTypeEdges
(
vertex
,
classificationDef
.
getSuperTypes
());
}
private
AtlasClassificationDef
toClassificationDef
(
AtlasVertex
vertex
)
{
AtlasClassificationDef
ret
=
null
;
if
(
vertex
!=
null
&&
typeDefStore
.
isTypeVertex
(
vertex
,
TypeCategory
.
TRAIT
))
{
ret
=
new
AtlasClassificationDef
();
AtlasStructDefStoreV1
.
toStructDef
(
vertex
,
ret
,
typeDefStore
);
ret
.
setSuperTypes
(
typeDefStore
.
getSuperTypeNames
(
vertex
));
}
return
ret
;
}
}
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef.AtlasEntityDefs
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.store.graph.AtlasEntityDefStore
;
import
org.apache.atlas.repository.util.FilterUtil
;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* EntityDef store in v1 format.
*/
public
class
AtlasEntityDefStoreV1
implements
AtlasEntityDefStore
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasEntityDefStoreV1
.
class
);
private
final
AtlasTypeDefGraphStoreV1
typeDefStore
;
public
AtlasEntityDefStoreV1
(
AtlasTypeDefGraphStoreV1
typeDefStore
)
{
super
();
this
.
typeDefStore
=
typeDefStore
;
}
@Override
public
AtlasEntityDef
create
(
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.create({})"
,
entityDef
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByName
(
entityDef
.
getName
());
if
(
vertex
!=
null
)
{
throw
new
AtlasBaseException
(
entityDef
.
getName
()
+
": type already exists"
);
}
vertex
=
typeDefStore
.
createTypeVertex
(
entityDef
);
toVertex
(
entityDef
,
vertex
);
AtlasEntityDef
ret
=
toEntityDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.create({}): {}"
,
entityDef
,
ret
);
}
return
ret
;
}
@Override
public
List
<
AtlasEntityDef
>
create
(
List
<
AtlasEntityDef
>
entityDefs
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.create({})"
,
entityDefs
);
}
List
<
AtlasEntityDef
>
entityDefList
=
new
LinkedList
<>();
for
(
AtlasEntityDef
structDef
:
entityDefs
)
{
try
{
AtlasEntityDef
atlasEntityDef
=
create
(
structDef
);
entityDefList
.
add
(
atlasEntityDef
);
}
catch
(
AtlasBaseException
baseException
)
{
LOG
.
error
(
"Failed to create {}"
,
structDef
);
LOG
.
error
(
"Exception: {}"
,
baseException
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.create({}, {})"
,
entityDefs
,
entityDefList
);
}
return
entityDefList
;
}
@Override
public
List
<
AtlasEntityDef
>
getAll
()
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.getAll()"
);
}
List
<
AtlasEntityDef
>
entityDefs
=
new
LinkedList
<>();
Iterator
<
AtlasVertex
>
verticesByCategory
=
typeDefStore
.
findTypeVerticesByCategory
(
TypeCategory
.
CLASS
);
while
(
verticesByCategory
.
hasNext
())
{
AtlasEntityDef
atlasEntityDef
=
toEntityDef
(
verticesByCategory
.
next
());
entityDefs
.
add
(
atlasEntityDef
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.getAll()"
);
}
return
entityDefs
;
}
@Override
public
AtlasEntityDef
getByName
(
String
name
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.getByName({})"
,
name
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with name "
+
name
);
}
vertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
TypeCategory
.
class
);
AtlasEntityDef
ret
=
toEntityDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.getByName({}): {}"
,
name
,
ret
);
}
return
ret
;
}
@Override
public
AtlasEntityDef
getByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.getByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with guid "
+
guid
);
}
AtlasEntityDef
ret
=
toEntityDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.getByGuid({}): {}"
,
guid
,
ret
);
}
return
ret
;
}
@Override
public
AtlasEntityDef
updateByName
(
String
name
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.updateByName({}, {})"
,
name
,
entityDef
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with name "
+
name
);
}
toVertex
(
entityDef
,
vertex
);
AtlasEntityDef
ret
=
toEntityDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.updateByName({}, {}): {}"
,
name
,
entityDef
,
ret
);
}
return
ret
;
}
@Override
public
AtlasEntityDef
updateByGuid
(
String
guid
,
AtlasEntityDef
entityDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.updateByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with guid "
+
guid
);
}
toVertex
(
entityDef
,
vertex
);
AtlasEntityDef
ret
=
toEntityDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.updateByGuid({}): {}"
,
guid
,
ret
);
}
return
ret
;
}
@Override
public
List
<
AtlasEntityDef
>
update
(
List
<
AtlasEntityDef
>
entityDefs
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.update({})"
,
entityDefs
);
}
List
<
AtlasEntityDef
>
updatedEntityDefs
=
new
ArrayList
<>();
for
(
AtlasEntityDef
entityDef
:
entityDefs
)
{
try
{
AtlasEntityDef
atlasEntityDef
=
updateByName
(
entityDef
.
getName
(),
entityDef
);
updatedEntityDefs
.
add
(
atlasEntityDef
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to update {}"
,
entityDef
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.update({}): {}"
,
entityDefs
,
updatedEntityDefs
);
}
return
updatedEntityDefs
;
}
@Override
public
void
deleteByName
(
String
name
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.deleteByName({})"
,
name
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with name "
+
name
);
}
typeDefStore
.
deleteTypeVertex
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.deleteByName({})"
,
name
);
}
}
@Override
public
void
deleteByNames
(
List
<
String
>
names
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.deleteByNames({})"
,
names
);
}
List
<
AtlasStructDef
>
updatedDefs
=
new
ArrayList
<>();
for
(
String
name
:
names
)
{
try
{
deleteByName
(
name
);
}
catch
(
AtlasBaseException
ex
)
{}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.deleteByNames({})"
,
names
);
}
}
@Override
public
void
deleteByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.deleteByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
CLASS
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no entityDef exists with guid "
+
guid
);
}
typeDefStore
.
deleteTypeVertex
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.deleteByGuid({})"
,
guid
);
}
}
@Override
public
void
deleteByGuids
(
List
<
String
>
guids
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.deleteByGuids({})"
,
guids
);
}
List
<
AtlasStructDef
>
updatedDefs
=
new
ArrayList
<>();
for
(
String
guid
:
guids
)
{
try
{
deleteByGuid
(
guid
);
}
catch
(
AtlasBaseException
ex
)
{}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.deleteByGuids({})"
,
guids
);
}
}
@Override
public
AtlasEntityDefs
search
(
SearchFilter
filter
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEntityDefStoreV1.search({})"
,
filter
);
}
List
<
AtlasEntityDef
>
entityDefs
=
new
ArrayList
<
AtlasEntityDef
>();
Iterator
<
AtlasVertex
>
vertices
=
typeDefStore
.
findTypeVerticesByCategory
(
TypeCategory
.
CLASS
);
while
(
vertices
.
hasNext
())
{
AtlasVertex
vertex
=
vertices
.
next
();
AtlasEntityDef
entityDef
=
toEntityDef
(
vertex
);
if
(
entityDef
!=
null
)
{
entityDefs
.
add
(
entityDef
);
}
}
if
(
CollectionUtils
.
isNotEmpty
(
entityDefs
))
{
CollectionUtils
.
filter
(
entityDefs
,
FilterUtil
.
getPredicateFromSearchFilter
(
filter
));
}
AtlasEntityDefs
ret
=
new
AtlasEntityDefs
(
entityDefs
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEntityDefStoreV1.search({}): {}"
,
filter
,
ret
);
}
return
ret
;
}
private
void
toVertex
(
AtlasEntityDef
entityDef
,
AtlasVertex
vertex
)
{
AtlasStructDefStoreV1
.
toVertex
(
entityDef
,
vertex
,
typeDefStore
);
typeDefStore
.
createSuperTypeEdges
(
vertex
,
entityDef
.
getSuperTypes
());
}
private
AtlasEntityDef
toEntityDef
(
AtlasVertex
vertex
)
{
AtlasEntityDef
ret
=
null
;
if
(
vertex
!=
null
&&
typeDefStore
.
isTypeVertex
(
vertex
,
TypeCategory
.
CLASS
))
{
ret
=
new
AtlasEntityDef
();
AtlasStructDefStoreV1
.
toStructDef
(
vertex
,
ret
,
typeDefStore
);
ret
.
setSuperTypes
(
typeDefStore
.
getSuperTypeNames
(
vertex
));
}
return
ret
;
}
}
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs
;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.store.graph.AtlasEnumDefStore
;
import
org.apache.atlas.repository.util.FilterUtil
;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* EnumDef store in v1 format.
*/
public
class
AtlasEnumDefStoreV1
implements
AtlasEnumDefStore
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasEnumDefStoreV1
.
class
);
private
final
AtlasTypeDefGraphStoreV1
typeDefStore
;
public
AtlasEnumDefStoreV1
(
AtlasTypeDefGraphStoreV1
typeDefStore
)
{
super
();
this
.
typeDefStore
=
typeDefStore
;
}
@Override
public
AtlasEnumDef
create
(
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.create({})"
,
enumDef
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByName
(
enumDef
.
getName
());
if
(
vertex
!=
null
)
{
throw
new
AtlasBaseException
(
enumDef
.
getName
()
+
": type already exists"
);
}
vertex
=
typeDefStore
.
createTypeVertex
(
enumDef
);
toVertex
(
enumDef
,
vertex
);
AtlasEnumDef
ret
=
toEnumDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.create({}): {}"
,
enumDef
,
ret
);
}
return
ret
;
}
@Override
public
List
<
AtlasEnumDef
>
create
(
List
<
AtlasEnumDef
>
atlasEnumDefs
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.create({})"
,
atlasEnumDefs
);
}
List
<
AtlasEnumDef
>
enumDefList
=
new
LinkedList
<>();
for
(
AtlasEnumDef
enumDef
:
atlasEnumDefs
)
{
try
{
AtlasEnumDef
atlasEnumDef
=
create
(
enumDef
);
enumDefList
.
add
(
atlasEnumDef
);
}
catch
(
AtlasBaseException
baseException
)
{
LOG
.
error
(
"Failed to create {}"
,
enumDef
);
LOG
.
error
(
"Exception: {}"
,
baseException
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.create({}, {})"
,
atlasEnumDefs
,
enumDefList
);
}
return
enumDefList
;
}
@Override
public
List
<
AtlasEnumDef
>
getAll
()
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.getAll()"
);
}
List
<
AtlasEnumDef
>
enumDefs
=
new
LinkedList
<>();
Iterator
<
AtlasVertex
>
verticesByCategory
=
typeDefStore
.
findTypeVerticesByCategory
(
TypeCategory
.
ENUM
);
while
(
verticesByCategory
.
hasNext
())
{
AtlasEnumDef
enumDef
=
toEnumDef
(
verticesByCategory
.
next
());
enumDefs
.
add
(
enumDef
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.getAll()"
);
}
return
enumDefs
;
}
@Override
public
AtlasEnumDef
getByName
(
String
name
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.getByName({})"
,
name
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with name "
+
name
);
}
vertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
TypeCategory
.
class
);
AtlasEnumDef
ret
=
toEnumDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.getByName({}): {}"
,
name
,
ret
);
}
return
ret
;
}
@Override
public
AtlasEnumDef
getByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.getByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with guid "
+
guid
);
}
AtlasEnumDef
ret
=
toEnumDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.getByGuid({}): {}"
,
guid
,
ret
);
}
return
ret
;
}
@Override
public
AtlasEnumDef
updateByName
(
String
name
,
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.updateByName({}, {})"
,
name
,
enumDef
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with name "
+
name
);
}
toVertex
(
enumDef
,
vertex
);
AtlasEnumDef
ret
=
toEnumDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.updateByName({}, {}): {}"
,
name
,
enumDef
,
ret
);
}
return
ret
;
}
@Override
public
AtlasEnumDef
updateByGuid
(
String
guid
,
AtlasEnumDef
enumDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.updateByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with guid "
+
guid
);
}
toVertex
(
enumDef
,
vertex
);
AtlasEnumDef
ret
=
toEnumDef
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.updateByGuid({}): {}"
,
guid
,
ret
);
}
return
ret
;
}
@Override
public
List
<
AtlasEnumDef
>
update
(
List
<
AtlasEnumDef
>
enumDefs
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.update({})"
,
enumDefs
);
}
List
<
AtlasEnumDef
>
updatedEnumDefs
=
new
ArrayList
<>();
for
(
AtlasEnumDef
enumDef
:
enumDefs
)
{
try
{
AtlasEnumDef
updatedDef
=
updateByName
(
enumDef
.
getName
(),
enumDef
);
updatedEnumDefs
.
add
(
updatedDef
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to update {}"
,
enumDef
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.update({}): {}"
,
enumDefs
,
updatedEnumDefs
);
}
return
updatedEnumDefs
;
}
@Override
public
void
deleteByName
(
String
name
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.deleteByName({})"
,
name
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with name "
+
name
);
}
typeDefStore
.
deleteTypeVertex
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.deleteByName({})"
,
name
);
}
}
@Override
public
void
deleteByNames
(
List
<
String
>
names
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.deleteByNames({})"
,
names
);
}
for
(
String
name
:
names
)
{
try
{
deleteByName
(
name
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to delete {}"
,
name
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.deleteByName({})"
,
names
);
}
}
@Override
public
void
deleteByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.deleteByGuid({})"
,
guid
);
}
AtlasVertex
vertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
ENUM
);
if
(
vertex
==
null
)
{
throw
new
AtlasBaseException
(
"no enumdef exists with guid "
+
guid
);
}
typeDefStore
.
deleteTypeVertex
(
vertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.deleteByGuid({})"
,
guid
);
}
}
@Override
public
void
deleteByGuids
(
List
<
String
>
guids
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.deleteByGuids({})"
,
guids
);
}
for
(
String
guid
:
guids
)
{
try
{
deleteByGuid
(
guid
);
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
error
(
"Failed to delete {}"
,
guid
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.deleteByGuids({})"
,
guids
);
}
}
@Override
public
AtlasEnumDefs
search
(
SearchFilter
filter
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasEnumDefStoreV1.search({})"
,
filter
);
}
List
<
AtlasEnumDef
>
enumDefs
=
new
ArrayList
<
AtlasEnumDef
>();
Iterator
<
AtlasVertex
>
vertices
=
typeDefStore
.
findTypeVerticesByCategory
(
TypeCategory
.
ENUM
);
while
(
vertices
.
hasNext
())
{
AtlasVertex
vertex
=
vertices
.
next
();
AtlasEnumDef
enumDef
=
toEnumDef
(
vertex
);
if
(
enumDef
!=
null
)
{
enumDefs
.
add
(
enumDef
);
}
}
if
(
CollectionUtils
.
isNotEmpty
(
enumDefs
))
{
CollectionUtils
.
filter
(
enumDefs
,
FilterUtil
.
getPredicateFromSearchFilter
(
filter
));
}
AtlasEnumDefs
ret
=
new
AtlasEnumDefs
(
enumDefs
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasEnumDefStoreV1.search({}): {}"
,
filter
,
ret
);
}
return
ret
;
}
private
void
toVertex
(
AtlasEnumDef
enumDef
,
AtlasVertex
vertex
)
{
List
<
String
>
values
=
new
ArrayList
<>(
enumDef
.
getElementDefs
().
size
());
for
(
AtlasEnumElementDef
element
:
enumDef
.
getElementDefs
())
{
String
elemKey
=
AtlasGraphUtilsV1
.
getPropertyKey
(
enumDef
,
element
.
getValue
());
AtlasGraphUtilsV1
.
setProperty
(
vertex
,
elemKey
,
element
.
getOrdinal
());
if
(
StringUtils
.
isNoneBlank
(
element
.
getDescription
()))
{
String
descKey
=
AtlasGraphUtilsV1
.
getPropertyKey
(
elemKey
,
"description"
);
AtlasGraphUtilsV1
.
setProperty
(
vertex
,
descKey
,
element
.
getDescription
());
}
values
.
add
(
element
.
getValue
());
}
AtlasGraphUtilsV1
.
setProperty
(
vertex
,
AtlasGraphUtilsV1
.
getPropertyKey
(
enumDef
),
values
);
}
private
AtlasEnumDef
toEnumDef
(
AtlasVertex
vertex
)
{
AtlasEnumDef
ret
=
null
;
if
(
vertex
!=
null
&&
typeDefStore
.
isTypeVertex
(
vertex
,
TypeCategory
.
ENUM
))
{
ret
=
toEnumDef
(
vertex
,
new
AtlasEnumDef
(),
typeDefStore
);
}
return
ret
;
}
private
static
AtlasEnumDef
toEnumDef
(
AtlasVertex
vertex
,
AtlasEnumDef
enumDef
,
AtlasTypeDefGraphStoreV1
typeDefStore
)
{
AtlasEnumDef
ret
=
enumDef
!=
null
?
enumDef
:
new
AtlasEnumDef
();
typeDefStore
.
vertexToTypeDef
(
vertex
,
ret
);
List
<
AtlasEnumElementDef
>
elements
=
new
ArrayList
<>();
List
<
String
>
elemValues
=
vertex
.
getProperty
(
AtlasGraphUtilsV1
.
getPropertyKey
(
ret
),
List
.
class
);
for
(
String
elemValue
:
elemValues
)
{
String
elemKey
=
AtlasGraphUtilsV1
.
getPropertyKey
(
ret
,
elemValue
);
String
descKey
=
AtlasGraphUtilsV1
.
getPropertyKey
(
elemKey
,
"description"
);
Integer
ordinal
=
AtlasGraphUtilsV1
.
getProperty
(
vertex
,
elemKey
,
Integer
.
class
);
String
desc
=
AtlasGraphUtilsV1
.
getProperty
(
vertex
,
descKey
,
String
.
class
);
elements
.
add
(
new
AtlasEnumElementDef
(
elemValue
,
desc
,
ordinal
));
}
ret
.
setElementDefs
(
elements
);
return
ret
;
}
}
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
com.google.common.collect.BiMap
;
import
com.google.common.collect.HashBiMap
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.AtlasEdge
;
import
org.apache.atlas.repository.graphdb.AtlasElement
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Collection
;
import
java.util.HashMap
;
/**
* Utility methods for Graph.
*/
public
class
AtlasGraphUtilsV1
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasGraphUtilsV1
.
class
);
public
static
final
String
PROPERTY_PREFIX
=
Constants
.
INTERNAL_PROPERTY_KEY_PREFIX
+
"type."
;
public
static
final
String
SUPERTYPE_EDGE_LABEL
=
PROPERTY_PREFIX
+
".supertype"
;
public
static
final
String
VERTEX_TYPE
=
"typeSystem"
;
public
static
final
BiMap
<
String
,
String
>
RESERVED_CHARS_ENCODE_MAP
=
HashBiMap
.
create
(
new
HashMap
<
String
,
String
>()
{{
put
(
"{"
,
"_o"
);
put
(
"}"
,
"_c"
);
put
(
"\""
,
"_q"
);
put
(
"$"
,
"_d"
);
put
(
"%"
,
"_p"
);
}});
public
static
String
getPropertyKey
(
AtlasBaseTypeDef
typeDef
)
{
return
getPropertyKey
(
typeDef
.
getName
());
}
public
static
String
getPropertyKey
(
AtlasBaseTypeDef
typeDef
,
String
child
)
{
return
getPropertyKey
(
typeDef
.
getName
(),
child
);
}
public
static
String
getPropertyKey
(
String
typeName
)
{
return
PROPERTY_PREFIX
+
typeName
;
}
public
static
String
getPropertyKey
(
String
typeName
,
String
child
)
{
return
PROPERTY_PREFIX
+
typeName
+
"."
+
child
;
}
public
static
String
getIdFromVertex
(
AtlasVertex
vertex
)
{
return
vertex
.<
String
>
getProperty
(
Constants
.
GUID_PROPERTY_KEY
,
String
.
class
);
}
public
static
String
getTypeName
(
AtlasVertex
instanceVertex
)
{
return
instanceVertex
.
getProperty
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
String
.
class
);
}
public
static
String
getEdgeLabel
(
String
fromNode
,
String
toNode
)
{
return
PROPERTY_PREFIX
+
"edge."
+
fromNode
+
"."
+
toNode
;
}
public
static
String
encodePropertyKey
(
String
key
)
{
String
ret
=
key
;
if
(
StringUtils
.
isNotBlank
(
key
))
{
for
(
String
str
:
RESERVED_CHARS_ENCODE_MAP
.
keySet
())
{
ret
=
ret
.
replace
(
str
,
RESERVED_CHARS_ENCODE_MAP
.
get
(
str
));
}
}
return
ret
;
}
public
static
String
decodePropertyKey
(
String
key
)
{
String
ret
=
key
;
if
(
StringUtils
.
isNotBlank
(
key
))
{
for
(
String
encodedStr
:
RESERVED_CHARS_ENCODE_MAP
.
values
())
{
ret
=
ret
.
replace
(
encodedStr
,
RESERVED_CHARS_ENCODE_MAP
.
inverse
().
get
(
encodedStr
));
}
}
return
ret
;
}
public
static
<
T
extends
AtlasElement
>
void
setProperty
(
T
element
,
String
propertyName
,
Object
value
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> setProperty({}, {}, {})"
,
toString
(
element
),
propertyName
,
value
);
}
propertyName
=
encodePropertyKey
(
propertyName
);
Object
existingValue
=
element
.
getProperty
(
propertyName
,
Object
.
class
);
if
(
value
==
null
||
(
value
instanceof
Collection
&&
((
Collection
)
value
).
isEmpty
()))
{
if
(
existingValue
!=
null
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Removing property {} from {}"
,
propertyName
,
toString
(
element
));
}
element
.
removeProperty
(
propertyName
);
}
}
else
{
if
(!
value
.
equals
(
existingValue
))
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Setting property {} in {}"
,
propertyName
,
toString
(
element
));
}
element
.
setProperty
(
propertyName
,
value
);
}
}
}
public
static
<
T
extends
AtlasElement
,
O
>
O
getProperty
(
T
element
,
String
propertyName
,
Class
<
O
>
returnType
)
{
Object
property
=
element
.
getProperty
(
encodePropertyKey
(
propertyName
),
returnType
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"getProperty({}, {}) ==> {}"
,
toString
(
element
),
propertyName
,
returnType
.
cast
(
property
));
}
return
returnType
.
cast
(
property
);
}
private
static
<
T
extends
AtlasElement
>
String
toString
(
T
element
)
{
if
(
element
instanceof
AtlasVertex
)
{
return
toString
((
AtlasVertex
)
element
);
}
else
if
(
element
instanceof
AtlasEdge
)
{
return
toString
((
AtlasEdge
)
element
);
}
return
element
.
toString
();
}
public
static
String
toString
(
AtlasVertex
vertex
)
{
if
(
vertex
==
null
)
{
return
"vertex[null]"
;
}
else
{
if
(
LOG
.
isDebugEnabled
())
{
return
getVertexDetails
(
vertex
);
}
else
{
return
String
.
format
(
"vertex[id=%s]"
,
vertex
.
getId
().
toString
());
}
}
}
public
static
String
toString
(
AtlasEdge
edge
)
{
if
(
edge
==
null
)
{
return
"edge[null]"
;
}
else
{
if
(
LOG
.
isDebugEnabled
())
{
return
getEdgeDetails
(
edge
);
}
else
{
return
String
.
format
(
"edge[id=%s]"
,
edge
.
getId
().
toString
());
}
}
}
public
static
String
getVertexDetails
(
AtlasVertex
vertex
)
{
return
String
.
format
(
"vertex[id=%s type=%s guid=%s]"
,
vertex
.
getId
().
toString
(),
getTypeName
(
vertex
),
getIdFromVertex
(
vertex
));
}
public
static
String
getEdgeDetails
(
AtlasEdge
edge
)
{
return
String
.
format
(
"edge[id=%s label=%s from %s -> to %s]"
,
edge
.
getId
(),
edge
.
getLabel
(),
toString
(
edge
.
getOutVertex
()),
toString
(
edge
.
getInVertex
()));
}
}
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.store.graph.AtlasStructDefStore
;
import
org.apache.atlas.repository.util.FilterUtil
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasTypeUtil
;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* StructDef store in v1 format.
*/
public
class
AtlasStructDefStoreV1
implements
AtlasStructDefStore
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasStructDefStoreV1
.
class
);
private
final
AtlasTypeDefGraphStoreV1
typeDefStore
;
public
AtlasStructDefStoreV1
(
AtlasTypeDefGraphStoreV1
typeDefStore
)
{
super
();
this
.
typeDefStore
=
typeDefStore
;
}
@Override
public
AtlasStructDef
create
(
AtlasStructDef
structDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.create({})"
,
structDef
);
}
AtlasVertex
AtlasVertex
=
typeDefStore
.
findTypeVertexByName
(
structDef
.
getName
());
if
(
AtlasVertex
!=
null
)
{
throw
new
AtlasBaseException
(
structDef
.
getName
()
+
": type already exists"
);
}
AtlasVertex
=
typeDefStore
.
createTypeVertex
(
structDef
);
toVertex
(
structDef
,
AtlasVertex
,
typeDefStore
);
AtlasStructDef
ret
=
toStructDef
(
AtlasVertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.create({}): {}"
,
structDef
,
ret
);
}
return
ret
;
}
@Override
public
List
<
AtlasStructDef
>
create
(
List
<
AtlasStructDef
>
structDefs
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.create({})"
,
structDefs
);
}
List
<
AtlasStructDef
>
structDefList
=
new
LinkedList
<>();
for
(
AtlasStructDef
structDef
:
structDefs
)
{
try
{
AtlasStructDef
atlasStructDef
=
create
(
structDef
);
structDefList
.
add
(
atlasStructDef
);
}
catch
(
AtlasBaseException
baseException
)
{
LOG
.
error
(
"Failed to create {}"
,
structDef
);
LOG
.
error
(
"Exception: {}"
,
baseException
);
}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.create({}, {})"
,
structDefs
,
structDefList
);
}
return
structDefList
;
}
@Override
public
List
<
AtlasStructDef
>
getAll
()
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.getAll()"
);
}
List
<
AtlasStructDef
>
structDefs
=
new
LinkedList
<>();
Iterator
<
AtlasVertex
>
verticesByCategory
=
typeDefStore
.
findTypeVerticesByCategory
(
TypeCategory
.
STRUCT
);
while
(
verticesByCategory
.
hasNext
())
{
AtlasStructDef
atlasStructDef
=
toStructDef
(
verticesByCategory
.
next
());
structDefs
.
add
(
atlasStructDef
);
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.getAll()"
);
}
return
structDefs
;
}
@Override
public
AtlasStructDef
getByName
(
String
name
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.getByName({})"
,
name
);
}
AtlasVertex
atlasVertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
STRUCT
);
if
(
atlasVertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with name "
+
name
);
}
atlasVertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
String
.
class
);
AtlasStructDef
ret
=
toStructDef
(
atlasVertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.getByName({}): {}"
,
name
,
ret
);
}
return
ret
;
}
@Override
public
AtlasStructDef
getByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.getByGuid({})"
,
guid
);
}
AtlasVertex
AtlasVertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
STRUCT
);
if
(
AtlasVertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with guid "
+
guid
);
}
AtlasStructDef
ret
=
toStructDef
(
AtlasVertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.getByGuid({}): {}"
,
guid
,
ret
);
}
return
ret
;
}
@Override
public
AtlasStructDef
updateByName
(
String
name
,
AtlasStructDef
structDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.updateByName({}, {})"
,
name
,
structDef
);
}
AtlasVertex
atlasVertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
STRUCT
);
if
(
atlasVertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with name "
+
name
);
}
toVertex
(
structDef
,
atlasVertex
);
AtlasStructDef
ret
=
toStructDef
(
atlasVertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.updateByName({}, {}): {}"
,
name
,
structDef
,
ret
);
}
return
ret
;
}
@Override
public
AtlasStructDef
updateByGuid
(
String
guid
,
AtlasStructDef
structDef
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.updateByGuid({})"
,
guid
);
}
AtlasVertex
atlasVertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
STRUCT
);
if
(
atlasVertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with guid "
+
guid
);
}
toVertex
(
structDef
,
atlasVertex
);
AtlasStructDef
ret
=
toStructDef
(
atlasVertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.updateByGuid({}): {}"
,
guid
,
ret
);
}
return
ret
;
}
@Override
public
List
<
AtlasStructDef
>
update
(
List
<
AtlasStructDef
>
structDefs
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.update({})"
,
structDefs
);
}
List
<
AtlasStructDef
>
updatedDefs
=
new
ArrayList
<>();
for
(
AtlasStructDef
structDef
:
structDefs
)
{
try
{
AtlasStructDef
updatedDef
=
updateByName
(
structDef
.
getName
(),
structDef
);
updatedDefs
.
add
(
updatedDef
);
}
catch
(
AtlasBaseException
ex
)
{}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.update({}): {}"
,
structDefs
,
updatedDefs
);
}
return
updatedDefs
;
}
@Override
public
void
deleteByName
(
String
name
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.deleteByName({})"
,
name
);
}
AtlasVertex
AtlasVertex
=
typeDefStore
.
findTypeVertexByNameAndCategory
(
name
,
TypeCategory
.
STRUCT
);
if
(
AtlasVertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with name "
+
name
);
}
typeDefStore
.
deleteTypeVertex
(
AtlasVertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.deleteByName({})"
,
name
);
}
}
@Override
public
void
deleteByNames
(
List
<
String
>
names
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.deleteByNames({})"
,
names
);
}
List
<
AtlasStructDef
>
updatedDefs
=
new
ArrayList
<>();
for
(
String
name
:
names
)
{
try
{
deleteByName
(
name
);
}
catch
(
AtlasBaseException
ex
)
{}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.deleteByNames({})"
,
names
);
}
}
@Override
public
void
deleteByGuid
(
String
guid
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.deleteByGuid({})"
,
guid
);
}
AtlasVertex
AtlasVertex
=
typeDefStore
.
findTypeVertexByGuidAndCategory
(
guid
,
TypeCategory
.
STRUCT
);
if
(
AtlasVertex
==
null
)
{
throw
new
AtlasBaseException
(
"no structDef exists with guid "
+
guid
);
}
typeDefStore
.
deleteTypeVertex
(
AtlasVertex
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.deleteByGuid({})"
,
guid
);
}
}
@Override
public
void
deleteByGuids
(
List
<
String
>
guids
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.deleteByGuids({})"
,
guids
);
}
List
<
AtlasStructDef
>
updatedDefs
=
new
ArrayList
<>();
for
(
String
guid
:
guids
)
{
try
{
deleteByGuid
(
guid
);
}
catch
(
AtlasBaseException
ex
)
{}
}
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.deleteByGuids({})"
,
guids
);
}
}
@Override
public
AtlasStructDefs
search
(
SearchFilter
filter
)
throws
AtlasBaseException
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> AtlasStructDefStoreV1.search({})"
,
filter
);
}
List
<
AtlasStructDef
>
structDefs
=
new
ArrayList
<
AtlasStructDef
>();
Iterator
<
AtlasVertex
>
vertices
=
typeDefStore
.
findTypeVerticesByCategory
(
TypeCategory
.
STRUCT
);
while
(
vertices
.
hasNext
())
{
AtlasVertex
AtlasVertex
=
vertices
.
next
();
AtlasStructDef
structDef
=
toStructDef
(
AtlasVertex
);
if
(
structDef
!=
null
)
{
structDefs
.
add
(
structDef
);
}
}
if
(
CollectionUtils
.
isNotEmpty
(
structDefs
))
{
CollectionUtils
.
filter
(
structDefs
,
FilterUtil
.
getPredicateFromSearchFilter
(
filter
));
}
AtlasStructDefs
ret
=
new
AtlasStructDefs
(
structDefs
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== AtlasStructDefStoreV1.search({}): {}"
,
filter
,
ret
);
}
return
ret
;
}
private
void
toVertex
(
AtlasStructDef
structDef
,
AtlasVertex
AtlasVertex
)
{
toVertex
(
structDef
,
AtlasVertex
,
typeDefStore
);
}
private
AtlasStructDef
toStructDef
(
AtlasVertex
AtlasVertex
)
{
AtlasStructDef
ret
=
null
;
if
(
AtlasVertex
!=
null
&&
typeDefStore
.
isTypeVertex
(
AtlasVertex
,
TypeCategory
.
STRUCT
))
{
ret
=
toStructDef
(
AtlasVertex
,
new
AtlasStructDef
(),
typeDefStore
);
}
return
ret
;
}
public
static
void
toVertex
(
AtlasStructDef
structDef
,
AtlasVertex
atlasVertex
,
AtlasTypeDefGraphStoreV1
typeDefStore
)
{
List
<
String
>
attrNames
=
new
ArrayList
<>(
structDef
.
getAttributeDefs
().
size
());
for
(
AtlasAttributeDef
attributeDef
:
structDef
.
getAttributeDefs
())
{
String
propertyKey
=
AtlasGraphUtilsV1
.
getPropertyKey
(
structDef
,
attributeDef
.
getName
());
AtlasGraphUtilsV1
.
setProperty
(
atlasVertex
,
propertyKey
,
toJsonFromAttributeDef
(
attributeDef
));
attrNames
.
add
(
attributeDef
.
getName
());
addReferencesForAttribute
(
atlasVertex
,
attributeDef
,
typeDefStore
);
}
AtlasGraphUtilsV1
.
setProperty
(
atlasVertex
,
AtlasGraphUtilsV1
.
getPropertyKey
(
structDef
),
attrNames
);
}
public
static
AtlasStructDef
toStructDef
(
AtlasVertex
atlasVertex
,
AtlasStructDef
structDef
,
AtlasTypeDefGraphStoreV1
typeDefStore
)
{
AtlasStructDef
ret
=
(
structDef
!=
null
)
?
structDef
:
new
AtlasStructDef
();
typeDefStore
.
vertexToTypeDef
(
atlasVertex
,
ret
);
List
<
AtlasAttributeDef
>
attributeDefs
=
new
ArrayList
<>();
List
<
String
>
attrNames
=
atlasVertex
.
getProperty
(
AtlasGraphUtilsV1
.
getPropertyKey
(
ret
),
List
.
class
);
if
(
CollectionUtils
.
isNotEmpty
(
attrNames
))
{
for
(
String
attrName
:
attrNames
)
{
String
propertyKey
=
AtlasGraphUtilsV1
.
getPropertyKey
(
ret
,
attrName
);
String
attribJson
=
atlasVertex
.
getProperty
(
propertyKey
,
String
.
class
);
attributeDefs
.
add
(
toAttributeDefFromJson
(
attribJson
));
}
}
ret
.
setAttributeDefs
(
attributeDefs
);
return
ret
;
}
private
static
void
addReferencesForAttribute
(
AtlasVertex
atlasVertex
,
AtlasAttributeDef
attributeDef
,
AtlasTypeDefGraphStoreV1
typeDefStore
)
{
Set
<
String
>
referencedTypeNames
=
AtlasTypeUtil
.
getReferencedTypeNames
(
attributeDef
.
getTypeName
());
String
AtlasVertexTypeName
=
atlasVertex
.
getProperty
(
Constants
.
TYPENAME_PROPERTY_KEY
,
String
.
class
);
for
(
String
referencedTypeName
:
referencedTypeNames
)
{
if
(!
AtlasTypeUtil
.
isBuiltInType
(
referencedTypeName
))
{
AtlasVertex
referencedTypeAtlasVertex
=
typeDefStore
.
findTypeVertexByName
(
referencedTypeName
);
if
(
referencedTypeAtlasVertex
==
null
)
{
// create atlasVertex?
}
if
(
referencedTypeAtlasVertex
!=
null
)
{
String
label
=
AtlasGraphUtilsV1
.
getEdgeLabel
(
AtlasVertexTypeName
,
attributeDef
.
getName
());
typeDefStore
.
getOrCreateEdge
(
atlasVertex
,
referencedTypeAtlasVertex
,
label
);
}
}
}
}
private
static
String
toJsonFromAttributeDef
(
AtlasAttributeDef
attributeDef
)
{
Map
<
String
,
Object
>
attribInfo
=
new
HashMap
<
String
,
Object
>();
attribInfo
.
put
(
"name"
,
attributeDef
.
getName
());
attribInfo
.
put
(
"dataType"
,
attributeDef
.
getTypeName
());
attribInfo
.
put
(
"isUnique"
,
attributeDef
.
isUnique
());
attribInfo
.
put
(
"isIndexable"
,
attributeDef
.
isIndexable
());
attribInfo
.
put
(
"isComposite"
,
Boolean
.
FALSE
);
attribInfo
.
put
(
"reverseAttributeName"
,
""
);
Map
<
String
,
Object
>
multiplicity
=
new
HashMap
<
String
,
Object
>();
multiplicity
.
put
(
"lower"
,
attributeDef
.
getValuesMinCount
());
multiplicity
.
put
(
"upper"
,
attributeDef
.
getValuesMaxCount
());
multiplicity
.
put
(
"isUnique"
,
AtlasAttributeDef
.
Cardinality
.
SET
.
equals
(
attributeDef
.
getCardinality
()));
attribInfo
.
put
(
"multiplicity"
,
AtlasType
.
toJson
(
multiplicity
));
return
AtlasType
.
toJson
(
attribInfo
);
}
private
static
AtlasAttributeDef
toAttributeDefFromJson
(
String
json
)
{
Map
attribInfo
=
AtlasType
.
fromJson
(
json
,
Map
.
class
);
AtlasAttributeDef
ret
=
new
AtlasAttributeDef
();
ret
.
setName
((
String
)
attribInfo
.
get
(
"name"
));
ret
.
setTypeName
((
String
)
attribInfo
.
get
(
"dataType"
));
ret
.
setUnique
((
Boolean
)
attribInfo
.
get
(
"isUnique"
));
ret
.
setIndexable
((
Boolean
)
attribInfo
.
get
(
"isIndexable"
));
/*
attributeMap.put("isComposite", isComposite);
attributeMap.put("reverseAttributeName", reverseAttributeName);
*/
Map
multiplicity
=
AtlasType
.
fromJson
((
String
)
attribInfo
.
get
(
"multiplicity"
),
Map
.
class
);
Number
minCount
=
(
Number
)
multiplicity
.
get
(
"lower"
);
Number
maxCount
=
(
Number
)
multiplicity
.
get
(
"upper"
);
Boolean
isUnique
=
(
Boolean
)
multiplicity
.
get
(
"isUnique"
);
if
(
minCount
==
null
||
minCount
.
intValue
()
==
0
)
{
ret
.
setOptional
(
true
);
ret
.
setValuesMinCount
(
0
);
}
else
{
ret
.
setOptional
(
false
);
ret
.
setValuesMinCount
(
minCount
.
intValue
());
}
if
(
maxCount
==
null
||
maxCount
.
intValue
()
<
2
)
{
ret
.
setCardinality
(
AtlasAttributeDef
.
Cardinality
.
SINGLE
);
ret
.
setValuesMaxCount
(
1
);
}
else
{
if
(
isUnique
==
null
||
isUnique
==
Boolean
.
FALSE
)
{
ret
.
setCardinality
(
AtlasAttributeDef
.
Cardinality
.
LIST
);
}
else
{
ret
.
setCardinality
(
AtlasAttributeDef
.
Cardinality
.
SET
);
}
ret
.
setValuesMaxCount
(
maxCount
.
intValue
());
}
return
ret
;
}
}
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
;
import
com.google.common.base.Preconditions
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graph.AtlasGraphProvider
;
import
org.apache.atlas.repository.graphdb.AtlasEdge
;
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.repository.store.graph.AtlasTypeDefGraphStore
;
import
org.apache.atlas.typesystem.types.DataTypes.TypeCategory
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Set
;
import
java.util.UUID
;
import
static
org
.
apache
.
atlas
.
repository
.
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
;
import
static
org
.
apache
.
atlas
.
repository
.
Constants
.
VERTEX_TYPE_PROPERTY_KEY
;
import
static
org
.
apache
.
atlas
.
repository
.
store
.
graph
.
v1
.
AtlasGraphUtilsV1
.
VERTEX_TYPE
;
/**
* Graph persistence store for TypeDef - v1
*/
public
class
AtlasTypeDefGraphStoreV1
extends
AtlasTypeDefGraphStore
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasTypeDefGraphStoreV1
.
class
);
protected
final
AtlasGraph
atlasGraph
=
AtlasGraphProvider
.
getGraphInstance
();
public
AtlasTypeDefGraphStoreV1
()
{
super
();
enumDefStore
=
new
AtlasEnumDefStoreV1
(
this
);
structDefStore
=
new
AtlasStructDefStoreV1
(
this
);
classificationDefStore
=
new
AtlasClassificationDefStoreV1
(
this
);
entityDefStore
=
new
AtlasEntityDefStoreV1
(
this
);
}
@Override
public
void
init
()
{
}
public
AtlasGraph
getAtlasGraph
()
{
return
atlasGraph
;
}
public
AtlasVertex
findTypeVertexByName
(
String
typeName
)
{
Iterator
results
=
atlasGraph
.
query
().
has
(
VERTEX_TYPE_PROPERTY_KEY
,
VERTEX_TYPE
)
.
has
(
Constants
.
TYPENAME_PROPERTY_KEY
,
typeName
)
.
vertices
().
iterator
();
AtlasVertex
ret
=
(
results
!=
null
&&
results
.
hasNext
())
?
(
AtlasVertex
)
results
.
next
()
:
null
;
return
ret
;
}
public
AtlasVertex
findTypeVertexByNameAndCategory
(
String
typeName
,
TypeCategory
category
)
{
Iterator
results
=
atlasGraph
.
query
().
has
(
VERTEX_TYPE_PROPERTY_KEY
,
VERTEX_TYPE
)
.
has
(
Constants
.
TYPENAME_PROPERTY_KEY
,
typeName
)
.
has
(
TYPE_CATEGORY_PROPERTY_KEY
,
category
)
.
vertices
().
iterator
();
AtlasVertex
ret
=
(
results
!=
null
&&
results
.
hasNext
())
?
(
AtlasVertex
)
results
.
next
()
:
null
;
return
ret
;
}
public
AtlasVertex
findTypeVertexByGuid
(
String
typeGuid
)
{
Iterator
<
AtlasVertex
>
vertices
=
atlasGraph
.
query
().
has
(
VERTEX_TYPE_PROPERTY_KEY
,
VERTEX_TYPE
)
.
has
(
Constants
.
GUID_PROPERTY_KEY
,
typeGuid
)
.
vertices
().
iterator
();
AtlasVertex
ret
=
(
vertices
!=
null
&&
vertices
.
hasNext
())
?
vertices
.
next
()
:
null
;
return
ret
;
}
public
AtlasVertex
findTypeVertexByGuidAndCategory
(
String
typeGuid
,
TypeCategory
category
)
{
Iterator
<
AtlasVertex
>
vertices
=
atlasGraph
.
query
().
has
(
VERTEX_TYPE_PROPERTY_KEY
,
VERTEX_TYPE
)
.
has
(
Constants
.
GUID_PROPERTY_KEY
,
typeGuid
)
.
has
(
TYPE_CATEGORY_PROPERTY_KEY
,
category
)
.
vertices
().
iterator
();
AtlasVertex
ret
=
(
vertices
!=
null
&&
vertices
.
hasNext
())
?
vertices
.
next
()
:
null
;
return
ret
;
}
public
Iterator
<
AtlasVertex
>
findTypeVerticesByCategory
(
TypeCategory
category
)
{
Iterator
<
AtlasVertex
>
ret
=
atlasGraph
.
query
().
has
(
VERTEX_TYPE_PROPERTY_KEY
,
VERTEX_TYPE
)
.
has
(
TYPE_CATEGORY_PROPERTY_KEY
,
category
)
.
vertices
().
iterator
();
return
ret
;
}
public
AtlasVertex
createTypeVertex
(
AtlasBaseTypeDef
typeDef
)
{
// Validate all the required checks
Preconditions
.
checkArgument
(
StringUtils
.
isNotBlank
(
typeDef
.
getName
()),
"Type name can't be null/empty"
);
Preconditions
.
checkArgument
(
StringUtils
.
isNotBlank
(
typeDef
.
getTypeVersion
()),
"Type version can't be null/empty"
);
Preconditions
.
checkArgument
(
typeDef
.
getVersion
()
!=
null
,
"Version can't be null"
);
AtlasVertex
ret
=
atlasGraph
.
addVertex
();
if
(
StringUtils
.
isBlank
(
typeDef
.
getTypeVersion
()))
{
typeDef
.
setTypeVersion
(
"1.0"
);
}
if
(
StringUtils
.
isBlank
(
typeDef
.
getGuid
()))
{
typeDef
.
setGuid
(
UUID
.
randomUUID
().
toString
());
}
if
(
typeDef
.
getCreateTime
()
==
null
)
{
typeDef
.
setCreateTime
(
new
Date
());
}
if
(
typeDef
.
getUpdateTime
()
==
null
)
{
typeDef
.
setUpdateTime
(
new
Date
());
}
ret
.
setProperty
(
VERTEX_TYPE_PROPERTY_KEY
,
VERTEX_TYPE
);
// Mark as type vertex
ret
.
setProperty
(
TYPE_CATEGORY_PROPERTY_KEY
,
getTypeCategory
(
typeDef
));
ret
.
setProperty
(
Constants
.
TYPENAME_PROPERTY_KEY
,
typeDef
.
getName
());
ret
.
setProperty
(
Constants
.
TYPEDESCRIPTION_PROPERTY_KEY
,
StringUtils
.
isNotBlank
(
typeDef
.
getDescription
())
?
typeDef
.
getDescription
()
:
typeDef
.
getName
());
ret
.
setProperty
(
Constants
.
TYPEVERSION_PROPERTY_KEY
,
typeDef
.
getTypeVersion
());
ret
.
setProperty
(
Constants
.
GUID_PROPERTY_KEY
,
typeDef
.
getGuid
());
ret
.
setProperty
(
Constants
.
TIMESTAMP_PROPERTY_KEY
,
typeDef
.
getCreateTime
().
getTime
());
ret
.
setProperty
(
Constants
.
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
typeDef
.
getUpdateTime
().
getTime
());
ret
.
setProperty
(
Constants
.
VERSION_PROPERTY_KEY
,
typeDef
.
getVersion
());
return
ret
;
}
public
void
deleteTypeVertex
(
AtlasVertex
vertex
)
throws
AtlasBaseException
{
Iterator
<
AtlasEdge
>
inEdges
=
vertex
.
getEdges
(
AtlasEdgeDirection
.
IN
).
iterator
();
if
(
inEdges
.
hasNext
())
{
throw
new
AtlasBaseException
(
"has references"
);
}
Iterable
<
AtlasEdge
>
edges
=
vertex
.
getEdges
(
AtlasEdgeDirection
.
OUT
);
for
(
AtlasEdge
edge
:
edges
)
{
atlasGraph
.
removeEdge
(
edge
);
}
atlasGraph
.
removeVertex
(
vertex
);
}
public
void
vertexToTypeDef
(
AtlasVertex
vertex
,
AtlasBaseTypeDef
typeDef
)
{
String
name
=
vertex
.
getProperty
(
Constants
.
TYPENAME_PROPERTY_KEY
,
String
.
class
);
String
description
=
vertex
.
getProperty
(
Constants
.
TYPEDESCRIPTION_PROPERTY_KEY
,
String
.
class
);
String
typeVersion
=
vertex
.
getProperty
(
Constants
.
TYPEVERSION_PROPERTY_KEY
,
String
.
class
);
String
guid
=
vertex
.
getProperty
(
Constants
.
GUID_PROPERTY_KEY
,
String
.
class
);
Long
createTime
=
vertex
.
getProperty
(
Constants
.
TIMESTAMP_PROPERTY_KEY
,
Long
.
class
);
Long
updateTime
=
vertex
.
getProperty
(
Constants
.
MODIFICATION_TIMESTAMP_PROPERTY_KEY
,
Long
.
class
);
Long
version
=
vertex
.
getProperty
(
Constants
.
VERSION_PROPERTY_KEY
,
Long
.
class
);
typeDef
.
setName
(
name
);
typeDef
.
setDescription
(
description
);
typeDef
.
setTypeVersion
(
typeVersion
);
typeDef
.
setGuid
(
guid
);
if
(
createTime
!=
null
)
{
typeDef
.
setCreateTime
(
new
Date
(
createTime
));
}
if
(
updateTime
!=
null
)
{
typeDef
.
setUpdateTime
(
new
Date
(
updateTime
));
}
if
(
version
!=
null
)
{
typeDef
.
setVersion
(
version
);
}
}
public
boolean
isTypeVertex
(
AtlasVertex
vertex
)
{
String
vertexType
=
vertex
.
getProperty
(
Constants
.
VERTEX_TYPE_PROPERTY_KEY
,
String
.
class
);
boolean
ret
=
VERTEX_TYPE
.
equals
(
vertexType
);
return
ret
;
}
public
boolean
isTypeVertex
(
AtlasVertex
vertex
,
TypeCategory
category
)
{
boolean
ret
=
false
;
if
(
isTypeVertex
(
vertex
))
{
TypeCategory
vertexCategory
=
vertex
.
getProperty
(
Constants
.
TYPE_CATEGORY_PROPERTY_KEY
,
TypeCategory
.
class
);
ret
=
category
.
equals
(
vertexCategory
);
}
return
ret
;
}
public
boolean
isTypeVertex
(
AtlasVertex
vertex
,
TypeCategory
[]
categories
)
{
boolean
ret
=
false
;
if
(
isTypeVertex
(
vertex
))
{
TypeCategory
vertexCategory
=
vertex
.
getProperty
(
TYPE_CATEGORY_PROPERTY_KEY
,
TypeCategory
.
class
);
for
(
TypeCategory
category
:
categories
)
{
if
(
category
.
equals
(
vertexCategory
))
{
ret
=
true
;
break
;
}
}
}
return
ret
;
}
public
AtlasEdge
getOrCreateEdge
(
AtlasVertex
outVertex
,
AtlasVertex
inVertex
,
String
edgeLabel
)
{
AtlasEdge
ret
=
null
;
Iterable
<
AtlasEdge
>
edges
=
outVertex
.
getEdges
(
AtlasEdgeDirection
.
OUT
,
edgeLabel
);
for
(
AtlasEdge
edge
:
edges
)
{
if
(
edge
.
getInVertex
().
getId
().
equals
(
inVertex
.
getId
()))
{
ret
=
edge
;
break
;
}
}
if
(
ret
==
null
)
{
ret
=
addEdge
(
outVertex
,
inVertex
,
edgeLabel
);
}
return
ret
;
}
public
AtlasEdge
addEdge
(
AtlasVertex
outVertex
,
AtlasVertex
inVertex
,
String
edgeLabel
)
{
AtlasEdge
ret
=
atlasGraph
.
addEdge
(
outVertex
,
inVertex
,
edgeLabel
);
return
ret
;
}
public
void
createSuperTypeEdges
(
AtlasVertex
vertex
,
Set
<
String
>
superTypes
)
{
if
(
CollectionUtils
.
isNotEmpty
(
superTypes
))
{
for
(
String
superType
:
superTypes
)
{
AtlasVertex
superTypeVertex
=
findTypeVertexByNameAndCategory
(
superType
,
TypeCategory
.
CLASS
);
getOrCreateEdge
(
vertex
,
superTypeVertex
,
AtlasGraphUtilsV1
.
SUPERTYPE_EDGE_LABEL
);
}
}
// TODO: remove any other superType edges, if any exists
}
public
Set
<
String
>
getSuperTypeNames
(
AtlasVertex
vertex
)
{
Set
<
String
>
ret
=
new
HashSet
<>();
Iterable
<
AtlasEdge
>
edges
=
vertex
.
getEdges
(
AtlasEdgeDirection
.
OUT
,
AtlasGraphUtilsV1
.
SUPERTYPE_EDGE_LABEL
);
for
(
AtlasEdge
edge
:
edges
)
{
ret
.
add
(
edge
.
getInVertex
().
getProperty
(
Constants
.
TYPENAME_PROPERTY_KEY
,
String
.
class
));
}
return
ret
;
}
private
TypeCategory
getTypeCategory
(
AtlasBaseTypeDef
typeDef
)
{
TypeCategory
ret
=
null
;
if
(
typeDef
instanceof
AtlasEntityDef
)
{
ret
=
TypeCategory
.
CLASS
;
}
else
if
(
typeDef
instanceof
AtlasClassificationDef
)
{
ret
=
TypeCategory
.
TRAIT
;
}
else
if
(
typeDef
instanceof
AtlasStructDef
)
{
ret
=
TypeCategory
.
STRUCT
;
}
else
if
(
typeDef
instanceof
AtlasEnumDef
)
{
ret
=
TypeCategory
.
ENUM
;
}
return
ret
;
}
}
repository/src/main/java/org/apache/atlas/repository/util/FilterUtil.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
repository
.
util
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasEnumDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.commons.collections.Predicate
;
import
org.apache.commons.collections.PredicateUtils
;
import
org.apache.commons.collections.functors.NotPredicate
;
import
org.apache.commons.lang.StringUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
FilterUtil
{
public
static
Predicate
getPredicateFromSearchFilter
(
SearchFilter
searchFilter
)
{
List
<
Predicate
>
predicates
=
new
ArrayList
<>();
final
String
type
=
searchFilter
.
getParam
(
SearchFilter
.
PARAM_TYPE
);
final
String
supertype
=
searchFilter
.
getParam
(
SearchFilter
.
PARAM_SUPERTYPE
);
final
String
notSupertype
=
searchFilter
.
getParam
(
SearchFilter
.
PARAM_NOT_SUPERTYPE
);
// Add filter for the type/category
if
(
StringUtils
.
isNotBlank
(
type
))
{
predicates
.
add
(
getTypePredicate
(
type
));
}
// Add filter for the supertype
if
(
StringUtils
.
isNotBlank
(
supertype
))
{
predicates
.
add
(
getSuperTypePredicate
(
supertype
));
}
// Add filter for the supertype negation
if
(
StringUtils
.
isNotBlank
(
notSupertype
))
{
predicates
.
add
(
new
NotPredicate
(
getSuperTypePredicate
(
notSupertype
)));
}
return
PredicateUtils
.
allPredicate
(
predicates
);
}
private
static
Predicate
getSuperTypePredicate
(
final
String
supertype
)
{
return
new
Predicate
()
{
private
boolean
isClassificationDef
(
Object
o
)
{
return
o
instanceof
AtlasClassificationDef
;
}
private
boolean
isEntityDef
(
Object
o
)
{
return
o
instanceof
AtlasEntityDef
;
}
@Override
public
boolean
evaluate
(
Object
o
)
{
return
(
isClassificationDef
(
o
)
&&
((
AtlasClassificationDef
)
o
).
getSuperTypes
().
contains
(
supertype
))||
(
isEntityDef
(
o
)
&&
((
AtlasEntityDef
)
o
).
getSuperTypes
().
contains
(
supertype
));
}
};
}
private
static
Predicate
getTypePredicate
(
final
String
type
)
{
return
new
Predicate
()
{
@Override
public
boolean
evaluate
(
Object
o
)
{
if
(
o
instanceof
AtlasBaseTypeDef
)
{
switch
(
type
.
toUpperCase
())
{
case
"CLASS"
:
case
"ENTITY"
:
return
o
instanceof
AtlasEntityDef
;
case
"TRAIT"
:
case
"CLASSIFICATION"
:
return
o
instanceof
AtlasClassificationDef
;
case
"STRUCT"
:
return
o
instanceof
AtlasStructDef
;
case
"ENUM"
:
return
o
instanceof
AtlasEnumDef
;
default
:
// This shouldn't have happened
return
false
;
}
}
else
{
return
false
;
}
}
};
}
}
repository/src/main/java/org/apache/atlas/util/TypeDefSorter.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
util
;
import
com.google.common.collect.ImmutableSet
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.typesystem.types.HierarchicalType
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
public
class
TypeDefSorter
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
TypeDefSorter
.
class
);
public
static
<
T
extends
AtlasStructDef
>
List
<
T
>
sortTypes
(
List
<
T
>
types
)
{
Map
<
String
,
T
>
typesByName
=
new
HashMap
<>();
for
(
T
type
:
types
)
{
typesByName
.
put
(
type
.
getName
(),
type
);
}
List
<
T
>
result
=
new
ArrayList
<>(
types
.
size
());
Set
<
T
>
processed
=
new
HashSet
<>();
for
(
T
type
:
types
)
{
addToResult
(
type
,
result
,
processed
,
typesByName
);
}
return
result
;
}
private
static
<
T
extends
AtlasStructDef
>
void
addToResult
(
T
type
,
List
<
T
>
result
,
Set
<
T
>
processed
,
Map
<
String
,
T
>
typesByName
)
{
if
(
processed
.
contains
(
type
))
{
return
;
}
processed
.
add
(
type
);
Set
<
String
>
superTypeNames
=
new
HashSet
<>();
try
{
AtlasClassificationDef
classificationDef
=
AtlasClassificationDef
.
class
.
cast
(
type
);
superTypeNames
.
addAll
(
classificationDef
.
getSuperTypes
());
}
catch
(
ClassCastException
ex
)
{
LOG
.
warn
(
"Casting to ClassificationDef failed"
);
}
try
{
AtlasEntityDef
entityDef
=
AtlasEntityDef
.
class
.
cast
(
type
);
superTypeNames
.
addAll
(
entityDef
.
getSuperTypes
());
}
catch
(
ClassCastException
ex
)
{
LOG
.
warn
(
"Casting to AtlasEntityDef failed"
);
}
for
(
String
superTypeName
:
superTypeNames
)
{
// Recursively add any supertypes first to the result.
T
superType
=
typesByName
.
get
(
superTypeName
);
if
(
superType
!=
null
)
{
addToResult
(
superType
,
result
,
processed
,
typesByName
);
}
}
result
.
add
(
type
);
}
}
webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
View file @
f8fe0945
...
...
@@ -17,16 +17,9 @@
*/
package
org
.
apache
.
atlas
.
web
.
rest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.PUT
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.Context
;
import
com.google.inject.Inject
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs
;
...
...
@@ -36,24 +29,61 @@ import org.apache.atlas.model.typedef.AtlasEnumDef;
import
org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumDefs
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.store.AtlasTypeDefStore
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.atlas.web.util.Servlets
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Set
;
@Path
(
"types"
)
import
javax.inject.Singleton
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.PUT
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.WebApplicationException
;
import
javax.ws.rs.core.Context
;
import
javax.ws.rs.core.Response
;
@Path
(
"v2/types"
)
@Singleton
public
class
TypesREST
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
TypesREST
.
class
);
private
AtlasTypeDefStore
typeDefStore
;
@Context
private
HttpServletRequest
httpServletRequest
;
@Inject
public
TypesREST
(
AtlasTypeDefStore
typeDefStore
,
AtlasTypeRegistry
atlasTypeRegistry
)
{
LOG
.
info
(
"new TypesREST"
);
this
.
typeDefStore
=
typeDefStore
;
}
/******* EnumDef REST calls *******/
@POST
@Path
(
"/enumdef"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDef
createEnumDef
(
AtlasEnumDef
enumDef
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.createEnumDef()
return
ret
;
try
{
ret
=
typeDefStore
.
createEnumDef
(
enumDef
);
return
ret
;
}
catch
(
AtlasBaseException
ex
)
{
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ex
,
Response
.
Status
.
BAD_REQUEST
));
}
}
@GET
...
...
@@ -62,7 +92,7 @@ public class TypesREST {
public
AtlasEnumDef
getEnumDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.getEnumDefByName(name)
ret
=
typeDefStore
.
getEnumDefByName
(
name
);
return
ret
;
}
...
...
@@ -73,29 +103,31 @@ public class TypesREST {
public
AtlasEnumDef
getEnumDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.getEnumDefByGuid(guid)
ret
=
typeDefStore
.
getEnumDefByGuid
(
guid
);
return
ret
;
}
@PUT
@Path
(
"/enumdef/name/{name}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDef
updateEnumDefByName
(
@PathParam
(
"name"
)
String
name
,
AtlasEnumDef
enumDef
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.updateEnumDefByName(name, enumDef)
ret
=
typeDefStore
.
updateEnumDefByName
(
name
,
enumDef
);
return
ret
;
}
@PUT
@Path
(
"/enumdef/guid/{guid}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDef
updateEnumDefByGuid
(
@PathParam
(
"guid"
)
String
guid
,
AtlasEnumDef
enumDef
)
throws
Exception
{
AtlasEnumDef
ret
=
null
;
// TODO: ret = store.updateEnumDefByGuid(guid, enumDef)
ret
=
typeDefStore
.
updateEnumDefByGuid
(
guid
,
enumDef
);
return
ret
;
}
...
...
@@ -104,38 +136,46 @@ public class TypesREST {
@Path
(
"/enumdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteEnumDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
// TODO: store.deleteEnumDefByName(name)
typeDefStore
.
deleteEnumDefByName
(
name
);
}
@DELETE
@Path
(
"/enumdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteEnumDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
// TODO: store.deleteEnumDefByGuid(guid)
typeDefStore
.
deleteEnumDefByGuid
(
guid
);
}
@GET
@Path
(
"/enumdef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEnumDefs
searchEnumDefs
(
@Context
HttpServletRequest
request
)
throws
Exception
{
public
AtlasEnumDefs
searchEnumDefs
()
throws
Exception
{
AtlasEnumDefs
ret
=
null
;
// TODO: SearchFilter filter = getSearchFilter(request);
// TODO: ret = store.searchEnumDefs(filter);
SearchFilter
filter
=
getSearchFilter
();
ret
=
typeDefStore
.
searchEnumDefs
(
filter
);
return
ret
;
}
/******* StructDef REST calls *******/
@POST
@Path
(
"/structdef"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDef
createStructDef
(
AtlasStructDef
structDef
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.createStructDef()
try
{
ret
=
typeDefStore
.
createStructDef
(
structDef
);
return
ret
;
}
catch
(
AtlasBaseException
ex
)
{
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ex
,
Response
.
Status
.
BAD_REQUEST
));
}
return
ret
;
}
@GET
...
...
@@ -144,7 +184,7 @@ public class TypesREST {
public
AtlasStructDef
getStructDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.getStructDefByName(name)
ret
=
typeDefStore
.
getStructDefByName
(
name
);
return
ret
;
}
...
...
@@ -155,29 +195,31 @@ public class TypesREST {
public
AtlasStructDef
getStructDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.getStructDefByGuid(guid)
ret
=
typeDefStore
.
getStructDefByGuid
(
guid
);
return
ret
;
}
@PUT
@Path
(
"/structdef/name/{name}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDef
updateStructDefByName
(
@PathParam
(
"name"
)
String
name
,
AtlasStructDef
structDef
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.updateStructDefByName(name, structDef)
ret
=
typeDefStore
.
updateStructDefByName
(
name
,
structDef
);
return
ret
;
}
@PUT
@Path
(
"/structdef/guid/{guid}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDef
updateStructDefByGuid
(
@PathParam
(
"guid"
)
String
guid
,
AtlasStructDef
structDef
)
throws
Exception
{
AtlasStructDef
ret
=
null
;
// TODO: ret = store.updateStructDefByGuid(guid, structDef)
ret
=
typeDefStore
.
updateStructDefByGuid
(
guid
,
structDef
);
return
ret
;
}
...
...
@@ -186,38 +228,43 @@ public class TypesREST {
@Path
(
"/structdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteStructDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
// TODO: store.deleteStructDefByName(name)
typeDefStore
.
deleteStructDefByName
(
name
);
}
@DELETE
@Path
(
"/structdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteStructDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
// TODO: store.deleteStructDefByGuid(guid)
typeDefStore
.
deleteStructDefByGuid
(
guid
);
}
@GET
@Path
(
"/structdef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasStructDefs
searchStructDefs
(
@Context
HttpServletRequest
request
)
throws
Exception
{
public
AtlasStructDefs
searchStructDefs
()
throws
Exception
{
AtlasStructDefs
ret
=
null
;
// TODO: SearchFilter filter = getSearchFilter(request
);
// TODO: ret = s
tore.searchStructDefs(filter);
SearchFilter
filter
=
getSearchFilter
(
);
ret
=
typeDefS
tore
.
searchStructDefs
(
filter
);
return
ret
;
}
/******* ClassificationDef REST calls *******/
@POST
@Path
(
"/classificationdef"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDef
createClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.createClassificationDef()
return
ret
;
try
{
ret
=
typeDefStore
.
createClassificationDef
(
classificationDef
);
return
ret
;
}
catch
(
AtlasBaseException
ex
)
{
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ex
,
Response
.
Status
.
BAD_REQUEST
));
}
}
@GET
...
...
@@ -226,7 +273,7 @@ public class TypesREST {
public
AtlasClassificationDef
getClassificationDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.getClassificationDefByName(name)
ret
=
typeDefStore
.
getClassificationDefByName
(
name
);
return
ret
;
}
...
...
@@ -237,29 +284,31 @@ public class TypesREST {
public
AtlasClassificationDef
getClassificationDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.getClassificationDefByGuid(guid)
ret
=
typeDefStore
.
getClassificationDefByGuid
(
guid
);
return
ret
;
}
@PUT
@Path
(
"/classificationdef/name/{name}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDef
updateClassificationDefByName
(
@PathParam
(
"name"
)
String
name
,
AtlasClassificationDef
classificationDef
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.updateClassificationDefByName(name, classificationDef)
ret
=
typeDefStore
.
updateClassificationDefByName
(
name
,
classificationDef
);
return
ret
;
}
@PUT
@Path
(
"/classificationdef/guid/{guid}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDef
updateClassificationDefByGuid
(
@PathParam
(
"guid"
)
String
guid
,
AtlasClassificationDef
classificationDef
)
throws
Exception
{
AtlasClassificationDef
ret
=
null
;
// TODO: ret = store.updateClassificationDefByGuid(guid, classificationDef)
ret
=
typeDefStore
.
updateClassificationDefByGuid
(
guid
,
classificationDef
);
return
ret
;
}
...
...
@@ -268,38 +317,44 @@ public class TypesREST {
@Path
(
"/classificationdef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteClassificationDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
// TODO: store.deleteClassificationDefByName(name)
typeDefStore
.
deleteClassificationDefByName
(
name
);
}
@DELETE
@Path
(
"/classificationdef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteClassificationDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
// TODO: store.deleteClassificationDefByGuid(guid)
typeDefStore
.
deleteClassificationDefByGuid
(
guid
);
}
@GET
@Path
(
"/classificationdef"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasClassificationDefs
searchClassificationDefs
(
SearchFilter
filter
)
throws
Exception
{
public
AtlasClassificationDefs
searchClassificationDefs
()
throws
Exception
{
AtlasClassificationDefs
ret
=
null
;
// TODO: SearchFilter filter = getSearchFilter(request
);
// TODO: ret = s
tore.searchClassificationDefs(filter);
SearchFilter
filter
=
getSearchFilter
(
);
ret
=
typeDefS
tore
.
searchClassificationDefs
(
filter
);
return
ret
;
}
/******* EntityDef REST calls *******/
@POST
@Path
(
"/entitydef"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
createEntityDef
(
AtlasEntityDef
entityDef
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.createEntityDef()
return
ret
;
try
{
ret
=
typeDefStore
.
createEntityDefs
(
entityDef
);
return
ret
;
}
catch
(
AtlasBaseException
ex
)
{
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ex
,
Response
.
Status
.
BAD_REQUEST
));
}
}
@GET
...
...
@@ -308,7 +363,7 @@ public class TypesREST {
public
AtlasEntityDef
getEntityDefByName
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.getEntityDefByName(name)
ret
=
typeDefStore
.
getEntityDefByName
(
name
);
return
ret
;
}
...
...
@@ -316,32 +371,34 @@ public class TypesREST {
@GET
@Path
(
"/entitydef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
getEntityDefBy
IdBy
Guid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
public
AtlasEntityDef
getEntityDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.getEntityDefByGuid(guid)
ret
=
typeDefStore
.
getEntityDefByGuid
(
guid
);
return
ret
;
}
@PUT
@Path
(
"/entitydef/name/{name}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
updateEntityDefByName
(
@PathParam
(
"name"
)
String
name
,
AtlasEntityDef
entityDef
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.updateEntityDefByName(name, entityDef)
ret
=
typeDefStore
.
updateEntityDefByName
(
name
,
entityDef
);
return
ret
;
}
@PUT
@Path
(
"/entitydef/guid/{guid}"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDef
updateEntityDefByGuid
(
@PathParam
(
"guid"
)
String
guid
,
AtlasEntityDef
entityDef
)
throws
Exception
{
AtlasEntityDef
ret
=
null
;
// TODO: ret = store.updateEntityDefByGuid(guid, entityDef)
ret
=
typeDefStore
.
updateEntityDefByGuid
(
guid
,
entityDef
);
return
ret
;
}
...
...
@@ -350,25 +407,109 @@ public class TypesREST {
@Path
(
"/entitydef/name/{name}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteEntityDef
(
@PathParam
(
"name"
)
String
name
)
throws
Exception
{
// TODO: store.deleteEntityDefByName(name)
typeDefStore
.
deleteEntityDefByName
(
name
);
}
@DELETE
@Path
(
"/entitydef/guid/{guid}"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
void
deleteEntityDefByGuid
(
@PathParam
(
"guid"
)
String
guid
)
throws
Exception
{
// TODO: store.deleteEntityDefByGuid(guid)
typeDefStore
.
deleteEntityDefByGuid
(
guid
);
}
@GET
@Path
(
"/entitydef"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasEntityDefs
searchEntityDefs
(
SearchFilter
filter
)
throws
Exception
{
public
AtlasEntityDefs
searchEntityDefs
()
throws
Exception
{
AtlasEntityDefs
ret
=
null
;
// TODO: SearchFilter filter = getSearchFilter(request);
// TODO: ret = store.searchEntityDefs(filter);
SearchFilter
filter
=
getSearchFilter
();
ret
=
typeDefStore
.
searchEntityDefs
(
filter
);
return
ret
;
}
/******************************************************************/
/** Bulk API operations **/
/******************************************************************/
/**
* Bulk retrieval API for retrieving all type definitions in Atlas
* @return A composite wrapper object with lists of all type definitions
* @throws Exception
*/
@GET
@Path
(
"/typedefs"
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasTypesDef
getAllTypeDefs
()
throws
Exception
{
SearchFilter
searchFilter
=
getSearchFilter
();
AtlasTypesDef
typesDef
=
null
;
try
{
typesDef
=
typeDefStore
.
searchTypesDef
(
searchFilter
);
}
catch
(
AtlasBaseException
ex
)
{
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ex
,
Response
.
Status
.
NOT_FOUND
));
}
return
typesDef
;
}
/**
* Bulk create APIs for all atlas type definitions, only new definitions will be created.
* Any changes to the existing definitions will be discarded
* @param typesDef A composite wrapper object with corresponding lists of the type definition
* @return A composite wrapper object with lists of type definitions that were successfully
* created
* @throws Exception
*/
@POST
@Path
(
"/typedefs"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasTypesDef
createAtlasTypeDefs
(
final
AtlasTypesDef
typesDef
)
throws
Exception
{
AtlasTypesDef
ret
=
null
;
try
{
ret
=
typeDefStore
.
createTypesDef
(
typesDef
);
}
catch
(
AtlasBaseException
ex
)
{
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ex
,
Response
.
Status
.
BAD_REQUEST
));
}
return
ret
;
}
/**
* Bulk update API for all types, changes detected in the type definitions would be persisted
* @param typesDef A composite object that captures all type definition changes
* @return A composite object with lists of type definitions that were updated
* @throws Exception
*/
@PUT
@Path
(
"/typedefs"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasTypesDef
updateAtlasTypeDefs
(
final
AtlasTypesDef
typesDef
)
throws
Exception
{
AtlasTypesDef
ret
=
null
;
try
{
ret
=
typeDefStore
.
updateTypesDef
(
typesDef
);
}
catch
(
AtlasBaseException
ex
)
{
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
ex
,
Response
.
Status
.
NOT_MODIFIED
));
}
return
ret
;
}
}
/**
* Populate a SearchFilter on the basis of the Query Parameters
* @return
*/
private
SearchFilter
getSearchFilter
()
{
SearchFilter
ret
=
new
SearchFilter
();
Set
<
String
>
keySet
=
httpServletRequest
.
getParameterMap
().
keySet
();
for
(
String
key
:
keySet
)
{
ret
.
setParam
(
String
.
valueOf
(
key
),
String
.
valueOf
(
httpServletRequest
.
getParameter
(
key
)));
}
return
ret
;
}}
webapp/src/main/java/org/apache/atlas/web/rest/module/RestModule.java
0 → 100644
View file @
f8fe0945
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
atlas
.
web
.
rest
.
module
;
import
com.google.inject.AbstractModule
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
/**
* @author anaik
*/
public
class
RestModule
extends
AbstractModule
{
@Override
protected
void
configure
()
{
bind
(
AtlasTypeRegistry
.
class
).
to
(
AtlasTypeRegistry
.
class
).
asEagerSingleton
();
}
}
webapp/src/main/webapp/WEB-INF/web.xml
View file @
f8fe0945
...
...
@@ -27,7 +27,7 @@
<context-param>
<param-name>
guice.packages
</param-name>
<param-value>
org.apache.atlas.web.resources,org.apache.atlas.web.params
org.apache.atlas.web.resources,org.apache.atlas.web.params
,org.apache.atlas.web.rest
</param-value>
</context-param>
...
...
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