use of org.apache.syncope.core.provisioning.api.propagation.PropagationException in project syncope by apache.
the class AbstractPullResultHandler method deprovision.
protected List<ProvisioningReport> deprovision(final SyncDelta delta, final List<String> anyKeys, final Provision provision, final boolean unlink) throws JobExecutionException {
if (!profile.getTask().isPerformUpdate()) {
LOG.debug("PullTask not configured for update");
finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
LOG.debug("About to deprovision {}", anyKeys);
final List<ProvisioningReport> results = new ArrayList<>();
for (String key : anyKeys) {
LOG.debug("About to unassign resource {}", key);
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.DELETE);
result.setAnyType(provision.getAnyType().getKey());
result.setStatus(ProvisioningReport.Status.SUCCESS);
result.setKey(key);
AnyTO before = getAnyTO(key);
if (before == null) {
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(String.format("Any '%s(%s)' not found", provision.getAnyType().getKey(), key));
}
if (!profile.isDryRun()) {
Object output;
Result resultStatus;
if (before == null) {
resultStatus = Result.FAILURE;
output = null;
} else {
result.setName(getName(before));
try {
if (unlink) {
for (PullActions action : profile.getActions()) {
action.beforeUnassign(profile, delta, before);
}
} else {
for (PullActions action : profile.getActions()) {
action.beforeDeprovision(profile, delta, before);
}
}
PropagationByResource propByRes = new PropagationByResource();
propByRes.add(ResourceOperation.DELETE, profile.getTask().getResource().getKey());
taskExecutor.execute(propagationManager.getDeleteTasks(provision.getAnyType().getKind(), key, propByRes, null), false);
AnyPatch anyPatch = null;
if (unlink) {
anyPatch = newPatch(key);
anyPatch.getResources().add(new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(profile.getTask().getResource().getKey()).build());
}
if (anyPatch == null) {
output = getAnyTO(key);
} else {
output = doUpdate(before, anyPatch, delta, result);
}
for (PullActions action : profile.getActions()) {
action.after(profile, delta, AnyTO.class.cast(output), result);
}
resultStatus = Result.SUCCESS;
LOG.debug("{} {} successfully updated", provision.getAnyType().getKey(), key);
} catch (PropagationException e) {
// A propagation failure doesn't imply a pull failure.
// The propagation exception status will be reported into the propagation task execution.
LOG.error("Could not propagate {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
} catch (Exception e) {
throwIgnoreProvisionException(delta, e);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.error("Could not update {} {}", provision.getAnyType().getKey(), delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
}
}
finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), resultStatus, before, output, delta);
}
results.add(result);
}
return results;
}
use of org.apache.syncope.core.provisioning.api.propagation.PropagationException in project syncope by apache.
the class DefaultRealmPullResultHandler method link.
private List<ProvisioningReport> link(final SyncDelta delta, final List<String> keys, final boolean unlink) throws JobExecutionException {
if (!profile.getTask().isPerformUpdate()) {
LOG.debug("PullTask not configured for update");
finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
LOG.debug("About to link {}", keys);
final List<ProvisioningReport> results = new ArrayList<>();
for (String key : keys) {
LOG.debug("About to unassign resource {}", key);
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.NONE);
result.setAnyType(REALM_TYPE);
result.setStatus(ProvisioningReport.Status.SUCCESS);
result.setKey(key);
Realm realm = realmDAO.find(key);
RealmTO before = binder.getRealmTO(realm, true);
if (before == null) {
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(String.format("Realm '%s' not found", key));
} else {
result.setName(before.getFullPath());
}
Object output;
Result resultStatus;
if (!profile.isDryRun()) {
if (before == null) {
resultStatus = Result.FAILURE;
output = null;
} else {
try {
if (unlink) {
for (PullActions action : profile.getActions()) {
action.beforeUnlink(profile, delta, before);
}
} else {
for (PullActions action : profile.getActions()) {
action.beforeLink(profile, delta, before);
}
}
if (unlink) {
realm.getResources().remove(profile.getTask().getResource());
} else {
realm.add(profile.getTask().getResource());
}
output = update(delta, Collections.singletonList(key));
for (PullActions action : profile.getActions()) {
action.after(profile, delta, RealmTO.class.cast(output), result);
}
resultStatus = Result.SUCCESS;
LOG.debug("{} successfully updated", realm);
} catch (PropagationException e) {
// A propagation failure doesn't imply a pull failure.
// The propagation exception status will be reported into the propagation task execution.
LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
} catch (Exception e) {
throwIgnoreProvisionException(delta, e);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.error("Could not update Realm {}", delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
}
}
finalize(unlink ? MatchingRule.toEventName(MatchingRule.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta);
}
results.add(result);
}
return results;
}
use of org.apache.syncope.core.provisioning.api.propagation.PropagationException in project syncope by apache.
the class DefaultUserProvisioningManager method delete.
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public List<PropagationStatus> delete(final String key, final Set<String> excludedResources, final boolean nullPriorityAsync) {
PropagationByResource propByRes = new PropagationByResource();
propByRes.set(ResourceOperation.DELETE, userDAO.findAllResourceKeys(key));
// Note here that we can only notify about "delete", not any other
// task defined in workflow process definition: this because this
// information could only be available after uwfAdapter.delete(), which
// will also effectively remove user from db, thus making virtually
// impossible by NotificationManager to fetch required user information
List<PropagationTaskTO> tasks = propagationManager.getDeleteTasks(AnyTypeKind.USER, key, propByRes, excludedResources);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
try {
uwfAdapter.delete(key);
} catch (PropagationException e) {
throw e;
}
return propagationReporter.getStatuses();
}
use of org.apache.syncope.core.provisioning.api.propagation.PropagationException in project syncope by apache.
the class PriorityPropagationTaskExecutor method doExecute.
@Override
protected void doExecute(final Collection<PropagationTaskTO> tasks, final PropagationReporter reporter, final boolean nullPriorityAsync) {
Map<PropagationTaskTO, ExternalResource> taskToResource = tasks.stream().collect(Collectors.toMap(Function.identity(), task -> resourceDAO.find(task.getResource())));
List<PropagationTaskTO> prioritizedTasks = tasks.stream().filter(task -> taskToResource.get(task).getPropagationPriority() != null).collect(Collectors.toList());
Collections.sort(prioritizedTasks, new PriorityComparator(taskToResource));
LOG.debug("Propagation tasks sorted by priority, for serial execution: {}", prioritizedTasks);
Collection<PropagationTaskTO> concurrentTasks = tasks.stream().filter(task -> !prioritizedTasks.contains(task)).collect(Collectors.toSet());
LOG.debug("Propagation tasks for concurrent execution: {}", concurrentTasks);
// first process priority resources sequentially and fail as soon as any propagation failure is reported
prioritizedTasks.forEach(task -> {
TaskExec execution = null;
PropagationTaskExecStatus execStatus;
try {
execution = newPropagationTaskCallable(task, reporter).call();
execStatus = PropagationTaskExecStatus.valueOf(execution.getStatus());
} catch (Exception e) {
LOG.error("Unexpected exception", e);
execStatus = PropagationTaskExecStatus.FAILURE;
}
if (execStatus != PropagationTaskExecStatus.SUCCESS) {
throw new PropagationException(task.getResource(), execution == null ? null : execution.getMessage());
}
});
// then process non-priority resources concurrently...
CompletionService<TaskExec> completionService = new ExecutorCompletionService<>(executor);
Map<PropagationTaskTO, Future<TaskExec>> nullPriority = new HashMap<>(concurrentTasks.size());
concurrentTasks.forEach(task -> {
try {
nullPriority.put(task, completionService.submit(newPropagationTaskCallable(task, reporter)));
} catch (Exception e) {
LOG.error("Unexpected exception", e);
}
});
// ...waiting for all callables to complete, if async processing was not required
if (!nullPriority.isEmpty()) {
if (nullPriorityAsync) {
nullPriority.forEach((task, exec) -> {
reporter.onSuccessOrNonPriorityResourceFailures(task, PropagationTaskExecStatus.CREATED, null, null, null);
});
} else {
final Set<Future<TaskExec>> nullPriorityFutures = new HashSet<>(nullPriority.values());
try {
executor.submit(() -> {
while (!nullPriorityFutures.isEmpty()) {
try {
nullPriorityFutures.remove(completionService.take());
} catch (Exception e) {
LOG.error("Unexpected exception", e);
}
}
}).get(60, TimeUnit.SECONDS);
} catch (Exception e) {
LOG.error("Unexpected exception", e);
} finally {
nullPriorityFutures.forEach(future -> {
future.cancel(true);
});
nullPriorityFutures.clear();
nullPriority.clear();
}
}
}
}
use of org.apache.syncope.core.provisioning.api.propagation.PropagationException in project syncope by apache.
the class DefaultRealmPullResultHandler method create.
private void create(final RealmTO realmTO, final SyncDelta delta, final String operation, final ProvisioningReport result) throws JobExecutionException {
Object output;
Result resultStatus;
try {
Realm realm = realmDAO.save(binder.create(profile.getTask().getDestinatioRealm(), realmTO));
PropagationByResource propByRes = new PropagationByResource();
for (String resource : realm.getResourceKeys()) {
propByRes.add(ResourceOperation.CREATE, resource);
}
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
taskExecutor.execute(tasks, false);
RealmTO actual = binder.getRealmTO(realm, true);
result.setKey(actual.getKey());
result.setName(profile.getTask().getDestinatioRealm().getFullPath() + "/" + actual.getName());
output = actual;
resultStatus = Result.SUCCESS;
for (PullActions action : profile.getActions()) {
action.after(profile, delta, actual, result);
}
LOG.debug("Realm {} successfully created", actual.getKey());
} catch (PropagationException e) {
// A propagation failure doesn't imply a pull failure.
// The propagation exception status will be reported into the propagation task execution.
LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
} catch (Exception e) {
throwIgnoreProvisionException(delta, e);
result.setStatus(ProvisioningReport.Status.FAILURE);
result.setMessage(ExceptionUtils.getRootCauseMessage(e));
LOG.error("Could not create Realm {} ", delta.getUid().getUidValue(), e);
output = e;
resultStatus = Result.FAILURE;
}
finalize(operation, resultStatus, null, output, delta);
}
Aggregations