Search in sources :

Example 1 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class SystemConfigurationDto method getNewObject.

public SystemConfigurationType getNewObject() throws DatatypeConfigurationException {
    SystemConfigurationType newObject = oldObject.clone();
    if (StringUtils.isNotBlank(getPassPolicyDto().getOid())) {
        ObjectReferenceType globalPassPolicyRef = ObjectTypeUtil.createObjectRef(getPassPolicyDto().getOid(), ObjectTypes.PASSWORD_POLICY);
        newObject.setGlobalPasswordPolicyRef(globalPassPolicyRef);
    } else {
        newObject.setGlobalPasswordPolicyRef(null);
    }
    if (StringUtils.isNotBlank(getSecurityPolicyDto().getOid())) {
        ObjectReferenceType globalSecurityPolicyRef = ObjectTypeUtil.createObjectRef(getSecurityPolicyDto().getOid(), WebComponentUtil.createPolyFromOrigString(getSecurityPolicyDto().getName()), ObjectTypes.SECURITY_POLICY);
        newObject.setGlobalSecurityPolicyRef(globalSecurityPolicyRef);
    } else {
        newObject.setGlobalSecurityPolicyRef(null);
    }
    AssignmentPolicyEnforcementType globalAEP = AEPlevel.toAEPValueType(getAepLevel());
    if (globalAEP != null) {
        ProjectionPolicyType projectionPolicy = new ProjectionPolicyType();
        projectionPolicy.setAssignmentPolicyEnforcement(globalAEP);
        newObject.setGlobalAccountSynchronizationSettings(projectionPolicy);
    }
    Duration auditCleanupDuration = DatatypeFactory.newInstance().newDuration(getAuditCleanupValue());
    Duration cleanupTaskDuration = DatatypeFactory.newInstance().newDuration(getTaskCleanupValue());
    CleanupPolicyType auditCleanup = new CleanupPolicyType();
    CleanupPolicyType taskCleanup = new CleanupPolicyType();
    auditCleanup.setMaxAge(auditCleanupDuration);
    taskCleanup.setMaxAge(cleanupTaskDuration);
    CleanupPoliciesType cleanupPolicies = new CleanupPoliciesType();
    cleanupPolicies.setAuditRecords(auditCleanup);
    cleanupPolicies.setClosedTasks(taskCleanup);
    newObject.setCleanupPolicy(cleanupPolicies);
    SystemConfigurationTypeUtil.setEnableExperimentalCode(newObject, getEnableExperimentalCode());
    newObject.setLogging(loggingConfig.getNewObject());
    newObject.setNotificationConfiguration(notificationConfig.getNewObject(newObject));
    newObject.setProfilingConfiguration(profilingDto.getNewObject());
    ClassLoggerConfigurationType profilingClassLogger = profilingDto.getProfilingClassLogerConfig();
    if (newObject.getLogging() != null) {
        newObject.getLogging().getClassLogger().add(profilingClassLogger);
    } else {
        LoggingConfigurationType profLogging = new LoggingConfigurationType();
        profLogging.getClassLogger().add(profilingClassLogger);
        newObject.setLogging(profLogging);
    }
    return newObject;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) LoggingConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.LoggingConfigurationType) AssignmentPolicyEnforcementType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentPolicyEnforcementType) CleanupPoliciesType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPoliciesType) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) Duration(javax.xml.datatype.Duration) ClassLoggerConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ClassLoggerConfigurationType) ProjectionPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionPolicyType)

Example 2 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class SqlAuditServiceImpl method cleanupAuditMaxAge.

private void cleanupAuditMaxAge(CleanupPolicyType policy, OperationResult parentResult) {
    final String operation = "deletingMaxAge";
    SqlPerformanceMonitor pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart("cleanupAuditMaxAge");
    int attempt = 1;
    if (policy.getMaxAge() == null) {
        return;
    }
    Duration duration = policy.getMaxAge();
    if (duration.getSign() > 0) {
        duration = duration.negate();
    }
    Date minValue = new Date();
    duration.addTo(minValue);
    // factored out because it produces INFO-level message
    Dialect dialect = Dialect.getDialect(baseHelper.getSessionFactoryBean().getHibernateProperties());
    checkTemporaryTablesSupport(dialect);
    long start = System.currentTimeMillis();
    boolean first = true;
    Holder<Integer> totalCountHolder = new Holder<>(0);
    try {
        while (true) {
            try {
                LOGGER.info("{} audit cleanup, deleting up to {} (duration '{}'), batch size {}{}.", first ? "Starting" : "Continuing with ", minValue, duration, CLEANUP_AUDIT_BATCH_SIZE, first ? "" : ", up to now deleted " + totalCountHolder.getValue() + " entries");
                first = false;
                int count;
                do {
                    // the following method may restart due to concurrency
                    // (or any other) problem - in any iteration
                    long batchStart = System.currentTimeMillis();
                    LOGGER.debug("Starting audit cleanup batch, deleting up to {} (duration '{}'), batch size {}, up to now deleted {} entries.", minValue, duration, CLEANUP_AUDIT_BATCH_SIZE, totalCountHolder.getValue());
                    count = batchDeletionAttempt((session, tempTable) -> selectRecordsByMaxAge(session, tempTable, minValue, dialect), totalCountHolder, batchStart, dialect, parentResult);
                } while (count > 0);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, parentResult);
                pm.registerOperationNewTrial(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
        LOGGER.info("Audit cleanup based on age finished; deleted {} entries in {} seconds.", totalCountHolder.getValue(), (System.currentTimeMillis() - start) / 1000L);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) BiFunction(java.util.function.BiFunction) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SQLQuery(org.hibernate.SQLQuery) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) GetObjectResult(com.evolveum.midpoint.repo.sql.util.GetObjectResult) Map(java.util.Map) Query(org.hibernate.Query) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) AuditService(com.evolveum.midpoint.audit.api.AuditService) Holder(com.evolveum.midpoint.util.Holder) ScrollableResults(org.hibernate.ScrollableResults) Timestamp(java.sql.Timestamp) Set(java.util.Set) FlushMode(org.hibernate.FlushMode) MiscUtil(com.evolveum.midpoint.util.MiscUtil) RowSelection(org.hibernate.engine.spi.RowSelection) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Projections(org.hibernate.criterion.Projections) Task(com.evolveum.midpoint.task.api.Task) LimitHandler(org.hibernate.dialect.pagination.LimitHandler) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) BaseHelper(com.evolveum.midpoint.repo.sql.helpers.BaseHelper) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) com.evolveum.midpoint.repo.sql.data.audit(com.evolveum.midpoint.repo.sql.data.audit) List(java.util.List) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) Dialect(org.hibernate.dialect.Dialect) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemException(com.evolveum.midpoint.util.exception.SystemException) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) Statement(java.sql.Statement) Entry(java.util.Map.Entry) RUtil(com.evolveum.midpoint.repo.sql.util.RUtil) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Types(java.sql.Types) Holder(com.evolveum.midpoint.util.Holder) Duration(javax.xml.datatype.Duration) Date(java.util.Date) Dialect(org.hibernate.dialect.Dialect)

Example 3 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class SqlAuditServiceImpl method cleanupAuditMaxRecords.

private void cleanupAuditMaxRecords(CleanupPolicyType policy, OperationResult parentResult) {
    final String operation = "deletingMaxRecords";
    SqlPerformanceMonitor pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart("cleanupAuditMaxRecords");
    int attempt = 1;
    if (policy.getMaxRecords() == null) {
        return;
    }
    Integer recordsToKeep = policy.getMaxRecords();
    // factored out because it produces INFO-level message
    Dialect dialect = Dialect.getDialect(baseHelper.getSessionFactoryBean().getHibernateProperties());
    checkTemporaryTablesSupport(dialect);
    long start = System.currentTimeMillis();
    boolean first = true;
    Holder<Integer> totalCountHolder = new Holder<>(0);
    try {
        while (true) {
            try {
                LOGGER.info("{} audit cleanup, keeping at most {} records, batch size {}{}.", first ? "Starting" : "Continuing with ", recordsToKeep, CLEANUP_AUDIT_BATCH_SIZE, first ? "" : ", up to now deleted " + totalCountHolder.getValue() + " entries");
                first = false;
                int count;
                do {
                    // the following method may restart due to concurrency
                    // (or any other) problem - in any iteration
                    long batchStart = System.currentTimeMillis();
                    LOGGER.debug("Starting audit cleanup batch, keeping at most {} records, batch size {}, up to now deleted {} entries.", recordsToKeep, CLEANUP_AUDIT_BATCH_SIZE, totalCountHolder.getValue());
                    count = batchDeletionAttempt((session, tempTable) -> selectRecordsByNumberToKeep(session, tempTable, recordsToKeep, dialect), totalCountHolder, batchStart, dialect, parentResult);
                } while (count > 0);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, parentResult);
                pm.registerOperationNewTrial(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
        LOGGER.info("Audit cleanup based on record count finished; deleted {} entries in {} seconds.", totalCountHolder.getValue(), (System.currentTimeMillis() - start) / 1000L);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) BiFunction(java.util.function.BiFunction) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SQLQuery(org.hibernate.SQLQuery) Session(org.hibernate.Session) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) GetObjectResult(com.evolveum.midpoint.repo.sql.util.GetObjectResult) Map(java.util.Map) Query(org.hibernate.Query) DtoTranslationException(com.evolveum.midpoint.repo.sql.util.DtoTranslationException) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) AuditService(com.evolveum.midpoint.audit.api.AuditService) Holder(com.evolveum.midpoint.util.Holder) ScrollableResults(org.hibernate.ScrollableResults) Timestamp(java.sql.Timestamp) Set(java.util.Set) FlushMode(org.hibernate.FlushMode) MiscUtil(com.evolveum.midpoint.util.MiscUtil) RowSelection(org.hibernate.engine.spi.RowSelection) PrismObject(com.evolveum.midpoint.prism.PrismObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Projections(org.hibernate.criterion.Projections) Task(com.evolveum.midpoint.task.api.Task) LimitHandler(org.hibernate.dialect.pagination.LimitHandler) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) BaseHelper(com.evolveum.midpoint.repo.sql.helpers.BaseHelper) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) com.evolveum.midpoint.repo.sql.data.audit(com.evolveum.midpoint.repo.sql.data.audit) List(java.util.List) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) Dialect(org.hibernate.dialect.Dialect) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemException(com.evolveum.midpoint.util.exception.SystemException) RObjectType(com.evolveum.midpoint.repo.sql.data.common.other.RObjectType) Statement(java.sql.Statement) Entry(java.util.Map.Entry) RUtil(com.evolveum.midpoint.repo.sql.util.RUtil) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Types(java.sql.Types) Holder(com.evolveum.midpoint.util.Holder) Dialect(org.hibernate.dialect.Dialect)

Example 4 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class CleanupTest method createPolicy.

private CleanupPolicyType createPolicy(Calendar when, long now) throws Exception {
    CleanupPolicyType policy = new CleanupPolicyType();
    Duration duration = createDuration(when, now);
    policy.setMaxAge(duration);
    return policy;
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Duration(javax.xml.datatype.Duration)

Example 5 with CleanupPolicyType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType in project midpoint by Evolveum.

the class CleanupTest method testAuditCleanupMaxRecords.

@Test
public void testAuditCleanupMaxRecords() throws Exception {
    //GIVEN
    prepareAuditEventRecords();
    //WHEN
    Calendar calendar = create_2013_07_12_12_00_Calendar();
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    calendar.add(Calendar.MINUTE, 1);
    final long NOW = System.currentTimeMillis();
    CleanupPolicyType policy = createPolicy(1);
    OperationResult result = new OperationResult("Cleanup audit");
    auditService.cleanupAudit(policy, result);
    result.recomputeStatus();
    //THEN
    RAuditEventRecord record = assertAndReturnAuditEventRecord(result);
}
Also used : CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) RAuditEventRecord(com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord) Calendar(java.util.Calendar) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)11 Duration (javax.xml.datatype.Duration)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 Date (java.util.Date)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 Calendar (java.util.Calendar)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 Test (org.testng.annotations.Test)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)2 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)2 AuditService (com.evolveum.midpoint.audit.api.AuditService)2 com.evolveum.midpoint.repo.sql.data.audit (com.evolveum.midpoint.repo.sql.data.audit)2 RAuditEventRecord (com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord)2 RObjectType (com.evolveum.midpoint.repo.sql.data.common.other.RObjectType)2 BaseHelper (com.evolveum.midpoint.repo.sql.helpers.BaseHelper)2 DtoTranslationException (com.evolveum.midpoint.repo.sql.util.DtoTranslationException)2 GetObjectResult (com.evolveum.midpoint.repo.sql.util.GetObjectResult)2