use of org.apache.syncope.core.provisioning.api.pushpull.PullActions in project syncope by apache.
the class PullJobDelegate method doExecuteProvisioning.
@Override
protected String doExecuteProvisioning(final PullTask pullTask, final Connector connector, final boolean dryRun) throws JobExecutionException {
LOG.debug("Executing pull on {}", pullTask.getResource());
List<PullActions> actions = new ArrayList<>();
pullTask.getActions().forEach(impl -> {
try {
actions.add(ImplementationManager.build(impl));
} catch (Exception e) {
LOG.warn("While building {}", impl, e);
}
});
profile = new ProvisioningProfile<>(connector, pullTask);
profile.getActions().addAll(actions);
profile.setDryRun(dryRun);
profile.setResAct(pullTask.getResource().getPullPolicy() == null ? ConflictResolutionAction.IGNORE : pullTask.getResource().getPullPolicy().getConflictResolutionAction());
latestSyncTokens.clear();
if (!profile.isDryRun()) {
for (PullActions action : actions) {
action.beforeAll(profile);
}
}
status.set("Initialization completed");
// First realms...
if (pullTask.getResource().getOrgUnit() != null) {
status.set("Pulling " + pullTask.getResource().getOrgUnit().getObjectClass().getObjectClassValue());
OrgUnit orgUnit = pullTask.getResource().getOrgUnit();
OperationOptions options = MappingUtils.buildOperationOptions(MappingUtils.getPullItems(orgUnit.getItems()).iterator());
rhandler = buildRealmHandler();
try {
switch(pullTask.getPullMode()) {
case INCREMENTAL:
if (!dryRun) {
latestSyncTokens.put(orgUnit.getObjectClass(), orgUnit.getSyncToken());
}
connector.sync(orgUnit.getObjectClass(), orgUnit.getSyncToken(), rhandler, options);
if (!dryRun) {
orgUnit.setSyncToken(latestSyncTokens.get(orgUnit.getObjectClass()));
resourceDAO.save(orgUnit.getResource());
}
break;
case FILTERED_RECONCILIATION:
ReconFilterBuilder filterBuilder = ImplementationManager.build(pullTask.getReconFilterBuilder());
connector.filteredReconciliation(orgUnit.getObjectClass(), filterBuilder, rhandler, options);
break;
case FULL_RECONCILIATION:
default:
connector.fullReconciliation(orgUnit.getObjectClass(), rhandler, options);
break;
}
} catch (Throwable t) {
throw new JobExecutionException("While pulling from connector", t);
}
}
// ...then provisions for any types
ahandler = buildAnyObjectHandler();
uhandler = buildUserHandler();
ghandler = buildGroupHandler();
for (Provision provision : pullTask.getResource().getProvisions()) {
if (provision.getMapping() != null) {
status.set("Pulling " + provision.getObjectClass().getObjectClassValue());
SyncopePullResultHandler handler;
switch(provision.getAnyType().getKind()) {
case USER:
handler = uhandler;
break;
case GROUP:
handler = ghandler;
break;
case ANY_OBJECT:
default:
handler = ahandler;
}
try {
Set<MappingItem> linkingMappingItems = virSchemaDAO.findByProvision(provision).stream().map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet());
Iterator<MappingItem> mapItems = new IteratorChain<>(provision.getMapping().getItems().iterator(), linkingMappingItems.iterator());
OperationOptions options = MappingUtils.buildOperationOptions(mapItems);
switch(pullTask.getPullMode()) {
case INCREMENTAL:
if (!dryRun) {
latestSyncTokens.put(provision.getObjectClass(), provision.getSyncToken());
}
connector.sync(provision.getObjectClass(), provision.getSyncToken(), handler, options);
if (!dryRun) {
provision.setSyncToken(latestSyncTokens.get(provision.getObjectClass()));
resourceDAO.save(provision.getResource());
}
break;
case FILTERED_RECONCILIATION:
ReconFilterBuilder filterBuilder = ImplementationManager.build(pullTask.getReconFilterBuilder());
connector.filteredReconciliation(provision.getObjectClass(), filterBuilder, handler, options);
break;
case FULL_RECONCILIATION:
default:
connector.fullReconciliation(provision.getObjectClass(), handler, options);
break;
}
} catch (Throwable t) {
throw new JobExecutionException("While pulling from connector", t);
}
}
}
try {
setGroupOwners(ghandler);
} catch (Exception e) {
LOG.error("While setting group owners", e);
}
if (!profile.isDryRun()) {
for (PullActions action : actions) {
action.afterAll(profile);
}
}
status.set("Pull done");
String result = createReport(profile.getResults(), pullTask.getResource(), dryRun);
LOG.debug("Pull result: {}", result);
return result;
}
use of org.apache.syncope.core.provisioning.api.pushpull.PullActions in project syncope by apache.
the class TaskTest method issueSYNCOPE144.
@Test
public void issueSYNCOPE144() {
ExternalResource resource = resourceDAO.find("ws-target-resource-1");
assertNotNull(resource);
Implementation pullActions = entityFactory.newEntity(Implementation.class);
pullActions.setKey("syncope144");
pullActions.setEngine(ImplementationEngine.JAVA);
pullActions.setType(ImplementationType.PULL_ACTIONS);
pullActions.setBody(PullActions.class.getName());
pullActions = implementationDAO.save(pullActions);
PullTask task = entityFactory.newEntity(PullTask.class);
task.setResource(resource);
task.setName("issueSYNCOPE144");
task.setDescription("issueSYNCOPE144 Description");
task.setActive(true);
task.setPullMode(PullMode.FULL_RECONCILIATION);
task.add(pullActions);
task.setMatchingRule(MatchingRule.UPDATE);
task.setUnmatchingRule(UnmatchingRule.PROVISION);
task = taskDAO.save(task);
assertNotNull(task);
PullTask actual = taskDAO.find(task.getKey());
assertEquals(task, actual);
assertEquals("issueSYNCOPE144", actual.getName());
assertEquals("issueSYNCOPE144 Description", actual.getDescription());
actual.setName("issueSYNCOPE144_2");
actual.setDescription("issueSYNCOPE144 Description_2");
actual = taskDAO.save(actual);
assertNotNull(actual);
assertEquals("issueSYNCOPE144_2", actual.getName());
assertEquals("issueSYNCOPE144 Description_2", actual.getDescription());
}
use of org.apache.syncope.core.provisioning.api.pushpull.PullActions 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);
}
use of org.apache.syncope.core.provisioning.api.pushpull.PullActions in project syncope by apache.
the class DefaultRealmPullResultHandler method provision.
private List<ProvisioningReport> provision(final SyncDelta delta, final OrgUnit orgUnit) throws JobExecutionException {
if (!profile.getTask().isPerformCreate()) {
LOG.debug("PullTask not configured for create");
finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
RealmTO realmTO = connObjectUtils.getRealmTO(delta.getObject(), profile.getTask(), orgUnit);
if (realmTO.getFullPath() == null) {
if (realmTO.getParent() == null) {
realmTO.setParent(profile.getTask().getDestinatioRealm().getFullPath());
}
realmTO.setFullPath(realmTO.getParent() + "/" + realmTO.getName());
}
ProvisioningReport result = new ProvisioningReport();
result.setOperation(ResourceOperation.CREATE);
result.setAnyType(REALM_TYPE);
result.setStatus(ProvisioningReport.Status.SUCCESS);
result.setName(realmTO.getFullPath());
if (profile.isDryRun()) {
result.setKey(null);
finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta);
} else {
for (PullActions action : profile.getActions()) {
action.beforeProvision(profile, delta, realmTO);
}
create(realmTO, delta, UnmatchingRule.toEventName(UnmatchingRule.PROVISION), result);
}
return Collections.singletonList(result);
}
use of org.apache.syncope.core.provisioning.api.pushpull.PullActions in project syncope by apache.
the class DefaultRealmPullResultHandler method deprovision.
private List<ProvisioningReport> deprovision(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.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), Result.SUCCESS, null, null, delta);
return Collections.<ProvisioningReport>emptyList();
}
LOG.debug("About to deprovision {}", 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.DELETE);
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()) {
Object output;
Result resultStatus;
if (before == null) {
resultStatus = Result.FAILURE;
output = null;
} else {
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.createTasks(realm, propByRes, null), false);
if (unlink) {
realm.getResources().remove(profile.getTask().getResource());
output = binder.getRealmTO(realmDAO.save(realm), true);
} else {
output = binder.getRealmTO(realm, true);
}
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.UNASSIGN) : MatchingRule.toEventName(MatchingRule.DEPROVISION), resultStatus, before, output, delta);
}
results.add(result);
}
return results;
}
Aggregations