use of org.apache.syncope.common.lib.to.PullTaskTO in project syncope by apache.
the class TaskDetails method details.
public void details() {
if (input.parameterNumber() == 0) {
try {
final Map<String, String> details = new LinkedHashMap<>();
final List<TaskTO> notificationTaskTOs = taskSyncopeOperations.list(TaskType.NOTIFICATION.name());
final List<TaskTO> propagationTaskTOs = taskSyncopeOperations.list(TaskType.PROPAGATION.name());
final List<TaskTO> pushTaskTOs = taskSyncopeOperations.list(TaskType.PUSH.name());
final List<TaskTO> scheduledTaskTOs = taskSyncopeOperations.list(TaskType.SCHEDULED.name());
final List<TaskTO> pullTaskTOs = taskSyncopeOperations.list(TaskType.PULL.name());
final List<JobTO> jobTOs = taskSyncopeOperations.listJobs();
final int notificationTaskSize = notificationTaskTOs.size();
final int propagationTaskSize = propagationTaskTOs.size();
final int pushTaskSize = pushTaskTOs.size();
final int scheduledTaskSize = scheduledTaskTOs.size();
final int pullTaskSize = pullTaskTOs.size();
final int jobsSize = jobTOs.size();
long notificationNotExecuted = notificationTaskTOs.stream().filter(notificationTaskTO -> !((NotificationTaskTO) notificationTaskTO).isExecuted()).count();
long propagationNotExecuted = propagationTaskTOs.stream().filter(propagationTaskTO -> ((PropagationTaskTO) propagationTaskTO).getExecutions().isEmpty()).count();
long pushNotExecuted = pushTaskTOs.stream().filter(pushTaskTO -> ((PushTaskTO) pushTaskTO).getExecutions().isEmpty()).count();
long scheduledNotExecuted = scheduledTaskTOs.stream().filter(scheduledTaskTO -> ((SchedTaskTO) scheduledTaskTO).getExecutions().isEmpty()).count();
int pullNotExecuted = 0;
int pullFull = 0;
for (final TaskTO pullTaskTO : pullTaskTOs) {
if (((PullTaskTO) pullTaskTO).getExecutions().isEmpty()) {
pullNotExecuted++;
}
if (((PullTaskTO) pullTaskTO).getPullMode() == PullMode.FULL_RECONCILIATION) {
pullFull++;
}
}
details.put("total number", String.valueOf(notificationTaskSize + propagationTaskSize + pushTaskSize + scheduledTaskSize + pullTaskSize));
details.put("notification tasks", String.valueOf(notificationTaskSize));
details.put("notification tasks not executed", String.valueOf(notificationNotExecuted));
details.put("propagation tasks", String.valueOf(propagationTaskSize));
details.put("propagation tasks not executed", String.valueOf(propagationNotExecuted));
details.put("push tasks", String.valueOf(pushTaskSize));
details.put("push tasks not executed", String.valueOf(pushNotExecuted));
details.put("scheduled tasks", String.valueOf(scheduledTaskSize));
details.put("scheduled tasks not executed", String.valueOf(scheduledNotExecuted));
details.put("pull tasks", String.valueOf(pullTaskSize));
details.put("pull tasks not executed", String.valueOf(pullNotExecuted));
details.put("pull tasks with full reconciliation", String.valueOf(pullFull));
details.put("jobs", String.valueOf(jobsSize));
taskResultManager.printDetails(details);
} catch (final SyncopeClientException ex) {
LOG.error("Error reading details about task", ex);
taskResultManager.genericError(ex.getMessage());
} catch (final IllegalArgumentException ex) {
LOG.error("Error reading details about task", ex);
taskResultManager.typeNotValidError("task", input.firstParameter(), CommandUtils.fromEnumToArray(TaskType.class));
}
} else {
taskResultManager.commandOptionError(DETAILS_HELP_MESSAGE);
}
}
use of org.apache.syncope.common.lib.to.PullTaskTO in project syncope by apache.
the class TaskDataBinderImpl method getTaskTO.
@Override
public <T extends TaskTO> T getTaskTO(final Task task, final TaskUtils taskUtils, final boolean details) {
T taskTO = taskUtils.newTaskTO();
BeanUtils.copyProperties(task, taskTO, IGNORE_TASK_PROPERTIES);
TaskExec latestExec = taskExecDAO.findLatestStarted(task);
if (latestExec == null) {
taskTO.setLatestExecStatus(StringUtils.EMPTY);
} else {
taskTO.setLatestExecStatus(latestExec.getStatus());
taskTO.setStart(latestExec.getStart());
taskTO.setEnd(latestExec.getEnd());
}
if (details) {
task.getExecs().stream().filter(execution -> execution != null).forEachOrdered(execution -> taskTO.getExecutions().add(getExecTO(execution)));
}
switch(taskUtils.getType()) {
case PROPAGATION:
PropagationTask propagationTask = (PropagationTask) task;
PropagationTaskTO propagationTaskTO = (PropagationTaskTO) taskTO;
propagationTaskTO.setAnyTypeKind(propagationTask.getAnyTypeKind());
propagationTaskTO.setEntityKey(propagationTask.getEntityKey());
propagationTaskTO.setResource(propagationTask.getResource().getKey());
propagationTaskTO.setAttributes(propagationTask.getSerializedAttributes());
break;
case SCHEDULED:
SchedTask schedTask = (SchedTask) task;
SchedTaskTO schedTaskTO = (SchedTaskTO) taskTO;
setExecTime(schedTaskTO, task);
if (schedTask.getJobDelegate() != null) {
schedTaskTO.setJobDelegate(schedTask.getJobDelegate().getKey());
}
break;
case PULL:
PullTask pullTask = (PullTask) task;
PullTaskTO pullTaskTO = (PullTaskTO) taskTO;
setExecTime(pullTaskTO, task);
pullTaskTO.setDestinationRealm(pullTask.getDestinatioRealm().getFullPath());
pullTaskTO.setResource(pullTask.getResource().getKey());
pullTaskTO.setMatchingRule(pullTask.getMatchingRule() == null ? MatchingRule.UPDATE : pullTask.getMatchingRule());
pullTaskTO.setUnmatchingRule(pullTask.getUnmatchingRule() == null ? UnmatchingRule.PROVISION : pullTask.getUnmatchingRule());
if (pullTask.getReconFilterBuilder() != null) {
pullTaskTO.setReconFilterBuilder(pullTask.getReconFilterBuilder().getKey());
}
pullTaskTO.getActions().addAll(pullTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
pullTask.getTemplates().forEach(template -> {
pullTaskTO.getTemplates().put(template.getAnyType().getKey(), template.get());
});
pullTaskTO.setRemediation(pullTask.isRemediation());
break;
case PUSH:
PushTask pushTask = (PushTask) task;
PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
setExecTime(pushTaskTO, task);
pushTaskTO.setSourceRealm(pushTask.getSourceRealm().getFullPath());
pushTaskTO.setResource(pushTask.getResource().getKey());
pushTaskTO.setMatchingRule(pushTask.getMatchingRule() == null ? MatchingRule.LINK : pushTask.getMatchingRule());
pushTaskTO.setUnmatchingRule(pushTask.getUnmatchingRule() == null ? UnmatchingRule.ASSIGN : pushTask.getUnmatchingRule());
pushTaskTO.getActions().addAll(pushTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
pushTask.getFilters().forEach(filter -> {
pushTaskTO.getFilters().put(filter.getAnyType().getKey(), filter.getFIQLCond());
});
break;
case NOTIFICATION:
NotificationTask notificationTask = (NotificationTask) task;
NotificationTaskTO notificationTaskTO = (NotificationTaskTO) taskTO;
notificationTaskTO.setNotification(notificationTask.getNotification().getKey());
notificationTaskTO.setAnyTypeKind(notificationTask.getAnyTypeKind());
notificationTaskTO.setEntityKey(notificationTask.getEntityKey());
if (notificationTask.isExecuted() && StringUtils.isBlank(taskTO.getLatestExecStatus())) {
taskTO.setLatestExecStatus("[EXECUTED]");
}
break;
default:
}
return taskTO;
}
use of org.apache.syncope.common.lib.to.PullTaskTO in project syncope by apache.
the class MembershipITCase method pull.
@Test
public void pull() {
// 0. create ad-hoc resource, with adequate mapping
ResourceTO newResource = resourceService.read(RESOURCE_NAME_DBPULL);
newResource.setKey(getUUIDString());
ItemTO item = newResource.getProvision("USER").get().getMapping().getItems().stream().filter(object -> "firstname".equals(object.getIntAttrName())).findFirst().get();
assertNotNull(item);
assertEquals("ID", item.getExtAttrName());
item.setIntAttrName("memberships[additional].aLong");
item.setPurpose(MappingPurpose.BOTH);
item = newResource.getProvision("USER").get().getMapping().getItems().stream().filter(object -> "fullname".equals(object.getIntAttrName())).findFirst().get();
item.setPurpose(MappingPurpose.PULL);
PullTaskTO newTask = null;
try {
newResource = createResource(newResource);
assertNotNull(newResource);
// 1. create user with new resource assigned
UserTO user = UserITCase.getUniqueSampleTO("memb@apache.org");
user.setRealm("/even/two");
user.getPlainAttrs().remove(user.getPlainAttr("ctype").get());
user.getResources().clear();
user.getResources().add(newResource.getKey());
MembershipTO membership = new MembershipTO.Builder().group("034740a9-fa10-453b-af37-dc7897e98fb1").build();
membership.getPlainAttrs().add(new AttrTO.Builder().schema("aLong").value("5432").build());
user.getMemberships().add(membership);
user = createUser(user).getEntity();
assertNotNull(user);
// 2. verify that user was found on resource
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
String idOnResource = queryForObject(jdbcTemplate, 50, "SELECT id FROM testpull WHERE id=?", String.class, "5432");
assertEquals("5432", idOnResource);
// 3. unlink user from resource, then remove it
DeassociationPatch patch = new DeassociationPatch();
patch.setKey(user.getKey());
patch.setAction(ResourceDeassociationAction.UNLINK);
patch.getResources().add(newResource.getKey());
assertNotNull(userService.deassociate(patch).readEntity(BulkActionResult.class));
userService.delete(user.getKey());
// 4. create pull task and execute
newTask = taskService.read(TaskType.PULL, "7c2242f4-14af-4ab5-af31-cdae23783655", true);
newTask.setResource(newResource.getKey());
newTask.setDestinationRealm("/even/two");
Response response = taskService.create(TaskType.PULL, newTask);
newTask = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
assertNotNull(newTask);
ExecTO execution = AbstractTaskITCase.execProvisioningTask(taskService, TaskType.PULL, newTask.getKey(), 50, false);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(execution.getStatus()));
// 5. verify that pulled user has
PagedResult<UserTO> users = userService.search(new AnyQuery.Builder().realm("/").fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo(user.getUsername()).query()).build());
assertEquals(1, users.getTotalCount());
assertEquals(1, users.getResult().get(0).getMemberships().size());
assertEquals("5432", users.getResult().get(0).getMemberships().get(0).getPlainAttr("aLong").get().getValues().get(0));
} catch (Exception e) {
LOG.error("Unexpected error", e);
fail(e.getMessage());
} finally {
if (newTask != null && !"83f7e85d-9774-43fe-adba-ccd856312994".equals(newTask.getKey())) {
taskService.delete(TaskType.PULL, newTask.getKey());
}
resourceService.delete(newResource.getKey());
}
}
use of org.apache.syncope.common.lib.to.PullTaskTO in project syncope by apache.
the class MultitenancyITCase method createResourceAndPull.
@Test
public void createResourceAndPull() {
// read connector
ConnInstanceTO conn = adminClient.getService(ConnectorService.class).read("b7ea96c3-c633-488b-98a0-b52ac35850f7", Locale.ENGLISH.getLanguage());
assertNotNull(conn);
assertEquals("LDAP", conn.getDisplayName());
// prepare resource
ResourceTO resource = new ResourceTO();
resource.setKey("new-ldap-resource");
resource.setConnector(conn.getKey());
try {
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resource.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
mapping.setConnObjectLink("'uid=' + username + ',ou=people,o=isp'");
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("username");
item.setExtAttrName("cn");
item.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(item);
item = new ItemTO();
item.setPassword(true);
item.setIntAttrName("password");
item.setExtAttrName("userPassword");
item.setPurpose(MappingPurpose.BOTH);
item.setMandatoryCondition("true");
mapping.add(item);
item = new ItemTO();
item.setIntAttrName("key");
item.setPurpose(MappingPurpose.BOTH);
item.setExtAttrName("sn");
item.setMandatoryCondition("true");
mapping.add(item);
item = new ItemTO();
item.setIntAttrName("email");
item.setPurpose(MappingPurpose.BOTH);
item.setExtAttrName("mail");
mapping.add(item);
// create resource
Response response = adminClient.getService(ResourceService.class).create(resource);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
resource = adminClient.getService(ResourceService.class).read(resource.getKey());
assertNotNull(resource);
// create pull task
PullTaskTO task = new PullTaskTO();
task.setName("LDAP Pull Task");
task.setActive(true);
task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
task.setResource(resource.getKey());
task.setPullMode(PullMode.FULL_RECONCILIATION);
task.setPerformCreate(true);
response = adminClient.getService(TaskService.class).create(TaskType.PULL, task);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
task = adminClient.getService(TaskService.class).read(TaskType.PULL, StringUtils.substringAfterLast(response.getLocation().toASCIIString(), "/"), true);
assertNotNull(resource);
// pull
ExecTO execution = AbstractTaskITCase.execProvisioningTask(adminClient.getService(TaskService.class), TaskType.PULL, task.getKey(), 50, false);
// verify execution status
String status = execution.getStatus();
assertNotNull(status);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(status));
// verify that pulled user is found
PagedResult<UserTO> matchingUsers = adminClient.getService(UserService.class).search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
assertNotNull(matchingUsers);
assertEquals(1, matchingUsers.getResult().size());
} finally {
adminClient.getService(ResourceService.class).delete(resource.getKey());
}
}
use of org.apache.syncope.common.lib.to.PullTaskTO in project syncope by apache.
the class PullTaskITCase method reconcileFromScriptedSQL.
@Test
public void reconcileFromScriptedSQL() throws IOException {
// 0. reset sync token and set MappingItemTransformer
ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED);
ResourceTO originalResource = SerializationUtils.clone(resource);
ProvisionTO provision = resource.getProvision("PRINTER").get();
assertNotNull(provision);
ItemTO mappingItem = provision.getMapping().getItems().stream().filter(object -> "location".equals(object.getIntAttrName())).findFirst().get();
assertNotNull(mappingItem);
final String prefix = "PREFIX_";
ImplementationTO transformer = new ImplementationTO();
transformer.setKey("PrefixItemTransformer");
transformer.setEngine(ImplementationEngine.GROOVY);
transformer.setType(ImplementationType.ITEM_TRANSFORMER);
transformer.setBody(IOUtils.toString(getClass().getResourceAsStream("/PrefixItemTransformer.groovy"), StandardCharsets.UTF_8));
Response response = implementationService.create(transformer);
transformer = implementationService.read(transformer.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(transformer);
mappingItem.getTransformers().clear();
mappingItem.getTransformers().add(transformer.getKey());
try {
resourceService.update(resource);
resourceService.removeSyncToken(resource.getKey(), provision.getAnyType());
// insert a deleted record in the external resource (SYNCOPE-923), which will be returned
// as sync event prior to the CREATE_OR_UPDATE events generated by the actions below (before pull)
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
jdbcTemplate.update("INSERT INTO TESTPRINTER (id, printername, location, deleted, lastmodification) VALUES (?,?,?,?,?)", UUID.randomUUID().toString(), "Mysterious Printer", "Nowhere", true, new Date());
// 1. create printer on external resource
AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("pull");
String originalLocation = anyObjectTO.getPlainAttr("location").get().getValues().get(0);
assertFalse(originalLocation.startsWith(prefix));
anyObjectTO = createAnyObject(anyObjectTO).getEntity();
assertNotNull(anyObjectTO);
// 2. verify that PrefixMappingItemTransformer was applied during propagation
// (location starts with given prefix on external resource)
ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
assertFalse(anyObjectTO.getPlainAttr("location").get().getValues().get(0).startsWith(prefix));
assertTrue(connObjectTO.getAttr("LOCATION").get().getValues().get(0).startsWith(prefix));
// 3. unlink any existing printer and delete from Syncope (printer is now only on external resource)
PagedResult<AnyObjectTO> matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
assertTrue(matchingPrinters.getSize() > 0);
for (AnyObjectTO printer : matchingPrinters.getResult()) {
anyObjectService.deassociate(new DeassociationPatch.Builder().key(printer.getKey()).action(ResourceDeassociationAction.UNLINK).resource(RESOURCE_NAME_DBSCRIPTED).build());
anyObjectService.delete(printer.getKey());
}
// ensure that the pull task does not have the DELETE capability (SYNCOPE-923)
PullTaskTO pullTask = taskService.read(TaskType.PULL, "30cfd653-257b-495f-8665-281281dbcb3d", false);
assertNotNull(pullTask);
assertFalse(pullTask.isPerformDelete());
// 4. pull
execProvisioningTask(taskService, TaskType.PULL, pullTask.getKey(), 50, false);
// 5. verify that printer was re-created in Syncope (implies that location does not start with given prefix,
// hence PrefixItemTransformer was applied during pull)
matchingPrinters = anyObjectService.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("pull*").query()).build());
assertTrue(matchingPrinters.getSize() > 0);
// 6. verify that synctoken was updated
assertNotNull(resourceService.read(RESOURCE_NAME_DBSCRIPTED).getProvision(anyObjectTO.getType()).get().getSyncToken());
} finally {
resourceService.update(originalResource);
}
}
Aggregations