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

fix(upgrade): Improving NoCodeUpgrade logic to account for Bootstrap logic #3301

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions datahub-frontend/app/auth/sso/oidc/OidcCallbackLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.linkedin.identity.CorpUserEditableInfo;
import com.linkedin.identity.CorpUserInfo;
import com.linkedin.identity.GroupMembership;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.aspect.CorpGroupAspect;
import com.linkedin.metadata.aspect.CorpGroupAspectArray;
import com.linkedin.metadata.aspect.CorpUserAspect;
Expand Down Expand Up @@ -64,7 +65,7 @@
@Slf4j
public class OidcCallbackLogic extends DefaultCallbackLogic<Result, PlayWebContext> {

private static final String SYSTEM_PRINCIPAL = "urn:li:corpuser:system";
private static final String SYSTEM_ACTOR = Constants.SYSTEM_ACTOR;
private final EntityClient _entityClient = GmsClientFactory.getEntitiesClient();
private final SsoManager _ssoManager;

Expand Down Expand Up @@ -271,7 +272,7 @@ private void tryProvisionUser(CorpUserSnapshot corpUserSnapshot) {

// 1. Check if this user already exists.
try {
final Entity corpUser = _entityClient.get(corpUserSnapshot.getUrn(), SYSTEM_PRINCIPAL);
final Entity corpUser = _entityClient.get(corpUserSnapshot.getUrn(), SYSTEM_ACTOR);

log.debug(String.format("Fetched GMS user with urn %s",corpUserSnapshot.getUrn()));

Expand All @@ -281,7 +282,7 @@ private void tryProvisionUser(CorpUserSnapshot corpUserSnapshot) {
// 2. The user does not exist. Provision them.
final Entity newEntity = new Entity();
newEntity.setValue(Snapshot.create(corpUserSnapshot));
_entityClient.update(newEntity, SYSTEM_PRINCIPAL);
_entityClient.update(newEntity, SYSTEM_ACTOR);

log.debug(String.format("Successfully provisioned user %s", corpUserSnapshot.getUrn()));
}
Expand All @@ -302,7 +303,7 @@ private void tryProvisionGroups(List<CorpGroupSnapshot> corpGroups) {
// 1. Check if this user already exists.
try {
final Set<Urn> urnsToFetch = corpGroups.stream().map(CorpGroupSnapshot::getUrn).collect(Collectors.toSet());
final Map<Urn, Entity> existingGroups = _entityClient.batchGet(urnsToFetch, SYSTEM_PRINCIPAL);
final Map<Urn, Entity> existingGroups = _entityClient.batchGet(urnsToFetch, SYSTEM_ACTOR);

log.debug(String.format("Fetched GMS groups with urns %s", existingGroups.keySet()));

Expand Down Expand Up @@ -335,7 +336,7 @@ private void tryProvisionGroups(List<CorpGroupSnapshot> corpGroups) {
// Now batch create all entities identified to create.
_entityClient.batchUpdate(groupsToCreate.stream().map(groupSnapshot ->
new Entity().setValue(Snapshot.create(groupSnapshot))
).collect(Collectors.toSet()), SYSTEM_PRINCIPAL);
).collect(Collectors.toSet()), SYSTEM_ACTOR);

log.debug(String.format("Successfully provisioned groups with urns %s", groupsToCreateUrns));

Expand All @@ -349,7 +350,7 @@ private void tryProvisionGroups(List<CorpGroupSnapshot> corpGroups) {
private void verifyPreProvisionedUser(CorpuserUrn urn) {
// Validate that the user exists in the system (there is more than just a key aspect for them, as of today).
try {
final Entity corpUser = _entityClient.get(urn, SYSTEM_PRINCIPAL);
final Entity corpUser = _entityClient.get(urn, SYSTEM_ACTOR);

log.debug(String.format("Fetched GMS user with urn %s", urn));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.linkedin.datahub.upgrade.UpgradeContext;
import com.linkedin.datahub.upgrade.UpgradeStep;
import com.linkedin.datahub.upgrade.UpgradeStepResult;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.utils.PegasusUtils;
import com.linkedin.metadata.dao.utils.RecordUtils;
import com.linkedin.metadata.entity.EntityService;
Expand Down Expand Up @@ -149,7 +150,7 @@ public Function<UpgradeContext, UpgradeStepResult> executable() {
browsePaths = BrowsePathUtils.buildBrowsePath(urn);

final AuditStamp browsePathsStamp = new AuditStamp();
browsePathsStamp.setActor(Urn.createFromString("urn:li:principal:system"));
browsePathsStamp.setActor(Urn.createFromString(Constants.SYSTEM_ACTOR));
browsePathsStamp.setTime(System.currentTimeMillis());

_entityService.ingestAspect(urn, BROWSE_PATHS_ASPECT_NAME, browsePaths, browsePathsStamp);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ private List<UpgradeStep> buildUpgradeSteps(
steps.add(new GMSQualificationStep());
steps.add(new UpgradeQualificationStep(server));
steps.add(new CreateAspectTableStep(server));
steps.add(new IngestDataPlatformsStep(entityService));
steps.add(new DataMigrationStep(server, entityService, entityRegistry));
steps.add(new GMSEnableWriteModeStep(entityClient));
return steps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private boolean isQualified(EbeanServer server, UpgradeContext context) {
boolean v2TableExists = AspectStorageValidationUtil.checkV2TableExists(server);
if (v2TableExists) {
context.report().addLine("-- V2 table exists");
long v2TableRowCount = AspectStorageValidationUtil.getV2RowCount(server);
long v2TableRowCount = AspectStorageValidationUtil.getV2NonSystemRowCount(server);
if (v2TableRowCount == 0) {
context.report().addLine("-- V2 table is empty");
return true;
Expand Down
4 changes: 2 additions & 2 deletions docker/mariadb/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ insert into metadata_aspect_v2 (urn, aspect, version, metadata, createdon, creat
0,
'{"displayName":"Data Hub","active":true,"fullName":"Data Hub","email":"datahub@linkedin.com"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
), (
'urn:li:corpuser:datahub',
'corpUserEditableInfo',
0,
'{"skills":[],"teams":[],"pictureLink":"https://raw.githubusercontent.com/linkedin/datahub/master/datahub-web-react/src/images/default_avatar.png"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
);
4 changes: 2 additions & 2 deletions docker/mysql-setup/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ INSERT INTO temp_metadata_aspect_v2 (urn, aspect, version, metadata, createdon,
0,
'{"displayName":"Data Hub","active":true,"fullName":"Data Hub","email":"datahub@linkedin.com"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
), (
'urn:li:corpuser:datahub',
'corpUserEditableInfo',
0,
'{"skills":[],"teams":[],"pictureLink":"https://raw.githubusercontent.com/linkedin/datahub/master/datahub-web-react/src/images/default_avatar.png"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
);
-- only add default records if metadata_aspect is empty
INSERT INTO metadata_aspect_v2
Expand Down
4 changes: 2 additions & 2 deletions docker/mysql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ INSERT INTO metadata_aspect_v2 (urn, aspect, version, metadata, createdon, creat
0,
'{"displayName":"Data Hub","active":true,"fullName":"Data Hub","email":"datahub@linkedin.com"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
), (
'urn:li:corpuser:datahub',
'corpUserEditableInfo',
0,
'{"skills":[],"teams":[],"pictureLink":"https://raw.githubusercontent.com/linkedin/datahub/master/datahub-web-react/src/images/default_avatar.png"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
);

-- create metadata index table
Expand Down
4 changes: 2 additions & 2 deletions docker/postgres-setup/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ INSERT INTO temp_metadata_aspect_v2 (urn, aspect, version, metadata, createdon,
0,
'{"displayName":"Data Hub","active":true,"fullName":"Data Hub","email":"datahub@linkedin.com"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
), (
'urn:li:corpuser:datahub',
'corpUserEditableInfo',
0,
'{"skills":[],"teams":[],"pictureLink":"https://raw.githubusercontent.com/linkedin/datahub/master/datahub-web-react/src/images/default_avatar.png"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
);
-- only add default records if metadata_aspect is empty
INSERT INTO metadata_aspect_v2
Expand Down
4 changes: 2 additions & 2 deletions docker/postgres/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ insert into metadata_aspect_v2 (urn, aspect, version, metadata, createdon, creat
0,
'{"displayName":"Data Hub","active":true,"fullName":"Data Hub","email":"datahub@linkedin.com"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
), (
'urn:li:corpuser:datahub',
'corpUserEditableInfo',
0,
'{"skills":[],"teams":[],"pictureLink":"https://raw.githubusercontent.com/linkedin/datahub/master/datahub-web-react/src/images/default_avatar.png"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
);
4 changes: 2 additions & 2 deletions docker/quickstart/mysql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ INSERT INTO metadata_aspect_v2 (urn, aspect, version, metadata, createdon, creat
0,
'{"displayName":"Data Hub","active":true,"fullName":"Data Hub","email":"datahub@linkedin.com"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
), (
'urn:li:corpuser:datahub',
'corpUserEditableInfo',
0,
'{"skills":[],"teams":[],"pictureLink":"https://raw.githubusercontent.com/linkedin/datahub/master/datahub-web-react/src/images/default_avatar.png"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
);

-- create metadata index table
Expand Down
4 changes: 2 additions & 2 deletions metadata-ingestion/tests/integration/mysql/setup/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ insert into metadata_aspect (urn, aspect, version, metadata, createdon, createdb
0,
'{"displayName":"Data Hub","active":true,"fullName":"Data Hub","email":"datahub@linkedin.com"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
), (
'urn:li:corpuser:datahub',
'com.linkedin.identity.CorpUserEditableInfo',
0,
'{"skills":[],"teams":[],"pictureLink":"https://raw.githubusercontent.com/linkedin/datahub/master/datahub-web-react/src/images/default_avatar.png"}',
now(),
'urn:li:principal:datahub'
'urn:li:corpuser:__datahub_system'
);

-- create metadata index table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.linkedin.metadata.entity;

import com.linkedin.metadata.Constants;
import com.linkedin.metadata.entity.ebean.EbeanAspectV1;
import com.linkedin.metadata.entity.ebean.EbeanAspectV2;
import io.ebean.EbeanServer;
import io.ebean.SqlQuery;
import io.ebean.SqlRow;
import java.util.List;

import static io.ebean.Expr.*;


public class AspectStorageValidationUtil {

Expand All @@ -18,8 +21,11 @@ public static long getV1RowCount(EbeanServer server) {
return server.find(EbeanAspectV1.class).findCount();
}

public static long getV2RowCount(EbeanServer server) {
return server.find(EbeanAspectV2.class).findCount();
/**
* Get the number of rows created not by the DataHub system actor (urn:li:corpuser:__datahub_system)
*/
public static long getV2NonSystemRowCount(EbeanServer server) {
return server.find(EbeanAspectV2.class).where(ne("createdby", Constants.SYSTEM_ACTOR)).findCount();
}

public static boolean checkV2TableExists(EbeanServer server) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void execute() throws IOException, URISyntaxException {
RecordUtils.toRecordTemplate(DataPlatformInfo.class, dataPlatform.get("aspect").toString());

final AuditStamp aspectAuditStamp =
new AuditStamp().setActor(Urn.createFromString(Constants.UNKNOWN_ACTOR)).setTime(System.currentTimeMillis());
new AuditStamp().setActor(Urn.createFromString(Constants.SYSTEM_ACTOR)).setTime(System.currentTimeMillis());

_entityService.ingestAspect(urn, PLATFORM_ASPECT_NAME, info, aspectAuditStamp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.linkedin.common.AuditStamp;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.boot.BootstrapStep;
import com.linkedin.events.metadata.ChangeType;
import com.linkedin.metadata.dao.utils.RecordUtils;
Expand Down Expand Up @@ -92,7 +93,7 @@ private void ingestPolicy(final Urn urn, final DataHubPolicyInfo info) throws UR
keyAspectProposal.setEntityUrn(urn);

_entityService.ingestProposal(keyAspectProposal,
new AuditStamp().setActor(Urn.createFromString("urn:li:corpuser:system")).setTime(System.currentTimeMillis()));
new AuditStamp().setActor(Urn.createFromString(Constants.SYSTEM_ACTOR)).setTime(System.currentTimeMillis()));

final MetadataChangeProposal proposal = new MetadataChangeProposal();
proposal.setEntityUrn(urn);
Expand All @@ -102,7 +103,7 @@ private void ingestPolicy(final Urn urn, final DataHubPolicyInfo info) throws UR
proposal.setChangeType(ChangeType.UPSERT);

_entityService.ingestProposal(proposal,
new AuditStamp().setActor(Urn.createFromString("urn:li:corpuser:system")).setTime(System.currentTimeMillis()));
new AuditStamp().setActor(Urn.createFromString(Constants.SYSTEM_ACTOR)).setTime(System.currentTimeMillis()));
}

private boolean hasDefaultPolicies() throws URISyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class Constants {
public static final String ACTOR_HEADER_NAME = "X-DataHub-Actor";
public static final String DATAHUB_ACTOR = "urn:li:corpuser:datahub"; // Super user.
public static final String SYSTEM_ACTOR = "urn:li:principal:datahub"; // DataHub internal service principal.
public static final String SYSTEM_ACTOR = "urn:li:corpuser:__datahub_system"; // DataHub internal service principal.
public static final String UNKNOWN_ACTOR = "urn:li:corpuser:UNKNOWN"; // Unknown principal.
public static final Long ASPECT_LATEST_VERSION = 0L;

Expand Down