mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
29.38.2016 6cbfdb7b0cf38f41d16df60ef427db7d629f5965
OPENDJ-2650 No more task log (detail or error) when running tools in online mode (import, backup,...)

The problem is linked to the removal of if (attributeType.mayHaveSubordinateTypes()) checks in Entry.java.
When it was there, this check ensured the method Entry.getAttribute(AttributeType)
always returned the internal List representing the ds-task-log-message attribute.
Thus the code in Task.addLogMessage() was always updating the internal state of the task entry.

Now that we have removed the aforementioned check, Entry.getAttribute(AttributeType)
always returns a newly created List object, thus the update performed by Task.addLogMessage() is lost.

Task.java:
In addLogMessage(), used a more robust way to update the ds-task-log-message attribute value.
1 files modified
59 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java 59 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/task/Task.java
@@ -44,12 +44,20 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.messages.Severity;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ServerContext;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.types.*;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.Attributes;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
import org.opends.server.types.LockManager.DNLock;
import org.opends.server.types.Modification;
import org.opends.server.types.Operation;
import org.opends.server.util.EMailMessage;
import org.opends.server.util.StaticUtils;
import org.opends.server.util.TimeThread;
@@ -820,6 +828,26 @@
    }
    try
    {
      String messageString = buildLogMessage(severity, message, exception);
      logMessages.add(messageString);
      final AttributeType type = DirectoryServer.getAttributeType(ATTR_TASK_LOG_MESSAGES);
      final Attribute attr = taskEntry.getExactAttribute(type, Collections.<String> emptySet());
      final AttributeBuilder builder = attr != null ? new AttributeBuilder(attr) : new AttributeBuilder(type);
      builder.add(messageString);
      taskEntry.putAttribute(type, builder.toAttributeList());
    }
    finally
    {
      if (lock != null)
      {
        lock.unlock();
      }
    }
  }
  private String buildLogMessage(Severity severity, LocalizableMessage message, Throwable exception)
  {
      StringBuilder buffer = new StringBuilder();
      buffer.append("[");
      buffer.append(TimeThread.getLocalTime());
@@ -840,32 +868,7 @@
        buffer.append(StaticUtils.stackTraceToSingleLineString(exception));
        buffer.append("\"");
      }
      String messageString = buffer.toString();
      logMessages.add(messageString);
      AttributeType type = DirectoryServer.getAttributeType(ATTR_TASK_LOG_MESSAGES);
      final List<Attribute> attrList = taskEntry.getAttribute(type);
      ByteString value = ByteString.valueOfUtf8(messageString);
      if (attrList.isEmpty())
      {
        taskEntry.putAttribute(type, newArrayList(Attributes.create(type, value)));
      }
      else
      {
        AttributeBuilder builder = new AttributeBuilder(attrList.get(0));
        builder.add(value);
        attrList.set(0, builder.toAttribute());
      }
    }
    finally
    {
      if (lock != null)
      {
        lock.unlock();
      }
    }
    return buffer.toString();
  }
  /**