Search in sources :

Example 16 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class ProvisioningBreakProcessorTest method testBlockSystemUpdateCombination.

@Test
public void testBlockSystemUpdateCombination() {
    SysSystemDto system = getHelper().createTestResourceSystem(true);
    // 
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    createProvisioningBreak(20l, 1, null, ProvisioningEventType.UPDATE, system.getId());
    // 
    this.createAccount(system, identity);
    // 
    // 
    // create
    provisioningService.doProvisioning(identity);
    // 
    SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
    SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
    List<SysProvisioningOperationDto> content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
    // 
    assertTrue(content.isEmpty());
    // 
    provisioningService.doProvisioning(identity);
    // block
    provisioningService.doProvisioning(identity);
    // 
    systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
    batch = batchService.findBatch(systemEntity.getId());
    content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
    assertEquals(1, content.size());
    // 
    SysProvisioningOperationDto sysProvisioningOperationDto = content.get(0);
    // 
    assertEquals(ProvisioningEventType.UPDATE, sysProvisioningOperationDto.getOperationType());
    assertEquals(OperationState.BLOCKED, sysProvisioningOperationDto.getResult().getState());
}
Also used : SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 17 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class SysProvisioningOperationFilterIntegrationTest method batchIdFilterTest.

@Test
public void batchIdFilterTest() {
    IdmBasePermission permission = IdmBasePermission.ADMIN;
    SystemEntityType entityType = SystemEntityType.IDENTITY;
    SysSystemDto system = createSystem();
    SysProvisioningOperationDto provisioningOperation1 = createProvisioningOperation(entityType, system);
    SysProvisioningBatchDto provisioningBatch = new SysProvisioningBatchDto(provisioningOperation1);
    provisioningBatch = batchService.save(provisioningBatch);
    provisioningOperation1.setBatch(provisioningBatch.getId());
    provisioningOperation1 = operationService.save(provisioningOperation1);
    SysProvisioningOperationDto provisioningOperation2 = createProvisioningOperation(entityType, system);
    provisioningOperation2.setBatch(provisioningBatch.getId());
    provisioningOperation2 = operationService.save(provisioningOperation2);
    SysProvisioningOperationDto provisioningOperation3 = createProvisioningOperation(entityType, system);
    SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
    filter.setSystemId(system.getId());
    filter.setBatchId(provisioningBatch.getId());
    Page<SysProvisioningOperationDto> result = operationService.find(filter, null, permission);
    assertEquals(2, result.getTotalElements());
    assertTrue(result.getContent().contains(provisioningOperation1));
    assertTrue(result.getContent().contains(provisioningOperation2));
    assertFalse(result.getContent().contains(provisioningOperation3));
}
Also used : SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 18 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class RetryProvisioningTaskExecutor method process.

@Override
public Boolean process() {
    LOG.info("Retry provisioning executor starts for all next attmepts old than [{}]", start);
    counter = 0L;
    boolean canContinue = true;
    while (canContinue) {
        // we process all batches
        Page<SysProvisioningBatchDto> batches = provisioningBatchService.findBatchesToRetry(start, PageRequest.of(0, 100));
        // init count
        if (count == null) {
            count = batches.getTotalElements();
        }
        // 
        for (SysProvisioningBatchDto batch : batches) {
            try {
                this.logItemProcessed(batch, provisioningExecutor.execute(batch));
                counter++;
                canContinue = updateState();
            } catch (Exception ex) {
                // TODO: redesign Boolean result to OperationResult
                LOG.error("Batch [{}] execution failed", batch.getId(), ex);
            }
            if (!canContinue) {
                break;
            }
        }
        if (!batches.hasNext()) {
            break;
        }
    }
    LOG.info("Retry provisioning executor ended for all next attempts old than [{}]", start);
    return Boolean.TRUE;
}
Also used : SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)

Example 19 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class DefaultSysProvisioningOperationService method handleSuccessful.

/**
 * REQUIRES_NEW => we want to have log in queue / archive all time, even original transaction ends with exception (after calling this method).
 */
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public SysProvisioningOperationDto handleSuccessful(SysProvisioningOperationDto operation) {
    ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SUCCEED, ImmutableMap.of(// FIXME: String uid = getByProvisioningOperation(operation).getUid();
    "name", // FIXME: String uid = getByProvisioningOperation(operation).getUid();
    operation.getSystemEntityUid(), "system", getSystem(operation).getName(), "operationType", operation.getOperationType(), "objectClass", operation.getProvisioningContext().getConnectorObject().getObjectClass().getType()));
    operation.setResult(new OperationResult.Builder(OperationState.EXECUTED).setModel(resultModel).build());
    if (!operation.isDryRun()) {
        operation = save(operation);
        // 
        // cleanup next attempt time - batch are not removed
        SysProvisioningBatchDto batch = DtoUtils.getEmbedded(operation, SysProvisioningOperation_.batch, (SysProvisioningBatchDto) null);
        if (batch == null) {
            batch = batchService.get(operation.getBatch());
        }
        if (batch.getNextAttempt() != null) {
            batch.setNextAttempt(null);
            batch = batchService.save(batch);
        }
        // 
        LOG.info(resultModel.toString());
    // 
    }
    return operation;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with SysProvisioningBatchDto

use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.

the class DefaultProvisioningExecutor method persistOperation.

/**
 * Persist new operation - assign appropriate batch. Operation is put into queue, if it's already in the queue.
 */
private SysProvisioningOperationDto persistOperation(SysProvisioningOperationDto provisioningOperation) {
    Assert.notNull(provisioningOperation, "Provisioning operation is required.");
    Assert.notNull(provisioningOperation.getSystemEntity(), "System entity is required.");
    Assert.notNull(provisioningOperation.getProvisioningContext(), "Provisioning context is required.");
    // get system from service, in provisioning operation may not exist
    SysSystemDto system = DtoUtils.getEmbedded(provisioningOperation, SysProvisioningOperation_.system, (SysSystemDto) null);
    if (system == null) {
        system = systemService.get(provisioningOperation.getSystem());
    }
    Assert.notNull(system, "System is required.");
    // make sure system will be in embedded - optimize
    provisioningOperation.getEmbedded().put(SysProvisioningOperation_.system.getName(), system);
    // dryRun provisioning - skip SysProvisioningOperationDto saving
    if (provisioningOperation.isDryRun()) {
        if (provisioningOperation.getId() == null) {
            // FAKE UUID - we don't want to save provisioningOperation but its UUID must not be null
            provisioningOperation.setId(UUID.randomUUID());
        }
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
        return provisioningOperation;
    }
    // save new operation to provisioning log / queue
    String uid = systemEntityService.getByProvisioningOperation(provisioningOperation).getUid();
    // look out - system entity uid can be changed - we need to use system entity id
    SysProvisioningBatchDto batch = batchService.findBatch(provisioningOperation.getSystemEntity());
    if (batch == null) {
        // new batch
        batch = batchService.save(new SysProvisioningBatchDto(provisioningOperation));
        provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
    } else {
        SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
        filter.setNotInState(OperationState.CREATED);
        filter.setBatchId(batch.getId());
        List<SysProvisioningOperationDto> activeOperations = provisioningOperationService.find(filter, PageRequest.of(0, 1, new Sort(Direction.DESC, SysProvisioningOperation_.created.getName()))).getContent();
        if (activeOperations.isEmpty()) {
            // batch is completed (no operations in queue)
            provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
        } else {
            // put to queue, if previous
            ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_IS_IN_QUEUE, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", provisioningOperation.getOperationType(), "objectClass", provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass()));
            LOG.debug(resultModel.toString());
            provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
            if (activeOperations.get(0).getResultState() == OperationState.RUNNING) {
                // the last operation = the first operation and it's running
                // Retry date will be set for the second operation in the queue (the first is running).
                // Other operations will be executed automatically by batch.
                provisioningOperation.setMaxAttempts(provisioningConfiguration.getRetryMaxAttempts());
                batch.setNextAttempt(batchService.calculateNextAttempt(provisioningOperation));
                batch = batchService.save(batch);
            }
            if (securityService.getCurrentId() != null) {
                // TODO: check logged identity and account owner
                notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder(NotificationLevel.WARNING).setModel(provisioningOperation.getResult().getModel()).build());
            }
        }
    }
    provisioningOperation.setBatch(batch.getId());
    provisioningOperation = provisioningOperationService.save(provisioningOperation);
    // 
    return provisioningOperation;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Sort(org.springframework.data.domain.Sort) SysProvisioningBatchDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)

Aggregations

SysProvisioningBatchDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto)24 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)16 SysProvisioningOperationDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto)15 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)14 Test (org.junit.Test)14 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)11 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)9 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)5 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)5 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)4 SysProvisioningArchiveDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto)3 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)3 RetryProvisioningTaskExecutor (eu.bcvsolutions.idm.acc.scheduler.task.impl.RetryProvisioningTaskExecutor)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)3 UUID (java.util.UUID)3