use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method listTasks.
protected Collection<TaskType> listTasks() throws SAXException, IOException, FaultMessage {
SelectorQualifiedGetOptionsType operationOptions = new SelectorQualifiedGetOptionsType();
// Let's say we want to retrieve tasks' next scheduled time (because this may be a costly operation if
// JDBC based quartz scheduler is used, the fetching of this attribute has to be explicitly requested)
SelectorQualifiedGetOptionType getNextScheduledTimeOption = new SelectorQualifiedGetOptionType();
// prepare a selector (described by path) + options (saying to retrieve that attribute)
OptionObjectSelectorType selector = new OptionObjectSelectorType();
selector.setPath(ModelClientUtil.createItemPathType("nextRunStartTimestamp"));
getNextScheduledTimeOption.setSelector(selector);
GetOperationOptionsType selectorOptions = new GetOperationOptionsType();
selectorOptions.setRetrieve(RetrieveOptionType.INCLUDE);
getNextScheduledTimeOption.setOptions(selectorOptions);
// add newly created option to the list of operation options
operationOptions.getOption().add(getNextScheduledTimeOption);
Holder<ObjectListType> objectListHolder = new Holder<ObjectListType>();
Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
modelPort.searchObjects(ModelClientUtil.getTypeQName(TaskType.class), null, operationOptions, objectListHolder, resultHolder);
ObjectListType objectList = objectListHolder.value;
return (Collection) objectList.getObject();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.
the class TaskSynchronizer method synchronizeJobStores.
/**
* Checks for consistency between Quartz job store and midPoint repository.
* In case of conflict, the latter is taken as authoritative source.
*
* (For RAM Job Store, running this method at startup effectively means that tasks from midPoint repo are imported into Quartz job store.)
*
*/
boolean synchronizeJobStores(OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(this.getClass().getName() + ".synchronizeJobStores");
Scheduler scheduler = taskManager.getExecutionManager().getQuartzScheduler();
LOGGER.info("Synchronizing Quartz job store with midPoint repository.");
List<PrismObject<TaskType>> tasks;
try {
tasks = getRepositoryService().searchObjects(TaskType.class, new ObjectQuery(), null, result);
} catch (SchemaException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Synchronization cannot be done, because tasks cannot be listed from the repository.", e);
return false;
}
LOGGER.trace("There are {} task(s) in repository", tasks.size());
// check consistency of tasks present in repo
Set<String> oidsInRepo = new HashSet<>();
int processed = 0;
int changed = 0;
int errors = 0;
for (PrismObject<TaskType> taskPrism : tasks) {
if (taskPrism.getOid() == null) {
LOGGER.error("Skipping task with no OID: {}", taskPrism);
errors++;
continue;
}
oidsInRepo.add(taskPrism.getOid());
TaskQuartzImpl task;
try {
// in order for the task to be "fresh"
task = (TaskQuartzImpl) taskManager.getTask(taskPrism.getOid(), result);
if (synchronizeTask(task, result)) {
// todo are we sure that we increment this counter only for successfully processed tasks? we hope so :)
changed++;
}
} catch (SchemaException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Task Manager cannot synchronize task {} due to schema exception.", e, taskPrism.getOid());
} catch (ObjectNotFoundException e) {
LoggingUtils.logException(LOGGER, "Task Manager cannot synchronize task {} because it does not exist", e, taskPrism.getOid());
}
if (result.getLastSubresultStatus() == OperationResultStatus.SUCCESS) {
processed++;
} else {
errors++;
}
}
// remove non-existing tasks
int removed = 0;
Set<JobKey> jobs = null;
try {
jobs = new HashSet<>(scheduler.getJobKeys(jobGroupEquals(JobKey.DEFAULT_GROUP)));
} catch (SchedulerException e) {
String message = "Cannot list jobs from Quartz scheduler, skipping second part of synchronization procedure.";
LoggingUtils.logUnexpectedException(LOGGER, message, e);
result.recordPartialError(message, e);
}
if (jobs != null) {
LOGGER.trace("There are {} job(s) in Quartz job store", jobs.size());
for (JobKey job : jobs) {
if (!oidsInRepo.contains(job.getName()) && !RemoteNodesManager.STARTER_JOB_KEY.equals(job)) {
LOGGER.info("Task " + job.getName() + " is not in repository, removing from Quartz job store.");
try {
scheduler.deleteJob(job);
removed++;
} catch (SchedulerException e) {
String message = "Cannot remove job " + job.getName() + " from Quartz job store";
LoggingUtils.logUnexpectedException(LOGGER, message, e);
result.createSubresult("deleteQuartzJob").recordPartialError(message, e);
errors++;
}
}
}
}
String resultMessage = "Synchronization of midpoint and Quartz task store finished. " + processed + " task(s) existing in midPoint repository successfully processed, resulting in " + changed + " updated Quartz job(s). " + removed + " task(s) removed from Quartz job store. Processing of " + errors + " task(s) failed.";
LOGGER.info(resultMessage);
if (result.isUnknown()) {
result.recordStatus(OperationResultStatus.SUCCESS, resultMessage);
}
return true;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.
the class WaitForSubtasksByPollingTaskHandler method run.
@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;
}
// not to overwrite task's result
runResult.setOperationResult(null);
// not to overwrite task's progress
runResult.setProgress(task.getProgress());
runResult.setRunResultStatus(status);
LOGGER.info("WaitForSubtasksByPollingTaskHandler run finishing; in task " + task.getName());
return runResult;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.
the class PageTaskAdd method loadTask.
private TaskAddDto loadTask(TaskType taskType) {
TaskAddDto taskAdd = new TaskAddDto();
taskAdd.setCategory(taskType.getCategory());
PrismProperty<ShadowKindType> pKind;
try {
pKind = taskType.asPrismObject().findOrCreateProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND));
taskAdd.setKind(pKind.getRealValue());
} catch (SchemaException e) {
warn("Could not set kind for new task : " + e.getMessage());
}
PrismProperty<String> pIntent;
try {
pIntent = taskType.asPrismObject().findOrCreateProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT));
taskAdd.setIntent(pIntent.getRealValue());
} catch (SchemaException e) {
warn("Could not set intent for new task : " + e.getMessage());
}
PrismProperty<QName> pObjectClass;
try {
pObjectClass = taskType.asPrismObject().findOrCreateProperty(new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME));
QName objectClass = pObjectClass.getRealValue();
if (objectClass != null) {
taskAdd.setObjectClass(objectClass.getLocalPart());
}
} catch (SchemaException e) {
warn("Could not set obejctClass for new task : " + e.getMessage());
}
ObjectReferenceType ref = taskType.getObjectRef();
if (ref != null) {
TaskAddResourcesDto resource = new TaskAddResourcesDto(ref.getOid(), WebComponentUtil.getName(ref));
taskAdd.setResource(resource);
}
return taskAdd;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType in project midpoint by Evolveum.
the class PageTaskEdit method loadObjectWrapper.
protected ObjectWrapper<TaskType> loadObjectWrapper(PrismObject<TaskType> object, Task task, OperationResult result) {
ObjectWrapper<TaskType> wrapper;
ObjectWrapperFactory owf = new ObjectWrapperFactory(this);
try {
// just to be sure (after deserialization the context is missing in this object)
object.revive(getPrismContext());
wrapper = owf.createObjectWrapper("pageAdminFocus.focusDetails", null, object, ContainerStatus.MODIFYING, task);
} catch (Exception ex) {
result.recordFatalError("Couldn't get user.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user", ex);
wrapper = owf.createObjectWrapper("pageAdminFocus.focusDetails", null, object, null, null, ContainerStatus.MODIFYING, false);
}
showResult(wrapper.getResult(), false);
return wrapper;
}
Aggregations