use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessor method process.
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
try {
SysProvisioningOperationDto provisioningOperation = event.getContent();
ProvisioningEventType operationType = provisioningOperation.getOperationType();
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
// system may be blocked
boolean blocked = isSystemBlockedOperation(operationType, system);
//
if (blocked) {
// system is already blocked
provisioningOperation = blockOperation(provisioningOperation, system);
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this, blocked);
}
//
// try found provisioning break configuration
SysProvisioningBreakConfigDto breakConfig = breakConfigService.getConfig(operationType, system.getId());
if (breakConfig == null) {
LOG.debug("Provisioning break configuration for system name: [{}] and operation: [{}] not found. Global configuration will be used.", system.getCode(), operationType.toString());
breakConfig = breakConfigService.getGlobalBreakConfiguration(operationType);
}
//
if (breakConfig == null) {
LOG.debug("Global configuration for provisioning break isn't found.");
return new DefaultEventResult<>(event, this, blocked);
}
//
if (breakConfig.isDisabled()) {
LOG.debug("Provisioning break configuration id: [{}] for system name: [{}] and operation: [{}] is disabled.", breakConfig.getId(), system.getCode(), operationType.toString());
// break configuration is disable continue
return new DefaultEventResult<>(event, this, blocked);
}
Long currentTimeMillis = System.currentTimeMillis();
//
// get cache for system
SysProvisioningBreakItems cache = breakConfigService.getCacheProcessedItems(system.getId());
// calculate timestamp without period
Long timestampWithoutPeriod = currentTimeMillis - breakConfig.getPeriod(TimeUnit.MILLISECONDS);
// remove older records
cache.removeOlderRecordsThan(operationType, timestampWithoutPeriod);
// get actual count - processed items from timestampWithoutPeriod
int actualCount = cache.getSizeRecordsNewerThan(operationType, timestampWithoutPeriod);
// operation count is sum all previous operation except this operation
if (breakConfig.getWarningLimit() != null && breakConfig.getWarningLimit().equals(actualCount)) {
// disabled may be null
if (breakConfig.getDisableLimit() == null) {
LOG.warn("Block for the system id [{}] and operation [{}] is not set. Operation counter [{}].", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), actualCount);
} else {
LOG.warn("To block the system id [{}] for operation [{}] remains [{}] operations + send message.", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), breakConfig.getDisableLimit() - actualCount);
}
IdmNotificationTemplateDto template = null;
if (breakConfig.getWarningTemplate() == null) {
LOG.debug("Warning template for provisioning break id [{}] missing.", breakConfig.getId());
} else {
template = DtoUtils.getEmbedded(breakConfig, SysProvisioningBreakConfig_.warningTemplate, IdmNotificationTemplateDto.class);
}
//
sendMessage(AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_WARNING, system, actualCount, template, breakConfig, operationType, cache.getDiffBetweenActualAndLast(operationType, currentTimeMillis));
} else if (breakConfig.getDisableLimit() != null && actualCount >= breakConfig.getDisableLimit()) {
// check count is higher than disable limit
// block system for operation
blockSystemForOperation(operationType, system);
//
IdmNotificationTemplateDto template = null;
if (breakConfig.getWarningTemplate() == null) {
LOG.debug("Warning template for provisioning break id [{}] missing.", breakConfig.getId());
} else {
template = DtoUtils.getEmbedded(breakConfig, SysProvisioningBreakConfig_.disableTemplate, IdmNotificationTemplateDto.class);
}
//
sendMessage(AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_DISABLE, system, actualCount, template, breakConfig, operationType, cache.getDiffBetweenActualAndLast(operationType, currentTimeMillis));
//
LOG.warn("System id: [{}] will be blocked for operation: [{}].", provisioningOperation.getSystem(), operationType.toString());
provisioningOperation = blockOperation(provisioningOperation, system);
blocked = true;
} else if (breakConfig.getWarningLimit() != null && actualCount > breakConfig.getWarningLimit()) {
// after overrun warning limit, isn't send any another notification - add at least log
if (breakConfig.getDisableLimit() == null) {
LOG.warn("Block for the system id [{}] and operation [{}] is not set. Operation counter [{}].", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), actualCount);
} else {
LOG.warn("To block the system id [{}] for operation [{}] remains [{}] operations.", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), breakConfig.getDisableLimit() - actualCount);
}
}
// remove all unless items in cache
cache.addItem(operationType, currentTimeMillis);
breakConfigService.saveCacheProcessedItems(provisioningOperation.getSystem(), cache);
//
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this, blocked);
} catch (Exception ex) {
LOG.error("Unexpect error while evaluate provisioning break.", ex);
throw new ProvisioningException(AccResultCode.PROVISIONING_FAILED, ex);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method testPeriod.
@Test
public void testPeriod() {
SysSystemDto system = testHelper.createTestResourceSystem(true);
IdmIdentityDto identity = testHelper.createIdentity();
SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, 2, null, ProvisioningEventType.UPDATE, system.getId());
IdmIdentityDto recipient = testHelper.createIdentity();
createRecipient(breakConfig.getId(), recipient.getId(), null);
//
this.createAccount(system, identity);
//
//
// create
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
//
SysProvisioningBreakItems cacheProcessedItems = provisioningBreakConfig.getCacheProcessedItems(system.getId());
//
// subtrack only 19 minutes from all items
long subtrackMinutes = 1140000;
List<Long> execudedItems = cacheProcessedItems.getExecutedItems(ProvisioningEventType.UPDATE);
// it isn't possible use foreEach or another stream function (reference)
for (Long item : execudedItems) {
execudedItems.set(execudedItems.indexOf(item), item - subtrackMinutes);
}
//
// block
provisioningService.doProvisioning(identity);
//
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
SysProvisioningBatchDto batch = batchService.findBatch(system.getId(), identity.getId(), systemEntity.getId());
//
assertNotNull(batch);
//
List<SysProvisioningOperationDto> 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());
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method testPeriodOld.
@Test
public void testPeriodOld() {
SysSystemDto system = testHelper.createTestResourceSystem(true);
IdmIdentityDto identity = testHelper.createIdentity();
SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, 3, null, ProvisioningEventType.UPDATE, system.getId());
IdmIdentityDto recipient = testHelper.createIdentity();
createRecipient(breakConfig.getId(), recipient.getId(), null);
//
this.createAccount(system, identity);
//
//
// create
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
//
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
SysProvisioningBatchDto batch = batchService.findBatch(system.getId(), identity.getId(), systemEntity.getId());
//
assertNull(batch);
//
SysProvisioningBreakItems cacheProcessedItems = provisioningBreakConfig.getCacheProcessedItems(system.getId());
//
// subtrack 25 minutes from all items
long subtrackMinutes = 1500000;
List<Long> execudedItems = cacheProcessedItems.getExecutedItems(ProvisioningEventType.UPDATE);
// it isn't possible use foreEach or another stream function (reference)
for (Long item : execudedItems) {
execudedItems.set(execudedItems.indexOf(item), item - subtrackMinutes);
}
//
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
//
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
batch = batchService.findBatch(system.getId(), identity.getId(), systemEntity.getId());
//
assertNull(batch);
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningBreakConfigService method getCacheProcessedItems.
@Override
public SysProvisioningBreakItems getCacheProcessedItems(UUID systemId) {
SimpleValueWrapper cachedValueWrapper = (SimpleValueWrapper) this.getCache().get(systemId);
if (cachedValueWrapper == null) {
return new SysProvisioningBreakItems();
}
SysProvisioningBreakItems cache = (SysProvisioningBreakItems) cachedValueWrapper.get();
if (cache == null) {
return new SysProvisioningBreakItems();
}
return cache;
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningBreakConfigService method clearCache.
@Override
public void clearCache(UUID systemId, ProvisioningEventType event) {
SysProvisioningBreakItems cache = this.getCacheProcessedItems(systemId);
cache.clearRecords(event);
}
Aggregations