Skip to content

Commit

Permalink
Rolling back automatic connector dispose (MID-3104,MID-4779)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jul 11, 2018
1 parent 7413ff6 commit 583475d
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 54 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Evolveum
* Copyright (c) 2013-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,8 @@
import com.evolveum.midpoint.model.impl.sync.ReconciliationTaskResult;
import com.evolveum.midpoint.model.impl.sync.ReconciliationTaskResultListener;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;

/**
* Debugging listener for reconciliation tasks.
Expand All @@ -33,7 +35,7 @@
*
*/
public class DebugReconciliationTaskResultListener implements
ReconciliationTaskResultListener {
ReconciliationTaskResultListener, DebugDumpable {

private List<ReconciliationTaskResult> results = Collections.synchronizedList(new ArrayList<ReconciliationTaskResult>());

Expand Down Expand Up @@ -69,4 +71,11 @@ private ReconciliationTaskResult findResult(String resourceOid) {
return null;
}

@Override
public String debugDump(int indent) {
StringBuilder sb = DebugUtil.createTitleStringBuilderLn(DebugReconciliationTaskResultListener.class, indent);
DebugUtil.debugDumpWithLabel(sb, "results", results, indent + 1);
return sb.toString();
}

}
Expand Up @@ -124,21 +124,19 @@ public void test131ModifyUserJackAssignAccount() throws Exception {
Task task = taskManager.createTaskInstance(TestCaseIgnore.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
ObjectDelta<UserType> accountAssignmentUserDelta = createAccountAssignmentUserDelta(USER_JACK_OID, RESOURCE_DUMMY_UPCASE_OID, null, true);
deltas.add(accountAssignmentUserDelta);

XMLGregorianCalendar startTime = clock.currentTimeXMLGregorianCalendar();

// WHEN
displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
displayWhen(TEST_NAME);
executeChanges(accountAssignmentUserDelta, null, task, result);

// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
displayThen(TEST_NAME);
assertSuccess(result);
XMLGregorianCalendar endTime = clock.currentTimeXMLGregorianCalendar();
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 1);
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);

PrismObject<UserType> userJack = getUser(USER_JACK_OID);
Expand Down
Expand Up @@ -169,13 +169,6 @@ public void test100AssignWillRoleOne() throws Exception {
assertSteadyResources();
}

@Override
protected void assertTest103Counters() {
super.assertTest103Counters();
// First use of the resoruce
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 1);
}

/**
* disable - do not run propagation yet
* (do not wait for delta to expire, we want several deltas at once so we can test grouping).
Expand Down
Expand Up @@ -698,7 +698,7 @@ public void test100AssignWillRoleOne() throws Exception {

assignWillRoleOne("test100AssignWillRoleOne", USER_WILL_FULL_NAME, PendingOperationExecutionStatusType.EXECUTION_PENDING);

assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0, 1);
assertSteadyResources();
}

Expand Down Expand Up @@ -778,18 +778,14 @@ public void test103RunPropagation() throws Exception {
displayThen(TEST_NAME);
assertSuccess(result);

assertTest103Counters();
assertCounterIncrement(InternalCounters.CONNECTOR_MODIFICATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0, 1);

assertAccountWillAfterAssign(TEST_NAME, USER_WILL_FULL_NAME, PendingOperationExecutionStatusType.EXECUTING);

assertSteadyResources();
}

protected void assertTest103Counters() {
// The count is checked only after propagation was run, so we can address both direct and grouping cases
assertCounterIncrement(InternalCounters.CONNECTOR_MODIFICATION_COUNT, 1);
}

@Test
public void test104RecomputeWill() throws Exception {
final String TEST_NAME = "test104RecomputeWill";
Expand Down
Expand Up @@ -1042,7 +1042,7 @@ public void test220ReconcileDummyBrokenGuybrush() throws Exception {
displayThen(TEST_NAME);

List<PrismObject<UserType>> users = modelService.searchObjects(UserType.class, null, null, task, result);
display("Users after reconciliation (broken resource)", users);
display("Users after reconciliation (broken resource account)", users);

reconciliationTaskResultListener.assertResult(RESOURCE_DUMMY_OID, 0, 7, 1, 0);

Expand Down
Expand Up @@ -186,9 +186,6 @@ private boolean isFresh(ConfiguredConnectorInstanceEntry configuredConnectorInst
if (!configuredConnectorInstanceEntry.connectorOid.equals(connectorSpec.getConnectorOid())) {
return false;
}
if (!configuredConnectorInstanceEntry.resourceVersion.equals(connectorSpec.getResource().getVersion())) {
return false;
}
if (!configuredConnectorInstanceEntry.configuration.equivalent(connectorSpec.getConnectorConfiguration())) {
return false;
}
Expand All @@ -204,7 +201,6 @@ void cacheConfiguredConnector(ConnectorSpec connectorSpec, ConnectorInstance con
if (resourceVersion == null) {
throw new IllegalArgumentException("Resource version is null, cannot cache connector for "+ connectorSpec.getResource());
}
cacheEntry.resourceVersion = resourceVersion;

cacheEntry.configuration = connectorSpec.getConnectorConfiguration();
cacheEntry.connectorInstance = configuredConnectorInstance;
Expand Down Expand Up @@ -576,7 +572,6 @@ public String getFrameworkVersion() {

private static class ConfiguredConnectorInstanceEntry {
public String connectorOid;
public String resourceVersion;
public PrismContainer<ConnectorConfigurationType> configuration;
public ConnectorInstance connectorInstance;
}
Expand Down
Expand Up @@ -934,7 +934,7 @@ private <T extends ObjectType> boolean handleRepoObject(final Class<T> type, Pri

completeObject = completeObject(type, object, options, task, objResult);

} catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
} catch (Throwable e) {
LOGGER.error("Error while completing {}: {}-{}. Using non-complete object.", object, e.getMessage(), e);
objResult.recordFatalError(e);
object.asObjectable().setFetchResult(objResult.createOperationResultType());
Expand Down Expand Up @@ -1009,12 +1009,11 @@ public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(final
metadata = getShadowCache(Mode.STANDARD).searchObjectsIterative(query, options, (ResultHandler<ShadowType>)handler, true, task, result);

result.computeStatus();
result.cleanupResult();

} catch (ConfigurationException | CommunicationException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
} catch (Throwable e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
} finally {
result.cleanupResult();
}

} else {
Expand All @@ -1032,11 +1031,10 @@ public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(final

result.computeStatus();
result.recordSuccessIfUnknown();
result.cleanupResult();

} catch (SchemaException | RuntimeException | Error e) {
} catch (Throwable e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
} finally {
result.cleanupResult();
}
}

Expand Down Expand Up @@ -1091,7 +1089,7 @@ public List<ConnectorOperationalStatus> getConnectorOperationalStatus(String res
List<ConnectorOperationalStatus> stats;
try {
stats = resourceManager.getConnectorOperationalStatus(resource, result);
} catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException ex) {
} catch (Throwable ex) {
ProvisioningUtil.recordFatalError(LOGGER, result, "Getting operations status from connector for resource "+resourceOid+" failed: "+ex.getMessage(), ex);
throw ex;
}
Expand Down Expand Up @@ -1131,7 +1129,7 @@ public <T extends ObjectType> void applyDefinition(ObjectDelta<T> delta, Objecta
result.recordSuccessIfUnknown();
result.cleanupResult();

} catch (ObjectNotFoundException | CommunicationException | ConfigurationException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
} catch (Throwable e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
}
Expand Down Expand Up @@ -1159,7 +1157,7 @@ public <T extends ObjectType> void applyDefinition(PrismObject<T> object, Task t
result.computeStatus();
result.recordSuccessIfUnknown();

} catch (ObjectNotFoundException | CommunicationException | ConfigurationException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
} catch (Throwable e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
} finally {
Expand Down Expand Up @@ -1198,7 +1196,7 @@ public <T extends ObjectType> void applyDefinition(Class<T> type, ObjectQuery qu
result.computeStatus();
result.recordSuccessIfUnknown();

} catch (ObjectNotFoundException | CommunicationException | ConfigurationException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
} catch (Throwable e) {
ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
throw e;
} finally {
Expand Down
Expand Up @@ -1253,7 +1253,15 @@ public SearchResultMetadata searchResourceObjects(final ProvisioningContext ctx,
try {
shadow = postProcessResourceObjectRead(ctx, shadow, fetchAssociations, objResult);
} catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ObjectNotFoundException | ExpressionEvaluationException e) {
if (objResult.isUnknown()) {
objResult.recordFatalError(e);
}
throw new TunnelException(e);
} catch (Throwable t) {
if (objResult.isUnknown()) {
objResult.recordFatalError(t);
}
throw t;
}
Validate.notNull(shadow, "null shadow");
boolean doContinue;
Expand Down
Expand Up @@ -240,8 +240,7 @@ public void test012AddAccountGetResource() throws Exception {
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT, 0);
assertCounterIncrement(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT, 0);
assertCounterIncrement(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT, 0);
// This is first resource operation after resource version has changed. Hence connector is reinitialized.
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0);
rememberConnectorInstance(resourceProvisioning);
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);

Expand Down Expand Up @@ -416,8 +415,7 @@ public void test022GetAccountGetResource() throws Exception {
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT, 0);
assertCounterIncrement(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT, 0);
assertCounterIncrement(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT, 0);
// This is first resource operation after resource version has changed. Hence connector is reinitialized.
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 0);
rememberConnectorInstance(resourceProvisioning);
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -207,7 +207,7 @@ static Throwable processConnIdException(Throwable connIdException, String desc,
if (connIdException instanceof ConnectorException && !connIdException.getClass().equals(ConnectorException.class)) {
// we have non generic connector exception
knownCause = processConnectorException((ConnectorException) connIdException, connIdResult);
LOGGER.error("LOOK FOR CONN ID EXCEPTION: {} -> {}", connIdException.getClass().getName(), knownCause.getClass().getName());
// LOGGER.error("LOOK FOR CONN ID EXCEPTION: {} -> {}", connIdException.getClass().getName(), knownCause.getClass().getName());
if (knownCause != null) {
return knownCause;
}
Expand All @@ -216,7 +216,7 @@ static Throwable processConnIdException(Throwable connIdException, String desc,
// Introspect the inner exceptions and look for known causes
knownCause = lookForKnownCause(connIdException, connIdException, connIdResult);
if (knownCause != null) {
LOGGER.error("LOOK FOR KNOWN EXCEPTION: {} -> {}", connIdException.getClass().getName(), knownCause.getClass().getName());
// LOGGER.error("LOOK FOR KNOWN EXCEPTION: {} -> {}", connIdException.getClass().getName(), knownCause.getClass().getName());
connIdResult.recordFatalError(knownCause);
return knownCause;
}
Expand All @@ -243,7 +243,7 @@ static Throwable processConnIdException(Throwable connIdException, String desc,
return newEx;
}

LOGGER.error("FALLBACK: {} -> {}", connIdException.getClass().getName(), (knownCause != null ? knownCause.getClass().getName() : null));
// LOGGER.error("FALLBACK: {} -> {}", connIdException.getClass().getName(), (knownCause != null ? knownCause.getClass().getName() : null));

// Fallback
Exception newEx = new GenericFrameworkException(createMessageFromAllExceptions(null,connIdException));
Expand Down
Expand Up @@ -423,6 +423,14 @@ public ConnectorOperationalStatus getOperationalStatus() throws ObjectNotFoundEx

return status;
}

private void validateConnectorFacade(OperationResult result) {
if (connIdConnectorFacade == null) {
result.recordFatalError("Attempt to use unconfigured connector");
throw new IllegalStateException("Attempt to use unconfigured connector "
+ connectorType);
}
}

@Override
public void initialize(ResourceSchema resourceSchema, Collection<Object> capabilities, boolean caseIgnoreAttributeNames, OperationResult parentResult) throws CommunicationException,
Expand All @@ -433,11 +441,7 @@ public void initialize(ResourceSchema resourceSchema, Collection<Object> capabil
result.addContext("connector", connectorType);
result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ConnectorFactoryConnIdImpl.class);

if (connIdConnectorFacade == null) {
result.recordFatalError("Attempt to use unconfigured connector");
throw new IllegalStateException("Attempt to use unconfigured connector "
+ ObjectTypeUtil.toShortString(connectorType));
}
validateConnectorFacade(parentResult);

setResourceSchema(resourceSchema);
this.capabilities = capabilities;
Expand Down Expand Up @@ -2347,6 +2351,8 @@ public SearchResultMetadata search(final ObjectClassComplexTypeDefinition object
+ ".search");
result.addArbitraryObjectAsParam("objectClass", objectClassDefinition);
result.addContext("connector", connectorType);

validateConnectorFacade(result);

if (objectClassDefinition == null) {
result.recordFatalError("Object class not defined");
Expand Down Expand Up @@ -2505,7 +2511,6 @@ public String toString() {
// create result for it
OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".search");
icfResult.addArbitraryObjectAsParam("objectClass", icfObjectClass);
icfResult.addContext("connector", connIdConnectorFacade.getClass());

SearchResult connIdSearchResult;
try {
Expand Down

0 comments on commit 583475d

Please sign in to comment.