mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-07 17:18:23 +00:00
parent
c94de59a40
commit
14e09bd1cc
90
ingestion/src/metadata/ingestion/ometa/mixins/server_mixin.py
Executable file
90
ingestion/src/metadata/ingestion/ometa/mixins/server_mixin.py
Executable file
@ -0,0 +1,90 @@
|
||||
# Copyright 2021 Collate
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# 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.
|
||||
"""
|
||||
Mixin class containing Server and client specific methods
|
||||
|
||||
To be used by OpenMetadata class
|
||||
"""
|
||||
import re
|
||||
from importlib.metadata import version
|
||||
|
||||
from metadata.ingestion.ometa.client import REST
|
||||
from metadata.utils.logger import ometa_logger
|
||||
|
||||
logger = ometa_logger()
|
||||
|
||||
|
||||
class VersionParsingException(Exception):
|
||||
"""
|
||||
Used when we cannot parse version information from a string
|
||||
"""
|
||||
|
||||
|
||||
class VersionMismatchException(Exception):
|
||||
"""
|
||||
Used when server and client versions do not match
|
||||
"""
|
||||
|
||||
|
||||
class OMetaServerMixin:
|
||||
"""
|
||||
OpenMetadata API methods related to the Pipeline Entity
|
||||
|
||||
To be inherited by OpenMetadata
|
||||
"""
|
||||
|
||||
client: REST
|
||||
|
||||
@staticmethod
|
||||
def get_version_from_string(raw_version: str) -> str:
|
||||
"""
|
||||
Given a raw version string, such as `0.10.1.dev0` or
|
||||
`0.11.0-SNAPSHOT`, we should extract the major.minor.patch
|
||||
:param raw_version: raw string with version info
|
||||
:return: Clean version string
|
||||
"""
|
||||
try:
|
||||
return re.match(r"\d+.\d+.\d+", raw_version).group(0)
|
||||
except AttributeError as err:
|
||||
raise VersionParsingException(
|
||||
f"Can't extract version from {raw_version} - {err}"
|
||||
)
|
||||
|
||||
def get_server_version(self) -> str:
|
||||
"""
|
||||
Run endpoint /version to check server version
|
||||
:return: Server version
|
||||
"""
|
||||
raw_version = self.client.get("/version")["version"]
|
||||
return self.get_version_from_string(raw_version)
|
||||
|
||||
def get_client_version(self) -> str:
|
||||
"""
|
||||
Get openmetadata-ingestion module version
|
||||
:return: client version
|
||||
"""
|
||||
raw_version = version("openmetadata-ingestion")
|
||||
return self.get_version_from_string(raw_version)
|
||||
|
||||
def validate_versions(self) -> None:
|
||||
"""
|
||||
Validate Server & Client versions. They should match.
|
||||
Otherwise, raise VersionMismatchException
|
||||
"""
|
||||
logger.debug("Validating client and server versions")
|
||||
|
||||
server_version = self.get_server_version()
|
||||
client_version = self.get_client_version()
|
||||
|
||||
if server_version != client_version:
|
||||
raise VersionMismatchException(
|
||||
f"Server version is {server_version} vs. Client version {client_version}. Both should match."
|
||||
)
|
@ -58,6 +58,7 @@ from metadata.ingestion.ometa.mixins.es_mixin import ESMixin
|
||||
from metadata.ingestion.ometa.mixins.glossary_mixin import GlossaryMixin
|
||||
from metadata.ingestion.ometa.mixins.mlmodel_mixin import OMetaMlModelMixin
|
||||
from metadata.ingestion.ometa.mixins.pipeline_mixin import OMetaPipelineMixin
|
||||
from metadata.ingestion.ometa.mixins.server_mixin import OMetaServerMixin
|
||||
from metadata.ingestion.ometa.mixins.service_mixin import OMetaServiceMixin
|
||||
from metadata.ingestion.ometa.mixins.table_mixin import OMetaTableMixin
|
||||
from metadata.ingestion.ometa.mixins.tag_mixin import OMetaTagMixin
|
||||
@ -121,6 +122,7 @@ class OpenMetadata(
|
||||
GlossaryMixin,
|
||||
OMetaServiceMixin,
|
||||
ESMixin,
|
||||
OMetaServerMixin,
|
||||
Generic[T, C],
|
||||
):
|
||||
"""
|
||||
@ -166,6 +168,8 @@ class OpenMetadata(
|
||||
self.client = REST(client_config)
|
||||
self._use_raw_data = raw_data
|
||||
|
||||
self.validate_versions()
|
||||
|
||||
def get_suffix(self, entity: Type[T]) -> str: # pylint: disable=R0911,R0912
|
||||
"""
|
||||
Given an entity Type from the generated sources,
|
||||
|
41
ingestion/tests/unit/test_server_mixin.py
Normal file
41
ingestion/tests/unit/test_server_mixin.py
Normal file
@ -0,0 +1,41 @@
|
||||
# Copyright 2021 Collate
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# 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.
|
||||
"""
|
||||
Validate Server Mixin version methods
|
||||
"""
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from metadata.ingestion.ometa.mixins.server_mixin import OMetaServerMixin
|
||||
|
||||
|
||||
class OMetaServerTest(TestCase):
|
||||
"""
|
||||
Check version methods
|
||||
"""
|
||||
|
||||
mixin = OMetaServerMixin()
|
||||
|
||||
def test_get_version_from_string(self):
|
||||
"""
|
||||
We should be able to parse regular version responses
|
||||
"""
|
||||
self.assertEqual("0.11.0", self.mixin.get_version_from_string("0.11.0.dev0"))
|
||||
self.assertEqual("0.11.0", self.mixin.get_version_from_string("0.11.0"))
|
||||
self.assertEqual(
|
||||
"1111.11.111", self.mixin.get_version_from_string("1111.11.111")
|
||||
)
|
||||
self.assertEqual(
|
||||
"1111.11.111", self.mixin.get_version_from_string("1111.11.111-SNAPSHOT")
|
||||
)
|
||||
self.assertEqual(
|
||||
"0.11.1", self.mixin.get_version_from_string("0.11.1.0.0.1.patch")
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user