From bd724fad0c954f1e607a0a90cbca3eb41d1f2460 Mon Sep 17 00:00:00 2001
From: pgamba <pgamba@localhost>
Date: Mon, 17 Sep 2007 08:00:37 +0000
Subject: [PATCH] Fixes repl init and total update #2253 #845 #1733

---
 opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java |  135 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 135 insertions(+), 0 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index b0c1bef..175455d 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -3974,6 +3974,7 @@
                         ne), ne);
       }
     }
+    resetGenerationId(ctx, suffixDn, true, sourceServerDisplay);
   }
 
   /**
@@ -4023,4 +4024,138 @@
   {
     return (random.nextInt() & modulo);
   }
+
+  private void resetGenerationId(InitialLdapContext ctx,
+      String suffixDn, boolean displayProgress, String sourceServerDisplay)
+  throws ApplicationException
+  {
+    boolean taskCreated = false;
+    int i = 1;
+    boolean isOver = false;
+    String dn = null;
+    BasicAttributes attrs = new BasicAttributes();
+    Attribute oc = new BasicAttribute("objectclass");
+    oc.add("top");
+    oc.add("ds-task");
+    oc.add("ds-task-reset-generation-id");
+    attrs.put(oc);
+    attrs.put("ds-task-class-name",
+        "org.opends.server.tasks.SetGenerationIdTask");
+    attrs.put("ds-task-reset-generation-id-domain-base-dn", suffixDn);
+    while (!taskCreated)
+    {
+      String id = "quicksetup-reset-generation-id-"+i;
+      dn = "ds-task-id="+id+",cn=Scheduled Tasks,cn=Tasks";
+      attrs.put("ds-task-id", id);
+      try
+      {
+        DirContext dirCtx = ctx.createSubcontext(dn, attrs);
+        taskCreated = true;
+        LOG.log(Level.INFO, "created task entry: "+attrs);
+        dirCtx.close();
+      }
+      catch (NameAlreadyBoundException x)
+      {
+      }
+      catch (NamingException ne)
+      {
+        LOG.log(Level.SEVERE, "Error creating task "+attrs, ne);
+        throw new ApplicationException(
+            ReturnCode.APPLICATION_ERROR,
+                getThrowableMsg(INFO_ERROR_LAUNCHING_INITIALIZATION.get(
+                        sourceServerDisplay
+                ), ne), ne);
+      }
+      i++;
+    }
+    // Wait until it is over
+    SearchControls searchControls = new SearchControls();
+    searchControls.setCountLimit(1);
+    searchControls.setSearchScope(
+        SearchControls. OBJECT_SCOPE);
+    String filter = "objectclass=*";
+    searchControls.setReturningAttributes(
+        new String[] {
+            "ds-task-log-message",
+            "ds-task-state"
+        });
+    Message lastDisplayedMsg = null;
+    String lastLogMsg = null;
+    long lastTimeMsgDisplayed = -1;
+    while (!isOver)
+    {
+      try
+      {
+        Thread.sleep(500);
+      }
+      catch (Throwable t)
+      {
+      }
+      try
+      {
+        NamingEnumeration res = ctx.search(dn, filter, searchControls);
+        SearchResult sr = (SearchResult)res.next();
+        String logMsg = getFirstValue(sr, "ds-task-log-message");
+        if (logMsg != null)
+        {
+          if (!logMsg.equals(lastLogMsg))
+          {
+            LOG.log(Level.INFO, logMsg);
+            lastLogMsg = logMsg;
+          }
+        }
+        InstallerHelper helper = new InstallerHelper();
+        String state = getFirstValue(sr, "ds-task-state");
+
+        if (helper.isDone(state) || helper.isStoppedByError(state))
+        {
+          isOver = true;
+          Message errorMsg;
+          if (lastLogMsg == null)
+          {
+            errorMsg = INFO_ERROR_DURING_INITIALIZATION_NO_LOG.get(
+                    sourceServerDisplay, state, sourceServerDisplay);
+          }
+          else
+          {
+            errorMsg = INFO_ERROR_DURING_INITIALIZATION_LOG.get(
+                    sourceServerDisplay, lastLogMsg, state,
+                    sourceServerDisplay);
+          }
+
+          if (helper.isCompletedWithErrors(state))
+          {
+            notifyListeners(getFormattedWarning(errorMsg));
+          }
+          else if (!helper.isSuccessful(state) ||
+              helper.isStoppedByError(state))
+          {
+            ApplicationException ae = new ApplicationException(
+                ReturnCode.APPLICATION_ERROR, errorMsg,
+                null);
+            throw ae;
+          }
+          else if (displayProgress)
+          {
+            notifyListeners(getFormattedProgress(
+                INFO_SUFFIX_INITIALIZED_SUCCESSFULLY.get()));
+          }
+        }
+      }
+      catch (NameNotFoundException x)
+      {
+        isOver = true;
+        notifyListeners(getFormattedProgress(
+            INFO_SUFFIX_INITIALIZED_SUCCESSFULLY.get()));
+      }
+      catch (NamingException ne)
+      {
+        throw new ApplicationException(
+            ReturnCode.APPLICATION_ERROR,
+                getThrowableMsg(INFO_ERROR_POOLING_INITIALIZATION.get(
+                        sourceServerDisplay),
+                        ne), ne);
+      }
+    }
+  }
 }

--
Gitblit v1.10.0