forked from apache/atlas
-
Notifications
You must be signed in to change notification settings - Fork 9
MLH-1336 Sets tags FF true for all new tenants by default #5451
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
repository/src/main/java/org/apache/atlas/services/TagsV2AutoEnabler.java
This file contains hidden or 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,97 @@ | ||
| package org.apache.atlas.services; | ||
|
|
||
| import org.apache.atlas.exception.AtlasBaseException; | ||
| import org.apache.atlas.repository.Constants; | ||
| import org.apache.atlas.repository.graphdb.AtlasGraph; | ||
| import org.apache.atlas.repository.graphdb.AtlasGraphQuery; | ||
| import org.apache.atlas.repository.graphdb.AtlasVertex; | ||
| import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; | ||
| import org.apache.atlas.service.FeatureFlag; | ||
| import org.apache.atlas.service.FeatureFlagStore; | ||
| import org.apache.atlas.store.AtlasTypeDefStore; | ||
| import org.apache.atlas.typesystem.types.DataTypes; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
| import javax.inject.Inject; | ||
| import java.util.Iterator; | ||
|
|
||
|
|
||
| /** | ||
| * Automatically enables Tag V2 for new Atlas instances | ||
| * where no classification types are present. This ensures new customer tenants get the | ||
| * latest tag propagation version by default. | ||
| */ | ||
| @Component | ||
| public class TagsV2AutoEnabler { | ||
| private static final Logger LOG = LoggerFactory.getLogger(TagsV2AutoEnabler.class); | ||
|
|
||
| private static final String CLASSIFICATION_TYPE = "classification"; | ||
| private static final String ENABLE_JANUS_OPTIMISATION_KEY = FeatureFlag.ENABLE_JANUS_OPTIMISATION.getKey(); | ||
|
|
||
| // Property keys for type system vertices | ||
| private static final String VERTEX_TYPE_PROPERTY_KEY = Constants.VERTEX_TYPE_PROPERTY_KEY; | ||
| private static final String TYPE_CATEGORY_PROPERTY_KEY = Constants.TYPE_CATEGORY_PROPERTY_KEY; | ||
| private static final String VERTEX_TYPE = AtlasGraphUtilsV2.VERTEX_TYPE; // "typeSystem" | ||
|
|
||
| private final AtlasTypeDefStore typeDefStore; | ||
| private final AtlasGraph graph; | ||
|
|
||
| @Inject | ||
| public TagsV2AutoEnabler(AtlasTypeDefStore typeDefStore, AtlasGraph graph) { | ||
| this.typeDefStore = typeDefStore; | ||
| this.graph = graph; | ||
| } | ||
|
|
||
| @PostConstruct | ||
| public void checkAndEnableJanusOptimisation() throws AtlasBaseException { | ||
| try { | ||
| LOG.info("Starting auto-enable check for Janus optimization..."); | ||
|
|
||
| boolean isTagV2Enabled = FeatureFlagStore.isTagV2Enabled(); | ||
| if (isTagV2Enabled) { | ||
| LOG.info("Tags v2 optimization is already enabled, skipping auto-enable check"); | ||
| return; | ||
| } | ||
|
|
||
| // Check if there are any classification types present | ||
| boolean hasClassificationTypes = hasClassificationTypes(); | ||
|
|
||
| if (!hasClassificationTypes) { | ||
| LOG.info("No classification types found - enabling Tags V2 for new tenant"); | ||
| FeatureFlagStore.setFlag(ENABLE_JANUS_OPTIMISATION_KEY, "true"); | ||
| LOG.info("Successfully enabled Tags V2 feature flag"); | ||
| } else { | ||
| LOG.info("Classification types found - keeping existing configuration (Tags v2 disabled)"); | ||
| } | ||
|
|
||
| } catch (Exception e) { | ||
| LOG.error("Error during auto-enable check for Tags v2 optimization", e); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When an exception occurs, do we abort the start? We shouldn't switch to v1 in case of exception
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the exception is thrown. We don't switch to v1. |
||
| throw e; | ||
| } | ||
suraj5077 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Optimized method to check if any classification types exist | ||
| * Uses direct graph query instead of loading all typedefs | ||
| * @return true if classification types exist, false otherwise | ||
| */ | ||
| private boolean hasClassificationTypes() throws AtlasBaseException { | ||
| try { | ||
| // Query for any vertex that is a type system vertex with TRAIT category | ||
| AtlasGraphQuery query = graph.query().has(VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE) | ||
| .has(TYPE_CATEGORY_PROPERTY_KEY, DataTypes.TypeCategory.TRAIT); | ||
|
|
||
| Iterator<AtlasVertex> results = query.vertices().iterator(); | ||
| boolean hasClassifications = results.hasNext(); | ||
|
|
||
| LOG.info("Found classification types: {}", hasClassifications); | ||
| return hasClassifications; | ||
| } catch (Exception e) { | ||
| LOG.error("Error checking for classification types", e); | ||
| throw new AtlasBaseException("Error checking for classification types", e); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.