/
WaitForSubtasksByPollingTaskHandler.java
110 lines (92 loc) · 4.36 KB
/
WaitForSubtasksByPollingTaskHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.task.quartzimpl.handlers;
import java.util.List;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskHandler;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.task.api.TaskRunResult;
import com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus;
import com.evolveum.midpoint.task.quartzimpl.TaskManagerQuartzImpl;
import com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
/**
* @author Pavol Mederly
*
*/
@Deprecated
public class WaitForSubtasksByPollingTaskHandler implements TaskHandler {
private static final transient Trace LOGGER = TraceManager.getTrace(WaitForSubtasksByPollingTaskHandler.class);
public static final String HANDLER_URI = "http://midpoint.evolveum.com/xml/ns/public/task/wait-for-subtasks-polling/handler-3";
private static WaitForSubtasksByPollingTaskHandler instance = null;
private TaskManagerQuartzImpl taskManagerImpl;
private WaitForSubtasksByPollingTaskHandler() {}
public static void instantiateAndRegister(TaskManagerQuartzImpl taskManager) {
if (instance == null)
instance = new WaitForSubtasksByPollingTaskHandler();
taskManager.registerHandler(HANDLER_URI, instance);
instance.taskManagerImpl = taskManager;
}
@Override
public TaskRunResult run(Task task) {
OperationResult opResult = new OperationResult(WaitForSubtasksByPollingTaskHandler.class.getName()+".run");
TaskRunResult runResult = new TaskRunResult();
LOGGER.info("WaitForSubtasksByPollingTaskHandler run starting; in task " + task.getName());
List<PrismObject<TaskType>> subtasks = null;
try {
subtasks = ((TaskQuartzImpl) task).listSubtasksRaw(opResult);
} catch (SchemaException e) {
throw new SystemException("Couldn't list subtasks of " + task + " due to schema exception", e);
}
LOGGER.info("Number of subtasks found: " + subtasks.size() + "; task = {}", task);
boolean allClosed = true;
for (PrismObject<TaskType> t : subtasks) {
if (t.asObjectable().getExecutionStatus() != TaskExecutionStatusType.CLOSED) {
LOGGER.info("Subtask " + t.getOid() + "/" + t.asObjectable().getName() + " is not closed, it is " + t.asObjectable().getExecutionStatus() + ", for task {}", task);
allClosed = false;
break;
}
}
TaskRunResultStatus status;
if (allClosed) {
LOGGER.info("All subtasks are closed, finishing waiting for them; task = {}", task);
status = TaskRunResultStatus.FINISHED_HANDLER;
} else {
status = TaskRunResultStatus.FINISHED;
}
runResult.setRunResultStatus(status);
LOGGER.info("WaitForSubtasksByPollingTaskHandler run finishing; in task " + task.getName());
return runResult;
}
@Override
public Long heartbeat(Task task) {
return null; // not to overwrite progress information!
}
@Override
public void refreshStatus(Task task) {
}
@Override
public String getCategoryName(Task task) {
return null; // hopefully we will never need to derive category from this handler! (category is filled-in when persisting tasks)
}
}