You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by js...@apache.org on 2022/07/12 16:18:33 UTC

[unomi] branch UNOMI-603-migration-profiles updated (55a0a13f8 -> 57a5aac24)

This is an automated email from the ASF dual-hosted git repository.

jsinovassinnaik pushed a change to branch UNOMI-603-migration-profiles
in repository https://gitbox.apache.org/repos/asf/unomi.git


 discard 55a0a13f8 feedbacks
     new 57a5aac24 feedbacks

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (55a0a13f8)
            \
             N -- N -- N   refs/heads/UNOMI-603-migration-profiles (57a5aac24)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../main/resources/requestBody/2.0.0/update_profile_interests.json    | 4 ----
 1 file changed, 4 deletions(-)
 delete mode 100644 tools/shell-commands/src/main/resources/requestBody/2.0.0/update_profile_interests.json


[unomi] 01/01: feedbacks

Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jsinovassinnaik pushed a commit to branch UNOMI-603-migration-profiles
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 57a5aac24b0b092bb6b74a57c40df84507e0bed8
Author: jsinovassin <js...@jahia.com>
AuthorDate: Tue Jul 12 18:10:20 2022 +0200

    feedbacks
---
 .../shell/migration/utils/MigrationUtils.java      | 30 +++++++++++++++++++---
 .../migrate-2.0.0-03-profileReindex.groovy         |  2 +-
 .../2.0.0/migrate_existing_interests.painless}     | 17 ++++++++----
 .../2.0.0/update_profile_interests.json            |  4 ---
 4 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/MigrationUtils.java b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/MigrationUtils.java
index 809e8dbc8..f055be2d3 100644
--- a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/MigrationUtils.java
+++ b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/utils/MigrationUtils.java
@@ -22,8 +22,11 @@ import org.apache.http.impl.client.CloseableHttpClient;
 import org.json.JSONObject;
 import org.osgi.framework.BundleContext;
 
+import java.io.BufferedReader;
+import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 
@@ -57,6 +60,24 @@ public class MigrationUtils {
         }
     }
 
+    public static String getFileWithoutComments(BundleContext bundleContext, final String resource) {
+        final URL url = bundleContext.getBundle().getResource(resource);
+        try (InputStream stream = url.openStream()) {
+            DataInputStream in = new DataInputStream(stream);
+            BufferedReader br = new BufferedReader(new InputStreamReader(in));
+            String line;
+            StringBuilder value = new StringBuilder();
+            while ((line = br.readLine()) != null) {
+                if (!line.startsWith("/*") && !line.startsWith(" *") && !line.startsWith("*/"))
+                    value.append(line);
+            }
+            in.close();
+            return value.toString();
+        } catch (final Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     public static void reIndex(CloseableHttpClient httpClient, BundleContext bundleContext, String esAddress, String indexName,
             String newIndexSettings, String painlessScript) throws IOException {
         String indexNameCloned = indexName + "-cloned";
@@ -69,9 +90,8 @@ public class MigrationUtils {
                 .replace("#maxDocValueFieldsSearch", originalIndexSettings.getJSONObject(indexName).getJSONObject("settings").getJSONObject("index").getString("max_docvalue_fields_search"))
                 .replace("#mappingTotalFieldsLimit", originalIndexSettings.getJSONObject(indexName).getJSONObject("settings").getJSONObject("index").getJSONObject("mapping").getJSONObject("total_fields").getString("limit"));
         String reIndexRequest = resourceAsString(bundleContext, "requestBody/2.0.0/base_reindex_request.json")
-                .replace("#source", indexNameCloned)
-                .replace("#dest", indexName)
-                .replace("#painless", StringUtils.isNotEmpty(painlessScript)? ", \"script\":" + painlessScript: "");
+                .replace("#source", indexNameCloned).replace("#dest", indexName)
+                .replace("#painless", StringUtils.isNotEmpty(painlessScript) ? getScriptPart(painlessScript) : "");
 
         String setIndexReadOnlyRequest = resourceAsString(bundleContext, "requestBody/2.0.0/base_set_index_readonly_request.json");
 
@@ -88,4 +108,8 @@ public class MigrationUtils {
         // Remove clone
         HttpUtils.executeDeleteRequest(httpClient, esAddress + "/" + indexNameCloned, null);
     }
+
+    private static String getScriptPart(String painlessScript) {
+        return ", \"script\": {\"source\": \"" + painlessScript + "\", \"lang\": \"painless\"}";
+    }
 }
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy
index 44f2731f1..5eaa63e0e 100644
--- a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy
+++ b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy
@@ -19,4 +19,4 @@ import org.apache.unomi.shell.migration.utils.MigrationUtils
 
 String newIndexSettings = MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/profile_index.json");
 MigrationUtils.reIndex(httpClient, bundleContext, migrationConfig.get("esAddress"), migrationConfig.get("indexPrefix") + "-profile",
-        newIndexSettings, MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/update_profile_interests.json"))
+        newIndexSettings, MigrationUtils.getFileWithoutComments(bundleContext, "requestBody/2.0.0/migrate_existing_interests.painless"))
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy b/tools/shell-commands/src/main/resources/requestBody/2.0.0/migrate_existing_interests.painless
similarity index 63%
copy from tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy
copy to tools/shell-commands/src/main/resources/requestBody/2.0.0/migrate_existing_interests.painless
index 44f2731f1..93fd9cec6 100644
--- a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.0.0-03-profileReindex.groovy
+++ b/tools/shell-commands/src/main/resources/requestBody/2.0.0/migrate_existing_interests.painless
@@ -1,5 +1,3 @@
-import org.apache.unomi.shell.migration.utils.MigrationUtils
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -17,6 +15,15 @@ import org.apache.unomi.shell.migration.utils.MigrationUtils
  * limitations under the License.
  */
 
-String newIndexSettings = MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/profile_index.json");
-MigrationUtils.reIndex(httpClient, bundleContext, migrationConfig.get("esAddress"), migrationConfig.get("indexPrefix") + "-profile",
-        newIndexSettings, MigrationUtils.resourceAsString(bundleContext, "requestBody/2.0.0/update_profile_interests.json"))
+List interests = new ArrayList();
+
+if (ctx._source.properties.interests != null && !(ctx._source.properties.interests instanceof List)){
+    for (entry in ctx._source.properties.interests.entrySet()){
+      Map interest = new HashMap();
+      interest.put('key',entry.getKey());
+      interest.put('value', entry.getValue());
+      interests.add(interest);
+    }
+    ctx._source.properties.remove('interests');
+    ctx._source.properties.put('interests',interests);
+}
diff --git a/tools/shell-commands/src/main/resources/requestBody/2.0.0/update_profile_interests.json b/tools/shell-commands/src/main/resources/requestBody/2.0.0/update_profile_interests.json
deleted file mode 100644
index eedc60dcd..000000000
--- a/tools/shell-commands/src/main/resources/requestBody/2.0.0/update_profile_interests.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-    "source": "List interests = new ArrayList(); if(ctx._source.properties.interests != null && !(ctx._source.properties.interests instanceof List)){ for (entry in ctx._source.properties.interests.entrySet()){ Map interest = new HashMap(); interest.put('key',entry.getKey()); interest.put('value', entry.getValue()); interests.add(interest);} ctx._source.properties.remove('interests'); ctx._source.properties.put('interests',interests);}",
-    "lang": "painless"
-}