Skip to content

Commit

Permalink
Fix worker tasks progress reporting
Browse files Browse the repository at this point in the history
These tasks do not have complete work state information
(only buckets allocated to them) so they cannot report
bucketed progress.

Should fix MID-7002.
  • Loading branch information
mederly committed Apr 27, 2021
1 parent 2c094d8 commit c287d23
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
Expand Up @@ -55,7 +55,7 @@ private TaskPartProgressInformation(String partOrHandlerUri, boolean complete, B
public static TaskPartProgressInformation fromPersistentSubtask(TaskType task) {
String partUri = task.getHandlerUri();
boolean complete = task.getExecutionStatus() == TaskExecutionStateType.CLOSED;
BucketsProgressInformation bucketsProgress = BucketsProgressInformation.fromWorkState(task.getWorkState());
BucketsProgressInformation bucketsProgress = getBucketsProgressInformation(task);
ItemsProgressInformation itemsProgress = ItemsProgressInformation.fromTask(task);
return new TaskPartProgressInformation(partUri, complete, bucketsProgress, itemsProgress);
}
Expand All @@ -76,11 +76,20 @@ public static TaskPartProgressInformation fromPartProgress(TaskPartProgressType
*/
static TaskPartProgressInformation fromSimpleTask(TaskType task) {
boolean complete = TaskWorkStateUtil.isAllWorkComplete(task);
BucketsProgressInformation bucketsProgress = BucketsProgressInformation.fromWorkState(task.getWorkState());
BucketsProgressInformation bucketsProgress = getBucketsProgressInformation(task);
ItemsProgressInformation itemsProgress = ItemsProgressInformation.fromTask(task);
return new TaskPartProgressInformation(null, complete, bucketsProgress, itemsProgress);
}

private static BucketsProgressInformation getBucketsProgressInformation(TaskType task) {
if (TaskWorkStateUtil.isWorker(task)) {
// Workers do not have complete information about buckets.
return null;
} else {
return BucketsProgressInformation.fromWorkState(task.getWorkState());
}
}

public String getPartOrHandlerUri() {
return partOrHandlerUri;
}
Expand Down
Expand Up @@ -129,6 +129,13 @@ public static boolean isCoordinator(TaskType task) {
return getKind(task) == TaskKindType.COORDINATOR;
}

/**
* @return True if the task is a worker (in the bucketing sense).
*/
public static boolean isWorker(TaskType task) {
return getKind(task) == TaskKindType.WORKER;
}

/**
* @return True if the task is a partitioned master.
*/
Expand Down
Expand Up @@ -10,6 +10,7 @@
import java.io.FileNotFoundException;
import java.net.ConnectException;
import java.util.Collection;
import java.util.List;

import com.evolveum.icf.dummy.resource.ConflictException;
import com.evolveum.icf.dummy.resource.ObjectAlreadyExistsException;
Expand All @@ -21,6 +22,7 @@
import com.evolveum.midpoint.schema.util.task.TaskPartProgressInformation;
import com.evolveum.midpoint.schema.util.task.TaskPerformanceInformation;
import com.evolveum.midpoint.schema.util.task.TaskProgressInformation;
import com.evolveum.midpoint.schema.util.task.TaskTreeUtil;
import com.evolveum.midpoint.task.api.TaskDebugUtil;
import com.evolveum.midpoint.test.TestResource;

Expand Down Expand Up @@ -407,6 +409,23 @@ private void executePartitionedBucketedReconciliation(TestResource<TaskType> rec

TaskPerformanceInformation perf2 = TaskPerformanceInformation.fromTaskTree(rootAfterSuspension2.asObjectable());
displayDumpable("perf after 2nd run", perf2);

PrismObject<TaskType> subtask2 = assertTask(rootAfterSuspension2.asObjectable(), "after 2nd run")
.subtaskForPart(2)
.getObject();
List<TaskType> children2 = TaskTreeUtil.getResolvedSubtasks(subtask2.asObjectable());
if (!children2.isEmpty()) {
TaskType worker = children2.get(0);
assertTask(worker, "worker")
.display()
.structuredProgress()
.display();
TaskProgressInformation progressOfSubtask = TaskProgressInformation.fromTaskTree(worker);
assertTaskProgress(progressOfSubtask, "worker task progress")
.display()
.part(null)
.assertNoBucketInformation(); // MID-7006
}
}

/**
Expand Down Expand Up @@ -513,5 +532,19 @@ private void executeRecomputation(TestResource<TaskType> recomputationTask, Stri

TaskPerformanceInformation perf2 = TaskPerformanceInformation.fromTaskTree(rootAfterSuspension2.asObjectable());
displayDumpable("perf after 2nd run", perf2);

List<TaskType> subtasks = TaskTreeUtil.getResolvedSubtasks(rootAfterSuspension2.asObjectable());
if (!subtasks.isEmpty()) {
TaskType subtask = subtasks.get(0);
assertTask(subtask, "subtask")
.display()
.structuredProgress()
.display();
TaskProgressInformation progressOfSubtask = TaskProgressInformation.fromTaskTree(subtask);
assertTaskProgress(progressOfSubtask, "subtask progress")
.display()
.part(null)
.assertNoBucketInformation(); // MID-7006
}
}
}

0 comments on commit c287d23

Please sign in to comment.