You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2023/03/20 10:36:17 UTC
[unomi] branch master updated: UNOMI-752 : ensure target indices and alias does not exist before per… (#591)
This is an automated email from the ASF dual-hosted git repository.
dgriffon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new 25e5f5196 UNOMI-752 : ensure target indices and alias does not exist before per… (#591)
25e5f5196 is described below
commit 25e5f5196d8aa13f32ab8fc77942f1d82aa4820a
Author: David Griffon <dg...@jahia.com>
AuthorDate: Mon Mar 20 11:35:37 2023 +0100
UNOMI-752 : ensure target indices and alias does not exist before per… (#591)
* UNOMI-752 : ensure target indices and alias does not exist before performing migration
* UNOMI-752 : ensure target indices and alias does not exist before performing migration
* UNOMI-752 : change step oder to have the migration rerun working properly
---
.../unomi/shell/migration/MigrationException.java | 26 +++++++++++++++
.../shell/migration/service/MigrationContext.java | 13 ++++++++
.../migration/service/MigrationServiceImpl.java | 4 +++
.../migrate-2.2.0-00-migrationEnvCheck.groovy | 38 ++++++++++++++++++++++
.../migrate-2.2.0-05-indicesReduction.groovy | 1 -
...2.2.0-10-rolloverAndMigrateEventSession.groovy} | 0
6 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/MigrationException.java b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/MigrationException.java
new file mode 100644
index 000000000..2fdf7c2a7
--- /dev/null
+++ b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/MigrationException.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.shell.migration;
+
+/**
+ * Simple exception to handle errors in migration
+ */
+public class MigrationException extends RuntimeException {
+ public MigrationException(String message) {
+ super(message);
+ }
+}
diff --git a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/service/MigrationContext.java b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/service/MigrationContext.java
index 21835c31e..7f64b594b 100644
--- a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/service/MigrationContext.java
+++ b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/service/MigrationContext.java
@@ -198,6 +198,19 @@ public class MigrationContext {
}
}
+ /**
+ * Same as above without stacktrace
+ * @param msg the message to print out with a newline
+ */
+ public void printException(String msg) {
+ if (session == null) {
+ logger.error(msg);
+ } else {
+ PrintStream writer = session.getConsole();
+ writer.println(msg);
+ }
+ }
+
/**
* Get config for property name, in case the property doesn't exist on file system config file
* Best effort will be made to prompt question in karaf shell to get the needed information
diff --git a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/service/MigrationServiceImpl.java b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/service/MigrationServiceImpl.java
index 9722bb3fd..f0159d947 100644
--- a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/service/MigrationServiceImpl.java
+++ b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/service/MigrationServiceImpl.java
@@ -26,6 +26,7 @@ import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.karaf.shell.api.console.Session;
+import org.apache.unomi.shell.migration.MigrationException;
import org.apache.unomi.shell.migration.MigrationService;
import org.apache.unomi.shell.migration.utils.HttpUtils;
import org.osgi.framework.Bundle;
@@ -128,6 +129,9 @@ public class MigrationServiceImpl implements MigrationService {
context.printMessage("Starting execution of: " + migrateScript);
try {
migrateScript.getCompiledScript().run();
+ } catch (MigrationException e) {
+ context.printException("Error executing: " + migrateScript);
+ throw e;
} catch (Exception e) {
context.printException("Error executing: " + migrateScript, e);
throw e;
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-00-migrationEnvCheck.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-00-migrationEnvCheck.groovy
new file mode 100644
index 000000000..bf28355c0
--- /dev/null
+++ b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-00-migrationEnvCheck.groovy
@@ -0,0 +1,38 @@
+import org.apache.unomi.shell.migration.MigrationException
+import org.apache.unomi.shell.migration.service.MigrationContext
+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
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+MigrationContext context = migrationContext
+String esAddress = context.getConfigString("esAddress")
+String indexPrefix = context.getConfigString("indexPrefix")
+def mewIndicesAndAliases = ["systemitems", "session-000001", "event-000001", "session", "event"]
+
+// Check env is ready for migration
+context.performMigrationStep("2.2.0-check-env-ready-for-migrate-event-session", () -> {
+ def currentIndex = ""
+ if (mewIndicesAndAliases.any{index -> {
+ currentIndex = index
+ return MigrationUtils.indexExists(context.getHttpClient(), esAddress, "${indexPrefix}-${currentIndex}")
+ }}) {
+ throw new MigrationException("Migration creates new index/aliases. Index or alias ${indexPrefix}-${currentIndex} already exists, please remove it then restart migration")
+ }
+})
+
+
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-05-indicesReduction.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-05-indicesReduction.groovy
index 631f0bced..6d2f9cfc3 100644
--- a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-05-indicesReduction.groovy
+++ b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-05-indicesReduction.groovy
@@ -42,7 +42,6 @@ def indicesToReduce = [
exportconfig: [reduceTo: "systemitems", renameId: true],
rulestats: [reduceTo: "systemitems", renameId: true],
groovyaction: [reduceTo: "systemitems", renameId: true],
-
persona: [reduceTo: "profile", renameId: false]
]
diff --git a/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-00-rolloverAndMigrateEventSession.groovy b/tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-10-rolloverAndMigrateEventSession.groovy
similarity index 100%
rename from tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-00-rolloverAndMigrateEventSession.groovy
rename to tools/shell-commands/src/main/resources/META-INF/cxs/migration/migrate-2.2.0-10-rolloverAndMigrateEventSession.groovy