Skip to content

Commit

Permalink
Tentative fix for MID-3706: in reconcile task with more then 1 worker…
Browse files Browse the repository at this point in the history
…Threads dry run option is ignored
  • Loading branch information
mederly committed Jan 28, 2017
1 parent 9eeef96 commit c9b08ac
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
Expand Up @@ -457,29 +457,26 @@ public static void clearRequestee(Task task) {
}

public static boolean isDryRun(Task task) throws SchemaException{

Boolean dryRun = isDryRunInternal(task);
if (dryRun == null && task.isLightweightAsynchronousTask() && task.getParentForLightweightAsynchronousTask() != null) {
dryRun = isDryRunInternal(task.getParentForLightweightAsynchronousTask());
}
return dryRun != null ? dryRun : Boolean.FALSE;
}

private static Boolean isDryRunInternal(Task task) throws SchemaException{
Validate.notNull(task, "Task must not be null.");

if (task.getExtension() == null){
return false;
if (task.getExtension() == null) {
return null;
}

PrismProperty<Boolean> item = task.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
if (item == null || item.isEmpty()){
return false;
if (item == null || item.isEmpty()) {
return null;
}

if (item.getValues().size() > 1){
if (item.getValues().size() > 1) {
throw new SchemaException("Unexpected number of values for option 'dry run'.");
}

Boolean dryRun = item.getValues().iterator().next().getValue();

if (dryRun == null){
return false;
}

return dryRun.booleanValue();
return item.getValues().iterator().next().getValue();
}

public static ExpressionVariables getDefaultExpressionVariables(@NotNull LensContext<?> context, @Nullable LensProjectionContext projCtx) throws SchemaException {
Expand Down
Expand Up @@ -592,6 +592,11 @@ public Task getParentTask(OperationResult result) throws SchemaException, Object
throw new UnsupportedOperationException("not implemented yet.");
}

@Override
public Task getParentForLightweightAsynchronousTask() {
throw new UnsupportedOperationException("not implemented yet.");
}

@Override
public TaskWaitingReason getWaitingReason() {
throw new UnsupportedOperationException("not implemented yet.");
Expand Down
Expand Up @@ -805,7 +805,13 @@ public void setResultImmediate(OperationResult result, OperationResult parentRes
*/
Task getParentTask(OperationResult result) throws SchemaException, ObjectNotFoundException;

/**
/**
* Returns the in-memory version of the parent task. Applicable only to lightweight subtasks.
* EXPERIMENTAL (use with care)
*/
Task getParentForLightweightAsynchronousTask();

/**
* Lists the (direct) subtasks of a given task.
*
* @param parentResult
Expand Down
Expand Up @@ -38,8 +38,6 @@
import com.evolveum.midpoint.prism.delta.builder.DeltaBuilder;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.EqualFilter;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
Expand Down Expand Up @@ -129,6 +127,7 @@ public class TaskQuartzImpl implements Task {
* This must be synchronized, because interrupt() method uses it.
*/
private Set<TaskQuartzImpl> lightweightAsynchronousSubtasks = Collections.synchronizedSet(new HashSet<TaskQuartzImpl>());
private Task parentForLightweightAsynchronousTask; // EXPERIMENTAL

/*
* Task result is stored here as well as in task prism.
Expand Down Expand Up @@ -1649,8 +1648,12 @@ public Task getParentTask(OperationResult result) throws SchemaException, Object
}
}

@Override
public Task getParentForLightweightAsynchronousTask() {
return parentForLightweightAsynchronousTask;
}

public void setParent(String value) {
public void setParent(String value) {
processModificationBatched(setParentAndPrepareDelta(value));
}

Expand Down Expand Up @@ -2496,6 +2499,7 @@ public Task createSubtask(LightweightTaskHandler handler) {
TaskQuartzImpl sub = ((TaskQuartzImpl) createSubtask());
sub.setLightweightTaskHandler(handler);
lightweightAsynchronousSubtasks.add(sub);
parentForLightweightAsynchronousTask = this;
return sub;
}

Expand Down

0 comments on commit c9b08ac

Please sign in to comment.