mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-24 17:59:52 +00:00
redash-test-connection-completed (#4672)
* redash-test-connection-completed * code-smell-removed * docstring-added-for-non-sqlalchemy-service-client
This commit is contained in:
parent
6cff9620b2
commit
6bd587be8d
@ -24,6 +24,9 @@ from metadata.generated.schema.entity.services.connections.metadata.openMetadata
|
||||
OpenMetadataConnection,
|
||||
)
|
||||
from metadata.generated.schema.entity.services.dashboardService import DashboardService
|
||||
from metadata.generated.schema.metadataIngestion.dashboardServiceMetadataPipeline import (
|
||||
DashboardServiceMetadataPipeline,
|
||||
)
|
||||
from metadata.generated.schema.metadataIngestion.workflow import (
|
||||
Source as WorkflowSource,
|
||||
)
|
||||
@ -33,6 +36,7 @@ from metadata.ingestion.api.source import InvalidSourceException, Source, Source
|
||||
from metadata.ingestion.models.table_metadata import Chart as ModelChart
|
||||
from metadata.ingestion.models.table_metadata import Dashboard
|
||||
from metadata.ingestion.ometa.ometa_api import OpenMetadata
|
||||
from metadata.utils.connections import get_connection, test_connection
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -63,12 +67,14 @@ class RedashSource(Source[Entity]):
|
||||
self.config = config
|
||||
self.metadata_config = metadata_config
|
||||
self.metadata = OpenMetadata(metadata_config)
|
||||
|
||||
self.source_config: DashboardServiceMetadataPipeline = (
|
||||
self.config.sourceConfig.config
|
||||
)
|
||||
self.connection_config = self.config.serviceConnection.__root__.config
|
||||
self.status = RedashSourceStatus()
|
||||
self.client = Redash(
|
||||
self.connection_config.hostPort, self.connection_config.apiKey
|
||||
)
|
||||
self.connection = get_connection(self.connection_config)
|
||||
self.client = self.connection.client
|
||||
|
||||
self.service = self.metadata.get_service_or_create(
|
||||
entity=DashboardService, config=config
|
||||
)
|
||||
|
@ -11,6 +11,12 @@
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
"""
|
||||
Creating client for non-sqlalchemy package is neccessary,
|
||||
Importing a Class directly in connection.py will break the ingestion,
|
||||
if non-sqlalchemy package is not installed
|
||||
"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class GlueClient:
|
||||
@ -46,3 +52,9 @@ class KafkaClient:
|
||||
class MetabaseClient:
|
||||
def __init__(self, client) -> None:
|
||||
self.client = client
|
||||
|
||||
|
||||
@dataclass
|
||||
class RedashClient:
|
||||
def __init__(self, client) -> None:
|
||||
self.client = client
|
||||
|
@ -31,6 +31,9 @@ from metadata.generated.schema.entity.services.connections.connectionBasicType i
|
||||
from metadata.generated.schema.entity.services.connections.dashboard.metabaseConnection import (
|
||||
MetabaseConnection,
|
||||
)
|
||||
from metadata.generated.schema.entity.services.connections.dashboard.redashConnection import (
|
||||
RedashConnection,
|
||||
)
|
||||
from metadata.generated.schema.entity.services.connections.database.bigQueryConnection import (
|
||||
BigQueryConnection,
|
||||
)
|
||||
@ -58,6 +61,7 @@ from metadata.utils.connection_clients import (
|
||||
GlueClient,
|
||||
KafkaClient,
|
||||
MetabaseClient,
|
||||
RedashClient,
|
||||
SalesforceClient,
|
||||
)
|
||||
from metadata.utils.credentials import set_google_credentials
|
||||
@ -364,7 +368,31 @@ def _(connection: MetabaseClient) -> None:
|
||||
connection.client["connection"].hostPort + "/api/dashboard",
|
||||
headers=connection.client["metabase_session"],
|
||||
)
|
||||
|
||||
except Exception as err:
|
||||
raise SourceConnectionException(
|
||||
f"Unknown error connecting with {connection} - {err}."
|
||||
)
|
||||
|
||||
|
||||
@get_connection.register
|
||||
def _(connection: RedashConnection, verbose: bool = False):
|
||||
|
||||
from redash_toolbelt import Redash
|
||||
|
||||
try:
|
||||
redash = Redash(connection.hostPort, connection.apiKey)
|
||||
redash_client = RedashClient(redash)
|
||||
return redash_client
|
||||
|
||||
except Exception as err:
|
||||
logger.error(f"Failed to connect with error : {err}")
|
||||
logger.error(err)
|
||||
|
||||
|
||||
@test_connection.register
|
||||
def _(connection: RedashClient) -> None:
|
||||
try:
|
||||
connection.client.dashboards()
|
||||
except Exception as err:
|
||||
raise SourceConnectionException(
|
||||
f"Unknown error connecting with {connection} - {err}."
|
||||
|
Loading…
x
Reference in New Issue
Block a user