Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Apr 1, 2020
2 parents 882a2ce + e0254e2 commit f86ef9d
Show file tree
Hide file tree
Showing 26 changed files with 601 additions and 83 deletions.
Expand Up @@ -621,7 +621,7 @@ public static TaskType createSingleRecurrenceTask(String taskName, QName applica

ObjectReferenceType ownerRef = new ObjectReferenceType();
ownerRef.setOid(owner.getOid());
ownerRef.setType(owner.getFocus().COMPLEX_TYPE);
ownerRef.setType(UserType.COMPLEX_TYPE);
task.setOwnerRef(ownerRef);

task.setBinding(TaskBindingType.LOOSE);
Expand Down
Expand Up @@ -11,6 +11,7 @@
import java.util.*;

import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand Down Expand Up @@ -184,15 +185,18 @@ public static <O extends ObjectType> List<ObjectReferenceType> createObjectRefer
return null;
}

public static String runTask(TaskType taskToRun, Task operationalTask, OperationResult parentResult, PageBase pageBase){
public static <O extends ObjectType> String runTask(TaskType taskToRun, Task operationalTask, OperationResult parentResult, PageBase pageBase){
try {
ObjectDelta<TaskType> delta = DeltaFactory.Object.createAddDelta(taskToRun.asPrismObject());
pageBase.getPrismContext().adopt(delta);
pageBase.getModelService().executeChanges(MiscUtil.createCollection(delta), null,
Collection<ObjectDeltaOperation<?>> deltaOperationRes = pageBase.getModelService().executeChanges(MiscUtil.createCollection(delta), null,
operationalTask, parentResult);
if (StringUtils.isEmpty(delta.getOid()) && deltaOperationRes != null && !deltaOperationRes.isEmpty()){
ObjectDeltaOperation deltaOperation = deltaOperationRes.iterator().next();
delta.setOid(deltaOperation.getObjectDelta().getOid());
}
parentResult.recordInProgress();
parentResult.setBackgroundTaskOid(delta.getOid());
pageBase.showResult(parentResult);
return delta.getOid();
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
Expand Down
Expand Up @@ -11,6 +11,15 @@
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;

import com.evolveum.midpoint.util.exception.*;

import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
Expand Down Expand Up @@ -38,6 +47,9 @@ public class InternalsCountersPanel extends BasePanel<ListView<InternalCounters>
private static final String ID_COUNTER_COUNT_LABEL = "counterCount";
private static final String ID_RESET_THRESHOLD_COUNTER = "resetThresholdCounter";

private static final String DOT_CLASS = InternalsCountersPanel.class.getName() + ".";
private static final String OPERATION_LOAD_TASK = DOT_CLASS + "loadTaskByIdentifier";


public InternalsCountersPanel(String id) {
super(id);
Expand All @@ -58,7 +70,7 @@ protected void onInitialize() {
@Override
protected void populateItem(ListItem<CounterSpecification> item) {
CounterSpecification counter = item.getModelObject();
Label task = new Label(ID_COUNTER_TASK_LABEL, counter.getTaskName());
Label task = new Label(ID_COUNTER_TASK_LABEL, createLabelModel(counter));
item.add(task);

Label policyRule = new Label(ID_COUNTER_POLICY_RULE_LABEL, counter.getPolicyRuleName());
Expand All @@ -73,7 +85,7 @@ protected void populateItem(ListItem<CounterSpecification> item) {

@Override
public void onClick(AjaxRequestTarget target) {
ConfirmationPanel confirmPanel = new ConfirmationPanel(getPageBase().getMainPopupBodyId(), createStringResource("InternalsCountersPanel.reset.confirm.message", counter.getTaskName(), counter.getPolicyRuleName())) {
ConfirmationPanel confirmPanel = new ConfirmationPanel(getPageBase().getMainPopupBodyId(), createStringResource("InternalsCountersPanel.reset.confirm.message", counter.getOid(), counter.getPolicyRuleName())) {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -118,6 +130,27 @@ public String getObject() {
add(countersTable);
}

private IModel<String> createLabelModel(CounterSpecification counter) {
return () -> {
Task operationTask = getPageBase().createSimpleTask(OPERATION_LOAD_TASK);
OperationResult parentResult = operationTask.getResult();
PrismObject<TaskType> taskPrism = null;
try {
taskPrism = getPageBase().getTaskService().getTaskByIdentifier(counter.getOid(), null, operationTask, parentResult);
} catch (SchemaException | CommunicationException | ExpressionEvaluationException | ObjectNotFoundException | ConfigurationException | SecurityViolationException e) {
parentResult.recordPartialError("Failed to load task with identifier: " + counter.getOid() + ". Reason: " + e.getMessage());
}

parentResult.computeStatusIfUnknown();
getPageBase().showResult(parentResult, false);

if (taskPrism == null) {
return counter.getOid();
}
return WebComponentUtil.getName(taskPrism) + "(" + counter.getOid() + ")";
};
}

private IModel<List<CounterSpecification>> createThresholdCounterModel() {
return new IModel<List<CounterSpecification>>() {
private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -340,21 +340,21 @@ private ModelExecuteOptions createOptions() {
private void onMultiUserRequestPerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_REQUEST_ASSIGNMENTS);
Task operationalTask = createSimpleTask(OPERATION_REQUEST_ASSIGNMENTS);

String executionTaskOid = null;
try {
TaskType task = WebComponentUtil.createSingleRecurrenceTask(
createStringResource(OPERATION_REQUEST_ASSIGNMENTS).getString(),
UserType.COMPLEX_TYPE,
getTaskQuery(), prepareDelta(null, result), createOptions(), TaskCategory.EXECUTE_CHANGES, PageAssignmentsList.this);
WebModelServiceUtils.runTask(task, operationalTask, result, PageAssignmentsList.this);
executionTaskOid = WebModelServiceUtils.runTask(task, operationalTask, result, PageAssignmentsList.this);
} catch (SchemaException e) {
result.recordFatalError(result.getOperation(), e);
result.setMessage(createStringResource("PageAssignmentsList.requestError").getString());
LoggingUtils.logUnexpectedException(LOGGER,
"Failed to execute operaton " + result.getOperation(), e);
target.add(getFeedbackPanel());
}
if (hasBackgroundTaskOperation(result)) {
if (hasBackgroundTaskOperation(result) || StringUtils.isNotEmpty(executionTaskOid)) {
result.setMessage(createStringResource("PageAssignmentsList.requestInProgress").getString());
showResult(result);
clearStorage();
Expand Down
Expand Up @@ -42,7 +42,9 @@ public RoleCatalogTabPanel(String id, RoleManagementConfigurationType roleManage

@Override
protected void initLeftSidePanel(){
getRoleCatalogStorage().setSelectedOid(roleCatalogOid);
if (StringUtils.isEmpty(getRoleCatalogStorage().getSelectedOid())) {
getRoleCatalogStorage().setSelectedOid(roleCatalogOid);
}

WebMarkupContainer treePanelContainer = new WebMarkupContainer(ID_TREE_PANEL_CONTAINER);
treePanelContainer.setOutputMarkupId(true);
Expand Down
Expand Up @@ -7,6 +7,7 @@
package com.evolveum.midpoint.model.impl.lens.projector.focus;

import java.util.Collection;
import java.util.stream.Collectors;

import javax.xml.datatype.XMLGregorianCalendar;

Expand Down Expand Up @@ -197,20 +198,22 @@ public DeltaSetTriple<EvaluatedAssignmentImpl<AH>> processAllAssignments() throw
prismContext, task, result);

LOGGER.trace("Task for process: {}", task.debugDumpLazily());
AssignmentType taskAssignment;
if (task.hasAssignments()) {
taskAssignment = new AssignmentType(prismContext);
ObjectReferenceType targetRef = new ObjectReferenceType();
targetRef.asReferenceValue().setObject(task.getUpdatedOrClonedTaskObject());
taskAssignment.setTargetRef(targetRef);
} else {
taskAssignment = null;
}

LOGGER.trace("Task assignment: {}", taskAssignment);
Collection<Task> allTasksToRoot = task.getPathToRootTask(result);
Collection<AssignmentType> taskAssignments = allTasksToRoot.stream()
.filter(taskPath -> taskPath.hasAssignments())
.map(taskPath -> createTaskAssignment(taskPath))
.collect(Collectors.toList());

LOGGER.trace("Task assignment: {}", taskAssignments);

if (taskAssignments.isEmpty()) {
assignmentCollection.collect(focusContext.getObjectCurrent(), focusContext.getObjectOld(), assignmentDelta, forcedAssignments, null);
}

assignmentCollection.collect(focusContext.getObjectCurrent(), focusContext.getObjectOld(), assignmentDelta,
forcedAssignments, taskAssignment);
for (AssignmentType taskAssignment : taskAssignments) {
assignmentCollection.collect(focusContext.getObjectCurrent(), focusContext.getObjectOld(), assignmentDelta, forcedAssignments, taskAssignment);
}

LOGGER.trace("Assignment collection:\n{}", assignmentCollection.debugDumpLazily(1));

Expand All @@ -229,6 +232,14 @@ public DeltaSetTriple<EvaluatedAssignmentImpl<AH>> processAllAssignments() throw
return evaluatedAssignmentTriple;
}

private AssignmentType createTaskAssignment(Task fromTask) {
AssignmentType taskAssignment = new AssignmentType(prismContext);
ObjectReferenceType targetRef = new ObjectReferenceType();
targetRef.asReferenceValue().setObject(fromTask.getUpdatedOrClonedTaskObject());
taskAssignment.setTargetRef(targetRef);
return taskAssignment;
}

private String getNewObjectLifecycleState(LensFocusContext<AH> focusContext) {
PrismObject<AH> focusNew = focusContext.getObjectNew();
AH focusTypeNew = focusNew.asObjectable();
Expand Down
Expand Up @@ -43,9 +43,10 @@ public <O extends ObjectType> void execute(@NotNull ModelContext<O> context, Tas
return;
}

TaskType taskType = task.getUpdatedOrClonedTaskObject().asObjectable();
String id = task.getTaskTreeId(result);

for (EvaluatedPolicyRule policyRule : focusCtx.getPolicyRules()) {
CounterSpecification counterSpec = counterManager.getCounterSpec(taskType, policyRule.getPolicyRuleIdentifier(), policyRule.getPolicyRule());
CounterSpecification counterSpec = counterManager.getCounterSpec(id, policyRule.getPolicyRuleIdentifier(), policyRule.getPolicyRule());
LOGGER.trace("Found counter specification {} for {}", counterSpec, DebugUtil.debugDumpLazily(policyRule));

int counter = 1;
Expand Down
Expand Up @@ -14,8 +14,11 @@

import com.evolveum.midpoint.model.impl.util.AuditHelper;
import com.evolveum.midpoint.prism.query.AndFilter;
import com.evolveum.midpoint.repo.api.PreconditionViolationException;
import com.evolveum.midpoint.repo.common.util.RepoCommonUtils;
import com.evolveum.midpoint.schema.cache.CacheConfigurationManager;
import com.evolveum.midpoint.task.api.*;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.QueryType;
import org.apache.commons.lang.BooleanUtils;
Expand Down Expand Up @@ -61,14 +64,6 @@
import com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus;
import com.evolveum.midpoint.util.Holder;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
Expand Down Expand Up @@ -334,6 +329,15 @@ public TaskWorkBucketProcessingResult run(RunningTask localCoordinatorTask, Work
} catch (ExpressionEvaluationException ex) {
processErrorFinal(runResult, "Expression error", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, localCoordinatorTask, opResult);
return runResult;
} catch (ObjectAlreadyExistsException ex) {
processErrorFinal(runResult, "Object already existis error", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, localCoordinatorTask, opResult);
return runResult;
} catch (PolicyViolationException ex) {
processErrorFinal(runResult, "Policy violation error", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, localCoordinatorTask, opResult);
return runResult;
} catch (PreconditionViolationException ex) {
processErrorFinal(runResult, "Precondition violation error", ex, TaskRunResultStatus.PERMANENT_ERROR, resource, localCoordinatorTask, opResult);
return runResult;
}

AuditEventRecord executionRecord = new AuditEventRecord(AuditEventType.RECONCILIATION, AuditEventStage.EXECUTION);
Expand Down Expand Up @@ -487,7 +491,7 @@ private boolean performResourceReconciliation(PrismObject<ResourceType> resource
ReconciliationTaskResult reconResult, RunningTask localCoordinatorTask,
TaskPartitionDefinitionType partitionDefinition, WorkBucketType workBucket, OperationResult result, boolean intentIsNull)
throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException,
SecurityViolationException, ExpressionEvaluationException {
SecurityViolationException, ExpressionEvaluationException, PreconditionViolationException, PolicyViolationException, ObjectAlreadyExistsException {

boolean interrupted;

Expand Down Expand Up @@ -549,6 +553,11 @@ private boolean performResourceReconciliation(PrismObject<ResourceType> resource
opResult.recordFatalError(e);
throw e;
}

if (handler.getExceptionEncountered() != null) {
RepoCommonUtils.throwException(handler.getExceptionEncountered(), opResult);
}

return !interrupted;
}

Expand Down
Expand Up @@ -17,9 +17,9 @@
*/
public interface CounterManager {

CounterSpecification getCounterSpec(TaskType task, String policyRuleId, PolicyRuleType policyRule);
void cleanupCounters(String taskOid);
CounterSpecification getCounterSpec(String taskId, String policyRuleId, PolicyRuleType policyRule);
void cleanupCounters(String oid);
Collection<CounterSpecification> listCounters();
void removeCounter(CounterSpecification counterSpecification);
void resetCounters(String taskOid);
void resetCounters(String oid);
}
Expand Up @@ -10,7 +10,6 @@
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyThresholdType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

/**
* @author katka
Expand All @@ -21,12 +20,12 @@ public class CounterSpecification implements DebugDumpable {
private int count = 0;
private long counterStart;

private TaskType task;
private String oid;
private PolicyRuleType policyRule;
private String policyRuleId;

public CounterSpecification(TaskType task, String policyRuleId, PolicyRuleType policyRule) {
this.task = task;
public CounterSpecification(String oid, String policyRuleId, PolicyRuleType policyRule) {
this.oid = oid;
this.policyRuleId = policyRuleId;
this.policyRule = policyRule;
}
Expand All @@ -48,16 +47,12 @@ public PolicyThresholdType getPolicyThreshold() {
return policyRule.getPolicyThreshold();
}

public String getTaskName() {
return task.getName().getOrig();
}

public String getPolicyRuleName() {
return policyRule.getName();
}

public String getTaskOid() {
return task.getOid();
public String getOid() {
return oid;
}

public String getPolicyRuleId() {
Expand All @@ -73,7 +68,7 @@ public void reset(long currentTimeMillis) {
@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
sb.append("Counter for: ").append(task).append(", policy rule: ").append(policyRule).append("\n");
sb.append("Counter for: ").append(oid).append(", policy rule: ").append(policyRule).append("\n");
sb.append("Current count: ").append(count).append("\n");
sb.append("Counter start: ").append(XmlTypeConverter.createXMLGregorianCalendar(counterStart)).append("\n");

Expand Down

0 comments on commit f86ef9d

Please sign in to comment.