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(bootstrap): add bootstrap step to clear out unknown aspect rows …
…from the database (datahub-project#5148)
- Loading branch information
1 parent
0cd65f1
commit 856a47f
Showing
10 changed files
with
215 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
15 changes: 15 additions & 0 deletions
15
...upgrade/src/main/java/com/linkedin/datahub/upgrade/config/RemoveUnknownAspectsConfig.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,15 @@ | ||
package com.linkedin.datahub.upgrade.config; | ||
|
||
import com.linkedin.datahub.upgrade.removeunknownaspects.RemoveUnknownAspects; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
|
||
@Configuration | ||
public class RemoveUnknownAspectsConfig { | ||
@Bean(name = "removeUnknownAspects") | ||
public RemoveUnknownAspects removeUnknownAspects(EntityService entityService) { | ||
return new RemoveUnknownAspects(entityService); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...main/java/com/linkedin/datahub/upgrade/removeunknownaspects/RemoveClientIdAspectStep.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,41 @@ | ||
package com.linkedin.datahub.upgrade.removeunknownaspects; | ||
|
||
import com.linkedin.datahub.upgrade.UpgradeContext; | ||
import com.linkedin.datahub.upgrade.UpgradeStep; | ||
import com.linkedin.datahub.upgrade.UpgradeStepResult; | ||
import com.linkedin.datahub.upgrade.impl.DefaultUpgradeStepResult; | ||
import com.linkedin.gms.factory.telemetry.TelemetryUtils; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import java.util.HashMap; | ||
import java.util.function.Function; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class RemoveClientIdAspectStep implements UpgradeStep { | ||
|
||
private static final String INVALID_CLIENT_ID_ASPECT = "clientId"; | ||
|
||
private final EntityService _entityService; | ||
|
||
@Override | ||
public String id() { | ||
return this.getClass().getSimpleName(); | ||
} | ||
|
||
@Override | ||
public boolean skip(UpgradeContext context) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Function<UpgradeContext, UpgradeStepResult> executable() { | ||
return upgradeContext -> { | ||
_entityService.deleteAspect(TelemetryUtils.CLIENT_ID_URN, INVALID_CLIENT_ID_ASPECT, | ||
new HashMap<>(), true); | ||
return (UpgradeStepResult) new DefaultUpgradeStepResult(id(), UpgradeStepResult.Result.SUCCEEDED); | ||
}; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...src/main/java/com/linkedin/datahub/upgrade/removeunknownaspects/RemoveUnknownAspects.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,40 @@ | ||
package com.linkedin.datahub.upgrade.removeunknownaspects; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.linkedin.datahub.upgrade.Upgrade; | ||
import com.linkedin.datahub.upgrade.UpgradeCleanupStep; | ||
import com.linkedin.datahub.upgrade.UpgradeStep; | ||
import com.linkedin.metadata.entity.EntityService; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
public class RemoveUnknownAspects implements Upgrade { | ||
|
||
private final List<UpgradeStep> _steps; | ||
|
||
public RemoveUnknownAspects(final EntityService entityService) { | ||
_steps = buildSteps(entityService); | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return this.getClass().getSimpleName(); | ||
} | ||
|
||
@Override | ||
public List<UpgradeStep> steps() { | ||
return _steps; | ||
} | ||
|
||
private List<UpgradeStep> buildSteps(final EntityService entityService) { | ||
final List<UpgradeStep> steps = new ArrayList<>(); | ||
steps.add(new RemoveClientIdAspectStep(entityService)); | ||
return steps; | ||
} | ||
|
||
@Override | ||
public List<UpgradeCleanupStep> cleanupSteps() { | ||
return ImmutableList.of(); | ||
} | ||
} |
14 changes: 13 additions & 1 deletion
14
metadata-io/src/main/java/com/linkedin/metadata/entity/EntityAspectIdentifier.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 |
---|---|---|
@@ -1,16 +1,28 @@ | ||
package com.linkedin.metadata.entity; | ||
|
||
import com.linkedin.metadata.entity.cassandra.CassandraAspect; | ||
import com.linkedin.metadata.entity.ebean.EbeanAspectV2; | ||
import javax.annotation.Nonnull; | ||
import lombok.Value; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* This class holds values required to construct a unique key to identify an entity aspect record in a database. | ||
* Its existence started mainly for compatibility with {@link com.linkedin.metadata.entity.ebean.EbeanAspectV2.PrimaryKey} | ||
*/ | ||
@Value | ||
@Slf4j | ||
public class EntityAspectIdentifier { | ||
@Nonnull String urn; | ||
@Nonnull String aspect; | ||
long version; | ||
|
||
public static EntityAspectIdentifier fromEbean(EbeanAspectV2 ebeanAspectV2) { | ||
return new EntityAspectIdentifier(ebeanAspectV2.getUrn(), ebeanAspectV2.getAspect(), ebeanAspectV2.getVersion()); | ||
} | ||
|
||
public static EntityAspectIdentifier fromCassandra(CassandraAspect cassandraAspect) { | ||
return new EntityAspectIdentifier(cassandraAspect.getUrn(), cassandraAspect.getAspect(), cassandraAspect.getVersion()); | ||
} | ||
} |
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
Oops, something went wrong.