-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat(ingestion): [WIP] Adding SSAS as a New Source for Data Ingestion #10286
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Module xmla communicate classes. | ||
""" | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Any, Dict, Union | ||
|
||
import xmltodict | ||
from requests.auth import HTTPBasicAuth | ||
from requests_kerberos import HTTPKerberosAuth | ||
|
||
from .config import SsasServerHTTPConfig | ||
from .tools import MsXmlaTemplates | ||
from .xmlaclient import XmlaClient | ||
|
||
|
||
class ISsasAPI(ABC): | ||
@abstractmethod | ||
def get_server(self): | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def auth_credentials(self): | ||
pass | ||
|
||
|
||
class SsasXmlaAPI: | ||
""" | ||
Class for parse ssas xmla server response | ||
""" | ||
|
||
def __init__(self, config: SsasServerHTTPConfig, auth: Union[HTTPKerberosAuth, HTTPBasicAuth]): | ||
self.__config = config | ||
self.__auth = auth | ||
self.__client = XmlaClient(config=config, auth=self.__auth) | ||
|
||
def get_server_info(self) -> Dict[str, Any]: | ||
""" | ||
Extract server metadata info from response | ||
""" | ||
|
||
server_data_xml = xmltodict.parse(self.get_server_metadata()) | ||
|
||
return server_data_xml["soap:Envelope"]["soap:Body"]["DiscoverResponse"][ | ||
"return" | ||
]["root"]["row"]["xars:METADATA"]["Server"] | ||
Comment on lines
+38
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for XML parsing in The def get_server_info(self) -> Dict[str, Any]:
"""
Extract server metadata info from response
"""
try:
server_data_xml = xmltodict.parse(self.get_server_metadata())
return server_data_xml["soap:Envelope"]["soap:Body"]["DiscoverResponse"][
"return"
]["root"]["row"]["xars:METADATA"]["Server"]
except (xmltodict.expat.ExpatError, KeyError) as e:
raise XMLAServerResponseError("Failed to parse server metadata") from e |
||
|
||
def get_server_metadata(self) -> str: | ||
""" | ||
Get ssas server metadata | ||
""" | ||
|
||
return str(self.__client.discover(query=MsXmlaTemplates.QUERY_METADATA)) | ||
Comment on lines
+49
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for network requests in The def get_server_metadata(self) -> str:
"""
Get ssas server metadata
"""
try:
return str(self.__client.discover(query=MsXmlaTemplates.QUERY_METADATA))
except SomeNetworkException as e:
raise XMLAServerResponseError("Failed to retrieve server metadata") from e |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from typing import List, Dict | ||
|
||
import datahub.emitter.mce_builder as builder | ||
import pydantic | ||
from datahub.configuration.common import AllowDenyPattern | ||
from datahub.configuration.source_common import EnvConfigMixin | ||
|
||
|
||
class SsasServerHTTPConfig(EnvConfigMixin): | ||
""" | ||
Class represent config object. | ||
Contains parameters for connect to ssas over http (HTTP Access to Analysis Services) | ||
https://learn.microsoft.com/en-us/analysis-services/instances/configure-http-access-to-analysis-services-on-iis-8-0?view=asallproducts-allversions | ||
|
||
username - Active Directory user login | ||
username - Active Directory user password | ||
host_port - XMLA gateway url (format - url:port) | ||
server_alias - XMLA gateway server alias | ||
virtual_directory_name - | ||
instance - not used ??? | ||
use_https - set true if use XMLA gateway over https | ||
dns_suffixes - list dns zone if use ssas servers in different domains. | ||
Used to search for the main domain for the ssas server if it is not specified in the cube properties | ||
|
||
""" | ||
username: str = pydantic.Field(description="Windows account username") | ||
password: str = pydantic.Field(description="Windows account password") | ||
instance: str | ||
host_port: str = pydantic.Field( | ||
default="localhost:81", description="XMLA gateway url" | ||
) | ||
server_alias: str = pydantic.Field(default="localhost") | ||
|
||
virtual_directory_name: str = pydantic.Field( | ||
default="ssas", description="Report Virtual Directory URL name" | ||
) | ||
ssas_instance: str | ||
use_https: bool = pydantic.Field(default=True) | ||
ssas_instance_auth_type: str = pydantic.Field(default="HTTPKerberosAuth", description="SSAS instance auth type") | ||
|
||
dns_suffixes: List = pydantic.Field(default_factory=list) | ||
default_ssas_instances_by_server: Dict = pydantic.Field(default_factory=dict) | ||
|
||
@pydantic.validator('ssas_instance_auth_type') | ||
def check_ssas_instance_auth_type(cls, v): | ||
if v not in ["HTTPBasicAuth", "HTTPKerberosAuth"]: | ||
raise ValueError("Support only HTTPBasicAuth or HTTPKerberosAuth auth type") | ||
return v | ||
|
||
@property | ||
def use_dns_resolver(self) -> bool: | ||
return bool(self.dns_suffixes) | ||
|
||
@property | ||
def base_api_url(self) -> str: | ||
protocol = "https" if self.use_https else "http" | ||
return f"{protocol}://{self.host_port}/{self.virtual_directory_name}/{self.ssas_instance}/msmdpump.dll" | ||
Comment on lines
+55
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding validation for URL components. Ensure that if not self.host_port or not self.virtual_directory_name:
raise ValueError("host_port and virtual_directory_name must not be empty.") |
||
|
||
@property | ||
def host(self) -> str: | ||
return self.server_alias or self.host_port.split(":")[0] | ||
|
||
|
||
class SsasServerHTTPSourceConfig(SsasServerHTTPConfig): | ||
platform_name: str = "ssas" | ||
platform_urn: str = builder.make_data_platform_urn(platform=platform_name) | ||
report_pattern: AllowDenyPattern = AllowDenyPattern.allow_all() | ||
chart_pattern: AllowDenyPattern = AllowDenyPattern.allow_all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for network requests in
SsasXmlaAPI
.The constructor initializes a client for making network requests. Consider adding error handling for potential network-related issues, such as connection timeouts or authentication failures.