-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ui): Batch set & unset Domain for assets via the UI #5560
Merged
jjoyce0510
merged 8 commits into
datahub-project:master
from
jjoyce0510:jj--support-batch-domains-backend
Aug 4, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8430c7a
Adding batch set domains resolver
jjoyce0510 34a0fdb
Support batch adding domains on the UI
jjoyce0510 34fa6ac
Merge remote-tracking branch 'acryl/jj--support-batch-domains-backend…
jjoyce0510 5b8a5d0
Support batch adding domain final touch
jjoyce0510 6b3d445
Merge remote-tracking branch 'acryl/jj--support-batch-domains-backend…
jjoyce0510 caf4fea
Addressing comments
jjoyce0510 6d973fa
Merge remote-tracking branch 'acryl/jj--support-batch-domains-backend…
jjoyce0510 2f9c4ce
Merge branch 'master' into jj--support-batch-domains-backend
jjoyce0510 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...e/src/main/java/com/linkedin/datahub/graphql/resolvers/mutate/BatchSetDomainResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.linkedin.datahub.graphql.resolvers.mutate; | ||
|
||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.generated.BatchSetDomainInput; | ||
import com.linkedin.datahub.graphql.generated.ResourceRefInput; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.DomainUtils; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class BatchSetDomainResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final EntityService _entityService; | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
final BatchSetDomainInput input = bindArgument(environment.getArgument("input"), BatchSetDomainInput.class); | ||
final String maybeDomainUrn = input.getDomainUrn(); | ||
final List<ResourceRefInput> resources = input.getResources(); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
// First, validate the domain | ||
validateDomain(maybeDomainUrn); | ||
validateInputResources(resources, context); | ||
|
||
try { | ||
// Then execute the bulk add | ||
batchSetDomains(maybeDomainUrn, resources, context); | ||
return true; | ||
} catch (Exception e) { | ||
log.error("Failed to perform update against input {}, {}", input.toString(), e.getMessage()); | ||
throw new RuntimeException(String.format("Failed to perform update against input %s", input.toString()), e); | ||
} | ||
}); | ||
} | ||
|
||
private void validateDomain(@Nullable String maybeDomainUrn) { | ||
if (maybeDomainUrn != null) { | ||
DomainUtils.validateDomain(UrnUtils.getUrn(maybeDomainUrn), _entityService); | ||
} | ||
} | ||
|
||
private void validateInputResources(List<ResourceRefInput> resources, QueryContext context) { | ||
for (ResourceRefInput resource : resources) { | ||
validateInputResource(resource, context); | ||
} | ||
} | ||
|
||
private void validateInputResource(ResourceRefInput resource, QueryContext context) { | ||
final Urn resourceUrn = UrnUtils.getUrn(resource.getResourceUrn()); | ||
if (!DomainUtils.isAuthorizedToUpdateDomainsForEntity(context, resourceUrn)) { | ||
throw new AuthorizationException("Unauthorized to perform this action. Please contact your DataHub administrator."); | ||
} | ||
LabelUtils.validateResource(resourceUrn, resource.getSubResource(), resource.getSubResourceType(), _entityService); | ||
} | ||
|
||
private void batchSetDomains(String maybeDomainUrn, List<ResourceRefInput> resources, QueryContext context) { | ||
log.debug("Batch adding Domains. domainUrn: {}, resources: {}", maybeDomainUrn, resources); | ||
try { | ||
DomainUtils.setDomainForResources(maybeDomainUrn == null ? null : UrnUtils.getUrn(maybeDomainUrn), | ||
resources, | ||
UrnUtils.getUrn(context.getActorUrn()), | ||
_entityService); | ||
} catch (Exception e) { | ||
throw new RuntimeException(String.format("Failed to batch set Domain %s to resources with urns %s!", | ||
maybeDomainUrn, | ||
resources.stream().map(ResourceRefInput::getResourceUrn).collect(Collectors.toList())), | ||
e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to allow users to set multiple domains on an asset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the product only allows one. The underlying data model was designed to support extension should this be a high-demand ask