use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.
the class SchedTaskITCase method deferred.
@Test
public void deferred() {
ImplementationTO taskJobDelegate = implementationService.read(ImplementationType.TASKJOB_DELEGATE, TestSampleJobDelegate.class.getSimpleName());
assertNotNull(taskJobDelegate);
SchedTaskTO task = new SchedTaskTO();
task.setActive(true);
task.setName("deferred");
task.setJobDelegate(taskJobDelegate.getKey());
Response response = taskService.create(TaskType.SCHEDULED, task);
task = getObject(response.getLocation(), TaskService.class, SchedTaskTO.class);
assertNotNull(task);
Date initial = new Date();
Date later = DateUtils.addSeconds(initial, 2);
taskService.execute(new ExecuteQuery.Builder().key(task.getKey()).startAt(later).build());
int i = 0;
int maxit = 50;
// wait for completion (executions incremented)
do {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
task = taskService.read(TaskType.SCHEDULED, task.getKey(), true);
assertNotNull(task);
assertNotNull(task.getExecutions());
i++;
} while (task.getExecutions().isEmpty() && i < maxit);
PagedResult<ExecTO> execs = taskService.listExecutions(new ExecQuery.Builder().key(task.getKey()).build());
assertEquals(1, execs.getTotalCount());
assertTrue(execs.getResult().get(0).getStart().after(initial));
// round 1 sec for safety
assertTrue(DateUtils.addSeconds(execs.getResult().get(0).getStart(), 1).after(later));
}
use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.
the class GroupITCase method bulkMembersAction.
@Test
public void bulkMembersAction() throws InterruptedException {
// 1. create group without resources
GroupTO groupTO = getBasicSampleTO("forProvision");
groupTO = createGroup(groupTO).getEntity();
// 2. create user with such group assigned
UserTO userTO = UserITCase.getUniqueSampleTO("forProvision@syncope.apache.org");
userTO.getMemberships().add(new MembershipTO.Builder().group(groupTO.getKey()).build());
userTO = createUser(userTO).getEntity();
// 3. modify the group by assiging the LDAP resource
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(groupTO.getKey());
groupPatch.getResources().add(new StringPatchItem.Builder().value(RESOURCE_NAME_LDAP).build());
ProvisioningResult<GroupTO> groupUpdateResult = updateGroup(groupPatch);
groupTO = groupUpdateResult.getEntity();
PropagationStatus propStatus = groupUpdateResult.getPropagationStatuses().get(0);
assertEquals(RESOURCE_NAME_LDAP, propStatus.getResource());
assertEquals(PropagationTaskExecStatus.SUCCESS, propStatus.getStatus());
// 4. verify that the user above is not found on LDAP
try {
resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
try {
// 5. bulk provision group members
ExecTO exec = groupService.bulkMembersAction(groupTO.getKey(), BulkMembersActionType.PROVISION);
assertNotNull(exec.getRefKey());
int i = 0;
int maxit = 50;
// wait for task exec completion (executions incremented)
SchedTaskTO taskTO;
do {
Thread.sleep(1000);
taskTO = taskService.read(TaskType.SCHEDULED, exec.getRefKey(), true);
assertNotNull(taskTO);
assertNotNull(taskTO.getExecutions());
i++;
} while (taskTO.getExecutions().isEmpty() && i < maxit);
assertFalse(taskTO.getExecutions().isEmpty());
assertEquals(TaskJob.Status.SUCCESS.name(), taskTO.getExecutions().get(0).getStatus());
// 6. verify that the user above is now fond on LDAP
ConnObjectTO userOnLdap = resourceService.readConnObject(RESOURCE_NAME_LDAP, AnyTypeKind.USER.name(), userTO.getKey());
assertNotNull(userOnLdap);
} finally {
groupService.delete(groupTO.getKey());
userService.delete(userTO.getKey());
}
}
use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.
the class ITImplementationLookup method load.
@Override
public void load() {
// in case the Elasticsearch extension is enabled, reinit a clean index for all available domains
if (AopUtils.getTargetClass(anySearchDAO).getName().contains("Elasticsearch")) {
for (Map.Entry<String, DataSource> entry : domainsHolder.getDomains().entrySet()) {
AuthContextUtils.execWithAuthContext(entry.getKey(), () -> {
Implementation reindex = implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream().filter(impl -> impl.getEngine() == ImplementationEngine.JAVA && ES_REINDEX.equals(impl.getBody())).findAny().orElse(null);
if (reindex == null) {
reindex = entityFactory.newEntity(Implementation.class);
reindex.setEngine(ImplementationEngine.JAVA);
reindex.setType(ImplementationType.TASKJOB_DELEGATE);
reindex.setBody(ES_REINDEX);
reindex = implementationDAO.save(reindex);
}
SchedTaskTO task = new SchedTaskTO();
task.setJobDelegate(reindex.getKey());
task.setName("Elasticsearch Reindex");
task = taskLogic.createSchedTask(TaskType.SCHEDULED, task);
taskLogic.execute(task.getKey(), null, false);
return null;
});
}
}
}
use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.
the class TaskServiceImpl method create.
@Override
public Response create(final TaskType type, final SchedTaskTO taskTO) {
SchedTaskTO createdTask;
if (taskTO != null) {
createdTask = logic.createSchedTask(type, taskTO);
} else {
throw new BadRequestException();
}
URI location = uriInfo.getAbsolutePathBuilder().path(createdTask.getKey()).build();
return Response.created(location).header(RESTHeaders.RESOURCE_KEY, createdTask.getKey()).build();
}
Aggregations