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

MESH-184 Validations for domainGUIDs de-norm attribute #3442

Merged
merged 21 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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 @@ -287,21 +287,20 @@ protected List<AtlasEntityHeader> getPolicies(Set<String> resources) throws Atla
}
}

protected Boolean isAssetLinked(String domainGuid) throws AtlasBaseException {
protected Boolean hasLinkedAssets(String domainGuid) throws AtlasBaseException {
AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("isAssetLinked");
boolean exists = false;
try {
List<Map<String, Object>> mustClauseList = new ArrayList<>();
mustClauseList.add(mapOf("term", mapOf("__state", "ACTIVE")));
mustClauseList.add(mapOf("term", mapOf(DOMAIN_GUIDS, domainGuid)));

Map<String, Object> bool = new HashMap<>();
bool.put("must", mustClauseList);

Map<String, Object> dsl = mapOf("query", mapOf("bool", bool));

List<AtlasEntityHeader> assets = fetchLinkedAssets(dsl, DOMAIN_GUID_ATTR, this.discovery);
if (CollectionUtils.isNotEmpty(assets)) {
boolean hasLinkedAsset = fetchLinkedAssets(dsl, DOMAIN_GUID_ATTR, this.discovery);
if (hasLinkedAsset) {
PRATHAM2002-DS marked this conversation as resolved.
Show resolved Hide resolved
exists = true;
}

Expand All @@ -312,31 +311,21 @@ protected Boolean isAssetLinked(String domainGuid) throws AtlasBaseException {
}
}

protected static List<AtlasEntityHeader> fetchLinkedAssets(Map<String, Object> dsl, Set<String> attributes, EntityDiscoveryService discovery) throws AtlasBaseException {
protected static Boolean fetchLinkedAssets(Map<String, Object> dsl, Set<String> attributes, EntityDiscoveryService discovery) throws AtlasBaseException {
PRATHAM2002-DS marked this conversation as resolved.
Show resolved Hide resolved
IndexSearchParams searchParams = new IndexSearchParams();
List<AtlasEntityHeader> ret = new ArrayList<>();

if (CollectionUtils.isNotEmpty(attributes)) {
searchParams.setAttributes(attributes);
}

List<Map> sortList = new ArrayList<>(0);
sortList.add(mapOf("__timestamp", mapOf("order", "asc")));
sortList.add(mapOf("__guid", mapOf("order", "asc")));
dsl.put("sort", sortList);
boolean exists = false;

int from = 0;
int size = 1;
dsl.put("from", from);
dsl.put("size", size);
searchParams.setAttributes(attributes);
dsl.put("from", 0);
dsl.put("size", 1);
searchParams.setDsl(dsl);

List<AtlasEntityHeader> headers = discovery.directIndexSearch(searchParams).getEntities();

if (CollectionUtils.isNotEmpty(headers)) {
ret.addAll(headers);
exists = true;
}
return ret;
return exists;
}

protected List<AtlasEntityHeader> getStakeholderTitlesAndStakeholders(Set<String> qualifiedNames) throws AtlasBaseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void processDelete(AtlasVertex vertex) throws AtlasBaseException {
LOG.debug("DataDomainPreProcessor.processDelete: pre processing {}", domainGuid);
}

if (isAssetLinked(domainGuid)) {
if (hasLinkedAssets(domainGuid)) {
throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED, "Domain cannot be deleted because some assets are linked to this domain");
}
}
Expand Down
Loading