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
8827bfb4
Commit
8827bfb4
authored
Jun 23, 2020
by
Jyoti Singh
Committed by
Madhan Neethiraj
Jul 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3875: added missing APIs in AtlasClient
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
a42f0c1c
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
2139 additions
and
206 deletions
+2139
-206
AtlasClientV2.java
...ient-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
+760
-113
AtlasBaseClient.java
...ommon/src/main/java/org/apache/atlas/AtlasBaseClient.java
+1
-2
pom.xml
webapp/pom.xml
+1
-0
TestUtils.java
webapp/src/test/java/org/apache/atlas/web/TestUtils.java
+3
-0
BaseResourceIT.java
...java/org/apache/atlas/web/integration/BaseResourceIT.java
+66
-13
BasicSearchIT.java
.../java/org/apache/atlas/web/integration/BasicSearchIT.java
+145
-0
EntityV2JerseyResourceIT.java
...pache/atlas/web/integration/EntityV2JerseyResourceIT.java
+423
-76
GlossaryClientV2IT.java
.../org/apache/atlas/web/integration/GlossaryClientV2IT.java
+482
-0
LineageClientV2IT.java
...a/org/apache/atlas/web/integration/LineageClientV2IT.java
+133
-0
TypedefsJerseyResourceIT.java
...pache/atlas/web/integration/TypedefsJerseyResourceIT.java
+85
-2
attribute-filters.json
...t/resources/json/search-parameters/attribute-filters.json
+35
-0
template.csv
webapp/src/test/resources/template.csv
+3
-0
template_metadata.csv
webapp/src/test/resources/template_metadata.csv
+2
-0
No files found.
client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
View file @
8827bfb4
...
...
@@ -21,41 +21,73 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.google.common.annotations.VisibleForTesting
;
import
com.sun.jersey.api.client.WebResource
;
import
com.sun.jersey.core.header.FormDataContentDisposition
;
import
com.sun.jersey.core.util.MultivaluedMapImpl
;
import
com.sun.jersey.multipart.FormDataBodyPart
;
import
com.sun.jersey.multipart.FormDataMultiPart
;
import
com.sun.jersey.multipart.MultiPart
;
import
com.sun.jersey.multipart.file.StreamDataBodyPart
;
import
org.apache.atlas.bulkimport.BulkImportResponse
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.audit.AtlasAuditEntry
;
import
org.apache.atlas.model.audit.AuditSearchParameters
;
import
org.apache.atlas.model.audit.EntityAuditEventV2
;
import
org.apache.atlas.model.discovery.AtlasQuickSearchResult
;
import
org.apache.atlas.model.discovery.AtlasSearchResult
;
import
org.apache.atlas.model.discovery.AtlasSuggestionsResult
;
import
org.apache.atlas.model.discovery.QuickSearchParameters
;
import
org.apache.atlas.model.discovery.SearchParameters
;
import
org.apache.atlas.model.glossary.AtlasGlossary
;
import
org.apache.atlas.model.glossary.AtlasGlossaryCategory
;
import
org.apache.atlas.model.glossary.AtlasGlossaryTerm
;
import
org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader
;
import
org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntityHeader
;
import
org.apache.atlas.model.instance.AtlasEntityHeaders
;
import
org.apache.atlas.model.instance.AtlasRelatedObjectId
;
import
org.apache.atlas.model.instance.AtlasRelationship
;
import
org.apache.atlas.model.instance.AtlasRelationship.AtlasRelationshipWithExtInfo
;
import
org.apache.atlas.model.instance.ClassificationAssociateRequest
;
import
org.apache.atlas.model.instance.EntityMutationResponse
;
import
org.apache.atlas.model.lineage.AtlasLineageInfo
;
import
org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection
;
import
org.apache.atlas.model.profile.AtlasUserSavedSearch
;
import
org.apache.atlas.model.typedef.AtlasBusinessMetadataDef
;
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.AtlasRelationshipDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasTypeDefHeader
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.hadoop.security.UserGroupInformation
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.Cookie
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MultivaluedMap
;
import
javax.ws.rs.core.Response
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
public
class
AtlasClientV2
extends
AtlasBaseClient
{
// Type APIs
public
static
final
String
TYPES_API
=
BASE_URI
+
"v2/types/"
;
...
...
@@ -80,16 +112,26 @@ public class AtlasClientV2 extends AtlasBaseClient {
// Discovery APIs
private
static
final
String
DISCOVERY_URI
=
BASE_URI
+
"v2/search"
;
private
static
final
String
DSL_
URI
=
DISCOVERY_URI
+
"/dsl"
;
private
static
final
String
FULL_TEXT_
URI
=
DISCOVERY_URI
+
"/fulltext"
;
private
static
final
String
DSL_
SEARCH_URI
=
DISCOVERY_URI
+
"/dsl"
;
private
static
final
String
FULL_TEXT_
SEARCH_URI
=
DISCOVERY_URI
+
"/fulltext"
;
private
static
final
String
BASIC_SEARCH_URI
=
DISCOVERY_URI
+
"/basic"
;
private
static
final
String
FACETED_SEARCH_URI
=
BASIC_SEARCH_URI
;
private
static
final
String
SAVED_SEARCH_URI
=
DISCOVERY_URI
+
"/saved"
;
private
static
final
String
QUICK_SEARCH_URI
=
DISCOVERY_URI
+
"/quick"
;
// Relationships APIs
private
static
final
String
RELATIONSHIPS_URI
=
BASE_URI
+
"v2/relationship/"
;
private
static
final
String
BULK_HEADERS
=
"bulk/headers"
;
private
static
final
String
BULK_SET_CLASSIFICATIONS
=
"bulk/setClassifications"
;
//Glossary APIs
private
static
final
String
GLOSSARY_URI
=
BASE_URI
+
"v2/glossary"
;
private
static
final
String
GLOSSARY_TERM
=
GLOSSARY_URI
+
"/term"
;
private
static
final
String
GLOSSARY_TERMS
=
GLOSSARY_URI
+
"/terms"
;
private
static
final
String
GLOSSARY_CATEGORY
=
GLOSSARY_URI
+
"/category"
;
private
static
final
String
GLOSSARY_CATEGORIES
=
GLOSSARY_URI
+
"/categories"
;
public
AtlasClientV2
(
String
[]
baseUrl
,
String
[]
basicAuthUserNamePassword
)
{
super
(
baseUrl
,
basicAuthUserNamePassword
);
}
...
...
@@ -141,12 +183,17 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
callAPI
(
API_V2
.
GET_ALL_TYPE_DEFS
,
AtlasTypesDef
.
class
,
searchFilter
.
getParams
());
}
public
List
<
AtlasTypeDefHeader
>
getAllTypeDefHeaders
(
SearchFilter
searchFilter
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
GET_ALL_TYPE_DEF_HEADERS
,
List
.
class
,
searchFilter
.
getParams
());
}
public
boolean
typeWithGuidExists
(
String
guid
)
{
try
{
callAPI
(
API_V2
.
GET_TYPEDEF_BY_GUID
,
String
.
class
,
null
,
guid
);
}
catch
(
AtlasServiceException
e
)
{
return
false
;
}
return
true
;
}
...
...
@@ -156,79 +203,111 @@ public class AtlasClientV2 extends AtlasBaseClient {
}
catch
(
AtlasServiceException
e
)
{
return
false
;
}
return
true
;
}
public
AtlasEnumDef
getEnumDefByName
(
final
String
name
)
throws
AtlasServiceException
{
public
AtlasEnumDef
getEnumDefByName
(
String
name
)
throws
AtlasServiceException
{
return
getTypeDefByName
(
name
,
AtlasEnumDef
.
class
);
}
public
AtlasEnumDef
getEnumDefByGuid
(
final
String
guid
)
throws
AtlasServiceException
{
public
AtlasEnumDef
getEnumDefByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
getTypeDefByGuid
(
guid
,
AtlasEnumDef
.
class
);
}
public
AtlasStructDef
getStructDefByName
(
final
String
name
)
throws
AtlasServiceException
{
public
AtlasStructDef
getStructDefByName
(
String
name
)
throws
AtlasServiceException
{
return
getTypeDefByName
(
name
,
AtlasStructDef
.
class
);
}
public
AtlasStructDef
getStructDefByGuid
(
final
String
guid
)
throws
AtlasServiceException
{
public
AtlasStructDef
getStructDefByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
getTypeDefByGuid
(
guid
,
AtlasStructDef
.
class
);
}
public
AtlasClassificationDef
getClassificationDefByName
(
final
String
name
)
throws
AtlasServiceException
{
public
AtlasClassificationDef
getClassificationDefByName
(
String
name
)
throws
AtlasServiceException
{
return
getTypeDefByName
(
name
,
AtlasClassificationDef
.
class
);
}
public
AtlasClassificationDef
getClassificationDefByGuid
(
final
String
guid
)
throws
AtlasServiceException
{
public
AtlasClassificationDef
getClassificationDefByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
getTypeDefByGuid
(
guid
,
AtlasClassificationDef
.
class
);
}
public
AtlasEntityDef
getEntityDefByName
(
final
String
name
)
throws
AtlasServiceException
{
public
AtlasEntityDef
getEntityDefByName
(
String
name
)
throws
AtlasServiceException
{
return
getTypeDefByName
(
name
,
AtlasEntityDef
.
class
);
}
public
AtlasEntityDef
getEntityDefByGuid
(
final
String
guid
)
throws
AtlasServiceException
{
public
AtlasEntityDef
getEntityDefByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
getTypeDefByGuid
(
guid
,
AtlasEntityDef
.
class
);
}
public
AtlasRelationshipDef
getRelationshipDefByName
(
String
name
)
throws
AtlasServiceException
{
return
getTypeDefByName
(
name
,
AtlasRelationshipDef
.
class
);
}
public
AtlasRelationshipDef
getRelationshipDefByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
getTypeDefByGuid
(
guid
,
AtlasRelationshipDef
.
class
);
}
public
AtlasBusinessMetadataDef
getBusinessMetadataDefByName
(
String
name
)
throws
AtlasServiceException
{
return
getTypeDefByName
(
name
,
AtlasBusinessMetadataDef
.
class
);
}
public
AtlasBusinessMetadataDef
getBusinessMetadataDefGuid
(
String
guid
)
throws
AtlasServiceException
{
return
getTypeDefByGuid
(
guid
,
AtlasBusinessMetadataDef
.
class
);
}
@Deprecated
public
AtlasEnumDef
createEnumDef
(
AtlasEnumDef
enumDef
)
throws
AtlasServiceException
{
AtlasTypesDef
atlasTypesDef
=
new
AtlasTypesDef
();
atlasTypesDef
.
getEnumDefs
().
add
(
enumDef
);
AtlasTypesDef
created
=
createAtlasTypeDefs
(
atlasTypesDef
);
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
();
typesDef
.
getEnumDefs
().
add
(
enumDef
);
AtlasTypesDef
created
=
createAtlasTypeDefs
(
typesDef
);
assert
created
!=
null
;
assert
created
.
getEnumDefs
()
!=
null
;
return
created
.
getEnumDefs
().
get
(
0
);
}
@Deprecated
public
AtlasStructDef
createStructDef
(
AtlasStructDef
structDef
)
throws
AtlasServiceException
{
AtlasTypesDef
atlasTypesDef
=
new
AtlasTypesDef
();
atlasTypesDef
.
getStructDefs
().
add
(
structDef
);
AtlasTypesDef
created
=
createAtlasTypeDefs
(
atlasTypesDef
);
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
();
typesDef
.
getStructDefs
().
add
(
structDef
);
AtlasTypesDef
created
=
createAtlasTypeDefs
(
typesDef
);
assert
created
!=
null
;
assert
created
.
getStructDefs
()
!=
null
;
return
created
.
getStructDefs
().
get
(
0
);
}
@Deprecated
public
AtlasEntityDef
createEntityDef
(
AtlasEntityDef
entityDef
)
throws
AtlasServiceException
{
AtlasTypesDef
atlasTypesDef
=
new
AtlasTypesDef
();
atlasTypesDef
.
getEntityDefs
().
add
(
entityDef
);
AtlasTypesDef
created
=
createAtlasTypeDefs
(
atlasTypesDef
);
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
();
typesDef
.
getEntityDefs
().
add
(
entityDef
);
AtlasTypesDef
created
=
createAtlasTypeDefs
(
typesDef
);
assert
created
!=
null
;
assert
created
.
getEntityDefs
()
!=
null
;
return
created
.
getEntityDefs
().
get
(
0
);
}
@Deprecated
public
AtlasClassificationDef
createClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
AtlasServiceException
{
AtlasTypesDef
atlasTypesDef
=
new
AtlasTypesDef
();
atlasTypesDef
.
getClassificationDefs
().
add
(
classificationDef
);
AtlasTypesDef
created
=
createAtlasTypeDefs
(
atlasTypesDef
);
public
AtlasClassificationDef
createClassificationDef
(
AtlasClassificationDef
classificationDef
)
throws
AtlasServiceException
{
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
();
typesDef
.
getClassificationDefs
().
add
(
classificationDef
);
AtlasTypesDef
created
=
createAtlasTypeDefs
(
typesDef
);
assert
created
!=
null
;
assert
created
.
getClassificationDefs
()
!=
null
;
return
created
.
getClassificationDefs
().
get
(
0
);
}
...
...
@@ -240,8 +319,8 @@ public class AtlasClientV2 extends AtlasBaseClient {
* @return A composite wrapper object with lists of type definitions that were successfully
* created
*/
public
AtlasTypesDef
createAtlasTypeDefs
(
final
AtlasTypesDef
typesDef
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_
ALL_
TYPE_DEFS
,
AtlasTypesDef
.
class
,
AtlasType
.
toJson
(
typesDef
));
public
AtlasTypesDef
createAtlasTypeDefs
(
AtlasTypesDef
typesDef
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_TYPE_DEFS
,
AtlasTypesDef
.
class
,
AtlasType
.
toJson
(
typesDef
));
}
/**
...
...
@@ -250,8 +329,8 @@ public class AtlasClientV2 extends AtlasBaseClient {
* @param typesDef A composite object that captures all type definition changes
* @return A composite object with lists of type definitions that were updated
*/
public
AtlasTypesDef
updateAtlasTypeDefs
(
final
AtlasTypesDef
typesDef
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
UPDATE_
ALL_
TYPE_DEFS
,
AtlasTypesDef
.
class
,
AtlasType
.
toJson
(
typesDef
));
public
AtlasTypesDef
updateAtlasTypeDefs
(
AtlasTypesDef
typesDef
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
UPDATE_TYPE_DEFS
,
AtlasTypesDef
.
class
,
AtlasType
.
toJson
(
typesDef
));
}
/**
...
...
@@ -259,26 +338,16 @@ public class AtlasClientV2 extends AtlasBaseClient {
*
* @param typesDef A composite object that captures all types to be deleted
*/
public
void
deleteAtlasTypeDefs
(
final
AtlasTypesDef
typesDef
)
throws
AtlasServiceException
{
callAPI
(
API_V2
.
DELETE_
ALL_
TYPE_DEFS
,
(
Class
<?>)
null
,
AtlasType
.
toJson
(
typesDef
));
public
void
deleteAtlasTypeDefs
(
AtlasTypesDef
typesDef
)
throws
AtlasServiceException
{
callAPI
(
API_V2
.
DELETE_TYPE_DEFS
,
(
Class
<?>)
null
,
AtlasType
.
toJson
(
typesDef
));
}
public
AtlasLineageInfo
getLineageInfo
(
final
String
guid
,
final
LineageDirection
direction
,
final
int
depth
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"direction"
,
direction
.
toString
());
queryParams
.
add
(
"depth"
,
String
.
valueOf
(
depth
));
return
callAPI
(
API_V2
.
LINEAGE_INFO
,
AtlasLineageInfo
.
class
,
queryParams
,
guid
);
public
void
deleteTypeByName
(
String
typeName
)
throws
AtlasServiceException
{
callAPI
(
API_V2
.
DELETE_TYPE_DEF_BY_NAME
,
(
Class
)
null
,
null
,
typeName
);
}
public
AtlasLineageInfo
getLineageInfo
(
String
type
,
Map
<
String
,
String
>
attributes
,
final
LineageDirection
direction
,
final
int
depth
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
attributes
);
queryParams
.
add
(
"direction"
,
direction
.
toString
());
queryParams
.
add
(
"depth"
,
String
.
valueOf
(
depth
));
return
callAPI
(
API_V2
.
GET_LINEAGE_BY_ATTRIBUTES
,
AtlasLineageInfo
.
class
,
queryParams
,
type
);
}
// Entity APIs
public
AtlasEntityWithExtInfo
getEntityByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
getEntityByGuid
(
guid
,
false
,
false
);
}
...
...
@@ -292,82 +361,108 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
callAPI
(
API_V2
.
GET_ENTITY_BY_GUID
,
AtlasEntityWithExtInfo
.
class
,
queryParams
,
guid
);
}
public
AtlasEntityWithExtInfo
getEntityByAttribute
(
String
type
,
Map
<
String
,
String
>
uniqAttributes
)
throws
AtlasServiceException
{
return
getEntityByAttribute
(
type
,
uniqAttributes
,
false
,
false
);
public
AtlasEntityWithExtInfo
getEntityByAttribute
(
String
type
Name
,
Map
<
String
,
String
>
uniqAttributes
)
throws
AtlasServiceException
{
return
getEntityByAttribute
(
type
Name
,
uniqAttributes
,
false
,
false
);
}
public
AtlasEntityWithExtInfo
getEntityByAttribute
(
String
type
,
Map
<
String
,
String
>
uniqAttributes
,
boolean
minExtInfo
,
boolean
ignoreRelationship
)
throws
AtlasServiceException
{
public
AtlasEntityWithExtInfo
getEntityByAttribute
(
String
type
Name
,
Map
<
String
,
String
>
uniqAttributes
,
boolean
minExtInfo
,
boolean
ignoreRelationship
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
queryParams
.
add
(
"minExtInfo"
,
String
.
valueOf
(
minExtInfo
));
queryParams
.
add
(
"ignoreRelationships"
,
String
.
valueOf
(
ignoreRelationship
));
return
callAPI
(
API_V2
.
GET_ENTITY_BY_ATTRIBUTE
,
AtlasEntityWithExtInfo
.
class
,
queryParams
,
type
);
return
callAPI
(
API_V2
.
GET_ENTITY_BY_UNIQUE_ATTRIBUTE
,
AtlasEntityWithExtInfo
.
class
,
queryParams
,
typeName
);
}
public
AtlasEntitiesWithExtInfo
getEntitiesByGuids
(
List
<
String
>
guids
)
throws
AtlasServiceException
{
return
getEntitiesByGuids
(
guids
,
false
,
false
);
}
public
AtlasEntitiesWithExtInfo
getEntitiesByGuids
(
List
<
String
>
guids
,
boolean
minExtInfo
,
boolean
ignoreRelationships
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
put
(
"guid"
,
guids
);
queryParams
.
add
(
"minExtInfo"
,
String
.
valueOf
(
minExtInfo
));
queryParams
.
add
(
"ignoreRelationships"
,
String
.
valueOf
(
ignoreRelationships
));
return
callAPI
(
API_V2
.
GET_ENTITIES_BY_GUIDS
,
AtlasEntitiesWithExtInfo
.
class
,
queryParams
);
}
public
AtlasEntitiesWithExtInfo
getEntitiesByAttribute
(
String
type
,
List
<
Map
<
String
,
String
>>
uniqAttributesList
)
throws
AtlasServiceException
{
return
getEntitiesByAttribute
(
type
,
uniqAttributesList
,
false
,
false
);
public
AtlasEntitiesWithExtInfo
getEntitiesByAttribute
(
String
type
Name
,
List
<
Map
<
String
,
String
>>
uniqAttributesList
)
throws
AtlasServiceException
{
return
getEntitiesByAttribute
(
type
Name
,
uniqAttributesList
,
false
,
false
);
}
public
AtlasEntitiesWithExtInfo
getEntitiesByAttribute
(
String
type
,
List
<
Map
<
String
,
String
>>
uniqAttributesList
,
boolean
minExtInfo
,
boolean
ignoreRelationship
)
throws
AtlasServiceException
{
public
AtlasEntitiesWithExtInfo
getEntitiesByAttribute
(
String
type
Name
,
List
<
Map
<
String
,
String
>>
uniqAttributesList
,
boolean
minExtInfo
,
boolean
ignoreRelationship
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributesList
,
null
);
queryParams
.
add
(
"minExtInfo"
,
String
.
valueOf
(
minExtInfo
));
queryParams
.
add
(
"ignoreRelationships"
,
String
.
valueOf
(
ignoreRelationship
));
return
callAPI
(
API_V2
.
GET_ENTITIES_BY_
ATTRIBUTES
,
AtlasEntitiesWithExtInfo
.
class
,
queryParams
,
typ
e
);
return
callAPI
(
API_V2
.
GET_ENTITIES_BY_
UNIQUE_ATTRIBUTE
,
AtlasEntitiesWithExtInfo
.
class
,
queryParams
,
typeNam
e
);
}
public
AtlasEntityHeader
getEntityHeaderByGuid
(
String
entityGuid
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_ENTITY_HEADER_BY_GUID
,
entityGuid
),
AtlasEntityHeader
.
class
,
null
);
}
public
EntityMutationResponse
updateEntityByAttribute
(
String
type
,
Map
<
String
,
String
>
uniqAttributes
,
AtlasEntityWithExtInfo
entityInfo
)
throws
AtlasServiceException
{
public
AtlasEntityHeader
getEntityHeaderByAttribute
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
return
callAPI
(
API_V2
.
UPDATE_ENTITY_BY_ATTRIBUTE
,
EntityMutationResponse
.
class
,
entityInfo
,
queryParams
,
type
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_ENTITY_HEADER_BY_UNIQUE_ATTRIBUTE
,
typeName
),
AtlasEntityHeader
.
class
,
queryParams
);
}
/* Lineage Calls */
public
List
<
EntityAuditEventV2
>
getAuditEvents
(
String
guid
,
String
startKey
,
EntityAuditEventV2
.
EntityAuditActionV2
auditAction
,
short
count
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
public
EntityMutationResponse
deleteEntityByAttribute
(
String
type
,
Map
<
String
,
String
>
uniqAttributes
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
queryParams
.
add
(
"startKey"
,
startKey
);
return
callAPI
(
API_V2
.
DELETE_ENTITY_BY_ATTRIBUTE
,
EntityMutationResponse
.
class
,
queryParams
,
type
);
if
(
auditAction
!=
null
)
{
queryParams
.
add
(
"auditAction"
,
auditAction
.
toString
());
}
/* Entity Calls */
queryParams
.
add
(
"count"
,
String
.
valueOf
(
count
));
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_AUDIT_EVENTS
,
guid
),
List
.
class
,
queryParams
);
}
public
EntityMutationResponse
createEntity
(
AtlasEntityWithExtInfo
entity
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_ENTITY
,
EntityMutationResponse
.
class
,
entity
);
}
public
EntityMutationResponse
createEntities
(
AtlasEntitiesWithExtInfo
atlasEntities
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_ENTITIES
,
EntityMutationResponse
.
class
,
atlasEntities
);
}
public
EntityMutationResponse
updateEntity
(
AtlasEntityWithExtInfo
entity
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
UPDATE_ENTITY
,
EntityMutationResponse
.
class
,
entity
);
}
public
EntityMutationResponse
deleteEntityByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
DELETE_ENTITY_BY_GUID
,
EntityMutationResponse
.
class
,
null
,
guid
);
public
EntityMutationResponse
updateEntities
(
AtlasEntitiesWithExtInfo
atlasEntities
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
UPDATE_ENTITIES
,
EntityMutationResponse
.
class
,
atlasEntities
);
}
public
AtlasEntitiesWithExtInfo
getEntitiesByGuids
(
List
<
String
>
guids
)
throws
AtlasServiceException
{
return
getEntitiesByGuids
(
guids
,
false
,
false
);
public
EntityMutationResponse
updateEntityByAttribute
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
,
AtlasEntityWithExtInfo
entityInfo
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
return
callAPI
(
API_V2
.
UPDATE_ENTITY_BY_ATTRIBUTE
,
EntityMutationResponse
.
class
,
entityInfo
,
queryParams
,
typeName
);
}
public
AtlasEntitiesWithExtInfo
getEntitiesByGuids
(
List
<
String
>
guids
,
boolean
minExtInfo
,
boolean
ignoreRelationships
)
throws
AtlasServiceException
{
public
EntityMutationResponse
partialUpdateEntityByGuid
(
String
entityGuid
,
Object
attrValue
,
String
attrName
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
put
(
"guid"
,
guids
);
queryParams
.
add
(
"minExtInfo"
,
String
.
valueOf
(
minExtInfo
));
queryParams
.
add
(
"ignoreRelationships"
,
String
.
valueOf
(
ignoreRelationships
));
queryParams
.
add
(
"name"
,
attrName
);
return
callAPI
(
API_V2
.
GET_ENTITIES_BY_GUIDS
,
AtlasEntitiesWithExtInfo
.
class
,
queryParams
);
return
callAPI
(
formatPathParameters
(
API_V2
.
PARTIAL_UPDATE_ENTITY_BY_GUID
,
entityGuid
),
EntityMutationResponse
.
class
,
attrValue
,
queryParams
);
}
public
EntityMutationResponse
createEntities
(
AtlasEntitiesWithExtInfo
atlasEntities
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_ENTITIES
,
EntityMutationResponse
.
class
,
atlasEntities
);
public
EntityMutationResponse
deleteEntityByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
DELETE_ENTITY_BY_GUID
,
EntityMutationResponse
.
class
,
null
,
guid
);
}
public
EntityMutationResponse
updateEntities
(
AtlasEntitiesWithExtInfo
atlasEntities
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
UPDATE_ENTITIES
,
EntityMutationResponse
.
class
,
atlasEntities
);
public
EntityMutationResponse
deleteEntityByAttribute
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
return
callAPI
(
API_V2
.
DELETE_ENTITY_BY_ATTRIBUTE
,
EntityMutationResponse
.
class
,
queryParams
,
typeName
);
}
public
EntityMutationResponse
deleteEntitiesByGuids
(
List
<
String
>
guids
)
throws
AtlasServiceException
{
...
...
@@ -378,49 +473,171 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
callAPI
(
API_V2
.
PURGE_ENTITIES_BY_GUIDS
,
EntityMutationResponse
.
class
,
guids
);
}
// Entity-classification APIs
public
AtlasClassifications
getClassifications
(
String
guid
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_CLASSIFICATIONS
,
guid
),
AtlasClassifications
.
class
,
null
);
}
public
AtlasClassifications
getEntityClassifications
(
String
entityGuid
,
String
classificationName
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_FROM_CLASSIFICATION
,
entityGuid
,
classificationName
),
AtlasClassifications
.
class
,
null
);
}
public
void
addClassification
(
ClassificationAssociateRequest
request
)
throws
AtlasServiceException
{
callAPI
(
API_V2
.
ADD_CLASSIFICATION
,
(
Class
<?>)
null
,
request
);
}
public
void
addClassifications
(
String
guid
,
List
<
AtlasClassification
>
classifications
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
ADD_CLASSIFICATIONS
,
guid
),
(
Class
<?>)
null
,
classifications
,
(
String
[])
null
);
}
public
void
addClassifications
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
,
List
<
AtlasClassification
>
classifications
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
callAPI
(
formatPathParameters
(
API_V2
.
ADD_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE
,
typeName
),
(
Class
<?>)
null
,
classifications
,
queryParams
);
}
public
void
updateClassifications
(
String
guid
,
List
<
AtlasClassification
>
classifications
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
UPDATE_CLASSIFICATIONS
,
guid
),
(
Class
<?>)
null
,
classifications
);
}
public
void
deleteClassifications
(
String
guid
,
List
<
AtlasClassification
>
classifications
)
throws
AtlasServiceException
{
for
(
AtlasClassification
c
:
classifications
)
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_CLASSIFICATION
,
guid
,
c
.
getTypeName
()),
AtlasClassifications
.
class
,
classifications
);
public
void
updateClassifications
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
,
List
<
AtlasClassification
>
classifications
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
callAPI
(
formatPathParameters
(
API_V2
.
UPDATE_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE
,
typeName
),
(
Class
<?>)
null
,
classifications
,
queryParams
);
}
public
String
setClassifications
(
AtlasEntityHeaders
entityHeaders
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
UPDATE_BULK_SET_CLASSIFICATIONS
,
String
.
class
,
entityHeaders
);
}
public
void
deleteClassification
(
String
guid
,
String
classificationName
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_CLASSIFICATION
,
guid
,
classificationName
),
null
,
null
);
}
public
void
deleteClassifications
(
String
guid
,
List
<
AtlasClassification
>
classifications
)
throws
AtlasServiceException
{
for
(
AtlasClassification
c
:
classifications
)
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_CLASSIFICATION
,
guid
,
c
.
getTypeName
()),
null
,
null
);
}
}
public
void
removeClassification
(
String
entityGuid
,
String
classificationName
,
String
associatedEntityGuid
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_CLASSIFICATION
,
entityGuid
,
classificationName
),
(
Class
<?>)
null
,
associatedEntityGuid
);
}
public
void
removeClassification
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
,
String
classificationName
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE
,
typeName
,
classificationName
),
(
Class
<?>)
null
,
queryParams
);
}
public
AtlasEntityHeaders
getEntityHeaders
(
long
tagUpdateStartTime
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"tagUpdateStartTime"
,
Long
.
toString
(
tagUpdateStartTime
));
return
callAPI
(
API_V2
.
GET_BULK_HEADERS
,
AtlasEntityHeaders
.
class
,
queryParams
);
}
public
String
setClassifications
(
AtlasEntityHeaders
entityHeaders
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
UPDATE_BULK_SET_CLASSIFICATIONS
,
String
.
class
,
entityHeaders
);
// Business attributes APIs
public
void
addOrUpdateBusinessAttributes
(
String
entityGuid
,
boolean
isOverwrite
,
Map
<
String
,
Map
<
String
,
Object
>>
businessAttributes
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"isOverwrite"
,
String
.
valueOf
(
isOverwrite
));
callAPI
(
formatPathParameters
(
API_V2
.
ADD_BUSINESS_ATTRIBUTE
,
entityGuid
),
(
Class
<?>)
null
,
businessAttributes
,
queryParams
);
}
public
void
addOrUpdateBusinessAttributes
(
String
entityGuid
,
String
bmName
,
Map
<
String
,
Map
<
String
,
Object
>>
businessAttributes
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
ADD_BUSINESS_ATTRIBUTE_BY_NAME
,
entityGuid
,
bmName
),
(
Class
<?>)
null
,
businessAttributes
);
}
public
void
removeBusinessAttributes
(
String
entityGuid
,
Map
<
String
,
Map
<
String
,
Object
>>
businessAttributes
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_BUSINESS_ATTRIBUTE
,
entityGuid
),
(
Class
<?>)
null
,
businessAttributes
);
}
public
void
removeBusinessAttributes
(
String
entityGuid
,
String
bmName
,
Map
<
String
,
Map
<
String
,
Object
>>
businessAttributes
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_BUSINESS_ATTRIBUTE_BY_NAME
,
entityGuid
,
bmName
),
(
Class
<?>)
null
,
businessAttributes
);
}
public
String
getTemplateForBulkUpdateBusinessAttributes
()
throws
AtlasServiceException
{
InputStream
inputStream
=
(
InputStream
)
callAPI
(
API_V2
.
GET_BUSINESS_METADATA_TEMPLATE
,
Object
.
class
,
null
);
return
readStreamContents
(
inputStream
);
}
public
BulkImportResponse
bulkUpdateBusinessAttributes
(
String
fileName
)
throws
AtlasServiceException
{
MultiPart
multipartEntity
=
getMultiPartData
(
fileName
);
return
callAPI
(
API_V2
.
IMPORT_BUSINESS_METADATA
,
BulkImportResponse
.
class
,
multipartEntity
);
}
// Labels APIs
public
void
addLabels
(
String
entityGuid
,
Set
<
String
>
labels
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
ADD_LABELS
,
entityGuid
),
(
Class
<?>)
null
,
labels
,
(
String
[])
null
);
}
public
void
addLabels
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
,
Set
<
String
>
labels
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
callAPI
(
formatPathParameters
(
API_V2
.
SET_LABELS_BY_UNIQUE_ATTRIBUTE
,
typeName
),
(
Class
<?>)
null
,
labels
,
queryParams
);
}
public
void
removeLabels
(
String
entityGuid
,
Set
<
String
>
labels
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_LABELS
,
entityGuid
),
(
Class
<?>)
null
,
labels
);
}
public
void
removeLabels
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
,
Set
<
String
>
labels
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_LABELS_BY_UNIQUE_ATTRIBUTE
,
typeName
),
(
Class
<?>)
null
,
labels
,
queryParams
);
}
public
void
setLabels
(
String
entityGuid
,
Set
<
String
>
labels
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
SET_LABELS
,
entityGuid
),
(
Class
<?>)
null
,
labels
,
(
String
[])
null
);
}
public
void
setLabels
(
String
typeName
,
Map
<
String
,
String
>
uniqAttributes
,
Set
<
String
>
labels
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
uniqAttributes
);
callAPI
(
formatPathParameters
(
API_V2
.
ADD_LABELS_BY_UNIQUE_ATTRIBUTE
,
typeName
),
(
Class
<?>)
null
,
labels
,
queryParams
);
}
/* Discovery calls */
public
AtlasSearchResult
dslSearch
(
final
String
query
)
throws
AtlasServiceException
{
/* Lineage APIs */
public
AtlasLineageInfo
getLineageInfo
(
String
guid
,
LineageDirection
direction
,
int
depth
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"direction"
,
direction
.
toString
());
queryParams
.
add
(
"depth"
,
String
.
valueOf
(
depth
));
return
callAPI
(
API_V2
.
LINEAGE_INFO
,
AtlasLineageInfo
.
class
,
queryParams
,
guid
);
}
public
AtlasLineageInfo
getLineageInfo
(
String
typeName
,
Map
<
String
,
String
>
attributes
,
LineageDirection
direction
,
int
depth
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
attributesToQueryParams
(
attributes
);
queryParams
.
add
(
"direction"
,
direction
.
toString
());
queryParams
.
add
(
"depth"
,
String
.
valueOf
(
depth
));
return
callAPI
(
API_V2
.
GET_LINEAGE_BY_ATTRIBUTES
,
AtlasLineageInfo
.
class
,
queryParams
,
typeName
);
}
/* Discovery APIs */
public
AtlasSearchResult
dslSearch
(
String
query
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
QUERY
,
query
);
return
callAPI
(
API_V2
.
DSL_SEARCH
,
AtlasSearchResult
.
class
,
queryParams
);
}
public
AtlasSearchResult
dslSearchWithParams
(
final
String
query
,
final
int
limit
,
final
int
offset
)
throws
AtlasServiceException
{
public
AtlasSearchResult
dslSearchWithParams
(
String
query
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
QUERY
,
query
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
...
...
@@ -428,15 +645,17 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
callAPI
(
API_V2
.
DSL_SEARCH
,
AtlasSearchResult
.
class
,
queryParams
);
}
public
AtlasSearchResult
fullTextSearch
(
final
String
query
)
throws
AtlasServiceException
{
public
AtlasSearchResult
fullTextSearch
(
String
query
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
QUERY
,
query
);
return
callAPI
(
API_V2
.
FULL_TEXT_SEARCH
,
AtlasSearchResult
.
class
,
queryParams
);
}
public
AtlasSearchResult
fullTextSearchWithParams
(
final
String
query
,
final
int
limit
,
final
int
offset
)
throws
AtlasServiceException
{
public
AtlasSearchResult
fullTextSearchWithParams
(
String
query
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
QUERY
,
query
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
...
...
@@ -444,9 +663,9 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
callAPI
(
API_V2
.
FULL_TEXT_SEARCH
,
AtlasSearchResult
.
class
,
queryParams
);
}
public
AtlasSearchResult
basicSearch
(
final
String
typeName
,
final
String
classification
,
final
String
query
,
final
boolean
excludeDeletedEntities
,
final
int
limit
,
final
int
offset
)
throws
AtlasServiceException
{
public
AtlasSearchResult
basicSearch
(
String
typeName
,
String
classification
,
String
query
,
boolean
excludeDeletedEntities
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"typeName"
,
typeName
);
queryParams
.
add
(
"classification"
,
classification
);
queryParams
.
add
(
QUERY
,
query
);
...
...
@@ -461,6 +680,109 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
callAPI
(
API_V2
.
FACETED_SEARCH
,
AtlasSearchResult
.
class
,
searchParameters
);
}
public
AtlasSearchResult
attributeSearch
(
String
typeName
,
String
attrName
,
String
attrValuePrefix
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"attrName"
,
attrName
);
queryParams
.
add
(
"attrValuePrefix"
,
attrValuePrefix
);
queryParams
.
add
(
"typeName"
,
typeName
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
return
callAPI
(
API_V2
.
ATTRIBUTE_SEARCH
,
AtlasSearchResult
.
class
,
queryParams
);
}
public
AtlasSearchResult
relationshipSearch
(
String
guid
,
String
relation
,
String
sortByAttribute
,
SortOrder
sortOrder
,
boolean
excludeDeletedEntities
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"guid"
,
guid
);
queryParams
.
add
(
"relation"
,
relation
);
queryParams
.
add
(
"sortBy"
,
sortByAttribute
);
if
(
sortOrder
!=
null
)
{
queryParams
.
add
(
"sortOrder"
,
String
.
valueOf
(
sortOrder
));
}
queryParams
.
add
(
"excludeDeletedEntities"
,
String
.
valueOf
(
excludeDeletedEntities
));
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
return
callAPI
(
API_V2
.
RELATIONSHIP_SEARCH
,
AtlasSearchResult
.
class
,
queryParams
);
}
public
AtlasQuickSearchResult
quickSearch
(
String
query
,
String
typeName
,
boolean
excludeDeletedEntities
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"query"
,
query
);
queryParams
.
add
(
"typeName"
,
typeName
);
queryParams
.
add
(
"excludeDeletedEntities"
,
String
.
valueOf
(
excludeDeletedEntities
));
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
return
callAPI
(
API_V2
.
QUICK_SEARCH_WITH_GET
,
AtlasQuickSearchResult
.
class
,
queryParams
);
}
public
AtlasQuickSearchResult
quickSearch
(
QuickSearchParameters
quickSearchParameters
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
QUICK_SEARCH_WITH_POST
,
AtlasQuickSearchResult
.
class
,
quickSearchParameters
);
}
// fieldName should be the parameter on which indexing is enabled such as "qualifiedName"
public
AtlasSuggestionsResult
getSuggestions
(
String
prefixString
,
String
fieldName
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
if
(
StringUtils
.
isNotEmpty
(
prefixString
))
{
queryParams
.
add
(
"prefixString"
,
prefixString
);
}
if
(
StringUtils
.
isNotEmpty
(
fieldName
))
{
queryParams
.
add
(
"fieldName"
,
fieldName
);
}
return
callAPI
(
API_V2
.
GET_SUGGESTIONS
,
AtlasSuggestionsResult
.
class
,
queryParams
);
}
public
List
<
AtlasUserSavedSearch
>
getSavedSearches
(
String
userName
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"user"
,
userName
);
return
callAPI
(
API_V2
.
GET_SAVED_SEARCHES
,
List
.
class
,
queryParams
);
}
public
AtlasUserSavedSearch
getSavedSearch
(
String
userName
,
String
searchName
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"user"
,
userName
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_SAVED_SEARCH
,
searchName
),
AtlasUserSavedSearch
.
class
,
queryParams
);
}
public
AtlasUserSavedSearch
addSavedSearch
(
AtlasUserSavedSearch
savedSearch
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
ADD_SAVED_SEARCH
,
AtlasUserSavedSearch
.
class
,
savedSearch
);
}
public
AtlasUserSavedSearch
updateSavedSearch
(
AtlasUserSavedSearch
savedSearch
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
UPDATE_SAVED_SEARCH
,
AtlasUserSavedSearch
.
class
,
savedSearch
);
}
public
void
deleteSavedSearch
(
String
guid
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_SAVED_SEARCH
,
guid
),
(
Class
<?>)
null
,
null
);
}
public
AtlasSearchResult
executeSavedSearch
(
String
userName
,
String
searchName
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"user"
,
userName
);
return
callAPI
(
formatPathParameters
(
API_V2
.
EXECUTE_SAVED_SEARCH_BY_NAME
,
searchName
),
AtlasSearchResult
.
class
,
queryParams
);
}
public
AtlasSearchResult
executeSavedSearch
(
String
searchGuid
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
EXECUTE_SAVED_SEARCH_BY_GUID
,
searchGuid
),
AtlasSearchResult
.
class
,
null
);
}
// Relationship APIs
public
AtlasRelationshipWithExtInfo
getRelationshipByGuid
(
String
guid
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
GET_RELATIONSHIP_BY_GUID
,
AtlasRelationshipWithExtInfo
.
class
,
null
,
guid
);
}
...
...
@@ -473,10 +795,6 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
callAPI
(
API_V2
.
GET_RELATIONSHIP_BY_GUID
,
AtlasRelationshipWithExtInfo
.
class
,
queryParams
,
guid
);
}
public
void
deleteRelationshipByGuid
(
String
guid
)
throws
AtlasServiceException
{
callAPI
(
API_V2
.
DELETE_RELATIONSHIP_BY_GUID
,
(
Class
)
null
,
null
,
guid
);
}
public
AtlasRelationship
createRelationship
(
AtlasRelationship
relationship
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_RELATIONSHIP
,
AtlasRelationship
.
class
,
relationship
);
}
...
...
@@ -485,7 +803,13 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
callAPI
(
API_V2
.
UPDATE_RELATIONSHIP
,
AtlasRelationship
.
class
,
relationship
);
}
public
List
<
AtlasAuditEntry
>
getAtlasAuditByOperation
(
final
AuditSearchParameters
auditSearchParameters
)
throws
AtlasServiceException
{
public
void
deleteRelationshipByGuid
(
String
guid
)
throws
AtlasServiceException
{
callAPI
(
API_V2
.
DELETE_RELATIONSHIP_BY_GUID
,
(
Class
)
null
,
null
,
guid
);
}
// Admin APIs
public
List
<
AtlasAuditEntry
>
getAtlasAuditByOperation
(
AuditSearchParameters
auditSearchParameters
)
throws
AtlasServiceException
{
ArrayNode
response
=
callAPI
(
API_V2
.
GET_ATLAS_AUDITS
,
ArrayNode
.
class
,
auditSearchParameters
);
return
extractResults
(
response
,
new
ExtractOperation
<
AtlasAuditEntry
,
ObjectNode
>()
{
...
...
@@ -496,24 +820,251 @@ public class AtlasClientV2 extends AtlasBaseClient {
});
}
// Glossary APIs
public
List
<
AtlasGlossary
>
getAllGlossaries
(
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"sort"
,
sortByAttribute
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
return
callAPI
(
API_V2
.
GET_ALL_GLOSSARIES
,
List
.
class
,
queryParams
);
}
public
AtlasGlossary
getGlossaryByGuid
(
String
glossaryGuid
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_GLOSSARY_BY_GUID
,
glossaryGuid
),
AtlasGlossary
.
class
,
null
);
}
public
AtlasGlossary
.
AtlasGlossaryExtInfo
getGlossaryExtInfo
(
String
glossaryGuid
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_DETAILED_GLOSSARY
,
glossaryGuid
),
AtlasGlossary
.
AtlasGlossaryExtInfo
.
class
,
null
);
}
public
AtlasGlossaryTerm
getGlossaryTerm
(
String
termGuid
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
GET_GLOSSARY_TERM
,
AtlasGlossaryTerm
.
class
,
null
,
termGuid
);
}
public
List
<
AtlasGlossaryTerm
>
getGlossaryTerms
(
String
glossaryGuid
,
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"glossaryGuid"
,
glossaryGuid
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
queryParams
.
add
(
"sort"
,
sortByAttribute
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_GLOSSARY_TERMS
,
glossaryGuid
),
List
.
class
,
queryParams
);
}
public
List
<
AtlasRelatedTermHeader
>
getGlossaryTermHeaders
(
String
glossaryGuid
,
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"glossaryGuid"
,
glossaryGuid
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
queryParams
.
add
(
"sort"
,
sortByAttribute
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_GLOSSARY_TERMS_HEADERS
,
glossaryGuid
),
List
.
class
,
queryParams
);
}
public
AtlasGlossaryCategory
getGlossaryCategory
(
String
categoryGuid
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
GET_GLOSSARY_CATEGORY
,
AtlasGlossaryCategory
.
class
,
null
,
categoryGuid
);
}
public
List
<
AtlasGlossaryCategory
>
getGlossaryCategories
(
String
glossaryGuid
,
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"glossaryGuid"
,
glossaryGuid
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
queryParams
.
add
(
"sort"
,
sortByAttribute
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_GLOSSARY_CATEGORIES
,
glossaryGuid
),
List
.
class
,
queryParams
);
}
public
List
<
AtlasRelatedCategoryHeader
>
getGlossaryCategoryHeaders
(
String
glossaryGuid
,
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"glossaryGuid"
,
glossaryGuid
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
queryParams
.
add
(
"sort"
,
sortByAttribute
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_GLOSSARY_CATEGORIES_HEADERS
,
glossaryGuid
),
List
.
class
,
queryParams
);
}
public
List
<
AtlasRelatedTermHeader
>
getCategoryTerms
(
String
categoryGuid
,
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"categoryGuid"
,
categoryGuid
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
queryParams
.
add
(
"sort"
,
sortByAttribute
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_CATEGORY_TERMS
,
categoryGuid
),
List
.
class
,
queryParams
);
}
public
Map
<
AtlasGlossaryTerm
.
Relation
,
Set
<
AtlasRelatedTermHeader
>>
getRelatedTerms
(
String
termGuid
,
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"termGuid"
,
termGuid
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
queryParams
.
add
(
"sort"
,
sortByAttribute
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_RELATED_TERMS
,
termGuid
),
Map
.
class
,
queryParams
);
}
public
Map
<
String
,
List
<
AtlasRelatedCategoryHeader
>>
getRelatedCategories
(
String
categoryGuid
,
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
queryParams
.
add
(
"sort"
,
sortByAttribute
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_RELATED_CATEGORIES
,
categoryGuid
),
Map
.
class
,
queryParams
);
}
public
AtlasGlossary
createGlossary
(
AtlasGlossary
glossary
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_GLOSSARY
,
AtlasGlossary
.
class
,
glossary
);
}
public
AtlasGlossaryTerm
createGlossaryTerm
(
AtlasGlossaryTerm
glossaryTerm
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_GLOSSARY_TERM
,
AtlasGlossaryTerm
.
class
,
glossaryTerm
);
}
public
List
<
AtlasGlossaryTerm
>
createGlossaryTerms
(
List
<
AtlasGlossaryTerm
>
glossaryTerms
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_GLOSSARY_TERMS
,
List
.
class
,
glossaryTerms
);
}
public
AtlasGlossaryCategory
createGlossaryCategory
(
AtlasGlossaryCategory
glossaryCategory
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_GLOSSARY_CATEGORY
,
AtlasGlossaryCategory
.
class
,
glossaryCategory
);
}
public
List
<
AtlasGlossaryCategory
>
createGlossaryCategories
(
List
<
AtlasGlossaryCategory
>
glossaryCategories
)
throws
AtlasServiceException
{
return
callAPI
(
API_V2
.
CREATE_GLOSSARY_CATEGORIES
,
List
.
class
,
glossaryCategories
);
}
public
AtlasGlossary
updateGlossaryByGuid
(
String
glossaryGuid
,
AtlasGlossary
updatedGlossary
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
UPDATE_GLOSSARY_BY_GUID
,
glossaryGuid
),
AtlasGlossary
.
class
,
updatedGlossary
);
}
public
AtlasGlossary
partialUpdateGlossaryByGuid
(
String
glossaryGuid
,
Map
<
String
,
String
>
attributes
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
UPDATE_PARTIAL_GLOSSARY
,
glossaryGuid
),
AtlasGlossary
.
class
,
attributes
);
}
public
AtlasGlossaryTerm
updateGlossaryTermByGuid
(
String
termGuid
,
AtlasGlossaryTerm
glossaryTerm
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
UPDATE_GLOSSARY_TERM
,
termGuid
),
AtlasGlossaryTerm
.
class
,
glossaryTerm
);
}
public
AtlasGlossaryTerm
partialUpdateTermByGuid
(
String
termGuid
,
Map
<
String
,
String
>
attributes
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
UPDATE_PARTIAL_TERM
,
termGuid
),
AtlasGlossaryTerm
.
class
,
attributes
);
}
public
AtlasGlossaryCategory
updateGlossaryCategoryByGuid
(
String
categoryGuid
,
AtlasGlossaryCategory
glossaryCategory
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
UPDATE_CATEGORY_BY_GUID
,
categoryGuid
),
AtlasGlossaryCategory
.
class
,
glossaryCategory
);
}
public
AtlasGlossaryCategory
partialUpdateCategoryByGuid
(
String
categoryGuid
,
Map
<
String
,
String
>
attributes
)
throws
AtlasServiceException
{
return
callAPI
(
formatPathParameters
(
API_V2
.
UPDATE_PARTIAL_CATEGORY
,
categoryGuid
),
AtlasGlossaryCategory
.
class
,
attributes
);
}
public
void
deleteGlossaryByGuid
(
String
glossaryGuid
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_GLOSSARY_BY_GUID
,
glossaryGuid
),
(
Class
<?>)
null
,
null
);
}
public
void
deleteGlossaryTermByGuid
(
String
termGuid
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_TERM_BY_GUID
,
termGuid
),
(
Class
<?>)
null
,
null
);
}
public
void
deleteGlossaryCategoryByGuid
(
String
categoryGuid
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DELETE_CATEGORY_BY_GUID
,
categoryGuid
),
(
Class
<?>)
null
,
null
);
}
public
List
<
AtlasRelatedObjectId
>
getEntitiesAssignedWithTerm
(
String
termGuid
,
String
sortByAttribute
,
int
limit
,
int
offset
)
throws
AtlasServiceException
{
MultivaluedMap
<
String
,
String
>
queryParams
=
new
MultivaluedMapImpl
();
queryParams
.
add
(
"termGuid"
,
termGuid
);
queryParams
.
add
(
LIMIT
,
String
.
valueOf
(
limit
));
queryParams
.
add
(
OFFSET
,
String
.
valueOf
(
offset
));
queryParams
.
add
(
"sort"
,
sortByAttribute
);
return
callAPI
(
formatPathParameters
(
API_V2
.
GET_ENTITIES_ASSIGNED_WITH_TERM
,
termGuid
),
List
.
class
,
queryParams
);
}
public
void
assignTermToEntities
(
String
termGuid
,
List
<
AtlasRelatedObjectId
>
relatedObjectIds
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
ASSIGN_TERM_TO_ENTITIES
,
termGuid
),
(
Class
<?>)
null
,
relatedObjectIds
);
}
public
void
disassociateTermFromEntities
(
String
termGuid
,
List
<
AtlasRelatedObjectId
>
relatedObjectIds
)
throws
AtlasServiceException
{
callAPI
(
formatPathParameters
(
API_V2
.
DISASSOCIATE_TERM_FROM_ENTITIES
,
termGuid
),
(
Class
<?>)
null
,
relatedObjectIds
);
}
public
String
getGlossaryImportTemplate
()
throws
AtlasServiceException
{
InputStream
inputStream
=
(
InputStream
)
callAPI
(
API_V2
.
GET_IMPORT_GLOSSARY_TEMPLATE
,
Object
.
class
,
null
);
return
readStreamContents
(
inputStream
);
}
public
List
<
AtlasGlossaryTerm
>
importGlossary
(
String
fileName
)
throws
AtlasServiceException
{
MultiPart
multipartEntity
=
getMultiPartData
(
fileName
);
return
callAPI
(
API_V2
.
IMPORT_GLOSSARY
,
List
.
class
,
multipartEntity
);
}
@Override
protected
API
formatPathParameters
(
final
API
api
,
final
String
...
params
)
{
protected
API
formatPathParameters
(
API
api
,
String
...
params
)
{
return
new
API
(
String
.
format
(
api
.
getPath
(),
params
),
api
.
getMethod
(),
api
.
getExpectedStatus
());
}
private
MultiPart
getMultiPartData
(
String
fileName
)
throws
AtlasServiceException
{
try
{
File
file
=
new
File
(
fileName
);
InputStream
inputStream
=
new
FileInputStream
(
file
);
final
FormDataContentDisposition
fd
=
FormDataContentDisposition
.
name
(
"file"
).
fileName
(
file
.
getName
()).
build
();
return
new
FormDataMultiPart
().
bodyPart
(
new
StreamDataBodyPart
(
"file"
,
inputStream
))
.
bodyPart
(
new
FormDataBodyPart
(
fd
,
"file"
));
}
catch
(
FileNotFoundException
e
)
{
throw
new
AtlasServiceException
(
e
);
}
}
private
class
ExtractOperation
<
T
,
U
>
{
T
extractElement
(
U
element
)
{
return
(
T
)
element
;
}
}
private
String
readStreamContents
(
InputStream
inputStream
)
throws
AtlasServiceException
{
try
{
//Converting InputStream to String
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
));
StringBuffer
sb
=
new
StringBuffer
();
String
template
;
while
((
template
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
template
);
}
return
sb
.
toString
();
}
catch
(
Exception
e
)
{
throw
new
AtlasServiceException
(
e
);
}
}
private
<
T
,
U
>
List
<
T
>
extractResults
(
ArrayNode
jsonResponse
,
ExtractOperation
<
T
,
U
>
extractInterafce
)
{
ArrayList
<
T
>
resultsList
=
new
ArrayList
<>();
ArrayList
<
T
>
ret
=
new
ArrayList
<>();
for
(
int
index
=
0
;
index
<
jsonResponse
.
size
();
index
++)
{
Object
element
=
jsonResponse
.
get
(
index
);
resultsList
.
add
(
extractInterafce
.
extractElement
((
U
)
element
));
ret
.
add
(
extractInterafce
.
extractElement
((
U
)
element
));
}
return
resultsList
;
return
ret
;
}
private
MultivaluedMap
<
String
,
String
>
attributesToQueryParams
(
Map
<
String
,
String
>
attributes
)
{
...
...
@@ -552,19 +1103,21 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
queryParams
;
}
private
<
T
>
T
getTypeDefByName
(
final
String
name
,
Class
<
T
>
typeDefClass
)
throws
AtlasServiceException
{
String
atlasPath
=
getAtlasPath
(
typeDefClass
);
API
api
=
new
API
(
String
.
format
(
GET_BY_NAME_TEMPLATE
,
atlasPath
,
name
),
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
private
<
T
>
T
getTypeDefByName
(
String
name
,
Class
<
T
>
typeDefClass
)
throws
AtlasServiceException
{
String
pathForType
=
getPathForType
(
typeDefClass
);
API
api
=
new
API
(
String
.
format
(
GET_BY_NAME_TEMPLATE
,
pathForType
,
name
),
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
return
callAPI
(
api
,
typeDefClass
,
null
);
}
private
<
T
>
T
getTypeDefByGuid
(
final
String
guid
,
Class
<
T
>
typeDefClass
)
throws
AtlasServiceException
{
String
atlasPath
=
getAtlasPath
(
typeDefClass
);
API
api
=
new
API
(
String
.
format
(
GET_BY_GUID_TEMPLATE
,
atlasPath
,
guid
),
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
private
<
T
>
T
getTypeDefByGuid
(
String
guid
,
Class
<
T
>
typeDefClass
)
throws
AtlasServiceException
{
String
pathForType
=
getPathForType
(
typeDefClass
);
API
api
=
new
API
(
String
.
format
(
GET_BY_GUID_TEMPLATE
,
pathForType
,
guid
),
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
return
callAPI
(
api
,
typeDefClass
,
null
);
}
private
<
T
>
String
get
AtlasPath
(
Class
<
T
>
typeDefClass
)
{
private
<
T
>
String
get
PathForType
(
Class
<
T
>
typeDefClass
)
{
if
(
AtlasEnumDef
.
class
.
isAssignableFrom
(
typeDefClass
))
{
return
"enumdef"
;
}
else
if
(
AtlasEntityDef
.
class
.
isAssignableFrom
(
typeDefClass
))
{
...
...
@@ -573,51 +1126,145 @@ public class AtlasClientV2 extends AtlasBaseClient {
return
"classificationdef"
;
}
else
if
(
AtlasStructDef
.
class
.
isAssignableFrom
(
typeDefClass
))
{
return
"structdef"
;
}
else
if
(
AtlasRelationshipDef
.
class
.
isAssignableFrom
(
typeDefClass
))
{
return
"relationshipdef"
;
}
else
if
(
AtlasBusinessMetadataDef
.
class
.
isAssignableFrom
(
typeDefClass
))
{
return
"businessmetadatadef"
;
}
// Code should never reach this point
return
""
;
}
public
static
class
API_V2
extends
API
{
// TypeDef APIs
public
static
final
API_V2
GET_TYPEDEF_BY_NAME
=
new
API_V2
(
TYPEDEF_BY_NAME
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_TYPEDEF_BY_GUID
=
new
API_V2
(
TYPEDEF_BY_GUID
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ALL_TYPE_DEFS
=
new
API_V2
(
TYPEDEFS_API
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_ALL_TYPE_DEFS
=
new
API_V2
(
TYPEDEFS_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_ALL_TYPE_DEFS
=
new
API_V2
(
TYPEDEFS_API
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_ALL_TYPE_DEFS
=
new
API_V2
(
TYPEDEFS_API
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
GET_ALL_TYPE_DEF_HEADERS
=
new
API_V2
(
TYPEDEFS_API
+
"headers"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_TYPE_DEFS
=
new
API_V2
(
TYPEDEFS_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_TYPE_DEFS
=
new
API_V2
(
TYPEDEFS_API
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_TYPE_DEFS
=
new
API_V2
(
TYPEDEFS_API
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DELETE_TYPE_DEF_BY_NAME
=
new
API_V2
(
TYPEDEF_BY_NAME
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
// Entity APIs
public
static
final
API_V2
GET_ENTITY_BY_GUID
=
new
API_V2
(
ENTITY_API
+
"guid/"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ENTITY_BY_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ENTITY_BY_UNIQUE_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ENTITIES_BY_GUIDS
=
new
API_V2
(
ENTITY_BULK_API
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ENTITIES_BY_UNIQUE_ATTRIBUTE
=
new
API_V2
(
ENTITY_BULK_API
+
"uniqueAttribute/type/"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ENTITY_HEADER_BY_GUID
=
new
API_V2
(
ENTITY_API
+
"guid/%s/header"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ENTITY_HEADER_BY_UNIQUE_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/%s/header"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_AUDIT_EVENTS
=
new
API_V2
(
ENTITY_API
+
"%s/audit"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_ENTITY
=
new
API_V2
(
ENTITY_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_ENTITIES
=
new
API_V2
(
ENTITY_BULK_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_ENTITY
=
new
API_V2
(
ENTITY_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_ENTITY_BY_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/"
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_ENTITIES
=
new
API_V2
(
ENTITY_BULK_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
PARTIAL_UPDATE_ENTITY_BY_GUID
=
new
API_V2
(
ENTITY_API
+
"guid/%s"
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_ENTITY_BY_GUID
=
new
API_V2
(
ENTITY_API
+
"guid/"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_ENTITY_BY_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ENTITIES_BY_ATTRIBUTES
=
new
API_V2
(
ENTITY_BULK_API
+
"uniqueAttribute/type/"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_ENTITIES_BY_GUIDS
=
new
API_V2
(
ENTITY_BULK_API
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_ENTITIES
=
new
API_V2
(
ENTITY_BULK_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_ENTITIES
=
new
API_V2
(
ENTITY_BULK_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_ENTITIES_BY_GUIDS
=
new
API_V2
(
ENTITY_BULK_API
,
HttpMethod
.
DELETE
,
Response
.
Status
.
OK
);
public
static
final
API_V2
PURGE_ENTITIES_BY_GUIDS
=
new
API_V2
(
ENTITY_PURGE_API
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
// Entity-classification APIs
public
static
final
API_V2
GET_CLASSIFICATIONS
=
new
API_V2
(
ENTITY_API
+
"guid/%s/classifications"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_FROM_CLASSIFICATION
=
new
API_V2
(
ENTITY_API
+
"guid/%s/classification/%s"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
ADD_CLASSIFICATIONS
=
new
API_V2
(
ENTITY_API
+
"guid/%s/classifications"
,
HttpMethod
.
POST
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
ADD_CLASSIFICATION
=
new
API_V2
(
ENTITY_BULK_API
+
"/classification"
,
HttpMethod
.
POST
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
ADD_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/%s/classifications"
,
HttpMethod
.
POST
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
UPDATE_CLASSIFICATIONS
=
new
API_V2
(
ENTITY_API
+
"guid/%s/classifications"
,
HttpMethod
.
PUT
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
UPDATE_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/%s/classifications"
,
HttpMethod
.
PUT
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
UPDATE_BULK_SET_CLASSIFICATIONS
=
new
API_V2
(
ENTITY_API
+
AtlasClientV2
.
BULK_SET_CLASSIFICATIONS
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_CLASSIFICATION
=
new
API_V2
(
ENTITY_API
+
"guid/%s/classification/%s"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DELETE_CLASSIFICATION_BY_TYPE_AND_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/%s/classification/%s"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
GET_BULK_HEADERS
=
new
API_V2
(
ENTITY_API
+
BULK_HEADERS
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
// business-attributes APIs
public
static
final
API_V2
ADD_BUSINESS_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"guid/%s/businessmetadata"
,
HttpMethod
.
POST
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
ADD_BUSINESS_ATTRIBUTE_BY_NAME
=
new
API_V2
(
ENTITY_API
+
"guid/%s/businessmetadata/%s"
,
HttpMethod
.
POST
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DELETE_BUSINESS_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"guid/%s/businessmetadata"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DELETE_BUSINESS_ATTRIBUTE_BY_NAME
=
new
API_V2
(
ENTITY_API
+
"guid/%s/businessmetadata/%s"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
GET_BUSINESS_METADATA_TEMPLATE
=
new
API_V2
(
ENTITY_API
+
"businessmetadata/import/template"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
,
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_OCTET_STREAM
);
public
static
final
API_V2
IMPORT_BUSINESS_METADATA
=
new
API_V2
(
ENTITY_API
+
"businessmetadata/import"
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
,
MediaType
.
MULTIPART_FORM_DATA
,
MediaType
.
APPLICATION_JSON
);
// labels APIs
public
static
final
API_V2
ADD_LABELS
=
new
API_V2
(
ENTITY_API
+
"guid/%s/labels"
,
HttpMethod
.
PUT
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
ADD_LABELS_BY_UNIQUE_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/%s/labels"
,
HttpMethod
.
PUT
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
SET_LABELS
=
new
API_V2
(
ENTITY_API
+
"guid/%s/labels"
,
HttpMethod
.
POST
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
SET_LABELS_BY_UNIQUE_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/%s/labels"
,
HttpMethod
.
POST
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DELETE_LABELS
=
new
API_V2
(
ENTITY_API
+
"guid/%s/labels"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DELETE_LABELS_BY_UNIQUE_ATTRIBUTE
=
new
API_V2
(
ENTITY_API
+
"uniqueAttribute/type/%s/labels"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
// Lineage APIs
public
static
final
API_V2
LINEAGE_INFO
=
new
API_V2
(
LINEAGE_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_LINEAGE_BY_ATTRIBUTES
=
new
API_V2
(
LINEAGE_URI
+
"uniqueAttribute/type/"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DSL_SEARCH
=
new
API_V2
(
DSL_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
FULL_TEXT_SEARCH
=
new
API_V2
(
FULL_TEXT_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
// Discovery APIs
public
static
final
API_V2
DSL_SEARCH
=
new
API_V2
(
DSL_SEARCH_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
FULL_TEXT_SEARCH
=
new
API_V2
(
FULL_TEXT_SEARCH_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
BASIC_SEARCH
=
new
API_V2
(
BASIC_SEARCH_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
FACETED_SEARCH
=
new
API_V2
(
FACETED_SEARCH_URI
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
ATTRIBUTE_SEARCH
=
new
API_V2
(
DISCOVERY_URI
+
"/attribute"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
RELATIONSHIP_SEARCH
=
new
API_V2
(
DISCOVERY_URI
+
"/relationship"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
QUICK_SEARCH_WITH_GET
=
new
API_V2
(
QUICK_SEARCH_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
QUICK_SEARCH_WITH_POST
=
new
API_V2
(
QUICK_SEARCH_URI
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_SUGGESTIONS
=
new
API_V2
(
DISCOVERY_URI
+
"/suggestions"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_SAVED_SEARCHES
=
new
API_V2
(
SAVED_SEARCH_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_SAVED_SEARCH
=
new
API_V2
(
SAVED_SEARCH_URI
+
"/%s"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
ADD_SAVED_SEARCH
=
new
API_V2
(
SAVED_SEARCH_URI
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_SAVED_SEARCH
=
new
API_V2
(
SAVED_SEARCH_URI
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_SAVED_SEARCH
=
new
API_V2
(
SAVED_SEARCH_URI
+
"/%s"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
EXECUTE_SAVED_SEARCH_BY_NAME
=
new
API_V2
(
SAVED_SEARCH_URI
+
"/execute/%s"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
EXECUTE_SAVED_SEARCH_BY_GUID
=
new
API_V2
(
SAVED_SEARCH_URI
+
"/execute/guid/%s"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
// Relationship APIs
public
static
final
API_V2
GET_RELATIONSHIP_BY_GUID
=
new
API_V2
(
RELATIONSHIPS_URI
+
"guid/"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_RELATIONSHIP_BY_GUID
=
new
API_V2
(
RELATIONSHIPS_URI
+
"guid/"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
CREATE_RELATIONSHIP
=
new
API_V2
(
RELATIONSHIPS_URI
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_RELATIONSHIP
=
new
API_V2
(
RELATIONSHIPS_URI
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_BULK_HEADERS
=
new
API_V2
(
ENTITY_API
+
BULK_HEADERS
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_BULK_SET_CLASSIFICATIONS
=
new
API_V2
(
ENTITY_API
+
AtlasClientV2
.
BULK_SET_CLASSIFICATIONS
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_RELATIONSHIP_BY_GUID
=
new
API_V2
(
RELATIONSHIPS_URI
+
"guid/"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
// Admin APIs
public
static
final
API_V2
GET_ATLAS_AUDITS
=
new
API_V2
(
ATLAS_AUDIT_API
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
// Glossary APIs
public
static
final
API_V2
GET_ALL_GLOSSARIES
=
new
API_V2
(
GLOSSARY_URI
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_GLOSSARY_BY_GUID
=
new
API_V2
(
GLOSSARY_URI
+
"/%s"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_DETAILED_GLOSSARY
=
new
API_V2
(
GLOSSARY_URI
+
"/%s/detailed"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_GLOSSARY_TERM
=
new
API_V2
(
GLOSSARY_TERM
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_GLOSSARY_TERMS
=
new
API_V2
(
GLOSSARY_URI
+
"/%s/terms"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_GLOSSARY_TERMS_HEADERS
=
new
API_V2
(
GLOSSARY_URI
+
"/%s/terms/headers"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_GLOSSARY_CATEGORY
=
new
API_V2
(
GLOSSARY_CATEGORY
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_GLOSSARY_CATEGORIES
=
new
API_V2
(
GLOSSARY_URI
+
"/%s/categories"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_GLOSSARY_CATEGORIES_HEADERS
=
new
API_V2
(
GLOSSARY_URI
+
"/%s/categories/headers"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_CATEGORY_TERMS
=
new
API_V2
(
GLOSSARY_CATEGORY
+
"/%s/terms"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_RELATED_TERMS
=
new
API_V2
(
GLOSSARY_TERMS
+
"/%s/related"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
GET_RELATED_CATEGORIES
=
new
API_V2
(
GLOSSARY_CATEGORY
+
"/%s/related"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_GLOSSARY
=
new
API_V2
(
GLOSSARY_URI
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_GLOSSARY_TERM
=
new
API_V2
(
GLOSSARY_TERM
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_GLOSSARY_TERMS
=
new
API_V2
(
GLOSSARY_TERMS
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_GLOSSARY_CATEGORY
=
new
API_V2
(
GLOSSARY_CATEGORY
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
CREATE_GLOSSARY_CATEGORIES
=
new
API_V2
(
GLOSSARY_CATEGORIES
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_GLOSSARY_BY_GUID
=
new
API_V2
(
GLOSSARY_URI
+
"/%s"
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_PARTIAL_GLOSSARY
=
new
API_V2
(
GLOSSARY_URI
+
"/%s/partial"
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_GLOSSARY_TERM
=
new
API_V2
(
GLOSSARY_TERM
+
"/%s"
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_PARTIAL_TERM
=
new
API_V2
(
GLOSSARY_TERM
+
"/%s/partial"
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_CATEGORY_BY_GUID
=
new
API_V2
(
GLOSSARY_CATEGORY
+
"/%s"
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
UPDATE_PARTIAL_CATEGORY
=
new
API_V2
(
GLOSSARY_CATEGORY
+
"/%s/partial"
,
HttpMethod
.
PUT
,
Response
.
Status
.
OK
);
public
static
final
API_V2
DELETE_GLOSSARY_BY_GUID
=
new
API_V2
(
GLOSSARY_URI
+
"/%s"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DELETE_TERM_BY_GUID
=
new
API_V2
(
GLOSSARY_TERM
+
"/%s"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DELETE_CATEGORY_BY_GUID
=
new
API_V2
(
GLOSSARY_CATEGORY
+
"/%s"
,
HttpMethod
.
DELETE
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
GET_ENTITIES_ASSIGNED_WITH_TERM
=
new
API_V2
(
GLOSSARY_TERMS
+
"/%s/assignedEntities"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
);
public
static
final
API_V2
ASSIGN_TERM_TO_ENTITIES
=
new
API_V2
(
GLOSSARY_TERMS
+
"/%s/assignedEntities"
,
HttpMethod
.
POST
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
DISASSOCIATE_TERM_FROM_ENTITIES
=
new
API_V2
(
GLOSSARY_TERMS
+
"/%s/assignedEntities"
,
HttpMethod
.
PUT
,
Response
.
Status
.
NO_CONTENT
);
public
static
final
API_V2
GET_IMPORT_GLOSSARY_TEMPLATE
=
new
API_V2
(
GLOSSARY_URI
+
"/import/template"
,
HttpMethod
.
GET
,
Response
.
Status
.
OK
,
MediaType
.
APPLICATION_JSON
,
MediaType
.
APPLICATION_OCTET_STREAM
);
public
static
final
API_V2
IMPORT_GLOSSARY
=
new
API_V2
(
GLOSSARY_URI
+
"/import"
,
HttpMethod
.
POST
,
Response
.
Status
.
OK
,
MediaType
.
MULTIPART_FORM_DATA
,
MediaType
.
APPLICATION_JSON
);
private
API_V2
(
String
path
,
String
method
,
Response
.
Status
status
)
{
super
(
path
,
method
,
status
);
}
private
API_V2
(
String
path
,
String
method
,
Response
.
Status
status
,
String
consumes
,
String
produces
)
{
super
(
path
,
method
,
status
,
consumes
,
produces
);
}
}
}
client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
View file @
8827bfb4
...
...
@@ -37,10 +37,10 @@ import com.sun.jersey.multipart.MultiPart;
import
com.sun.jersey.multipart.file.FileDataBodyPart
;
import
com.sun.jersey.multipart.file.StreamDataBodyPart
;
import
com.sun.jersey.multipart.impl.MultiPartWriter
;
import
org.apache.atlas.model.impexp.AtlasServer
;
import
org.apache.atlas.model.impexp.AtlasExportRequest
;
import
org.apache.atlas.model.impexp.AtlasImportRequest
;
import
org.apache.atlas.model.impexp.AtlasImportResult
;
import
org.apache.atlas.model.impexp.AtlasServer
;
import
org.apache.atlas.model.metrics.AtlasMetrics
;
import
org.apache.atlas.security.SecureClientUtils
;
import
org.apache.atlas.type.AtlasType
;
...
...
@@ -66,7 +66,6 @@ import java.io.InputStream;
import
java.io.OutputStream
;
import
java.net.ConnectException
;
import
java.net.URI
;
import
java.nio.file.Paths
;
import
java.util.List
;
import
java.util.Map
;
...
...
webapp/pom.xml
View file @
8827bfb4
...
...
@@ -741,6 +741,7 @@
<resource>
<directory>
${basedir}/../addons/models/
</directory>
<includes>
<include>
0000-Area0/0011-glossary_model.json
</include>
<include>
0000-Area0/0010-base_model.json
</include>
<include>
1000-Hadoop/**
</include>
</includes>
...
...
webapp/src/test/java/org/apache/atlas/web/TestUtils.java
View file @
8827bfb4
...
...
@@ -56,4 +56,7 @@ public class TestUtils {
return
System
.
getProperty
(
"projectBaseDir"
)
+
"/webapp/target"
;
}
public
static
String
getGlossaryType
(){
return
System
.
getProperty
(
"projectBaseDir"
)
+
"/webapp/target/models/0000-Area0/0011-glossary_model.json"
;
}
}
webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
View file @
8827bfb4
...
...
@@ -24,6 +24,8 @@ import org.apache.atlas.ApplicationProperties;
import
org.apache.atlas.AtlasClient
;
import
org.apache.atlas.AtlasClientV2
;
import
org.apache.atlas.AtlasServiceException
;
import
org.apache.atlas.kafka.AtlasKafkaMessage
;
import
org.apache.atlas.kafka.KafkaNotification
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
...
...
@@ -31,24 +33,36 @@ import org.apache.atlas.model.instance.AtlasEntityHeader;
import
org.apache.atlas.model.instance.AtlasStruct
;
import
org.apache.atlas.model.instance.EntityMutationResponse
;
import
org.apache.atlas.model.instance.EntityMutations
;
import
org.apache.atlas.model.typedef.*
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasBusinessMetadataDef
;
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.AtlasRelationshipDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.notification.NotificationConsumer
;
import
org.apache.atlas.notification.NotificationInterface
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasTypeUtil
;
import
org.apache.atlas.utils.AuthenticationUtil
;
import
org.apache.atlas.utils.ParamChecker
;
import
org.apache.atlas.v1.model.instance.Id
;
import
org.apache.atlas.v1.model.instance.Referenceable
;
import
org.apache.atlas.v1.model.instance.Struct
;
import
org.apache.atlas.v1.model.typedef.*
;
import
org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue
;
import
org.apache.atlas.notification.NotificationConsumer
;
import
org.apache.atlas.kafka.*
;
import
org.apache.atlas.v1.model.notification.EntityNotificationV1
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasTypeUtil
;
import
org.apache.atlas.v1.model.typedef.AttributeDefinition
;
import
org.apache.atlas.v1.model.typedef.ClassTypeDefinition
;
import
org.apache.atlas.v1.model.typedef.EnumTypeDefinition
;
import
org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue
;
import
org.apache.atlas.v1.model.typedef.Multiplicity
;
import
org.apache.atlas.v1.model.typedef.StructTypeDefinition
;
import
org.apache.atlas.v1.model.typedef.TraitTypeDefinition
;
import
org.apache.atlas.v1.model.typedef.TypesDef
;
import
org.apache.atlas.v1.typesystem.types.utils.TypesUtil
;
import
org.apache.atlas.utils.AuthenticationUtil
;
import
org.apache.atlas.utils.ParamChecker
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.lang.RandomStringUtils
;
import
org.slf4j.Logger
;
...
...
@@ -66,6 +80,8 @@ import java.util.Map;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasStructDef
.
AtlasConstraintDef
.
CONSTRAINT_PARAM_ATTRIBUTE
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasStructDef
.
AtlasConstraintDef
.
CONSTRAINT_TYPE_INVERSE_REF
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasStructDef
.
AtlasConstraintDef
.
CONSTRAINT_TYPE_OWNED_REF
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasTypeUtil
.
createBusinessMetadataDef
;
import
static
org
.
apache
.
atlas
.
type
.
AtlasTypeUtil
.
createOptionalAttrDef
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
...
...
@@ -160,6 +176,22 @@ public abstract class BaseResourceIT {
}
}
for
(
AtlasRelationshipDef
relationshipDef
:
typesDef
.
getRelationshipDefs
())
{
if
(
atlasClientV2
.
typeWithNameExists
(
relationshipDef
.
getName
()))
{
LOG
.
warn
(
"Type with name {} already exists. Skipping"
,
relationshipDef
.
getName
());
}
else
{
toCreate
.
getRelationshipDefs
().
add
(
relationshipDef
);
}
}
for
(
AtlasBusinessMetadataDef
businessMetadataDef
:
typesDef
.
getBusinessMetadataDefs
())
{
if
(
atlasClientV2
.
typeWithNameExists
(
businessMetadataDef
.
getName
()))
{
LOG
.
warn
(
"Type with name {} already exists. Skipping"
,
businessMetadataDef
.
getName
());
}
else
{
toCreate
.
getBusinessMetadataDefs
().
add
(
businessMetadataDef
);
}
}
atlasClientV2
.
createAtlasTypeDefs
(
toCreate
);
}
...
...
@@ -440,11 +472,33 @@ public abstract class BaseResourceIT {
AtlasClassificationDef
secTrait
=
AtlasTypeUtil
.
createTraitTypeDef
(
SEC_TAG
,
Collections
.<
String
>
emptySet
());
AtlasClassificationDef
financeTrait
=
AtlasTypeUtil
.
createTraitTypeDef
(
FINANCE_TAG
,
Collections
.<
String
>
emptySet
());
//bussinessmetadata
String
_description
=
"_description"
;
Map
<
String
,
String
>
options
=
new
HashMap
<>();
options
.
put
(
"maxStrLength"
,
"20"
);
AtlasBusinessMetadataDef
bmNoApplicableTypes
=
createBusinessMetadataDef
(
"bmNoApplicableTypes"
,
_description
,
"1.0"
,
createOptionalAttrDef
(
"attr0"
,
"string"
,
options
,
_description
));
AtlasBusinessMetadataDef
bmNoAttributes
=
createBusinessMetadataDef
(
"bmNoAttributes"
,
_description
,
"1.0"
,
null
);
options
.
put
(
"applicableEntityTypes"
,
"[\""
+
DATABASE_TYPE_V2
+
"\",\""
+
HIVE_TABLE_TYPE_V2
+
"\"]"
);
AtlasBusinessMetadataDef
bmWithAllTypes
=
createBusinessMetadataDef
(
"bmWithAllTypes"
,
_description
,
"1.0"
,
createOptionalAttrDef
(
"attr1"
,
AtlasBusinessMetadataDef
.
ATLAS_TYPE_BOOLEAN
,
options
,
_description
),
createOptionalAttrDef
(
"attr2"
,
AtlasBusinessMetadataDef
.
ATLAS_TYPE_BYTE
,
options
,
_description
),
createOptionalAttrDef
(
"attr8"
,
AtlasBusinessMetadataDef
.
ATLAS_TYPE_STRING
,
options
,
_description
));
AtlasBusinessMetadataDef
bmWithAllTypesMV
=
createBusinessMetadataDef
(
"bmWithAllTypesMV"
,
_description
,
"1.0"
,
createOptionalAttrDef
(
"attr11"
,
"array<boolean>"
,
options
,
_description
),
createOptionalAttrDef
(
"attr18"
,
"array<string>"
,
options
,
_description
));
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
(
Collections
.
singletonList
(
enumDef
),
Collections
.
singletonList
(
structTypeDef
),
Arrays
.
asList
(
classificationTrait
,
piiTrait
,
phiTrait
,
pciTrait
,
soxTrait
,
secTrait
,
financeTrait
),
Arrays
.
asList
(
dbClsTypeDef
,
columnClsDef
,
tblClsDef
,
loadProcessClsDef
));
Arrays
.
asList
(
dbClsTypeDef
,
columnClsDef
,
tblClsDef
,
loadProcessClsDef
),
new
ArrayList
<>(),
Arrays
.
asList
(
bmNoApplicableTypes
,
bmNoAttributes
,
bmWithAllTypes
,
bmWithAllTypesMV
));
batchCreateTypes
(
typesDef
);
}
...
...
@@ -549,6 +603,7 @@ public abstract class BaseResourceIT {
return
tableInstance
;
}
protected
Referenceable
createHiveDBInstanceBuiltIn
(
String
dbName
)
{
Referenceable
databaseInstance
=
new
Referenceable
(
DATABASE_TYPE_BUILTIN
);
...
...
@@ -560,7 +615,6 @@ public abstract class BaseResourceIT {
return
databaseInstance
;
}
protected
Referenceable
createHiveDBInstanceV1
(
String
dbName
)
{
Referenceable
databaseInstance
=
new
Referenceable
(
DATABASE_TYPE
);
...
...
@@ -584,7 +638,6 @@ public abstract class BaseResourceIT {
return
atlasEntity
;
}
public
interface
Predicate
{
/**
...
...
webapp/src/test/java/org/apache/atlas/web/integration/BasicSearchIT.java
View file @
8827bfb4
...
...
@@ -23,12 +23,16 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
org.apache.atlas.AtlasServiceException
;
import
org.apache.atlas.model.discovery.AtlasQuickSearchResult
;
import
org.apache.atlas.model.discovery.AtlasSearchResult
;
import
org.apache.atlas.model.discovery.QuickSearchParameters
;
import
org.apache.atlas.model.discovery.SearchParameters
;
import
org.apache.atlas.model.impexp.AtlasImportRequest
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntityHeader
;
import
org.apache.atlas.model.instance.EntityMutationResponse
;
import
org.apache.atlas.model.profile.AtlasUserSavedSearch
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.type.AtlasTypeUtil
;
...
...
@@ -42,15 +46,18 @@ import java.net.URLEncoder;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
static
com
.
fasterxml
.
jackson
.
annotation
.
JsonAutoDetect
.
Visibility
.
NONE
;
import
static
com
.
fasterxml
.
jackson
.
annotation
.
JsonAutoDetect
.
Visibility
.
PUBLIC_ONLY
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
assertNull
;
import
static
org
.
testng
.
Assert
.
fail
;
public
class
BasicSearchIT
extends
BaseResourceIT
{
private
AtlasUserSavedSearch
userSavedSearch
;
@BeforeClass
@Override
...
...
@@ -113,6 +120,13 @@ public class BasicSearchIT extends BaseResourceIT {
};
}
@DataProvider
public
Object
[][]
attributeSearchJSONNames
()
{
return
new
String
[][]{
{
"search-parameters/attribute-filters"
}
};
}
@Test
(
dataProvider
=
"basicSearchJSONNames"
)
public
void
testDiscoveryWithSearchParameters
(
String
jsonFile
)
{
try
{
...
...
@@ -141,6 +155,137 @@ public class BasicSearchIT extends BaseResourceIT {
}
}
@Test
(
dataProvider
=
"attributeSearchJSONNames"
)
public
void
testAttributeSearch
(
String
jsonFile
)
{
try
{
BasicSearchParametersWithExpectation
[]
testExpectations
=
TestResourceFileUtils
.
readObjectFromJson
(
jsonFile
,
BasicSearchParametersWithExpectation
[].
class
);
assertNotNull
(
testExpectations
);
for
(
BasicSearchParametersWithExpectation
testExpectation
:
testExpectations
)
{
LOG
.
info
(
"TestDescription :{}"
,
testExpectation
.
testDescription
);
LOG
.
info
(
"SearchParameters :{}"
,
testExpectation
.
searchParameters
);
SearchParameters
parameters
=
testExpectation
.
getSearchParameters
();
if
(
parameters
.
getEntityFilters
()
==
null
||
parameters
.
getEntityFilters
().
getAttributeName
()
==
null
)
{
continue
;
}
SearchParameters
.
FilterCriteria
filterCriteria
=
parameters
.
getEntityFilters
();
AtlasSearchResult
searchResult
=
atlasClientV2
.
attributeSearch
(
parameters
.
getTypeName
(),
filterCriteria
.
getAttributeName
(),
filterCriteria
.
getAttributeValue
(),
parameters
.
getLimit
(),
parameters
.
getOffset
());
if
(
testExpectation
.
expectedCount
>
0
)
{
assertNotNull
(
searchResult
.
getEntities
());
assertEquals
(
searchResult
.
getEntities
().
size
(),
testExpectation
.
expectedCount
);
}
if
(
testExpectation
.
searchParameters
.
getSortBy
()
!=
null
&&
!
testExpectation
.
searchParameters
.
getSortBy
().
isEmpty
())
{
assertNotNull
(
searchResult
.
getEntities
());
assertEquals
(
searchResult
.
getEntities
().
get
(
0
).
getAttribute
(
"name"
),
"testtable_1"
);
}
}
}
catch
(
IOException
|
AtlasServiceException
e
)
{
fail
(
e
.
getMessage
());
}
}
@Test
(
dataProvider
=
"attributeSearchJSONNames"
)
public
void
testSavedSearch
(
String
jsonFile
)
{
try
{
BasicSearchParametersWithExpectation
[]
testExpectations
=
TestResourceFileUtils
.
readObjectFromJson
(
jsonFile
,
BasicSearchParametersWithExpectation
[].
class
);
assertNotNull
(
testExpectations
);
for
(
BasicSearchParametersWithExpectation
testExpectation
:
testExpectations
)
{
LOG
.
info
(
"TestDescription :{}"
,
testExpectation
.
testDescription
);
LOG
.
info
(
"SearchParameters :{}"
,
testExpectation
.
searchParameters
);
SearchParameters
parameters
=
testExpectation
.
getSearchParameters
();
AtlasUserSavedSearch
savedSearch
=
new
AtlasUserSavedSearch
();
savedSearch
.
setSearchType
(
AtlasUserSavedSearch
.
SavedSearchType
.
BASIC
);
savedSearch
.
setName
(
"basic_test"
);
savedSearch
.
setGuid
(
""
);
savedSearch
.
setSearchParameters
(
parameters
);
savedSearch
.
setOwnerName
(
"admin"
);
userSavedSearch
=
atlasClientV2
.
addSavedSearch
(
savedSearch
);
assertNotNull
(
userSavedSearch
);
List
<
AtlasUserSavedSearch
>
list
=
atlasClientV2
.
getSavedSearches
(
"admin"
);
assertNotNull
(
list
);
}
}
catch
(
IOException
|
AtlasServiceException
e
)
{
fail
(
e
.
getMessage
());
}
}
@Test
(
dependsOnMethods
=
"testSavedSearch"
)
public
void
testExecuteSavedSearchByName
()
{
try
{
AtlasSearchResult
searchResult
=
atlasClientV2
.
executeSavedSearch
(
"admin"
,
"basic_test"
);
assertNotNull
(
searchResult
);
}
catch
(
AtlasServiceException
e
)
{
fail
(
e
.
getMessage
());
}
}
@Test
(
dependsOnMethods
=
"testSavedSearch"
)
public
void
tesUpdateSavedSearch
()
{
try
{
userSavedSearch
.
setSearchType
(
AtlasUserSavedSearch
.
SavedSearchType
.
ADVANCED
);
userSavedSearch
=
atlasClientV2
.
updateSavedSearch
(
userSavedSearch
);
assertNotNull
(
userSavedSearch
);
assertEquals
(
userSavedSearch
.
getSearchType
(),
AtlasUserSavedSearch
.
SavedSearchType
.
ADVANCED
);
}
catch
(
AtlasServiceException
e
)
{
fail
(
e
.
getMessage
());
}
}
@Test
(
dependsOnMethods
=
"tesUpdateSavedSearch"
)
public
void
testExecuteSavedSearchByGuid
()
{
try
{
AtlasSearchResult
searchResult
=
atlasClientV2
.
executeSavedSearch
(
userSavedSearch
.
getGuid
());
assertNotNull
(
searchResult
);
}
catch
(
AtlasServiceException
e
)
{
fail
(
e
.
getMessage
());
}
}
@Test
(
dependsOnMethods
=
"testExecuteSavedSearchByGuid"
)
public
void
testDeleteSavedSearch
()
{
AtlasUserSavedSearch
searchAfterDelete
=
null
;
try
{
atlasClientV2
.
deleteSavedSearch
(
userSavedSearch
.
getGuid
());
searchAfterDelete
=
atlasClientV2
.
getSavedSearch
(
"admin"
,
"basic_test"
);
}
catch
(
AtlasServiceException
e
)
{
assertNull
(
searchAfterDelete
);
}
}
@Test
public
void
testGetQuickSearch
()
{
try
{
AtlasQuickSearchResult
result
=
atlasClientV2
.
quickSearch
(
"test"
,
"hdfs_path"
,
false
,
2
,
0
);
assertNotNull
(
result
);
List
<
AtlasEntityHeader
>
list
=
result
.
getSearchResults
().
getEntities
();
assertEquals
(
list
.
size
(),
1
);
}
catch
(
AtlasServiceException
e
)
{
fail
(
e
.
getMessage
());
}
}
@Test
public
void
testPostQuickSearch
()
{
try
{
QuickSearchParameters
quickSearchParameters
=
new
QuickSearchParameters
();
quickSearchParameters
.
setQuery
(
"test"
);
quickSearchParameters
.
setTypeName
(
"hdfs_path"
);
AtlasQuickSearchResult
result
=
atlasClientV2
.
quickSearch
(
quickSearchParameters
);
List
<
AtlasEntityHeader
>
list
=
result
.
getSearchResults
().
getEntities
();
assertEquals
(
list
.
size
(),
1
);
}
catch
(
AtlasServiceException
e
)
{
fail
(
e
.
getMessage
());
}
}
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
...
...
webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java
View file @
8827bfb4
...
...
@@ -18,6 +18,8 @@
package
org
.
apache
.
atlas
.
web
.
integration
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.google.common.collect.Lists
;
import
com.sun.jersey.api.client.ClientResponse
;
...
...
@@ -25,18 +27,27 @@ import org.apache.atlas.ApplicationProperties;
import
org.apache.atlas.AtlasClient
;
import
org.apache.atlas.AtlasServiceException
;
import
org.apache.atlas.EntityAuditEvent
;
import
org.apache.atlas.bulkimport.BulkImportResponse
;
import
org.apache.atlas.model.TimeBoundary
;
import
org.apache.atlas.model.audit.AtlasAuditEntry
;
import
org.apache.atlas.model.audit.AuditSearchParameters
;
import
org.apache.atlas.model.instance.*
;
import
org.apache.atlas.model.audit.EntityAuditEventV2
;
import
org.apache.atlas.model.instance.AtlasClassification
;
import
org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo
;
import
org.apache.atlas.model.instance.AtlasEntityHeader
;
import
org.apache.atlas.model.instance.AtlasObjectId
;
import
org.apache.atlas.model.instance.ClassificationAssociateRequest
;
import
org.apache.atlas.model.instance.EntityMutationResponse
;
import
org.apache.atlas.model.instance.EntityMutations
;
import
org.apache.atlas.model.typedef.AtlasClassificationDef
;
import
org.apache.atlas.model.typedef.AtlasEntityDef
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.type.AtlasTypeUtil
;
import
org.apache.atlas.utils.TestResourceFileUtils
;
import
org.apache.atlas.v1.typesystem.types.utils.TypesUtil
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang.RandomStringUtils
;
import
org.apache.hadoop.util.StringUtils
;
import
org.slf4j.Logger
;
...
...
@@ -45,13 +56,29 @@ import org.testng.Assert;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
static
org
.
testng
.
Assert
.*;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertFalse
;
import
static
org
.
testng
.
Assert
.
assertNotEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
assertNull
;
import
static
org
.
testng
.
Assert
.
assertTrue
;
import
static
org
.
testng
.
Assert
.
fail
;
/**
* Integration tests for Entity Jersey Resource.
...
...
@@ -65,9 +92,12 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
private
final
String
DATABASE_NAME
=
"db"
+
randomString
();
private
final
String
TABLE_NAME
=
"table"
+
randomString
();
private
String
traitName
;
private
String
createdDBName
;
private
String
createdTableQualifiedName
;
private
AtlasEntity
dbEntity
;
private
AtlasEntity
tableEntity
;
private
AtlasClassificationDef
piiTrait
;
@BeforeClass
public
void
setUp
()
throws
Exception
{
...
...
@@ -83,6 +113,8 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
assertNotNull
(
dbAndTable
);
assertNotNull
(
dbAndTable
.
left
);
assertNotNull
(
dbAndTable
.
right
);
// Writing created table data to a file for import test.
createImportFile
();
}
@Test
...
...
@@ -172,17 +204,6 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
assertEquals
(
results
.
size
(),
1
);
}
private
void
assertEntityAudit
(
String
dbid
,
EntityAuditEvent
.
EntityAuditAction
auditAction
)
throws
Exception
{
List
<
EntityAuditEvent
>
events
=
atlasClientV1
.
getEntityAuditEvents
(
dbid
,
(
short
)
100
);
for
(
EntityAuditEvent
event
:
events
)
{
if
(
event
.
getAction
()
==
auditAction
)
{
return
;
}
}
fail
(
"Expected audit event with action = "
+
auditAction
);
}
@Test
public
void
testEntityDefinitionAcrossTypeUpdate
()
throws
Exception
{
//create type
...
...
@@ -268,6 +289,24 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
}
@Test
public
void
testGetEntitiesByAttribute
()
throws
Exception
{
AtlasEntity
hiveDB1
=
createHiveDB
();
AtlasEntity
hiveDB2
=
createHiveDB
();
String
qualifiedNameDB1
=
(
String
)
hiveDB1
.
getAttribute
(
NAME
);
String
qualifiedNameDB2
=
(
String
)
hiveDB2
.
getAttribute
(
NAME
);
List
<
Map
<
String
,
String
>>
list
=
new
ArrayList
<>();
list
.
add
(
toMap
(
NAME
,
qualifiedNameDB1
));
list
.
add
(
toMap
(
NAME
,
qualifiedNameDB2
));
AtlasEntity
.
AtlasEntitiesWithExtInfo
info
=
atlasClientV2
.
getEntitiesByAttribute
(
DATABASE_TYPE_V2
,
list
);
List
<
AtlasEntity
>
entityList
=
info
.
getEntities
();
assertEquals
(
entityList
.
size
(),
2
);
assertEquals
(
entityList
.
get
(
0
).
getTypeName
(),
DATABASE_TYPE_V2
);
assertEquals
(
entityList
.
get
(
1
).
getTypeName
(),
DATABASE_TYPE_V2
);
}
@Test
public
void
testSubmitEntityWithBadDateFormat
()
throws
Exception
{
AtlasEntity
hiveDBEntity
=
createHiveDBInstanceV2
(
"db"
+
randomString
());
AtlasEntityHeader
hiveDBHeader
=
createEntity
(
hiveDBEntity
);
...
...
@@ -376,7 +415,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
AtlasClassifications
classifications
=
atlasClientV2
.
getClassifications
(
createHiveTable
().
getGuid
());
assertNotNull
(
classifications
);
assertTrue
(
classifications
.
getList
().
size
()
>
0
);
assertEquals
(
classifications
.
getList
().
size
(),
8
);
assertEquals
(
classifications
.
getList
().
size
(),
9
);
}
@Test
(
dependsOnMethods
=
"testSubmitEntity"
)
...
...
@@ -390,55 +429,6 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
Assert
.
assertNotNull
(
entity
.
getUpdateTime
());
}
private
void
addProperty
(
String
guid
,
String
property
,
Object
value
)
throws
AtlasServiceException
{
AtlasEntity
entityByGuid
=
getEntityByGuid
(
guid
);
entityByGuid
.
setAttribute
(
property
,
value
);
EntityMutationResponse
response
=
atlasClientV2
.
updateEntity
(
new
AtlasEntityWithExtInfo
(
entityByGuid
));
assertNotNull
(
response
);
assertNotNull
(
response
.
getEntitiesByOperation
(
EntityMutations
.
EntityOperation
.
UPDATE
));
}
private
AtlasEntity
createHiveDB
()
{
if
(
dbEntity
==
null
)
{
dbEntity
=
createHiveDB
(
DATABASE_NAME
);
}
return
dbEntity
;
}
private
AtlasEntity
createHiveDB
(
String
dbName
)
{
AtlasEntity
hiveDBInstanceV2
=
createHiveDBInstanceV2
(
dbName
);
AtlasEntityHeader
entityHeader
=
createEntity
(
hiveDBInstanceV2
);
assertNotNull
(
entityHeader
);
assertNotNull
(
entityHeader
.
getGuid
());
hiveDBInstanceV2
.
setGuid
(
entityHeader
.
getGuid
());
return
hiveDBInstanceV2
;
}
private
TypesUtil
.
Pair
<
AtlasEntity
,
AtlasEntity
>
createDBAndTable
()
throws
Exception
{
AtlasEntity
dbInstanceV2
=
createHiveDB
();
AtlasEntity
hiveTableInstanceV2
=
createHiveTable
();
return
TypesUtil
.
Pair
.
of
(
dbInstanceV2
,
hiveTableInstanceV2
);
}
private
AtlasEntity
createHiveTable
()
throws
Exception
{
if
(
tableEntity
==
null
)
{
tableEntity
=
createHiveTable
(
createHiveDB
(),
TABLE_NAME
);
}
return
tableEntity
;
}
private
AtlasEntity
createHiveTable
(
AtlasEntity
dbInstanceV2
,
String
tableName
)
throws
Exception
{
AtlasEntity
hiveTableInstanceV2
=
createHiveTableInstanceV2
(
dbInstanceV2
,
tableName
);
AtlasEntityHeader
createdHeader
=
createEntity
(
hiveTableInstanceV2
);
assertNotNull
(
createdHeader
);
assertNotNull
(
createdHeader
.
getGuid
());
hiveTableInstanceV2
.
setGuid
(
createdHeader
.
getGuid
());
tableEntity
=
hiveTableInstanceV2
;
return
hiveTableInstanceV2
;
}
@Test
(
dependsOnMethods
=
"testGetTraitNames"
)
public
void
testAddTrait
()
throws
Exception
{
traitName
=
"PII_Trait"
+
randomString
();
...
...
@@ -451,6 +441,41 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
atlasClientV2
.
addClassifications
(
createHiveTable
().
getGuid
(),
Collections
.
singletonList
(
new
AtlasClassification
(
piiTrait
.
getName
())));
assertEntityAudit
(
createHiveTable
().
getGuid
(),
EntityAuditEvent
.
EntityAuditAction
.
TAG_ADD
);
AtlasClassifications
classifications
=
atlasClientV2
.
getEntityClassifications
(
createHiveTable
().
getGuid
(),
piiTrait
.
getName
());
assertNotNull
(
classifications
);
}
@Test
(
dependsOnMethods
=
"testAddTrait"
)
public
void
testAddLabels
()
throws
Exception
{
Set
<
String
>
set
=
new
HashSet
<>();
set
.
add
(
"lable"
);
atlasClientV2
.
addLabels
(
createHiveTable
().
getGuid
(),
set
);
AtlasEntityWithExtInfo
info
=
atlasClientV2
.
getEntityByGuid
(
createHiveTable
().
getGuid
(),
false
,
true
);
assertNotNull
(
info
);
assertNotNull
(
info
.
getEntity
().
getLabels
());
assertEquals
(
info
.
getEntity
().
getLabels
().
size
(),
1
);
}
@Test
(
dependsOnMethods
=
"testAddLabels"
)
public
void
testSetLabels
()
throws
Exception
{
Set
<
String
>
setNet
=
new
HashSet
<>();
setNet
.
add
(
"labelNext"
);
atlasClientV2
.
setLabels
(
createHiveTable
().
getGuid
(),
setNet
);
AtlasEntityWithExtInfo
infoForSet
=
atlasClientV2
.
getEntityByGuid
(
createHiveTable
().
getGuid
(),
false
,
true
);
assertNotNull
(
infoForSet
);
assertNotNull
(
infoForSet
.
getEntity
().
getLabels
());
assertEquals
(
infoForSet
.
getEntity
().
getLabels
().
size
(),
1
);
}
@Test
(
dependsOnMethods
=
"testSetLabels"
)
public
void
testDeleteLabels
()
throws
Exception
{
Set
<
String
>
set
=
new
HashSet
<>();
set
.
add
(
"testNext"
);
atlasClientV2
.
removeLabels
(
createHiveTable
().
getGuid
(),
set
);
AtlasEntityWithExtInfo
info
=
atlasClientV2
.
getEntityByGuid
(
createHiveTable
().
getGuid
(),
false
,
true
);
assertNotNull
(
info
);
assertNotNull
(
info
.
getEntity
().
getLabels
());
assertEquals
(
info
.
getEntity
().
getLabels
().
size
(),
1
);
}
@Test
(
dependsOnMethods
=
"testGetTraitNames"
)
...
...
@@ -521,10 +546,9 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
AtlasClassifications
classifications
=
atlasClientV2
.
getClassifications
(
hiveTable
.
getGuid
());
assertNotNull
(
classifications
);
assertTrue
(
classifications
.
getList
().
size
()
>
0
);
assertEquals
(
classifications
.
getList
().
size
(),
8
);
assertEquals
(
classifications
.
getList
().
size
(),
9
);
}
@Test
(
dependsOnMethods
=
"testGetTraitNames"
)
public
void
testAddTraitWithAttribute
()
throws
Exception
{
final
String
traitName
=
"PII_Trait"
+
randomString
();
...
...
@@ -615,18 +639,21 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
}
}
private
String
random
()
{
return
RandomStringUtils
.
random
(
10
);
}
private
String
randomUTF8
()
throws
Exception
{
String
ret
=
random
();
if
(!
StandardCharsets
.
UTF_8
.
equals
(
Charset
.
defaultCharset
()))
{
ret
=
new
String
(
ret
.
getBytes
(),
StandardCharsets
.
UTF_8
.
name
());
@Test
(
dependsOnMethods
=
"testSubmitEntity"
)
public
void
testGetEntityHeaderByGuid
()
throws
Exception
{
AtlasEntityHeader
header
=
atlasClientV2
.
getEntityHeaderByGuid
(
createHiveTable
().
getGuid
());
assertNotNull
(
header
);
assertEquals
(
header
.
getGuid
(),
createHiveTable
().
getGuid
());
}
return
ret
;
@Test
(
dependsOnMethods
=
"testSubmitEntity"
)
public
void
testGetEntityHeaderByAttribute
()
throws
Exception
{
AtlasEntity
hiveDB
=
createHiveDB
();
String
qualifiedName
=
(
String
)
hiveDB
.
getAttribute
(
NAME
);
AtlasEntityHeader
header
=
atlasClientV2
.
getEntityHeaderByAttribute
(
DATABASE_TYPE_V2
,
toMap
(
NAME
,
qualifiedName
));
assertNotNull
(
header
);
assertEquals
(
header
.
getTypeName
(),
DATABASE_TYPE_V2
);
assertEquals
(
header
.
getAttribute
(
NAME
),
qualifiedName
);
}
@Test
...
...
@@ -837,6 +864,312 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
// Verify entities were deleted from the repository.
}
@Test
public
void
testPartialUpdateEntityByGuid
()
throws
Exception
{
EntityMutationResponse
updateResponse
=
atlasClientV2
.
partialUpdateEntityByGuid
(
createHiveTable
().
getGuid
(),
Collections
.
singletonMap
(
"key1"
,
"value1"
),
"description"
);
assertNotNull
(
updateResponse
);
assertNotNull
(
updateResponse
.
getEntitiesByOperation
(
EntityMutations
.
EntityOperation
.
PARTIAL_UPDATE
));
assertTrue
(
updateResponse
.
getEntitiesByOperation
(
EntityMutations
.
EntityOperation
.
PARTIAL_UPDATE
).
size
()
>
0
);
}
@Test
(
dependsOnMethods
=
"testGetTraitNames"
)
public
void
testAddClassificationsByUniqueAttribute
()
throws
Exception
{
traitName
=
"PII_Trait"
+
randomString
();
piiTrait
=
AtlasTypeUtil
.
createTraitTypeDef
(
traitName
,
Collections
.<
String
>
emptySet
());
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
();
typesDef
.
getClassificationDefs
().
add
(
piiTrait
);
createType
(
typesDef
);
createdTableQualifiedName
=
(
String
)
createHiveTable
().
getAttribute
(
QUALIFIED_NAME
);
atlasClientV2
.
addClassifications
(
createHiveTable
().
getTypeName
(),
toMap
(
QUALIFIED_NAME
,
createdTableQualifiedName
),
Collections
.
singletonList
(
new
AtlasClassification
(
piiTrait
.
getName
())));
assertEntityAudit
(
createHiveTable
().
getGuid
(),
EntityAuditEvent
.
EntityAuditAction
.
TAG_ADD
);
}
@Test
(
dependsOnMethods
=
"testAddClassificationsByUniqueAttribute"
)
public
void
testUpdateClassifications
()
throws
Exception
{
atlasClientV2
.
updateClassifications
(
createHiveTable
().
getGuid
(),
Collections
.
singletonList
(
new
AtlasClassification
(
piiTrait
.
getName
())));
assertEntityAudit
(
createHiveTable
().
getGuid
(),
EntityAuditEvent
.
EntityAuditAction
.
TAG_UPDATE
);
}
@Test
(
dependsOnMethods
=
"testUpdateClassifications"
)
public
void
testUpdateClassificationsByUniqueAttribute
()
throws
Exception
{
createdTableQualifiedName
=
(
String
)
createHiveTable
().
getAttribute
(
QUALIFIED_NAME
);
atlasClientV2
.
updateClassifications
(
createHiveTable
().
getTypeName
(),
toMap
(
QUALIFIED_NAME
,
createdTableQualifiedName
),
Collections
.
singletonList
(
new
AtlasClassification
(
piiTrait
.
getName
())));
assertEntityAudit
(
createHiveTable
().
getGuid
(),
EntityAuditEvent
.
EntityAuditAction
.
TAG_ADD
);
}
@Test
(
dependsOnMethods
=
"testUpdateClassificationsByUniqueAttribute"
)
public
void
testRemoveEntityClassification
()
throws
Exception
{
createdTableQualifiedName
=
(
String
)
createHiveTable
().
getAttribute
(
QUALIFIED_NAME
);
atlasClientV2
.
removeClassification
(
createHiveTable
().
getTypeName
(),
toMap
(
QUALIFIED_NAME
,
createdTableQualifiedName
),
piiTrait
.
getName
());
assertEntityAuditV2
(
createHiveTable
().
getGuid
(),
EntityAuditEventV2
.
EntityAuditActionV2
.
CLASSIFICATION_DELETE
);
}
@Test
public
void
testAddOrUpdateBusinessAttributes
()
throws
Exception
{
Map
<
String
,
Map
<
String
,
Object
>>
businessAttributesMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
bmAttrMapReq
=
new
HashMap
<>();
bmAttrMapReq
.
put
(
"attr8"
,
"01234567890123456789"
);
businessAttributesMap
.
put
(
"bmWithAllTypes"
,
bmAttrMapReq
);
atlasClientV2
.
addOrUpdateBusinessAttributes
(
createHiveTable
().
getGuid
(),
false
,
businessAttributesMap
);
AtlasEntity
.
AtlasEntityWithExtInfo
info
=
atlasClientV2
.
getEntityByGuid
(
createHiveTable
().
getGuid
());
assertNotNull
(
info
);
Map
<
String
,
Map
<
String
,
Object
>>
outputMap
=
info
.
getEntity
().
getBusinessAttributes
();
assertNotNull
(
outputMap
);
assertEquals
(
outputMap
.
get
(
"bmWithAllTypes"
).
size
(),
1
);
}
@Test
(
dependsOnMethods
=
"testAddOrUpdateBusinessAttributes"
)
public
void
testRemoveBusinessAttributes
()
throws
Exception
{
Map
<
String
,
Map
<
String
,
Object
>>
businessAttributesMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
bmAttrMapReq
=
new
HashMap
<>();
bmAttrMapReq
.
put
(
"attr8"
,
"01234567890123456789"
);
businessAttributesMap
.
put
(
"bmWithAllTypes"
,
bmAttrMapReq
);
atlasClientV2
.
removeBusinessAttributes
(
createHiveTable
().
getGuid
(),
businessAttributesMap
);
AtlasEntity
.
AtlasEntityWithExtInfo
info
=
atlasClientV2
.
getEntityByGuid
(
createHiveTable
().
getGuid
());
assertNotNull
(
info
);
Map
<
String
,
Map
<
String
,
Object
>>
outputMap
=
info
.
getEntity
().
getBusinessAttributes
();
assertNull
(
outputMap
);
}
// TODO Enable this test case after fixing addOrUpdateBusinessAttributesByBName API.
@Test
(
enabled
=
false
)
public
void
testAddOrUpdateBusinessAttributesByBName
()
throws
Exception
{
Map
<
String
,
Map
<
String
,
Object
>>
businessAttributesMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
bmAttrMapReq
=
new
HashMap
<>();
bmAttrMapReq
.
put
(
"attr8"
,
"01234567890123456789"
);
businessAttributesMap
.
put
(
"bmWithAllTypes"
,
bmAttrMapReq
);
atlasClientV2
.
addOrUpdateBusinessAttributes
(
createHiveTable
().
getGuid
(),
"bmWithAllTypes"
,
businessAttributesMap
);
AtlasEntity
.
AtlasEntityWithExtInfo
info
=
atlasClientV2
.
getEntityByGuid
(
createHiveTable
().
getGuid
());
assertNotNull
(
info
);
Map
<
String
,
Map
<
String
,
Object
>>
outputMap
=
info
.
getEntity
().
getBusinessAttributes
();
assertNotNull
(
outputMap
);
assertEquals
(
outputMap
.
get
(
"bmWithAllTypes"
).
size
(),
1
);
}
// TODO Enable this test case after fixing addOrUpdateBusinessAttributesByBName API.
@Test
(
enabled
=
false
,
dependsOnMethods
=
"testAddOrUpdateBusinessAttributesByBName"
)
public
void
testRemoveBusinessAttributesByBName
()
throws
Exception
{
Map
<
String
,
Map
<
String
,
Object
>>
businessAttributesMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
bmAttrMapReq
=
new
HashMap
<>();
bmAttrMapReq
.
put
(
"attr8"
,
"01234567890123456789"
);
businessAttributesMap
.
put
(
"bmWithAllTypes"
,
bmAttrMapReq
);
atlasClientV2
.
removeBusinessAttributes
(
createHiveTable
().
getGuid
(),
"bmWithAllTypes"
,
businessAttributesMap
);
AtlasEntity
.
AtlasEntityWithExtInfo
info
=
atlasClientV2
.
getEntityByGuid
(
createHiveTable
().
getGuid
());
assertNotNull
(
info
);
Map
<
String
,
Map
<
String
,
Object
>>
outputMap
=
info
.
getEntity
().
getBusinessAttributes
();
assertNull
(
outputMap
);
}
@Test
public
void
testAddLabelsByTypeName
()
throws
Exception
{
createdDBName
=
(
String
)
createHiveDB
().
getAttribute
(
NAME
);
Set
<
String
>
labels
=
new
HashSet
<>();
labels
.
add
(
"labelByTypeName"
);
atlasClientV2
.
addLabels
(
createHiveDB
().
getTypeName
(),
toMap
(
NAME
,
createdDBName
),
labels
);
AtlasEntityWithExtInfo
info
=
atlasClientV2
.
getEntityByGuid
(
createHiveDB
().
getGuid
(),
false
,
true
);
assertNotNull
(
info
);
assertNotNull
(
info
.
getEntity
().
getLabels
());
assertEquals
(
info
.
getEntity
().
getLabels
().
size
(),
1
);
}
@Test
(
dependsOnMethods
=
"testAddLabelsByTypeName"
)
public
void
testSetLabelsByTypeName
()
throws
Exception
{
createdDBName
=
(
String
)
createHiveDB
().
getAttribute
(
NAME
);
Set
<
String
>
labels
=
new
HashSet
<>();
labels
.
add
(
"labelByTypeNameNext"
);
atlasClientV2
.
setLabels
(
createHiveDB
().
getTypeName
(),
toMap
(
NAME
,
createdDBName
),
labels
);
AtlasEntityWithExtInfo
infoForSet
=
atlasClientV2
.
getEntityByGuid
(
createHiveDB
().
getGuid
(),
false
,
true
);
assertNotNull
(
infoForSet
);
assertNotNull
(
infoForSet
.
getEntity
().
getLabels
());
assertEquals
(
infoForSet
.
getEntity
().
getLabels
().
size
(),
2
);
}
@Test
(
dependsOnMethods
=
"testSetLabelsByTypeName"
)
public
void
testDeleteLabelsByTypeName
()
throws
Exception
{
Set
<
String
>
labels
=
new
HashSet
<>();
labels
.
add
(
"labelByTypeNameNext"
);
createdDBName
=
(
String
)
createHiveDB
().
getAttribute
(
NAME
);
atlasClientV2
.
removeLabels
(
createHiveDB
().
getTypeName
(),
toMap
(
NAME
,
createdDBName
),
labels
);
AtlasEntityWithExtInfo
info
=
atlasClientV2
.
getEntityByGuid
(
createHiveDB
().
getGuid
(),
false
,
true
);
assertNotNull
(
info
);
assertNotNull
(
info
.
getEntity
().
getLabels
());
assertEquals
(
info
.
getEntity
().
getLabels
().
size
(),
1
);
}
@Test
()
public
void
testAddClassification
()
throws
Exception
{
traitName
=
"PII_Trait"
+
randomString
();
AtlasClassificationDef
piiTrait
=
AtlasTypeUtil
.
createTraitTypeDef
(
traitName
,
Collections
.<
String
>
emptySet
());
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
();
typesDef
.
getClassificationDefs
().
add
(
piiTrait
);
createType
(
typesDef
);
ClassificationAssociateRequest
request
=
new
ClassificationAssociateRequest
();
request
.
setEntityGuids
(
Arrays
.
asList
(
createHiveTable
().
getGuid
(),
createHiveDB
().
getGuid
()));
request
.
setClassification
(
new
AtlasClassification
(
piiTrait
.
getName
()));
atlasClientV2
.
addClassification
(
request
);
assertEntityAuditV2
(
createHiveTable
().
getGuid
(),
EntityAuditEventV2
.
EntityAuditActionV2
.
CLASSIFICATION_ADD
);
assertEntityAuditV2
(
createHiveDB
().
getGuid
(),
EntityAuditEventV2
.
EntityAuditActionV2
.
CLASSIFICATION_ADD
);
AtlasClassifications
classificationsTable
=
atlasClientV2
.
getEntityClassifications
(
createHiveTable
().
getGuid
(),
piiTrait
.
getName
());
assertNotNull
(
classificationsTable
);
AtlasClassifications
classificationsDB
=
atlasClientV2
.
getEntityClassifications
(
createHiveDB
().
getGuid
(),
piiTrait
.
getName
());
assertNotNull
(
classificationsDB
);
}
@Test
()
public
void
testDeleteClassifications
()
throws
Exception
{
final
String
guid
=
createHiveTable
().
getGuid
();
try
{
atlasClientV2
.
deleteClassifications
(
guid
,
Arrays
.
asList
(
new
AtlasClassification
(
getAndAddClassification
().
getName
()),
new
AtlasClassification
(
getAndAddClassification
().
getName
())));
}
catch
(
AtlasServiceException
ex
)
{
fail
(
"Deletion should've succeeded"
);
}
assertEntityAudit
(
guid
,
EntityAuditEvent
.
EntityAuditAction
.
TAG_DELETE
);
}
@Test
()
public
void
testRemoveEntityClassificationByGuid
()
throws
Exception
{
final
String
guid
=
createHiveTable
().
getGuid
();
try
{
String
name
=
getAndAddClassification
().
getName
();
atlasClientV2
.
removeClassification
(
guid
,
name
,
guid
);
}
catch
(
AtlasServiceException
ex
)
{
fail
(
"Deletion should've succeeded"
);
}
assertEntityAudit
(
guid
,
EntityAuditEvent
.
EntityAuditAction
.
TAG_DELETE
);
}
@Test
()
public
void
testProduceTemplate
()
{
try
{
String
template
=
atlasClientV2
.
getTemplateForBulkUpdateBusinessAttributes
();
assertNotNull
(
template
);
}
catch
(
AtlasServiceException
ex
)
{
fail
(
"Deletion should've succeeded"
);
}
}
//TODO Enable this test after fixing the BulkImportResponse Deserialization issue.
@Test
(
dependsOnMethods
=
"testSubmitEntity"
,
enabled
=
false
)
public
void
testImportBMAttributes
()
throws
AtlasServiceException
{
BulkImportResponse
response
=
atlasClientV2
.
bulkUpdateBusinessAttributes
(
TestResourceFileUtils
.
getTestFilePath
(
"template_metadata.csv"
));
assertNotNull
(
response
);
}
private
void
createImportFile
()
throws
Exception
{
try
{
String
filePath
=
TestResourceFileUtils
.
getTestFilePath
(
"template_metadata.csv"
);
String
dbName
=
(
String
)
createHiveTable
().
getAttribute
(
"name"
);
String
header
=
"TypeName,UniqueAttributeValue,BusinessAttributeName,BusinessAttributeValue,UniqueAttributeName[optional]"
;
String
values
=
"hive_table_v2,"
+
dbName
+
",bmWithAllTypes.attr8,\"Awesome Attribute 1\",qualifiedName"
;
File
tempFile
=
new
File
(
filePath
);
FileUtils
.
writeLines
(
tempFile
,
Arrays
.
asList
(
header
,
values
));
}
catch
(
IOException
e
)
{
fail
(
"Should have created file"
);
throw
new
AtlasServiceException
(
e
);
}
}
private
void
assertEntityAudit
(
String
dbid
,
EntityAuditEvent
.
EntityAuditAction
auditAction
)
throws
Exception
{
List
<
EntityAuditEvent
>
events
=
atlasClientV1
.
getEntityAuditEvents
(
dbid
,
(
short
)
100
);
for
(
EntityAuditEvent
event
:
events
)
{
if
(
event
.
getAction
()
==
auditAction
)
{
return
;
}
}
fail
(
"Expected audit event with action = "
+
auditAction
);
}
private
void
assertEntityAuditV2
(
String
guid
,
EntityAuditEventV2
.
EntityAuditActionV2
auditAction
)
throws
Exception
{
// Passing auditAction as "null" as this feature is not added for InMemoryEntityRepository for IT testing.
List
<
EntityAuditEventV2
>
events
=
atlasClientV2
.
getAuditEvents
(
guid
,
""
,
null
,
(
short
)
100
);
assertNotNull
(
events
);
assertNotEquals
(
events
.
size
(),
0
);
ObjectMapper
mapper
=
new
ObjectMapper
();
List
<
EntityAuditEventV2
>
auditEventV2s
=
mapper
.
convertValue
(
events
,
new
TypeReference
<
List
<
EntityAuditEventV2
>>()
{
});
for
(
EntityAuditEventV2
event
:
auditEventV2s
)
{
if
(
event
.
getAction
()
==
auditAction
)
{
return
;
}
}
fail
(
"Expected audit event with action = "
+
auditAction
);
}
private
void
addProperty
(
String
guid
,
String
property
,
Object
value
)
throws
AtlasServiceException
{
AtlasEntity
entityByGuid
=
getEntityByGuid
(
guid
);
entityByGuid
.
setAttribute
(
property
,
value
);
EntityMutationResponse
response
=
atlasClientV2
.
updateEntity
(
new
AtlasEntityWithExtInfo
(
entityByGuid
));
assertNotNull
(
response
);
assertNotNull
(
response
.
getEntitiesByOperation
(
EntityMutations
.
EntityOperation
.
UPDATE
));
}
private
AtlasEntity
createHiveDB
()
{
if
(
dbEntity
==
null
)
{
dbEntity
=
createHiveDB
(
DATABASE_NAME
);
}
return
dbEntity
;
}
private
AtlasEntity
createHiveDB
(
String
dbName
)
{
AtlasEntity
hiveDBInstanceV2
=
createHiveDBInstanceV2
(
dbName
);
AtlasEntityHeader
entityHeader
=
createEntity
(
hiveDBInstanceV2
);
assertNotNull
(
entityHeader
);
assertNotNull
(
entityHeader
.
getGuid
());
hiveDBInstanceV2
.
setGuid
(
entityHeader
.
getGuid
());
return
hiveDBInstanceV2
;
}
private
TypesUtil
.
Pair
<
AtlasEntity
,
AtlasEntity
>
createDBAndTable
()
throws
Exception
{
AtlasEntity
dbInstanceV2
=
createHiveDB
();
AtlasEntity
hiveTableInstanceV2
=
createHiveTable
();
return
TypesUtil
.
Pair
.
of
(
dbInstanceV2
,
hiveTableInstanceV2
);
}
private
AtlasEntity
createHiveTable
()
throws
Exception
{
if
(
tableEntity
==
null
)
{
tableEntity
=
createHiveTable
(
createHiveDB
(),
TABLE_NAME
);
}
return
tableEntity
;
}
private
AtlasEntity
createHiveTable
(
AtlasEntity
dbInstanceV2
,
String
tableName
)
throws
Exception
{
AtlasEntity
hiveTableInstanceV2
=
createHiveTableInstanceV2
(
dbInstanceV2
,
tableName
);
AtlasEntityHeader
createdHeader
=
createEntity
(
hiveTableInstanceV2
);
assertNotNull
(
createdHeader
);
assertNotNull
(
createdHeader
.
getGuid
());
hiveTableInstanceV2
.
setGuid
(
createdHeader
.
getGuid
());
tableEntity
=
hiveTableInstanceV2
;
return
hiveTableInstanceV2
;
}
private
AtlasClassificationDef
getAndAddClassification
()
throws
Exception
{
String
traitNameNext
=
"PII_Trait"
+
randomString
();
AtlasClassificationDef
piiTrait
=
AtlasTypeUtil
.
createTraitTypeDef
(
traitNameNext
,
Collections
.<
String
>
emptySet
());
AtlasTypesDef
typesDef
=
new
AtlasTypesDef
();
typesDef
.
getClassificationDefs
().
add
(
piiTrait
);
createType
(
typesDef
);
atlasClientV2
.
addClassifications
(
createHiveTable
().
getGuid
(),
Collections
.
singletonList
(
new
AtlasClassification
(
piiTrait
.
getName
())));
assertEntityAudit
(
createHiveTable
().
getGuid
(),
EntityAuditEvent
.
EntityAuditAction
.
TAG_ADD
);
AtlasClassifications
classifications
=
atlasClientV2
.
getEntityClassifications
(
createHiveTable
().
getGuid
(),
piiTrait
.
getName
());
assertNotNull
(
classifications
);
return
piiTrait
;
}
private
Map
<
String
,
String
>
toMap
(
final
String
name
,
final
String
value
)
{
return
new
HashMap
<
String
,
String
>()
{{
put
(
name
,
value
);
...
...
@@ -852,4 +1185,18 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
db
.
setAttribute
(
"description"
,
randomString
());
return
createEntity
(
db
);
}
private
String
random
()
{
return
RandomStringUtils
.
random
(
10
);
}
private
String
randomUTF8
()
throws
Exception
{
String
ret
=
random
();
if
(!
StandardCharsets
.
UTF_8
.
equals
(
Charset
.
defaultCharset
()))
{
ret
=
new
String
(
ret
.
getBytes
(),
StandardCharsets
.
UTF_8
.
name
());
}
return
ret
;
}
}
webapp/src/test/java/org/apache/atlas/web/integration/GlossaryClientV2IT.java
0 → 100644
View file @
8827bfb4
/**
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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
.
integration
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.sun.jersey.api.client.ClientResponse
;
import
org.apache.atlas.AtlasClientV2
;
import
org.apache.atlas.AtlasServiceException
;
import
org.apache.atlas.model.glossary.AtlasGlossary
;
import
org.apache.atlas.model.glossary.AtlasGlossaryCategory
;
import
org.apache.atlas.model.glossary.AtlasGlossaryTerm
;
import
org.apache.atlas.model.glossary.enums.AtlasTermRelationshipStatus
;
import
org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader
;
import
org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader
;
import
org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader
;
import
org.apache.atlas.model.instance.AtlasEntity
;
import
org.apache.atlas.model.instance.AtlasEntityHeader
;
import
org.apache.atlas.model.instance.AtlasRelatedObjectId
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.utils.AuthenticationUtil
;
import
org.apache.atlas.utils.TestResourceFileUtils
;
import
org.apache.atlas.web.TestUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang.RandomStringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
import
static
org
.
testng
.
Assert
.
assertNull
;
import
static
org
.
testng
.
Assert
.
fail
;
public
class
GlossaryClientV2IT
extends
BaseResourceIT
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GlossaryClientV2IT
.
class
);
private
static
final
ObjectMapper
mapper
=
new
ObjectMapper
();
private
AtlasTypesDef
typeDefinitions
;
private
AtlasClientV2
clientV2
;
private
AtlasGlossary
educationGlossary
,
healthCareGlossary
;
private
AtlasGlossaryTerm
educationTerm
,
schoolEducationTerm
;
private
AtlasGlossaryCategory
educationCategory
;
private
List
<
AtlasRelatedObjectId
>
relatedObjectIds
;
private
AtlasEntityHeader
entityHeader
;
@BeforeClass
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
typeDefinitions
=
setForGlossary
();
createType
(
typeDefinitions
);
if
(!
AuthenticationUtil
.
isKerberosAuthenticationEnabled
())
{
clientV2
=
new
AtlasClientV2
(
atlasUrls
,
new
String
[]{
"admin"
,
"admin"
});
}
else
{
clientV2
=
new
AtlasClientV2
(
atlasUrls
);
}
}
@AfterClass
public
void
tearDown
()
throws
Exception
{
emptyTypeDefs
(
typeDefinitions
);
}
@Test
public
void
testCreateGlossary
()
throws
Exception
{
educationGlossary
=
createAndGetGlossary
(
"Education"
);
assertNotNull
(
educationGlossary
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testGetGlossaryByGuid
()
throws
Exception
{
healthCareGlossary
=
createAndGetGlossary
(
"HealthCare"
);
AtlasGlossary
atlasGlossaryByGuid
=
atlasClientV2
.
getGlossaryByGuid
(
healthCareGlossary
.
getGuid
());
assertNotNull
(
atlasGlossaryByGuid
);
assertEquals
(
healthCareGlossary
.
getGuid
(),
atlasGlossaryByGuid
.
getGuid
());
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testGetDetailGlossary
()
throws
Exception
{
AtlasGlossary
.
AtlasGlossaryExtInfo
extInfo
=
atlasClientV2
.
getGlossaryExtInfo
(
educationGlossary
.
getGuid
());
assertNotNull
(
extInfo
);
assertEquals
(
educationGlossary
.
getGuid
(),
extInfo
.
getGuid
());
}
@Test
(
dependsOnMethods
=
"testGetGlossaryByGuid"
)
public
void
getAllGlossary
()
throws
Exception
{
List
<
AtlasGlossary
>
list
=
atlasClientV2
.
getAllGlossaries
(
"ASC"
,
5
,
0
);
assertNotNull
(
list
);
assertEquals
(
list
.
size
(),
2
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
updateGlossaryByGuid
()
throws
Exception
{
AtlasGlossary
newGlossary
=
new
AtlasGlossary
();
newGlossary
.
setLanguage
(
"English"
);
newGlossary
.
setName
(
"updateGlossary"
);
AtlasGlossary
updated
=
atlasClientV2
.
updateGlossaryByGuid
(
educationGlossary
.
getGuid
(),
newGlossary
);
assertNotNull
(
updated
);
assertEquals
(
updated
.
getGuid
(),
educationGlossary
.
getGuid
());
assertEquals
(
updated
.
getLanguage
(),
newGlossary
.
getLanguage
());
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testCreateTerm
()
throws
Exception
{
AtlasGlossaryTerm
term
=
new
AtlasGlossaryTerm
();
AtlasGlossaryHeader
header
=
new
AtlasGlossaryHeader
();
header
.
setGlossaryGuid
(
educationGlossary
.
getGuid
());
header
.
setDisplayText
(
educationGlossary
.
getName
());
term
.
setAnchor
(
header
);
term
.
setName
(
"termForEducation"
);
educationTerm
=
atlasClientV2
.
createGlossaryTerm
(
term
);
assertNotNull
(
educationTerm
);
assertNotNull
(
educationTerm
.
getGuid
());
}
@Test
(
dependsOnMethods
=
"testCreateTerm"
)
public
void
testGetGlossaryTerm
()
throws
Exception
{
AtlasGlossaryTerm
term
=
atlasClientV2
.
getGlossaryTerm
(
educationTerm
.
getGuid
());
assertNotNull
(
term
);
assertEquals
(
term
.
getGuid
(),
educationTerm
.
getGuid
());
}
@Test
(
dependsOnMethods
=
"testCreateTerm"
)
public
void
testGetGlossaryTerms
()
throws
Exception
{
AtlasRelatedTermHeader
relatedTermHeader
=
new
AtlasRelatedTermHeader
();
relatedTermHeader
.
setTermGuid
(
educationTerm
.
getGuid
());
relatedTermHeader
.
setDescription
(
"test description"
);
relatedTermHeader
.
setExpression
(
"test expression"
);
relatedTermHeader
.
setSource
(
"School"
);
relatedTermHeader
.
setSteward
(
"School"
);
relatedTermHeader
.
setStatus
(
AtlasTermRelationshipStatus
.
ACTIVE
);
schoolEducationTerm
=
new
AtlasGlossaryTerm
();
AtlasGlossaryHeader
header
=
new
AtlasGlossaryHeader
();
header
.
setGlossaryGuid
(
educationGlossary
.
getGuid
());
header
.
setDisplayText
(
educationGlossary
.
getName
());
schoolEducationTerm
.
setAnchor
(
header
);
schoolEducationTerm
.
setName
(
"termForSchool"
);
schoolEducationTerm
.
setSeeAlso
(
Collections
.
singleton
(
relatedTermHeader
));
schoolEducationTerm
=
clientV2
.
createGlossaryTerm
(
schoolEducationTerm
);
assertNotNull
(
schoolEducationTerm
);
assertNotNull
(
schoolEducationTerm
.
getGuid
());
//Getting multiple terms
List
<
AtlasGlossaryTerm
>
terms
=
atlasClientV2
.
getGlossaryTerms
(
educationGlossary
.
getGuid
(),
"ASC"
,
2
,
0
);
assertNotNull
(
terms
);
assertEquals
(
terms
.
size
(),
2
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testCreateGlossaryCategory
()
throws
Exception
{
AtlasGlossaryCategory
category
=
new
AtlasGlossaryCategory
();
AtlasGlossaryHeader
header
=
new
AtlasGlossaryHeader
();
header
.
setGlossaryGuid
(
educationGlossary
.
getGuid
());
header
.
setDisplayText
(
educationGlossary
.
getName
());
category
.
setAnchor
(
header
);
category
.
setName
(
"categoryForEducation"
);
educationCategory
=
atlasClientV2
.
createGlossaryCategory
(
category
);
assertNotNull
(
educationCategory
);
assertNotNull
(
educationCategory
.
getGuid
());
}
@Test
(
dependsOnMethods
=
"testCreateGlossaryCategory"
)
public
void
testCreateGlossaryCategories
()
throws
Exception
{
List
<
AtlasGlossaryCategory
>
glossaryCategories
=
new
ArrayList
<>();
AtlasGlossaryCategory
category1
=
new
AtlasGlossaryCategory
();
AtlasGlossaryHeader
header1
=
new
AtlasGlossaryHeader
();
header1
.
setGlossaryGuid
(
healthCareGlossary
.
getGuid
());
header1
.
setDisplayText
(
healthCareGlossary
.
getName
());
category1
.
setAnchor
(
header1
);
category1
.
setName
(
"category1ForEducation"
);
glossaryCategories
.
add
(
category1
);
//Setting different category
AtlasGlossaryCategory
category2
=
new
AtlasGlossaryCategory
();
category2
.
setAnchor
(
header1
);
category2
.
setName
(
"category2ForEducation"
);
glossaryCategories
.
add
(
category2
);
List
<
AtlasGlossaryCategory
>
list
=
atlasClientV2
.
createGlossaryCategories
(
glossaryCategories
);
assertNotNull
(
list
);
assertEquals
(
list
.
size
(),
2
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossaryCategory"
)
public
void
testGetGlossaryByCategory
()
throws
Exception
{
AtlasGlossaryCategory
atlasGlossaryCategory
=
atlasClientV2
.
getGlossaryCategory
(
educationCategory
.
getGuid
());
assertNotNull
(
atlasGlossaryCategory
);
assertEquals
(
atlasGlossaryCategory
.
getGuid
(),
educationCategory
.
getGuid
());
}
@Test
(
dependsOnMethods
=
"testGetGlossaryByGuid"
)
public
void
testCreateGlossaryTerms
()
throws
Exception
{
List
<
AtlasGlossaryTerm
>
list
=
new
ArrayList
<>();
int
index
=
0
;
List
<
AtlasGlossary
>
glossaries
=
atlasClientV2
.
getAllGlossaries
(
"ASC"
,
5
,
0
);
List
<
AtlasGlossary
>
glossaryList
=
mapper
.
convertValue
(
glossaries
,
new
TypeReference
<
List
<
AtlasGlossary
>>()
{
});
for
(
AtlasGlossary
glossary
:
glossaryList
)
{
AtlasGlossaryTerm
term
=
new
AtlasGlossaryTerm
();
AtlasGlossaryHeader
header
=
new
AtlasGlossaryHeader
();
header
.
setGlossaryGuid
(
glossary
.
getGuid
());
header
.
setDisplayText
(
glossary
.
getName
());
term
.
setAnchor
(
header
);
term
.
setName
(
"termName"
+
index
);
list
.
add
(
term
);
index
++;
}
List
<
AtlasGlossaryTerm
>
termList
=
atlasClientV2
.
createGlossaryTerms
(
list
);
assertNotNull
(
termList
);
assertEquals
(
termList
.
size
(),
2
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testPartialUpdateGlossaryByGuid
()
throws
Exception
{
Map
<
String
,
String
>
partialUpdates
=
new
HashMap
<>();
partialUpdates
.
put
(
"shortDescription"
,
"shortDescription"
);
partialUpdates
.
put
(
"longDescription"
,
"longDescription"
);
AtlasGlossary
atlasGlossary
=
atlasClientV2
.
partialUpdateGlossaryByGuid
(
educationGlossary
.
getGuid
(),
partialUpdates
);
assertNotNull
(
atlasGlossary
);
assertEquals
(
atlasGlossary
.
getShortDescription
(),
"shortDescription"
);
assertEquals
(
atlasGlossary
.
getLongDescription
(),
"longDescription"
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testUpdateGlossaryTermByGuid
()
throws
Exception
{
AtlasGlossaryTerm
term
=
new
AtlasGlossaryTerm
(
educationTerm
);
term
.
setAbbreviation
(
"trm"
);
AtlasGlossaryTerm
responseTerm
=
atlasClientV2
.
updateGlossaryTermByGuid
(
educationTerm
.
getGuid
(),
term
);
assertNotNull
(
responseTerm
);
assertEquals
(
responseTerm
.
getAbbreviation
(),
term
.
getAbbreviation
());
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testUpdateGlossaryCategoryByGuid
()
throws
Exception
{
AtlasGlossaryCategory
category
=
new
AtlasGlossaryCategory
(
educationCategory
);
category
.
setLongDescription
(
"this is about category"
);
AtlasGlossaryCategory
responseCategory
=
atlasClientV2
.
updateGlossaryCategoryByGuid
(
educationCategory
.
getGuid
(),
category
);
assertNotNull
(
responseCategory
);
assertEquals
(
responseCategory
.
getLongDescription
(),
category
.
getLongDescription
());
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testPartialUpdateTermByGuid
()
throws
Exception
{
Map
<
String
,
String
>
partialUpdates
=
new
HashMap
<>();
partialUpdates
.
put
(
"shortDescription"
,
"shortDescriptionTerm"
);
partialUpdates
.
put
(
"longDescription"
,
"longDescriptionTerm"
);
AtlasGlossaryTerm
term
=
atlasClientV2
.
partialUpdateTermByGuid
(
educationTerm
.
getGuid
(),
partialUpdates
);
assertNotNull
(
term
);
assertEquals
(
term
.
getShortDescription
(),
"shortDescriptionTerm"
);
assertEquals
(
term
.
getLongDescription
(),
"longDescriptionTerm"
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testPartialUpdateCategoryByGuid
()
throws
Exception
{
Map
<
String
,
String
>
partialUpdates
=
new
HashMap
<>();
partialUpdates
.
put
(
"shortDescription"
,
"shortDescriptionCategory"
);
partialUpdates
.
put
(
"longDescription"
,
"longDescriptionCategory"
);
AtlasGlossaryCategory
category
=
atlasClientV2
.
partialUpdateCategoryByGuid
(
educationCategory
.
getGuid
(),
partialUpdates
);
assertNotNull
(
category
);
assertEquals
(
category
.
getShortDescription
(),
"shortDescriptionCategory"
);
assertEquals
(
category
.
getLongDescription
(),
"longDescriptionCategory"
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testGetGlossaryTermHeadersByGuid
()
throws
Exception
{
List
<
AtlasRelatedTermHeader
>
list
=
atlasClientV2
.
getGlossaryTermHeaders
(
educationGlossary
.
getGuid
(),
"ASC"
,
2
,
0
);
assertNotNull
(
list
);
assertEquals
(
list
.
size
(),
1
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossaryCategories"
)
public
void
testGetGlossaryCategoriesByGuid
()
throws
Exception
{
List
<
AtlasGlossaryCategory
>
list
=
atlasClientV2
.
getGlossaryCategories
(
healthCareGlossary
.
getGuid
(),
"ASC"
,
2
,
0
);
assertNotNull
(
list
);
assertEquals
(
list
.
size
(),
2
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossaryCategories"
)
public
void
testGetGlossaryCategoryHeaders
()
throws
Exception
{
List
<
AtlasRelatedCategoryHeader
>
list
=
atlasClientV2
.
getGlossaryCategoryHeaders
(
healthCareGlossary
.
getGuid
(),
"ASC"
,
2
,
0
);
assertNotNull
(
list
);
assertEquals
(
list
.
size
(),
2
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testGetCategoryTerms
()
throws
Exception
{
List
<
AtlasRelatedTermHeader
>
list
=
atlasClientV2
.
getCategoryTerms
(
educationCategory
.
getGuid
(),
"ASC"
,
2
,
0
);
assertNotNull
(
list
);
assertEquals
(
list
.
size
(),
0
);
}
@Test
(
dependsOnMethods
=
"testCreateGlossary"
)
public
void
testGetAllRelatedTerms
()
throws
Exception
{
Map
<
AtlasGlossaryTerm
.
Relation
,
Set
<
AtlasRelatedTermHeader
>>
map
=
atlasClientV2
.
getRelatedTerms
(
educationTerm
.
getGuid
(),
"ASC"
,
2
,
0
);
assertNotNull
(
map
);
}
@Test
(
dependsOnMethods
=
"testCreateTerm"
)
public
void
testAssignTermToEntities
()
throws
Exception
{
try
{
AtlasEntity
entity
=
new
AtlasEntity
(
"Asset"
);
entity
.
setAttribute
(
"qualifiedName"
,
"testAsset"
);
entity
.
setAttribute
(
"name"
,
"testAsset"
);
if
(
entityHeader
==
null
)
{
entityHeader
=
createEntity
(
entity
);
}
AtlasRelatedObjectId
relatedObjectId
=
new
AtlasRelatedObjectId
();
relatedObjectId
.
setGuid
(
entityHeader
.
getGuid
());
relatedObjectId
.
setTypeName
(
entityHeader
.
getTypeName
());
assertNotNull
(
relatedObjectId
);
relatedObjectIds
=
new
ArrayList
<>();
relatedObjectIds
.
add
(
relatedObjectId
);
atlasClientV2
.
assignTermToEntities
(
educationTerm
.
getGuid
(),
relatedObjectIds
);
List
<
AtlasRelatedObjectId
>
assignedEntities
=
atlasClientV2
.
getEntitiesAssignedWithTerm
(
educationTerm
.
getGuid
(),
"ASC"
,
2
,
0
);
assertNotNull
(
assignedEntities
);
assertEquals
(
assignedEntities
.
size
(),
1
);
List
<
AtlasRelatedObjectId
>
entityList
=
mapper
.
convertValue
(
assignedEntities
,
new
TypeReference
<
List
<
AtlasRelatedObjectId
>>()
{
});
String
relationshipGuid
=
entityList
.
get
(
0
).
getRelationshipGuid
();
assertNotNull
(
relationshipGuid
);
relatedObjectId
.
setRelationshipGuid
(
relationshipGuid
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Test
(
dependsOnMethods
=
"testAssignTermToEntities"
)
public
void
testDisassociateTermAssignmentFromEntities
()
throws
Exception
{
atlasClientV2
.
disassociateTermFromEntities
(
educationTerm
.
getGuid
(),
relatedObjectIds
);
AtlasGlossaryTerm
term
=
atlasClientV2
.
getGlossaryTerm
(
educationTerm
.
getGuid
());
atlasClientV2
.
deleteEntityByGuid
(
entityHeader
.
getGuid
());
assertNotNull
(
term
);
assertNull
(
term
.
getAssignedEntities
());
}
@Test
(
dependsOnMethods
=
"testCreateGlossaryCategory"
)
public
void
testGetRelatedCategories
()
throws
Exception
{
Map
<
String
,
List
<
AtlasRelatedCategoryHeader
>>
map
=
atlasClientV2
.
getRelatedCategories
(
educationCategory
.
getGuid
(),
"ASC"
,
1
,
0
);
assertEquals
(
map
.
size
(),
0
);
}
@Test
(
dependsOnMethods
=
"testDeleteGlossaryTerm"
)
public
void
testDeleteGlossary
()
throws
Exception
{
emptyTypeDefs
(
typeDefinitions
);
atlasClientV2
.
deleteGlossaryByGuid
(
educationGlossary
.
getGuid
());
atlasClientV2
.
deleteGlossaryByGuid
(
healthCareGlossary
.
getGuid
());
try
{
atlasClientV2
.
getGlossaryByGuid
(
healthCareGlossary
.
getGuid
());
}
catch
(
AtlasServiceException
ex
)
{
assertNotNull
(
ex
.
getStatus
());
assertEquals
(
ex
.
getStatus
(),
ClientResponse
.
Status
.
NOT_FOUND
);
}
try
{
atlasClientV2
.
getGlossaryByGuid
(
educationGlossary
.
getGuid
());
}
catch
(
AtlasServiceException
ex
)
{
assertNotNull
(
ex
.
getStatus
());
assertEquals
(
ex
.
getStatus
(),
ClientResponse
.
Status
.
NOT_FOUND
);
}
}
@Test
(
dependsOnMethods
=
"testDisassociateTermAssignmentFromEntities"
)
public
void
testDeleteGlossaryTerm
()
throws
Exception
{
atlasClientV2
.
deleteGlossaryTermByGuid
(
educationTerm
.
getGuid
());
try
{
atlasClientV2
.
getGlossaryTerm
(
educationTerm
.
getGuid
());
}
catch
(
AtlasServiceException
ex
)
{
assertNotNull
(
ex
.
getStatus
());
assertEquals
(
ex
.
getStatus
(),
ClientResponse
.
Status
.
NOT_FOUND
);
}
}
@Test
(
dependsOnMethods
=
"testGetRelatedCategories"
)
public
void
testDeleteGlossaryCategory
()
throws
Exception
{
atlasClientV2
.
deleteGlossaryCategoryByGuid
(
educationCategory
.
getGuid
());
try
{
atlasClientV2
.
getGlossaryCategory
(
educationCategory
.
getGuid
());
}
catch
(
AtlasServiceException
ex
)
{
assertNotNull
(
ex
.
getStatus
());
assertEquals
(
ex
.
getStatus
(),
ClientResponse
.
Status
.
NOT_FOUND
);
}
}
@Test
()
public
void
testProduceTemplate
()
{
try
{
String
template
=
atlasClientV2
.
getGlossaryImportTemplate
();
assertNotNull
(
template
);
}
catch
(
AtlasServiceException
ex
)
{
fail
(
"Deletion should've succeeded"
);
}
}
@Test
()
public
void
testImportGlossaryData
()
{
try
{
String
filePath
=
TestResourceFileUtils
.
getTestFilePath
(
"template.csv"
);
List
<
AtlasGlossaryTerm
>
terms
=
atlasClientV2
.
importGlossary
(
filePath
);
assertNotNull
(
terms
);
List
<
AtlasGlossaryTerm
>
termList
=
mapper
.
convertValue
(
terms
,
new
TypeReference
<
List
<
AtlasGlossaryTerm
>>()
{
});
assertEquals
(
terms
.
size
(),
1
);
AtlasGlossaryTerm
createdTerm
=
termList
.
get
(
0
);
String
glossaryGuid
=
createdTerm
.
getAnchor
().
getGlossaryGuid
();
atlasClientV2
.
deleteGlossaryByGuid
(
glossaryGuid
);
}
catch
(
AtlasServiceException
ex
)
{
fail
(
"Import GlossaryData should've succeeded"
);
}
}
private
AtlasGlossary
createAndGetGlossary
(
String
name
)
throws
Exception
{
AtlasGlossary
atlasGlossary
=
new
AtlasGlossary
();
atlasGlossary
.
setName
(
name
);
return
atlasClientV2
.
createGlossary
(
atlasGlossary
);
}
private
void
emptyTypeDefs
(
AtlasTypesDef
def
)
{
def
.
getEnumDefs
().
clear
();
def
.
getStructDefs
().
clear
();
def
.
getClassificationDefs
().
clear
();
def
.
getEntityDefs
().
clear
();
def
.
getRelationshipDefs
().
clear
();
def
.
getBusinessMetadataDefs
().
clear
();
}
private
AtlasTypesDef
setForGlossary
()
throws
IOException
{
String
filePath
=
TestUtils
.
getGlossaryType
();
String
json
=
FileUtils
.
readFileToString
(
new
File
(
filePath
));
return
AtlasType
.
fromJson
(
json
,
AtlasTypesDef
.
class
);
}
protected
String
randomString
()
{
//names cannot start with a digit
return
RandomStringUtils
.
randomAlphabetic
(
1
)
+
RandomStringUtils
.
randomAlphanumeric
(
9
);
}
}
webapp/src/test/java/org/apache/atlas/web/integration/LineageClientV2IT.java
0 → 100644
View file @
8827bfb4
/**
* 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
.
integration
;
import
org.apache.atlas.model.instance.AtlasEntityHeader
;
import
org.apache.atlas.model.lineage.AtlasLineageInfo
;
import
org.apache.atlas.v1.model.instance.Id
;
import
org.apache.atlas.v1.model.instance.Referenceable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
static
org
.
apache
.
atlas
.
AtlasClient
.
REFERENCEABLE_ATTRIBUTE_NAME
;
/**
* Entity Lineage v2 Integration Tests.
*/
public
class
LineageClientV2IT
extends
DataSetLineageJerseyResourceIT
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
LineageClientV2IT
.
class
);
private
String
salesFactTable
;
private
String
salesMonthlyTable
;
private
String
salesDBName
;
@BeforeClass
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
createTypeDefinitionsV1
();
setupInstances
();
}
@Test
public
void
testGetLineageInfo
()
throws
Exception
{
String
tableId
=
atlasClientV1
.
getEntity
(
HIVE_TABLE_TYPE
,
REFERENCEABLE_ATTRIBUTE_NAME
,
salesMonthlyTable
).
getId
().
_getId
();
AtlasLineageInfo
inputLineageInfo
=
atlasClientV2
.
getLineageInfo
(
tableId
,
AtlasLineageInfo
.
LineageDirection
.
INPUT
,
5
);
Assert
.
assertNotNull
(
inputLineageInfo
);
Map
<
String
,
AtlasEntityHeader
>
entities
=
inputLineageInfo
.
getGuidEntityMap
();
Assert
.
assertNotNull
(
entities
);
Set
<
AtlasLineageInfo
.
LineageRelation
>
relations
=
inputLineageInfo
.
getRelations
();
Assert
.
assertNotNull
(
relations
);
Assert
.
assertEquals
(
entities
.
size
(),
6
);
Assert
.
assertEquals
(
relations
.
size
(),
5
);
Assert
.
assertEquals
(
inputLineageInfo
.
getLineageDirection
(),
AtlasLineageInfo
.
LineageDirection
.
INPUT
);
Assert
.
assertEquals
(
inputLineageInfo
.
getLineageDepth
(),
5
);
Assert
.
assertEquals
(
inputLineageInfo
.
getBaseEntityGuid
(),
tableId
);
}
@Test
public
void
testGetLineageInfoByAttribute
()
throws
Exception
{
Map
<
String
,
String
>
attributeMap
=
new
HashMap
<>();
attributeMap
.
put
(
"qualifiedName"
,
salesMonthlyTable
);
AtlasLineageInfo
bothLineageInfo
=
atlasClientV2
.
getLineageInfo
(
HIVE_TABLE_TYPE
,
attributeMap
,
AtlasLineageInfo
.
LineageDirection
.
BOTH
,
5
);
Assert
.
assertNotNull
(
bothLineageInfo
);
Map
<
String
,
AtlasEntityHeader
>
entities
=
bothLineageInfo
.
getGuidEntityMap
();
Assert
.
assertNotNull
(
entities
);
Set
<
AtlasLineageInfo
.
LineageRelation
>
relations
=
bothLineageInfo
.
getRelations
();
Assert
.
assertNotNull
(
relations
);
Assert
.
assertEquals
(
entities
.
size
(),
6
);
Assert
.
assertEquals
(
relations
.
size
(),
5
);
Assert
.
assertEquals
(
bothLineageInfo
.
getLineageDirection
(),
AtlasLineageInfo
.
LineageDirection
.
BOTH
);
Assert
.
assertEquals
(
bothLineageInfo
.
getLineageDepth
(),
5
);
}
private
void
setupInstances
()
throws
Exception
{
salesDBName
=
"Sales"
+
randomString
();
Id
salesDB
=
database
(
salesDBName
,
"Sales Database"
,
"John ETL"
,
"hdfs://host:8000/apps/warehouse/sales"
);
List
<
Referenceable
>
salesFactColumns
=
Arrays
.
asList
(
column
(
"time_id"
,
"int"
,
"time id"
),
column
(
"product_id"
,
"int"
,
"product id"
),
column
(
"customer_id"
,
"int"
,
"customer id"
),
column
(
"sales"
,
"double"
,
"product id"
));
salesFactTable
=
"sales_fact"
+
randomString
();
Id
salesFact
=
table
(
salesFactTable
,
"sales fact table"
,
salesDB
,
"Joe"
,
"MANAGED"
,
salesFactColumns
);
List
<
Referenceable
>
timeDimColumns
=
Arrays
.
asList
(
column
(
"time_id"
,
"int"
,
"time id"
),
column
(
"dayOfYear"
,
"int"
,
"day Of Year"
),
column
(
"weekDay"
,
"int"
,
"week Day"
));
Id
timeDim
=
table
(
"time_dim"
+
randomString
(),
"time dimension table"
,
salesDB
,
"John Doe"
,
"EXTERNAL"
,
timeDimColumns
);
Id
reportingDB
=
database
(
"Reporting"
+
randomString
(),
"reporting database"
,
"Jane BI"
,
"hdfs://host:8000/apps/warehouse/reporting"
);
Id
salesFactDaily
=
table
(
"sales_fact_daily_mv"
+
randomString
(),
"sales fact daily materialized view"
,
reportingDB
,
"Joe BI"
,
"MANAGED"
,
salesFactColumns
);
loadProcess
(
"loadSalesDaily"
+
randomString
(),
"John ETL"
,
Arrays
.
asList
(
salesFact
,
timeDim
),
Collections
.
singletonList
(
salesFactDaily
),
"create table as select "
,
"plan"
,
"id"
,
"graph"
);
salesMonthlyTable
=
"sales_fact_monthly_mv"
+
randomString
();
Id
salesFactMonthly
=
table
(
salesMonthlyTable
,
"sales fact monthly materialized view"
,
reportingDB
,
"Jane BI"
,
"MANAGED"
,
salesFactColumns
);
loadProcess
(
"loadSalesMonthly"
+
randomString
(),
"John ETL"
,
Collections
.
singletonList
(
salesFactDaily
),
Collections
.
singletonList
(
salesFactMonthly
),
"create table as select "
,
"plan"
,
"id"
,
"graph"
);
}
}
webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java
View file @
8827bfb4
...
...
@@ -20,18 +20,20 @@ package org.apache.atlas.web.integration;
import
com.sun.jersey.core.util.MultivaluedMapImpl
;
import
org.apache.atlas.AtlasClientV2
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.AtlasServiceException
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.model.SearchFilter
;
import
org.apache.atlas.model.TypeCategory
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.model.typedef.AtlasBusinessMetadataDef
;
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.AtlasRelationshipDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef
;
import
org.apache.atlas.model.typedef.AtlasTypeDefHeader
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.type.AtlasTypeUtil
;
import
org.apache.atlas.utils.AuthenticationUtil
;
...
...
@@ -46,6 +48,7 @@ import javax.ws.rs.core.Response;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
static
org
.
apache
.
atlas
.
AtlasErrorCode
.
TYPE_NAME_NOT_FOUND
;
import
static
org
.
apache
.
atlas
.
model
.
typedef
.
AtlasStructDef
.
AtlasAttributeDef
.
Cardinality
;
...
...
@@ -102,6 +105,33 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
for
(
AtlasEntityDef
entityDef
:
typeDefinitions
.
getEntityDefs
())
{
checkIfTypeExists
(
entityDef
.
getName
());
}
for
(
AtlasRelationshipDef
relationshipDef
:
typeDefinitions
.
getRelationshipDefs
())
{
checkIfTypeExists
(
relationshipDef
.
getName
());
}
for
(
AtlasBusinessMetadataDef
businessMetadataDef
:
typeDefinitions
.
getBusinessMetadataDefs
())
{
checkIfTypeExists
(
businessMetadataDef
.
getName
());
}
}
@Test
public
void
testGetHeaders
()
throws
Exception
{
MultivaluedMap
<
String
,
String
>
filterParams
=
new
MultivaluedMapImpl
();
filterParams
.
add
(
SearchFilter
.
PARAM_TYPE
,
"ENTITY"
);
List
<
AtlasTypeDefHeader
>
headers
=
clientV2
.
getAllTypeDefHeaders
(
new
SearchFilter
(
filterParams
));
assertNotNull
(
headers
);
}
@Test
(
dependsOnMethods
=
"testGetDefinition"
)
public
void
testDeleteAtlasTypeByName
()
throws
Exception
{
String
typeName
=
"table"
;
boolean
typeExists
=
atlasClientV2
.
typeWithNameExists
(
typeName
);
if
(
typeExists
)
{
clientV2
.
deleteTypeByName
(
typeName
);
boolean
afterDelete
=
atlasClientV2
.
typeWithNameExists
(
typeName
);
assertEquals
(
afterDelete
,
false
);
}
}
@Test
...
...
@@ -191,9 +221,21 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
verifyByNameAndGUID
(
entityDef
);
}
}
if
(
CollectionUtils
.
isNotEmpty
(
typeDefinitions
.
getRelationshipDefs
()))
{
for
(
AtlasRelationshipDef
relationshipDef
:
typeDefinitions
.
getRelationshipDefs
())
{
verifyByNameAndGUID
(
relationshipDef
);
}
}
@Test
if
(
CollectionUtils
.
isNotEmpty
(
typeDefinitions
.
getBusinessMetadataDefs
()))
{
for
(
AtlasBusinessMetadataDef
businessMetadataDef
:
typeDefinitions
.
getBusinessMetadataDefs
())
{
verifyByNameAndGUID
(
businessMetadataDef
);
}
}
}
@Test
()
public
void
testInvalidGets
()
throws
Exception
{
try
{
AtlasEnumDef
byName
=
clientV2
.
getEnumDefByName
(
"blah"
);
...
...
@@ -259,6 +301,37 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
"Should've returned a 404"
);
}
try
{
AtlasRelationshipDef
byName
=
clientV2
.
getRelationshipDefByName
(
"blah"
);
fail
(
"Get for invalid name should have reported a failure"
);
}
catch
(
AtlasServiceException
e
)
{
assertEquals
(
e
.
getStatus
().
getStatusCode
(),
Response
.
Status
.
NOT_FOUND
.
getStatusCode
(),
"Should've returned a 404"
);
}
try
{
AtlasRelationshipDef
byGuid
=
clientV2
.
getRelationshipDefByGuid
(
"blah"
);
fail
(
"Get for invalid name should have reported a failure"
);
}
catch
(
AtlasServiceException
e
)
{
assertEquals
(
e
.
getStatus
().
getStatusCode
(),
Response
.
Status
.
NOT_FOUND
.
getStatusCode
(),
"Should've returned a 404"
);
}
try
{
AtlasBusinessMetadataDef
byName
=
clientV2
.
getBusinessMetadataDefByName
(
"blah"
);
fail
(
"Get for invalid name should have reported a failure"
);
}
catch
(
AtlasServiceException
e
)
{
assertEquals
(
e
.
getStatus
().
getStatusCode
(),
Response
.
Status
.
NOT_FOUND
.
getStatusCode
(),
"Should've returned a 404"
);
}
try
{
AtlasBusinessMetadataDef
byGuid
=
clientV2
.
getBusinessMetadataDefGuid
(
"blah"
);
fail
(
"Get for invalid name should have reported a failure"
);
}
catch
(
AtlasServiceException
e
)
{
assertEquals
(
e
.
getStatus
().
getStatusCode
(),
Response
.
Status
.
NOT_FOUND
.
getStatusCode
(),
"Should've returned a 404"
);
}
}
...
...
@@ -339,6 +412,10 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
byName
=
clientV2
.
getClassificationDefByName
(
typeDef
.
getName
());
}
else
if
(
typeDef
.
getCategory
()
==
TypeCategory
.
STRUCT
)
{
byName
=
clientV2
.
getStructDefByName
(
typeDef
.
getName
());
}
else
if
(
typeDef
.
getCategory
()
==
TypeCategory
.
RELATIONSHIP
)
{
byName
=
clientV2
.
getRelationshipDefByName
(
typeDef
.
getName
());
}
else
if
(
typeDef
.
getCategory
()
==
TypeCategory
.
BUSINESS_METADATA
)
{
byName
=
clientV2
.
getBusinessMetadataDefByName
(
typeDef
.
getName
());
}
assertNotNull
(
byName
);
}
catch
(
AtlasServiceException
e
)
{
...
...
@@ -355,6 +432,10 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
byGuid
=
clientV2
.
getClassificationDefByGuid
(
typeDef
.
getGuid
());
}
else
if
(
typeDef
.
getCategory
()
==
TypeCategory
.
STRUCT
)
{
byGuid
=
clientV2
.
getStructDefByGuid
(
typeDef
.
getGuid
());
}
else
if
(
typeDef
.
getCategory
()
==
TypeCategory
.
RELATIONSHIP
)
{
byGuid
=
clientV2
.
getRelationshipDefByGuid
(
typeDef
.
getGuid
());
}
else
if
(
typeDef
.
getCategory
()
==
TypeCategory
.
BUSINESS_METADATA
)
{
byGuid
=
clientV2
.
getBusinessMetadataDefGuid
(
typeDef
.
getGuid
());
}
assertNotNull
(
byGuid
);
}
catch
(
AtlasServiceException
e
)
{
...
...
@@ -368,6 +449,8 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
def
.
getStructDefs
().
clear
();
def
.
getClassificationDefs
().
clear
();
def
.
getEntityDefs
().
clear
();
def
.
getRelationshipDefs
().
clear
();
def
.
getBusinessMetadataDefs
().
clear
();
}
private
void
checkIfTypeExists
(
String
typeName
)
throws
Exception
{
...
...
webapp/src/test/resources/json/search-parameters/attribute-filters.json
0 → 100644
View file @
8827bfb4
[
{
"testDescription"
:
"hive_table contains testtable or retentionSize != 0"
,
"searchParameters"
:
{
"typeName"
:
"hive_table"
,
"excludeDeletedEntities"
:
true
,
"classification"
:
""
,
"query"
:
""
,
"limit"
:
25
,
"offset"
:
0
,
"entityFilters"
:
{
"attributeName"
:
"name"
,
"attributeValue"
:
"testtable"
,
"condition"
:
"OR"
,
"criterion"
:
[
{
"attributeName"
:
"name"
,
"operator"
:
"contains"
,
"attributeValue"
:
"testtable"
},
{
"attributeName"
:
"retention"
,
"operator"
:
"neq"
,
"attributeValue"
:
"0"
}
]
},
"tagFilters"
:
null
,
"attributes"
:
[
""
]
},
"expectedCount"
:
3
}]
\ No newline at end of file
webapp/src/test/resources/template.csv
0 → 100644
View file @
8827bfb4
GlossaryName, TermName, ShortDescription, LongDescription, Examples, Abbreviation, Usage, AdditionalAttributes, TranslationTerms, ValidValuesFor, Synonyms, ReplacedBy, ValidValues, ReplacementTerms, SeeAlso, TranslatedTerms, IsA, Antonyms, Classifies, PreferredToTerms, PreferredTerms
testBankingGlossary,BankBranch,SD4,LD4,"EXAMPLE","ABBREVIATION","USAGE",,,,,,,,,,,,,,
\ No newline at end of file
webapp/src/test/resources/template_metadata.csv
0 → 100644
View file @
8827bfb4
TypeName,UniqueAttributeValue,BusinessAttributeName,BusinessAttributeValue,UniqueAttributeName[optional]
hive_table_v2,tableqZPo3C488c,bmWithAllTypes.attr8,"Awesome Attribute 1",qualifiedName
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