You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2023/12/27 15:10:20 UTC
(syncope) branch 3_0_X updated: Minor refinements
This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 3_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/3_0_X by this push:
new 280597ff1f Minor refinements
280597ff1f is described below
commit 280597ff1f528e876df46d0b0ca2ac3acb9f1347
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Wed Dec 27 16:10:10 2023 +0100
Minor refinements
---
.../java/job/ElasticsearchReindex.java | 63 +++++++++++---------
.../provisioning/java/job/OpenSearchReindex.java | 67 ++++++++++++----------
2 files changed, 72 insertions(+), 58 deletions(-)
diff --git a/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java b/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java
index 18b5d7e509..eba46b5a44 100644
--- a/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java
+++ b/ext/elasticsearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/ElasticsearchReindex.java
@@ -158,14 +158,29 @@ public class ElasticsearchReindex extends AbstractSchedTaskJobDelegate<SchedTask
setStatus("Start rebuilding indexes");
try {
- indexManager.createAnyIndex(
- AuthContextUtils.getDomain(), AnyTypeKind.USER, userSettings(), userMapping());
+ indexManager.createRealmIndex(AuthContextUtils.getDomain(), realmSettings(), realmMapping());
- indexManager.createAnyIndex(
- AuthContextUtils.getDomain(), AnyTypeKind.GROUP, groupSettings(), groupMapping());
+ int realms = realmDAO.count();
+ String rindex = ElasticsearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+ setStatus("Indexing " + realms + " realms under " + rindex + "...");
+
+ try (BulkIngester<Void> ingester = BulkIngester.of(b -> b.client(client).
+ maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE))) {
+
+ for (int page = 1; page <= (realms / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
+ for (String realm : realmDAO.findAllKeys(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
+ ingester.add(op -> op.index(idx -> idx.
+ index(rindex).
+ id(realm).
+ document(utils.document(realmDAO.find(realm)))));
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Errors while ingesting index {}", rindex, e);
+ }
indexManager.createAnyIndex(
- AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT, anyObjectSettings(), anyObjectMapping());
+ AuthContextUtils.getDomain(), AnyTypeKind.USER, userSettings(), userMapping());
int users = userDAO.count();
String uindex = ElasticsearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER);
@@ -186,6 +201,9 @@ public class ElasticsearchReindex extends AbstractSchedTaskJobDelegate<SchedTask
LOG.error("Errors while ingesting index {}", uindex, e);
}
+ indexManager.createAnyIndex(
+ AuthContextUtils.getDomain(), AnyTypeKind.GROUP, groupSettings(), groupMapping());
+
int groups = groupDAO.count();
String gindex = ElasticsearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.GROUP);
setStatus("Indexing " + groups + " groups under " + gindex + "...");
@@ -202,9 +220,12 @@ public class ElasticsearchReindex extends AbstractSchedTaskJobDelegate<SchedTask
}
}
} catch (Exception e) {
- LOG.error("Errors while ingesting index {}", uindex, e);
+ LOG.error("Errors while ingesting index {}", gindex, e);
}
+ indexManager.createAnyIndex(
+ AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT, anyObjectSettings(), anyObjectMapping());
+
int anyObjects = anyObjectDAO.count();
String aindex = ElasticsearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT);
setStatus("Indexing " + anyObjects + " any objects under " + aindex + "...");
@@ -221,33 +242,19 @@ public class ElasticsearchReindex extends AbstractSchedTaskJobDelegate<SchedTask
}
}
} catch (Exception e) {
- LOG.error("Errors while ingesting index {}", uindex, e);
- }
-
- indexManager.createRealmIndex(AuthContextUtils.getDomain(), realmSettings(), realmMapping());
-
- int realms = realmDAO.count();
- String rindex = ElasticsearchUtils.getRealmIndex(AuthContextUtils.getDomain());
- setStatus("Indexing " + realms + " realms under " + rindex + "...");
-
- try (BulkIngester<Void> ingester = BulkIngester.of(b -> b.client(client).
- maxOperations(AnyDAO.DEFAULT_PAGE_SIZE).listener(ErrorLoggingBulkListener.INSTANCE))) {
-
- for (int page = 1; page <= (realms / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
- for (String realm : realmDAO.findAllKeys(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
- ingester.add(op -> op.index(idx -> idx.
- index(rindex).
- id(realm).
- document(utils.document(realmDAO.find(realm)))));
- }
- }
- } catch (Exception e) {
- LOG.error("Errors while ingesting index {}", uindex, e);
+ LOG.error("Errors while ingesting index {}", aindex, e);
}
indexManager.createAuditIndex(AuthContextUtils.getDomain(), auditSettings(), auditMapping());
setStatus("Rebuild indexes for domain " + AuthContextUtils.getDomain() + " successfully completed");
+
+ return "Indexes created:\n"
+ + " " + rindex + " [" + realms + "]\n"
+ + " " + uindex + " [" + users + "]\n"
+ + " " + gindex + " [" + groups + "]\n"
+ + " " + aindex + " [" + anyObjects + "]\n"
+ + " " + ElasticsearchUtils.getAuditIndex(AuthContextUtils.getDomain());
} catch (Exception e) {
throw new JobExecutionException("While rebuilding index for domain " + AuthContextUtils.getDomain(), e);
}
diff --git a/ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java b/ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java
index 782c8de24a..ae3d63e960 100644
--- a/ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java
+++ b/ext/opensearch/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/OpenSearchReindex.java
@@ -113,14 +113,33 @@ public class OpenSearchReindex extends AbstractSchedTaskJobDelegate<SchedTask> {
setStatus("Start rebuilding indexes");
try {
- indexManager.createAnyIndex(
- AuthContextUtils.getDomain(), AnyTypeKind.USER, userSettings(), userMapping());
+ indexManager.createRealmIndex(AuthContextUtils.getDomain(), realmSettings(), realmMapping());
- indexManager.createAnyIndex(
- AuthContextUtils.getDomain(), AnyTypeKind.GROUP, groupSettings(), groupMapping());
+ int realms = realmDAO.count();
+ String rindex = OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
+ setStatus("Indexing " + realms + " realms under " + rindex + "...");
+ for (int page = 1; page <= (realms / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
+ BulkRequest.Builder bulkRequest = new BulkRequest.Builder();
+
+ for (String realm : realmDAO.findAllKeys(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
+ bulkRequest.operations(op -> op.index(idx -> idx.
+ index(rindex).
+ id(realm).
+ document(utils.document(realmDAO.find(realm)))));
+ }
+
+ try {
+ BulkResponse response = client.bulk(bulkRequest.build());
+ LOG.debug("Index successfully created for {} [{}/{}]: {}",
+ rindex, page, AnyDAO.DEFAULT_PAGE_SIZE, response);
+ } catch (Exception e) {
+ LOG.error("Could not create index for {} [{}/{}]: {}",
+ rindex, page, AnyDAO.DEFAULT_PAGE_SIZE, e);
+ }
+ }
indexManager.createAnyIndex(
- AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT, anyObjectSettings(), anyObjectMapping());
+ AuthContextUtils.getDomain(), AnyTypeKind.USER, userSettings(), userMapping());
int users = userDAO.count();
String uindex = OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.USER);
@@ -145,6 +164,9 @@ public class OpenSearchReindex extends AbstractSchedTaskJobDelegate<SchedTask> {
}
}
+ indexManager.createAnyIndex(
+ AuthContextUtils.getDomain(), AnyTypeKind.GROUP, groupSettings(), groupMapping());
+
int groups = groupDAO.count();
String gindex = OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.GROUP);
setStatus("Indexing " + groups + " groups under " + gindex + "...");
@@ -168,6 +190,9 @@ public class OpenSearchReindex extends AbstractSchedTaskJobDelegate<SchedTask> {
}
}
+ indexManager.createAnyIndex(
+ AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT, anyObjectSettings(), anyObjectMapping());
+
int anyObjects = anyObjectDAO.count();
String aindex = OpenSearchUtils.getAnyIndex(AuthContextUtils.getDomain(), AnyTypeKind.ANY_OBJECT);
setStatus("Indexing " + anyObjects + " any objects under " + aindex + "...");
@@ -191,34 +216,16 @@ public class OpenSearchReindex extends AbstractSchedTaskJobDelegate<SchedTask> {
}
}
- indexManager.createRealmIndex(AuthContextUtils.getDomain(), realmSettings(), realmMapping());
-
- int realms = realmDAO.count();
- String rindex = OpenSearchUtils.getRealmIndex(AuthContextUtils.getDomain());
- setStatus("Indexing " + realms + " realms under " + rindex + "...");
- for (int page = 1; page <= (realms / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
- BulkRequest.Builder bulkRequest = new BulkRequest.Builder();
-
- for (String realm : realmDAO.findAllKeys(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
- bulkRequest.operations(op -> op.index(idx -> idx.
- index(rindex).
- id(realm).
- document(utils.document(realmDAO.find(realm)))));
- }
-
- try {
- BulkResponse response = client.bulk(bulkRequest.build());
- LOG.debug("Index successfully created for {} [{}/{}]: {}",
- rindex, page, AnyDAO.DEFAULT_PAGE_SIZE, response);
- } catch (Exception e) {
- LOG.error("Could not create index for {} [{}/{}]: {}",
- rindex, page, AnyDAO.DEFAULT_PAGE_SIZE, e);
- }
- }
-
indexManager.createAuditIndex(AuthContextUtils.getDomain(), auditSettings(), auditMapping());
setStatus("Rebuild indexes for domain " + AuthContextUtils.getDomain() + " successfully completed");
+
+ return "Indexes created:\n"
+ + " " + rindex + " [" + realms + "]\n"
+ + " " + uindex + " [" + users + "]\n"
+ + " " + gindex + " [" + groups + "]\n"
+ + " " + aindex + " [" + anyObjects + "]\n"
+ + " " + OpenSearchUtils.getAuditIndex(AuthContextUtils.getDomain());
} catch (Exception e) {
throw new JobExecutionException("While rebuilding index for domain " + AuthContextUtils.getDomain(), e);
}