Beispiel #1
0
    def __create_process_helper(self, entity):
        process = entity.entity

        process.relationshipAttributes = {}

        if self.entity_table_us:
            process.relationshipAttributes['inputs'] = [
                AtlasRelatedObjectId({'guid': self.entity_table_us.guid})
            ]

        if self.entity_table_canada:
            process.relationshipAttributes['outputs'] = [
                AtlasRelatedObjectId({'guid': self.entity_table_canada.guid})
            ]

        return self.__create_entity(entity)
Beispiel #2
0
    def delete_tag(self,
                   *,
                   id: str,
                   tag: str,
                   tag_type: str,
                   resource_type: ResourceType = ResourceType.Table) -> None:
        """
        Removes the Glossary Term assignment from the provided source.
        :param id: Table URI / Dashboard ID etc.
        :param tag: Tag Name
        :return:None
        """
        entity = self._get_table_entity(table_uri=id)
        term = self._get_create_glossary_term(tag)

        if not term:
            return

        assigned_entities = self.client.glossary.get_entities_assigned_with_term(
            term.guid, "ASC", -1, 0)

        for item in assigned_entities or list():
            if item.get(self.GUID_KEY) == entity.entity[self.GUID_KEY]:
                related_entity = AtlasRelatedObjectId(item)
                return self.client.glossary.disassociate_term_from_entities(
                    term.guid, [related_entity])
Beispiel #3
0
    def add_tag(self,
                *,
                id: str,
                tag: str,
                tag_type: str = "default",
                resource_type: ResourceType = ResourceType.Table) -> None:
        """
        Assign the Glossary Term to the give table. If the term is not there, it will
        create a new term under the Glossary self.ATLAS_USER_DEFINED_TERMS
        :param id: Table URI / Dashboard ID etc.
        :param tag: Tag Name
        :param tag_type
        :return: None
        """
        entity = self._get_table_entity(table_uri=id)

        term = self._get_create_glossary_term(tag)
        related_entity = AtlasRelatedObjectId({
            self.GUID_KEY:
            entity.entity[self.GUID_KEY],
            "typeName":
            resource_type.name
        })
        self.client.glossary.assign_term_to_entities(term.guid,
                                                     [related_entity])
Beispiel #4
0
    def __create_table_helper(self, entity):
        table = entity.entity

        if self.entity_db:
            dbId = AtlasRelatedObjectId({'guid': self.entity_db.guid})

            LOG.info("setting: table(%s).db=%s", table.guid, dbId)

            table.relationshipAttributes['db'] = dbId

        self.__create_entity(entity)

        return table
Beispiel #5
0
    def test_delete_tag(self) -> None:
        tag = "TAG"
        ent = self._mock_get_table_entity()
        term = self._mock_get_create_glossary_term(tag, ent.entity)
        self.proxy.client.glossary.get_entities_assigned_with_term = MagicMock(
            return_value=[ent.entity])

        with patch.object(self.proxy.client.glossary,
                          'disassociate_term_from_entities') as mock_execute:
            self.proxy.delete_tag(id=self.table_uri,
                                  tag=tag,
                                  tag_type='default')
            mock_execute.assert_called_with(
                term.guid, [AtlasRelatedObjectId(self.entity1)])
Beispiel #6
0
    def test_add_tag(self) -> None:
        tag = "TAG"
        self._mock_get_table_entity()
        term = self._mock_get_create_glossary_term(tag)

        with patch.object(self.proxy.client.glossary,
                          'assign_term_to_entities') as mock_execute:
            self.proxy.add_tag(id=self.table_uri, tag=tag, tag_type='default')
            mock_execute.assert_called_with(term.guid, [
                AtlasRelatedObjectId({
                    self.proxy.GUID_KEY: self.entity1['guid'],
                    "typeName": "Table"
                })
            ])
Beispiel #7
0
    def _assign_glossary_term(self, relationship_spec: Dict) -> None:
        _glossary_name, _term_name = relationship_spec[
            AtlasSerializedRelationshipFields.qualified_name_2].split(',')

        glossary_name = _glossary_name.split('=')[1]
        term_name = _term_name.split('=')[1]

        entity_type = relationship_spec[
            AtlasSerializedRelationshipFields.entity_type_1]
        entity_qn = relationship_spec[
            AtlasSerializedRelationshipFields.qualified_name_1]

        glossary = next(
            filter(lambda g: g.get('name') == glossary_name,
                   self._atlas_client.glossary.get_all_glossaries()))

        glossary_guid = glossary[AtlasCommonParams.guid]

        term = next(
            filter(
                lambda t: t.get('name') == term_name,
                self._atlas_client.glossary.get_glossary_terms(glossary_guid)))

        entity = self._atlas_client.entity.get_entity_by_attribute(
            entity_type,
            uniq_attributes=[(AtlasCommonParams.qualified_name, entity_qn)])

        entity_guid = entity.entity.guid

        e = AtlasRelatedObjectId({
            AtlasCommonParams.guid: entity_guid,
            AtlasCommonParams.type_name: entity_type
        })

        try:
            self._atlas_client.glossary.assign_term_to_entities(
                term[AtlasCommonParams.guid], [e])
        except Exception:
            LOGGER.error('Error assigning terms to entities.', exc_info=True)
Beispiel #8
0
 def _get_atlas_related_object_id_by_qn(self, entity_type: str,
                                        qn: str) -> AtlasRelatedObjectId:
     return AtlasRelatedObjectId(
         attrs=self._render_unique_attributes(entity_type, qn))