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.
feat(propagation): Add models for Action feature settings (datahub-pr…
- Loading branch information
Showing
15 changed files
with
954 additions
and
171 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
57 changes: 57 additions & 0 deletions
57
...din/datahub/graphql/resolvers/settings/docPropagation/DocPropagationSettingsResolver.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,57 @@ | ||
package com.linkedin.datahub.graphql.resolvers.settings.docPropagation; | ||
|
||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.concurrency.GraphQLConcurrencyUtils; | ||
import com.linkedin.datahub.graphql.generated.DocPropagationSettings; | ||
import com.linkedin.metadata.service.SettingsService; | ||
import com.linkedin.settings.global.GlobalSettingsInfo; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
import javax.annotation.Nonnull; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** Retrieves the Global Settings related to the Actions feature. */ | ||
@Slf4j | ||
public class DocPropagationSettingsResolver | ||
implements DataFetcher<CompletableFuture<DocPropagationSettings>> { | ||
|
||
private final SettingsService _settingsService; | ||
|
||
public DocPropagationSettingsResolver(final SettingsService settingsService) { | ||
_settingsService = Objects.requireNonNull(settingsService, "settingsService must not be null"); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<DocPropagationSettings> get(final DataFetchingEnvironment environment) | ||
throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
return GraphQLConcurrencyUtils.supplyAsync( | ||
() -> { | ||
try { | ||
final GlobalSettingsInfo globalSettings = | ||
_settingsService.getGlobalSettings(context.getOperationContext()); | ||
final DocPropagationSettings defaultSettings = new DocPropagationSettings(); | ||
defaultSettings.setDocColumnPropagation(true); | ||
return globalSettings != null && globalSettings.hasDocPropagation() | ||
? mapDocPropagationSettings(globalSettings.getDocPropagation()) | ||
: defaultSettings; | ||
} catch (Exception e) { | ||
throw new RuntimeException("Failed to retrieve Action Settings", e); | ||
} | ||
}, | ||
this.getClass().getSimpleName(), | ||
"get"); | ||
} | ||
|
||
private static DocPropagationSettings mapDocPropagationSettings( | ||
@Nonnull final com.linkedin.settings.global.DocPropagationFeatureSettings settings) { | ||
final DocPropagationSettings result = new DocPropagationSettings(); | ||
|
||
// Map docColumnPropagation settings field | ||
result.setDocColumnPropagation(settings.isColumnPropagationEnabled()); | ||
|
||
return result; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...tahub/graphql/resolvers/settings/docPropagation/UpdateDocPropagationSettingsResolver.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,77 @@ | ||
package com.linkedin.datahub.graphql.resolvers.settings.docPropagation; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.authorization.AuthorizationUtils; | ||
import com.linkedin.datahub.graphql.concurrency.GraphQLConcurrencyUtils; | ||
import com.linkedin.datahub.graphql.exception.AuthorizationException; | ||
import com.linkedin.datahub.graphql.generated.UpdateDocPropagationSettingsInput; | ||
import com.linkedin.metadata.service.SettingsService; | ||
import com.linkedin.settings.global.DocPropagationFeatureSettings; | ||
import com.linkedin.settings.global.GlobalSettingsInfo; | ||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
import javax.annotation.Nonnull; | ||
|
||
/** Resolver responsible for updating the actions settings. */ | ||
public class UpdateDocPropagationSettingsResolver | ||
implements DataFetcher<CompletableFuture<Boolean>> { | ||
|
||
private final SettingsService _settingsService; | ||
|
||
public UpdateDocPropagationSettingsResolver(@Nonnull final SettingsService settingsService) { | ||
_settingsService = Objects.requireNonNull(settingsService, "settingsService must not be null"); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Boolean> get(final DataFetchingEnvironment environment) | ||
throws Exception { | ||
final QueryContext context = environment.getContext(); | ||
final UpdateDocPropagationSettingsInput input = | ||
bindArgument(environment.getArgument("input"), UpdateDocPropagationSettingsInput.class); | ||
|
||
return GraphQLConcurrencyUtils.supplyAsync( | ||
() -> { | ||
if (AuthorizationUtils.canManageFeatures(context)) { | ||
try { | ||
// First, fetch the existing global settings. This does a R-M-F. | ||
final GlobalSettingsInfo maybeGlobalSettings = | ||
_settingsService.getGlobalSettings(context.getOperationContext()); | ||
|
||
final GlobalSettingsInfo newGlobalSettings = | ||
maybeGlobalSettings != null ? maybeGlobalSettings : new GlobalSettingsInfo(); | ||
|
||
final DocPropagationFeatureSettings newDocPropagationSettings = | ||
newGlobalSettings.hasDocPropagation() | ||
? newGlobalSettings.getDocPropagation() | ||
: new DocPropagationFeatureSettings().setEnabled(true); | ||
|
||
// Next, patch the actions settings. | ||
updateDocPropagationSettings(newDocPropagationSettings, input); | ||
newGlobalSettings.setDocPropagation(newDocPropagationSettings); | ||
|
||
// Finally, write back to GMS. | ||
_settingsService.updateGlobalSettings( | ||
context.getOperationContext(), newGlobalSettings); | ||
return true; | ||
} catch (Exception e) { | ||
throw new RuntimeException( | ||
String.format("Failed to update action settings! %s", input), e); | ||
} | ||
} | ||
throw new AuthorizationException( | ||
"Unauthorized to perform this action. Please contact your DataHub administrator."); | ||
}, | ||
this.getClass().getSimpleName(), | ||
"get"); | ||
} | ||
|
||
private static void updateDocPropagationSettings( | ||
@Nonnull final com.linkedin.settings.global.DocPropagationFeatureSettings settings, | ||
@Nonnull final UpdateDocPropagationSettingsInput input) { | ||
settings.setColumnPropagationEnabled(input.getDocColumnPropagation()); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
...ta-models/src/main/pegasus/com/linkedin/settings/global/DocPropagationFeatureSettings.pdl
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,8 @@ | ||
namespace com.linkedin.settings.global | ||
|
||
|
||
record DocPropagationFeatureSettings includes FeatureSettings { | ||
|
||
columnPropagationEnabled: boolean = true | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
metadata-models/src/main/pegasus/com/linkedin/settings/global/FeatureSettings.pdl
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 @@ | ||
namespace com.linkedin.settings.global | ||
|
||
/** | ||
* A standardized settings template for a feature. | ||
*/ | ||
|
||
record FeatureSettings { | ||
|
||
enabled: boolean | ||
|
||
/** | ||
* The configuration for the feature, in JSON format. | ||
*/ | ||
config: optional string | ||
|
||
/** | ||
* The version of the configuration schema that has been used to serialize | ||
the config. | ||
* If not provided, the version is assumed to be the latest version. | ||
*/ | ||
configVersion: optional string | ||
} |
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.