-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into jj--support-batch-domains-backend
- Loading branch information
Showing
51 changed files
with
1,346 additions
and
164 deletions.
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
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
90 changes: 90 additions & 0 deletions
90
...e/src/main/java/com/linkedin/datahub/graphql/resolvers/mutate/BatchAddOwnersResolver.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,90 @@ | ||
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.BatchAddOwnersInput; | ||
import com.linkedin.datahub.graphql.generated.OwnerInput; | ||
import com.linkedin.datahub.graphql.generated.ResourceRefInput; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.OwnerUtils; | ||
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 lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class BatchAddOwnersResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final EntityService _entityService; | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
final BatchAddOwnersInput input = bindArgument(environment.getArgument("input"), BatchAddOwnersInput.class); | ||
final List<OwnerInput> owners = input.getOwners(); | ||
final List<ResourceRefInput> resources = input.getResources(); | ||
final QueryContext context = environment.getContext(); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
// First, validate the batch | ||
validateOwners(owners); | ||
validateInputResources(resources, context); | ||
|
||
try { | ||
// Then execute the bulk add | ||
batchAddOwners(owners, 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 validateOwners(List<OwnerInput> owners) { | ||
for (OwnerInput ownerInput : owners) { | ||
OwnerUtils.validateOwner(UrnUtils.getUrn(ownerInput.getOwnerUrn()), ownerInput.getOwnerEntityType(), _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 (resource.getSubResource() != null) { | ||
throw new IllegalArgumentException("Malformed input provided: owners cannot be applied to subresources."); | ||
} | ||
|
||
if (!OwnerUtils.isAuthorizedToUpdateOwners(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 batchAddOwners(List<OwnerInput> owners, List<ResourceRefInput> resources, QueryContext context) { | ||
log.debug("Batch adding owners. owners: {}, resources: {}", owners, resources); | ||
try { | ||
OwnerUtils.addOwnersToResources(owners, resources, UrnUtils.getUrn(context.getActorUrn()), _entityService); | ||
} catch (Exception e) { | ||
throw new RuntimeException(String.format("Failed to batch add Owners %s to resources with urns %s!", | ||
owners, | ||
resources.stream().map(ResourceRefInput::getResourceUrn).collect(Collectors.toList())), | ||
e); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...rc/main/java/com/linkedin/datahub/graphql/resolvers/mutate/BatchRemoveOwnersResolver.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,83 @@ | ||
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.BatchRemoveOwnersInput; | ||
import com.linkedin.datahub.graphql.generated.ResourceRefInput; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.LabelUtils; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.OwnerUtils; | ||
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 lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class BatchRemoveOwnersResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final EntityService _entityService; | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
final BatchRemoveOwnersInput input = bindArgument(environment.getArgument("input"), BatchRemoveOwnersInput.class); | ||
final List<String> owners = input.getOwnerUrns(); | ||
final List<ResourceRefInput> resources = input.getResources(); | ||
final QueryContext context = environment.getContext(); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
// First, validate the batch | ||
validateInputResources(resources, context); | ||
|
||
try { | ||
// Then execute the bulk remove | ||
batchRemoveOwners(owners, 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 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 (resource.getSubResource() != null) { | ||
throw new IllegalArgumentException("Malformed input provided: owners cannot be removed from subresources."); | ||
} | ||
|
||
if (!OwnerUtils.isAuthorizedToUpdateOwners(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 batchRemoveOwners(List<String> ownerUrns, List<ResourceRefInput> resources, QueryContext context) { | ||
log.debug("Batch removing owners. owners: {}, resources: {}", ownerUrns, resources); | ||
try { | ||
OwnerUtils.removeOwnersFromResources(ownerUrns.stream().map(UrnUtils::getUrn).collect( | ||
Collectors.toList()), resources, UrnUtils.getUrn(context.getActorUrn()), _entityService); | ||
} catch (Exception e) { | ||
throw new RuntimeException(String.format("Failed to batch remove Owners %s to resources with urns %s!", | ||
ownerUrns, | ||
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
Oops, something went wrong.