From 6f1be89d51900380c45646b23a29c7f907d3b6d9 Mon Sep 17 00:00:00 2001 From: PRATHAM2002-DS Date: Mon, 1 Apr 2024 20:06:31 +0530 Subject: [PATCH 1/7] IndexSearch param changes --- .../atlas/model/discovery/IndexSearchParams.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java b/intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java index 384ac27360..8d8cc08247 100644 --- a/intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java +++ b/intg/src/main/java/org/apache/atlas/model/discovery/IndexSearchParams.java @@ -27,6 +27,7 @@ public class IndexSearchParams extends SearchParams { * (this will include related attributes which has relationshipStatus as DELETED along with ACTIVE ones) * */ private boolean allowDeletedRelations; + private boolean accessControlExclusive; @Override public String getQuery() { @@ -46,6 +47,14 @@ public boolean isAllowDeletedRelations() { return allowDeletedRelations; } + public boolean isAccessControlExclusive() { + return accessControlExclusive; + } + + public void setAccessControlExclusive(boolean accessControlExclusive) { + this.accessControlExclusive = accessControlExclusive; + } + public void setAllowDeletedRelations(boolean allowDeletedRelations) { this.allowDeletedRelations = allowDeletedRelations; } @@ -78,6 +87,7 @@ public String toString() { ", persona='" + persona + '\'' + ", queryString='" + queryString + '\'' + ", allowDeletedRelations=" + allowDeletedRelations + + ", accessControlExclusive=" + accessControlExclusive + ", utmTags="+ getUtmTags() + '}'; } From 33eb987ba7a8306c93fc6845ded4e873cf367bb1 Mon Sep 17 00:00:00 2001 From: PRATHAM2002-DS Date: Mon, 1 Apr 2024 20:15:40 +0530 Subject: [PATCH 2/7] dsl build change --- .../discovery/EntityDiscoveryService.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java index 8b2aeecda1..46dc4022c0 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java @@ -1149,9 +1149,56 @@ private String getIndexName(IndexSearchParams params) throws AtlasBaseException String aliasName = parts[parts.length - 1]; if (StringUtils.isNotEmpty(aliasName)) { + if(params.isAccessControlExclusive()) { + aliasName = aliasName+","+VERTEX_INDEX_NAME; + Map < String, Object > dsl = accessControlExclusiveDsl(params.getDsl(), aliasName); + params.setDsl(dsl); + } return aliasName; } else { throw new AtlasBaseException("ES alias not found for purpose/persona " + params.getPurpose()); } } + + private Map accessControlExclusiveDsl(Map dsl, String aliasName) { + Map accessControlDsl = new HashMap<>(); + + List> mustClauses = new ArrayList<>(); + Map clientQuery = (Map) dsl.get("query"); + + mustClauses.add(clientQuery); + + Map filterClause = getMap("filter", getMap("terms", getMap("_index", Collections.singletonList(aliasName)))); + + + Map boolQuery = new HashMap<>(); + boolQuery.put("must", mustClauses); + boolQuery.put("filter",filterClause); + + List> shouldClauses = new ArrayList<>(); + shouldClauses.add(boolQuery); + shouldClauses.add(getStaticBoolQuery()); + + Map topBoolQuery = getMap("bool", getMap("should", shouldClauses)); + + accessControlDsl.put("query", topBoolQuery); + return accessControlDsl; + } + + private Map getStaticBoolQuery() { + List> mustClauses = new ArrayList<>(); + Map mustClause = getMap("bool", getMap("should", Arrays.asList( + getMap("term", getMap("daapVisibility", "Public")), + getMap("term", getMap("daapVisibility", "Protected")) + ))); + mustClauses.add(mustClause); + + Map filterClause = getMap("filter", getMap("terms", getMap("_index", Collections.singletonList(VERTEX_INDEX_NAME)))); + + Map boolQuery = new HashMap<>(); + boolQuery.put("must", mustClauses); + boolQuery.put("filter",filterClause); + + return boolQuery; + } } From cd9063a40e0c14afbafc629d32832f01f6a70a82 Mon Sep 17 00:00:00 2001 From: PRATHAM2002-DS Date: Mon, 1 Apr 2024 22:45:41 +0530 Subject: [PATCH 3/7] update clientDsl --- .../apache/atlas/discovery/EntityDiscoveryService.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java index 46dc4022c0..417681ffb2 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java @@ -1151,8 +1151,7 @@ private String getIndexName(IndexSearchParams params) throws AtlasBaseException if (StringUtils.isNotEmpty(aliasName)) { if(params.isAccessControlExclusive()) { aliasName = aliasName+","+VERTEX_INDEX_NAME; - Map < String, Object > dsl = accessControlExclusiveDsl(params.getDsl(), aliasName); - params.setDsl(dsl); + accessControlExclusiveDsl(params.getDsl(), aliasName); } return aliasName; } else { @@ -1160,8 +1159,7 @@ private String getIndexName(IndexSearchParams params) throws AtlasBaseException } } - private Map accessControlExclusiveDsl(Map dsl, String aliasName) { - Map accessControlDsl = new HashMap<>(); + private void accessControlExclusiveDsl(Map dsl, String aliasName) { List> mustClauses = new ArrayList<>(); Map clientQuery = (Map) dsl.get("query"); @@ -1181,8 +1179,7 @@ private Map accessControlExclusiveDsl(Map dsl, String aliasName) Map topBoolQuery = getMap("bool", getMap("should", shouldClauses)); - accessControlDsl.put("query", topBoolQuery); - return accessControlDsl; + dsl.put("query", topBoolQuery); } private Map getStaticBoolQuery() { From ddee9e70f7dc0f644799f732f3cbbc64ae462b8d Mon Sep 17 00:00:00 2001 From: PRATHAM2002-DS Date: Mon, 1 Apr 2024 23:30:31 +0530 Subject: [PATCH 4/7] filter type changed --- pom.xml | 2 +- .../atlas/discovery/EntityDiscoveryService.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 1cc9aa70dc..3abc39041b 100644 --- a/pom.xml +++ b/pom.xml @@ -717,7 +717,7 @@ 4.4.13 2.12.4 2.12.4 - 0.6.03 + 0.6.04 0.5.3 1 3.1.0 diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java index 417681ffb2..a64ebc3957 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java @@ -1166,15 +1166,16 @@ private void accessControlExclusiveDsl(Map dsl, String aliasName) { mustClauses.add(clientQuery); - Map filterClause = getMap("filter", getMap("terms", getMap("_index", Collections.singletonList(aliasName)))); - + List>filterClauses = new ArrayList<>(); + filterClauses.add(getMap("terms", getMap("_index", Collections.singletonList(aliasName)))); + Map filterClause = getMap("filter", filterClauses); Map boolQuery = new HashMap<>(); boolQuery.put("must", mustClauses); boolQuery.put("filter",filterClause); List> shouldClauses = new ArrayList<>(); - shouldClauses.add(boolQuery); + shouldClauses.add(getMap("bool", boolQuery)); shouldClauses.add(getStaticBoolQuery()); Map topBoolQuery = getMap("bool", getMap("should", shouldClauses)); @@ -1190,7 +1191,10 @@ private Map getStaticBoolQuery() { ))); mustClauses.add(mustClause); - Map filterClause = getMap("filter", getMap("terms", getMap("_index", Collections.singletonList(VERTEX_INDEX_NAME)))); + List>filterClauses = new ArrayList<>(); + filterClauses.add(getMap("terms", getMap("_index", Collections.singletonList(VERTEX_INDEX_NAME)))); + + Map filterClause = getMap("filter", filterClauses); Map boolQuery = new HashMap<>(); boolQuery.put("must", mustClauses); From 88361cf8e55f3d05e2421ea4917a14f347192c84 Mon Sep 17 00:00:00 2001 From: PRATHAM2002-DS Date: Mon, 1 Apr 2024 23:34:36 +0530 Subject: [PATCH 5/7] fixed static bool --- .../java/org/apache/atlas/discovery/EntityDiscoveryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java index a64ebc3957..0af8809b6d 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java @@ -1200,6 +1200,6 @@ private Map getStaticBoolQuery() { boolQuery.put("must", mustClauses); boolQuery.put("filter",filterClause); - return boolQuery; + return getMap("bool", boolQuery); } } From 2799d22febec36054f7ee440461638989587d934 Mon Sep 17 00:00:00 2001 From: Nikhil P Bonte Date: Tue, 2 Apr 2024 00:11:00 +0530 Subject: [PATCH 6/7] Fix 500 due to query manipulation --- .../discovery/EntityDiscoveryService.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java index a64ebc3957..b1b120c3fb 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java @@ -1150,8 +1150,8 @@ private String getIndexName(IndexSearchParams params) throws AtlasBaseException if (StringUtils.isNotEmpty(aliasName)) { if(params.isAccessControlExclusive()) { + accessControlExclusiveDsl(params, aliasName); aliasName = aliasName+","+VERTEX_INDEX_NAME; - accessControlExclusiveDsl(params.getDsl(), aliasName); } return aliasName; } else { @@ -1159,20 +1159,19 @@ private String getIndexName(IndexSearchParams params) throws AtlasBaseException } } - private void accessControlExclusiveDsl(Map dsl, String aliasName) { + private void accessControlExclusiveDsl(IndexSearchParams params, String aliasName) { List> mustClauses = new ArrayList<>(); - Map clientQuery = (Map) dsl.get("query"); + Map clientQuery = (Map) params.getDsl().get("query"); mustClauses.add(clientQuery); List>filterClauses = new ArrayList<>(); filterClauses.add(getMap("terms", getMap("_index", Collections.singletonList(aliasName)))); - Map filterClause = getMap("filter", filterClauses); Map boolQuery = new HashMap<>(); boolQuery.put("must", mustClauses); - boolQuery.put("filter",filterClause); + boolQuery.put("filter",filterClauses); List> shouldClauses = new ArrayList<>(); shouldClauses.add(getMap("bool", boolQuery)); @@ -1180,7 +1179,10 @@ private void accessControlExclusiveDsl(Map dsl, String aliasName) { Map topBoolQuery = getMap("bool", getMap("should", shouldClauses)); - dsl.put("query", topBoolQuery); + Map copyOfDsl = new HashMap(params.getDsl()); + copyOfDsl.put("query", topBoolQuery); + + params.setDsl(copyOfDsl); } private Map getStaticBoolQuery() { @@ -1194,12 +1196,10 @@ private Map getStaticBoolQuery() { List>filterClauses = new ArrayList<>(); filterClauses.add(getMap("terms", getMap("_index", Collections.singletonList(VERTEX_INDEX_NAME)))); - Map filterClause = getMap("filter", filterClauses); - Map boolQuery = new HashMap<>(); boolQuery.put("must", mustClauses); - boolQuery.put("filter",filterClause); + boolQuery.put("filter", filterClauses); - return boolQuery; + return getMap("bool", boolQuery); } } From 6651392759e9c55f4f286202a6f04d2ddde50f71 Mon Sep 17 00:00:00 2001 From: PRATHAM2002-DS Date: Tue, 2 Apr 2024 00:32:42 +0530 Subject: [PATCH 7/7] pom.xml change reverted --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3abc39041b..1cc9aa70dc 100644 --- a/pom.xml +++ b/pom.xml @@ -717,7 +717,7 @@ 4.4.13 2.12.4 2.12.4 - 0.6.04 + 0.6.03 0.5.3 1 3.1.0