Search in sources :

Example 6 with TaskRunResult

use of com.evolveum.midpoint.task.api.TaskRunResult in project midpoint by Evolveum.

the class ReportCreateTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    // TODO Auto-generated method stub
    OperationResult parentResult = task.getResult();
    OperationResult result = parentResult.createSubresult(ReportCreateTaskHandler.class.getSimpleName() + ".run");
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(result);
    recordProgress(task, 0, result);
    long progress = task.getProgress();
    JRSwapFile swapFile = null;
    // http://community.jaspersoft.com/wiki/virtualizers-jasperreports
    JRAbstractLRUVirtualizer virtualizer = null;
    try {
        ReportType parentReport = objectResolver.resolve(task.getObjectRef(), ReportType.class, null, "resolving report", task, result);
        Map<String, Object> parameters = completeReport(parentReport, task, result);
        JasperReport jasperReport = ReportTypeUtil.loadJasperReport(parentReport);
        LOGGER.trace("compile jasper design, create jasper report : {}", jasperReport);
        PrismContainer<ReportParameterType> reportParams = (PrismContainer) task.getExtensionItem(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
        if (reportParams != null) {
            PrismContainerValue<ReportParameterType> reportParamsValues = reportParams.getValue();
            List<Item<?, ?>> items = reportParamsValues.getItems();
            if (items != null) {
                for (Item item : items) {
                    PrismProperty pp = (PrismProperty) item;
                    String paramName = ItemPath.getName(pp.getPath().lastNamed()).getLocalPart();
                    Object value = null;
                    if (isSingleValue(paramName, jasperReport.getParameters())) {
                        value = pp.getRealValues().iterator().next();
                    } else {
                        value = pp.getRealValues();
                    }
                    parameters.put(paramName, value);
                }
            }
        }
        String virtualizerS = parentReport.getVirtualizer();
        Integer virtualizerKickOn = parentReport.getVirtualizerKickOn();
        Integer maxPages = parentReport.getMaxPages();
        Integer timeout = parentReport.getTimeout();
        if (maxPages != null && maxPages > 0) {
            LOGGER.trace("Setting hardlimit on number of report pages: " + maxPages);
            jasperReport.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES_ENABLED, Boolean.TRUE.toString());
            jasperReport.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES, String.valueOf(maxPages));
        }
        if (timeout != null && timeout > 0) {
            LOGGER.trace("Setting timeout on report execution [ms]: " + timeout);
            jasperReport.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT_ENABLED, Boolean.TRUE.toString());
            jasperReport.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT, String.valueOf(timeout));
        }
        if (virtualizerS != null && virtualizerKickOn != null && virtualizerKickOn > 0) {
            String virtualizerClassName = JASPER_VIRTUALIZER_PKG + "." + virtualizerS;
            try {
                Class<?> clazz = Class.forName(virtualizerClassName);
                if (clazz.equals(JRSwapFileVirtualizer.class)) {
                    swapFile = new JRSwapFile(TEMP_DIR, 4096, 200);
                    virtualizer = new JRSwapFileVirtualizer(virtualizerKickOn, swapFile);
                } else if (clazz.equals(JRGzipVirtualizer.class)) {
                    virtualizer = new JRGzipVirtualizer(virtualizerKickOn);
                } else if (clazz.equals(JRFileVirtualizer.class)) {
                    virtualizer = new JRFileVirtualizer(virtualizerKickOn, TEMP_DIR);
                } else {
                    throw new ClassNotFoundException("No support for virtualizer class: " + clazz.getName());
                }
                LOGGER.trace("Setting explicit Jasper virtualizer: " + virtualizer);
                virtualizer.setReadOnly(false);
                parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
            } catch (ClassNotFoundException e) {
                LOGGER.error("Cannot find Jasper virtualizer: " + e.getMessage());
            }
        }
        LOGGER.trace("All Report parameters : {}", parameters);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
        LOGGER.trace("fill report : {}", jasperPrint);
        String reportFilePath = generateReport(parentReport, jasperPrint);
        LOGGER.trace("generate report : {}", reportFilePath);
        saveReportOutputType(reportFilePath, parentReport, task, result);
        LOGGER.trace("create report output type : {}", reportFilePath);
        result.computeStatus();
    } catch (Exception ex) {
        LOGGER.error("CreateReport: {}", ex.getMessage(), ex);
        result.recordFatalError(ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } finally {
        if (swapFile != null) {
            swapFile.dispose();
        }
        if (virtualizer != null) {
            virtualizer.cleanup();
        }
    }
    // This "run" is finished. But the task goes on ...
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    runResult.setProgress(progress);
    LOGGER.trace("CreateReportTaskHandler.run stopping");
    return runResult;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) JasperReport(net.sf.jasperreports.engine.JasperReport) Item(com.evolveum.midpoint.prism.Item) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) JRFileVirtualizer(net.sf.jasperreports.engine.fill.JRFileVirtualizer) ReportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType) ReportParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType) JRSwapFileVirtualizer(net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JRSwapFile(net.sf.jasperreports.engine.util.JRSwapFile) JRAbstractLRUVirtualizer(net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer) JRGzipVirtualizer(net.sf.jasperreports.engine.fill.JRGzipVirtualizer) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException) JRException(net.sf.jasperreports.engine.JRException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 7 with TaskRunResult

use of com.evolveum.midpoint.task.api.TaskRunResult 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 8 with TaskRunResult

use of com.evolveum.midpoint.task.api.TaskRunResult in project midpoint by Evolveum.

the class MockLongTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    long progress = task.getProgress();
    LOGGER.info("MockLong.run starting (id = {}, progress = {})", id, progress);
    OperationResult opResult = new OperationResult(MockLongTaskHandler.class.getName() + ".run");
    TaskRunResult runResult = new TaskRunResult();
    while (task.canRun()) {
        progress++;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            LOGGER.info("Interrupted: exiting", e);
            break;
        }
    }
    opResult.recordSuccess();
    runResult.setOperationResult(opResult);
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    runResult.setProgress(progress);
    LOGGER.info("MockLong.run stopping; progress = {}", progress);
    return runResult;
}
Also used : TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 9 with TaskRunResult

use of com.evolveum.midpoint.task.api.TaskRunResult in project midpoint by Evolveum.

the class MockParallelTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    LOGGER.info("MockParallelTaskHandler.run starting (id = " + id + ")");
    OperationResult opResult = new OperationResult(MockParallelTaskHandler.class.getName() + ".run");
    TaskRunResult runResult = new TaskRunResult();
    PrismProperty<Integer> duration = task.getExtensionProperty(DURATION_QNAME);
    Integer durationValue = null;
    if (duration != null) {
        durationValue = duration.getRealValue();
    }
    LOGGER.info("Duration value = {}", durationValue);
    // we create and start some subtasks
    for (int i = 0; i < NUM_SUBTASKS; i++) {
        MyLightweightTaskHandler handler = new MyLightweightTaskHandler(durationValue);
        TaskQuartzImpl subtask = (TaskQuartzImpl) task.createSubtask(handler);
        assertTrue("Subtask is not transient", subtask.isTransient());
        assertTrue("Subtask is not asynchronous", subtask.isAsynchronous());
        assertTrue("Subtask is not a LAT", subtask.isLightweightAsynchronousTask());
        assertEquals("Subtask has a wrong lightweight handler", handler, subtask.getLightweightTaskHandler());
        assertTrue("Subtask is not in LAT list of parent", task.getLightweightAsynchronousSubtasks().contains(subtask));
        assertFalse("Subtask is in Running LAT list of parent", task.getRunningLightweightAsynchronousSubtasks().contains(subtask));
        assertFalse("Subtask is marked as already started", subtask.lightweightHandlerStartRequested());
        subtask.startLightweightHandler();
        assertTrue("Subtask is not in Running LAT list of parent", task.getRunningLightweightAsynchronousSubtasks().contains(subtask));
        assertTrue("Subtask is not marked as already started", subtask.lightweightHandlerStartRequested());
    }
    opResult.recordSuccess();
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    runResult.setProgress(task.getProgress() + 1);
    runResult.setOperationResult(opResult);
    hasRun = true;
    lastTaskExecuted = task;
    LOGGER.info("MockParallelTaskHandler.run stopping");
    return runResult;
}
Also used : TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 10 with TaskRunResult

use of com.evolveum.midpoint.task.api.TaskRunResult in project midpoint by Evolveum.

the class MockCycleTaskHandler method run.

/* (non-Javadoc)
      * @see com.evolveum.midpoint.task.api.TaskHandler#run(com.evolveum.midpoint.task.api.Task)
      */
@Override
public TaskRunResult run(Task task) {
    LOGGER.info("MockCycle.run starting");
    long progress = task.getProgress();
    OperationResult opResult = new OperationResult(MockCycleTaskHandler.class.getName() + ".run");
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    // TODO
    progress++;
    opResult.recordSuccess();
    // This "run" is finished. But the task goes on ... (if finishTheHandler == false)
    runResult.setRunResultStatus(finishTheHandler ? TaskRunResultStatus.FINISHED_HANDLER : TaskRunResultStatus.FINISHED);
    runResult.setProgress(progress);
    LOGGER.info("MockCycle.run stopping");
    return runResult;
}
Also used : TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

TaskRunResult (com.evolveum.midpoint.task.api.TaskRunResult)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 AccessCertificationCampaignType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)2 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)2 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)2 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)1 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)1 CertificationHandler (com.evolveum.midpoint.certification.impl.handlers.CertificationHandler)1