-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from atlanhq/DVX-118
DVX-118: Add support for workflow packages
- Loading branch information
Showing
28 changed files
with
3,166 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
Empty file.
Empty file.
This file contains 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,111 @@ | ||
from json import dumps | ||
from typing import Any, Dict, Optional | ||
|
||
from pyatlan import utils | ||
from pyatlan.errors import ErrorCode | ||
from pyatlan.model.assets import Connection | ||
from pyatlan.model.packages.base.package import AbstractPackage | ||
|
||
|
||
class AbstractCrawler(AbstractPackage): | ||
""" | ||
Abstract class for crawlers | ||
:param connection_name: name for the connection | ||
:param connection_type: type of connector for the connection | ||
:param admin_roles: admin roles for the connection | ||
:param admin_groups: admin groups for the connection | ||
:param admin_users: admin users for the connection | ||
:param allow_query: allow data to be queried in the connection (True) or not (False) | ||
:param allow_query_preview: allow sample data viewing for assets in the connection (True) or not (False) | ||
:param row_limit: maximum number of rows that can be returned by a query | ||
:param source_logo: logo to use for the source | ||
:raises AtlanException: if there is not at least one role, | ||
group, or user defined as an admin (or any of them are invalid) | ||
""" | ||
|
||
def __init__( | ||
self, | ||
connection_name: str, | ||
connection_type: str, | ||
admin_roles: Optional[list[str]], | ||
admin_groups: Optional[list[str]], | ||
admin_users: Optional[list[str]], | ||
allow_query: bool = False, | ||
allow_query_preview: bool = False, | ||
row_limit: int = 0, | ||
source_logo: str = "", | ||
): | ||
self._parameters: list = [] | ||
self._credentials_body: dict = {} | ||
self._epoch = int(utils.get_epoch_timestamp()) | ||
self._connection_name = connection_name | ||
self._connection_type = connection_type | ||
self._admin_roles = admin_roles | ||
self._admin_groups = admin_groups | ||
self._admin_users = admin_users | ||
self._allow_query = allow_query | ||
self._allow_query_preview = allow_query_preview | ||
self._row_limit = row_limit | ||
self._source_logo = source_logo | ||
|
||
def _get_connection(self) -> Connection: | ||
""" | ||
Builds a connection using the provided parameters, | ||
which will be the target for the package to crawl assets. | ||
""" | ||
connection = Connection.create( | ||
name=self._connection_name, | ||
connector_type=self._connection_type, | ||
admin_roles=self._admin_roles, | ||
admin_groups=self._admin_groups, | ||
admin_users=self._admin_users, | ||
) | ||
connection.allow_query = self._allow_query | ||
connection.allow_query_preview = self._allow_query_preview | ||
connection.row_limit = self._row_limit | ||
connection.default_credential_guid = "{{credentialGuid}}" | ||
connection.source_logo = self._source_logo | ||
connection.is_discoverable = True | ||
connection.is_editable = False | ||
return connection | ||
|
||
@staticmethod | ||
def build_hierarchical_filter(raw_filter: Optional[dict]) -> str: | ||
""" | ||
Build an exact match filter from the provided map of databases and schemas. | ||
:param raw_filter: map keyed by database name with each value being a list of schemas | ||
:returns: an exact-match filter map string, usable in crawlers include / exclude filters | ||
:raises InvalidRequestException: In the unlikely event the provided filter cannot be translated | ||
""" | ||
to_include: Dict[str, Any] = {} | ||
if not raw_filter: | ||
return "" | ||
try: | ||
for db_name, schemas in raw_filter.items(): | ||
exact_schemas = [f"^{schema}$" for schema in schemas] | ||
to_include[f"^{db_name}$"] = exact_schemas | ||
return dumps(to_include) | ||
except (AttributeError, TypeError): | ||
raise ErrorCode.UNABLE_TO_TRANSLATE_FILTERS.exception_with_parameters() | ||
|
||
@staticmethod | ||
def build_flat_filter(raw_filter: Optional[list]) -> str: | ||
""" | ||
Build a filter from the provided list of object names / IDs. | ||
:param raw_filter: list of objects for the filter | ||
:returns: a filter map string, usable in crawlers include / exclude filters | ||
:raises InvalidRequestException: In the unlikely event the provided filter cannot be translated | ||
""" | ||
to_include: Dict[str, Any] = {} | ||
if not raw_filter: | ||
return "" | ||
try: | ||
for entry in raw_filter: | ||
to_include[entry] = {} | ||
return dumps(to_include) | ||
except (AttributeError, TypeError): | ||
raise ErrorCode.UNABLE_TO_TRANSLATE_FILTERS.exception_with_parameters() |
This file contains 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,64 @@ | ||
from pyatlan.model.workflow import ( | ||
PackageParameter, | ||
Workflow, | ||
WorkflowDAG, | ||
WorkflowMetadata, | ||
WorkflowParameters, | ||
WorkflowSpec, | ||
WorkflowTask, | ||
WorkflowTemplate, | ||
WorkflowTemplateRef, | ||
) | ||
|
||
|
||
class AbstractPackage: | ||
""" | ||
Abstract class for packages | ||
""" | ||
|
||
_PACKAGE_NAME: str = "" | ||
_PACKAGE_PREFIX: str = "" | ||
|
||
def _get_metadata(self) -> WorkflowMetadata: | ||
raise NotImplementedError | ||
|
||
def to_workflow(self) -> Workflow: | ||
metadata = self._get_metadata() | ||
spec = WorkflowSpec( | ||
entrypoint="main", | ||
templates=[ | ||
WorkflowTemplate( | ||
name="main", | ||
dag=WorkflowDAG( | ||
tasks=[ | ||
WorkflowTask( | ||
name="run", | ||
arguments=WorkflowParameters( | ||
parameters=self._parameters # type: ignore | ||
), | ||
template_ref=WorkflowTemplateRef( | ||
name=self._PACKAGE_PREFIX, | ||
template="main", | ||
cluster_scope=True, | ||
), | ||
) | ||
] | ||
), | ||
) | ||
], | ||
workflow_metadata=WorkflowMetadata( | ||
annotations={"package.argoproj.io/name": self._PACKAGE_NAME} | ||
), | ||
) | ||
payload = [ | ||
PackageParameter( | ||
parameter="credentialGuid", | ||
type="credential", | ||
body=self._credentials_body, # type: ignore | ||
) | ||
] | ||
return Workflow( | ||
metadata=metadata, | ||
spec=spec, | ||
payload=payload if self._credentials_body else [], # type: ignore | ||
) |
Oops, something went wrong.