From 7ad4f4390386efb991a50890b2a6c89bdb8bca52 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Mon, 11 Feb 2013 10:08:21 +0000
Subject: [PATCH] SP-281, BIS-193: handle enabling/disabling pathinfo_db

SVN: 28326
---
 installation/resource/installer/install.xml   |  1 +
 .../resource/installer/userInputSpec.xml      | 11 +++-
 .../izpack/ExecuteSetupScriptsAction.java     | 33 +++++++++++
 .../izpack/GlobalInstallationContext.java     |  2 +
 .../izpack/OpenGettingStartedPageAction.java  |  3 +-
 .../izpack/SetDatabasesToBackupAction.java    | 27 ++++++---
 .../izpack/SetPathinfoDBCheckBoxAction.java   | 52 +++++++++++++++++
 .../cisd/openbis/installer/izpack/Utils.java  | 51 +++++++++++++++++
 .../izpack/ExecuteSetupScriptsActionTest.java | 56 ++++++++++++++++++-
 9 files changed, 222 insertions(+), 14 deletions(-)
 create mode 100644 installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetPathinfoDBCheckBoxAction.java

diff --git a/installation/resource/installer/install.xml b/installation/resource/installer/install.xml
index 18b5ea84b7e..0e98f4228a7 100644
--- a/installation/resource/installer/install.xml
+++ b/installation/resource/installer/install.xml
@@ -128,6 +128,7 @@
     <panel classname="com.izforge.izpack.panels.userinput.UserInputPanel" id="UserInputPanel.TECHNOLOGIES">
       <actions>
         <action stage="preactivate" classname="ch.systemsx.cisd.openbis.installer.izpack.SetTechnologyCheckBoxesAction" />
+        <action stage="preactivate" classname="ch.systemsx.cisd.openbis.installer.izpack.SetPathinfoDBCheckBoxAction" />
         <action stage="postvalidate" classname="ch.systemsx.cisd.openbis.installer.izpack.SetEnableTechnologiesVariableAction" />
       </actions>
     </panel>
diff --git a/installation/resource/installer/userInputSpec.xml b/installation/resource/installer/userInputSpec.xml
index 0727dae61c8..7c1768e2357 100644
--- a/installation/resource/installer/userInputSpec.xml
+++ b/installation/resource/installer/userInputSpec.xml
@@ -47,12 +47,10 @@
         <param name="pattern" value="^.+$" />
       </validator>
     </field>
-    
-    
   </panel>
 
   <panel id="UserInputPanel.TECHNOLOGIES">
-    <field type="title" txt="Technologies" bold="true" size="2" />
+    <field type="title" txt="Technologies and Fast File Browsing" bold="true" size="2" />
     <field type="staticText" align="left"
       txt="Please, deselect those technologies which are not needed. Later, at the next upgrade, the selection can be changed:" />
     <field type="check" variable="PROTEOMICS">
@@ -64,6 +62,13 @@
     <field type="check" variable="ILLUMINA-NGS">
       <spec txt="Illumina NGS (ETH BSSE Setup)" true="true" false="false"/>
     </field>
+    
+    <field type="space"/>
+    <field type="staticText" align="left"
+      txt="Please, select or deselect fast data set file browsing. This feature improves file browsing of data sets with a large number of files." />
+    <field type="check" variable="PATHINFO_DB_ENABLED">
+      <spec txt="Fast data set file browsing (recommended, especially for screening)" true="true" false="false"/>
+    </field>
   </panel>
 
   <panel id="UserInputPanel.MISC">
diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/ExecuteSetupScriptsAction.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/ExecuteSetupScriptsAction.java
index 6882c8d5214..3eea038137e 100644
--- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/ExecuteSetupScriptsAction.java
+++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/ExecuteSetupScriptsAction.java
@@ -42,6 +42,13 @@ import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
  */
 public class ExecuteSetupScriptsAction extends AbstractScriptExecutor implements PanelAction
 {
+    static final String DATA_SOURCES_KEY = "data-sources";
+    static final String PATHINFO_DB_DATA_SOURCE = "path-info-db";
+    static final String POST_REGISTRATION_TASKS_KEY = "post-registration.post-registration-tasks";
+    static final String PATHINFO_DB_FEEDING_TASK = "pathinfo-feeding";
+    static final String MAINTENANCE_PLUGINS_KEY = "maintenance-plugins";
+    static final String PATHINFO_DB_DELETION_TASK = "path-info-deletion";
+
     /**
      * executed for first time installations.
      */
@@ -71,6 +78,9 @@ public class ExecuteSetupScriptsAction extends AbstractScriptExecutor implements
         File installDir = GlobalInstallationContext.installDir;
         try
         {
+            enablePathinfoDB(
+                    "true".equals(data.getVariable(GlobalInstallationContext.PATHINFO_DB_ENABLED)),
+                    installDir);
             installKeyStore(keyStoreFileName, installDir);
             injectPasswords(keyStorePassword, certificatePassword, installDir);
         } catch (Exception ex)
@@ -99,6 +109,29 @@ public class ExecuteSetupScriptsAction extends AbstractScriptExecutor implements
             }
         }
     }
+    
+    void enablePathinfoDB(boolean enableFlag, File installDir)
+    {
+        File dssServicePropertiesFile =
+                new File(installDir, Utils.DSS_PATH + Utils.SERVICE_PROPERTIES_PATH);
+        if (enableFlag)
+        {
+            Utils.addTermToPropertyList(dssServicePropertiesFile, DATA_SOURCES_KEY,
+                    PATHINFO_DB_DATA_SOURCE);
+            Utils.addTermToPropertyList(dssServicePropertiesFile, POST_REGISTRATION_TASKS_KEY,
+                    PATHINFO_DB_FEEDING_TASK);
+            Utils.addTermToPropertyList(dssServicePropertiesFile, MAINTENANCE_PLUGINS_KEY,
+                    PATHINFO_DB_DELETION_TASK);
+        } else
+        {
+            Utils.removeTermFromPropertyList(dssServicePropertiesFile, DATA_SOURCES_KEY,
+                    PATHINFO_DB_DATA_SOURCE);
+            Utils.removeTermFromPropertyList(dssServicePropertiesFile, POST_REGISTRATION_TASKS_KEY,
+                    PATHINFO_DB_FEEDING_TASK);
+            Utils.removeTermFromPropertyList(dssServicePropertiesFile, MAINTENANCE_PLUGINS_KEY,
+                    PATHINFO_DB_DELETION_TASK);
+        }
+    }
 
     void injectPasswords(String keyStorePassword, String keyPassword, File installDir)
     {
diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/GlobalInstallationContext.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/GlobalInstallationContext.java
index 9084c7d071f..c304ee5b3dd 100644
--- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/GlobalInstallationContext.java
+++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/GlobalInstallationContext.java
@@ -50,6 +50,8 @@ public class GlobalInstallationContext
     
     public static final String TECHNOLOGY_ILLUMINA_NGS = "ILLUMINA-NGS";
     
+    public static final String PATHINFO_DB_ENABLED = "PATHINFO_DB_ENABLED";
+    
     public static final String[] TECHNOLOGIES =
         { TECHNOLOGY_PROTEOMICS, TECHNOLOGY_SCREENING, TECHNOLOGY_ILLUMINA_NGS };
     
diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/OpenGettingStartedPageAction.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/OpenGettingStartedPageAction.java
index 40f1e356415..3013720d2c5 100644
--- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/OpenGettingStartedPageAction.java
+++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/OpenGettingStartedPageAction.java
@@ -41,7 +41,8 @@ public class OpenGettingStartedPageAction implements PanelAction
     @Override
     public synchronized void executeAction(AutomatedInstallData data, AbstractUIHandler arg1)
     {
-        if (GlobalInstallationContext.isUpdateInstallation || data.isInstallSuccess() == false)
+        if (GlobalInstallationContext.isUpdateInstallation || data.isInstallSuccess() == false
+                || Utils.isASInstalled(GlobalInstallationContext.installDir) == false)
         {
             return;
         }
diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetDatabasesToBackupAction.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetDatabasesToBackupAction.java
index c606dad3c92..0a5fc5a128f 100644
--- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetDatabasesToBackupAction.java
+++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetDatabasesToBackupAction.java
@@ -37,7 +37,6 @@ public class SetDatabasesToBackupAction extends AbstractScriptExecutor implement
 {
     private static final String HELPER_CLASS =
             "ch.systemsx.cisd.openbis.dss.generic.server.dbbackup.BackupDatabaseDescriptionGenerator";
-    
 
     static final String DATABASES_TO_BACKUP_VARNAME = "DATABASES_TO_BACKUP";
 
@@ -52,7 +51,7 @@ public class SetDatabasesToBackupAction extends AbstractScriptExecutor implement
     {
         try
         {
-            String descriptions = extractDescriptions();
+            String descriptions = extractDescriptions().trim();
             String databases = extractDatabases(data, descriptions);
             data.setVariable(DATABASES_TO_BACKUP_VARNAME, databases);
             return;
@@ -62,21 +61,30 @@ public class SetDatabasesToBackupAction extends AbstractScriptExecutor implement
             handler.emitError("Exception", ex.toString());
         }
     }
-    
+
     private String extractDatabases(AutomatedInstallData data, String descriptions)
     {
         CommaSeparatedListBuilder builder = new CommaSeparatedListBuilder();
-        for (String description : descriptions.split("\n"))
+        if (descriptions.length() > 0)
         {
-            String database = description.split(";")[0].split("=")[1].trim();
-            if (databaseExists(data, database))
+            for (String description : descriptions.split("\n"))
             {
-                builder.append(database);
+                String[] splitted = description.split(";")[0].split("=");
+                if (splitted.length < 2)
+                {
+                    throw new IllegalArgumentException("Invalid database description: "
+                            + description);
+                }
+                String database = splitted[1].trim();
+                if (databaseExists(data, database))
+                {
+                    builder.append(database);
+                }
             }
         }
         return builder.toString();
     }
-    
+
     private boolean databaseExists(AutomatedInstallData data, String database)
     {
         File scriptFile = getAdminScriptFile(data, "database-existence-check.sh");
@@ -87,7 +95,7 @@ public class SetDatabasesToBackupAction extends AbstractScriptExecutor implement
         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         executeAdminScript(null, outputStream, outputStream, scriptFile.getAbsolutePath(), database);
         return outputStream.toString().trim().equals("FALSE") == false;
-        
+
     }
 
     private String extractDescriptions() throws Exception
@@ -109,6 +117,7 @@ public class SetDatabasesToBackupAction extends AbstractScriptExecutor implement
         }
         paths.add(new File(GlobalInstallationContext.installDir, Utils.DSS_PATH
                 + Utils.SERVICE_PROPERTIES_PATH).getAbsolutePath());
+        System.out.println("Scan following properties file for data source definitions: " + paths);
         return new Object[]
             { paths.toArray(new String[0]) };
     }
diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetPathinfoDBCheckBoxAction.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetPathinfoDBCheckBoxAction.java
new file mode 100644
index 00000000000..7c99a18258d
--- /dev/null
+++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetPathinfoDBCheckBoxAction.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2013 ETH Zuerich, CISD
+ *
+ * Licensed 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 ch.systemsx.cisd.openbis.installer.izpack;
+
+import com.izforge.izpack.api.data.AutomatedInstallData;
+import com.izforge.izpack.api.data.PanelActionConfiguration;
+import com.izforge.izpack.api.handler.AbstractUIHandler;
+import com.izforge.izpack.data.PanelAction;
+
+/**
+ * Action which sets the boolean variable PATHINFO_DB_ENABLED
+ * 
+ * @author Franz-Josef Elmer
+ */
+public class SetPathinfoDBCheckBoxAction implements PanelAction
+{
+    @Override
+    public void initialize(PanelActionConfiguration configuration)
+    {
+    }
+
+    @Override
+    public void executeAction(AutomatedInstallData data, AbstractUIHandler handler)
+    {
+        boolean pathinfoDBEnabled = true;
+        String dataSources =
+                Utils.tryToGetServicePropertyOfDSS(GlobalInstallationContext.installDir,
+                        ExecuteSetupScriptsAction.DATA_SOURCES_KEY);
+        if (dataSources != null)
+        {
+            pathinfoDBEnabled =
+                    dataSources.contains(ExecuteSetupScriptsAction.PATHINFO_DB_DATA_SOURCE);
+        }
+        data.setVariable(GlobalInstallationContext.PATHINFO_DB_ENABLED,
+                Boolean.toString(pathinfoDBEnabled));
+    }
+
+}
diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/Utils.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/Utils.java
index e292770df69..2539027b970 100644
--- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/Utils.java
+++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/Utils.java
@@ -31,6 +31,7 @@ import java.util.Properties;
 import org.apache.commons.io.IOUtils;
 
 import ch.systemsx.cisd.common.filesystem.FileUtilities;
+import ch.systemsx.cisd.common.shared.basic.string.CommaSeparatedListBuilder;
 
 /**
  * Utility functions for exploring <code>service.properties</code> files of an installation.
@@ -213,7 +214,57 @@ class Utils
             appendEntryToConfigFile(configFile, propertiesEntry);
         }
     }
+    
+    static void addTermToPropertyList(File configFile, String propertyKey, String newTerm)
+    {
+        Properties properties = tryToGetProperties(configFile);
+        if (properties == null)
+        {
+            return;
+        }
+        String property = properties.getProperty(propertyKey);
+        CommaSeparatedListBuilder builder = new CommaSeparatedListBuilder();
+        if (property != null)
+        {
+            String[] terms = property.split(",");
+            for (String term : terms)
+            {
+                String trimmedTerm = term.trim();
+                if (trimmedTerm.equals(newTerm))
+                {
+                    return;
+                }
+                builder.append(trimmedTerm);
+            }
+        }
+        builder.append(newTerm);
+        updateOrAppendProperty(configFile, propertyKey, builder.toString());
+    }
 
+    static void removeTermFromPropertyList(File configFile, String propertyKey, String termToRemove)
+    {
+        Properties properties = tryToGetProperties(configFile);
+        if (properties == null)
+        {
+            return;
+        }
+        String property = properties.getProperty(propertyKey);
+        CommaSeparatedListBuilder builder = new CommaSeparatedListBuilder();
+        if (property != null)
+        {
+            String[] terms = property.split(",");
+            for (String term : terms)
+            {
+                String trimmedTerm = term.trim();
+                if (trimmedTerm.equals(termToRemove) == false)
+                {
+                    builder.append(trimmedTerm);
+                }
+            }
+        }
+        updateOrAppendProperty(configFile, propertyKey, builder.toString());
+    }
+    
     static File getKeystoreFileForDSS(File installDir)
     {
         return new File(installDir, DSS_PATH + KEYSTORE_PATH);
diff --git a/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/ExecuteSetupScriptsActionTest.java b/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/ExecuteSetupScriptsActionTest.java
index 9ae9b63ba89..b10ddca7098 100644
--- a/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/ExecuteSetupScriptsActionTest.java
+++ b/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/ExecuteSetupScriptsActionTest.java
@@ -51,7 +51,7 @@ public class ExecuteSetupScriptsActionTest extends AbstractFileSystemTestCase
         dssServicePropertiesFile =
                 new File(workingDirectory, Utils.DSS_PATH + Utils.SERVICE_PROPERTIES_PATH);
         jettyXMLFile = new File(workingDirectory, Utils.AS_PATH + Utils.JETTY_XML_PATH);
-        FileUtils.copyFile(new File("../datastore_server/dist/etc/service.properties/"),
+        FileUtils.copyFile(new File("../openbis_standard_technologies/dist/etc/service.properties/"),
                 dssServicePropertiesFile);
         FileUtils.copyFile(new File("../openbis/dist/server/jetty.xml/"), jettyXMLFile);
 
@@ -82,6 +82,60 @@ public class ExecuteSetupScriptsActionTest extends AbstractFileSystemTestCase
         assertEquals("my-keys", FileUtils.readFileToString(keystoreFileDSS));
     }
     
+    @Test
+    public void testDisableAndEnablePathinfoDB() throws Exception
+    {
+        Properties properties = loadProperties(dssServicePropertiesFile);
+        assertEquals(ExecuteSetupScriptsAction.PATHINFO_DB_DATA_SOURCE,
+                properties.getProperty(ExecuteSetupScriptsAction.DATA_SOURCES_KEY));
+        assertEquals(ExecuteSetupScriptsAction.PATHINFO_DB_FEEDING_TASK,
+                properties.getProperty(ExecuteSetupScriptsAction.POST_REGISTRATION_TASKS_KEY));
+        assertEquals("post-registration, " + ExecuteSetupScriptsAction.PATHINFO_DB_DELETION_TASK,
+                properties.getProperty(ExecuteSetupScriptsAction.MAINTENANCE_PLUGINS_KEY));
+        
+        action.enablePathinfoDB(false, workingDirectory);
+
+        properties = loadProperties(dssServicePropertiesFile);
+        assertEquals("",
+                properties.getProperty(ExecuteSetupScriptsAction.DATA_SOURCES_KEY));
+        assertEquals("",
+                properties.getProperty(ExecuteSetupScriptsAction.POST_REGISTRATION_TASKS_KEY));
+        assertEquals("post-registration",
+                properties.getProperty(ExecuteSetupScriptsAction.MAINTENANCE_PLUGINS_KEY));
+        
+        action.enablePathinfoDB(true, workingDirectory);
+        
+        properties = loadProperties(dssServicePropertiesFile);
+        assertEquals(ExecuteSetupScriptsAction.PATHINFO_DB_DATA_SOURCE,
+                properties.getProperty(ExecuteSetupScriptsAction.DATA_SOURCES_KEY));
+        assertEquals(ExecuteSetupScriptsAction.PATHINFO_DB_FEEDING_TASK,
+                properties.getProperty(ExecuteSetupScriptsAction.POST_REGISTRATION_TASKS_KEY));
+        assertEquals("post-registration, " + ExecuteSetupScriptsAction.PATHINFO_DB_DELETION_TASK,
+                properties.getProperty(ExecuteSetupScriptsAction.MAINTENANCE_PLUGINS_KEY));
+}
+    
+    @Test
+    public void testEnableAlreadyEnabledPathinfoDB() throws Exception
+    {
+        Properties properties = loadProperties(dssServicePropertiesFile);
+        assertEquals(ExecuteSetupScriptsAction.PATHINFO_DB_DATA_SOURCE,
+                properties.getProperty(ExecuteSetupScriptsAction.DATA_SOURCES_KEY));
+        assertEquals(ExecuteSetupScriptsAction.PATHINFO_DB_FEEDING_TASK,
+                properties.getProperty(ExecuteSetupScriptsAction.POST_REGISTRATION_TASKS_KEY));
+        assertEquals("post-registration, " + ExecuteSetupScriptsAction.PATHINFO_DB_DELETION_TASK,
+                properties.getProperty(ExecuteSetupScriptsAction.MAINTENANCE_PLUGINS_KEY));
+        
+        action.enablePathinfoDB(true, workingDirectory);
+        
+        properties = loadProperties(dssServicePropertiesFile);
+        assertEquals(ExecuteSetupScriptsAction.PATHINFO_DB_DATA_SOURCE,
+                properties.getProperty(ExecuteSetupScriptsAction.DATA_SOURCES_KEY));
+        assertEquals(ExecuteSetupScriptsAction.PATHINFO_DB_FEEDING_TASK,
+                properties.getProperty(ExecuteSetupScriptsAction.POST_REGISTRATION_TASKS_KEY));
+        assertEquals("post-registration, " + ExecuteSetupScriptsAction.PATHINFO_DB_DELETION_TASK,
+                properties.getProperty(ExecuteSetupScriptsAction.MAINTENANCE_PLUGINS_KEY));
+    }
+    
     @Test
     public void testInjectPasswords() throws Exception
     {
-- 
GitLab