From 58821a211f38cf48a75a9cbc36b472d95b035ce2 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Tue, 05 May 2015 15:26:43 +0000
Subject: [PATCH] OPENDJ-1932 OPENDJ-1933 (CR-6839) New Backend in UI

---
 opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java      |  214 ++++++++++
 opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java                |  131 ------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java |  789 +++++++++++++++++-------------------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java    |   40 +
 opendj-server-legacy/src/main/java/org/opends/server/tools/BackendTypeHelper.java          |   62 +-
 opendj-server-legacy/src/messages/org/opends/messages/admin_tool.properties                |    4 
 6 files changed, 660 insertions(+), 580 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
index 7c5bbe6..adcfde5 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
@@ -28,7 +28,6 @@
 package org.opends.guitools.controlpanel.ui;
 
 import static org.opends.messages.AdminToolMessages.*;
-import static org.opends.messages.ConfigMessages.*;
 import static org.opends.messages.QuickSetupMessages.*;
 
 import java.awt.Component;
@@ -38,12 +37,11 @@
 import java.awt.event.ItemListener;
 import java.io.File;
 import java.io.IOException;
-import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -51,16 +49,13 @@
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.ldap.InitialLdapContext;
 import javax.swing.AbstractButton;
 import javax.swing.Box;
 import javax.swing.ButtonGroup;
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
+import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
@@ -72,11 +67,12 @@
 import javax.swing.event.DocumentListener;
 
 import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.config.server.ConfigException;
-import org.forgerock.opendj.ldap.ByteString;
+import org.forgerock.opendj.adapter.server3x.Converters;
+import org.forgerock.opendj.config.LDAPProfile;
 import org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
 import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
+import org.opends.guitools.controlpanel.datamodel.IndexTypeDescriptor;
 import org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
 import org.opends.guitools.controlpanel.event.BrowseActionListener;
 import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
@@ -89,26 +85,31 @@
 import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.installer.InstallerHelper;
 import org.opends.quicksetup.util.Utils;
-import org.opends.server.admin.client.ManagementContext;
+import org.opends.server.admin.AdminException;
 import org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
 import org.opends.server.admin.client.ldap.LDAPManagementContext;
+import org.opends.server.admin.std.client.BackendCfgClient;
+import org.opends.server.admin.std.client.BackendIndexCfgClient;
 import org.opends.server.admin.std.client.LocalDBBackendCfgClient;
+import org.opends.server.admin.std.client.LocalDBIndexCfgClient;
+import org.opends.server.admin.std.client.PluggableBackendCfgClient;
 import org.opends.server.admin.std.client.RootCfgClient;
 import org.opends.server.admin.std.meta.BackendCfgDefn;
-import org.opends.server.admin.std.meta.LocalDBBackendCfgDefn;
-import org.opends.server.config.ConfigConstants;
-import org.opends.server.config.ConfigEntry;
-import org.opends.server.config.DNConfigAttribute;
+import org.opends.server.admin.std.meta.BackendIndexCfgDefn;
+import org.opends.server.admin.std.meta.BackendIndexCfgDefn.IndexType;
+import org.opends.server.admin.std.meta.LocalDBIndexCfgDefn;
+import org.opends.server.backends.jeb.RemoveOnceLocalDBBackendIsPluggable;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.extensions.ConfigFileHandler;
+import org.opends.server.tools.BackendCreationHelper;
+import org.opends.server.tools.BackendCreationHelper.DefaultIndex;
+import org.opends.server.tools.BackendTypeHelper;
+import org.opends.server.tools.BackendTypeHelper.BackendTypeUIAdapter;
 import org.opends.server.tools.ImportLDIF;
 import org.opends.server.tools.LDAPModify;
 import org.opends.server.tools.makeldif.MakeLDIF;
 import org.opends.server.types.DN;
-import org.opends.server.types.Entry;
-import org.opends.server.types.LDIFImportConfig;
 import org.opends.server.types.OpenDsException;
-import org.opends.server.util.LDIFReader;
 import org.opends.server.util.SetupUtils;
 
 import com.forgerock.opendj.cli.CommandBuilder;
@@ -124,6 +125,7 @@
   private static final LocalizableMessage NEW_BACKEND_TEXT = INFO_CTRL_PANEL_NEW_BACKEND_LABEL.get();
 
   private JComboBox<?> backends;
+  private JComboBox<BackendTypeUIAdapter> backendTypes;
   private JTextField newBackend;
   private JTextField baseDN;
   private JRadioButton onlyCreateBaseEntry;
@@ -140,6 +142,7 @@
   private JLabel lPath;
   private JLabel lNumberOfEntries;
   private JLabel lDirectoryData;
+  private JLabel lNewBackendType;
 
   private DocumentListener documentListener;
 
@@ -182,6 +185,8 @@
     addBackendLabel(gbc);
     addBackendNamesComboBox(gbc);
     addNewBackendName(gbc);
+    addNewBackendTypeLabel(gbc);
+    addNewBackendTypeComboBox(gbc);
     addBaseDNLabel(gbc);
     addBaseDNTextField(gbc);
     addBaseDNInlineHelp(gbc);
@@ -220,22 +225,53 @@
     backends.addItemListener(new IgnoreItemListener(backends));
     gbc.gridwidth = 1;
     add(backends, gbc);
+  }
 
+  private void addNewBackendTypeLabel(GridBagConstraints gbc)
+  {
+    gbc.insets.top = 10;
+    gbc.gridx = 0;
+    gbc.gridy++;
+    gbc.insets.left = 0;
+    gbc.gridwidth = 1;
+    lNewBackendType = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_BASE_DN_NEW_BACKEND_TYPE_LABEL.get());
+    add(lNewBackendType, gbc);
+    addBackendNameChangeListener(lNewBackendType);
+  }
+
+  @SuppressWarnings("unchecked")
+  private void addNewBackendTypeComboBox(GridBagConstraints gbc)
+  {
+    gbc.insets.left = 10;
+    gbc.gridx = 1;
+    gbc.gridwidth = 1;
+    final BackendTypeHelper backendTypeHelper = new BackendTypeHelper();
+    backendTypes = Utilities.createComboBox();
+    backendTypes.setModel(new DefaultComboBoxModel<>(backendTypeHelper.getBackendTypeUIAdaptors()));
+    backendTypes.setRenderer(new CustomListCellRenderer(backendTypes));
+    backendTypes.addItemListener(new IgnoreItemListener(backendTypes));
+    add(backendTypes, gbc);
+    addBackendNameChangeListener(backendTypes);
   }
 
   private void addNewBackendName(GridBagConstraints gbc)
   {
-    newBackend = Utilities.createTextField();
-    newBackend.setColumns(25);
     gbc.gridx = 2;
+    newBackend = Utilities.createTextField();
+    newBackend.setColumns(18);
     add(newBackend, gbc);
+    addBackendNameChangeListener(newBackend);
+  }
+
+  private void addBackendNameChangeListener(final JComponent component)
+  {
     ItemListener comboListener = new ItemListener()
     {
       @Override
       public void itemStateChanged(ItemEvent ev)
       {
         Object o = backends.getSelectedItem();
-        newBackend.setEnabled(NEW_BACKEND_TEXT.equals(o));
+        component.setVisible(NEW_BACKEND_TEXT.equals(o));
       }
     };
     backends.addItemListener(comboListener);
@@ -675,6 +711,11 @@
     return null;
   }
 
+  private BackendTypeUIAdapter getSelectedBackendType()
+  {
+    return (BackendTypeUIAdapter) backendTypes.getSelectedItem();
+  }
+
   private boolean isNewBackend()
   {
     return NEW_BACKEND_TEXT.equals(backends.getSelectedItem());
@@ -838,113 +879,47 @@
       return args;
     }
 
-    private void updateConfiguration() throws OpenDsException, ConfigException
+    private void updateConfigurationOnline() throws OpenDsException
+    {
+      SwingUtilities.invokeLater(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          List<String> args = getObfuscatedCommandLineArguments(getDSConfigCommandLineArguments());
+          args.removeAll(getConfigCommandLineArguments());
+          printEquivalentCommandLine(
+              getConfigCommandLineFullPath(), args, INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_CREATE_BASE_DN.get());
+        }
+      });
+
+      performTask();
+      printTaskDone();
+      if (isNewBackend())
+      {
+        createAdditionalIndexes();
+      }
+      refreshProgressBar();
+    }
+
+    private void updateConfigurationOffline() throws OpenDsException
     {
       boolean configHandlerUpdated = false;
       try
       {
-        if (!isServerRunning())
+        getInfo().stopPooling();
+        if (getInfo().mustDeregisterConfig())
         {
-          getInfo().stopPooling();
-          if (getInfo().mustDeregisterConfig())
-          {
-            DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
-          }
-          DirectoryServer.getInstance().initializeConfiguration(
-              ConfigFileHandler.class.getName(), ConfigReader.configFile);
-          getInfo().setMustDeregisterConfig(true);
-          configHandlerUpdated = true;
+          DirectoryServer.deregisterBaseDN(DN.valueOf("cn=config"));
         }
-        else
-        {
-          SwingUtilities.invokeLater(new Runnable()
-          {
-            @Override
-            public void run()
-            {
-              List<String> args = getObfuscatedCommandLineArguments(getDSConfigCommandLineArguments());
-              args.removeAll(getConfigCommandLineArguments());
-              printEquivalentCommandLine(
-                  getConfigCommandLineFullPath(), args, INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_CREATE_BASE_DN.get());
-            }
-          });
-        }
+        DirectoryServer.getInstance().initializeConfiguration(
+            ConfigFileHandler.class.getName(), ConfigReader.configFile);
+        getInfo().setMustDeregisterConfig(true);
+        configHandlerUpdated = true;
 
-        if (isNewBackend())
-        {
-          SwingUtilities.invokeLater(new Runnable()
-          {
-            @Override
-            public void run()
-            {
-              LocalizableMessage msg = INFO_CTRL_PANEL_CREATING_BACKEND_PROGRESS.get(getBackendName(), newBaseDN);
-              getProgressDialog().appendProgressHtml(
-                  Utilities.getProgressWithPoints(msg, ColorAndFontConstants.progressFont));
-            }
-          });
-
-          if (isServerRunning())
-          {
-            createBackend(getInfo().getDirContext(), getBackendName(), newBaseDN);
-          }
-          else
-          {
-            copyLdifEntries(getBackendLdif(getBackendName()));
-            copyLdifEntries(getAdditionalIndexLdif(getBackendName()));
-          }
-        }
-        else
-        {
-          SwingUtilities.invokeLater(new Runnable()
-          {
-            @Override
-            public void run()
-            {
-              LocalizableMessage msg = INFO_CTRL_PANEL_CREATING_BASE_DN_PROGRESS.get(newBaseDN, getBackendName());
-              getProgressDialog().appendProgressHtml(
-                  Utilities.getProgressWithPoints(msg, ColorAndFontConstants.progressFont));
-            }
-          });
-
-          if (isServerRunning())
-          {
-            addBaseDN(getInfo().getDirContext(), getBackendName(), newBaseDN);
-          }
-          else
-          {
-            addBaseDN(getBackendName(), newBaseDN);
-          }
-        }
-
-        SwingUtilities.invokeLater(new Runnable()
-        {
-          @Override
-          public void run()
-          {
-            getProgressDialog().appendProgressHtml(
-                Utilities.getProgressDone(ColorAndFontConstants.progressFont) + "<br><br>");
-          }
-        });
-
-        if (isNewBackend() && isServerRunning())
-        {
-          // Create additional indexes and display the equivalent command.
-          // Everything is done in the method createAdditionalIndexes
-          createAdditionalIndexes(getInfo().getDirContext(), getBackendName());
-        }
-
-        if (progressAfterConfigurationUpdate > 0)
-        {
-          SwingUtilities.invokeLater(new Runnable()
-          {
-            @Override
-            public void run()
-            {
-              getProgressDialog().getProgressBar().setIndeterminate(false);
-              getProgressDialog().getProgressBar().setValue(progressAfterConfigurationUpdate);
-            }
-          });
-        }
+        performTask();
+        printTaskDone();
+        refreshProgressBar();
       }
       finally
       {
@@ -956,31 +931,280 @@
       }
     }
 
-    private void copyLdifEntries(final String ldif) throws OpenDsException
+    private void printCreateNewBackendProgress(final String backendName) throws OpenDsException
     {
-      LDIFImportConfig ldifImportConfig = null;
+      SwingUtilities.invokeLater(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          LocalizableMessage message = INFO_CTRL_PANEL_CREATING_BACKEND_PROGRESS.get(backendName, newBaseDN);
+          getProgressDialog().appendProgressHtml(
+              Utilities.getProgressWithPoints(message, ColorAndFontConstants.progressFont));
+        }
+      });
+    }
+
+    private void performTask() throws OpenDsException
+    {
+      final String backendName = getBackendName();
+      if (isNewBackend())
+      {
+        printCreateNewBackendProgress(backendName);
+        createBackend(backendName);
+      }
+      else
+      {
+        printCreateNewBaseDNProgress(backendName);
+        addNewBaseDN(backendName);
+      }
+    }
+
+    private void createBackend(String backendName) throws OpenDsException
+    {
+      if (!isServerRunning())
+      {
+        createBackendOffline(backendName);
+        return;
+      }
+
+      //FIXME GB This could be replaced by a call to BackendCreationHelper.createBackend(...)
+      // once the new configuration framework migration will be done
+      final RootCfgClient root = getRootConfigurationClient();
+      final BackendCfgClient backend =
+          root.createBackend(getSelectedBackendType().getOldConfigFrameworkBackend(), backendName, null);
+      backend.setEnabled(true);
+      backend.setBaseDN(Collections.singleton(DN.valueOf(newBaseDN)));
+      backend.setBackendId(backendName);
+      backend.setWritabilityMode(BackendCfgDefn.WritabilityMode.ENABLED);
+      backend.commit();
+    }
+
+    private void createBackendOffline(String backendName) throws OpenDsException
+    {
       try
       {
-        ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
-        LDIFReader reader = new LDIFReader(ldifImportConfig);
-        Entry indexEntry;
-        while ((indexEntry = reader.readEntry()) != null)
-        {
-          DirectoryServer.getConfigHandler().addEntry(indexEntry, null);
-        }
-        DirectoryServer.getConfigHandler().writeUpdatedConfig();
+        Set<org.forgerock.opendj.ldap.DN> baseDN = Collections.singleton(Converters.from(DN.valueOf(newBaseDN)));
+        BackendCreationHelper.createBackendOffline(backendName, baseDN, getSelectedBackendType().getBackend());
       }
-      catch (IOException ioe)
+      catch (Exception e)
       {
-        throw new OfflineUpdateException(ERR_CTRL_PANEL_ERROR_UPDATING_CONFIGURATION.get(ioe), ioe);
+        throw new OfflineUpdateException(ERROR_CTRL_PANEL_CREATE_NEW_BACKEND.get(backendName, e.getMessage()), e);
       }
-      finally
+    }
+
+    private RootCfgClient getRootConfigurationClient()
+    {
+      final JNDIDirContextAdaptor jndiContext = JNDIDirContextAdaptor.adapt(getInfo().getDirContext());
+      return LDAPManagementContext.createFromContext(jndiContext).getRootConfiguration();
+    }
+
+    private void addNewBaseDN(String backendName) throws OpenDsException
+    {
+      if (!isServerRunning())
       {
-        if (ldifImportConfig != null)
-        {
-          ldifImportConfig.close();
-        }
+        addNewBaseDNOffline(backendName);
+        return;
       }
+
+      final BackendCfgClient backend = getRootConfigurationClient().getBackend(backendName);
+      final Set<DN> baseDNs = backend.getBaseDN();
+      baseDNs.add(DN.valueOf(newBaseDN));
+      backend.setBaseDN(baseDNs);
+      backend.commit();
+    }
+
+    private void addNewBaseDNOffline(String backendName) throws OpenDsException
+    {
+      try
+      {
+        getInfo().initializeConfigurationFramework();
+        final List<IOException> exceptions = new ArrayList<>();
+        final org.forgerock.opendj.config.client.ManagementContext context =
+            org.forgerock.opendj.config.client.ldap.LDAPManagementContext.newLDIFManagementContext(
+                Installation.getLocal().getCurrentConfigurationFile(), LDAPProfile.getInstance(), exceptions);
+        final org.forgerock.opendj.server.config.client.BackendCfgClient backend =
+            context.getRootConfiguration().getBackend(backendName);
+        final SortedSet<org.forgerock.opendj.ldap.DN> baseDNs = backend.getBaseDN();
+        baseDNs.add(org.forgerock.opendj.ldap.DN.valueOf(newBaseDN));
+        backend.setBaseDN(baseDNs);
+        backend.commit();
+        context.close();
+        Utilities.throwFirstFrom(exceptions);
+      }
+      catch (Exception e)
+      {
+        throw new OfflineUpdateException(LocalizableMessage.raw(e.getMessage()), e);
+      }
+    }
+
+    private void createAdditionalIndexes() throws OpenDsException
+    {
+      final String backendName = getBackendName();
+      displayCreateAdditionalIndexesDsConfigCmdLine();
+      final RootCfgClient root = getRootConfigurationClient();
+      if (isLocalDBBackend())
+      {
+        addJEDefaultIndexes((LocalDBBackendCfgClient) root.getBackend(backendName));
+      }
+      else
+      {
+        addBackendDefaultIndexes((PluggableBackendCfgClient) root.getBackend(backendName));
+      }
+      displayCreateAdditionalIndexesDone();
+    }
+
+    @RemoveOnceLocalDBBackendIsPluggable
+    private void addJEDefaultIndexes(final LocalDBBackendCfgClient jeBackendCfgClient) throws AdminException
+    {
+      for (DefaultIndex defaultIndex : BackendCreationHelper.DEFAULT_INDEXES)
+      {
+        final LocalDBIndexCfgClient jeIndex =
+            jeBackendCfgClient.createLocalDBIndex(LocalDBIndexCfgDefn.getInstance(), defaultIndex.getName(), null);
+
+        final List<LocalDBIndexCfgDefn.IndexType> indexTypes = new LinkedList<>();
+        indexTypes.add(LocalDBIndexCfgDefn.IndexType.EQUALITY);
+        if (defaultIndex.shouldCreateSubstringIndex())
+        {
+          indexTypes.add(LocalDBIndexCfgDefn.IndexType.SUBSTRING);
+        }
+        jeIndex.setIndexType(indexTypes);
+        jeIndex.commit();
+      }
+    }
+
+    private void addBackendDefaultIndexes(PluggableBackendCfgClient backendCfgClient) throws AdminException
+    {
+      for (DefaultIndex defaultIndex : BackendCreationHelper.DEFAULT_INDEXES)
+      {
+        final BackendIndexCfgClient index = backendCfgClient.createBackendIndex(
+            BackendIndexCfgDefn.getInstance(), defaultIndex.getName(), null);
+
+        final List<IndexType> indexTypes = new LinkedList<>();
+        indexTypes.add(IndexType.EQUALITY);
+        if (defaultIndex.shouldCreateSubstringIndex())
+        {
+          indexTypes.add(IndexType.SUBSTRING);
+        }
+        index.setIndexType(indexTypes);
+        index.commit();
+      }
+    }
+
+    private void printCreateNewBaseDNProgress(final String backendName) throws OpenDsException
+    {
+      SwingUtilities.invokeLater(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          LocalizableMessage message = INFO_CTRL_PANEL_CREATING_BASE_DN_PROGRESS.get(newBaseDN, backendName);
+          getProgressDialog().appendProgressHtml(
+              Utilities.getProgressWithPoints(message, ColorAndFontConstants.progressFont));
+        }
+      });
+    }
+
+    private void printTaskDone()
+    {
+      SwingUtilities.invokeLater(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          getProgressDialog().appendProgressHtml(
+              Utilities.getProgressDone(ColorAndFontConstants.progressFont) + "<br><br>");
+        }
+      });
+    }
+
+    private void refreshProgressBar()
+    {
+      if (progressAfterConfigurationUpdate > 0)
+      {
+        SwingUtilities.invokeLater(new Runnable()
+        {
+          @Override
+          public void run()
+          {
+            getProgressDialog().getProgressBar().setIndeterminate(false);
+            getProgressDialog().getProgressBar().setValue(progressAfterConfigurationUpdate);
+          }
+        });
+      }
+    }
+
+    private void displayCreateAdditionalIndexesDsConfigCmdLine()
+    {
+      final List<List<String>> argsArray = new ArrayList<>();
+      for (DefaultIndex defaultIndex : BackendCreationHelper.DEFAULT_INDEXES)
+      {
+        argsArray.add(getCreateIndexCommandLineArguments(defaultIndex));
+      }
+
+      final StringBuilder sb = new StringBuilder();
+      for (List<String> args : argsArray)
+      {
+        sb.append(getEquivalentCommandLine(getCommandLinePath("dsconfig"), getObfuscatedCommandLineArguments(args)));
+        sb.append("<br><br>");
+      }
+
+      SwingUtilities.invokeLater(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          getProgressDialog().appendProgressHtml(Utilities.applyFont(
+              INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_CREATE_ADDITIONAL_INDEXES.get()
+              + "<br><br><b>" + sb + "</b>", ColorAndFontConstants.progressFont));
+          getProgressDialog().appendProgressHtml(Utilities.getProgressWithPoints(
+              INFO_CTRL_PANEL_CREATING_ADDITIONAL_INDEXES_PROGRESS.get(), ColorAndFontConstants.progressFont));
+        }
+      });
+    }
+
+    private List<String> getCreateIndexCommandLineArguments(final DefaultIndex defaultIndex)
+    {
+      final List<String> args = new ArrayList<>();
+      args.add(isLocalDBBackend() ? "create-local-db-index" : "create-backend-index");
+      args.add("--backend-name");
+      args.add(getBackendName());
+      args.add("--type");
+      args.add("generic");
+      args.add("--index-name");
+      args.add(defaultIndex.getName());
+      args.add("--set");
+      args.add("index-type:" + IndexTypeDescriptor.EQUALITY.toBackendIndexType());
+      if (defaultIndex.shouldCreateSubstringIndex())
+      {
+        args.add("--set");
+        args.add("index-type:" + IndexTypeDescriptor.SUBSTRING.toBackendIndexType());
+      }
+      args.addAll(getConnectionCommandLineArguments());
+      args.add(getNoPropertiesFileArgument());
+      args.add("--no-prompt");
+
+      return args;
+    }
+
+    private void displayCreateAdditionalIndexesDone()
+    {
+      SwingUtilities.invokeLater(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          getProgressDialog().appendProgressHtml(
+              Utilities.getProgressDone(ColorAndFontConstants.progressFont) + "<br><br>");
+        }
+      });
+    }
+
+    @RemoveOnceLocalDBBackendIsPluggable
+    private boolean isLocalDBBackend()
+    {
+      return getSelectedBackendType().getBackend()
+          instanceof org.forgerock.opendj.server.config.meta.LocalDBBackendCfgDefn;
     }
 
     /**
@@ -1151,286 +1375,6 @@
       }
     }
 
-    private void createBackend(InitialLdapContext ctx, String backendName, String baseDN) throws OpenDsException
-    {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
-      LocalDBBackendCfgDefn provider = LocalDBBackendCfgDefn.getInstance();
-      LocalDBBackendCfgClient backend = root.createBackend(provider, backendName, null);
-      backend.setEnabled(true);
-
-      Set<DN> baseDNs = new HashSet<>();
-      baseDNs.add(DN.valueOf(baseDN));
-      backend.setBaseDN(baseDNs);
-      backend.setBackendId(backendName);
-      backend.setWritabilityMode(BackendCfgDefn.WritabilityMode.ENABLED);
-      backend.commit();
-    }
-
-    private String getBackendLdif(String backendName)
-    {
-      String dn = Utilities.getRDNString("ds-cfg-backend-id", backendName ) +  ",cn=Backends,cn=config";
-      return Utilities.makeLdif(
-          "dn: " + dn,
-          "objectClass: top",
-          "objectClass: ds-cfg-backend",
-          "objectClass: ds-cfg-local-db-backend",
-          "ds-cfg-base-dn: " + newBaseDN,
-          "ds-cfg-enabled: true",
-          "ds-cfg-writability-mode: enabled",
-          "ds-cfg-java-class: " +
-          org.opends.server.backends.jeb.BackendImpl.class.getName(),
-          "ds-cfg-backend-id: " + backendName,
-          "ds-cfg-db-directory: db",
-          "",
-          "dn: cn=Index," + dn,
-          "objectClass: top",
-          "objectClass: ds-cfg-branch",
-          "cn: Index",
-          "",
-          "dn: ds-cfg-attribute=aci,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: aci",
-          "ds-cfg-index-type: presence",
-          "",
-          "dn: ds-cfg-attribute=ds-sync-hist,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: ds-sync-hist",
-          "ds-cfg-index-type: ordering",
-          "",
-          "dn: ds-cfg-attribute=entryUUID,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: entryUUID",
-          "ds-cfg-index-type: equality",
-          "",
-          "dn: ds-cfg-attribute=objectClass,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: objectClass",
-          "ds-cfg-index-type: equality"
-      );
-    }
-
-    private String getAdditionalIndexLdif(String backendName)
-    {
-      String dn = "ds-cfg-backend-id=" + backendName + ",cn=Backends,cn=config";
-      return Utilities.makeLdif(
-          "dn: ds-cfg-attribute=cn,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: cn",
-          "ds-cfg-index-type: equality",
-          "ds-cfg-index-type: substring",
-          "",
-          "dn: ds-cfg-attribute=givenName,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: givenName",
-          "ds-cfg-index-type: equality",
-          "ds-cfg-index-type: substring",
-          "",
-          "dn: ds-cfg-attribute=mail,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: mail",
-          "ds-cfg-index-type: equality",
-          "ds-cfg-index-type: substring",
-          "",
-          "dn: ds-cfg-attribute=member,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: member",
-          "ds-cfg-index-type: equality",
-          "",
-          "dn: ds-cfg-attribute=sn,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: sn",
-          "ds-cfg-index-type: equality",
-          "ds-cfg-index-type: substring",
-          "",
-          "dn: ds-cfg-attribute=telephoneNumber,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: telephoneNumber",
-          "ds-cfg-index-type: equality",
-          "ds-cfg-index-type: substring",
-          "",
-          "dn: ds-cfg-attribute=uid,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: uid",
-          "ds-cfg-index-type: equality",
-          "",
-          "dn: ds-cfg-attribute=uniqueMember,cn=Index," + dn,
-          "objectClass: ds-cfg-local-db-index",
-          "objectClass: top",
-          "ds-cfg-attribute: uniqueMember",
-          "ds-cfg-index-type: equality"
-      );
-    }
-
-    private void createAdditionalIndexes(InitialLdapContext ctx, String backendName) throws OpenDsException
-    {
-      List<List<String>> argsArray = new ArrayList<>();
-      List<String> dns = new ArrayList<>();
-      List<Attributes> attributes = new ArrayList<>();
-
-      // Instead of adding indexes using management framework, use this approach
-      // so that we have to define the additional indexes only in the method
-      // getBackendLdif.
-      String ldif = getAdditionalIndexLdif(backendName);
-      LDIFImportConfig ldifImportConfig = null;
-      try
-      {
-        ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
-        LDIFReader reader = new LDIFReader(ldifImportConfig);
-        Entry indexEntry;
-        while ((indexEntry = reader.readEntry()) != null)
-        {
-          List<String> args = new ArrayList<>();
-          args.add("create-local-db-index");
-          args.add("--backend-name");
-          args.add(backendName);
-          args.add("--type");
-          args.add("generic");
-
-          argsArray.add(args);
-          Attributes attrs = new BasicAttributes();
-
-          BasicAttribute oc = new BasicAttribute("objectClass");
-          Iterator<ByteString> it = indexEntry.getObjectClassAttribute().iterator();
-          while (it.hasNext())
-          {
-            oc.add(it.next().toString());
-          }
-          attrs.put(oc);
-
-          List<org.opends.server.types.Attribute> odsAttrs = indexEntry.getAttributes();
-          for (org.opends.server.types.Attribute odsAttr : odsAttrs)
-          {
-            String attrName = odsAttr.getName();
-            BasicAttribute attr = new BasicAttribute(attrName);
-            it = odsAttr.iterator();
-            while (it.hasNext())
-            {
-              attr.add(it.next().toString());
-            }
-            attrs.put(attr);
-
-            if ("ds-cfg-attribute".equalsIgnoreCase(attrName))
-            {
-              args.add("--index-name");
-              args.add(odsAttr.iterator().next().toString());
-            }
-            else if ("ds-cfg-index-type".equalsIgnoreCase(attrName))
-            {
-              it = odsAttr.iterator();
-              while (it.hasNext())
-              {
-                args.add("--set");
-                args.add("index-type:" + it.next());
-              }
-            }
-          }
-          args.addAll(getConnectionCommandLineArguments());
-          args.add(getNoPropertiesFileArgument());
-          args.add("--no-prompt");
-
-          dns.add(indexEntry.getName().toString());
-          attributes.add(attrs);
-        }
-
-        StringBuilder sb = new StringBuilder();
-        for (List<String> args : argsArray)
-        {
-          sb.append(getEquivalentCommandLine(getCommandLinePath("dsconfig"), getObfuscatedCommandLineArguments(args)));
-          sb.append("<br><br>");
-        }
-        final String cmdLines = sb.toString();
-        SwingUtilities.invokeLater(new Runnable()
-        {
-          @Override
-          public void run()
-          {
-            getProgressDialog().appendProgressHtml(Utilities.applyFont(
-             INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_CREATE_ADDITIONAL_INDEXES.get() + "<br><br><b>" + cmdLines + "</b>",
-             ColorAndFontConstants.progressFont));
-            getProgressDialog().appendProgressHtml(Utilities.getProgressWithPoints(
-                    INFO_CTRL_PANEL_CREATING_ADDITIONAL_INDEXES_PROGRESS.get(), ColorAndFontConstants.progressFont));
-          }
-        });
-
-        for (int i = 0; i < dns.size(); i++)
-        {
-          ctx.createSubcontext(dns.get(i), attributes.get(i));
-        }
-
-        SwingUtilities.invokeLater(new Runnable()
-        {
-          @Override
-          public void run()
-          {
-            getProgressDialog().appendProgressHtml(
-                Utilities.getProgressDone(ColorAndFontConstants.progressFont) + "<br><br>");
-          }
-        });
-      }
-      catch (Throwable t)
-      {
-        throw new OnlineUpdateException(ERR_CTRL_PANEL_ERROR_UPDATING_CONFIGURATION.get(t), t);
-      }
-      finally
-      {
-        if (ldifImportConfig != null)
-        {
-          ldifImportConfig.close();
-        }
-      }
-    }
-
-    private void addBaseDN(String backendName, String baseDN) throws OpenDsException, ConfigException
-    {
-      List<DN> baseDNs = new LinkedList<>();
-      for (BackendDescriptor backend : getInfo().getServerDescriptor().getBackends())
-      {
-        if (backend.getBackendID().equalsIgnoreCase(backendName))
-        {
-          for (BaseDNDescriptor b : backend.getBaseDns())
-          {
-            baseDNs.add(b.getDn());
-          }
-          break;
-        }
-      }
-      baseDNs.add(DN.valueOf(baseDN));
-
-      String dn = Utilities.getRDNString("ds-cfg-backend-id", backendName) + ",cn=Backends,cn=config";
-      ConfigEntry configEntry = DirectoryServer.getConfigHandler().getConfigEntry(DN.valueOf(dn));
-
-      DNConfigAttribute baseDNAttr = new DNConfigAttribute(
-            ConfigConstants.ATTR_BACKEND_BASE_DN, INFO_CONFIG_BACKEND_ATTR_DESCRIPTION_BASE_DNS.get(),
-            true, true, false, baseDNs);
-      configEntry.putConfigAttribute(baseDNAttr);
-      DirectoryServer.getConfigHandler().writeUpdatedConfig();
-    }
-
-    private void addBaseDN(InitialLdapContext ctx, String backendName, String baseDN) throws OpenDsException
-    {
-      ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(ctx));
-      RootCfgClient root = mCtx.getRootConfiguration();
-      LocalDBBackendCfgClient backend = (LocalDBBackendCfgClient) root.getBackend(backendName);
-
-      Set<DN> baseDNs = backend.getBaseDN();
-      DN dn = DN.valueOf(baseDN);
-      baseDNs.add(dn);
-      backend.setBaseDN(baseDNs);
-      backend.commit();
-    }
-
     /** {@inheritDoc} */
     @Override
     protected String getCommandLinePath()
@@ -1465,7 +1409,7 @@
           args.add("--set");
           args.add("enabled:true");
           args.add("--type");
-          args.add("local-db");
+          args.add(BackendTypeHelper.filterSchemaBackendName(getSelectedBackendType().getBackend().getName()));
         }
         else
         {
@@ -1491,7 +1435,14 @@
 
       try
       {
-        updateConfiguration();
+        if (isServerRunning())
+        {
+          updateConfigurationOnline();
+        }
+        else
+        {
+          updateConfigurationOffline();
+        }
         updateData();
       }
       catch (Throwable t)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
index 3a5e079..567e8bc 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
@@ -26,6 +26,14 @@
  */
 package org.opends.guitools.controlpanel.util;
 
+import static org.opends.admin.ads.util.ConnectionUtils.*;
+import static org.opends.messages.AdminToolMessages.*;
+import static org.opends.quicksetup.Installation.*;
+import static org.opends.server.types.CommonSchemaElements.*;
+
+import static com.forgerock.opendj.cli.Utils.*;
+import static com.forgerock.opendj.util.OperatingSystem.*;
+
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Container;
@@ -91,6 +99,8 @@
 import javax.swing.table.TableColumnModel;
 
 import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.i18n.slf4j.LocalizedLogger;
+import org.forgerock.opendj.config.ConfigurationFramework;
 import org.forgerock.opendj.config.server.ConfigException;
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.schema.MatchingRule;
@@ -129,19 +139,13 @@
 import org.opends.server.util.ServerConstants;
 import org.opends.server.util.StaticUtils;
 
-import static com.forgerock.opendj.cli.Utils.*;
-import static com.forgerock.opendj.util.OperatingSystem.*;
-
-import static org.opends.admin.ads.util.ConnectionUtils.*;
-import static org.opends.messages.AdminToolMessages.*;
-import static org.opends.quicksetup.Installation.*;
-import static org.opends.server.types.CommonSchemaElements.*;
-
 /**
  * A static class that provides miscellaneous functions.
  */
 public class Utilities
 {
+  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
+
   private static File rootDirectory;
   private static File instanceRootDirectory;
 
@@ -2910,4 +2914,24 @@
     }
   }
 
+  /**
+   * Initialize the configuration framework.
+   */
+  public static void initializeConfigurationFramework()
+  {
+    if (!ConfigurationFramework.getInstance().isInitialized())
+    {
+      try
+      {
+        ConfigurationFramework.getInstance().initialize();
+      }
+      catch (ConfigException e)
+      {
+        final LocalizableMessage message = ERROR_CTRL_PANEL_INITIALIZE_CONFIG_OFFLINE.get(e.getLocalizedMessage());
+        logger.error(message);
+        throw new RuntimeException(message.toString(), e);
+      }
+    }
+  }
+
 }
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java
new file mode 100644
index 0000000..0478454
--- /dev/null
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java
@@ -0,0 +1,214 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ * or http://forgerock.org/license/CDDLv1.0.html.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at legal-notices/CDDLv1_0.txt.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Copyright 2015 ForgeRock AS
+ */
+package org.opends.server.tools;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.forgerock.opendj.config.LDAPProfile;
+import org.forgerock.opendj.config.ManagedObjectDefinition;
+import org.forgerock.opendj.config.client.ManagementContext;
+import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
+import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.server.config.client.BackendCfgClient;
+import org.forgerock.opendj.server.config.client.BackendIndexCfgClient;
+import org.forgerock.opendj.server.config.client.LocalDBBackendCfgClient;
+import org.forgerock.opendj.server.config.client.LocalDBIndexCfgClient;
+import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
+import org.forgerock.opendj.server.config.client.RootCfgClient;
+import org.forgerock.opendj.server.config.meta.BackendCfgDefn.WritabilityMode;
+import org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn;
+import org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType;
+import org.forgerock.opendj.server.config.meta.LocalDBBackendCfgDefn;
+import org.forgerock.opendj.server.config.meta.LocalDBIndexCfgDefn;
+import org.forgerock.opendj.server.config.server.BackendCfg;
+import org.opends.guitools.controlpanel.util.Utilities;
+import org.opends.quicksetup.Installation;
+import org.opends.server.backends.jeb.RemoveOnceLocalDBBackendIsPluggable;
+
+/**
+ * Utility class which can be used by tools to create a new backend with default indexes.
+ */
+public class BackendCreationHelper
+{
+  /** Describes an attribute index which should be created during installation. */
+  public static final class DefaultIndex
+  {
+    static DefaultIndex withEqualityAndSubstring(final String name)
+    {
+      return new DefaultIndex(name, true);
+    }
+
+    static DefaultIndex withEquality(final String name)
+    {
+      return new DefaultIndex(name, false);
+    }
+
+    private final String name;
+    private final boolean shouldCreateSubstringIndex;
+
+    private DefaultIndex(final String name, final boolean substringIndex)
+    {
+      this.name = name;
+      this.shouldCreateSubstringIndex = substringIndex;
+    }
+
+    /**
+     * Return the name of this default index.
+     *
+     * @return The name of this default index
+     */
+    public String getName()
+    {
+      return name;
+    }
+
+    /**
+     * Return {@code true} if the substring index type should be enabled for
+     * this index.
+     *
+     * @return {@code true} if the substring index type should be enabled for
+     *         this index.
+     */
+    public boolean shouldCreateSubstringIndex()
+    {
+      return shouldCreateSubstringIndex;
+    }
+  }
+
+  /** Default indexes to add in a new backend. */
+  public static final DefaultIndex[] DEFAULT_INDEXES = {
+    DefaultIndex.withEqualityAndSubstring("cn"),
+    DefaultIndex.withEqualityAndSubstring("givenName"),
+    DefaultIndex.withEqualityAndSubstring("mail"),
+    DefaultIndex.withEqualityAndSubstring("sn"),
+    DefaultIndex.withEqualityAndSubstring("telephoneNumber"),
+    DefaultIndex.withEquality("member"),
+    DefaultIndex.withEquality("uid"),
+    DefaultIndex.withEquality("uniqueMember")
+  };
+
+  /**
+   * Add a new backend with the provided name in the config.ldif file.
+   *
+   * @param backendName
+   *          The new backend name
+   * @param baseDNs
+   *          The base dns to add in the new backend.
+   * @param backendType
+   *          The backend type
+   * @throws Exception
+   *           If any problems occurred
+   */
+  public static void createBackendOffline(String backendName, Collection<DN> baseDNs,
+      ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType) throws Exception
+  {
+    Utilities.initializeConfigurationFramework();
+    final List<IOException> exceptions = new ArrayList<>();
+    final ManagementContext context = LDAPManagementContext.newLDIFManagementContext(
+        Installation.getLocal().getCurrentConfigurationFile(), LDAPProfile.getInstance(), exceptions);
+    createBackend(context.getRootConfiguration(), backendName, baseDNs, backendType);
+    context.close();
+    Utilities.throwFirstFrom(exceptions);
+  }
+
+  /**
+   * Create a backend with the provided name using the provided
+   * {@code RootCfgClient}.
+   *
+   * @param rootConfiguration
+   *          The root configuration to use to create the new backend
+   * @param backendName
+   *          The new backend name
+   * @param baseDNs
+   *          The base dns to add in the new backend.
+   * @param backendType
+   *          The backend type
+   * @throws Exception
+   *           If any problems occurred
+   */
+  public static void createBackend(RootCfgClient rootConfiguration, String backendName, Collection<DN> baseDNs,
+      ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backendType) throws Exception
+  {
+      final BackendCfgClient backendCfgClient = rootConfiguration.createBackend(backendType, backendName, null);
+      backendCfgClient.setEnabled(true);
+      backendCfgClient.setBaseDN(baseDNs);
+      backendCfgClient.setWritabilityMode(WritabilityMode.ENABLED);
+      backendCfgClient.commit();
+
+      if (backendType instanceof LocalDBBackendCfgDefn)
+      {
+        addJEDefaultIndexes((LocalDBBackendCfgClient) backendCfgClient);
+      }
+      else
+      {
+        addBackendDefaultIndexes((PluggableBackendCfgClient) backendCfgClient);
+      }
+  }
+
+  private static void addBackendDefaultIndexes(PluggableBackendCfgClient backendCfgClient) throws Exception
+  {
+    for (DefaultIndex defaultIndex : DEFAULT_INDEXES)
+    {
+      final BackendIndexCfgClient index =
+          backendCfgClient.createBackendIndex(BackendIndexCfgDefn.getInstance(), defaultIndex.name, null);
+
+      final List<IndexType> indexTypes = new LinkedList<>();
+      indexTypes.add(IndexType.EQUALITY);
+      if (defaultIndex.shouldCreateSubstringIndex)
+      {
+        indexTypes.add(IndexType.SUBSTRING);
+      }
+      index.setIndexType(indexTypes);
+
+      index.commit();
+    }
+  }
+
+  @RemoveOnceLocalDBBackendIsPluggable
+  private static void addJEDefaultIndexes(final LocalDBBackendCfgClient jeBackendCfgClient) throws Exception
+  {
+    for (DefaultIndex defaultIndex : DEFAULT_INDEXES)
+    {
+      final LocalDBIndexCfgClient jeIndex =
+          jeBackendCfgClient.createLocalDBIndex(LocalDBIndexCfgDefn.getInstance(), defaultIndex.name, null);
+
+      final List<LocalDBIndexCfgDefn.IndexType> indexTypes = new ArrayList<>();
+      indexTypes.add(LocalDBIndexCfgDefn.IndexType.EQUALITY);
+      if (defaultIndex.shouldCreateSubstringIndex)
+      {
+        indexTypes.add(LocalDBIndexCfgDefn.IndexType.SUBSTRING);
+      }
+      jeIndex.setIndexType(indexTypes);
+
+      jeIndex.commit();
+    }
+  }
+
+}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendTypeHelper.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendTypeHelper.java
index 911df37..9fcd48c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendTypeHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/BackendTypeHelper.java
@@ -31,16 +31,14 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.config.AbstractManagedObjectDefinition;
-import org.forgerock.opendj.config.ConfigurationFramework;
 import org.forgerock.opendj.config.ManagedObjectDefinition;
-import org.forgerock.opendj.config.server.ConfigException;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
 import org.forgerock.opendj.server.config.meta.LocalDBBackendCfgDefn;
 import org.forgerock.opendj.server.config.meta.PluggableBackendCfgDefn;
 import org.forgerock.opendj.server.config.server.BackendCfg;
+import org.opends.guitools.controlpanel.util.Utilities;
+import org.opends.server.backends.jeb.RemoveOnceLocalDBBackendIsPluggable;
 
 /**
  * Helper class for setup applications. It helps applications to provide a
@@ -48,7 +46,6 @@
  */
 public class BackendTypeHelper
 {
-  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
   /**
    * Filter the provided backend name by removing the backend suffix.
@@ -105,6 +102,41 @@
     {
       return backend;
     }
+
+    /**
+     * Return the old configuration framework backend object.
+     *
+     * @return The old configuration framework backend object
+     */
+    @SuppressWarnings("unchecked")
+    public org.opends.server.admin.ManagedObjectDefinition<
+        ? extends org.opends.server.admin.std.client.BackendCfgClient,
+        ? extends org.opends.server.admin.std.server.BackendCfg> getOldConfigFrameworkBackend()
+    {
+      if (isLocalDBBackend())
+      {
+        return org.opends.server.admin.std.meta.LocalDBBackendCfgDefn.getInstance();
+      }
+
+      for (org.opends.server.admin.AbstractManagedObjectDefinition<?, ?> oldConfigBackend :
+        org.opends.server.admin.std.meta.PluggableBackendCfgDefn.getInstance().getAllChildren())
+      {
+        if (oldConfigBackend.getName().equals(getBackend().getName()))
+        {
+          return (org.opends.server.admin.ManagedObjectDefinition<
+              ? extends org.opends.server.admin.std.client.BackendCfgClient,
+              ? extends org.opends.server.admin.std.server.BackendCfg>) oldConfigBackend;
+        }
+      }
+      throw new IllegalArgumentException("Impossible to find the equivalent backend type in old config framework: "
+          + getBackend().getName());
+    }
+
+    @RemoveOnceLocalDBBackendIsPluggable
+    private boolean isLocalDBBackend()
+    {
+      return getBackend().getName().equals(LocalDBBackendCfgDefn.getInstance().getName());
+    }
   }
 
   private List<ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg>> backends;
@@ -112,28 +144,10 @@
   /** Creates a new backend type helper. */
   public BackendTypeHelper()
   {
-    initializeConfigurationFramework();
+    Utilities.initializeConfigurationFramework();
     createAvailableBackendsList();
   }
 
-  private void initializeConfigurationFramework()
-  {
-    if (!ConfigurationFramework.getInstance().isInitialized())
-    {
-      try
-      {
-        ConfigurationFramework.getInstance().initialize();
-      }
-      catch (ConfigException e)
-      {
-        final LocalizableMessage message = LocalizableMessage.raw(
-            "Error occured while loading the configuration framework: " + e.getLocalizedMessage());
-        logger.error(message);
-        throw new RuntimeException(message.toString());
-      }
-    }
-  }
-
   @SuppressWarnings("unchecked")
   private void createAvailableBackendsList()
   {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
index 608b885..57227a1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
@@ -38,7 +38,6 @@
 import static com.forgerock.opendj.cli.Utils.*;
 
 import java.io.File;
-import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.StringReader;
@@ -53,31 +52,15 @@
 import javax.crypto.Cipher;
 
 import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.config.LDAPProfile;
 import org.forgerock.opendj.config.ManagedObjectDefinition;
-import org.forgerock.opendj.config.client.ManagementContext;
-import org.forgerock.opendj.config.client.ldap.LDAPManagementContext;
-import org.forgerock.opendj.ldap.schema.Schema;
 import org.forgerock.opendj.server.config.client.BackendCfgClient;
-import org.forgerock.opendj.server.config.client.BackendIndexCfgClient;
-import org.forgerock.opendj.server.config.client.LocalDBBackendCfgClient;
-import org.forgerock.opendj.server.config.client.LocalDBIndexCfgClient;
-import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient;
-import org.forgerock.opendj.server.config.client.RootCfgClient;
-import org.forgerock.opendj.server.config.meta.BackendCfgDefn.WritabilityMode;
-import org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn;
-import org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType;
-import org.forgerock.opendj.server.config.meta.LocalDBBackendCfgDefn;
-import org.forgerock.opendj.server.config.meta.LocalDBIndexCfgDefn;
 import org.forgerock.opendj.server.config.server.BackendCfg;
-import org.opends.quicksetup.Installation;
 import org.opends.quicksetup.installer.Installer;
 import org.opends.server.admin.DefaultBehaviorProvider;
 import org.opends.server.admin.DefinedDefaultBehaviorProvider;
 import org.opends.server.admin.StringPropertyDefinition;
 import org.opends.server.admin.std.meta.CryptoManagerCfgDefn;
 import org.opends.server.api.ConfigHandler;
-import org.opends.server.backends.jeb.RemoveOnceLocalDBBackendIsPluggable;
 import org.opends.server.config.BooleanConfigAttribute;
 import org.opends.server.config.ConfigEntry;
 import org.opends.server.config.DNConfigAttribute;
@@ -212,9 +195,6 @@
   /** The fully-qualified name of this class. */
   private static final String CLASS_NAME = "org.opends.server.tools.ConfigureDS";
 
-  /** The DN of the configuration entry defining the JE database backend. */
-  private static final String DN_JE_BACKEND = ATTR_BACKEND_ID + "=userRoot," + DN_BACKEND_BASE;
-
   /** The DN of the configuration entry defining the LDAP connection handler. */
   public static final String DN_LDAP_CONNECTION_HANDLER = "cn=LDAP Connection Handler," + DN_CONNHANDLER_BASE;
 
@@ -236,41 +216,6 @@
   /** The DN of the DIGEST-MD5 SASL mechanism handler. */
   public static final String DN_DIGEST_MD5_SASL_MECHANISM = "cn=DIGEST-MD5,cn=SASL Mechanisms,cn=config";
 
-  /** Describes an attribute index which should be created during installation. */
-  private static final class DefaultIndex
-  {
-    private final String name;
-    private final boolean shouldCreateSubstringIndex;
-
-    private DefaultIndex(final String name, final boolean substringIndex)
-    {
-      this.name = name;
-      this.shouldCreateSubstringIndex = substringIndex;
-    }
-
-    private static DefaultIndex withEqualityAndSubstring(final String name)
-    {
-      return new DefaultIndex(name, true);
-    }
-
-    private static DefaultIndex withEquality(final String name)
-    {
-      return new DefaultIndex(name, false);
-    }
-  }
-
-  private static final DefaultIndex[] DEFAULT_INDEXES = {
-    DefaultIndex.withEqualityAndSubstring("cn"),
-    DefaultIndex.withEqualityAndSubstring("givenName"),
-    DefaultIndex.withEqualityAndSubstring("mail"),
-    DefaultIndex.withEqualityAndSubstring("sn"),
-    DefaultIndex.withEqualityAndSubstring("telephoneNumber"),
-    DefaultIndex.withEquality("member"),
-    DefaultIndex.withEquality("uid"),
-    DefaultIndex.withEquality("uniqueMember")
-  };
-
-
   private static int SUCCESS = 0;
   private static int ERROR = 1;
 
@@ -802,86 +747,16 @@
 
       try
       {
-          final File ldifConfigFile = Installation.getLocal().getCurrentConfigurationFile();
-          final List<IOException> exceptions = new LinkedList<IOException>();
-          final ManagementContext context =
-              LDAPManagementContext.newLDIFManagementContext(ldifConfigFile, LDAPProfile.getInstance(), exceptions);
-          createBackend(context.getRootConfiguration(), baseDNs,
-              (ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg>) backend);
-          context.close();
-          if (!exceptions.isEmpty())
-          {
-            throw exceptions.get(0);
-          }
+        BackendCreationHelper.createBackendOffline(Installer.ROOT_BACKEND_NAME, baseDNs,
+            (ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg>) backend);
       }
-      catch (final Exception e)
+      catch (Exception e)
       {
         throw new ConfigureDSException(ERR_CONFIGDS_SET_BACKEND_TYPE.get(backendTypeName, e.getMessage()));
       }
     }
   }
 
-  private void createBackend(final RootCfgClient rootConfiguration, final List<org.forgerock.opendj.ldap.DN> baseDNs,
-      final ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> backend) throws Exception
-  {
-      final BackendCfgClient backendCfgClient =
-          rootConfiguration.createBackend(backend, Installer.ROOT_BACKEND_NAME, null);
-      backendCfgClient.setEnabled(true);
-      backendCfgClient.setBaseDN(baseDNs);
-      backendCfgClient.setWritabilityMode(WritabilityMode.ENABLED);
-      backendCfgClient.commit();
-
-      if (backend instanceof LocalDBBackendCfgDefn)
-      {
-        addJEIndexes((LocalDBBackendCfgClient) backendCfgClient);
-        return;
-      }
-
-      addBackendIndexes((PluggableBackendCfgClient) backendCfgClient);
-  }
-
-  private void addBackendIndexes(PluggableBackendCfgClient backendCfgClient) throws Exception
-  {
-    for (DefaultIndex defaultIndex : DEFAULT_INDEXES)
-    {
-      final BackendIndexCfgClient index =
-          backendCfgClient.createBackendIndex(BackendIndexCfgDefn.getInstance(), defaultIndex.name, null);
-      index.setAttribute(Schema.getCoreSchema().getAttributeType(defaultIndex.name));
-
-      final List<IndexType> indexTypes = new LinkedList<IndexType>();
-      indexTypes.add(IndexType.EQUALITY);
-      if (defaultIndex.shouldCreateSubstringIndex)
-      {
-        indexTypes.add(IndexType.SUBSTRING);
-      }
-      index.setIndexType(indexTypes);
-
-      index.commit();
-    }
-  }
-
-  @RemoveOnceLocalDBBackendIsPluggable
-  private void addJEIndexes(final LocalDBBackendCfgClient jeBackendCfgClient) throws Exception
-  {
-    for (DefaultIndex defaultIndex : DEFAULT_INDEXES)
-    {
-      final LocalDBIndexCfgClient jeIndex =
-          jeBackendCfgClient.createLocalDBIndex(LocalDBIndexCfgDefn.getInstance(), defaultIndex.name, null);
-      jeIndex.setAttribute(Schema.getCoreSchema().getAttributeType(defaultIndex.name));
-
-      final List<org.forgerock.opendj.server.config.meta.LocalDBIndexCfgDefn.IndexType> indexTypes =
-          new LinkedList<org.forgerock.opendj.server.config.meta.LocalDBIndexCfgDefn.IndexType>();
-      indexTypes.add(org.forgerock.opendj.server.config.meta.LocalDBIndexCfgDefn.IndexType.EQUALITY);
-      if (defaultIndex.shouldCreateSubstringIndex)
-      {
-        indexTypes.add(org.forgerock.opendj.server.config.meta.LocalDBIndexCfgDefn.IndexType.SUBSTRING);
-      }
-      jeIndex.setIndexType(indexTypes);
-
-      jeIndex.commit();
-    }
-  }
-
   private void updateLdapPort() throws ConfigureDSException
   {
     if (ldapPort.isPresent())
diff --git a/opendj-server-legacy/src/messages/org/opends/messages/admin_tool.properties b/opendj-server-legacy/src/messages/org/opends/messages/admin_tool.properties
index 638d7d3..34f7ae8 100644
--- a/opendj-server-legacy/src/messages/org/opends/messages/admin_tool.properties
+++ b/opendj-server-legacy/src/messages/org/opends/messages/admin_tool.properties
@@ -2972,4 +2972,6 @@
 ERR_DEPENDENCY_TASK_NOT_DEFINED=There is no task with ID '%s' in the \
  server.
 INFO_AVAILABLE_DEFINED_TASKS=The available defined tasks are:%s
-
+INFO_CTRL_PANEL_BASE_DN_NEW_BACKEND_TYPE_LABEL=Backend Type:
+ERROR_CTRL_PANEL_CREATE_NEW_BACKEND=Impossible to create the new backend '%s'. Details: %s
+ERROR_CTRL_PANEL_INITIALIZE_CONFIG_OFFLINE=An error occured while loading the configuration framework: %s

--
Gitblit v1.10.0