-
Notifications
You must be signed in to change notification settings - Fork 21
Tool: Create Data Domains/Sub Domains/Products #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+402
−64
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1d8b07e
feat: new tool for creating domains, products
Hk669 e8eee7a
integrate into server
Hk669 e3eb02f
fix: get domains and data products working
Hk669 aa221b2
feat: new tools
Hk669 e018359
fix: address comments
Hk669 5e4d694
Merge branch 'main' into hrushikeshdokala/mcp-15
Hk669 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import Any, Dict, List, Union | ||
|
|
||
| from pyatlan.model.assets import Asset, DataDomain, DataProduct | ||
| from pyatlan.model.fluent_search import CompoundQuery, FluentSearch | ||
|
|
||
| from utils import save_assets | ||
| from .models import DataDomainSpec, DataProductSpec | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def create_data_domain_assets( | ||
| domains: Union[Dict[str, Any], List[Dict[str, Any]]], | ||
| ) -> List[Dict[str, Any]]: | ||
| """ | ||
| Create one or multiple Data Domain or Sub Domain assets in Atlan. | ||
|
|
||
| Args: | ||
| domains (Union[Dict[str, Any], List[Dict[str, Any]]]): Either a single domain | ||
| specification (dict) or a list of domain specifications. Each specification | ||
| can be a dictionary containing: | ||
| - name (str): Name of the domain (required) | ||
| - parent_domain_qualified_name (str, optional): Qualified name of the parent | ||
| domain. If provided, creates a Sub Domain under that parent. | ||
| - user_description (str, optional): Detailed description of the domain | ||
| - certificate_status (str, optional): Certification status | ||
| ("VERIFIED", "DRAFT", or "DEPRECATED") | ||
|
|
||
| Returns: | ||
| List[Dict[str, Any]]: List of dictionaries, each with details for a created domain: | ||
| - guid: The GUID of the created domain | ||
| - name: The name of the domain | ||
| - qualified_name: The qualified name of the created domain | ||
|
|
||
| Raises: | ||
| Exception: If there's an error creating the domain assets. | ||
| """ | ||
| data = domains if isinstance(domains, list) else [domains] | ||
| logger.info(f"Creating {len(data)} data domain asset(s)") | ||
| logger.debug(f"Domain specifications: {data}") | ||
|
|
||
| specs = [DataDomainSpec(**item) for item in data] | ||
|
|
||
| assets: List[DataDomain] = [] | ||
| for spec in specs: | ||
| logger.debug( | ||
| f"Creating DataDomain: {spec.name}" | ||
| + ( | ||
| f" under {spec.parent_domain_qualified_name}" | ||
| if spec.parent_domain_qualified_name | ||
| else "" | ||
| ) | ||
| ) | ||
| domain = DataDomain.creator( | ||
| name=spec.name, | ||
| parent_domain_qualified_name=spec.parent_domain_qualified_name, | ||
| ) | ||
| domain.user_description = spec.user_description | ||
| domain.certificate_status = ( | ||
| spec.certificate_status.value if spec.certificate_status else None | ||
| ) | ||
|
|
||
| if spec.certificate_status: | ||
| logger.debug( | ||
| f"Set certificate status for {spec.name}: {spec.certificate_status.value}" | ||
| ) | ||
|
|
||
| assets.append(domain) | ||
|
|
||
| return save_assets(assets) | ||
|
|
||
|
|
||
| def create_data_product_assets( | ||
| products: Union[Dict[str, Any], List[Dict[str, Any]]], | ||
| ) -> List[Dict[str, Any]]: | ||
| """ | ||
| Create one or multiple Data Product assets in Atlan. | ||
|
|
||
| Args: | ||
| products (Union[Dict[str, Any], List[Dict[str, Any]]]): Either a single product | ||
| specification (dict) or a list of product specifications. Each specification | ||
| can be a dictionary containing: | ||
| - name (str): Name of the product (required) | ||
| - domain_qualified_name (str): Qualified name of the domain this product | ||
| belongs to (required) | ||
| - asset_guids (List[str]): List of asset GUIDs to link to this product | ||
| (required, at least one) | ||
| - user_description (str, optional): Detailed description of the product | ||
| - certificate_status (str, optional): Certification status | ||
| ("VERIFIED", "DRAFT", or "DEPRECATED") | ||
|
|
||
| Returns: | ||
| List[Dict[str, Any]]: List of dictionaries, each with details for a created product: | ||
| - guid: The GUID of the created product | ||
| - name: The name of the product | ||
| - qualified_name: The qualified name of the created product | ||
|
|
||
| Raises: | ||
| Exception: If there's an error creating the product assets. | ||
| ValueError: If no asset_guids are provided (validated in DataProductSpec model). | ||
| """ | ||
| data = products if isinstance(products, list) else [products] | ||
| logger.info(f"Creating {len(data)} data product asset(s)") | ||
| logger.debug(f"Product specifications: {data}") | ||
|
|
||
| # Validation for asset_guids is now handled by DataProductSpec model | ||
| specs = [DataProductSpec(**item) for item in data] | ||
|
|
||
| assets: List[DataProduct] = [] | ||
| for spec in specs: | ||
| logger.debug( | ||
| f"Creating DataProduct: {spec.name} under {spec.domain_qualified_name}" | ||
| ) | ||
| logger.debug(f"Linking {len(spec.asset_guids)} asset(s) to product") | ||
|
|
||
| # Build FluentSearch to select assets by their GUIDs | ||
| asset_selection = ( | ||
firecast marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| FluentSearch() | ||
| .where(CompoundQuery.active_assets()) | ||
| .where(Asset.GUID.within(spec.asset_guids)) | ||
| ).to_request() | ||
|
|
||
| product = DataProduct.creator( | ||
| name=spec.name, | ||
| domain_qualified_name=spec.domain_qualified_name, | ||
| asset_selection=asset_selection, | ||
| ) | ||
| product.user_description = spec.user_description | ||
| product.certificate_status = ( | ||
| spec.certificate_status.value if spec.certificate_status else None | ||
| ) | ||
|
|
||
| if spec.certificate_status: | ||
Hk669 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger.debug( | ||
| f"Set certificate status for {spec.name}: {spec.certificate_status.value}" | ||
| ) | ||
|
|
||
| assets.append(product) | ||
|
|
||
| return save_assets(assets) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.