Skip to content

Commit

Permalink
Separate provisioning script execution: fixes (MID-5921)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Nov 28, 2019
1 parent e469089 commit 08cff3d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
Expand Up @@ -80,6 +80,10 @@ private static CriticalityType getCriticality(CriticalityType value, Criticality
}
}

public static boolean isFatalCriticality(CriticalityType value, CriticalityType defaultValue) {
return getCriticality(value,defaultValue) == CriticalityType.FATAL;
}

public static LocalizableMessage getUserFriendlyMessage(Throwable cause) {
while (cause != null) {
if (cause instanceof CommonException) {
Expand Down
Expand Up @@ -1284,6 +1284,7 @@ public void test528UnassignResourceEbony() throws Exception {

// THEN
displayThen(TEST_NAME);
display("Result", result);
assertPartialError(result);

String shadowOid = assertUserAfter(USER_GUYBRUSH_OID)
Expand Down
Expand Up @@ -30,10 +30,7 @@
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.midpoint.schema.result.*;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.schema.util.*;
import com.evolveum.midpoint.task.api.RunningTask;
import com.evolveum.midpoint.task.api.StateReporter;
import com.evolveum.midpoint.task.api.Task;
Expand Down Expand Up @@ -390,11 +387,11 @@ public AsynchronousOperationResult deleteResourceObject(ProvisioningContext ctx,
throw e;
}

executeProvisioningScripts(ctx, ProvisioningOperationTypeType.DELETE, BeforeAfterType.BEFORE, scripts, result);

// Execute entitlement modification on other objects (if needed)
executeEntitlementChangesDelete(ctx, shadow, scripts, connOptions, result);

executeProvisioningScripts(ctx, ProvisioningOperationTypeType.DELETE, BeforeAfterType.BEFORE, scripts, result);

ConnectorInstance connector = ctx.getConnector(DeleteCapabilityType.class, result);
AsynchronousOperationResult connectorAsyncOpRet = null;
try {
Expand All @@ -414,9 +411,6 @@ public AsynchronousOperationResult deleteResourceObject(ProvisioningContext ctx,

connectorAsyncOpRet = connector.deleteObject(ctx.getObjectClassDefinition(), shadow, identifiers, ctx, result);

computeResultStatus(result);
LOGGER.debug("PROVISIONING DELETE: {}", result.getStatus());

} catch (ObjectNotFoundException ex) {
result.recordFatalError("Can't delete object " + shadow
+ ". Reason: " + ex.getMessage(), ex);
Expand Down Expand Up @@ -449,6 +443,9 @@ public AsynchronousOperationResult deleteResourceObject(ProvisioningContext ctx,

executeProvisioningScripts(ctx, ProvisioningOperationTypeType.DELETE, BeforeAfterType.AFTER, scripts, result);

computeResultStatus(result);
LOGGER.debug("PROVISIONING DELETE result: {}", result.getStatus());

AsynchronousOperationResult aResult = AsynchronousOperationResult.wrap(result);
updateQuantum(ctx, connector, aResult, parentResult);
if (connectorAsyncOpRet != null) {
Expand Down Expand Up @@ -2541,13 +2538,29 @@ private void executeProvisioningScripts(ProvisioningContext ctx, ProvisioningOpe
}

} catch (CommunicationException ex) {
result.recordFatalError(
"Could not execute provisioning script. Error communicating with the connector " + connector + ": " + ex.getMessage(), ex);
throw new CommunicationException("Error communicating with the connector " + connector + ": "
+ ex.getMessage(), ex);
String message = "Could not execute provisioning script. Error communicating with the connector " + connector + ": " + ex.getMessage();
if (ExceptionUtil.isFatalCriticality(operation.getCriticality(), CriticalityType.FATAL)) {
result.recordFatalError(message, ex);
throw new CommunicationException(message, ex);
} else {
LOGGER.warn("{}", message);
}
} catch (GenericFrameworkException ex) {
result.recordFatalError("Could not execute provisioning script. Generic error in connector: " + ex.getMessage(), ex);
throw new GenericConnectorException("Generic error in connector: " + ex.getMessage(), ex);
String message = "Could not execute provisioning script. Generic error in connector: " + ex.getMessage();
if (ExceptionUtil.isFatalCriticality(operation.getCriticality(), CriticalityType.FATAL)) {
result.recordFatalError(message, ex);
throw new GenericConnectorException(message, ex);
} else {
LOGGER.warn("{}", message);
}
} catch (Throwable t) {
String message = "Could not execute provisioning script. Unexpected error in connector: " +t.getClass().getSimpleName() + ": " + t.getMessage();
if (ExceptionUtil.isFatalCriticality(operation.getCriticality(), CriticalityType.FATAL)) {
result.recordFatalError(message, t);
throw t;
} else {
LOGGER.warn("{}", message);
}
}

}
Expand Down

0 comments on commit 08cff3d

Please sign in to comment.