Search in sources :

Example 41 with TaskType

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();
}
Also used : GetOperationOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.GetOperationOptionsType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) OptionObjectSelectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.OptionObjectSelectorType) Holder(javax.xml.ws.Holder) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) Collection(java.util.Collection) SelectorQualifiedGetOptionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionType) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Example 42 with TaskType

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) JobKey(org.quartz.JobKey) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) TaskQuartzImpl(com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) HashSet(java.util.HashSet)

Example 43 with TaskType

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;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) SystemException(com.evolveum.midpoint.util.exception.SystemException) TaskRunResultStatus(com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 44 with TaskType

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;
}
Also used : TaskAddDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskAddDto) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) TaskAddResourcesDto(com.evolveum.midpoint.web.page.admin.server.dto.TaskAddResourcesDto) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 45 with TaskType

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;
}
Also used : TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Aggregations

TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)88 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)63 Test (org.testng.annotations.Test)50 Task (com.evolveum.midpoint.task.api.Task)47 PrismObject (com.evolveum.midpoint.prism.PrismObject)30 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)25 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)23 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)19 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)16 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)15 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 ArrayList (java.util.ArrayList)14 QName (javax.xml.namespace.QName)13 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)11 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)8 Checker (com.evolveum.midpoint.test.Checker)8 ObjectChecker (com.evolveum.midpoint.test.ObjectChecker)8