use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskActivityStateType in project midpoint by Evolveum.
the class RepoConcurrencyTest method test150WorkBucketsReplace.
/**
* Here we test concurrent work bucket delegation using
* {@link RepositoryService#modifyObjectDynamically(Class, String, Collection, ModificationsSupplier, RepoModifyOptions, OperationResult)}
* method.
*/
@Test
public void test150WorkBucketsReplace() throws Exception {
int THREADS = 8;
long DURATION = 30_000L;
TaskType task = new TaskType(prismContext).name("test150").beginActivityState().beginActivity().beginBucketing().bucketsProcessingRole(BucketsProcessingRoleType.COORDINATOR).<ActivityStateType>end().<TaskActivityStateType>end().end();
OperationResult result = new OperationResult("test150WorkBucketsReplace");
String oid = plainRepositoryService.addObject(task.asPrismObject(), null, result);
displayValue("object added", oid);
logger.info("Starting worker threads");
List<WorkerThread> threads = new ArrayList<>();
for (int i = 0; i < THREADS; i++) {
final int threadIndex = i;
WorkerThread thread = new WorkerThread(i) {
@Override
void runOnce(OperationResult result) throws Exception {
ModificationsSupplier<TaskType> modificationSupplier = task -> prismContext.deltaFor(TaskType.class).item(TaskType.F_ACTIVITY_STATE, F_ACTIVITY, F_BUCKETING, F_BUCKET).replaceRealValues(getBucketsToReplace(task)).asItemDeltas();
plainRepositoryService.modifyObjectDynamically(TaskType.class, oid, null, modificationSupplier, null, result);
}
private List<WorkBucketType> getBucketsToReplace(TaskType task) {
List<WorkBucketType> currentBuckets = getCurrentBuckets(task);
List<WorkBucketType> newBuckets = CloneUtil.cloneCollectionMembers(currentBuckets);
newBuckets.add(getNextBucket(currentBuckets));
return newBuckets;
}
private WorkBucketType getNextBucket(List<WorkBucketType> currentBuckets) {
return new WorkBucketType(prismContext).sequentialNumber(getLastBucketNumber(currentBuckets) + 1).state(WorkBucketStateType.DELEGATED).workerRef(String.valueOf(threadIndex), TaskType.COMPLEX_TYPE);
}
private List<WorkBucketType> getCurrentBuckets(TaskType task) {
return task.getActivityState().getActivity().getBucketing().getBucket();
}
private int getLastBucketNumber(List<WorkBucketType> buckets) {
return buckets.stream().mapToInt(WorkBucketType::getSequentialNumber).max().orElse(0);
}
@Override
String description() {
return "Bucket computer thread #" + threadIndex;
}
};
thread.start();
threads.add(thread);
}
waitForThreads(threads, DURATION);
PrismObject<TaskType> taskAfter = plainRepositoryService.getObject(TaskType.class, oid, null, result);
displayValue("task after", taskAfter);
assertCorrectBucketSequence(taskAfter.asObjectable().getActivityState().getActivity().getBucketing().getBucket());
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskActivityStateType in project midpoint by Evolveum.
the class RepoConcurrencyTest method test140WorkBucketsAdd.
/**
* Here we test concurrent work bucket creation using
* {@link RepositoryService#modifyObjectDynamically(Class, String, Collection, ModificationsSupplier, RepoModifyOptions, OperationResult)}
* method.
*/
@Test
public void test140WorkBucketsAdd() throws Exception {
int THREADS = 8;
long DURATION = 30_000L;
TaskType task = new TaskType(prismContext).name("test140").beginActivityState().beginActivity().beginBucketing().bucketsProcessingRole(BucketsProcessingRoleType.COORDINATOR).<ActivityStateType>end().<TaskActivityStateType>end().end();
OperationResult result = new OperationResult("test140WorkBucketsAdd");
String oid = plainRepositoryService.addObject(task.asPrismObject(), null, result);
displayValue("object added", oid);
logger.info("Starting worker threads");
List<WorkerThread> threads = new ArrayList<>();
for (int i = 0; i < THREADS; i++) {
final int threadIndex = i;
WorkerThread thread = new WorkerThread(i) {
@Override
void runOnce(OperationResult result) throws Exception {
ModificationsSupplier<TaskType> modificationSupplier = task -> prismContext.deltaFor(TaskType.class).item(TaskType.F_ACTIVITY_STATE, F_ACTIVITY, F_BUCKETING, F_BUCKET).add(getNextBucket(task)).asItemDeltas();
plainRepositoryService.modifyObjectDynamically(TaskType.class, oid, null, modificationSupplier, null, result);
}
private WorkBucketType getNextBucket(TaskType task) {
int lastBucketNumber = task.getActivityState() != null ? getLastBucketNumber(task.getActivityState().getActivity().getBucketing().getBucket()) : 0;
return new WorkBucketType(prismContext).sequentialNumber(lastBucketNumber + 1).state(WorkBucketStateType.DELEGATED).workerRef(String.valueOf(threadIndex), TaskType.COMPLEX_TYPE);
}
private int getLastBucketNumber(List<WorkBucketType> buckets) {
return buckets.stream().mapToInt(WorkBucketType::getSequentialNumber).max().orElse(0);
}
@Override
String description() {
return "Bucket computer thread #" + threadIndex;
}
};
thread.start();
threads.add(thread);
}
waitForThreads(threads, DURATION);
PrismObject<TaskType> taskAfter = plainRepositoryService.getObject(TaskType.class, oid, null, result);
displayValue("task after", taskAfter);
assertCorrectBucketSequence(taskAfter.asObjectable().getActivityState().getActivity().getBucketing().getBucket());
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskActivityStateType in project midpoint by Evolveum.
the class ActivityTreePurger method purgeInSubtasks.
/**
* Purges activity states in the subtasks. Deletes those subtasks if possible.
*
* @return true if there are no subtasks left
*/
private boolean purgeInSubtasks(Task parent, OperationResult result) throws CommonException {
List<? extends Task> subtasks = parent.listSubtasks(true, result);
for (Iterator<? extends Task> iterator = subtasks.iterator(); iterator.hasNext(); ) {
Task subtask = iterator.next();
TaskActivityStateType taskActivityState = subtask.getActivitiesStateOrClone();
if (taskActivityState == null) {
LOGGER.error("Non-activity related subtask {} of {}. Please resolve manually.", subtask, parent);
continue;
}
boolean canDeleteSubtask = purgeInTasksRecursively(ActivityPath.fromBean(taskActivityState.getLocalRoot()), subtask, result);
if (canDeleteSubtask) {
LOGGER.info("Deleting obsolete subtask {}", subtask);
beans.taskManager.deleteTask(subtask.getOid(), result);
iterator.remove();
}
}
return subtasks.isEmpty();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskActivityStateType in project midpoint by Evolveum.
the class NodeDownCleaner method releaseAllBucketsOfWorker.
/**
* We don't want this task to hold its buckets forever. So let's release them.
*
* (There's a slight risk if the task is restarted in the meanwhile, i.e. before learning that node is down and this
* moment. But let us live with this risk for now.)
*/
private void releaseAllBucketsOfWorker(OperationResult result) throws ObjectNotFoundException, SchemaException {
TaskActivityStateType state = task.getActivitiesStateOrClone();
if (state == null || state.getTaskRole() != TaskRoleType.WORKER) {
return;
}
if (parent == null) {
LOGGER.warn("No parent for worker {} (root {}) ?", task, root);
return;
}
ActivityPath activityPath = ActivityPath.fromBean(Objects.requireNonNull(state.getLocalRoot(), "No local root in " + task));
LOGGER.info("Returning all buckets from {} (coordinator {})", task, parent);
beans.bucketingManager.releaseAllWorkBucketsFromWorker(parent.getOid(), task.getOid(), activityPath, null, result);
}
Aggregations