Skip to content

Commit

Permalink
Connector: rename microstrategy connector (#18604)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshsoni2024 authored Nov 28, 2024
1 parent f99ed51 commit cb33f27
Show file tree
Hide file tree
Showing 27 changed files with 409 additions and 157 deletions.
24 changes: 24 additions & 0 deletions bootstrap/sql/migrations/native/1.6.0/mysql/schemaChanges.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1773,3 +1773,27 @@ SET json = JSON_SET(
)
)
WHERE serviceType = 'DBTCloud';

-- Update serviceType in dashboard_entity table
UPDATE dashboard_entity
SET json = JSON_SET(json, '$.serviceType', 'MicroStrategy')
WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'Mstr';

-- Update serviceType in dashboard_service_entity table
UPDATE dashboard_service_entity
SET json = JSON_SET(json, '$.serviceType', 'MicroStrategy')
WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'Mstr';

UPDATE dashboard_service_entity
SET json = JSON_SET(json, '$.connection.config.type', 'MicroStrategy')
WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.connection.config.type')) = 'Mstr';

-- Update serviceType in dashboard_data_model_entity table
UPDATE dashboard_data_model_entity
SET json = JSON_SET(json, '$.serviceType', 'MicroStrategy')
WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'Mstr';

-- Update serviceType in chart_entity table
UPDATE chart_entity
SET json = JSON_SET(json, '$.serviceType', 'MicroStrategy')
WHERE JSON_UNQUOTE(JSON_EXTRACT(json, '$.serviceType')) = 'Mstr';
24 changes: 24 additions & 0 deletions bootstrap/sql/migrations/native/1.6.0/postgres/schemaChanges.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1756,3 +1756,27 @@ and servicetype = 'DBTCloud';
UPDATE pipeline_service_entity
SET json = jsonb_set(json, '{connection, config, projectIds}', '[]', true)
WHERE servicetype = 'DBTCloud';

-- Update serviceType in dashboard_entity table
UPDATE dashboard_entity
SET json = jsonb_set(json, '{serviceType}', '"MicroStrategy"')
WHERE jsonb_extract_path_text(json, 'serviceType') = 'Mstr';

-- Update serviceType in dashboard_service_entity table
UPDATE dashboard_service_entity
SET json = jsonb_set(json, '{serviceType}', '"MicroStrategy"')
WHERE jsonb_extract_path_text(json, 'serviceType') = 'Mstr';

UPDATE dashboard_service_entity
SET json = jsonb_set(json, '{connection,config,type}', '"MicroStrategy"')
WHERE jsonb_extract_path_text(json, 'connection', 'config', 'type') = 'Mstr';

-- Update serviceType in dashboard_data_model_entity table
UPDATE dashboard_data_model_entity
SET json = jsonb_set(json, '{serviceType}', '"MicroStrategy"')
WHERE jsonb_extract_path_text(json, 'serviceType') = 'Mstr';

-- Update serviceType in chart_entity table
UPDATE chart_entity
SET json = jsonb_set(json, '{serviceType}', '"MicroStrategy"')
WHERE jsonb_extract_path_text(json, 'serviceType') = 'Mstr';
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
source:
type: mstr
type: microstrategy
serviceName: test
serviceConnection:
config:
type: Mstr
type: MicroStrategy
username: username
password: password
hostPort: http://hostPort
projectName: project
loginMode: "8"
sourceConfig:
config:
type: DashboardMetadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
REST Auth & Client for Mstr
REST Auth & Client for MicroStrategy
"""
import traceback
from typing import List, Optional

import requests

from metadata.generated.schema.entity.services.connections.dashboard.mstrConnection import (
MstrConnection,
from metadata.generated.schema.entity.services.connections.dashboard.microStrategyConnection import (
MicroStrategyConnection,
)
from metadata.ingestion.connections.test_connections import SourceConnectionException
from metadata.ingestion.ometa.client import REST, ClientConfig
from metadata.ingestion.source.dashboard.mstr.models import (
from metadata.ingestion.source.dashboard.microstrategy.models import (
AuthHeaderCookie,
MstrDashboard,
MstrDashboardDetails,
Expand All @@ -37,30 +37,29 @@
logger = ingestion_logger()

API_VERSION = "MicroStrategyLibrary/api"
LOGIN_MODE_GUEST = 8
APPLICATION_TYPE = 35


class MSTRClient:
class MicroStrategyClient:
"""
Client Handling API communication with Metabase
"""

def _get_base_url(self, path=None):
if not path:
return f"{clean_uri(self.config.hostPort)}/{API_VERSION}"
return f"{clean_uri(self.config.hostPort)}/{API_VERSION}/{path}"
return f"{clean_uri(str(self.config.hostPort))}/{API_VERSION}"
return f"{clean_uri(str(self.config.hostPort))}/{API_VERSION}/{path}"

def __init__(
self,
config: MstrConnection,
config: MicroStrategyConnection,
):
self.config = config

self.auth_params: AuthHeaderCookie = self._get_auth_header_and_cookies()

client_config = ClientConfig(
base_url=clean_uri(config.hostPort),
base_url=clean_uri(str(self.config.hostPort)),
api_version=API_VERSION,
extra_headers=self.auth_params.auth_header,
allow_redirects=True,
Expand All @@ -81,7 +80,7 @@ def _get_auth_header_and_cookies(self) -> Optional[AuthHeaderCookie]:
data = {
"username": self.config.username,
"password": self.config.password.get_secret_value(),
"loginMode": LOGIN_MODE_GUEST,
"loginMode": self.config.loginMode,
"applicationType": APPLICATION_TYPE,
}
response = requests.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,29 @@
from metadata.generated.schema.entity.automations.workflow import (
Workflow as AutomationWorkflow,
)
from metadata.generated.schema.entity.services.connections.dashboard.mstrConnection import (
MstrConnection,
from metadata.generated.schema.entity.services.connections.dashboard.microStrategyConnection import (
MicroStrategyConnection,
)
from metadata.generated.schema.entity.services.connections.testConnectionResult import (
TestConnectionResult,
)
from metadata.ingestion.connections.test_connections import test_connection_steps
from metadata.ingestion.ometa.ometa_api import OpenMetadata
from metadata.ingestion.source.dashboard.mstr.client import MSTRClient
from metadata.utils.constants import THREE_MIN
from metadata.ingestion.source.dashboard.microstrategy.client import MicroStrategyClient


def get_connection(connection: MstrConnection) -> MSTRClient:
def get_connection(connection: MicroStrategyConnection) -> MicroStrategyClient:
"""
Create connection
"""
return MSTRClient(connection)
return MicroStrategyClient(connection)


def test_connection(
metadata: OpenMetadata,
client: MSTRClient,
service_connection: MstrConnection,
client: MicroStrategyClient,
service_connection: MicroStrategyConnection,
automation_workflow: Optional[AutomationWorkflow] = None,
timeout_seconds: Optional[int] = THREE_MIN,
) -> TestConnectionResult:
"""
Test connection. This can be executed either as part
Expand All @@ -55,5 +53,4 @@ def test_connection(
test_fn=test_fn,
service_type=service_connection.type.value,
automation_workflow=automation_workflow,
timeout_seconds=timeout_seconds,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Mstr source module"""
"""MicroStrategy source module"""
import traceback
from typing import Iterable, List, Optional

from metadata.generated.schema.api.data.createChart import CreateChartRequest
from metadata.generated.schema.api.data.createDashboard import CreateDashboardRequest
from metadata.generated.schema.api.lineage.addLineage import AddLineageRequest
from metadata.generated.schema.entity.data.chart import Chart
from metadata.generated.schema.entity.services.connections.dashboard.mstrConnection import (
MstrConnection,
from metadata.generated.schema.entity.services.connections.dashboard.microStrategyConnection import (
MicroStrategyConnection,
)
from metadata.generated.schema.entity.services.ingestionPipelines.status import (
StackTraceError,
Expand All @@ -34,7 +34,7 @@
from metadata.ingestion.api.steps import InvalidSourceException
from metadata.ingestion.ometa.ometa_api import OpenMetadata
from metadata.ingestion.source.dashboard.dashboard_service import DashboardServiceSource
from metadata.ingestion.source.dashboard.mstr.models import (
from metadata.ingestion.source.dashboard.microstrategy.models import (
MstrDashboard,
MstrDashboardDetails,
MstrPage,
Expand All @@ -47,9 +47,9 @@
logger = ingestion_logger()


class MstrSource(DashboardServiceSource):
class MicrostrategySource(DashboardServiceSource):
"""
MSTR Source Class
Microstrategy Source Class
"""

@classmethod
Expand All @@ -60,10 +60,10 @@ def create(
pipeline_name: Optional[str] = None,
):
config = WorkflowSource.model_validate(config_dict)
connection: MstrConnection = config.serviceConnection.root.config
if not isinstance(connection, MstrConnection):
connection: MicroStrategyConnection = config.serviceConnection.root.config
if not isinstance(connection, MicroStrategyConnection):
raise InvalidSourceException(
f"Expected MstrConnection, but got {connection}"
f"Expected MicroStrategyConnection, but got {connection}"
)
return cls(config, metadata)

Expand All @@ -75,14 +75,18 @@ def get_dashboards_list(self) -> Optional[List[MstrDashboard]]:

if self.client.is_project_name():
project = self.client.get_project_by_name()
dashboards.extend(self.client.get_dashboards_list(project.id, project.name))

if not self.client.is_project_name():
for project in self.client.get_projects_list():
if project:
dashboards.extend(
self.client.get_dashboards_list(project.id, project.name)
)

if not self.client.is_project_name():
for project in self.client.get_projects_list():
if project:
dashboards.extend(
self.client.get_dashboards_list(project.id, project.name)
)

return dashboards

def get_dashboard_name(self, dashboard: MstrDashboard) -> str:
Expand Down Expand Up @@ -121,7 +125,7 @@ def yield_dashboard(
if dashboard_details:
try:
dashboard_url = (
f"{clean_uri(self.service_connection.hostPort)}/MicroStrategyLibrary/app/"
f"{clean_uri(str(self.service_connection.hostPort))}/MicroStrategyLibrary/app/"
f"{dashboard_details.projectId}/{dashboard_details.id}"
)
dashboard_request = CreateDashboardRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
MSTR Models
MicroStrategy Models
"""
from datetime import datetime
from typing import Any, List, Optional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from metadata.ingestion.source.dashboard.microstrategy.metadata import (
MicrostrategySource,
)
from metadata.utils.service_spec.default import DefaultDatabaseSpec

ServiceSpec = DefaultDatabaseSpec(metadata_source_class=MicrostrategySource)

This file was deleted.

Loading

0 comments on commit cb33f27

Please sign in to comment.