<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hello Алексей,<br>
      <br>
      I've studied the logs you've sent here.<br>
      <br>
      Look at the line 9182, just after the text "2015-05-26
      12:46:50,285 TRACE: Evaluating hook 'Example scripting hook'".<br>
      <br>
      You see that "User old" and "User current" have all the
      assignments, namely:<br>
      <br>
      <tt>            assignment: </tt><tt><br>
      </tt><tt>              id=2</tt><tt><br>
      </tt><tt>                targetRef:
        oid=5e8b8660-a788-4b7c-8a6c-f08f3ff3d4a1(RoleType)</tt><tt><br>
      </tt><tt>              id=3</tt><tt><br>
      </tt><tt>                targetRef:
        oid=7faa8e52-d8d8-487f-8a25-987a0eaf4521(RoleType)</tt><tt><br>
      </tt><tt>              id=4</tt><tt><br>
      </tt><tt>                targetRef:
        oid=cdb06bb4-c134-4ce5-b0f9-483b32832114(RoleType)</tt><tt><br>
      </tt><tt>              id=5</tt><tt><br>
      </tt><tt>                targetRef:
        oid=3427d715-52a1-4806-9f81-0304f57ffb90(RoleType)</tt><tt><br>
      </tt><tt>              id=1</tt><tt><br>
      </tt><tt>                targetRef:
        oid=aa1de21f-33a9-46c9-a3fb-f92e88b71377(OrgType)</tt><tt><br>
      </tt><tt><br>
      </tt>and "User new" does not have them. So far so good.<br>
      <br>
      BUT.<br>
      <br>
      The secondary delta(s) do not contain the delta that caused that
      removal:<br>
      <tt><br>
      </tt><tt>     User secondary delta:</tt><tt><br>
      </tt><tt>        ObjectDeltaWaves:2 waves</tt><tt><br>
      </tt><tt>          wave 0:</tt><tt><br>
      </tt><tt>           
ObjectDelta<UserType>(UserType:1e0a1255-9a03-415f-9bef-1ea5d4d4bbd8,MODIFY):</tt><tt><br>
      </tt><tt>              extension/hrStatus</tt><tt><br>
      </tt><tt>                REPLACE: REJ</tt><tt><br>
      </tt><tt>              assignment</tt><tt><br>
      </tt><tt>                ADD:</tt><tt><br>
      </tt><tt>                  id=null</tt><tt><br>
      </tt><tt>                    targetRef:
        oid=c2af1367-9ebd-4806-a7fa-05c0914083e0(OrgType)</tt><tt><br>
      </tt><tt>                DELETE:</tt><tt><br>
      </tt><tt>                  id=null</tt><tt><br>
      </tt><tt>                    targetRef:
        oid=aa1de21f-33a9-46c9-a3fb-f92e88b71377(OrgType)</tt><tt><br>
      </tt><tt>              activation/administrativeStatus</tt><tt><br>
      </tt><tt>                REPLACE: DISABLED</tt><tt><br>
      </tt><tt>              parentOrgRef</tt><tt><br>
      </tt><tt>                ADD:
        oid=c2af1367-9ebd-4806-a7fa-05c0914083e0(OrgType)</tt><tt><br>
      </tt><tt>                DELETE:
        oid=aa1de21f-33a9-46c9-a3fb-f92e88b71377(OrgType)</tt><tt><br>
      </tt><tt>          wave 1:</tt><tt><br>
      </tt><tt>           
ObjectDelta<UserType>(UserType:1e0a1255-9a03-415f-9bef-1ea5d4d4bbd8,MODIFY):</tt><tt><br>
      </tt><tt>              extension/hrStatus</tt><tt><br>
      </tt><tt>                REPLACE: REJ</tt><tt><br>
      </tt><tt>              activation/effectiveStatus</tt><tt><br>
      </tt><tt>                REPLACE: DISABLED</tt><tt><br>
      </tt><tt>              activation/disableTimestamp</tt><tt><br>
      </tt><tt>                REPLACE: 2015-05-26T12:46:45.745+03:00</tt><tt><br>
      </tt><tt>              parentOrgRef</tt><tt><br>
      </tt><tt>                ADD:
        oid=c2af1367-9ebd-4806-a7fa-05c0914083e0(OrgType)</tt><tt><br>
      </tt><tt>                DELETE:
        oid=aa1de21f-33a9-46c9-a3fb-f92e88b71377(OrgType)</tt><br>
      <br>
      And the deltas are what counts. ChangeExecutor executes deltas,
      not the "User new" state. The "User new" state is dynamically
      recomputed (using deltas), at many places.<br>
      <br>
      I'm refering to this code:<br>
      <br>
      <tt>result = new OperationResult("get_object_by_oid");</tt><tt><br>
      </tt><tt>
        task = taskManager.createTaskInstance("get_user_by_oid");</tt><tt><br>
      </tt><tt>
        focus.assignment.removeAll(rolesToDelete);</tt><tt><br>
      </tt><tt>
        current = modelController.getObject(UserType.class, focus.oid,
        null, task, result);</tt><tt><br>
      </tt><tt>
        delta = current.diff(focus.asPrismObject(), true, true);</tt><tt><br>
      </tt><tt>
context.engineScope.get("modelContext").focusContext.addSecondaryDelta(delta)</tt><tt><br>
      </tt><tt>
      </tt><br>
      So, I have two recommendation:<br>
      1) Do not call removeAll(rolesToDelete) on live object from the
      model context. Use a clone instead.<br>
      2) Try to find why the computed deltas are not incorporated in the
      context.<br>
      <br>
      As for 2, I would recommend putting some kind of logging to make
      sure the delta is computed well.<br>
      In particular, I would replace <tt>current.diff(focus.asPrismObject(),
        true, true)</tt> by <tt><br>
      </tt><tt>current.diff(focus.asPrismObject())</tt>.<tt> </tt>But
      that does not seem like the cause.<tt><br>
      </tt><br>
      There's probably one more caveat - not showing in your particular
      case, but still present.<br>
      If you put something into secondary delta, there's a risk that
      these deltas will get recomputed<br>
      if clockwork would think that the context is not fresh - around
      lines 236-241 of Clockwork:<br>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <pre style="background-color:#ffffff;color:#000000;font-family:'Courier New';font-size:9,0pt;"><small><small><span style="color:#000080;font-weight:bold;">if </span>(!context.isFresh()) {
   context.cleanup();
   <span style="color:#660e7a;font-weight:bold;">projector</span>.project(context, <span style="color:#008000;font-weight:bold;">"PROJECTOR ("</span>+state+<span style="color:#008000;font-weight:bold;">")"</span>, task, result);
} <span style="color:#000080;font-weight:bold;">else </span>{
   <span style="color:#660e7a;font-weight:bold;font-style:italic;">LOGGER</span>.trace(<span style="color:#008000;font-weight:bold;">"Skipping projection because the context is fresh"</span>);
}
</small></small></pre>
      Note that the projector.project simply re-computes secondary
      deltas from the beginning (i.e. from the primary delta). I'm not
      sure how to work around this. (Rado? Have you any idea?) Maybe
      modifying the primary delta instead of secondary one? Or just
      hoping this situation would not occur? :)<br>
      <br>
      Anyway, if I find a little bit more time, I could play for a while
      with this. Until that, you could consider modifying your code
      according to the recommendations above.<br>
      <br>
      Regards,<br>
      Pavol<br>
      <br>
      On 26. 5. 2015 11:59, Алексей Ващенков wrote:<br>
    </div>
    <blockquote
      cite="mid:23F96C83E30B7E4DA253EBD07C550836014D0BA3@EX-MB2.solar.local"
      type="cite">
      <pre wrap="">Send the log in attachment
________________________________________
От: midPoint [<a class="moz-txt-link-abbreviated" href="mailto:midpoint-bounces@lists.evolveum.com">midpoint-bounces@lists.evolveum.com</a>] от имени Pavol Mederly [<a class="moz-txt-link-abbreviated" href="mailto:pavol.mederly@gmail.com">pavol.mederly@gmail.com</a>]
Отправлено: 26 мая 2015 г. 12:38
Кому: <a class="moz-txt-link-abbreviated" href="mailto:midpoint@lists.evolveum.com">midpoint@lists.evolveum.com</a>
Тема: Re: [midPoint] HA:  HA:  Prohibit having particular assignments

I think this thread <a class="moz-txt-link-freetext" href="https://lists.evolveum.com/pipermail/midpoint/2015-May/000995.html">https://lists.evolveum.com/pipermail/midpoint/2015-May/000995.html</a> would be a better place to discuss this issue because the initial problem is rooted there.

OK, so continuing here.


System configuration is in attachments. How properly setup logs? If I enable model logger to debug, then each time hook is fired logs increase by 6MB

Yes, model diagnostic is quite verbose. Anyway, I suggest the following:

      <classLogger>
         <level>TRACE</level>
         <package>com.evolveum.midpoint.model.impl.lens.Clockwork</package>
      </classLogger>
      <classLogger>
         <level>TRACE</level>
         <package>com.evolveum.midpoint.model.impl.lens.projector.Projector</package>
      </classLogger>

...and remove the DEBUG placed at the level of model, i.e. this one:

      <classLogger>
         <level>DEBUG</level>
         <package>com.evolveum.midpoint.model</package>
         <appender>IDM-PROFILE_LOG</appender>
      </classLogger>

I really suspect that the secondary deltas get recomputed during the process.

Pavol
</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
midPoint mailing list
<a class="moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com">midPoint@lists.evolveum.com</a>
<a class="moz-txt-link-freetext" href="http://lists.evolveum.com/mailman/listinfo/midpoint">http://lists.evolveum.com/mailman/listinfo/midpoint</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>