diff --git a/installation/resource/installer/install.xml b/installation/resource/installer/install.xml index 2435d9661e7cb98280131ea7bfca1556a9050a02..d2799fef5b432c12888f46fe40d110ef911f9ab2 100644 --- a/installation/resource/installer/install.xml +++ b/installation/resource/installer/install.xml @@ -99,6 +99,10 @@ <validator classname="ch.systemsx.cisd.openbis.installer.izpack.DBConnectionValidator"/> </panel> + <panel classname="com.izforge.izpack.panels.userinput.UserInputPanel" id="UserInputPanel.DB_CHECK" condition="isUpdateInstallation"> + <validator classname="ch.systemsx.cisd.openbis.installer.izpack.DBConnectionValidator"/> + </panel> + <panel classname="com.izforge.izpack.panels.userinput.UserInputPanel" id="UserInputPanel.PSQL_PATH" condition="noPsqlToolsOnPath"> <validator classname="ch.systemsx.cisd.openbis.installer.izpack.PostgresToolsPathValidator"/> </panel> diff --git a/installation/resource/installer/userInputSpec.xml b/installation/resource/installer/userInputSpec.xml index 93d0ee4d6d3f65ee80720e1b18039b821ec05dbf..716e09525f1f7f05eb26105c3d34d590e0749948 100644 --- a/installation/resource/installer/userInputSpec.xml +++ b/installation/resource/installer/userInputSpec.xml @@ -1,4 +1,10 @@ <userInput> + <panel id="UserInputPanel.DB_CHECK"> + <field type="staticText" align="left" + txt="Click on 'Next' to perform the check for the owner and the admin user specified in service.properties." /> + <field type="title" txt="Database access check" bold="true" size="2" /> + </panel> + <panel id="UserInputPanel.PSQL_PATH"> <field type="staticText" align="left" txt="The openBIS installation process requires access to the PostreSQL command line tools 'psql' and 'pg_dump'. Please specify their location:" /> diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java index f934d5347668b24f6d8feb66623a58e3d4907e49..06cfd6b6bd4f6b876e851344685d8ab2c4915ad4 100644 --- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java +++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/DBConnectionValidator.java @@ -71,14 +71,78 @@ public class DBConnectionValidator implements DataValidator @Override public Status validateData(AutomatedInstallData data) { - if (testConnectionOK(POSTGRES_USER, NO_PASSWORD)) + String admin = getAdmin(); + String adminPassword = getAdminPassword(); + String owner = getOwner(); + String ownerPassword = getOwnerPassword(); + if (testConnectionOK(admin, adminPassword, "admin user") == false) { - return Status.OK; + return Status.ERROR; } - return Status.ERROR; + if (testConnectionOK(owner, ownerPassword, "owner") == false) + { + return Status.ERROR; + } + return Status.OK; } - private boolean testConnectionOK(String username, String password) + private String getOwner() + { + String user = System.getProperty("user.name").toLowerCase(); + if (GlobalInstallationContext.isFirstTimeInstallation) + { + return user; + } + String owner = + Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir, + "database.owner"); + if (owner != null && owner.length() > 0) + { + return owner; + } + return user; + } + + private String getOwnerPassword() + { + if (GlobalInstallationContext.isFirstTimeInstallation) + { + return NO_PASSWORD; + } + String password = + Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir, + "database.owner-password"); + return password == null ? "" : password; + } + + private String getAdmin() + { + String defaultAdmin = POSTGRES_USER; + if (GlobalInstallationContext.isFirstTimeInstallation) + { + return defaultAdmin; + } + String admin = + Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir, + "database.admin-user"); + if (admin != null && admin.length() > 0) + { + return admin; + } + return defaultAdmin; + } + + private String getAdminPassword() + { + if (GlobalInstallationContext.isFirstTimeInstallation) + { + return NO_PASSWORD; + } + return Utils.tryToGetServicePropertyOfAS(GlobalInstallationContext.installDir, + "database.admin-password"); + } + + private boolean testConnectionOK(String username, String password, String messagePostfix) { boolean connected = false; try @@ -93,12 +157,18 @@ public class DBConnectionValidator implements DataValidator } } catch (ClassNotFoundException cnfe) { - errorMessage = cnfe.getMessage(); + errorMessage = createMessage(cnfe, messagePostfix); } catch (SQLException e) { - errorMessage = e.getMessage(); + errorMessage = createMessage(e, messagePostfix); } return connected; } + + private String createMessage(Exception exception, String messagePostfix) + { + return exception.getMessage() + ".\nThe error is probably caused by an illconfigured " + + messagePostfix + "."; + } }