def type_coerce_attrs(self): super(AtlasGlossaryCategory, self).type_coerce_attrs() self.anchor = type_coerce(self.anchor, AtlasGlossaryHeader) self.parentCategory = type_coerce(self.parentCategory, AtlasRelatedCategoryHeader) self.childrenCategories = type_coerce_list(self.childrenCategories, AtlasRelatedCategoryHeader) self.terms = type_coerce_list(self.terms, AtlasRelatedTermHeader)
def type_coerce_attrs(self): super(AtlasRelationship, self).type_coerce_attrs() self.end1 = type_coerce(self.end1, AtlasObjectId) self.end2 = type_coerce(self.end2, AtlasObjectId) self.propagatedClassifications = type_coerce_list( self.propagatedClassifications, AtlasClassification) self.blockedPropagatedClassifications = type_coerce_list( self.blockedPropagatedClassifications, AtlasClassification)
def add_owner(self, *, table_uri: str, owner: str) -> None: """ Query on Atlas User entity to find if the entity exist for the owner string in parameter, if not create one. And then use that User entity's GUID and add a relationship between Table and User, on ownedBy field. :param table_uri: :param owner: Email address of the owner :return: None, as it simply adds the owner. """ owner_info = self._get_user_details(owner) if not owner_info: raise NotFoundException(f'User "{owner}" does not exist.') user_dict = type_coerce( { "entity": { "typeName": "User", "attributes": { "qualifiedName": owner }, } }, AtlasEntityWithExtInfo) # Get or Create a User user_entity = self.client.entity.create_entity(user_dict) user_guid = next(iter(user_entity.guidAssignments.values())) table = self._get_table_entity(table_uri=table_uri) entity_def = { "typeName": "DataSet_Users_Owner", "end1": { "guid": table.entity.get("guid"), "typeName": "Table", }, "end2": { "guid": user_guid, "typeName": "User", }, } try: relationship = type_coerce(entity_def, AtlasRelationship) self.client.relationship.create_relationship( relationship=relationship) except Exception as ex: LOGGER.exception( 'Error while adding the owner information. {}'.format(str(ex))) raise BadRequest( f'User {owner} is already added as a data owner for ' f'table {table_uri}.')
def type_coerce_attrs(self): super(AtlasSearchResult, self).type_coerce_attrs() self.entities = type_coerce_list(self.entities, AtlasEntityHeader) self.attributes = type_coerce(self.attributes, AttributeSearchResult) self.referredEntities = type_coerce_dict(self.referredEntities, AtlasEntityHeader)
def _create_bookmark(self, entity: AtlasEntityWithExtInfo, user_guid: str, bookmark_qn: str, table_uri: str) -> None: """ Creates a bookmark entity for a specific user and table uri. :param user_guid: User's guid :param bookmark_qn: Bookmark qualifiedName :return: """ bookmark_entity = { 'entity': { 'typeName': self.BOOKMARK_TYPE, 'attributes': { 'qualifiedName': bookmark_qn, self.BOOKMARK_ACTIVE_KEY: True, 'entityUri': table_uri, 'user': { 'guid': user_guid }, 'entity': { 'guid': entity.entity[self.GUID_KEY] } } } } bookmark_entity = type_coerce(bookmark_entity, AtlasEntityWithExtInfo) self.client.entity.create_entity(bookmark_entity)
def type_coerce_attrs(self): super(AtlasGlossaryTerm, self).type_coerce_attrs() self.anchor = type_coerce(self.anchor, AtlasGlossaryHeader) 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) self.antonyms = type_coerce_list(self.antonyms, AtlasRelatedTermHeader) self.preferredTerms = type_coerce_list(self.preferredTerms, AtlasRelatedTermHeader) self.preferredToTerms = type_coerce_list(self.preferredToTerms, AtlasRelatedTermHeader) self.replacementTerms = type_coerce_list(self.replacementTerms, AtlasRelatedTermHeader) self.replacedBy = type_coerce_list(self.replacedBy, AtlasRelatedTermHeader) self.translationTerms = type_coerce_list(self.translationTerms, AtlasRelatedTermHeader) self.isA = type_coerce_list(self.isA, AtlasRelatedTermHeader) self.classifies = type_coerce_list(self.classifies, AtlasRelatedTermHeader) self.validValues = type_coerce_list(self.validValues, AtlasRelatedTermHeader) self.validValuesFor = type_coerce_list(self.validValuesFor, AtlasRelatedTermHeader)
def type_coerce_attrs(self): super(AtlasGlossaryTerm, self).type_coerce_attrs() # This is to avoid the circular dependencies that instance.py and glossary.py has. import apache_atlas.model.instance as instance self.anchor = type_coerce(self.anchor, AtlasGlossaryHeader) 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) self.antonyms = type_coerce_list(self.antonyms, AtlasRelatedTermHeader) self.preferredTerms = type_coerce_list(self.preferredTerms, AtlasRelatedTermHeader) self.preferredToTerms = type_coerce_list(self.preferredToTerms, AtlasRelatedTermHeader) self.replacementTerms = type_coerce_list(self.replacementTerms, AtlasRelatedTermHeader) self.replacedBy = type_coerce_list(self.replacedBy, AtlasRelatedTermHeader) self.translationTerms = type_coerce_list(self.translationTerms, AtlasRelatedTermHeader) self.isA = type_coerce_list(self.isA, AtlasRelatedTermHeader) self.classifies = type_coerce_list(self.classifies, AtlasRelatedTermHeader) self.validValues = type_coerce_list(self.validValues, AtlasRelatedTermHeader) self.validValuesFor = type_coerce_list(self.validValuesFor, AtlasRelatedTermHeader)
def create_type_def(self): try: if not self.typesDef: with open('request_json/typedef_create.json') as f: typedef = type_coerce(json.load(f), AtlasTypesDef) self.typesDef = self.__create(typedef) except Exception as e: LOG.exception("Error in creating typeDef", exc_info=e)
def __create_db(self): if not self.entity_db: with open('request_json/entity_create_db.json') as f: entity = type_coerce(json.load(f), AtlasEntityWithExtInfo) self.entity_db = self.__create_db_helper(entity) if self.entity_db: LOG.info("Created database entity: guid=%s, attr.name=%s", self.entity_db.guid, self.entity_db.attributes['name']) else: LOG.info("Failed to create database entity")
def __create_us_table(self): if not self.entity_table_us: with open('request_json/entity_create_table_us.json') as f: entity = type_coerce(json.load(f), AtlasEntityWithExtInfo) self.entity_table_us = self.__create_table_helper(entity) if self.entity_table_us: LOG.info("Created US table entity: guid=%s, attr.name=%s", self.entity_table_us.guid, self.entity_table_us.attributes['name']) else: LOG.info("Failed to create US table entity")
def test_add_owner(self) -> None: owner = "OWNER" user_guid = 123 self._mock_get_table_entity() mocked_user_entity = MagicMock() mocked_user_entity.guidAssignments = dict(user_guid=user_guid) self.proxy.client.entity.create_entity = MagicMock( return_value=mocked_user_entity) with patch.object(self.proxy.client.relationship, 'create_relationship') as mock_execute: self.proxy.add_owner(table_uri=self.table_uri, owner=owner) mock_execute.assert_called_with(relationship=type_coerce( { 'typeName': 'DataSet_Users_Owner', 'end1': { 'guid': self.entity1['guid'], 'typeName': 'Table' }, 'end2': { 'guid': user_guid, 'typeName': 'User' } }, AtlasRelationship))
def type_coerce_attrs(self): super(AtlasRelatedObjectId, self).type_coerce_attrs() self.relationshipAttributes = type_coerce(self.relationshipAttributes, AtlasStruct)
def type_coerce_attrs(self): super(AtlasBase, self).type_coerce_attrs() self.relationship = type_coerce(self.relationship, AtlasRelationship) self.referredEntities = type_coerce_dict(self.referredEntities, AtlasEntityHeader)
def type_coerce_attrs(self): super(SearchParameters, self).type_coerce_attrs() self.entityFilters = type_coerce(self.entityFilters, FilterCriteria) self.tagFilters = type_coerce(self.tagFilters, FilterCriteria)
def type_coerce_attrs(self): super(FilterCriteria, self).type_coerce_attrs() self.criterion = type_coerce(self.criterion, FilterCriteria)
def call_api(self, api, response_type=None, query_params=None, request_obj=None): params = copy.deepcopy(self.request_params) path = os.path.join(self.host, api.path) params['headers']['Accept'] = api.consumes params['headers']['Content-type'] = api.produces if query_params: params['params'] = query_params if request_obj: params['data'] = json.dumps(request_obj) if LOG.isEnabledFor(logging.DEBUG): LOG.debug("------------------------------------------------------") LOG.debug("Call : %s %s", api.method, path) LOG.debug("Content-type : %s", api.consumes) LOG.debug("Accept : %s", api.produces) response = None if api.method == HttpMethod.GET: response = self.session.get(path, **params) elif api.method == HttpMethod.POST: response = self.session.post(path, **params) elif api.method == HttpMethod.PUT: response = self.session.put(path, **params) elif api.method == HttpMethod.DELETE: response = self.session.delete(path, **params) if response is not None: LOG.debug("HTTP Status: %s", response.status_code) if response is None: return None elif response.status_code == api.expected_status: if not response_type: return None try: if response.content: if LOG.isEnabledFor(logging.DEBUG): LOG.debug("<== __call_api(%s,%s,%s), result = %s", vars(api), params, request_obj, response) LOG.debug(response.json()) if response_type == str: return json.dumps(response.json()) return type_coerce(response.json(), response_type) else: return None except Exception as e: print(e) LOG.exception( "Exception occurred while parsing response with msg: %s", e) raise AtlasServiceException(api, response) elif response.status_code == HTTPStatus.SERVICE_UNAVAILABLE: LOG.error("Atlas Service unavailable. HTTP Status: %s", HTTPStatus.SERVICE_UNAVAILABLE) return None else: raise AtlasServiceException(api, response)
def type_coerce_attrs(self): super(AtlasCheckStateResult, self).type_coerce_attrs() self.entities = type_coerce(self.entities, AtlasEntityState)
def type_coerce_attrs(self): super(AtlasFullTextResult, self).type_coerce_attrs() self.entity = type_coerce(self.criterion, AtlasEntityHeader)
def type_coerce_attrs(self): super(AtlasUserSavedSearch, self).type_coerce_attrs() self.searchParameters = type_coerce(self.searchParameters, SearchParameters)
def type_coerce_attrs(self): super(AtlasEntityWithExtInfo, self).type_coerce_attrs() self.entity = type_coerce(self.entity, AtlasEntity)
def type_coerce_attrs(self): super(AtlasQuickSearchResult, self).type_coerce_attrs() self.searchResults = type_coerce(self.searchResults, AtlasSearchResult) self.aggregationMetrics = type_coerce_dict_list( self.aggregationMetrics, AtlasAggregationEntry)
def type_coerce_attrs(self): super(AtlasRelationshipDef, self).type_coerce_attrs() self.endDef1 = type_coerce(self.endDef1, AtlasRelationshipEndDef) self.endDef2 = type_coerce(self.endDef2, AtlasRelationshipEndDef)
def type_coerce_attrs(self): super(EntityMutation, self).type_coerce_attrs() self.entity = type_coerce(self.entity, AtlasEntity)