From 0418e30716942bc043d20cf1580391f44b2cb73e Mon Sep 17 00:00:00 2001
From: coulbeck <coulbeck@localhost>
Date: Tue, 25 Sep 2007 18:38:03 +0000
Subject: [PATCH] These changes use the new LDIF backend implementation so that the adminRoot backend is always present. The adminRoot LDIF backend is initially populated with the admin container entries, except for the cn=Servers container. To avoid breaking the setup and dsreplication tools, I have changed things so that the absence of the cn=Servers container entry implies that the server is not yet configured as an ADS server. I have commented out code that is no longer applicable.

---
 opends/src/ads/org/opends/admin/ads/ADSContext.java |   95 +++++++++++++++++++++++++++++------------------
 1 files changed, 58 insertions(+), 37 deletions(-)

diff --git a/opends/src/ads/org/opends/admin/ads/ADSContext.java b/opends/src/ads/org/opends/admin/ads/ADSContext.java
index 42fc739..761dba1 100644
--- a/opends/src/ads/org/opends/admin/ads/ADSContext.java
+++ b/opends/src/ads/org/opends/admin/ads/ADSContext.java
@@ -54,6 +54,8 @@
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapName;
 import javax.naming.ldap.Rdn;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.LdapContext;
 
 /**
  * Class used to update and read the contents of the Administration Data.
@@ -942,22 +944,22 @@
   public void createAdminData(String backendName) throws ADSContextException
   {
     // Add the administration suffix
-    createAdministrationSuffix(backendName);
+//    createAdministrationSuffix(backendName);
 
     // Create the DIT below the administration suffix
-    createTopContainerEntry();
-    createAdministratorContainerEntry();
+//    createTopContainerEntry();
+//    createAdministratorContainerEntry();
     createContainerEntry(getServerContainerDN());
-    createContainerEntry(getServerGroupContainerDN());
+//    createContainerEntry(getServerGroupContainerDN());
 
     // Add the default "all-servers" group
-    Map<ServerGroupProperty, Object> allServersGroupsMap =
-      new HashMap<ServerGroupProperty, Object>();
-    allServersGroupsMap.put(ServerGroupProperty.UID, ALL_SERVERGROUP_NAME);
-    createServerGroup(allServersGroupsMap);
+//    Map<ServerGroupProperty, Object> allServersGroupsMap =
+//      new HashMap<ServerGroupProperty, Object>();
+//    allServersGroupsMap.put(ServerGroupProperty.UID, ALL_SERVERGROUP_NAME);
+//    createServerGroup(allServersGroupsMap);
 
     // Create the CryptoManager DIT below the administration suffix
-    createContainerEntry(getInstanceKeysContainerDN());
+//    createContainerEntry(getInstanceKeysContainerDN());
   }
 
   /**
@@ -966,7 +968,25 @@
    */
   public void removeAdminData() throws ADSContextException
   {
-    removeAdministrationSuffix();
+    LdapName dn = nameFromDN(getServerContainerDN());
+    try
+    {
+      Control[] controls = new Control[] { new SubtreeDeleteControl() };
+      LdapContext tmpContext = dirContext.newInstance(controls);
+      try
+      {
+        tmpContext.destroySubcontext(dn);
+      }
+      finally
+      {
+        tmpContext.close();
+      }
+    }
+    catch(NamingException x)
+    {
+      throw new ADSContextException(
+          ADSContextException.ErrorType.ERROR_UNEXPECTED, x);
+    }
   }
 
 
@@ -979,7 +999,7 @@
    */
   public boolean hasAdminData() throws ADSContextException
   {
-    return isExistingEntry(nameFromDN(getAdministrationSuffixDN()));
+    return isExistingEntry(nameFromDN(getServerContainerDN()));
   }
 
   /**
@@ -1975,28 +1995,29 @@
    * Administration Suffix will be used.
    * @throws ADSContextException if something goes wrong.
    */
-  public void createAdministrationSuffix(String backendName)
-  throws ADSContextException
-  {
-    ADSContextHelper helper = new ADSContextHelper();
-    String ben = backendName ;
-    if (backendName == null)
-    {
-      ben = getDefaultBackendName() ;
-    }
-    helper.createAdministrationSuffix(getDirContext(), ben,
-        getDbName(), getImportTemp());
-  }
+//  public void createAdministrationSuffix(String backendName)
+//  throws ADSContextException
+//  {
+//    ADSContextHelper helper = new ADSContextHelper();
+//    String ben = backendName ;
+//    if (backendName == null)
+//    {
+//      ben = getDefaultBackendName() ;
+//    }
+//    helper.createAdministrationSuffix(getDirContext(), ben,
+//        getDbName(), getImportTemp());
+//  }
 
   /**
    * Removes the administration suffix.
    * @throws ADSContextException if something goes wrong.
    */
-  private void removeAdministrationSuffix() throws ADSContextException
-  {
-    ADSContextHelper helper = new ADSContextHelper();
-    helper.removeAdministrationSuffix(getDirContext(), getDefaultBackendName());
-  }
+//  private void removeAdministrationSuffix() throws ADSContextException
+//  {
+//    ADSContextHelper helper = new ADSContextHelper();
+//    helper.removeAdministrationSuffix(getDirContext(),
+//                                      getDefaultBackendName());
+//  }
 
   /**
    * Returns the default backend name of the administration data.
@@ -2007,15 +2028,15 @@
     return "adminRoot";
   }
 
-  private static String getDbName()
-  {
-    return "adminDb";
-  }
-
-  private static String getImportTemp()
-  {
-    return "importAdminTemp";
-  }
+//  private static String getDbName()
+//  {
+//    return "adminDb";
+//  }
+//
+//  private static String getImportTemp()
+//  {
+//    return "importAdminTemp";
+//  }
 
 
 

--
Gitblit v1.10.0