Skip to content

Commit

Permalink
MINOR: Add Governance Bot to the workflow automated tasks (open-metad…
Browse files Browse the repository at this point in the history
…ata#19222)

* Add Governance Bot to the workflow automated tasks

* Fix tests
  • Loading branch information
IceS2 authored Jan 7, 2025
1 parent 3d8b9b3 commit 617b894
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void execute(DelegateExecution execution) {
.orElse(null);
String user =
Optional.ofNullable((String) execution.getVariable(RESOLVED_BY_VARIABLE))
.orElse(entity.getUpdatedBy());
.orElse("governance-bot");

setStatus(entity, entityType, user, certification);
} catch (Exception exc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void execute(DelegateExecution execution) {
String status = (String) statusExpr.getValue(execution);
String user =
Optional.ofNullable((String) execution.getVariable(RESOLVED_BY_VARIABLE))
.orElse(glossaryTerm.getUpdatedBy());
.orElse("governance-bot");

setStatus(glossaryTerm, user, status);
} catch (Exception exc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,8 @@ private void validateAssignee(Thread thread) {
String createdByUserName = thread.getCreatedBy();
User createdByUser =
Entity.getEntityByName(USER, createdByUserName, TEAMS_FIELD, NON_DELETED);
if (Boolean.TRUE.equals(createdByUser.getIsBot())) {
if (Boolean.TRUE.equals(createdByUser.getIsBot())
&& !createdByUser.getName().equals("governance-bot")) {
throw new IllegalArgumentException("Task cannot be created by bot only by user or teams");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openmetadata.schema.api.data.CreateGlossary;
import org.openmetadata.schema.api.data.CreateGlossaryTerm;
import org.openmetadata.schema.api.data.CreateTable;
Expand All @@ -88,6 +90,7 @@
import org.openmetadata.schema.type.TaskDetails;
import org.openmetadata.schema.type.TaskStatus;
import org.openmetadata.service.Entity;
import org.openmetadata.service.governance.workflows.WorkflowHandler;
import org.openmetadata.service.resources.EntityResourceTest;
import org.openmetadata.service.resources.databases.TableResourceTest;
import org.openmetadata.service.resources.feeds.FeedResource.ThreadList;
Expand Down Expand Up @@ -264,7 +267,11 @@ void test_commonPrefixTagLabelCount(TestInfo test) throws IOException {
}

@Test
@Execution(ExecutionMode.SAME_THREAD)
void patch_addDeleteReviewers(TestInfo test) throws IOException {
// Note: We are disabling the GlossaryTermApprovalWorkflow to avoid the Workflow Kicking it and
// adding extra ChangeDescriptions.
WorkflowHandler.getInstance().suspendWorkflow("GlossaryTermApprovalWorkflow");
CreateGlossaryTerm create =
createRequest(getEntityName(test), "desc", "", null).withReviewers(null).withSynonyms(null);
GlossaryTerm term = createEntity(create, ADMIN_AUTH_HEADERS);
Expand All @@ -281,14 +288,11 @@ void patch_addDeleteReviewers(TestInfo test) throws IOException {
term.withReviewers(List.of(USER1_REF))
.withSynonyms(List.of("synonym1"))
.withReferences(List.of(reference1));
patchEntity(term.getId(), origJson, term, ADMIN_AUTH_HEADERS);
waitForTaskToBeCreated(term.getFullyQualifiedName());

ChangeDescription change = getChangeDescription(term, MINOR_UPDATE);
fieldAdded(change, "reviewers", List.of(USER1_REF));
fieldAdded(change, "synonyms", List.of("synonym1"));
fieldAdded(change, "references", List.of(reference1));
fieldUpdated(change, "status", Status.APPROVED, Status.IN_REVIEW);
term = patchEntityAndCheck(term, origJson, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);

// Add reviewer USER2, synonym2, reference2 in PATCH request
Expand All @@ -303,7 +307,6 @@ void patch_addDeleteReviewers(TestInfo test) throws IOException {
fieldAdded(change, "reviewers", List.of(USER1_REF, USER2_REF));
fieldAdded(change, "synonyms", List.of("synonym1", "synonym2"));
fieldAdded(change, "references", List.of(reference1, reference2));
fieldUpdated(change, "status", Status.APPROVED, Status.IN_REVIEW);
term = patchEntityAndCheck(term, origJson, ADMIN_AUTH_HEADERS, CHANGE_CONSOLIDATED, change);

// Remove a reviewer USER1, synonym1, reference1 in PATCH request
Expand All @@ -316,8 +319,10 @@ void patch_addDeleteReviewers(TestInfo test) throws IOException {
fieldAdded(change, "reviewers", List.of(USER2_REF));
fieldAdded(change, "synonyms", List.of("synonym2"));
fieldAdded(change, "references", List.of(reference2));
fieldUpdated(change, "status", Status.APPROVED, Status.IN_REVIEW);
patchEntityAndCheck(term, origJson, ADMIN_AUTH_HEADERS, CHANGE_CONSOLIDATED, change);

// Note: We are re-enabling the GlossaryTermApprovalWorkflow.
WorkflowHandler.getInstance().resumeWorkflow("GlossaryTermApprovalWorkflow");
}

@Test
Expand Down Expand Up @@ -485,12 +490,19 @@ taskId2, new ResolveTask().withNewValue("rejected"), ADMIN_AUTH_HEADERS),
String origJson = JsonUtils.pojoToJson(g2t5);

// Add reviewer DATA_CONSUMER in PATCH request
g2t5.withReviewers(List.of(DATA_CONSUMER_REF, USER1_REF, USER2_REF));
List<EntityReference> newReviewers = List.of(DATA_CONSUMER_REF, USER1_REF, USER2_REF);
g2t5.withReviewers(newReviewers);

double previousVersion = g2t5.getVersion();
g2t5 = patchEntityUsingFqn(g2t5.getFullyQualifiedName(), origJson, g2t5, ADMIN_AUTH_HEADERS);

ChangeDescription change = getChangeDescription(g2t5, MINOR_UPDATE);
fieldAdded(change, "reviewers", List.of(DATA_CONSUMER_REF));
fieldUpdated(change, "status", Status.DRAFT.value(), Status.IN_REVIEW.value());
g2t5 = patchEntityUsingFqnAndCheck(g2t5, origJson, ADMIN_AUTH_HEADERS, MINOR_UPDATE, change);
// Due to the Glossary Workflow changing the Status from 'DRAFT' to 'IN_REVIEW' as a
// GovernanceBot, two changes are created.
assertEquals(g2t5.getVersion(), previousVersion + 0.2, 0.0001);
assertTrue(
g2t5.getReviewers().containsAll(newReviewers)
&& newReviewers.containsAll(g2t5.getReviewers()));
assertEquals(g2t5.getStatus(), Status.IN_REVIEW);

Thread approvalTask1 =
assertApprovalTask(g2t5, TaskStatus.Open); // A Request Approval task is opened
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public final class TestUtils {
public static String LONG_ENTITY_NAME = "a".repeat(256 + 1);
public static final Map<String, String> ADMIN_AUTH_HEADERS =
authHeaders(ADMIN_USER_NAME + "@open-metadata.org");
public static final String GOVERNANCE_BOT = "governance-bot";
public static final Map<String, String> GOVERNANCE_BOT_AUTH_HEADERS =
authHeaders(GOVERNANCE_BOT + "@open-metadata.org");
public static final String INGESTION_BOT = "ingestion-bot";
public static final Map<String, String> INGESTION_BOT_AUTH_HEADERS =
authHeaders(INGESTION_BOT + "@open-metadata.org");
Expand Down

0 comments on commit 617b894

Please sign in to comment.