Skip to content
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/data-contract): Data contract UI under Validation Tab #10625

Merged
merged 32 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bdd9667
feat(graphql) data contract resolvers for graphql
jayacryl May 30, 2024
a240d12
feat(data-contract): Add initial file for data contract on validation…
amit-apptware May 30, 2024
2704ca7
feat(data-contract): add datacontract tab file and its graphql files
amit-apptware May 31, 2024
6785fc9
feat(data-contract): add modal files to create contract
amit-apptware May 31, 2024
e89e384
spotless
jayacryl Jun 1, 2024
10c7568
wired contracts to resolver
jayacryl Jun 1, 2024
292a936
added schema file
jayacryl Jun 1, 2024
437b63c
Merge branch 'master' into jp--datacontract-tab
jayacryl Jun 1, 2024
3a6b3ef
feat(ui/data-contract): remove acryl file and use datahub component f…
amit-apptware Jun 2, 2024
23669a0
Merge remote-tracking branch 'upstream/jp--datacontract-tab' into ag-…
amit-apptware Jun 2, 2024
3882ece
feat(ui/data-contract): remove other acryl files and create OSS files
amit-apptware Jun 4, 2024
25536da
feat(ui/data-contract): add condtional rendering the assertion list i…
amit-apptware Jun 5, 2024
0cb37e2
feat(ui/data-contract): removed unwanted code for data contract
amit-apptware Jun 6, 2024
2d872c8
feat(ui/data-contract): add datacontract image for assertion list
amit-apptware Jun 6, 2024
7915c5f
feat(ui/data-contract): add contract icon assigned to assertion
amit-apptware Jun 7, 2024
0555c61
feat(ui/data-contract): change graphql request to update the status a…
amit-apptware Jun 7, 2024
21e148a
feat(ui/data-contract): removed unwanted code
amit-apptware Jun 10, 2024
8c7d796
feat(ui/data-contract): Merge latest code from master
amit-apptware Jun 10, 2024
0bd62b1
feat(ui/data-contract): resolved PR comments
amit-apptware Jun 11, 2024
b1278f9
feat(ui/data-contract): resolved PR comments
amit-apptware Jun 11, 2024
364d508
feat(ui/data-contract): resolved PR comments
amit-apptware Jun 12, 2024
c8e71e7
feat(ui/data-contract): resolved PR comments
amit-apptware Jun 12, 2024
036cdf3
feat(ui/data-contract): create util function for the volume
amit-apptware Jun 14, 2024
abadacb
merge master into feature
amit-apptware Jun 14, 2024
f74169a
feat(feature-flags): data contract feature flag
jayacryl Jun 14, 2024
f74b7d9
feat(ui/data-contracct): remove yarn lock file changes
amit-apptware Jun 14, 2024
b598719
nit fix
jayacryl Jun 14, 2024
26c99d7
disable data contracts by default
jayacryl Jun 14, 2024
8761259
WIP: a240d125adb feat(data-contract): Add initial file for data contr…
amit-apptware Jun 18, 2024
5dd3125
feat(ui/data-contract): fix lint issues
amit-apptware Jun 18, 2024
650ac95
feat(ui/data-contract): fix lint issues
amit-apptware Jun 18, 2024
2b407d2
Merge branch 'master' into ag--datacontract-tab
amit-apptware Jun 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.linkedin.datahub.graphql.resolvers.datacontract;

import com.datahub.authorization.ConjunctivePrivilegeGroup;
import com.datahub.authorization.DisjunctivePrivilegeGroup;
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.metadata.authorization.PoliciesConfig;
import javax.annotation.Nonnull;

public class DataContractUtils {

public static boolean canEditDataContract(@Nonnull QueryContext context, Urn entityUrn) {
final DisjunctivePrivilegeGroup orPrivilegeGroups =
new DisjunctivePrivilegeGroup(
ImmutableList.of(
AuthorizationUtils.ALL_PRIVILEGES_GROUP,
new ConjunctivePrivilegeGroup(
ImmutableList.of(
PoliciesConfig.EDIT_ENTITY_DATA_CONTRACT_PRIVILEGE.getType()))));

return AuthorizationUtils.isAuthorized(
context.getAuthorizer(),
context.getActorUrn(),
entityUrn.getEntityType(),
entityUrn.toString(),
orPrivilegeGroups);
}

private DataContractUtils() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.linkedin.datahub.graphql.resolvers.datacontract;

import com.google.common.collect.ImmutableList;
import com.linkedin.common.EntityRelationship;
import com.linkedin.common.EntityRelationships;
import com.linkedin.common.urn.Urn;
import com.linkedin.datahub.graphql.QueryContext;
import com.linkedin.datahub.graphql.generated.DataContract;
import com.linkedin.datahub.graphql.generated.Entity;
import com.linkedin.datahub.graphql.types.datacontract.DataContractMapper;
import com.linkedin.entity.EntityResponse;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.graph.GraphClient;
import com.linkedin.metadata.query.filter.RelationshipDirection;
import com.linkedin.r2.RemoteInvocationException;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class EntityDataContractResolver implements DataFetcher<CompletableFuture<DataContract>> {
static final String CONTRACT_FOR_RELATIONSHIP = "ContractFor";

private final EntityClient _entityClient;
private final GraphClient _graphClient;

public EntityDataContractResolver(
final EntityClient entityClient, final GraphClient graphClient) {
_entityClient = Objects.requireNonNull(entityClient, "entityClient must not be null");
_graphClient = Objects.requireNonNull(graphClient, "graphClient must not be null");
}

@Override
public CompletableFuture<DataContract> get(DataFetchingEnvironment environment) {
return CompletableFuture.supplyAsync(
() -> {
final QueryContext context = environment.getContext();
final String entityUrn = ((Entity) environment.getSource()).getUrn();

try {
// Step 1: Fetch the contract associated with the dataset.
final EntityRelationships relationships =
_graphClient.getRelatedEntities(
entityUrn,
ImmutableList.of(CONTRACT_FOR_RELATIONSHIP),
RelationshipDirection.INCOMING,
0,
1,
context.getActorUrn());

// If we found multiple contracts for same entity, we have an invalid system state. Log
// a warning.
if (relationships.getTotal() > 1) {
// Someone created 2 contracts for the same entity. Currently we do not handle this in
// the UI.
log.warn(
String.format(
"Unexpectedly found multiple contracts (%s) for entity with urn %s! This may lead to inconsistent behavior.",
relationships.getRelationships(), entityUrn));
}

final List<Urn> contractUrns =
relationships.getRelationships().stream()
.map(EntityRelationship::getEntity)
.collect(Collectors.toList());

if (contractUrns.size() >= 1) {
final Urn contractUrn = contractUrns.get(0);

// Step 2: Hydrate the contract entities based on the urns from step 1
final EntityResponse entityResponse =
_entityClient.getV2(
context.getOperationContext(),
Constants.DATA_CONTRACT_ENTITY_NAME,
contractUrn,
null);

if (entityResponse != null) {
// Step 4: Package and return result
return DataContractMapper.mapContract(entityResponse);
}
}
// No contract found
return null;
} catch (URISyntaxException | RemoteInvocationException e) {
throw new RuntimeException("Failed to retrieve Assertion Run Events from GMS", e);
}
});
}
}
Loading
Loading