Skip to content

Commit

Permalink
Progress reporting and statistics in bulk actions. (TODO - in task ta…
Browse files Browse the repository at this point in the history
…ble there is no progress reported yet. Only in task details, if observed at the same node.)
  • Loading branch information
mederly committed Sep 28, 2015
1 parent 6408080 commit 501074c
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 23 deletions.
Expand Up @@ -2523,7 +2523,7 @@ TaskStatePanel.message.timeInfoWithDurationAndAgo={0} ({1} ago - in {2} ms)
TaskStatePanel.objectsProcessedFailure=Objects failed to be processed
TaskStatePanel.objectsProcessedSuccess=Objects successfully processed
TaskStatePanel.objectsTotal=Total objects processed
TaskStatePanel.opResult=Operation result#
TaskStatePanel.opResult=Operation result
TaskStatePanel.progress=Progress
TaskStatePanel.statistics=Operational statistics
TaskStatePanel.subtaskName=Name
Expand Down
Expand Up @@ -16,7 +16,10 @@

package com.evolveum.midpoint.schema.statistics;

import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;
Expand Down Expand Up @@ -55,4 +58,22 @@ public static <O extends ObjectType> String getDisplayName(PrismObject<O> object
return objectable.getClass().getSimpleName() + " " + objectable.getName();
}
}

public static QName getObjectType(ObjectType objectType, PrismContext prismContext) {
if (objectType == null) {
return null;
}
PrismObjectDefinition def = objectType.asPrismObject().getDefinition();
if (def == null) {
Class<? extends Objectable> clazz = objectType.asPrismObject().getCompileTimeClass();
if (clazz == null) {
return null;
}
def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(clazz);
if (def == null) {
return ObjectType.COMPLEX_TYPE;
}
}
return def.getTypeName();
}
}
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.model.api.ScriptExecutionException;
import com.evolveum.midpoint.model.api.ScriptExecutionResult;
import com.evolveum.midpoint.model.api.ScriptingService;
import com.evolveum.midpoint.model.impl.sync.TaskHandlerUtil;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down Expand Up @@ -71,6 +72,8 @@ public TaskRunResult run(Task task) {
}

try {
TaskHandlerUtil.initAllStatistics(task, true, false);
task.setProgress(0);
ScriptExecutionResult executionResult = scriptingService.evaluateExpression(executeScriptProperty.getValue().getValue().getScriptingExpression().getValue(), task, result);
LOGGER.debug("Execution output: {} item(s)", executionResult.getDataOutput().size());
LOGGER.debug("Execution result:\n", executionResult.getConsoleOutput());
Expand All @@ -80,10 +83,13 @@ public TaskRunResult run(Task task) {
result.recordFatalError("Couldn't execute script: " + e.getMessage(), e);
LoggingUtils.logException(LOGGER, "Couldn't execute script", e);
runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.PERMANENT_ERROR);
} finally {
TaskHandlerUtil.storeAllStatistics(task);
}

task.getResult().computeStatus();
runResult.setOperationResult(task.getResult());
runResult.setProgress(task.getProgress()); // incremented directly in actions implementations
return runResult;
}

Expand Down
Expand Up @@ -175,6 +175,7 @@ public ExecutionContext evaluateExpression(ExecuteScriptType executeScript, Task
return evaluateExpression(executeScript.getScriptingExpression().getValue(), task, result);
}

// use in tests only (we need the task at least to report progress/statistics)
public ExecutionContext evaluateExpression(ScriptingExpressionType expression, OperationResult result) throws ScriptExecutionException {
Task task = taskManager.createTaskInstance();
return evaluateExpression(expression, task, result);
Expand Down
Expand Up @@ -61,7 +61,14 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
operationsHelper.applyDelta(createAddDelta(objectType), operationsHelper.createExecutionOptions(raw), context, result);
long started = operationsHelper.recordStart(context, objectType);
try {
operationsHelper.applyDelta(createAddDelta(objectType), operationsHelper.createExecutionOptions(raw), context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex; // TODO think about this
}
context.println("Added " + item.toString() + rawSuffix(raw));
} else {
throw new ScriptExecutionException("Item couldn't be added, because it is not a PrismObject: " + item.toString());
Expand Down
Expand Up @@ -93,7 +93,14 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject && ((PrismObject) item).asObjectable() instanceof FocusType) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), context, result);
long started = operationsHelper.recordStart(context, objectType);
try {
operationsHelper.applyDelta(createDelta(objectType, resources, roles), operationsHelper.createExecutionOptions(raw), context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex; // TODO reconsider this
}
context.println("Modified " + item.toString() + rawSuffix(raw));
} else {
throw new ScriptExecutionException("Item could not be modified, because it is not a PrismObject of FocusType: " + item.toString());
Expand Down
Expand Up @@ -61,7 +61,14 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
operationsHelper.applyDelta(createDeleteDelta(objectType), operationsHelper.createExecutionOptions(raw), context, result);
long started = operationsHelper.recordStart(context, objectType);
try {
operationsHelper.applyDelta(createDeleteDelta(objectType), operationsHelper.createExecutionOptions(raw), context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex; // TODO think about this
}
context.println("Deleted " + item.toString() + rawSuffix(raw));
} else {
throw new ScriptExecutionException("Item couldn't be deleted, because it is not a PrismObject: " + item.toString());
Expand Down
Expand Up @@ -76,9 +76,12 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject && ((PrismObject) item).asObjectable() instanceof ConnectorHostType) {
PrismObject<ConnectorHostType> connectorHostTypePrismObject = (PrismObject) item;
Set<ConnectorType> newConnectors;
long started = operationsHelper.recordStart(context, connectorHostTypePrismObject.asObjectable());
try {
newConnectors = modelService.discoverConnectors(connectorHostTypePrismObject.asObjectable(), context.getTask(), result);
} catch (CommunicationException | SecurityViolationException | SchemaException | ConfigurationException | ObjectNotFoundException e) {
operationsHelper.recordEnd(context, connectorHostTypePrismObject.asObjectable(), started, null);
} catch (CommunicationException | SecurityViolationException | SchemaException | ConfigurationException | ObjectNotFoundException | RuntimeException e) {
operationsHelper.recordEnd(context, connectorHostTypePrismObject.asObjectable(), started, e);
throw new ScriptExecutionException("Couldn't discover connectors from " + connectorHostTypePrismObject, e);
}
context.println("Discovered " + newConnectors.size() + " new connector(s) from " + connectorHostTypePrismObject);
Expand Down
Expand Up @@ -68,14 +68,21 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
if (objectType instanceof FocusType) {
operationsHelper.applyDelta(createEnableDisableDelta((FocusType) objectType, isEnable), context, result);
context.println((isEnable ? "Enabled " : "Disabled ") + item.toString());
} else if (objectType instanceof ShadowType) {
operationsHelper.applyDelta(createEnableDisableDelta((ShadowType) objectType, isEnable), context, result);
context.println((isEnable ? "Enabled " : "Disabled ") + item.toString());
} else {
throw new ScriptExecutionException("Item could not be enabled/disabled, because it is not a FocusType nor ShadowType: " + item.toString());
long started = operationsHelper.recordStart(context, objectType);
try {
if (objectType instanceof FocusType) {
operationsHelper.applyDelta(createEnableDisableDelta((FocusType) objectType, isEnable), context, result);
context.println((isEnable ? "Enabled " : "Disabled ") + item.toString());
} else if (objectType instanceof ShadowType) {
operationsHelper.applyDelta(createEnableDisableDelta((ShadowType) objectType, isEnable), context, result);
context.println((isEnable ? "Enabled " : "Disabled ") + item.toString());
} else {
throw new ScriptExecutionException("Item could not be enabled/disabled, because it is not a FocusType nor ShadowType: " + item.toString());
}
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex;
}
} else {
throw new ScriptExecutionException("Item could not be enabled/disabled, because it is not a PrismObject: " + item.toString());
Expand Down
Expand Up @@ -66,7 +66,14 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
if (item instanceof PrismObject) {
PrismObject<? extends ObjectType> prismObject = (PrismObject) item;
ObjectType objectType = prismObject.asObjectable();
operationsHelper.applyDelta(createDelta(objectType, deltaData), operationsHelper.createExecutionOptions(raw), context, result);
long started = operationsHelper.recordStart(context, objectType);
try {
operationsHelper.applyDelta(createDelta(objectType, deltaData), operationsHelper.createExecutionOptions(raw), context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
throw ex;
}
context.println("Modified " + item.toString() + rawSuffix(raw));
} else {
throw new ScriptExecutionException("Item could not be modified, because it is not a PrismObject: " + item.toString());
Expand Down
Expand Up @@ -58,14 +58,22 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
for (Item item : input.getData()) {
if (item instanceof PrismObject && ((PrismObject) item).asObjectable() instanceof ResourceType) {
PrismObject<ResourceType> resourceTypePrismObject = (PrismObject) item;
ResourceType resourceType = resourceTypePrismObject.asObjectable();
long started = operationsHelper.recordStart(context, resourceType);
ObjectDelta delta = createDelta(resourceTypePrismObject.asObjectable());
if (delta != null) {
operationsHelper.applyDelta(delta, ModelExecuteOptions.createRaw(), context, result);
context.println("Purged schema information from " + item);
output.addItem(operationsHelper.getObject(ResourceType.class, resourceTypePrismObject.getOid(), true, context, result));
} else {
context.println("There's no schema information to be purged in " + item);
output.addItem(resourceTypePrismObject);
try {
if (delta != null) {
operationsHelper.applyDelta(delta, ModelExecuteOptions.createRaw(), context, result);
context.println("Purged schema information from " + item);
output.addItem(operationsHelper.getObject(ResourceType.class, resourceTypePrismObject.getOid(), true, context, result));
} else {
context.println("There's no schema information to be purged in " + item);
output.addItem(resourceTypePrismObject);
}
operationsHelper.recordEnd(context, resourceType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, resourceType, started, ex);
throw ex;
}
} else {
throw new ScriptExecutionException("Couldn't purge resource schema, because input is not a PrismObject<ResourceType>: " + item.toString());
Expand Down
Expand Up @@ -70,14 +70,18 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
for (Item item : input.getData()) {
if (item instanceof PrismObject && FocusType.class.isAssignableFrom(((PrismObject) item).getCompileTimeClass())) {
PrismObject<FocusType> focalPrismObject = (PrismObject) item;
FocusType focusType = focalPrismObject.asObjectable();
long started = operationsHelper.recordStart(context, focusType);
try {
LensContext<FocusType> syncContext = contextFactory.createRecomputeContext(focalPrismObject, context.getTask(), result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Recomputing object {}: context:\n{}", focalPrismObject, syncContext.debugDump());
}
clockwork.run(syncContext, context.getTask(), result);
LOGGER.trace("Recomputing of object {}: {}", focalPrismObject, result.getStatus());
} catch (ObjectNotFoundException|ConfigurationException|SecurityViolationException|PolicyViolationException|ExpressionEvaluationException|ObjectAlreadyExistsException|CommunicationException|SchemaException e) {
operationsHelper.recordEnd(context, focusType, started, null);
} catch (ObjectNotFoundException|ConfigurationException|SecurityViolationException|PolicyViolationException|ExpressionEvaluationException|ObjectAlreadyExistsException|CommunicationException|SchemaException|RuntimeException e) {
operationsHelper.recordEnd(context, focusType, started, e);
throw new ScriptExecutionException("Couldn't recompute object " + focalPrismObject + ": " + e.getMessage(), e);
}
context.println("Recomputed " + item.toString());
Expand Down
Expand Up @@ -71,10 +71,14 @@ public Data execute(ActionExpressionType expression, Data input, ExecutionContex
for (Item item : input.getData()) {
if (item instanceof PrismObject && ((PrismObject) item).asObjectable() instanceof ResourceType) {
PrismObject<ResourceType> resourceTypePrismObject = (PrismObject) item;
ResourceType resourceType = resourceTypePrismObject.asObjectable();
long started = operationsHelper.recordStart(context, resourceType);
OperationResult testResult;
try {
testResult = modelService.testResource(resourceTypePrismObject.getOid(), context.getTask());
} catch (ObjectNotFoundException e) {
operationsHelper.recordEnd(context, resourceType, started, null);
} catch (ObjectNotFoundException|RuntimeException e) {
operationsHelper.recordEnd(context, resourceType, started, e);
throw new ScriptExecutionException("Couldn't test resource " + resourceTypePrismObject, e);
}
result.addSubresult(testResult);
Expand Down

0 comments on commit 501074c

Please sign in to comment.