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);
}
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.");
}
}
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;
}
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);
}
}
}
}
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);
}
}
Aggregations