-
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 remote-tracking branch 'datahub-project/feat/elasticsearch-opti…
…mization-ext' into david-leifker/elasticsearch-optimization-ext
- Loading branch information
Showing
120 changed files
with
8,264 additions
and
3,484 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
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
104 changes: 104 additions & 0 deletions
104
...-core/src/main/java/com/linkedin/datahub/graphql/resolvers/embed/UpdateEmbedResolver.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,104 @@ | ||
package com.linkedin.datahub.graphql.resolvers.embed; | ||
|
||
import com.linkedin.common.AuditStamp; | ||
import com.linkedin.common.Embed; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.data.template.SetMode; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.generated.UpdateEmbedInput; | ||
import com.linkedin.datahub.graphql.resolvers.mutate.util.EmbedUtils; | ||
import com.linkedin.events.metadata.ChangeType; | ||
import com.linkedin.metadata.Constants; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import com.linkedin.metadata.utils.GenericRecordUtils; | ||
import com.linkedin.mxe.MetadataChangeProposal; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.concurrent.CompletableFuture; | ||
import javax.annotation.Nonnull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
import static com.linkedin.datahub.graphql.resolvers.mutate.MutationUtils.*; | ||
|
||
|
||
/** | ||
* Resolver used for updating the embed render URL for an asset. | ||
*/ | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class UpdateEmbedResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final EntityService _entityService; | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
|
||
final QueryContext context = environment.getContext(); | ||
final UpdateEmbedInput input = bindArgument(environment.getArgument("input"), UpdateEmbedInput.class); | ||
final Urn entityUrn = UrnUtils.getUrn(input.getUrn()); | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
|
||
if (!EmbedUtils.isAuthorizedToUpdateEmbedForEntity(entityUrn, environment.getContext())) { | ||
throw new AuthorizationException("Unauthorized to perform this action. Please contact your DataHub administrator."); | ||
} | ||
validateUpdateEmbedInput( | ||
input, | ||
_entityService | ||
); | ||
try { | ||
final Embed embed = (Embed) getAspectFromEntity( | ||
entityUrn.toString(), | ||
Constants.EMBED_ASPECT_NAME, | ||
_entityService, | ||
new Embed()); | ||
|
||
updateEmbed(embed, input); | ||
|
||
final MetadataChangeProposal proposal = new MetadataChangeProposal(); | ||
proposal.setEntityUrn(entityUrn); | ||
proposal.setEntityType(entityUrn.getEntityType()); | ||
proposal.setAspectName(Constants.EMBED_ASPECT_NAME); | ||
proposal.setAspect(GenericRecordUtils.serializeAspect(embed)); | ||
proposal.setChangeType(ChangeType.UPSERT); | ||
_entityService.ingestProposal( | ||
proposal, | ||
new AuditStamp().setActor(UrnUtils.getUrn(context.getActorUrn())).setTime(System.currentTimeMillis()), | ||
false | ||
); | ||
return true; | ||
} catch (Exception e) { | ||
throw new RuntimeException(String.format("Failed to update Embed for to resource with entity urn %s", entityUrn), e); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Validates an instance of {@link UpdateEmbedInput}, and throws an {@link IllegalArgumentException} if the input | ||
* is not valid. | ||
* | ||
* For an input to be valid, the target URN must exist. | ||
* | ||
* @param input the input to validate | ||
* @param entityService an instance of {@link EntityService} used to validate the input. | ||
*/ | ||
private static void validateUpdateEmbedInput(@Nonnull final UpdateEmbedInput input, @Nonnull final EntityService entityService) { | ||
if (!entityService.exists(UrnUtils.getUrn(input.getUrn()))) { | ||
throw new IllegalArgumentException( | ||
String.format("Failed to update embed for entity with urn %s. Entity does not exist!", input.getUrn())); | ||
} | ||
} | ||
|
||
/** | ||
* Applies an instance of {@link UpdateEmbedInput} to a base instance of {@link Embed}. | ||
* @param embed an embed to update | ||
* @param input the updates to apply | ||
*/ | ||
private static void updateEmbed(@Nonnull final Embed embed, @Nonnull final UpdateEmbedInput input) { | ||
embed.setRenderUrl(input.getRenderUrl(), SetMode.IGNORE_NULL); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...hql-core/src/main/java/com/linkedin/datahub/graphql/resolvers/mutate/util/EmbedUtils.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,36 @@ | ||
package com.linkedin.datahub.graphql.resolvers.mutate.util; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.authorization.AuthorizationUtils; | ||
import com.linkedin.datahub.graphql.authorization.ConjunctivePrivilegeGroup; | ||
import com.linkedin.datahub.graphql.authorization.DisjunctivePrivilegeGroup; | ||
import com.linkedin.metadata.authorization.PoliciesConfig; | ||
import javax.annotation.Nonnull; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
|
||
@Slf4j | ||
public class EmbedUtils { | ||
private static final ConjunctivePrivilegeGroup ALL_PRIVILEGES_GROUP = new ConjunctivePrivilegeGroup(ImmutableList.of( | ||
PoliciesConfig.EDIT_ENTITY_PRIVILEGE.getType() | ||
)); | ||
|
||
private EmbedUtils() { } | ||
|
||
public static boolean isAuthorizedToUpdateEmbedForEntity(@Nonnull final Urn entityUrn, @Nonnull final QueryContext context) { | ||
final DisjunctivePrivilegeGroup orPrivilegeGroups = new DisjunctivePrivilegeGroup(ImmutableList.of( | ||
ALL_PRIVILEGES_GROUP, | ||
new ConjunctivePrivilegeGroup(ImmutableList.of(PoliciesConfig.EDIT_ENTITY_EMBED_PRIVILEGE.getType())) | ||
)); | ||
|
||
return AuthorizationUtils.isAuthorized( | ||
context.getAuthorizer(), | ||
context.getActorUrn(), | ||
entityUrn.getEntityType(), | ||
entityUrn.toString(), | ||
orPrivilegeGroups); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...hql-core/src/main/java/com/linkedin/datahub/graphql/types/common/mappers/EmbedMapper.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,22 @@ | ||
package com.linkedin.datahub.graphql.types.common.mappers; | ||
|
||
import com.linkedin.datahub.graphql.generated.Embed; | ||
import com.linkedin.datahub.graphql.types.mappers.ModelMapper; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class EmbedMapper implements ModelMapper<com.linkedin.common.Embed, Embed> { | ||
|
||
public static final EmbedMapper INSTANCE = new EmbedMapper(); | ||
|
||
public static Embed map(@Nonnull final com.linkedin.common.Embed metadata) { | ||
return INSTANCE.apply(metadata); | ||
} | ||
|
||
@Override | ||
public Embed apply(@Nonnull final com.linkedin.common.Embed input) { | ||
final Embed result = new Embed(); | ||
result.setRenderUrl(input.getRenderUrl()); | ||
return result; | ||
} | ||
} |
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
Oops, something went wrong.