Skip to content

Commit

Permalink
Consistency update: provisioning tests almost passing (MID-3603)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jul 20, 2018
1 parent 62488e5 commit 1adf106
Show file tree
Hide file tree
Showing 16 changed files with 629 additions and 377 deletions.
Expand Up @@ -469,6 +469,9 @@ public String addShadow(PrismObject<ShadowType> shadowToAdd, OperationProvisioni
ctx.assertDefinition();
} catch (SchemaException e) {
parentResult.recordFatalError(e);
ResourceOperationDescription operationDescription = ProvisioningUtil.createResourceFailureDescription(
shadowToAdd, ctx.getResource(), shadowToAdd.createAddDelta(), parentResult);
operationListener.notifyFailure(operationDescription, task, parentResult);
throw e;
}

Expand All @@ -490,9 +493,11 @@ private String addShadowAttempt(ProvisioningContext ctx,

PrismContainer<?> attributesContainer = shadowToAdd.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer == null || attributesContainer.isEmpty()) {
SchemaException e = new SchemaException(
"Attempt to add shadow without any attributes: " + shadowToAdd);
SchemaException e = new SchemaException("Attempt to add shadow without any attributes: " + shadowToAdd);
parentResult.recordFatalError(e);
ResourceOperationDescription operationDescription = ProvisioningUtil.createResourceFailureDescription(
shadowToAdd, ctx.getResource(), shadowToAdd.createAddDelta(), parentResult);
operationListener.notifyFailure(operationDescription, task, parentResult);
throw e;
}
if (!(attributesContainer instanceof ResourceAttributeContainer)) {
Expand Down Expand Up @@ -584,14 +589,26 @@ private String addShadowAttempt(ProvisioningContext ctx,

notifyAfterAdd(ctx, addedShadow, opState, task, parentResult);

setParentOperationStatus(parentResult, opState, finalOperationStatus);

return opState.getRepoShadow().getOid();
}

private void setParentOperationStatus(OperationResult parentResult,
ProvisioningOperationState<? extends AsynchronousOperationResult> opState,
OperationResultStatus finalOperationStatus) {
if (finalOperationStatus != null) {
parentResult.setStatus(finalOperationStatus);
} else {
if (opState.isCompleted()) {
parentResult.computeStatus();
} else {
parentResult.recordInProgress();
}
}
parentResult.setAsynchronousOperationReference(opState.getAsynchronousOperationReference());

return opState.getRepoShadow().getOid();
}

private boolean hasDeadShadowWithDeleteOperation(ProvisioningContext ctx,
PrismObject<ShadowType> shadowToAdd,
OperationResult parentResult)
Expand Down Expand Up @@ -974,16 +991,7 @@ private String modifyShadowAttempt(ProvisioningContext ctx,

notifyAfterModify(ctx, repoShadow, modifications, opState, task, parentResult);

if (finalOperationStatus != null) {
parentResult.setStatus(finalOperationStatus);
} else {
if (opState.isCompleted()) {
parentResult.computeStatus();
} else {
parentResult.recordInProgress();
}
}
parentResult.setAsynchronousOperationReference(opState.getAsynchronousOperationReference());
setParentOperationStatus(parentResult, opState, finalOperationStatus);

return repoShadow.getOid();
}
Expand Down Expand Up @@ -1170,10 +1178,8 @@ private void deleteShadowAttempt(ProvisioningContext ctx,
}

notifyAfterDelete(ctx, repoShadow, opState, task, parentResult);
if (finalOperationStatus != null) {
parentResult.setStatus(finalOperationStatus);
}
parentResult.setAsynchronousOperationReference(opState.getAsynchronousOperationReference());

setParentOperationStatus(parentResult, opState, finalOperationStatus);
}

private ProvisioningOperationState<AsynchronousOperationResult> executeResourceDelete(
Expand Down

This file was deleted.

Expand Up @@ -265,18 +265,15 @@ public PrismObject<ShadowType> applyPendingOperations(ProvisioningContext ctx,
// Not applicable means: "no point trying this, will not retry". Therefore it will not change future state.
continue;
}
if (PendingOperationExecutionStatusType.COMPLETED.equals(executionStatus)) {
// Completed operations. They have already affected current state. They are already "applied".
if (PendingOperationExecutionStatusType.COMPLETED.equals(executionStatus) && ProvisioningUtil.isOverPeriod(now, gracePeriod, pendingOperation)) {
// Completed operations over grace period. They have already affected current state. They are already "applied".
continue;
}
// Note: We still want to process errors, even fatal errors. As long as they are in executing state then they
// are going to be retried and they still may influence future state
if (skipExecutionPendingOperations && executionStatus == PendingOperationExecutionStatusType.EXECUTION_PENDING) {
continue;
}
if (ProvisioningUtil.isOverPeriod(now, gracePeriod, pendingOperation)) {
continue;
}
if (resourceReadIsCachingOnly) {
// We are getting the data from our own cache. So we know that all completed operations are already applied in the cache.
// Re-applying them will mean additional risk of corrupting the data.
Expand Down
Expand Up @@ -1492,9 +1492,12 @@ public void recordModifyResult(

List<ItemDelta> internalShadowModifications = computeInternalShadowModifications(ctx, opState, requestDelta);

// TODO

List<ItemDelta> modifications = MiscUtil.join(requestedModifications, (List)internalShadowModifications);
List<ItemDelta> modifications;
if (opState.isCompleted()) {
modifications = MiscUtil.join(requestedModifications, (List)internalShadowModifications);
} else {
modifications = internalShadowModifications;
}
LOGGER.trace("Updating repository {} after MODIFY operation {}, {} repository shadow modifications", oldRepoShadow, opState, requestedModifications.size());

modifyShadowAttributes(ctx, oldRepoShadow, modifications, parentResult);
Expand Down
Expand Up @@ -160,7 +160,7 @@ public void test050AddAccountWill() throws Exception {
ShadowAsserter.forShadow(accountProvisioning)
.assertNoLegacyConsistency()
.pendingOperations()
.none();
.assertNone();

DummyAccount dummyAccount = dummyResource.getAccountByUsername(transformNameFromResource(ACCOUNT_WILL_USERNAME));
assertNotNull("No dummy account", dummyAccount);
Expand All @@ -178,7 +178,7 @@ public void test050AddAccountWill() throws Exception {
ShadowAsserter.forShadow(shadowFromRepo)
.assertNoLegacyConsistency()
.pendingOperations()
.none();
.assertNone();

checkUniqueness(accountProvisioning);
rememberSteadyResources();
Expand Down Expand Up @@ -1120,7 +1120,7 @@ public void test190AccountMorganDeadExpireOperation() throws Exception {
shadowAsserter
.display()
.pendingOperations()
.none();
.assertNone();
shadowAsserter
.assertBasicRepoProperties()
.assertKind(ShadowKindType.ACCOUNT)
Expand All @@ -1135,7 +1135,7 @@ public void test190AccountMorganDeadExpireOperation() throws Exception {
shadowAsserter
.display()
.pendingOperations()
.none();
.assertNone();
shadowAsserter
.assertDead()
.assertIsNotExists()
Expand Down Expand Up @@ -1472,6 +1472,13 @@ private void assertUnmodifiedMorgan(int expectedAttemptNumber, int expectenNumbe

// Check if the shadow is still in the repo (e.g. that the consistency or sync haven't removed it)
checkUniqueness(accountProvisioningFuture);

dummyResource.resetBreakMode();
dummyResourceCtl.assertAccountByUsername(ACCOUNT_MORGAN_NAME)
.assertName(ACCOUNT_MORGAN_NAME)
.assertFullName(ACCOUNT_MORGAN_FULLNAME)
.assertEnabled()
.assertPassword(ACCOUNT_MORGAN_PASSWORD);
}

private void assertModifiedMorgan(int expectedAttemptNumber, int expectenNumberOfPendingOperations, String expectedFullName) throws Exception {
Expand Down Expand Up @@ -1571,6 +1578,13 @@ private void assertModifiedMorgan(int expectedAttemptNumber, int expectenNumberO

// Check if the shadow is still in the repo (e.g. that the consistency or sync haven't removed it)
checkUniqueness(accountProvisioningFuture);

dummyResource.resetBreakMode();
dummyResourceCtl.assertAccountByUsername(ACCOUNT_MORGAN_NAME)
.assertName(ACCOUNT_MORGAN_NAME)
.assertFullName(expectedFullName)
.assertEnabled()
.assertPassword(ACCOUNT_MORGAN_PASSWORD);
}

private void assertMorganModifyFailed() throws Exception {
Expand Down Expand Up @@ -1662,6 +1676,13 @@ private void assertMorganModifyFailed() throws Exception {

// Check if the shadow is still in the repo (e.g. that the consistency or sync haven't removed it)
checkUniqueness(accountProvisioningFuture);

dummyResource.resetBreakMode();
dummyResourceCtl.assertAccountByUsername(ACCOUNT_MORGAN_NAME)
.assertName(ACCOUNT_MORGAN_NAME)
.assertFullName(ACCOUNT_MORGAN_FULLNAME)
.assertEnabled()
.assertPassword(ACCOUNT_MORGAN_PASSWORD);
}

private void assertUndeletedMorgan(int expectedAttemptNumber, int expectenNumberOfPendingOperations) throws Exception {
Expand Down Expand Up @@ -1756,6 +1777,13 @@ private void assertUndeletedMorgan(int expectedAttemptNumber, int expectenNumber

// Check if the shadow is still in the repo (e.g. that the consistency or sync haven't removed it)
checkUniqueness(accountProvisioningFuture);

dummyResource.resetBreakMode();
dummyResourceCtl.assertAccountByUsername(ACCOUNT_MORGAN_NAME)
.assertName(ACCOUNT_MORGAN_NAME)
.assertFullName(ACCOUNT_MORGAN_FULLNAME_CHM)
.assertEnabled()
.assertPassword(ACCOUNT_MORGAN_PASSWORD);
}

private void assertMorganDeleteFailed() throws Exception {
Expand Down Expand Up @@ -1850,6 +1878,13 @@ private void assertMorganDeleteFailed() throws Exception {

// Check if the shadow is still in the repo (e.g. that the consistency or sync haven't removed it)
checkUniqueness(accountProvisioningFuture);

dummyResource.resetBreakMode();
dummyResourceCtl.assertAccountByUsername(ACCOUNT_MORGAN_NAME)
.assertName(ACCOUNT_MORGAN_NAME)
.assertFullName(ACCOUNT_MORGAN_FULLNAME_CHM)
.assertEnabled()
.assertPassword(ACCOUNT_MORGAN_PASSWORD);
}

private void assertDeletedMorgan(int expectedAttemptNumber, int expectenNumberOfPendingOperations) throws Exception {
Expand Down Expand Up @@ -1932,6 +1967,9 @@ private void assertDeletedMorgan(int expectedAttemptNumber, int expectenNumberOf
} catch (ObjectNotFoundException e) {
// expected
}

dummyResource.resetBreakMode();
dummyResourceCtl.assertNoAccountByUsername(ACCOUNT_MORGAN_NAME);
}


Expand Down

0 comments on commit 1adf106

Please sign in to comment.