UNOMI-150 Migration help message with all scripts

Add migration help message listing all available scripts.


Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/2ca6dc6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/2ca6dc6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/2ca6dc6e

Branch: refs/heads/master
Commit: 2ca6dc6ea4f987089e305be961e21e8f66a68720
Parents: 1bbce3f
Author: Jarek Lipski <jlip...@jahia.com>
Authored: Thu Feb 8 19:21:36 2018 +0100
Committer: Jarek Lipski <jlip...@jahia.com>
Committed: Thu Feb 8 19:21:36 2018 +0100

----------------------------------------------------------------------
 .../apache/unomi/shell/migration/Migration.java |  6 ++++++
 .../unomi/shell/migration/actions/Migrate.java  | 20 +++++++++++++++++++-
 .../shell/migration/impl/MigrationTo121.java    |  5 +++++
 .../shell/migration/impl/MigrationTo122.java    |  5 +++++
 4 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2ca6dc6e/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/Migration.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/Migration.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/Migration.java
index 141c4b4..84f3566 100644
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/Migration.java
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/Migration.java
@@ -41,6 +41,12 @@ public interface Migration {
     Version getToVersion();
 
     /**
+     * This method returns a short description of the changes performed during 
this migration
+     * @return the migration description
+     */
+    String getDescription();
+
+    /**
      * This method is called to execute the migration
      * @param session       CommandSession
      * @param httpClient    CloseableHttpClient

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2ca6dc6e/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
index 9b5fa58..4a0d07e 100644
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/actions/Migrate.java
@@ -32,10 +32,15 @@ public class Migrate extends OsgiCommandSupport {
 
     private List<Migration> migrations;
 
-    @Argument(name = "fromVersionWithoutSuffix", description = "Origin version 
without suffix/qualifier (e.g: 1.2.0)", required = true, multiValued = false, 
valueToShowInHelp = "1.2.0")
+    @Argument(name = "fromVersionWithoutSuffix", description = "Origin version 
without suffix/qualifier (e.g: 1.2.0)", multiValued = false, valueToShowInHelp 
= "1.2.0")
     private String fromVersionWithoutSuffix;
 
     protected Object doExecute() throws Exception {
+        if (fromVersionWithoutSuffix == null) {
+            listMigrations();
+            return null;
+        }
+
         String confirmation = 
ConsoleUtils.askUserWithAuthorizedAnswer(session,"[WARNING] You are about to 
execute a migration, this a very sensitive operation, are you sure? (yes/no): 
", Arrays.asList("yes", "no"));
         if (confirmation.equalsIgnoreCase("no")) {
             System.out.println("Migration process aborted");
@@ -83,6 +88,19 @@ public class Migrate extends OsgiCommandSupport {
         return new Version(currentVersion.getMajor() + "." + 
currentVersion.getMinor() + "." + currentVersion.getMicro());
     }
 
+    private void listMigrations() {
+        Version previousVersion = new Version("0.0.0");
+        for (Migration migration : migrations) {
+            if (migration.getToVersion().getMajor() > 
previousVersion.getMajor() || migration.getToVersion().getMinor() > 
previousVersion.getMinor()) {
+                System.out.println("From " + 
migration.getToVersion().getMajor() + "." + migration.getToVersion().getMinor() 
+ ".0:");
+            }
+            System.out.println("- " + migration.getToVersion() + " " + 
migration.getDescription());
+            previousVersion = migration.getToVersion();
+        }
+        System.out.println("Select your migration starting point by specifying 
the current version (e.g. 1.2.0) or the last script that was already run (e.g. 
1.2.1)");
+
+    }
+
     public void setMigrations(List<Migration> migrations) {
         this.migrations = migrations;
     }

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2ca6dc6e/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
index b2cd923..4187862 100644
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo121.java
@@ -51,6 +51,11 @@ public class MigrationTo121 implements Migration {
     }
 
     @Override
+    public String getDescription() {
+        return "Migrate tags";
+    }
+
+    @Override
     public void execute(CommandSession session, CloseableHttpClient 
httpClient, String esAddress) throws IOException {
         this.httpClient = httpClient;
         this.session = session;

http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/2ca6dc6e/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
----------------------------------------------------------------------
diff --git 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
index 95c3a53..6782728 100644
--- 
a/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
+++ 
b/tools/shell-commands/src/main/java/org/apache/unomi/shell/migration/impl/MigrationTo122.java
@@ -42,6 +42,11 @@ public class MigrationTo122 implements Migration {
     }
 
     @Override
+    public String getDescription() {
+        return "Delete old index template";
+    }
+
+    @Override
     public void execute(CommandSession session, CloseableHttpClient 
httpClient, String esAddress) throws IOException {
         this.httpClient = httpClient;
         this.session = session;

Reply via email to