Skip to content

Commit

Permalink
(Not much successful) attempts to make OperationResult for reconcilia…
Browse files Browse the repository at this point in the history
…tion task handler more meaningful.
  • Loading branch information
mederly committed Dec 2, 2016
1 parent 34564dd commit 1ca7614
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 44 deletions.
Expand Up @@ -94,36 +94,30 @@ public class ReconciliationTaskHandler implements TaskHandler {
*/
private ReconciliationTaskResultListener reconciliationTaskResultListener;

@Autowired(required = true)
@Autowired
private TaskManager taskManager;

@Autowired(required = true)
@Autowired
private ProvisioningService provisioningService;

@Autowired(required = true)
@Autowired
@Qualifier("cacheRepositoryService")
private RepositoryService repositoryService;

@Autowired(required = true)
@Autowired
private PrismContext prismContext;

@Autowired(required = true)
@Autowired
private ChangeNotificationDispatcher changeNotificationDispatcher;

@Autowired(required = true)
@Autowired
private AuditService auditService;

@Autowired(required = true)
@Autowired
private Clock clock;

private static final transient Trace LOGGER = TraceManager.getTrace(ReconciliationTaskHandler.class);

private static final int SEARCH_MAX_SIZE = 100;

private static final int MAX_ITERATIONS = 10;

private static final int BLOCK_SIZE = 20;

public ReconciliationTaskResultListener getReconciliationTaskResultListener() {
return reconciliationTaskResultListener;
}
Expand Down Expand Up @@ -320,11 +314,11 @@ public TaskRunResult runInternal(Task coordinatorTask) {
long resourceReconTime = afterResourceReconTimestamp - beforeResourceReconTimestamp;
long shadowReconTime = afterShadowReconTimestamp - afterResourceReconTimestamp;
LOGGER.info("Done executing reconciliation of resource {}, object class {}, Etime: {} ms (un-ops: {}, resource: {}, shadow: {})",
new Object[]{resource, objectclassDef,
etime,
unOpsTime,
resourceReconTime,
shadowReconTime});
resource, objectclassDef,
etime,
unOpsTime,
resourceReconTime,
shadowReconTime);

reconResult.setRunResult(runResult);
if (reconciliationTaskResultListener != null) {
Expand Down Expand Up @@ -459,7 +453,7 @@ private boolean performResourceReconciliation(PrismObject<ResourceType> resource

ObjectQuery query = objectclassDef.createShadowSearchQuery(resource.getOid());

OperationResult searchResult = new OperationResult(OperationConstants.RECONCILIATION+".searchIterative");
OperationResult searchResult = opResult.createSubresult(OperationConstants.RECONCILIATION+".searchIterative");

handler.createWorkerThreads(coordinatorTask, searchResult);
provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, coordinatorTask, searchResult); // note that progress is incremented within the handler, as it extends AbstractSearchIterativeResultHandler
Expand All @@ -469,7 +463,7 @@ private boolean performResourceReconciliation(PrismObject<ResourceType> resource

opResult.computeStatus();

String message = "Processed " + handler.getProgress() + " account(s), got " + handler.getErrors() + " error(s)";
String message = "Processed " + handler.getProgress() + " shadow(s), got " + handler.getErrors() + " error(s)";
if (interrupted) {
message += "; was interrupted during processing";
}
Expand All @@ -481,8 +475,10 @@ private boolean performResourceReconciliation(PrismObject<ResourceType> resource
if (handler.getErrors() > 0) {
resultStatus = OperationResultStatus.PARTIAL_ERROR;
}
opResult.recordStatus(resultStatus, message);
opResult.setStatus(resultStatus);
LOGGER.info("Finished resource part of {} reconciliation: {}", resource, message);
result.createSubresult(OperationConstants.RECONCILIATION+".resourceReconciliation.statistics")
.recordStatus(OperationResultStatus.SUCCESS, message);

reconResult.setResourceReconCount(handler.getProgress());
reconResult.setResourceReconErrors(handler.getErrors());
Expand Down Expand Up @@ -656,7 +652,7 @@ private boolean scanForUnfinishedOperations(Task task, String resourceOid, Recon
ObjectAlreadyExistsException, CommunicationException, ObjectNotFoundException,
ConfigurationException, SecurityViolationException {
LOGGER.trace("Scan for unfinished operations starting");
OperationResult opResult = result.createSubresult(OperationConstants.RECONCILIATION+".repoReconciliation");
OperationResult opResult = result.createSubresult(OperationConstants.RECONCILIATION+".scanForUnfinishedOperations");
opResult.addParam("reconciled", true);

ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext)
Expand All @@ -667,7 +663,7 @@ private boolean scanForUnfinishedOperations(Task task, String resourceOid, Recon

task.setExpectedTotal((long) shadows.size()); // for this phase, obviously

LOGGER.trace("Found {} accounts that were not successfully processed.", shadows.size());
LOGGER.trace("Found {} shadows that were not successfully processed.", shadows.size());
reconResult.setUnOpsCount(shadows.size());

long startedAll = System.currentTimeMillis();
Expand Down
Expand Up @@ -162,9 +162,6 @@ public void setEnableActionsExecutedStatistics(boolean enableActionsExecutedStat
this.enableActionsExecutedStatistics = enableActionsExecutedStatistics;
}

/* (non-Javadoc)
* @see com.evolveum.midpoint.schema.ResultHandler#handle(com.evolveum.midpoint.prism.PrismObject, com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public boolean handle(PrismObject<O> object, OperationResult parentResult) {
if (object.getOid() == null) {
Expand Down Expand Up @@ -207,10 +204,7 @@ private boolean shouldStop(OperationResult parentResult) {

private void recordInterrupted(OperationResult parentResult) {
parentResult.createSubresult(taskOperationPrefix + ".handle").recordWarning("Interrupted");
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("{} {} interrupted",new Object[]{
getProcessShortNameCapitalized(), getContextDesc()});
}
LOGGER.warn("{} {} interrupted", getProcessShortNameCapitalized(), getContextDesc());
}

public void signalAllItemsSubmitted() {
Expand Down Expand Up @@ -313,8 +307,7 @@ private void processRequest(ProcessingRequest request, Task workerTask, Operatio
RepositoryCache.enter();

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("{} starting for {} {}",new Object[] {
getProcessShortNameCapitalized(), object, getContextDesc()});
LOGGER.trace("{} starting for {} {}", getProcessShortNameCapitalized(), object, getContextDesc());
}

if (isRecordIterationStatistics()) {
Expand Down Expand Up @@ -382,18 +375,18 @@ private void processRequest(ProcessingRequest request, Task workerTask, Operatio

if (logObjectProgress) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("{} object {} {} done with status {} (this one: {} ms, avg: {} ms) (total progress: {}, wall clock avg: {} ms)", new Object[]{
LOGGER.info("{} object {} {} done with status {} (this one: {} ms, avg: {} ms) (total progress: {}, wall clock avg: {} ms)",
getProcessShortNameCapitalized(), object,
getContextDesc(), result.getStatus(),
duration, total/progress, progress,
(System.currentTimeMillis()-this.startTime)/progress});
(System.currentTimeMillis()-this.startTime)/progress);
}
}
}

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("{} finished for {} {}, result:\n{}", new Object[]{
getProcessShortNameCapitalized(), object, getContextDesc(), result.debugDump()});
LOGGER.trace("{} finished for {} {}, result:\n{}", getProcessShortNameCapitalized(), object, getContextDesc(),
result.debugDump());
}

if (!cont) {
Expand Down
Expand Up @@ -1184,14 +1184,15 @@ public boolean handle(PrismObject<T> object, OperationResult objResult) {

@Override
public boolean handle(ShadowType shadowType) {

OperationResult handleResult = result.createSubresult(ProvisioningService.class.getName()
+ ".searchObjectsIterative.handle");
handleResult.addParam("shadow", ObjectTypeUtil.toShortString(shadowType));

if (shouldDoRepoSearch) {
return handleRepoObject(type, shadowType.asPrismObject(), options, handler, handleResult);
}

if (shadowType == null) {
throw new IllegalArgumentException("Null shadow in call to handler");
}
Expand All @@ -1200,15 +1201,13 @@ public boolean handle(ShadowType shadowType) {
SchemaDebugUtil.prettyPrint(shadowType));
}



boolean doContinue;
try {
PrismObject shadow = shadowType.asPrismObject();
validateObject(shadow);

doContinue = handler.handle(shadow, handleResult);

handleResult.computeStatus();
handleResult.recordSuccessIfUnknown();

Expand Down Expand Up @@ -1243,8 +1242,8 @@ public boolean handle(ShadowType shadowType) {
handleResult.recordSuccessIfUnknown();
// FIXME: hack. Hardcoded ugly summarization of successes. something like
// AbstractSummarizingResultHandler [lazyman]
if (result.isSuccess()) {
result.getSubresults().clear();
if (handleResult.isSuccess()) {
handleResult.getSubresults().clear();
}
result.summarize();
}
Expand Down
Expand Up @@ -380,6 +380,7 @@ public <T extends ObjectType> SearchResultList<PrismObject<T>> searchObjectsAtte

List<PrismObject<T>> list = queryResultToPrismObjects(queryResult, type, null, options, session, result);
session.getTransaction().commit();
result.addReturn("object count", list.size());
return new SearchResultList<>(list);

} catch (QueryException | RuntimeException ex) {
Expand Down

0 comments on commit 1ca7614

Please sign in to comment.