mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-20 05:15:08 +00:00
Test Connection Improvements: Use patch instead of put (#10897)
* Test Connection Improvements: Use patch instead of put * Update openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/WorkflowRepository.java Co-authored-by: Nahuel <nahuel@getcollate.io> --------- Co-authored-by: Nahuel <nahuel@getcollate.io>
This commit is contained in:
parent
6cf357ed2a
commit
5bd476da23
@ -105,7 +105,7 @@ def _test_connection_steps(
|
|||||||
def _test_connection_steps_automation_workflow(
|
def _test_connection_steps_automation_workflow(
|
||||||
metadata: OpenMetadata,
|
metadata: OpenMetadata,
|
||||||
steps: List[TestConnectionStep],
|
steps: List[TestConnectionStep],
|
||||||
automation_workflow: Optional[AutomationWorkflow],
|
automation_workflow: AutomationWorkflow,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Run the test connection as part of the automation workflow
|
Run the test connection as part of the automation workflow
|
||||||
@ -137,15 +137,9 @@ def _test_connection_steps_automation_workflow(
|
|||||||
)
|
)
|
||||||
|
|
||||||
test_connection_result.lastUpdatedAt = datetime.now().timestamp()
|
test_connection_result.lastUpdatedAt = datetime.now().timestamp()
|
||||||
updated_workflow = CreateWorkflowRequest(
|
metadata.patch_automation_workflow_response(
|
||||||
name=automation_workflow.name,
|
automation_workflow, test_connection_result, WorkflowStatus.Running
|
||||||
description=automation_workflow.description,
|
|
||||||
workflowType=automation_workflow.workflowType,
|
|
||||||
request=automation_workflow.request,
|
|
||||||
response=test_connection_result,
|
|
||||||
status=WorkflowStatus.Running,
|
|
||||||
)
|
)
|
||||||
metadata.create_or_update(updated_workflow)
|
|
||||||
|
|
||||||
test_connection_result.lastUpdatedAt = datetime.now().timestamp()
|
test_connection_result.lastUpdatedAt = datetime.now().timestamp()
|
||||||
|
|
||||||
@ -155,15 +149,8 @@ def _test_connection_steps_automation_workflow(
|
|||||||
else StatusType.Successful
|
else StatusType.Successful
|
||||||
)
|
)
|
||||||
|
|
||||||
metadata.create_or_update(
|
metadata.patch_automation_workflow_response(
|
||||||
CreateWorkflowRequest(
|
automation_workflow, test_connection_result, WorkflowStatus.Successful
|
||||||
name=automation_workflow.name,
|
|
||||||
description=automation_workflow.description,
|
|
||||||
workflowType=automation_workflow.workflowType,
|
|
||||||
request=automation_workflow.request,
|
|
||||||
response=test_connection_result,
|
|
||||||
status=WorkflowStatus.Successful,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -19,7 +19,14 @@ from typing import Dict, List, Optional, Type, TypeVar, Union
|
|||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from metadata.generated.schema.entity.automations.workflow import (
|
||||||
|
Workflow as AutomationWorkflow,
|
||||||
|
)
|
||||||
|
from metadata.generated.schema.entity.automations.workflow import WorkflowStatus
|
||||||
from metadata.generated.schema.entity.data.table import Table, TableConstraint
|
from metadata.generated.schema.entity.data.table import Table, TableConstraint
|
||||||
|
from metadata.generated.schema.entity.services.connections.testConnectionResult import (
|
||||||
|
TestConnectionResult,
|
||||||
|
)
|
||||||
from metadata.generated.schema.type import basic
|
from metadata.generated.schema.type import basic
|
||||||
from metadata.generated.schema.type.entityReference import EntityReference
|
from metadata.generated.schema.type.entityReference import EntityReference
|
||||||
from metadata.generated.schema.type.tagLabel import LabelType, State, TagSource
|
from metadata.generated.schema.type.tagLabel import LabelType, State, TagSource
|
||||||
@ -462,3 +469,40 @@ class OMetaPatchMixin(OMetaPatchMixinBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def patch_automation_workflow_response(
|
||||||
|
self,
|
||||||
|
automation_workflow: AutomationWorkflow,
|
||||||
|
test_connection_result: TestConnectionResult,
|
||||||
|
workflow_status: WorkflowStatus,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Given an AutomationWorkflow, JSON PATCH the status and response.
|
||||||
|
"""
|
||||||
|
result_data: Dict = {
|
||||||
|
PatchField.PATH: PatchPath.RESPONSE,
|
||||||
|
PatchField.VALUE: test_connection_result.dict(),
|
||||||
|
PatchField.OPERATION: PatchOperation.ADD,
|
||||||
|
}
|
||||||
|
|
||||||
|
# for deserializing into json convert enum object to string
|
||||||
|
result_data[PatchField.VALUE]["status"] = result_data[PatchField.VALUE][
|
||||||
|
"status"
|
||||||
|
].value
|
||||||
|
|
||||||
|
status_data: Dict = {
|
||||||
|
PatchField.PATH: PatchPath.STATUS,
|
||||||
|
PatchField.OPERATION: PatchOperation.ADD,
|
||||||
|
PatchField.VALUE: workflow_status.value,
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.client.patch(
|
||||||
|
path=f"{self.get_suffix(AutomationWorkflow)}/{model_str(automation_workflow.id)}",
|
||||||
|
data=json.dumps([result_data, status_data]),
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
logger.debug(traceback.format_exc())
|
||||||
|
logger.error(
|
||||||
|
f"Error trying to PATCH status for automation workflow [{model_str(automation_workflow)}]: {exc}"
|
||||||
|
)
|
||||||
|
@ -80,6 +80,8 @@ class PatchPath(str, Enum):
|
|||||||
SYNONYMS = "/synonyms/{index}"
|
SYNONYMS = "/synonyms/{index}"
|
||||||
TABLE_CONSTRAINTS = "/tableConstraints"
|
TABLE_CONSTRAINTS = "/tableConstraints"
|
||||||
TAGS = "/tags/{tag_index}"
|
TAGS = "/tags/{tag_index}"
|
||||||
|
RESPONSE = "/response"
|
||||||
|
STATUS = "/status"
|
||||||
|
|
||||||
|
|
||||||
class PatchValue(str, Enum):
|
class PatchValue(str, Enum):
|
||||||
|
@ -15,7 +15,7 @@ import org.openmetadata.service.util.EntityUtil;
|
|||||||
public class WorkflowRepository extends EntityRepository<Workflow> {
|
public class WorkflowRepository extends EntityRepository<Workflow> {
|
||||||
|
|
||||||
private static final String UPDATE_FIELDS = "owner";
|
private static final String UPDATE_FIELDS = "owner";
|
||||||
private static final String PATCH_FIELDS = "owner";
|
private static final String PATCH_FIELDS = "owner,status,response";
|
||||||
|
|
||||||
public WorkflowRepository(CollectionDAO dao) {
|
public WorkflowRepository(CollectionDAO dao) {
|
||||||
super(
|
super(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user