You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by ma...@apache.org on 2015/10/21 12:29:07 UTC

syncope git commit: refactoring of installation process, SYNCOPE-158

Repository: syncope
Updated Branches:
  refs/heads/master 3f58b93c1 -> 4f543e8c0


refactoring of installation process, SYNCOPE-158


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/4f543e8c
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4f543e8c
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4f543e8c

Branch: refs/heads/master
Commit: 4f543e8c045edf6a321a1ac2bcf4b4ac7755b620
Parents: 3f58b93
Author: massi <ma...@tirasa.net>
Authored: Wed Oct 21 12:28:40 2015 +0200
Committer: massi <ma...@tirasa.net>
Committed: Wed Oct 21 12:28:40 2015 +0200

----------------------------------------------------------------------
 .../cli/commands/install/InstallCommand.java    | 215 +------------------
 .../commands/install/InstallResultManager.java  |  72 +++++++
 .../cli/commands/install/InstallSetup.java      | 161 ++++++++++++++
 3 files changed, 235 insertions(+), 213 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/4f543e8c/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java
index 533c1ce..0caba9f 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java
@@ -18,21 +18,11 @@
  */
 package org.apache.syncope.client.cli.commands.install;
 
-import java.io.FileNotFoundException;
-import java.io.UnsupportedEncodingException;
-import java.net.ConnectException;
-import java.net.UnknownHostException;
-import java.util.Scanner;
-import javax.ws.rs.ProcessingException;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.client.cli.Command;
 import org.apache.syncope.client.cli.Input;
-import org.apache.syncope.client.cli.SyncopeServices;
 import org.apache.syncope.client.cli.commands.AbstractCommand;
 import org.apache.syncope.client.cli.commands.logger.LoggerCommand;
-import org.apache.syncope.client.cli.util.FileSystemUtils;
-import org.apache.syncope.client.cli.util.JasyptUtils;
-import org.apache.syncope.common.rest.api.service.SyncopeService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,222 +36,21 @@ public class InstallCommand extends AbstractCommand {
             + "    --help \n"
             + "    --setup";
 
-    private String syncopeAdminUser;
-
-    private String syncopeAdminPassword;
-
-    private String syncopeServerSchema;
-
-    private String syncopeServerHostname = "localhost";
-
-    private String syncopeServerPort = "8080";
-
-    private String syncopeServerRestContext = "/syncope/rest/";
-
     @Override
     public void execute(final Input input) {
-        LOG.debug("Option: {}", input.getOption());
-        LOG.debug("Parameters:");
-        for (final String parameter : input.getParameters()) {
-            LOG.debug("   > " + parameter);
-        }
-
         if (StringUtils.isBlank(input.getOption())) {
             input.setOption(Options.HELP.getOptionName());
         }
 
         switch (Options.fromName(input.getOption())) {
             case INSTALL:
-                final Scanner scanIn = new Scanner(System.in);
-
-                System.out.println("");
-                System.out.println("###############################################");
-                System.out.println("#                                             #");
-                System.out.println("# Welcome to Syncope CLI installation process #");
-                System.out.println("#                                             #");
-                System.out.println("###############################################");
-                System.out.println("");
-
-                System.out.println("Path to config files of Syncope CLI client will be: "
-                        + InstallConfigFileTemplate.DIR_PATH);
-
-                if (!FileSystemUtils.canWrite(InstallConfigFileTemplate.DIR_PATH)) {
-                    System.out.println("Permission denied on " + InstallConfigFileTemplate.DIR_PATH);
-                    break;
-                }
-                System.out.println("- File system permission checked");
-                System.out.println("");
-
-                System.out.println("Syncope server schema [http/https]:");
-                String syncopeServerSchemaFromSystemIn = scanIn.nextLine();
-                boolean schemaFounded = false;
-                while (!schemaFounded) {
-                    if (("http".equalsIgnoreCase(syncopeServerSchemaFromSystemIn))
-                            || ("https".equalsIgnoreCase(syncopeServerSchemaFromSystemIn))) {
-                        syncopeServerSchema = syncopeServerSchemaFromSystemIn;
-                        schemaFounded = true;
-                    } else {
-                        System.out.println("Please use one of below values:");
-                        System.out.println("   - http");
-                        System.out.println("   - https");
-                        syncopeServerSchemaFromSystemIn = scanIn.nextLine();
-                    }
-                }
-
-                System.out.println("Syncope server hostname [e.g. " + syncopeServerHostname + "]:");
-                String syncopeServerHostnameFromSystemIn = scanIn.nextLine();
-                boolean syncopeServerHostnameFounded = false;
-                while (!syncopeServerHostnameFounded) {
-                    if (StringUtils.isNotBlank(syncopeServerHostnameFromSystemIn)) {
-                        syncopeServerHostname = syncopeServerHostnameFromSystemIn;
-                        syncopeServerHostnameFounded = true;
-                    } else {
-                        System.out.println("Syncope server hostname [e.g. " + syncopeServerHostname + "]:");
-                        syncopeServerHostnameFromSystemIn = scanIn.nextLine();
-                    }
-                }
-
-                System.out.println("Syncope server port [e.g. " + syncopeServerPort + "]:");
-                String syncopeServerPortFromSystemIn = scanIn.nextLine();
-                boolean syncopeServerPortFounded = false;
-                while (!syncopeServerPortFounded) {
-                    if (StringUtils.isNotBlank(syncopeServerPortFromSystemIn)) {
-                        syncopeServerPort = syncopeServerPortFromSystemIn;
-                        syncopeServerPortFounded = true;
-                    } else if (!StringUtils.isNumeric(syncopeServerPortFromSystemIn)) {
-                        System.out.println(syncopeServerPortFromSystemIn + " is not a numeric string, try again");
-                        syncopeServerPortFromSystemIn = scanIn.nextLine();
-                    } else {
-                        System.out.println("Syncope server port [e.g. " + syncopeServerPort + "]:");
-                        syncopeServerPortFromSystemIn = scanIn.nextLine();
-                    }
-                }
-
-                System.out.println("Syncope server rest context [e.g. " + syncopeServerRestContext + "]:");
-                String syncopeServerRestContextFromSystemIn = scanIn.nextLine();
-                boolean syncopeServerRestContextFounded = false;
-                while (!syncopeServerRestContextFounded) {
-                    if (StringUtils.isNotBlank(syncopeServerRestContextFromSystemIn)) {
-                        syncopeServerRestContext = syncopeServerRestContextFromSystemIn;
-                        syncopeServerRestContextFounded = true;
-                    } else {
-                        System.out.println("Syncope server port [e.g. " + syncopeServerRestContext + "]:");
-                        syncopeServerRestContextFromSystemIn = scanIn.nextLine();
-                    }
-                }
-
-                System.out.println("Syncope admin user:");
-                String syncopeAdminUserFromSystemIn = scanIn.nextLine();
-                boolean syncopeAdminUserFounded = false;
-                while (!syncopeAdminUserFounded) {
-                    if (StringUtils.isNotBlank(syncopeAdminUserFromSystemIn)) {
-                        syncopeAdminUser = syncopeAdminUserFromSystemIn;
-                        syncopeAdminUserFounded = true;
-                    } else {
-                        System.out.println("Syncope admin user:");
-                        syncopeAdminUserFromSystemIn = scanIn.nextLine();
-                    }
-                }
-
-                System.out.println("Syncope admin password:");
-                String syncopeAdminPasswordFromSystemIn = scanIn.nextLine();
-                boolean syncopeAdminPasswordFounded = false;
-                while (!syncopeAdminPasswordFounded) {
-                    if (StringUtils.isNotBlank(syncopeAdminPasswordFromSystemIn)) {
-                        syncopeAdminPassword = syncopeAdminPasswordFromSystemIn;
-                        syncopeAdminPasswordFounded = true;
-                    } else {
-                        System.out.println("Syncope admin user:");
-                        syncopeAdminPasswordFromSystemIn = scanIn.nextLine();
-                    }
-                }
-
-                scanIn.close();
-
-                final JasyptUtils jasyptUtils = JasyptUtils.getJasyptUtils();
-
-                try {
-                    FileSystemUtils.createNewDirectory(InstallConfigFileTemplate.DIR_PATH);
-                    final String contentCliPropertiesFile = InstallConfigFileTemplate.createFile(
-                            syncopeServerSchema,
-                            syncopeServerHostname,
-                            syncopeServerPort,
-                            syncopeServerRestContext,
-                            syncopeAdminUser,
-                            jasyptUtils.encrypt(syncopeAdminPassword));
-                    FileSystemUtils.createFileWith(InstallConfigFileTemplate.FILE_PATH, contentCliPropertiesFile);
-
-                } catch (final FileNotFoundException | UnsupportedEncodingException ex) {
-                    System.out.println(ex.getMessage());
-                }
-
-                try {
-                    final SyncopeService syncopeService = SyncopeServices.get(SyncopeService.class);
-                    System.out.println("Provided parameters checked on Syncope core version: "
-                            + syncopeService.info().getVersion());
-                    System.out.println("");
-                    System.out.println("###############################################");
-                    System.out.println("#                                             #");
-                    System.out.println("#           Installation successful           #");
-                    System.out.println("#     now you can use Syncope CLI client      #");
-                    System.out.println("#                                             #");
-                    System.out.println("###############################################");
-                    System.out.println("");
-                } catch (final ProcessingException ex) {
-                    if (ex.getCause() instanceof UnknownHostException) {
-                        final String unknownHost = ex.getCause().getMessage().split(":")[3];
-                        System.out.println("");
-                        System.out.println("Provided host:" + unknownHost);
-                        System.out.println("");
-                        System.out.println("###############################################");
-                        System.out.println("#                                             #");
-                        System.out.println("#            Provided unknown host!           #");
-                        System.out.println("#        START AGAIN the installation!        #");
-                        System.out.println("#                                             #");
-                        System.out.println("###############################################");
-                        System.out.println("");
-                    } else if (ex.getCause() instanceof ConnectException) {
-                        System.out.println("");
-                        System.out.println("Provided address :" + SyncopeServices.getAddress());
-                        System.out.println("");
-                        System.out.println("###############################################");
-                        System.out.println("#                                             #");
-                        System.out.println("#       Provided address is unreachable!      #");
-                        System.out.println("#         Check it and if it is wrong         #");
-                        System.out.println("#        START AGAIN the installation!        #");
-                        System.out.println("#                                             #");
-                        System.out.println("###############################################");
-                        System.out.println("");
-                    }
-                } catch (final Exception e) {
-                    if (e.getMessage().contains("not authenticated")) {
-                        System.out.println("");
-                        System.out.println("###############################################");
-                        System.out.println("#                                             #");
-                        System.out.println("#   Username or password provided are wrong   #");
-                        System.out.println("#        START AGAIN the installation!        #");
-                        System.out.println("#                                             #");
-                        System.out.println("###############################################");
-                        System.out.println("");
-                    } else {
-                        System.out.println("");
-                        System.out.println("###############################################");
-                        System.out.println("#                                             #");
-                        System.out.println("#                Something wrong              #");
-                        System.out.println("#        START AGAIN the installation!        #");
-                        System.out.println("#                                             #");
-                        System.out.println("###############################################");
-                        System.out.println("");
-                    }
-                }
+                new InstallSetup().setup();
                 break;
             case HELP:
                 System.out.println(HELP_MESSAGE);
                 break;
             default:
-                System.out.println(input.getOption() + " is not a valid option.");
-                System.out.println("");
-                System.out.println(HELP_MESSAGE);
+                new InstallResultManager().defaultError(input.getOption(), HELP_MESSAGE);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/4f543e8c/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallResultManager.java
new file mode 100644
index 0000000..994aca6
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallResultManager.java
@@ -0,0 +1,72 @@
+package org.apache.syncope.client.cli.commands.install;
+
+import java.net.ConnectException;
+import java.net.UnknownHostException;
+import javax.ws.rs.ProcessingException;
+import org.apache.syncope.client.cli.SyncopeServices;
+import org.apache.syncope.client.cli.commands.CommonsResultManager;
+
+public class InstallResultManager extends CommonsResultManager {
+
+    public void installationSuccessful(final String version) {
+        System.out.println("Installation parameters checked on Syncope core version: " + version);
+        System.out.println("");
+        System.out.println("###############################################");
+        System.out.println("#                                             #");
+        System.out.println("#           Installation successful           #");
+        System.out.println("#     now you can use Syncope CLI client      #");
+        System.out.println("#                                             #");
+        System.out.println("###############################################");
+        System.out.println("");
+    }
+
+    public void manageProcessingException(final ProcessingException ex) {
+        if (ex.getCause() instanceof UnknownHostException) {
+            final String unknownHost = ex.getCause().getMessage().split(":")[3];
+            System.out.println("");
+            System.out.println("Provided host:" + unknownHost);
+            System.out.println("");
+            System.out.println("###############################################");
+            System.out.println("#                                             #");
+            System.out.println("#            Provided unknown host!           #");
+            System.out.println("#        START AGAIN the installation!        #");
+            System.out.println("#                                             #");
+            System.out.println("###############################################");
+            System.out.println("");
+        } else if (ex.getCause() instanceof ConnectException) {
+            System.out.println("");
+            System.out.println("Provided address :" + SyncopeServices.getAddress());
+            System.out.println("");
+            System.out.println("###############################################");
+            System.out.println("#                                             #");
+            System.out.println("#       Provided address is unreachable!      #");
+            System.out.println("#         Check it and if it is wrong         #");
+            System.out.println("#        START AGAIN the installation!        #");
+            System.out.println("#                                             #");
+            System.out.println("###############################################");
+            System.out.println("");
+        }
+    }
+
+    public void manageException(final Exception e) {
+        if (e.getMessage().contains("not authenticated")) {
+            System.out.println("");
+            System.out.println("###############################################");
+            System.out.println("#                                             #");
+            System.out.println("#   Username or password provided are wrong   #");
+            System.out.println("#        START AGAIN the installation!        #");
+            System.out.println("#                                             #");
+            System.out.println("###############################################");
+            System.out.println("");
+        } else {
+            System.out.println("");
+            System.out.println("###############################################");
+            System.out.println("#                                             #");
+            System.out.println("#                Something wrong              #");
+            System.out.println("#        START AGAIN the installation!        #");
+            System.out.println("#                                             #");
+            System.out.println("###############################################");
+            System.out.println("");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/4f543e8c/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java
new file mode 100644
index 0000000..2a4079e
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java
@@ -0,0 +1,161 @@
+package org.apache.syncope.client.cli.commands.install;
+
+import java.io.FileNotFoundException;
+import java.io.UnsupportedEncodingException;
+import java.util.Scanner;
+import javax.ws.rs.ProcessingException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.cli.SyncopeServices;
+import org.apache.syncope.client.cli.util.FileSystemUtils;
+import org.apache.syncope.client.cli.util.JasyptUtils;
+import org.apache.syncope.common.rest.api.service.SyncopeService;
+
+public class InstallSetup {
+
+    private final InstallResultManager installResultManager = new InstallResultManager();
+
+    private String syncopeAdminUser;
+
+    private String syncopeAdminPassword;
+
+    private String syncopeServerSchema;
+
+    private String syncopeServerHostname = "localhost";
+
+    private String syncopeServerPort = "8080";
+
+    private String syncopeServerRestContext = "/syncope/rest/";
+
+    public void setup() {
+        final Scanner scanIn = new Scanner(System.in);
+
+        System.out.println("");
+        System.out.println("###############################################");
+        System.out.println("#                                             #");
+        System.out.println("# Welcome to Syncope CLI installation process #");
+        System.out.println("#                                             #");
+        System.out.println("###############################################");
+        System.out.println("");
+
+        System.out.println("Path to config files of Syncope CLI client will be: "
+                + InstallConfigFileTemplate.DIR_PATH);
+
+        if (!FileSystemUtils.canWrite(InstallConfigFileTemplate.DIR_PATH)) {
+            System.out.println("Permission denied on " + InstallConfigFileTemplate.DIR_PATH);
+        }
+        System.out.println("- File system permission checked");
+        System.out.println("");
+
+        System.out.println("Syncope server schema [http/https]:");
+        String syncopeServerSchemaFromSystemIn = scanIn.nextLine();
+        boolean schemaFounded = false;
+        while (!schemaFounded) {
+            if (("http".equalsIgnoreCase(syncopeServerSchemaFromSystemIn))
+                    || ("https".equalsIgnoreCase(syncopeServerSchemaFromSystemIn))) {
+                syncopeServerSchema = syncopeServerSchemaFromSystemIn;
+                schemaFounded = true;
+            } else {
+                System.out.println("Please use one of below values:");
+                System.out.println("   - http");
+                System.out.println("   - https");
+                syncopeServerSchemaFromSystemIn = scanIn.nextLine();
+            }
+        }
+
+        System.out.println("Syncope server hostname [e.g. " + syncopeServerHostname + "]:");
+        String syncopeServerHostnameFromSystemIn = scanIn.nextLine();
+        boolean syncopeServerHostnameFounded = false;
+        while (!syncopeServerHostnameFounded) {
+            if (StringUtils.isNotBlank(syncopeServerHostnameFromSystemIn)) {
+                syncopeServerHostname = syncopeServerHostnameFromSystemIn;
+                syncopeServerHostnameFounded = true;
+            } else {
+                System.out.println("Syncope server hostname [e.g. " + syncopeServerHostname + "]:");
+                syncopeServerHostnameFromSystemIn = scanIn.nextLine();
+            }
+        }
+
+        System.out.println("Syncope server port [e.g. " + syncopeServerPort + "]:");
+        String syncopeServerPortFromSystemIn = scanIn.nextLine();
+        boolean syncopeServerPortFounded = false;
+        while (!syncopeServerPortFounded) {
+            if (StringUtils.isNotBlank(syncopeServerPortFromSystemIn)) {
+                syncopeServerPort = syncopeServerPortFromSystemIn;
+                syncopeServerPortFounded = true;
+            } else if (!StringUtils.isNumeric(syncopeServerPortFromSystemIn)) {
+                System.out.println(syncopeServerPortFromSystemIn + " is not a numeric string, try again");
+                syncopeServerPortFromSystemIn = scanIn.nextLine();
+            } else {
+                System.out.println("Syncope server port [e.g. " + syncopeServerPort + "]:");
+                syncopeServerPortFromSystemIn = scanIn.nextLine();
+            }
+        }
+
+        System.out.println("Syncope server rest context [e.g. " + syncopeServerRestContext + "]:");
+        String syncopeServerRestContextFromSystemIn = scanIn.nextLine();
+        boolean syncopeServerRestContextFounded = false;
+        while (!syncopeServerRestContextFounded) {
+            if (StringUtils.isNotBlank(syncopeServerRestContextFromSystemIn)) {
+                syncopeServerRestContext = syncopeServerRestContextFromSystemIn;
+                syncopeServerRestContextFounded = true;
+            } else {
+                System.out.println("Syncope server port [e.g. " + syncopeServerRestContext + "]:");
+                syncopeServerRestContextFromSystemIn = scanIn.nextLine();
+            }
+        }
+
+        System.out.println("Syncope admin user:");
+        String syncopeAdminUserFromSystemIn = scanIn.nextLine();
+        boolean syncopeAdminUserFounded = false;
+        while (!syncopeAdminUserFounded) {
+            if (StringUtils.isNotBlank(syncopeAdminUserFromSystemIn)) {
+                syncopeAdminUser = syncopeAdminUserFromSystemIn;
+                syncopeAdminUserFounded = true;
+            } else {
+                System.out.println("Syncope admin user:");
+                syncopeAdminUserFromSystemIn = scanIn.nextLine();
+            }
+        }
+
+        System.out.println("Syncope admin password:");
+        String syncopeAdminPasswordFromSystemIn = scanIn.nextLine();
+        boolean syncopeAdminPasswordFounded = false;
+        while (!syncopeAdminPasswordFounded) {
+            if (StringUtils.isNotBlank(syncopeAdminPasswordFromSystemIn)) {
+                syncopeAdminPassword = syncopeAdminPasswordFromSystemIn;
+                syncopeAdminPasswordFounded = true;
+            } else {
+                System.out.println("Syncope admin user:");
+                syncopeAdminPasswordFromSystemIn = scanIn.nextLine();
+            }
+        }
+
+        scanIn.close();
+
+        final JasyptUtils jasyptUtils = JasyptUtils.getJasyptUtils();
+
+        try {
+            FileSystemUtils.createNewDirectory(InstallConfigFileTemplate.DIR_PATH);
+            final String contentCliPropertiesFile = InstallConfigFileTemplate.createFile(
+                    syncopeServerSchema,
+                    syncopeServerHostname,
+                    syncopeServerPort,
+                    syncopeServerRestContext,
+                    syncopeAdminUser,
+                    jasyptUtils.encrypt(syncopeAdminPassword));
+            FileSystemUtils.createFileWith(InstallConfigFileTemplate.FILE_PATH, contentCliPropertiesFile);
+
+        } catch (final FileNotFoundException | UnsupportedEncodingException ex) {
+            System.out.println(ex.getMessage());
+        }
+
+        try {
+            final SyncopeService syncopeService = SyncopeServices.get(SyncopeService.class);
+            installResultManager.installationSuccessful(syncopeService.info().getVersion());
+        } catch (final ProcessingException ex) {
+            installResultManager.manageProcessingException(ex);
+        } catch (final Exception e) {
+            installResultManager.manageException(e);
+        }
+    }
+}