From 4d686ea5429db66a72a98e9e3c4d6d0a20ab3d6d Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 3 Jun 2024 13:36:39 +0100 Subject: [PATCH] fix(views): Add relationship annotation to GlobalViewsSettings urn (#10597) --- .../settings/global/GlobalViewsSettings.pdl | 6 +++++- .../linkedin/metadata/service/ViewService.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/metadata-models/src/main/pegasus/com/linkedin/settings/global/GlobalViewsSettings.pdl b/metadata-models/src/main/pegasus/com/linkedin/settings/global/GlobalViewsSettings.pdl index ff34dea556855..10b1176b637ef 100644 --- a/metadata-models/src/main/pegasus/com/linkedin/settings/global/GlobalViewsSettings.pdl +++ b/metadata-models/src/main/pegasus/com/linkedin/settings/global/GlobalViewsSettings.pdl @@ -9,5 +9,9 @@ record GlobalViewsSettings { /** * The default View for the instance, or organization. */ + @Relationship = { + "name": "viewedWith", + "entityTypes": [ "dataHubView" ] + } defaultView: optional Urn -} \ No newline at end of file +} diff --git a/metadata-service/services/src/main/java/com/linkedin/metadata/service/ViewService.java b/metadata-service/services/src/main/java/com/linkedin/metadata/service/ViewService.java index 13bb4a5b9f73b..e01c2d224691a 100644 --- a/metadata-service/services/src/main/java/com/linkedin/metadata/service/ViewService.java +++ b/metadata-service/services/src/main/java/com/linkedin/metadata/service/ViewService.java @@ -11,12 +11,14 @@ import com.linkedin.metadata.entity.AspectUtils; import com.linkedin.metadata.key.DataHubViewKey; import com.linkedin.metadata.utils.EntityKeyUtils; +import com.linkedin.r2.RemoteInvocationException; import com.linkedin.view.DataHubViewDefinition; import com.linkedin.view.DataHubViewInfo; import com.linkedin.view.DataHubViewType; import io.datahubproject.metadata.context.OperationContext; import java.util.Objects; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import javax.annotation.Nonnull; import javax.annotation.Nullable; import lombok.extern.slf4j.Slf4j; @@ -177,6 +179,20 @@ public void deleteView(@Nonnull OperationContext opContext, @Nonnull Urn viewUrn try { this.entityClient.deleteEntity( opContext, Objects.requireNonNull(viewUrn, "viewUrn must not be null")); + + // Asynchronously delete all references to the entity (to return quickly) + CompletableFuture.runAsync( + () -> { + try { + this.entityClient.deleteEntityReferences(opContext, viewUrn); + } catch (RemoteInvocationException e) { + log.error( + String.format( + "Caught exception while attempting to clear all entity references for view with urn %s", + viewUrn), + e); + } + }); } catch (Exception e) { throw new RuntimeException(String.format("Failed to delete View with urn %s", viewUrn), e); }