forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'datahub-project:master' into master
- Loading branch information
Showing
87 changed files
with
8,870 additions
and
167 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
88 changes: 88 additions & 0 deletions
88
...va/com/linkedin/datahub/graphql/resolvers/entity/versioning/LinkAssetVersionResolver.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.entity.versioning; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument; | ||
import static com.linkedin.metadata.Constants.VERSION_SET_ENTITY_NAME; | ||
import static com.linkedin.metadata.authorization.ApiOperation.UPDATE; | ||
|
||
import com.datahub.authorization.AuthUtil; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.concurrency.GraphQLConcurrencyUtils; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.featureflags.FeatureFlags; | ||
import com.linkedin.datahub.graphql.generated.LinkVersionInput; | ||
import com.linkedin.metadata.entity.IngestResult; | ||
import com.linkedin.metadata.entity.versioning.EntityVersioningService; | ||
import com.linkedin.metadata.entity.versioning.VersionPropertiesInput; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import io.datahubproject.metadata.context.OperationContext; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
/** | ||
* Currently only supports linking the latest version, but may be modified later to support inserts | ||
*/ | ||
public class LinkAssetVersionResolver implements DataFetcher<CompletableFuture<String>> { | ||
|
||
private final EntityVersioningService entityVersioningService; | ||
private final FeatureFlags featureFlags; | ||
|
||
public LinkAssetVersionResolver( | ||
EntityVersioningService entityVersioningService, FeatureFlags featureFlags) { | ||
this.entityVersioningService = entityVersioningService; | ||
this.featureFlags = featureFlags; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<String> get(DataFetchingEnvironment environment) throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
final LinkVersionInput input = | ||
bindArgument(environment.getArgument("input"), LinkVersionInput.class); | ||
if (!featureFlags.isEntityVersioning()) { | ||
throw new IllegalAccessError( | ||
"Entity Versioning is not configured, please enable before attempting to use this feature."); | ||
} | ||
Urn versionSetUrn = UrnUtils.getUrn(input.getVersionSet()); | ||
if (!VERSION_SET_ENTITY_NAME.equals(versionSetUrn.getEntityType())) { | ||
throw new IllegalArgumentException( | ||
String.format("Version Set urn %s must be of type Version Set.", input.getVersionSet())); | ||
} | ||
Urn entityUrn = UrnUtils.getUrn(input.getLinkedEntity()); | ||
OperationContext opContext = context.getOperationContext(); | ||
if (!AuthUtil.isAPIAuthorizedEntityUrns( | ||
opContext, UPDATE, ImmutableSet.of(versionSetUrn, entityUrn))) { | ||
throw new AuthorizationException( | ||
String.format( | ||
"%s is unauthorized to %s entities %s and %s", | ||
opContext.getAuthentication().getActor().toUrnStr(), | ||
UPDATE, | ||
input.getVersionSet(), | ||
input.getLinkedEntity())); | ||
} | ||
VersionPropertiesInput versionPropertiesInput = | ||
new VersionPropertiesInput( | ||
input.getComment(), | ||
input.getVersion(), | ||
input.getSourceTimestamp(), | ||
input.getSourceCreator()); | ||
return GraphQLConcurrencyUtils.supplyAsync( | ||
() -> { | ||
List<IngestResult> linkResults = | ||
entityVersioningService.linkLatestVersion( | ||
opContext, versionSetUrn, entityUrn, versionPropertiesInput); | ||
|
||
return linkResults.stream() | ||
.filter( | ||
ingestResult -> input.getLinkedEntity().equals(ingestResult.getUrn().toString())) | ||
.map(ingestResult -> ingestResult.getUrn().toString()) | ||
.findAny() | ||
.orElse(StringUtils.EMPTY); | ||
}, | ||
this.getClass().getSimpleName(), | ||
"get"); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
.../com/linkedin/datahub/graphql/resolvers/entity/versioning/UnlinkAssetVersionResolver.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,67 @@ | ||
package com.linkedin.datahub.graphql.resolvers.entity.versioning; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.bindArgument; | ||
import static com.linkedin.metadata.Constants.VERSION_SET_ENTITY_NAME; | ||
import static com.linkedin.metadata.authorization.ApiOperation.UPDATE; | ||
|
||
import com.datahub.authorization.AuthUtil; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.common.urn.UrnUtils; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.concurrency.GraphQLConcurrencyUtils; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.featureflags.FeatureFlags; | ||
import com.linkedin.datahub.graphql.generated.UnlinkVersionInput; | ||
import com.linkedin.metadata.entity.versioning.EntityVersioningService; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import io.datahubproject.metadata.context.OperationContext; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class UnlinkAssetVersionResolver implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final EntityVersioningService entityVersioningService; | ||
private final FeatureFlags featureFlags; | ||
|
||
public UnlinkAssetVersionResolver( | ||
EntityVersioningService entityVersioningService, FeatureFlags featureFlags) { | ||
this.entityVersioningService = entityVersioningService; | ||
this.featureFlags = featureFlags; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throws Exception { | ||
if (!featureFlags.isEntityVersioning()) { | ||
throw new IllegalAccessError( | ||
"Entity Versioning is not configured, please enable before attempting to use this feature."); | ||
} | ||
final QueryContext context = environment.getContext(); | ||
final UnlinkVersionInput input = | ||
bindArgument(environment.getArgument("input"), UnlinkVersionInput.class); | ||
Urn versionSetUrn = UrnUtils.getUrn(input.getVersionSet()); | ||
if (!VERSION_SET_ENTITY_NAME.equals(versionSetUrn.getEntityType())) { | ||
throw new IllegalArgumentException( | ||
String.format("Version Set urn %s must be of type Version Set.", input.getVersionSet())); | ||
} | ||
Urn entityUrn = UrnUtils.getUrn(input.getUnlinkedEntity()); | ||
OperationContext opContext = context.getOperationContext(); | ||
if (!AuthUtil.isAPIAuthorizedEntityUrns( | ||
opContext, UPDATE, ImmutableSet.of(versionSetUrn, entityUrn))) { | ||
throw new AuthorizationException( | ||
String.format( | ||
"%s is unauthorized to %s entities %s and %s", | ||
opContext.getAuthentication().getActor(), | ||
UPDATE, | ||
input.getVersionSet(), | ||
input.getUnlinkedEntity())); | ||
} | ||
return GraphQLConcurrencyUtils.supplyAsync( | ||
() -> { | ||
entityVersioningService.unlinkVersion(opContext, versionSetUrn, entityUrn); | ||
return true; | ||
}, | ||
this.getClass().getSimpleName(), | ||
"get"); | ||
} | ||
} |
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.