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

- Add validation to remove using pipeline/storeProcedure as a node #16223

Closed
wants to merge 1 commit into from
Closed
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 @@ -23,6 +23,7 @@
import static org.openmetadata.service.Entity.MLMODEL;
import static org.openmetadata.service.Entity.PIPELINE;
import static org.openmetadata.service.Entity.SEARCH_INDEX;
import static org.openmetadata.service.Entity.STORED_PROCEDURE;
import static org.openmetadata.service.Entity.TABLE;
import static org.openmetadata.service.Entity.TOPIC;
import static org.openmetadata.service.search.SearchClient.GLOBAL_SEARCH_ALIAS;
Expand All @@ -35,6 +36,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.json.JsonPatch;
import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -75,6 +77,9 @@
public class LineageRepository {
private final CollectionDAO dao;

private static final Set<String> UNSUPPORTED_LINEAGE_NODE_ENTITIES =
Set.of(PIPELINE, STORED_PROCEDURE);

private static final SearchClient searchClient = Entity.getSearchRepository().getSearchClient();

public LineageRepository() {
Expand All @@ -96,12 +101,19 @@ public EntityLineage getByName(

@Transaction
public void addLineage(AddLineage addLineage) {
// Validate from entity
EntityReference from = addLineage.getEdge().getFromEntity();
from = Entity.getEntityReferenceById(from.getType(), from.getId(), Include.NON_DELETED);

// Validate to entity
EntityReference to = addLineage.getEdge().getToEntity();

// Check if these
if (UNSUPPORTED_LINEAGE_NODE_ENTITIES.contains(to.getType())
|| UNSUPPORTED_LINEAGE_NODE_ENTITIES.contains(from.getType())) {
throw new IllegalArgumentException(
String.format(
"Unsupported Entity Type %s for lineage, It cannot be used as Node.", to.getType()));
}

// Validate from and to entites
from = Entity.getEntityReferenceById(from.getType(), from.getId(), Include.NON_DELETED);
to = Entity.getEntityReferenceById(to.getType(), to.getId(), Include.NON_DELETED);

if (addLineage.getEdge().getLineageDetails() != null
Expand Down Expand Up @@ -437,7 +449,7 @@ private void getUpstreamLineage(
}
List<EntityRelationshipRecord> records;
// pipeline information is not maintained
if (entityType.equals(Entity.PIPELINE) || entityType.equals(Entity.STORED_PROCEDURE)) {
if (entityType.equals(Entity.PIPELINE) || entityType.equals(STORED_PROCEDURE)) {
records = dao.relationshipDAO().findFromPipeline(id, Relationship.UPSTREAM.ordinal());
} else {
records = dao.relationshipDAO().findFrom(id, entityType, Relationship.UPSTREAM.ordinal());
Expand Down Expand Up @@ -524,7 +536,7 @@ private void getDownstreamLineage(
return;
}
List<EntityRelationshipRecord> records;
if (entityType.equals(Entity.PIPELINE) || entityType.equals(Entity.STORED_PROCEDURE)) {
if (entityType.equals(Entity.PIPELINE) || entityType.equals(STORED_PROCEDURE)) {
records = dao.relationshipDAO().findToPipeline(id, Relationship.UPSTREAM.ordinal());
} else {
records = dao.relationshipDAO().findTo(id, entityType, Relationship.UPSTREAM.ordinal());
Expand Down
Loading