Search in sources :

Example 16 with ProvisioningReport

use of org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport in project syncope by apache.

the class DefaultRealmPullResultHandler method update.

private List<ProvisioningReport> update(final SyncDelta delta, final List<String> keys) throws JobExecutionException {
    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(MatchingRule.toEventName(MatchingRule.UPDATE), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to update {}", keys);
    List<ProvisioningReport> results = new ArrayList<>();
    for (String key : keys) {
        LOG.debug("About to update {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.UPDATE);
        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());
        }
        if (!profile.isDryRun()) {
            Result resultStatus;
            Object output;
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                try {
                    for (PullActions action : profile.getActions()) {
                        action.beforeUpdate(profile, delta, before, null);
                    }
                    PropagationByResource propByRes = binder.update(realm, before);
                    realm = realmDAO.save(realm);
                    RealmTO updated = binder.getRealmTO(realm, true);
                    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
                    taskExecutor.execute(tasks, false);
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, updated, result);
                    }
                    output = updated;
                    resultStatus = Result.SUCCESS;
                    result.setName(updated.getFullPath());
                    LOG.debug("{} successfully updated", updated);
                } 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(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before, output, delta);
        }
        results.add(result);
    }
    return results;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) RealmTO(org.apache.syncope.common.lib.to.RealmTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) Realm(org.apache.syncope.core.persistence.api.entity.Realm)

Example 17 with ProvisioningReport

use of org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport in project syncope by apache.

the class AbstractPullResultHandler method handle.

@Override
public boolean handle(final SyncDelta delta) {
    Provision provision = null;
    try {
        provision = profile.getTask().getResource().getProvision(delta.getObject().getObjectClass()).orElse(null);
        if (provision == null) {
            throw new JobExecutionException("No provision found on " + profile.getTask().getResource() + " for " + delta.getObject().getObjectClass());
        }
        doHandle(delta, provision);
        executor.reportHandled(delta.getObjectClass(), delta.getObject().getName());
        LOG.debug("Successfully handled {}", delta);
        if (profile.getTask().getPullMode() != PullMode.INCREMENTAL) {
            if (executor.wasInterruptRequested()) {
                LOG.debug("Pull interrupted");
                executor.setInterrupted();
                return false;
            }
            return true;
        }
        boolean shouldContinue;
        synchronized (this) {
            shouldContinue = latestResult == Result.SUCCESS;
            this.latestResult = null;
        }
        if (shouldContinue) {
            executor.setLatestSyncToken(delta.getObjectClass(), delta.getToken());
        }
        if (executor.wasInterruptRequested()) {
            LOG.debug("Pull interrupted");
            executor.setInterrupted();
            return false;
        }
        return shouldContinue;
    } catch (IgnoreProvisionException e) {
        ProvisioningReport ignoreResult = new ProvisioningReport();
        ignoreResult.setOperation(ResourceOperation.NONE);
        ignoreResult.setAnyType(provision == null ? getAnyUtils().getAnyTypeKind().name() : provision.getAnyType().getKey());
        ignoreResult.setStatus(ProvisioningReport.Status.IGNORE);
        ignoreResult.setKey(null);
        ignoreResult.setName(delta.getObject().getName().getNameValue());
        profile.getResults().add(ignoreResult);
        LOG.warn("Ignoring during pull", e);
        executor.setLatestSyncToken(delta.getObjectClass(), delta.getToken());
        executor.reportHandled(delta.getObjectClass(), delta.getObject().getName());
        return true;
    } catch (JobExecutionException e) {
        LOG.error("Pull failed", e);
        return false;
    }
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) JobExecutionException(org.quartz.JobExecutionException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)

Example 18 with ProvisioningReport

use of org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport in project syncope by apache.

the class AbstractPullResultHandler method link.

protected List<ProvisioningReport> link(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.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to update {}", 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.NONE);
        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()) {
            Result resultStatus;
            Object output;
            AnyPatch effectivePatch = null;
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                result.setName(getName(before));
                try {
                    if (unlink) {
                        for (PullActions action : profile.getActions()) {
                            action.beforeUnlink(profile, delta, before);
                        }
                    } else {
                        for (PullActions action : profile.getActions()) {
                            action.beforeLink(profile, delta, before);
                        }
                    }
                    AnyPatch anyPatch = newPatch(before.getKey());
                    anyPatch.getResources().add(new StringPatchItem.Builder().operation(unlink ? PatchOperation.DELETE : PatchOperation.ADD_REPLACE).value(profile.getTask().getResource().getKey()).build());
                    effectivePatch = update(anyPatch).getResult();
                    output = AnyOperations.patch(before, effectivePatch);
                    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.UNLINK) : MatchingRule.toEventName(MatchingRule.LINK), resultStatus, before, output, delta, effectivePatch);
        }
        results.add(result);
    }
    return results;
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

Example 19 with ProvisioningReport

use of org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport in project syncope by apache.

the class AbstractPullResultHandler method ignore.

protected List<ProvisioningReport> ignore(final SyncDelta delta, final List<String> anyKeys, final Provision provision, final boolean matching, final String... message) throws JobExecutionException {
    LOG.debug("Any to ignore {}", delta.getObject().getUid().getUidValue());
    List<ProvisioningReport> results = new ArrayList<>();
    if (anyKeys == null) {
        ProvisioningReport report = new ProvisioningReport();
        report.setKey(null);
        report.setName(delta.getObject().getUid().getUidValue());
        report.setOperation(ResourceOperation.NONE);
        report.setAnyType(provision.getAnyType().getKey());
        report.setStatus(ProvisioningReport.Status.SUCCESS);
        if (message != null && message.length >= 1) {
            report.setMessage(message[0]);
        }
        results.add(report);
    } else {
        for (String anyKey : anyKeys) {
            ProvisioningReport report = new ProvisioningReport();
            report.setKey(anyKey);
            report.setName(delta.getObject().getUid().getUidValue());
            report.setOperation(ResourceOperation.NONE);
            report.setAnyType(provision.getAnyType().getKey());
            report.setStatus(ProvisioningReport.Status.SUCCESS);
            if (message != null && message.length >= 1) {
                report.setMessage(message[0]);
            }
            results.add(report);
        }
    }
    finalize(matching ? MatchingRule.toEventName(MatchingRule.IGNORE) : UnmatchingRule.toEventName(UnmatchingRule.IGNORE), Result.SUCCESS, null, null, delta);
    return results;
}
Also used : ArrayList(java.util.ArrayList) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)

Example 20 with ProvisioningReport

use of org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport in project syncope by apache.

the class AbstractPullResultHandler method update.

protected List<ProvisioningReport> update(final SyncDelta delta, final List<String> anyKeys, final Provision provision) throws JobExecutionException {
    if (!profile.getTask().isPerformUpdate()) {
        LOG.debug("PullTask not configured for update");
        finalize(MatchingRule.toEventName(MatchingRule.UPDATE), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to update {}", anyKeys);
    List<ProvisioningReport> results = new ArrayList<>();
    for (String key : anyKeys) {
        LOG.debug("About to update {}", key);
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.UPDATE);
        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));
        } else {
            result.setName(getName(before));
        }
        if (!profile.isDryRun()) {
            Result resultStatus;
            Object output;
            AnyPatch effectivePatch = null;
            if (before == null) {
                resultStatus = Result.FAILURE;
                output = null;
            } else {
                AnyPatch anyPatch = null;
                try {
                    anyPatch = connObjectUtils.getAnyPatch(before.getKey(), delta.getObject(), before, profile.getTask(), provision, getAnyUtils());
                    for (PullActions action : profile.getActions()) {
                        action.beforeUpdate(profile, delta, before, anyPatch);
                    }
                    effectivePatch = doUpdate(before, anyPatch, delta, result);
                    AnyTO updated = AnyOperations.patch(before, effectivePatch);
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, updated, result);
                    }
                    output = updated;
                    resultStatus = Result.SUCCESS;
                    result.setName(getName(updated));
                    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;
                    if (profile.getTask().isRemediation()) {
                        Remediation entity = entityFactory.newEntity(Remediation.class);
                        entity.setAnyType(provision.getAnyType());
                        entity.setOperation(ResourceOperation.UPDATE);
                        entity.setPayload(anyPatch);
                        entity.setError(result.getMessage());
                        entity.setInstant(new Date());
                        entity.setRemoteName(delta.getObject().getName().getNameValue());
                        entity.setPullTask(profile.getTask());
                        remediationDAO.save(entity);
                    }
                }
            }
            finalize(MatchingRule.toEventName(MatchingRule.UPDATE), resultStatus, before, output, delta, effectivePatch);
        }
        results.add(result);
    }
    return results;
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) Date(java.util.Date) Result(org.apache.syncope.common.lib.types.AuditElements.Result) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation)

Aggregations

ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)21 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)14 JobExecutionException (org.quartz.JobExecutionException)14 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)12 ArrayList (java.util.ArrayList)10 Result (org.apache.syncope.common.lib.types.AuditElements.Result)10 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)8 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)8 AnyTO (org.apache.syncope.common.lib.to.AnyTO)6 RealmTO (org.apache.syncope.common.lib.to.RealmTO)6 Realm (org.apache.syncope.core.persistence.api.entity.Realm)5 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)4 AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)2 Remediation (org.apache.syncope.core.persistence.api.entity.Remediation)2 OrgUnit (org.apache.syncope.core.persistence.api.entity.resource.OrgUnit)2