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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations