This is an automated email from the ASF dual-hosted git repository. madhan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/atlas.git
commit e06db7deaa4a013e7ee64ed52572f63b3f990037 Author: Verdan Mahmood <[email protected]> AuthorDate: Mon Jan 18 13:15:40 2021 -0800 ATLAS-4086: python client fixes - search APIs and others Signed-off-by: Madhan Neethiraj <[email protected]> --- intg/src/main/python/README.md | 5 ++-- intg/src/main/python/apache_atlas/client/admin.py | 5 +--- .../main/python/apache_atlas/client/discovery.py | 34 +++++++++++----------- intg/src/main/python/apache_atlas/client/entity.py | 4 +-- .../main/python/apache_atlas/client/glossary.py | 9 ++++-- .../python/apache_atlas/client/relationship.py | 2 +- .../src/main/python/apache_atlas/client/typedef.py | 1 + .../src/main/python/apache_atlas/model/glossary.py | 15 ++++------ .../src/main/python/apache_atlas/model/instance.py | 15 +++++----- intg/src/main/python/setup.py | 2 +- 10 files changed, 46 insertions(+), 46 deletions(-) diff --git a/intg/src/main/python/README.md b/intg/src/main/python/README.md index a973717..5efc49a 100644 --- a/intg/src/main/python/README.md +++ b/intg/src/main/python/README.md @@ -16,7 +16,7 @@ Verify if apache-atlas client is installed: Package Version ------------ --------- -apache-atlas 0.0.3 +apache-atlas 0.0.4 ``` ## Usage @@ -28,7 +28,8 @@ apache-atlas 0.0.3 import time from apache_atlas.client.base_client import AtlasClient -from apache_atlas.model.instance import * +from apache_atlas.model.instance import AtlasEntity, AtlasEntityWithExtInfo, AtlasEntitiesWithExtInfo, AtlasRelatedObjectId +from apache_atlas.model.enums import EntityOperation ## Step 1: create a client to connect to Apache Atlas server diff --git a/intg/src/main/python/apache_atlas/client/admin.py b/intg/src/main/python/apache_atlas/client/admin.py index ebe72dc..e6a71b0 100644 --- a/intg/src/main/python/apache_atlas/client/admin.py +++ b/intg/src/main/python/apache_atlas/client/admin.py @@ -16,10 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from apache_atlas.model.admin import AtlasAdminMetrics -from apache_atlas.utils import API -from apache_atlas.utils import BASE_URI -from apache_atlas.utils import HTTPMethod -from apache_atlas.utils import HTTPStatus +from apache_atlas.utils import API, BASE_URI, HTTPStatus, HTTPMethod class AdminClient: diff --git a/intg/src/main/python/apache_atlas/client/discovery.py b/intg/src/main/python/apache_atlas/client/discovery.py index 04f5fc9..b4fc0a8 100644 --- a/intg/src/main/python/apache_atlas/client/discovery.py +++ b/intg/src/main/python/apache_atlas/client/discovery.py @@ -15,14 +15,12 @@ # 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. -from apache_atlas.model.discovery import AtlasQuickSearchResult -from apache_atlas.model.discovery import AtlasSearchResult -from apache_atlas.model.discovery import AtlasSuggestionsResult -from apache_atlas.model.discovery import AtlasUserSavedSearch -from apache_atlas.utils import API -from apache_atlas.utils import BASE_URI -from apache_atlas.utils import HTTPMethod -from apache_atlas.utils import HTTPStatus +from apache_atlas.model.discovery import (AtlasQuickSearchResult, AtlasSearchResult, + AtlasSuggestionsResult, AtlasUserSavedSearch) +from apache_atlas.utils import API, BASE_URI, HTTPMethod, HTTPStatus + +DEFAULT_LIMIT = 100 +DEFAULT_OFFSET = 0 class DiscoveryClient: @@ -66,7 +64,7 @@ class DiscoveryClient: return self.client.call_api(DiscoveryClient.DSL_SEARCH, AtlasSearchResult, query_params) - def dsl_search_with_params(self, query, limit, offset): + def dsl_search_with_params(self, query, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET): query_params = {DiscoveryClient.QUERY: query, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset} return self.client.call_api(DiscoveryClient.DSL_SEARCH, AtlasSearchResult, query_params) @@ -76,29 +74,31 @@ class DiscoveryClient: return self.client.call_api(DiscoveryClient.FULL_TEXT_SEARCH, AtlasSearchResult, query_params) - def full_text_search_with_params(self, query, limit, offset): + def full_text_search_with_params(self, query, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET): query_params = {DiscoveryClient.QUERY: query, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset} return self.client.call_api(DiscoveryClient.FULL_TEXT_SEARCH, AtlasSearchResult, query_params) - def basic_search(self, type_name, classification, query, exclude_deleted_entities, limit, offset): + def basic_search(self, type_name, classification, query, exclude_deleted_entities, + sort_by_attribute=None, sort_order=None, + limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET): query_params = {"typeName": type_name, "classification": classification, DiscoveryClient.QUERY: query, "excludeDeletedEntities": exclude_deleted_entities, DiscoveryClient.LIMIT: limit, - DiscoveryClient.OFFSET: offset} + DiscoveryClient.OFFSET: offset, "sortBy": sort_by_attribute, "sortOrder": sort_order} return self.client.call_api(DiscoveryClient.BASIC_SEARCH, AtlasSearchResult, query_params) def faceted_search(self, search_parameters): - return self.client.call_api(DiscoveryClient.FACETED_SEARCH, AtlasSearchResult, search_parameters) + return self.client.call_api(DiscoveryClient.FACETED_SEARCH, AtlasSearchResult, None, search_parameters) - def attribute_search(self, type_name, attr_name, attr_value_prefix, limit, offset): + def attribute_search(self, type_name, attr_name, attr_value_prefix, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET): query_params = {"attrName": attr_name, "attrValuePrefix": attr_value_prefix, "typeName": type_name, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset} return self.client.call_api(DiscoveryClient.ATTRIBUTE_SEARCH, AtlasSearchResult, query_params) - def relationship_search(self, guid, relation, sort_by_attribute, sort_order, exclude_deleted_entities, limit, - offset): + def relationship_search(self, guid, relation, sort_by_attribute, sort_order, exclude_deleted_entities, + limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET): query_params = {"guid": guid, "relation": relation, "sortBy": sort_by_attribute, "excludeDeletedEntities": exclude_deleted_entities, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset} @@ -108,7 +108,7 @@ class DiscoveryClient: return self.client.call_api(DiscoveryClient.RELATIONSHIP_SEARCH, AtlasSearchResult, query_params) - def quick_search(self, query, type_name, exclude_deleted_entities, limit, offset): + def quick_search(self, query, type_name, exclude_deleted_entities, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET): query_params = {"query": query, "typeName": type_name, "excludeDeletedEntities": exclude_deleted_entities, DiscoveryClient.LIMIT: limit, DiscoveryClient.OFFSET: offset} diff --git a/intg/src/main/python/apache_atlas/client/entity.py b/intg/src/main/python/apache_atlas/client/entity.py index 7edacf9..f48ab7d 100644 --- a/intg/src/main/python/apache_atlas/client/entity.py +++ b/intg/src/main/python/apache_atlas/client/entity.py @@ -170,11 +170,11 @@ class EntityClient: return self.client.call_api(EntityClient.UPDATE_ENTITY, EntityMutationResponse, None, atlas_entities) def partial_update_entity_by_guid(self, entity_guid, attr_value, attr_name): - query_params = {"name", attr_name} + query_params = {"name": attr_name} return self.client.call_api( EntityClient.PARTIAL_UPDATE_ENTITY_BY_GUID.format_path({'entity_guid': entity_guid}), - EntityMutationResponse, attr_value, query_params) + EntityMutationResponse, query_params, attr_value) def delete_entity_by_guid(self, guid): return self.client.call_api(EntityClient.DELETE_ENTITY_BY_GUID.format_path_with_params(guid), diff --git a/intg/src/main/python/apache_atlas/client/glossary.py b/intg/src/main/python/apache_atlas/client/glossary.py index efa0612..0399c7c 100644 --- a/intg/src/main/python/apache_atlas/client/glossary.py +++ b/intg/src/main/python/apache_atlas/client/glossary.py @@ -86,10 +86,14 @@ class GlossaryClient: OFFSET = "offset" STATUS = "Status" + DEFAULT_LIMIT = -1 + DEFAULT_OFFSET = 0 + DEFAULT_SORT = "ASC" + def __init__(self, client): self.client = client - def get_all_glossaries(self, sort_by_attribute, limit, offset): + def get_all_glossaries(self, sort_by_attribute=DEFAULT_SORT, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET): query_params = {"sort": sort_by_attribute, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset} return self.client.call_api(GlossaryClient.GET_ALL_GLOSSARIES, list, query_params) @@ -106,7 +110,8 @@ class GlossaryClient: return self.client.call_api(GlossaryClient.GET_GLOSSARY_TERM.format_path_with_params(term_guid), AtlasGlossaryTerm) - def get_glossary_terms(self, glossary_guid, sort_by_attribute, limit, offset): + def get_glossary_terms(self, glossary_guid, sort_by_attribute=DEFAULT_SORT, + limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET): query_params = {"glossaryGuid": glossary_guid, GlossaryClient.LIMIT: limit, GlossaryClient.OFFSET: offset, "sort": sort_by_attribute} diff --git a/intg/src/main/python/apache_atlas/client/relationship.py b/intg/src/main/python/apache_atlas/client/relationship.py index f5790a4..112ec33 100644 --- a/intg/src/main/python/apache_atlas/client/relationship.py +++ b/intg/src/main/python/apache_atlas/client/relationship.py @@ -47,7 +47,7 @@ class RelationshipClient: AtlasRelationshipWithExtInfo, query_params) def create_relationship(self, relationship): - return self.client.call_api(RelationshipClient.CREATE_RELATIONSHIP, AtlasRelationship, relationship) + return self.client.call_api(RelationshipClient.CREATE_RELATIONSHIP, AtlasRelationship, None, relationship) def update_relationship(self, relationship): return self.client.call_api(RelationshipClient.UPDATE_RELATIONSHIP, AtlasRelationship, relationship) diff --git a/intg/src/main/python/apache_atlas/client/typedef.py b/intg/src/main/python/apache_atlas/client/typedef.py index aa1581d..4ccfb60 100644 --- a/intg/src/main/python/apache_atlas/client/typedef.py +++ b/intg/src/main/python/apache_atlas/client/typedef.py @@ -40,6 +40,7 @@ class TypeDefClient: GET_TYPEDEF_BY_GUID = API(TYPEDEF_BY_GUID, HTTPMethod.GET, HTTPStatus.OK) GET_ALL_TYPE_DEFS = API(TYPEDEFS_API, HTTPMethod.GET, HTTPStatus.OK) GET_ALL_TYPE_DEF_HEADERS = API(TYPEDEFS_API + "headers", HTTPMethod.GET, HTTPStatus.OK) + UPDATE_TYPE_DEFS = API(TYPEDEFS_API, HTTPMethod.PUT, HTTPStatus.OK) CREATE_TYPE_DEFS = API(TYPEDEFS_API, HTTPMethod.POST, HTTPStatus.OK) DELETE_TYPE_DEFS = API(TYPEDEFS_API, HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) DELETE_TYPE_DEF_BY_NAME = API(TYPEDEF_BY_NAME, HTTPMethod.DELETE, HTTPStatus.NO_CONTENT) diff --git a/intg/src/main/python/apache_atlas/model/glossary.py b/intg/src/main/python/apache_atlas/model/glossary.py index 7a0faac..2afc168 100644 --- a/intg/src/main/python/apache_atlas/model/glossary.py +++ b/intg/src/main/python/apache_atlas/model/glossary.py @@ -15,13 +15,10 @@ # 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. -from apache_atlas.model.instance import AtlasBase -from apache_atlas.model.instance import AtlasClassification -from apache_atlas.model.instance import AtlasRelatedObjectId -from apache_atlas.model.misc import AtlasBaseModelObject -from apache_atlas.utils import type_coerce -from apache_atlas.utils import type_coerce_dict -from apache_atlas.utils import type_coerce_list +# This is to avoid the circular dependencies that instance.py and glossary.py has. +import apache_atlas.model.instance as instance +from apache_atlas.model.misc import AtlasBase, AtlasBaseModelObject +from apache_atlas.utils import type_coerce, type_coerce_dict, type_coerce_list class AtlasGlossaryBaseObject(AtlasBaseModelObject): @@ -38,7 +35,7 @@ class AtlasGlossaryBaseObject(AtlasBaseModelObject): def type_coerce_attrs(self): super(AtlasGlossaryBaseObject, self).type_coerce_attrs() - self.classifications = type_coerce_list(self.classifications, AtlasClassification) + self.classifications = type_coerce_list(self.classifications, instance.AtlasClassification) class AtlasGlossary(AtlasGlossaryBaseObject): @@ -141,7 +138,7 @@ class AtlasGlossaryTerm(AtlasGlossaryBaseObject): super(AtlasGlossaryTerm, self).type_coerce_attrs() self.anchor = type_coerce(self.anchor, AtlasGlossaryHeader) - self.assignedEntities = type_coerce_list(self.assignedEntities, AtlasRelatedObjectId) + self.assignedEntities = type_coerce_list(self.assignedEntities, instance.AtlasRelatedObjectId) self.categories = type_coerce_list(self.categories, AtlasTermCategorizationHeader) self.seeAlso = type_coerce_list(self.seeAlso, AtlasRelatedTermHeader) self.synonyms = type_coerce_list(self.synonyms, AtlasRelatedTermHeader) diff --git a/intg/src/main/python/apache_atlas/model/instance.py b/intg/src/main/python/apache_atlas/model/instance.py index 8cfb254..3b2edc4 100644 --- a/intg/src/main/python/apache_atlas/model/instance.py +++ b/intg/src/main/python/apache_atlas/model/instance.py @@ -15,11 +15,10 @@ # 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. -import apache_atlas - -from apache_atlas.model.enums import * -from apache_atlas.model.misc import * -from apache_atlas.utils import * +from apache_atlas.model.enums import EntityStatus +from apache_atlas.model.glossary import AtlasTermAssignmentHeader +from apache_atlas.model.misc import AtlasBase, next_id, Plist, TimeBoundary +from apache_atlas.utils import non_null, type_coerce, type_coerce_dict, type_coerce_dict_list, type_coerce_list class AtlasStruct(AtlasBase): @@ -62,7 +61,7 @@ class AtlasEntity(AtlasStruct): super(AtlasEntity, self).type_coerce_attrs() self.classifications = type_coerce_list(self.classifications, AtlasClassification) - self.meanings = type_coerce_list(self.meanings, apache_atlas.model.glossary.AtlasTermAssignmentHeader) + self.meanings = type_coerce_list(self.meanings, AtlasTermAssignmentHeader) def get_relationship_attribute(self, name): return self.relationshipAttributes[ @@ -122,7 +121,7 @@ class AtlasEntitiesWithExtInfo(AtlasEntityExtInfo): def type_coerce_attrs(self): super(AtlasEntitiesWithExtInfo, self).type_coerce_attrs() - self.entities = type_coerce_list(self.entity, AtlasEntity) + self.entities = type_coerce_list(self.entities, AtlasEntity) def add_entity(self, entity): if self.entities is None: @@ -152,7 +151,7 @@ class AtlasEntityHeader(AtlasStruct): super(AtlasEntityHeader, self).type_coerce_attrs() self.classifications = type_coerce_list(self.classifications, AtlasClassification) - self.meanings = type_coerce_list(self.meanings, apache_atlas.model.glossary.AtlasTermAssignmentHeader) + self.meanings = type_coerce_list(self.meanings, AtlasTermAssignmentHeader) class AtlasClassification(AtlasStruct): diff --git a/intg/src/main/python/setup.py b/intg/src/main/python/setup.py index 7c563c9..59c7327 100644 --- a/intg/src/main/python/setup.py +++ b/intg/src/main/python/setup.py @@ -28,7 +28,7 @@ with open("README.md", "r") as fh: setup( name='apache-atlas', - version='0.0.3', + version='0.0.4', author="Apache Atlas", author_email='[email protected]', description="Apache Atlas Python Client",
