Search in sources :

Example 6 with SchedTaskTO

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));
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) ExecQuery(org.apache.syncope.common.rest.api.beans.ExecQuery) TestSampleJobDelegate(org.apache.syncope.fit.core.reference.TestSampleJobDelegate) Date(java.util.Date) ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Test(org.junit.jupiter.api.Test)

Example 7 with SchedTaskTO

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());
    }
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Test(org.junit.jupiter.api.Test)

Example 8 with SchedTaskTO

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;
            });
        }
    }
}
Also used : SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Map(java.util.Map) HashMap(java.util.HashMap) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) DataSource(javax.sql.DataSource)

Example 9 with SchedTaskTO

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();
}
Also used : SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI)

Aggregations

SchedTaskTO (org.apache.syncope.common.lib.to.SchedTaskTO)9 Test (org.junit.jupiter.api.Test)5 Response (javax.ws.rs.core.Response)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 ExecTO (org.apache.syncope.common.lib.to.ExecTO)3 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)3 TaskService (org.apache.syncope.common.rest.api.service.TaskService)3 TestSampleJobDelegate (org.apache.syncope.fit.core.reference.TestSampleJobDelegate)3 Map (java.util.Map)2 JobTO (org.apache.syncope.common.lib.to.JobTO)2 NotificationTaskTO (org.apache.syncope.common.lib.to.NotificationTaskTO)2 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)2 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)2 PushTaskTO (org.apache.syncope.common.lib.to.PushTaskTO)2 TaskTO (org.apache.syncope.common.lib.to.TaskTO)2 TaskType (org.apache.syncope.common.lib.types.TaskType)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 URI (java.net.URI)1 Date (java.util.Date)1