Search in sources :

Example 36 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class ShadowReconcileTriggerHandler method createNextAttemptTrigger.

private void createNextAttemptTrigger(ShadowType shadow, PlannedOperationAttemptType currentAttemptInfo, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    Duration interval = getInterval(currentAttemptInfo);
    PlannedOperationAttemptType nextAttemptInfo = new PlannedOperationAttemptType(prismContext).number(getNumber(currentAttemptInfo) + 1).interval(interval).limit(getLimit(currentAttemptInfo));
    TriggerType nextTrigger = new TriggerType(prismContext).handlerUri(HANDLER_URI).timestamp(getNextAttemptTimestamp(interval));
    ObjectTypeUtil.setExtensionContainerRealValues(prismContext, nextTrigger.asPrismContainerValue(), SchemaConstants.MODEL_EXTENSION_PLANNED_OPERATION_ATTEMPT, nextAttemptInfo);
    LOGGER.debug("Scheduling new attempt for the synchronization of {} (will be #{} of {}, at {})", shadow, nextAttemptInfo.getNumber(), nextAttemptInfo.getLimit(), nextTrigger.getTimestamp());
    List<ItemDelta<?, ?>> modifications = prismContext.deltaFor(ShadowType.class).item(ShadowType.F_TRIGGER).add(nextTrigger).asItemDeltas();
    repositoryService.modifyObject(ShadowType.class, shadow.getOid(), modifications, result);
}
Also used : Duration(javax.xml.datatype.Duration) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 37 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class ReportManagerImpl method cleanupReports.

@Override
public void cleanupReports(CleanupPolicyType cleanupPolicy, RunningTask task, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS);
    if (cleanupPolicy.getMaxAge() == null) {
        return;
    }
    Duration duration = cleanupPolicy.getMaxAge();
    if (duration.getSign() > 0) {
        duration = duration.negate();
    }
    Date deleteReportOutputsTo = new Date();
    duration.addTo(deleteReportOutputsTo);
    LOGGER.info("Starting cleanup for report outputs deleting up to {} (duration '{}').", deleteReportOutputsTo, duration);
    XMLGregorianCalendar timeXml = XmlTypeConverter.createXMLGregorianCalendar(deleteReportOutputsTo.getTime());
    List<PrismObject<ReportDataType>> obsoleteReportDataObjects;
    try {
        ObjectQuery obsoleteReportOutputsQuery = prismContext.queryFor(ReportDataType.class).item(ReportDataType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP).le(timeXml).build();
        obsoleteReportDataObjects = modelService.searchObjects(ReportDataType.class, obsoleteReportOutputsQuery, null, task, result);
    } catch (Exception e) {
        throw new SystemException("Couldn't get the list of obsolete report outputs: " + e.getMessage(), e);
    }
    LOGGER.debug("Found {} report output(s) to be cleaned up", obsoleteReportDataObjects.size());
    boolean interrupted = false;
    int deleted = 0;
    int problems = 0;
    for (PrismObject<ReportDataType> reportDataPrism : obsoleteReportDataObjects) {
        if (!task.canRun()) {
            interrupted = true;
            break;
        }
        if (ObjectTypeUtil.isIndestructible(reportDataPrism)) {
            LOGGER.trace("NOT removing report output {} as it is marked as indestructible", reportDataPrism);
            continue;
        }
        ReportDataType reportData = reportDataPrism.asObjectable();
        LOGGER.trace("Removing report output {} along with {} file.", reportData.getName().getOrig(), reportData.getFilePath());
        boolean problem = false;
        try {
            deleteReportData(reportData, task, result);
        } catch (Exception e) {
            LoggingUtils.logException(LOGGER, "Couldn't delete obsolete report output {} due to a exception", e, reportData);
            problem = true;
        }
        if (problem) {
            problems++;
        } else {
            deleted++;
        }
    }
    result.computeStatusIfUnknown();
    LOGGER.info("Report cleanup procedure " + (interrupted ? "was interrupted" : "finished") + ". Successfully deleted {} report outputs; there were problems with deleting {} report ouptuts.", deleted, problems);
    String suffix = interrupted ? " Interrupted." : "";
    if (problems == 0) {
        parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS + ".statistics").recordStatus(OperationResultStatus.SUCCESS, "Successfully deleted " + deleted + " report output(s)." + suffix);
    } else {
        parentResult.createSubresult(CLEANUP_REPORT_OUTPUTS + ".statistics").recordPartialError("Successfully deleted " + deleted + " report output(s), " + "there was problems with deleting " + problems + " report outputs.");
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Duration(javax.xml.datatype.Duration) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Date(java.util.Date) IOException(java.io.IOException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 38 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class ObjectValuePolicyEvaluator method isMaxAgeViolated.

private boolean isMaxAgeViolated() {
    if (oldCredential == null) {
        return false;
    }
    Duration maxAge = getMaxAge();
    MetadataType currentCredentialMetadata = oldCredential.getMetadata();
    if (maxAge != null && currentCredentialMetadata != null) {
        XMLGregorianCalendar lastChangeTimestamp = getLastChangeTimestamp(currentCredentialMetadata);
        if (lastChangeTimestamp != null) {
            XMLGregorianCalendar changeAllowedTimestamp = XmlTypeConverter.addDuration(lastChangeTimestamp, maxAge);
            if (changeAllowedTimestamp.compare(now) == DatatypeConstants.LESSER) {
                LOGGER.trace("Password maxAge violated. lastChange={}, maxAge={}, now={}", lastChangeTimestamp, maxAge, now);
                return true;
            }
        }
    }
    return false;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration)

Example 39 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class ObjectValuePolicyEvaluator method validateMinAge.

private void validateMinAge(List<LocalizableMessage> messages, OperationResult result) {
    if (oldCredential == null) {
        return;
    }
    Duration minAge = getMinAge();
    MetadataType currentCredentialMetadata = oldCredential.getMetadata();
    if (minAge != null && currentCredentialMetadata != null) {
        XMLGregorianCalendar lastChangeTimestamp = getLastChangeTimestamp(currentCredentialMetadata);
        if (lastChangeTimestamp != null) {
            XMLGregorianCalendar changeAllowedTimestamp = XmlTypeConverter.addDuration(lastChangeTimestamp, minAge);
            if (changeAllowedTimestamp.compare(now) == DatatypeConstants.GREATER) {
                LOGGER.trace("Password minAge violated. lastChange={}, minAge={}, now={}", lastChangeTimestamp, minAge, now);
                LocalizableMessage msg = LocalizableMessageBuilder.buildKey("ValuePolicy.minAgeNotReached");
                result.addSubresult(new OperationResult("Password minimal age", OperationResultStatus.FATAL_ERROR, msg));
                messages.add(msg);
            }
        }
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 40 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class SqlAuditServiceImpl method cleanupAuditMaxAge.

private void cleanupAuditMaxAge(CleanupPolicyType policy, OperationResult parentResult) {
    if (policy.getMaxAge() == null) {
        return;
    }
    final String operation = "deletingMaxAge";
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(OP_CLEANUP_AUDIT_MAX_AGE, AuditEventRecord.class);
    int attempt = 1;
    Duration duration = policy.getMaxAge();
    if (duration.getSign() > 0) {
        duration = duration.negate();
    }
    Date minValue = new Date();
    duration.addTo(minValue);
    checkTemporaryTablesSupport();
    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), totalCountHolder, batchStart, parentResult);
                } while (count > 0);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, parentResult);
                pm.registerOperationNewAttempt(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 : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) AuditReferenceValue(com.evolveum.midpoint.audit.api.AuditReferenceValue) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) com.evolveum.midpoint.repo.sqlbase(com.evolveum.midpoint.repo.sqlbase) BiFunction(java.util.function.BiFunction) ChangeType(com.evolveum.midpoint.prism.delta.ChangeType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) com.evolveum.midpoint.repo.sql.audit.querymodel(com.evolveum.midpoint.repo.sql.audit.querymodel) ColumnMetadata(com.querydsl.sql.ColumnMetadata) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) ObjectType(com.evolveum.prism.xml.ns._public.types_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Duration(javax.xml.datatype.Duration) SystemConfigurationAuditType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationAuditType) S_MatchingRuleEntry(com.evolveum.midpoint.prism.query.builder.S_MatchingRuleEntry) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) S_ConditionEntry(com.evolveum.midpoint.prism.query.builder.S_ConditionEntry) Holder(com.evolveum.midpoint.util.Holder) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RChangeType(com.evolveum.midpoint.repo.sql.data.common.enums.RChangeType) SystemConfigurationAuditUtil.isEscapingInvalidCharacters(com.evolveum.midpoint.schema.util.SystemConfigurationAuditUtil.isEscapingInvalidCharacters) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Instant(java.time.Instant) Task(com.evolveum.midpoint.task.api.Task) com.evolveum.midpoint.repo.sql.audit.mapping(com.evolveum.midpoint.repo.sql.audit.mapping) BaseHelper(com.evolveum.midpoint.repo.sql.helpers.BaseHelper) CleanupPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType) Nullable(org.jetbrains.annotations.Nullable) SystemException(com.evolveum.midpoint.util.exception.SystemException) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Entry(java.util.Map.Entry) RUtil(com.evolveum.midpoint.repo.sql.util.RUtil) NotNull(org.jetbrains.annotations.NotNull) MAuditDelta(com.evolveum.midpoint.repo.sql.audit.beans.MAuditDelta) Types(java.sql.Types) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) java.util(java.util) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) ObjectDeltaOperationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType) ROperationResultStatus(com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus) AuditSqlQueryContext(com.evolveum.midpoint.repo.sql.audit.AuditSqlQueryContext) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType) SQLQuery(com.querydsl.sql.SQLQuery) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) com.evolveum.midpoint.xml.ns._public.common.audit_3(com.evolveum.midpoint.xml.ns._public.common.audit_3) SQLInsertClause(com.querydsl.sql.dml.SQLInsertClause) AuditService(com.evolveum.midpoint.audit.api.AuditService) TemporaryTableDialect(com.evolveum.midpoint.repo.sql.util.TemporaryTableDialect) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) Validate(org.apache.commons.lang3.Validate) DefaultMapper(com.querydsl.sql.dml.DefaultMapper) MAuditEventRecord(com.evolveum.midpoint.repo.sql.audit.beans.MAuditEventRecord) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) Holder(com.evolveum.midpoint.util.Holder) Duration(javax.xml.datatype.Duration) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

Duration (javax.xml.datatype.Duration)110 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)50 Test (org.junit.Test)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 ArrayList (java.util.ArrayList)11 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 GregorianCalendar (java.util.GregorianCalendar)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 Date (java.util.Date)7 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)6 Calendar (java.util.Calendar)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)5 Collection (java.util.Collection)4 NodeValue (org.apache.jena.sparql.expr.NodeValue)4 NotNull (org.jetbrains.annotations.NotNull)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 Task (com.evolveum.midpoint.task.api.Task)3