forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(models) : Joins (Datasets) schema, resolvers and UI (datahub-pro…
…ject#8325) Co-authored-by: Raj Tekal <[email protected]> Co-authored-by: Raj Tekal <[email protected]> Co-authored-by: Raj Tekal <[email protected]> Co-authored-by: Chris Collins <[email protected]>
- Loading branch information
1 parent
aeb245d
commit 9cd0542
Showing
62 changed files
with
3,638 additions
and
30 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
113 changes: 113 additions & 0 deletions
113
...linkedin/datahub/graphql/types/ermodelrelationship/CreateERModelRelationshipResolver.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,113 @@ | ||
package com.linkedin.datahub.graphql.types.ermodelrelationship; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument; | ||
|
||
import com.datahub.authentication.Authentication; | ||
import com.linkedin.common.urn.CorpuserUrn; | ||
import com.linkedin.common.urn.ERModelRelationshipUrn; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.generated.ERModelRelationship; | ||
import com.linkedin.datahub.graphql.generated.ERModelRelationshipPropertiesInput; | ||
import com.linkedin.datahub.graphql.generated.ERModelRelationshipUpdateInput; | ||
import com.linkedin.datahub.graphql.types.ermodelrelationship.mappers.ERModelRelationMapper; | ||
import com.linkedin.datahub.graphql.types.ermodelrelationship.mappers.ERModelRelationshipUpdateInputMapper; | ||
import com.linkedin.entity.client.EntityClient; | ||
import com.linkedin.metadata.service.ERModelRelationshipService; | ||
import com.linkedin.mxe.MetadataChangeProposal; | ||
import com.linkedin.r2.RemoteInvocationException; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collection; | ||
import java.util.concurrent.CompletableFuture; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.codec.digest.DigestUtils; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class CreateERModelRelationshipResolver | ||
implements DataFetcher<CompletableFuture<ERModelRelationship>> { | ||
|
||
private final EntityClient _entityClient; | ||
private final ERModelRelationshipService _erModelRelationshipService; | ||
|
||
@Override | ||
public CompletableFuture<ERModelRelationship> get(DataFetchingEnvironment environment) | ||
throws Exception { | ||
final ERModelRelationshipUpdateInput input = | ||
bindArgument(environment.getArgument("input"), ERModelRelationshipUpdateInput.class); | ||
|
||
final ERModelRelationshipPropertiesInput erModelRelationshipPropertiesInput = | ||
input.getProperties(); | ||
String ermodelrelationName = erModelRelationshipPropertiesInput.getName(); | ||
String source = erModelRelationshipPropertiesInput.getSource(); | ||
String destination = erModelRelationshipPropertiesInput.getDestination(); | ||
|
||
String lowDataset = source; | ||
String highDataset = destination; | ||
if (source.compareTo(destination) > 0) { | ||
lowDataset = destination; | ||
highDataset = source; | ||
} | ||
// The following sequence mimics datahub.emitter.mce_builder.datahub_guid | ||
|
||
String ermodelrelationKey = | ||
"{\"Source\":\"" | ||
+ lowDataset | ||
+ "\",\"Destination\":\"" | ||
+ highDataset | ||
+ "\",\"ERModelRelationName\":\"" | ||
+ ermodelrelationName | ||
+ "\"}"; | ||
|
||
byte[] mybytes = ermodelrelationKey.getBytes(StandardCharsets.UTF_8); | ||
|
||
String ermodelrelationKeyEncoded = new String(mybytes, StandardCharsets.UTF_8); | ||
String ermodelrelationGuid = DigestUtils.md5Hex(ermodelrelationKeyEncoded); | ||
log.info( | ||
"ermodelrelationkey {}, ermodelrelationGuid {}", | ||
ermodelrelationKeyEncoded, | ||
ermodelrelationGuid); | ||
|
||
ERModelRelationshipUrn inputUrn = new ERModelRelationshipUrn(ermodelrelationGuid); | ||
QueryContext context = environment.getContext(); | ||
final Authentication authentication = context.getAuthentication(); | ||
final CorpuserUrn actor = CorpuserUrn.createFromString(context.getActorUrn()); | ||
if (!ERModelRelationshipType.canCreateERModelRelation( | ||
context, | ||
Urn.createFromString(input.getProperties().getSource()), | ||
Urn.createFromString(input.getProperties().getDestination()))) { | ||
throw new AuthorizationException( | ||
"Unauthorized to create erModelRelationship. Please contact your DataHub administrator."); | ||
} | ||
return CompletableFuture.supplyAsync( | ||
() -> { | ||
try { | ||
log.debug("Create ERModelRelation input: {}", input); | ||
final Collection<MetadataChangeProposal> proposals = | ||
ERModelRelationshipUpdateInputMapper.map(input, actor); | ||
proposals.forEach(proposal -> proposal.setEntityUrn(inputUrn)); | ||
try { | ||
_entityClient.batchIngestProposals(proposals, context.getAuthentication(), false); | ||
} catch (RemoteInvocationException e) { | ||
throw new RuntimeException("Failed to create erModelRelationship entity", e); | ||
} | ||
return ERModelRelationMapper.map( | ||
_erModelRelationshipService.getERModelRelationshipResponse( | ||
Urn.createFromString(inputUrn.toString()), authentication)); | ||
} catch (Exception e) { | ||
log.error( | ||
"Failed to create ERModelRelation to resource with input {}, {}", | ||
input, | ||
e.getMessage()); | ||
throw new RuntimeException( | ||
String.format( | ||
"Failed to create erModelRelationship to resource with input %s", input), | ||
e); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.