use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStateType.RUNNABLE in project midpoint by Evolveum.
the class ExportAuditRepositoryAction method execute.
@Override
public void execute() throws Exception {
OperationResult result = new OperationResult(OPERATION_NAME);
OperationStatus operation = new OperationStatus(context, result);
// "+ 2" will be used for consumer and progress reporter
ExecutorService executor = Executors.newFixedThreadPool(options.getMultiThread() + 2);
BlockingQueue<AuditEventRecordType> queue = new LinkedBlockingQueue<>(QUEUE_CAPACITY_PER_THREAD * options.getMultiThread());
List<ExportAuditProducerWorker> producers = createProducers(queue, operation);
log.info("Starting " + OPERATION_SHORT_NAME);
operation.start();
// execute as many producers as there are threads for them
for (int i = 0; i < producers.size() && i < options.getMultiThread(); i++) {
executor.execute(producers.get(i));
}
Thread.sleep(CONSUMERS_WAIT_FOR_START);
executor.execute(new ProgressReporterWorker<>(context, options, queue, operation));
Runnable consumer = createConsumer(queue, operation);
executor.execute(consumer);
// execute rest of the producers
for (int i = options.getMultiThread(); i < producers.size(); i++) {
executor.execute(producers.get(i));
}
executor.shutdown();
boolean awaitResult = executor.awaitTermination(NinjaUtils.WAIT_FOR_EXECUTOR_FINISH, TimeUnit.DAYS);
if (!awaitResult) {
log.error("Executor did not finish before timeout");
}
handleResultOnFinish(operation, "Finished " + OPERATION_SHORT_NAME);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStateType.RUNNABLE in project midpoint by Evolveum.
the class ScheduleNowHelper method scheduleCoordinatorAndWorkersNow.
public void scheduleCoordinatorAndWorkersNow(String coordinatorOid, OperationResult result) throws SchemaException, ObjectNotFoundException {
TaskQuartzImpl coordinatorTask = taskRetriever.getTaskPlain(coordinatorOid, result);
TaskSchedulingStateType state = coordinatorTask.getSchedulingState();
switch(state) {
case CLOSED:
case READY:
// hoping that the task handler will do what is needed (i.e. recreate or restart workers)
scheduleTaskNow(coordinatorTask, result);
break;
case WAITING:
// this means that workers are either busy (runnable) or are suspended; administrator should do something with that
String msg1 = "Coordinator " + coordinatorTask + " cannot be run now, because it is in WAITING scheduling state. " + "Please check and resolve state of its worker tasks.";
LOGGER.error(msg1);
result.recordFatalError(msg1);
break;
case SUSPENDED:
String msg2 = "Coordinator " + coordinatorTask + " cannot be run now, because it is in SUSPENDED state. " + "Please use appropriate method to schedule its execution.";
LOGGER.error(msg2);
result.recordFatalError(msg2);
break;
default:
throw new IllegalStateException("Coordinator " + coordinatorTask + " is in unsupported state: " + state);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStateType.RUNNABLE in project midpoint by Evolveum.
the class UnpauseHelper method unpauseTask.
boolean unpauseTask(TaskQuartzImpl task, OperationResult result) throws ObjectNotFoundException, SchemaException, PreconditionViolationException {
// The closeTask method is OK even if the task has become suspended in the meanwhile.
if (task.getSchedulingState() != TaskSchedulingStateType.WAITING) {
String message = "Attempted to unpause a task that is not in the WAITING state (task = " + task + ", scheduling state = " + task.getSchedulingState();
LOGGER.error(message);
result.recordFatalError(message);
return false;
}
TaskUnpauseActionType action = getUnpauseAction(task);
switch(action) {
case EXECUTE_IMMEDIATELY:
LOGGER.debug("Unpausing task using 'executeImmediately' action (scheduling it now): {}", task);
scheduleNowHelper.scheduleWaitingTaskNow(task, result);
break;
case RESCHEDULE:
if (task.isRecurring()) {
LOGGER.debug("Unpausing recurring task using 'reschedule' action (making it runnable): {}", task);
makeWaitingTaskRunnable(task, result);
} else {
LOGGER.debug("Unpausing task using 'reschedule' action (closing it, because the task is single-run): {}", task);
closeHelper.closeTask(task, result);
}
break;
case CLOSE:
LOGGER.debug("Unpausing task using 'close' action: {}", task);
closeHelper.closeTask(task, result);
break;
default:
throw new IllegalStateException("Unsupported unpause action: " + action);
}
return true;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStateType.RUNNABLE in project midpoint by Evolveum.
the class WebComponentUtil method createMenuItemsFromActions.
@NotNull
public static List<InlineMenuItem> createMenuItemsFromActions(@NotNull List<GuiActionType> actions, String operation, PageBase pageBase, @NotNull Supplier<Collection<? extends ObjectType>> selectedObjectsSupplier) {
List<InlineMenuItem> menuItems = new ArrayList<>();
actions.forEach(action -> {
if (action.getTaskTemplateRef() == null) {
return;
}
String templateOid = action.getTaskTemplateRef().getOid();
if (StringUtils.isEmpty(templateOid)) {
return;
}
String label = action.getDisplay() != null && PolyStringUtils.isNotEmpty(action.getDisplay().getLabel()) ? action.getDisplay().getLabel().getOrig() : action.getName();
menuItems.add(new InlineMenuItem(Model.of(label)) {
private static final long serialVersionUID = 1L;
@Override
public InlineMenuItemAction initAction() {
return new ColumnMenuAction<SelectableBean<ObjectType>>() {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
OperationResult result = new OperationResult(operation);
try {
Collection<String> oids;
if (getRowModel() != null) {
oids = Collections.singletonList(getRowModel().getObject().getValue().getOid());
} else {
oids = CollectionUtils.emptyIfNull(selectedObjectsSupplier.get()).stream().filter(o -> o.getOid() != null).map(o -> o.getOid()).collect(Collectors.toSet());
}
if (!oids.isEmpty()) {
@NotNull Item<PrismValue, ItemDefinition> extensionQuery = prepareExtensionValues(oids);
MidPointPrincipal principal = pageBase.getPrincipal();
if (principal == null) {
throw new SecurityViolationException("No current user");
}
TaskType newTask = pageBase.getModelService().getObject(TaskType.class, templateOid, createCollection(createExecutionPhase()), pageBase.createSimpleTask(operation), result).asObjectable();
newTask.setName(PolyStringType.fromOrig(newTask.getName().getOrig() + " " + (int) (Math.random() * 10000)));
newTask.setOid(null);
newTask.setTaskIdentifier(null);
newTask.setOwnerRef(createObjectRef(principal.getFocus()));
newTask.setExecutionState(RUNNABLE);
newTask.setSchedulingState(READY);
newTask.asPrismObject().getOrCreateExtension().add(extensionQuery);
ObjectSetBasedWorkDefinitionType workDef = ObjectSetUtil.getObjectSetDefinitionFromTask(newTask);
QueryType query = (QueryType) extensionQuery.getRealValue();
ObjectSetType objectSet = workDef.getObjects();
if (objectSet == null) {
objectSet = new ObjectSetType();
objectSet.setType(ObjectType.COMPLEX_TYPE);
}
objectSet.setQuery(query);
workDef.setObjects(objectSet);
ObjectDelta<TaskType> delta = DeltaFactory.Object.createAddDelta(newTask.asPrismObject());
Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = saveTask(delta, result, pageBase);
String newTaskOid = ObjectDeltaOperation.findAddDeltaOid(executedChanges, newTask.asPrismObject());
newTask.setOid(newTaskOid);
newTask.setTaskIdentifier(newTaskOid);
result.setInProgress();
result.setBackgroundTaskOid(newTask.getOid());
} else {
result.recordWarning(pageBase.createStringResource("WebComponentUtil.message.createMenuItemsFromActions.warning").getString());
}
} catch (Exception ex) {
result.recordFatalError(result.getOperation(), ex);
target.add(pageBase.getFeedbackPanel());
} finally {
pageBase.showResult(result);
target.add(pageBase.getFeedbackPanel());
}
}
};
}
/**
* Extension values are task-dependent. Therefore, in the future we will probably make
* this behaviour configurable. For the time being we assume that the task template will be
* of "iterative task handler" type and so it will expect mext:objectQuery extension property.
*
* FIXME
*/
@NotNull
private Item<PrismValue, ItemDefinition> prepareExtensionValues(Collection<String> oids) throws SchemaException {
PrismContext prismContext = pageBase.getPrismContext();
ObjectQuery objectQuery = prismContext.queryFor(ObjectType.class).id(oids.toArray(new String[0])).build();
QueryType queryBean = pageBase.getQueryConverter().createQueryType(objectQuery);
PrismContainerDefinition<?> extDef = PrismContext.get().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(TaskType.class).findContainerDefinition(TaskType.F_EXTENSION);
ItemDefinition<Item<PrismValue, ItemDefinition>> def = extDef != null ? extDef.findItemDefinition(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY) : null;
if (def == null) {
throw new SchemaException("No definition of " + SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY + " in the extension");
}
Item<PrismValue, ItemDefinition> extensionItem = def.instantiate();
extensionItem.add(prismContext.itemFactory().createValue(queryBean));
return extensionItem;
}
});
});
return menuItems;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStateType.RUNNABLE in project midpoint by Evolveum.
the class ClockworkMedic method partialExecute.
public void partialExecute(String baseComponentName, ProjectorComponentRunnable runnable, Supplier<PartialProcessingTypeType> optionSupplier, Class<?> executingClass, LensContext<?> context, LensProjectionContext projectionContext, OperationResult initialParentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException, ExpressionEvaluationException, ObjectAlreadyExistsException, ConflictDetectedException {
context.checkAbortRequested();
OperationResult parentResult;
if (initialParentResult == null) {
LOGGER.warn("No parentResult in ClockworkMedic.partialExecute! Creating dummy one");
parentResult = new OperationResult(ClockworkMedic.class.getName() + ".partialExecute");
} else {
parentResult = initialParentResult;
}
String componentName;
if (projectionContext != null) {
componentName = baseComponentName + " " + projectionContext.getHumanReadableName();
} else {
componentName = baseComponentName;
}
ClockworkInspector clockworkInspector = getClockworkInspector();
PartialProcessingTypeType option = optionSupplier.get();
if (option == PartialProcessingTypeType.SKIP) {
LOGGER.debug("Skipping projector component {} because partial execution option is set to {}", componentName, option);
if (clockworkInspector != null) {
clockworkInspector.projectorComponentSkip(componentName);
}
} else {
String operationName = executingClass.getName() + "." + baseComponentName;
String qualifier = context.getOperationQualifier();
if (projectionContext != null) {
qualifier += "." + projectionContext.getResourceOid() + "." + projectionContext.getResourceShadowDiscriminator().getKind() + "." + projectionContext.getResourceShadowDiscriminator().getIntent();
}
OperationResult result = parentResult.subresult(operationName).addQualifier(qualifier).build();
ProjectorComponentTraceType trace;
if (result.isTracingAny(ProjectorComponentTraceType.class)) {
trace = new ProjectorComponentTraceType();
if (result.isTracingNormal(ProjectorComponentTraceType.class)) {
trace.setInputLensContextText(context.debugDump());
}
trace.setInputLensContext(context.toLensContextType(getExportType(trace, result)));
if (projectionContext != null) {
trace.setResourceShadowDiscriminator(LensUtil.createDiscriminatorBean(projectionContext.getResourceShadowDiscriminator(), context));
}
result.addTrace(trace);
} else {
trace = null;
}
try {
LOGGER.trace("Projector component started: {}", componentName);
if (clockworkInspector != null) {
clockworkInspector.projectorComponentStart(componentName);
}
runnable.run(result);
LOGGER.trace("Projector component finished: {}", componentName);
} catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException | PolicyViolationException | ExpressionEvaluationException | ObjectAlreadyExistsException | ConflictDetectedException | RuntimeException | Error e) {
LOGGER.trace("Projector component error: {}: {}: {}", componentName, e.getClass().getSimpleName(), e.getMessage());
result.recordFatalError(e);
throw e;
} finally {
result.computeStatusIfUnknown();
if (trace != null) {
if (result.isTracingNormal(ProjectorComponentTraceType.class)) {
trace.setOutputLensContextText(context.debugDump());
}
trace.setOutputLensContext(context.toLensContextType(getExportType(trace, result)));
}
if (clockworkInspector != null) {
clockworkInspector.projectorComponentFinish(componentName);
}
}
}
}
Aggregations