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

feat(ui) Adding support for deleting Tags and Domains via the UI #5280

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ private String getUrnField(DataFetchingEnvironment env) {
private void configureMutationResolvers(final RuntimeWiring.Builder builder) {
builder.type("Mutation", typeWiring -> typeWiring
.dataFetcher("updateDataset", new MutableTypeResolver<>(datasetType))
.dataFetcher("createTag", new CreateTagResolver(entityService))
.dataFetcher("createTag", new CreateTagResolver(this.entityClient))
.dataFetcher("updateTag", new MutableTypeResolver<>(tagType))
.dataFetcher("setTagColor", new SetTagColorResolver(entityClient, entityService))
.dataFetcher("deleteTag", new DeleteTagResolver(entityClient))
Expand Down Expand Up @@ -707,7 +707,7 @@ private void configureMutationResolvers(final RuntimeWiring.Builder builder) {
.dataFetcher("removeUser", new RemoveUserResolver(this.entityClient))
.dataFetcher("removeGroup", new RemoveGroupResolver(this.entityClient))
.dataFetcher("updateUserStatus", new UpdateUserStatusResolver(this.entityClient))
.dataFetcher("createDomain", new CreateDomainResolver(this.entityService))
.dataFetcher("createDomain", new CreateDomainResolver(this.entityClient))
.dataFetcher("deleteDomain", new DeleteDomainResolver(entityClient))
.dataFetcher("setDomain", new SetDomainResolver(this.entityClient, this.entityService))
.dataFetcher("updateDeprecation", new UpdateDeprecationResolver(this.entityClient, this.entityService))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.generated.CreateDomainInput;
import com.linkedin.domain.DomainProperties;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.events.metadata.ChangeType;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.entity.EntityService;
import com.linkedin.metadata.key.DomainKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
Expand All @@ -20,7 +20,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import static com.linkedin.datahub.graphql.authorization.AuthorizationUtils.*;
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*;

/**
Expand All @@ -30,7 +29,7 @@
@RequiredArgsConstructor
public class CreateDomainResolver implements DataFetcher<CompletableFuture<String>> {

private final EntityService _entityService;
private final EntityClient _entityClient;

@Override
public CompletableFuture<String> get(DataFetchingEnvironment environment) throws Exception {
Expand All @@ -52,7 +51,7 @@ public CompletableFuture<String> get(DataFetchingEnvironment environment) throws
final String id = input.getId() != null ? input.getId() : UUID.randomUUID().toString();
key.setId(id);

if (_entityService.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.DOMAIN_ENTITY_NAME))) {
if (_entityClient.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.DOMAIN_ENTITY_NAME), context.getAuthentication())) {
throw new IllegalArgumentException("This Domain already exists!");
}

Expand All @@ -64,7 +63,7 @@ public CompletableFuture<String> get(DataFetchingEnvironment environment) throws
proposal.setAspect(GenericRecordUtils.serializeAspect(mapDomainProperties(input)));
proposal.setChangeType(ChangeType.UPSERT);

return _entityService.ingestProposal(proposal, createAuditStamp(context)).getUrn().toString();
return _entityClient.ingestProposal(proposal, context.getAuthentication());
} catch (Exception e) {
log.error("Failed to create Domain with id: {}, name: {}: {}", input.getId(), input.getName(), e.getMessage());
throw new RuntimeException(String.format("Failed to create Domain with id: %s, name: %s", input.getId(), input.getName()), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public CompletableFuture<Boolean> get(final DataFetchingEnvironment environment)
if (AuthorizationUtils.canManageDomains(context) || AuthorizationUtils.canDeleteEntity(urn, context)) {
try {
_entityClient.deleteEntity(urn, context.getAuthentication());
log.info(String.format("I've successfully deleted the entity %s with urn", domainUrn));

// Asynchronously Delete all references to the entity (to return quickly)
CompletableFuture.runAsync(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.linkedin.glossary.GlossaryNodeInfo;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.key.GlossaryNodeKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
import com.linkedin.mxe.MetadataChangeProposal;
import graphql.schema.DataFetcher;
Expand Down Expand Up @@ -44,6 +45,10 @@ public CompletableFuture<String> get(DataFetchingEnvironment environment) throws
final String id = input.getId() != null ? input.getId() : UUID.randomUUID().toString();
key.setName(id);

if (_entityClient.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.GLOSSARY_NODE_ENTITY_NAME), context.getAuthentication())) {
throw new IllegalArgumentException("This Glossary Node already exists!");
}

final MetadataChangeProposal proposal = new MetadataChangeProposal();
proposal.setEntityKeyAspect(GenericRecordUtils.serializeAspect(key));
proposal.setEntityType(Constants.GLOSSARY_NODE_ENTITY_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.linkedin.glossary.GlossaryTermInfo;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.key.GlossaryTermKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
import com.linkedin.mxe.MetadataChangeProposal;
import graphql.schema.DataFetcher;
Expand Down Expand Up @@ -44,6 +45,10 @@ public CompletableFuture<String> get(DataFetchingEnvironment environment) throws
final String id = input.getId() != null ? input.getId() : UUID.randomUUID().toString();
key.setName(id);

if (_entityClient.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.GLOSSARY_TERM_ENTITY_NAME), context.getAuthentication())) {
throw new IllegalArgumentException("This Glossary Term already exists!");
}

final MetadataChangeProposal proposal = new MetadataChangeProposal();
proposal.setEntityKeyAspect(GenericRecordUtils.serializeAspect(key));
proposal.setEntityType(Constants.GLOSSARY_TERM_ENTITY_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.linkedin.identity.CorpGroupInfo;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.key.CorpGroupKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
import com.linkedin.mxe.MetadataChangeProposal;
import graphql.schema.DataFetcher;
Expand Down Expand Up @@ -46,6 +47,10 @@ public CompletableFuture<String> get(final DataFetchingEnvironment environment)
final String id = input.getId() != null ? input.getId() : UUID.randomUUID().toString();
key.setName(id); // 'name' in the key really reflects nothing more than a stable "id".

if (_entityClient.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.CORP_GROUP_ENTITY_NAME), context.getAuthentication())) {
throw new IllegalArgumentException("This Group already exists!");
}

// Create the Group info.
final CorpGroupInfo info = new CorpGroupInfo();
info.setDisplayName(input.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.key.DataHubSecretKey;
import com.linkedin.metadata.secret.SecretService;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
import com.linkedin.mxe.MetadataChangeProposal;
import com.linkedin.secret.DataHubSecretValue;
Expand Down Expand Up @@ -38,34 +39,36 @@ public CreateSecretResolver(
@Override
public CompletableFuture<String> get(final DataFetchingEnvironment environment) throws Exception {
final QueryContext context = environment.getContext();
final CreateSecretInput input = bindArgument(environment.getArgument("input"), CreateSecretInput.class);

return CompletableFuture.supplyAsync(() -> {

if (IngestionAuthUtils.canManageSecrets(context)) {

final CreateSecretInput input = bindArgument(environment.getArgument("input"), CreateSecretInput.class);
try {

final MetadataChangeProposal proposal = new MetadataChangeProposal();
final MetadataChangeProposal proposal = new MetadataChangeProposal();

// Create the Ingestion source key --> use the display name as a unique id to ensure it's not duplicated.
final DataHubSecretKey key = new DataHubSecretKey();
key.setId(input.getName());
proposal.setEntityKeyAspect(GenericRecordUtils.serializeAspect(key));
// Create the Ingestion source key --> use the display name as a unique id to ensure it's not duplicated.
final DataHubSecretKey key = new DataHubSecretKey();
key.setId(input.getName());
proposal.setEntityKeyAspect(GenericRecordUtils.serializeAspect(key));

// Create the secret value.
final DataHubSecretValue value = new DataHubSecretValue();
value.setName(input.getName());
value.setValue(_secretService.encrypt(input.getValue()));
value.setDescription(input.getDescription(), SetMode.IGNORE_NULL);
if (_entityClient.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.SECRETS_ENTITY_NAME), context.getAuthentication())) {
throw new IllegalArgumentException("This Secret already exists!");
}

proposal.setEntityType(Constants.SECRETS_ENTITY_NAME);
proposal.setAspectName(Constants.SECRET_VALUE_ASPECT_NAME);
proposal.setAspect(GenericRecordUtils.serializeAspect(value));
proposal.setChangeType(ChangeType.UPSERT);
// Create the secret value.
final DataHubSecretValue value = new DataHubSecretValue();
value.setName(input.getName());
value.setValue(_secretService.encrypt(input.getValue()));
value.setDescription(input.getDescription(), SetMode.IGNORE_NULL);

System.out.println(String.format("About to ingest %s", proposal));
proposal.setEntityType(Constants.SECRETS_ENTITY_NAME);
proposal.setAspectName(Constants.SECRET_VALUE_ASPECT_NAME);
proposal.setAspect(GenericRecordUtils.serializeAspect(value));
proposal.setChangeType(ChangeType.UPSERT);

try {
return _entityClient.ingestProposal(proposal, context.getAuthentication());
} catch (Exception e) {
throw new RuntimeException(String.format("Failed to create new secret with name %s", input.getName()), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.linkedin.datahub.graphql.authorization.AuthorizationUtils;
import com.linkedin.datahub.graphql.exception.AuthorizationException;
import com.linkedin.datahub.graphql.generated.CreateTagInput;
import com.linkedin.entity.client.EntityClient;
import com.linkedin.events.metadata.ChangeType;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.entity.EntityService;
import com.linkedin.metadata.key.TagKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
Expand All @@ -20,7 +20,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import static com.linkedin.datahub.graphql.authorization.AuthorizationUtils.*;
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*;

/**
Expand All @@ -30,7 +29,7 @@
@RequiredArgsConstructor
public class CreateTagResolver implements DataFetcher<CompletableFuture<String>> {

private final EntityService _entityService;
private final EntityClient _entityClient;

@Override
public CompletableFuture<String> get(DataFetchingEnvironment environment) throws Exception {
Expand All @@ -52,7 +51,7 @@ public CompletableFuture<String> get(DataFetchingEnvironment environment) throws
final String id = input.getId() != null ? input.getId() : UUID.randomUUID().toString();
key.setName(id);

if (_entityService.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.TAG_ENTITY_NAME))) {
if (_entityClient.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.TAG_ENTITY_NAME), context.getAuthentication())) {
throw new IllegalArgumentException("This Tag already exists!");
}

Expand All @@ -63,7 +62,7 @@ public CompletableFuture<String> get(DataFetchingEnvironment environment) throws
proposal.setAspectName(Constants.TAG_PROPERTIES_ASPECT_NAME);
proposal.setAspect(GenericRecordUtils.serializeAspect(mapTagProperties(input)));
proposal.setChangeType(ChangeType.UPSERT);
return _entityService.ingestProposal(proposal, createAuditStamp(context)).getUrn().toString();
return _entityClient.ingestProposal(proposal, context.getAuthentication());
} catch (Exception e) {
log.error("Failed to create Domain with id: {}, name: {}: {}", input.getId(), input.getName(), e.getMessage());
throw new RuntimeException(String.format("Failed to create Domain with id: %s, name: %s", input.getId(), input.getName()), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.linkedin.events.metadata.ChangeType;
import com.linkedin.metadata.Constants;
import com.linkedin.metadata.key.TestKey;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
import com.linkedin.mxe.MetadataChangeProposal;
import com.linkedin.test.TestInfo;
Expand All @@ -34,32 +35,37 @@ public CreateTestResolver(final EntityClient entityClient) {
@Override
public CompletableFuture<String> get(final DataFetchingEnvironment environment) throws Exception {
final QueryContext context = environment.getContext();
final CreateTestInput input = bindArgument(environment.getArgument("input"), CreateTestInput.class);

return CompletableFuture.supplyAsync(() -> {

if (canManageTests(context)) {

final CreateTestInput input = bindArgument(environment.getArgument("input"), CreateTestInput.class);
final MetadataChangeProposal proposal = new MetadataChangeProposal();
try {

// Create new test
// Since we are creating a new Test, we need to generate a unique UUID.
final UUID uuid = UUID.randomUUID();
final String uuidStr = input.getId() == null ? uuid.toString() : input.getId();
final MetadataChangeProposal proposal = new MetadataChangeProposal();

// Create the Ingestion source key
final TestKey key = new TestKey();
key.setId(uuidStr);
proposal.setEntityKeyAspect(GenericRecordUtils.serializeAspect(key));
// Create new test
// Since we are creating a new Test, we need to generate a unique UUID.
final UUID uuid = UUID.randomUUID();
final String uuidStr = input.getId() == null ? uuid.toString() : input.getId();

// Create the Test info.
final TestInfo info = mapCreateTestInput(input);
proposal.setEntityType(Constants.TEST_ENTITY_NAME);
proposal.setAspectName(Constants.TEST_INFO_ASPECT_NAME);
proposal.setAspect(GenericRecordUtils.serializeAspect(info));
proposal.setChangeType(ChangeType.UPSERT);
// Create the Ingestion source key
final TestKey key = new TestKey();
key.setId(uuidStr);
proposal.setEntityKeyAspect(GenericRecordUtils.serializeAspect(key));

if (_entityClient.exists(EntityKeyUtils.convertEntityKeyToUrn(key, Constants.TEST_ENTITY_NAME), context.getAuthentication())) {
throw new IllegalArgumentException("This Test already exists!");
}

// Create the Test info.
final TestInfo info = mapCreateTestInput(input);
proposal.setEntityType(Constants.TEST_ENTITY_NAME);
proposal.setAspectName(Constants.TEST_INFO_ASPECT_NAME);
proposal.setAspect(GenericRecordUtils.serializeAspect(info));
proposal.setChangeType(ChangeType.UPSERT);

try {
return _entityClient.ingestProposal(proposal, context.getAuthentication());
} catch (Exception e) {
throw new RuntimeException(String.format("Failed to perform update against Test with urn %s", input.toString()), e);
Expand Down
Loading